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 HTLC fulfill race condition in integration spec #1666

Merged
merged 2 commits into from
Jan 19, 2021

Conversation

t-bast
Copy link
Member

@t-bast t-bast commented Jan 7, 2021

We were extracting F's commit tx from its internal state right after receiving the PaymentSent event. The issue is that this could happen before the fulfill was completely signed on both sides, so the commit tx we obtained would still contain the HTLC and would be different from the one F would publish when closing.

This is the race condition that was sometimes happening:

C            F
 add ------->
 <--- fulfill

 payment-sent
 F's commit tx 1

 <------- sig
 rev ------->
 sig ------->
 <------- rev

 force-close
 F's commit tx 2

And F's commit tx1 and commit tx2 would be different, so we were trying to get the wrong tx from bitcoind.

We were extracting F's commit tx from its internal state right after receiving
the `PaymentSent` event. The issue is that this could happen before the fulfill
was completely signed on both sides, so the commit tx we obtained would still
contain the HTLC and would be different from the one F would publish when
closing.
@t-bast t-bast requested a review from pm47 January 7, 2021 09:11
@codecov-io
Copy link

codecov-io commented Jan 7, 2021

Codecov Report

Merging #1666 (079920b) into master (b477d17) will increase coverage by 0.02%.
The diff coverage is n/a.

@@            Coverage Diff             @@
##           master    #1666      +/-   ##
==========================================
+ Coverage   85.94%   85.97%   +0.02%     
==========================================
  Files         151      151              
  Lines       11471    11471              
  Branches      505      505              
==========================================
+ Hits         9859     9862       +3     
+ Misses       1612     1609       -3     
Impacted Files Coverage Δ
...cinq/eclair/blockchain/bitcoind/zmq/ZMQActor.scala 90.00% <0.00%> (-5.00%) ⬇️
...c/main/scala/fr/acinq/eclair/payment/Auditor.scala 95.65% <0.00%> (-2.18%) ⬇️
...nq/eclair/blockchain/electrum/ElectrumClient.scala 73.52% <0.00%> (ø)
...c/main/scala/fr/acinq/eclair/channel/Channel.scala 86.14% <0.00%> (+0.17%) ⬆️
...main/scala/fr/acinq/eclair/router/Validation.scala 92.91% <0.00%> (+1.49%) ⬆️

@pm47
Copy link
Member

pm47 commented Jan 7, 2021

Wasn't it a nice corner case to test though? (force close with only the unsigned fulfill).

@t-bast
Copy link
Member Author

t-bast commented Jan 7, 2021

True, but we can't test it reliably in an integration test because we can't control the timing to ensure we're exactly at that step.
But it can be tested in the channel tests, I'll add it there (if it's missing).

@t-bast
Copy link
Member Author

t-bast commented Jan 7, 2021

Wasn't it a nice corner case to test though? (force close with only the unsigned fulfill).

Done in 079920b

@t-bast t-bast merged commit 9c4ab7d into master Jan 19, 2021
@t-bast t-bast deleted the integration-spec-fix branch January 19, 2021 14:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants