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

Fix parallel open + deposit and disable channel closing if Metamask prompt is cancelled #2967

Merged
merged 7 commits into from
Oct 11, 2021

Conversation

andrevmatos
Copy link
Contributor

Fixes #2963
Also fixes an issue seen in highly-concurrent scenarios like BF7

Short description
See commits messages for descriptions of what got fixed.

Definition of Done

  • Steps to manually test the change have been documented
  • Acceptance criteria are met
  • Change has been manually tested by the reviewer (dApp)

Steps to manually test the change (dApp)

rxjs@7 renamed  `merge` operator to `mergeWith`, which merges the
content of observable arguments with input (like `merge` function, but
as inline operator), and this conflicts with the name we've choosen for
our custom operator (no functionality yet provided ootb).
The new name `withMergeFrom`, is also more descriptive, as it acts like
`withLatestFrom` operator, but without losing values from input before
arguments emitted (which the later does) and also emitting for each
inner emition as well.
@andrevmatos andrevmatos requested a review from palango October 9, 2021 01:15
@andrevmatos andrevmatos self-assigned this Oct 9, 2021
@andrevmatos andrevmatos force-pushed the fix/parallel_deposit branch from 77f3f08 to d14cbe7 Compare October 9, 2021 01:20
@codecov
Copy link

codecov bot commented Oct 9, 2021

Codecov Report

Merging #2967 (27763e5) into master (69878d1) will decrease coverage by 0.03%.
The diff coverage is 96.92%.

❗ Current head 27763e5 differs from pull request most recent head 5a5e798. Consider uploading reports for the commit 5a5e798 to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2967      +/-   ##
==========================================
- Coverage   93.30%   93.26%   -0.04%     
==========================================
  Files         207      207              
  Lines        8813     8761      -52     
  Branches     1372     1353      -19     
==========================================
- Hits         8223     8171      -52     
  Misses        489      489              
  Partials      101      101              
Flag Coverage Δ
dapp 88.96% <ø> (ø)
dapp.unit 88.96% <ø> (ø)
sdk 95.80% <96.92%> (-0.04%) ⬇️
sdk.e2e 72.75% <80.00%> (+0.39%) ⬆️
sdk.integration 80.21% <56.92%> (+0.31%) ⬆️
sdk.unit 48.68% <56.92%> (-0.18%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
raiden-ts/src/channels/epics/deposit.ts 87.27% <33.33%> (-3.64%) ⬇️
raiden-ts/src/channels/epics/open.ts 100.00% <100.00%> (ø)
raiden-ts/src/channels/epics/settle.ts 93.87% <100.00%> (+0.12%) ⬆️
raiden-ts/src/channels/reducer.ts 99.00% <100.00%> (-0.06%) ⬇️
raiden-ts/src/helpers.ts 87.26% <100.00%> (-0.76%) ⬇️
raiden-ts/src/raiden.ts 94.84% <100.00%> (-0.05%) ⬇️
raiden-ts/src/services/epics/helpers.ts 96.07% <100.00%> (ø)
raiden-ts/src/services/epics/udc.ts 100.00% <100.00%> (ø)
raiden-ts/src/transport/epics/messages.ts 94.70% <100.00%> (ø)
raiden-ts/src/transport/epics/presence.ts 100.00% <100.00%> (ø)
... and 4 more

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 69878d1...5a5e798. Read the comment docs.

Since we are waiting 2x confirmations after deposit/open, this is more
than enough time for the PFSCapacityUpdates to be sent, and we can
remove this quite complex and bug-prone helper.
This ensures `BigNumber` constructor instance is the same across CLI and
SDK, and CLI's logging `util.inspect.custom` method properly pretty
print BigNumber instances in logs
if a first unconfirmed openChannel from partner came through while we
were openChannelWithDeposit'ing, a channelDeposit is requested, which
will fail if the former openChannel is replaced by our
openChannelWithDeposit on a reorg. In this case, we must give up on the
deposit request. This happens on BF7/high-concurrency scenarios.
A rare race condition (visible only on high-concurrency scenarios like
BF7) could cause an openChannelWithDeposit which first succeeded (and
therefore cancelled parallel deposit) to be reorged and replaced by
partner's concurrent openChannel, causing deposit to never go through
(and scenario's timeout). By dispatching `channelDeposit.request` in
parallel unconditionally with method used (and actually using it for
ensureApprovedBalance$) guarantees deposit will be performed on either
condition, and is cancelled only when/if/after totalDeposit gets
confirmed.
Allows users to change their minds and reject Metamask's tx prompt and
still get an usable channel after that. Channel goes to closing/settling
state upon respective unconfirmed success now.
Copy link
Contributor

@palango palango left a comment

Choose a reason for hiding this comment

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

Nice find with the parallel open/deposit case!

Rest is good to go as well!

@andrevmatos andrevmatos merged commit e6ee970 into master Oct 11, 2021
@andrevmatos andrevmatos deleted the fix/parallel_deposit branch October 11, 2021 15:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants