Skip to content

Correct Channel outbound HTLC serialization and expand fuzzing coverage #892

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

Merged
merged 4 commits into from
May 31, 2021

Conversation

TheBlueMatt
Copy link
Collaborator

@TheBlueMatt TheBlueMatt commented Apr 21, 2021

This is based on #851 as it is required to get chanmon_consistency_target to run clean anyway.

This fixes a few trivial bugs in full_stack_target, then expands the coverage of chanmon_consistency_target significantly, fixing one bug that that expansion found (so far).

@TheBlueMatt TheBlueMatt force-pushed the 2021-04-fix-htlc-ser branch from caaba21 to 055f0b3 Compare April 21, 2021 22:25
@codecov
Copy link

codecov bot commented Apr 21, 2021

Codecov Report

Merging #892 (25dbd0d) into main (f8450a7) will increase coverage by 1.93%.
The diff coverage is 66.66%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #892      +/-   ##
==========================================
+ Coverage   90.42%   92.36%   +1.93%     
==========================================
  Files          59       61       +2     
  Lines       30173    41340   +11167     
==========================================
+ Hits        27285    38184   +10899     
- Misses       2888     3156     +268     
Impacted Files Coverage Δ
lightning/src/ln/channel.rs 92.72% <66.66%> (+4.42%) ⬆️
lightning/src/util/errors.rs 64.51% <0.00%> (-6.92%) ⬇️
lightning/src/util/events.rs 16.57% <0.00%> (-3.78%) ⬇️
lightning/src/ln/features.rs 98.57% <0.00%> (-0.26%) ⬇️
lightning/src/util/ser.rs 92.85% <0.00%> (-0.12%) ⬇️
lightning/src/chain/mod.rs 100.00% <0.00%> (ø)
lightning/src/chain/transaction.rs 100.00% <0.00%> (ø)
lightning/src/chain/package.rs 92.51% <0.00%> (ø)
lightning/src/chain/onchaintx.rs 94.14% <0.00%> (ø)
lightning/src/util/poly1305.rs 99.52% <0.00%> (+0.04%) ⬆️
... and 28 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 f8450a7...25dbd0d. Read the comment docs.

@TheBlueMatt
Copy link
Collaborator Author

Rebased after #851 merge.

@TheBlueMatt TheBlueMatt force-pushed the 2021-04-fix-htlc-ser branch from 50e9525 to 46697b9 Compare May 25, 2021 18:25
@jkczyz jkczyz self-requested a review May 26, 2021 00:03
@TheBlueMatt TheBlueMatt force-pushed the 2021-04-fix-htlc-ser branch from 46697b9 to 1c818cd Compare May 27, 2021 16:21
@TheBlueMatt
Copy link
Collaborator Author

Added some additional documentation.

While trying to debug the issue ultimately tracked down to a
`PeerHandler` locking bug in lightningdevkit#891, the ability to deliver only
individual messages at a time in chanmon_consistency looked
important. Specifically, it initially appeared there may be a race
when an update_add_htlc was delivered, then a node sent a payment,
and only after that, the corresponding commitment-signed was
delivered.

This commit adds such an ability, greatly expanding the potential
for chanmon_consistency to identify channel state machine bugs.
Channel serialization should happen "as if
remove_uncommitted_htlcs_and_mark_paused had just been called".

This is true for the most part, but outbound RemoteRemoved HTLCs
were being serialized as normal, even though
`remote_uncommitted_htlcs_and_mark_paused` resets them to
`Committed`.

This led to a bug identified by the `chanmon_consistency_target`
fuzzer wherein, if we receive a update_*_htlc message bug not the
corresponding commitment_signed prior to a serialization roundtrip,
we'd force-close the channel due to the peer "attempting to
fail/claim an HTLC which was already failed/claimed".
@TheBlueMatt TheBlueMatt force-pushed the 2021-04-fix-htlc-ser branch from 1c818cd to 25dbd0d Compare May 31, 2021 18:20
@TheBlueMatt
Copy link
Collaborator Author

Squashed fixups with no changes. Will merge after CI:

$ git diff-tree -U3  1c818cd13 25dbd0d7e
$

@TheBlueMatt TheBlueMatt merged commit c05347f into lightningdevkit:main May 31, 2021
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