Skip to content

Regenerate PendingHTLCsForwardable on reload instead of serializing #1076

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

Conversation

TheBlueMatt
Copy link
Collaborator

When we are prepared to forward HTLCs, we generate a
PendingHTLCsForwardable event with a time in the future when the
user should tell us to forward. This provides some basic batching
of forward events, improving privacy slightly.

After we generate the event, we expect users to spawn a timer in
the background and let us know when it finishes. However, if the
user shuts down before the timer fires, the user will restart and
have no idea that HTLCs are waiting to be forwarded/received.

To fix this, instead of serializing PendingHTLCsForwardable events
to disk while they're pending (before the user starts the timer),
we simply regenerate them when a ChannelManager is deserialized
with HTLCs pending.

Fixes #1042

@TheBlueMatt TheBlueMatt added this to the 0.0.102 milestone Sep 15, 2021
@codecov
Copy link

codecov bot commented Sep 15, 2021

Codecov Report

Merging #1076 (8b956e9) into main (24065c8) will increase coverage by 0.21%.
The diff coverage is 98.80%.

❗ Current head 8b956e9 differs from pull request most recent head 0fcc34b. Consider uploading reports for the commit 0fcc34b to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1076      +/-   ##
==========================================
+ Coverage   91.00%   91.22%   +0.21%     
==========================================
  Files          65       65              
  Lines       33695    34613     +918     
==========================================
+ Hits        30663    31574     +911     
- Misses       3032     3039       +7     
Impacted Files Coverage Δ
lightning/src/util/events.rs 28.57% <0.00%> (+1.02%) ⬆️
lightning/src/ln/channelmanager.rs 86.01% <100.00%> (+0.11%) ⬆️
lightning/src/ln/functional_tests.rs 97.46% <100.00%> (-0.07%) ⬇️
lightning/src/ln/chanmon_update_fail_tests.rs 97.75% <0.00%> (-0.14%) ⬇️
lightning/src/ln/channel.rs 90.67% <0.00%> (+2.00%) ⬆️

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 24065c8...0fcc34b. Read the comment docs.

Copy link

@ariard ariard left a comment

Choose a reason for hiding this comment

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

Code Review ACK 8b956e9

// constant as enough time has likely passed that we should simply handle the forwards
// now, or at least after the user gets a chance to reconnect to our peers.
pending_events_read.push(events::Event::PendingHTLCsForwardable {
time_forwardable: Duration::from_secs(2),
Copy link

Choose a reason for hiding this comment

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

Do we still expect the user to wait between "now + 2 time forwardable" and "now + 5 * time forwardable" following PendingHTLCsForwardable doc ? Not sure if it makes sense to wait at least 5 * after reload as all pending HTLCs have been normalized in the same period due to the serialization. If yes, maybe doc could suggest that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yea, we haven't changed the docs here, but we would have to do something other than just change the docs - a user cannot determine just by looking at a PendingHTLCsForwardable whether it was created during startup or at runtime, so I dunno if we want to put that complexity on the user. In the future we can/should just do the randomization ourselves, IMO, now that we have a generic random value interface, but that's a bigger change.

When we are prepared to forward HTLCs, we generate a
PendingHTLCsForwardable event with a time in the future when the
user should tell us to forward. This provides some basic batching
of forward events, improving privacy slightly.

After we generate the event, we expect users to spawn a timer in
the background and let us know when it finishes. However, if the
user shuts down before the timer fires, the user will restart and
have no idea that HTLCs are waiting to be forwarded/received.

To fix this, instead of serializing PendingHTLCsForwardable events
to disk while they're pending (before the user starts the timer),
we simply regenerate them when a ChannelManager is deserialized
with HTLCs pending.

Fixes lightningdevkit#1042
@TheBlueMatt
Copy link
Collaborator Author

Squashed with no diff, will take after CI, opened issue to track randomization in RL at #1101.

$ git diff-tree -U1 8b956e9e 0fcc34b9
$

@TheBlueMatt TheBlueMatt merged commit 2352587 into lightningdevkit:main Sep 29, 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.

Consider auto-regenerating PendingHTLCsForwardable on restart
3 participants