Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement tx confirmation for channelOpen #1009

Merged
merged 3 commits into from
Feb 12, 2020
Merged

Conversation

andrevmatos
Copy link
Contributor

@andrevmatos andrevmatos commented Feb 10, 2020

Part of #613
Todo in a later PR, is to extend this method to all on-chain transactions.
First time the on-chain transaction is seen, it gets dispatched with payload.confirmed property present but set as undefined, meaning pending. Reducer will persist/serialize it to state.pendingTx (thanks to #759).

Then, on each block, the possibly confirmed actions (when more than config.confirmationBlocks have passed since first/pending action) gets fetched with getTransactionReceipt, and if the transaction is still present on-chain, it gets re-emitted with confirmed=true, which also removes it from the pendintTx state.
If it isn't present, on each block until 2 * confirmationBlocks, check again. If it still isn't there/confirmed after this timeout, consider the transaction as having been removed by a chain reorg, and re-emit it, now with confirmed=false, which also removes it from pendingTx and rejects any pending promise.
.
The confirmable actions always being emitted twice (first as pending, later as confirmed or removed) enables each part of the codebase to chose which actions/events to react to, be it first time seeing a tx event, or upon confirmation: e.g. the transfer epics can react early to channelClose and avoid accepting new transfers or mediating (in the future), while accepting deposits as increasing the channel's capacity is done only after it has been confirmed.

The confirmationEpic reacting on state ensures this algorithm is safe upon shutdown and later client restart, even with to-be-confirmed actions being able to be picked up again after much time (as long as receipt can be fetched by eth client, which may not be the case without full or even archiving node with enormous block ranges, but we'd consider this as an unexpected edge case).

@andrevmatos andrevmatos added enhancement New feature or request sdk 🖥 labels Feb 10, 2020
@andrevmatos andrevmatos force-pushed the feat/confirmation branch 3 times, most recently from 65d86be to 825f31b Compare February 11, 2020 15:43
@codecov
Copy link

codecov bot commented Feb 11, 2020

Codecov Report

Merging #1009 into master will decrease coverage by 0.03%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1009      +/-   ##
==========================================
- Coverage   96.04%   96.00%   -0.04%     
==========================================
  Files          95       95              
  Lines        3588     3633      +45     
  Branches      759      775      +16     
==========================================
+ Hits         3446     3488      +42     
- Misses         85       88       +3     
  Partials       57       57              
Flag Coverage Δ
#dapp 91.46% <ø> (ø) ⬆️
#sdk 97.86% <95.31%> (-0.09%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update dc99aea...a0ef008. Read the comment docs.

@andrevmatos andrevmatos marked this pull request as ready for review February 11, 2020 16:07
@andrevmatos andrevmatos linked an issue Feb 11, 2020 that may be closed by this pull request
Copy link
Contributor

@kelsos kelsos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good, thank you 👍

Copy link
Contributor

@nephix nephix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests must have been pain. Good job 👍

raiden-ts/src/config.ts Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request sdk 🖥
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement confirmation blocks
3 participants