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

Don't pause events for chainsync persistence #2957

Merged
merged 5 commits into from May 6, 2024

Conversation

G8XSU
Copy link
Contributor

@G8XSU G8XSU commented Mar 21, 2024

This change was introduced in 5c2ff2cb30ef1639c80b275eea209a289dd91b77 (#1108)
and the main reason mentioned is to avoid duplicate payment events.

Duplicate payment events should be expected by clients and handled in an idempotent manner.

Removing this holding up of events simplifies the logic and makes it easier to do #2647 in which we will stop persisting channelmonitors for every block update.

  • Don't pause events for chainsync persistence
  • Remove testcase that detects chain_sync_pauses_events
  • Fix existing testcase for duplicate payment events.
  • Where should we fail when persistence fails? (Update: We no longer fail in release_pending_events for this, hence this should not be a concern anymore.)
  • Make MonitorUpdateId optional in persist trait
  • Remove UpdateOrigin::ChainSync
  • Remove sync_persistence_id
  • Remove concept of MonitorUpdateId altogether,
  • Remove update_id from public API of persist interface, i.e. both persist_new_channel and update_persisted_channel
  • Doc to notify channel_monitor_updated using monitor.getlatestUpdateId or update.update_id.
  • and to not notify when an update is absent in update_persisted_channel

@G8XSU G8XSU force-pushed the pause-events branch 2 times, most recently from f674099 to 5ea38da Compare March 21, 2024 04:52
@codecov-commenter
Copy link

codecov-commenter commented Mar 21, 2024

Codecov Report

Attention: Patch coverage is 98.66667% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 89.35%. Comparing base (9a438ee) to head (4d5de1f).
Report is 41 commits behind head on main.

Files Patch % Lines
lightning/src/chain/chainmonitor.rs 97.43% 1 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2957      +/-   ##
==========================================
+ Coverage   89.13%   89.35%   +0.21%     
==========================================
  Files         118      118              
  Lines       97678    98933    +1255     
  Branches    97678    98933    +1255     
==========================================
+ Hits        87066    88401    +1335     
+ Misses       8370     8267     -103     
- Partials     2242     2265      +23     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@tnull
Copy link
Contributor

tnull commented Mar 21, 2024

Duplicate payment events should be expected by clients and handled in an idempotent manner.

I'm not sure if we document that assumption anywhere so far? Could you clarify if this would also pertain inbound payments and PaymentForwarded events? Given that these don't expose a PaymentId I'm not sure we provide the user a good way to handle spurious events in and idempotent manner?

@G8XSU
Copy link
Contributor Author

G8XSU commented Mar 21, 2024

Could you clarify if this would also pertain inbound payments and PaymentForwarded events? Given that these don't expose a PaymentId I'm not sure we provide the user a good way to handle spurious events in and idempotent manner?

Synced offline, due to current event architecture, we could always get duplicate events after an event is handled and channel-manager isn't immediately persisted.
Inbound payments afaiu, should have payment hash but PaymentForwarded don't have any such identifier.
We can separately consider adding a hash of htlc forwarded in PaymentForwarded

@G8XSU
Copy link
Contributor Author

G8XSU commented Mar 21, 2024

Where should we fail when persistence fails?

Update: We no longer fail in release_pending_events for this, hence it should not be a concern anymore.

TheBlueMatt
TheBlueMatt previously approved these changes Mar 21, 2024
lightning/src/ln/payment_tests.rs Outdated Show resolved Hide resolved
Copy link
Collaborator

@TheBlueMatt TheBlueMatt left a comment

Choose a reason for hiding this comment

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

The change itself here looks good, but there's a ton of other changes in ChainMonitor that we should unwind now. I'm pretty sure we can entirely drop UpdateOrigin now (and just use the off-chain monitor update ID), stop tracking any pending monitor updates that came from on-chain, etc.

lightning/src/chain/chainmonitor.rs Outdated Show resolved Hide resolved
lightning/src/chain/chainmonitor.rs Outdated Show resolved Hide resolved
@G8XSU G8XSU requested a review from TheBlueMatt April 12, 2024 06:51
Copy link
Collaborator

@TheBlueMatt TheBlueMatt left a comment

Choose a reason for hiding this comment

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

Basically LGTM!

lightning/src/chain/chainmonitor.rs Outdated Show resolved Hide resolved
lightning/src/chain/chainmonitor.rs Outdated Show resolved Hide resolved
@TheBlueMatt TheBlueMatt added this to the 0.0.124 milestone Apr 12, 2024
@TheBlueMatt
Copy link
Collaborator

Needs rebase, also I think the top commit should be squashed down into the places that create the warnings.

@TheBlueMatt
Copy link
Collaborator

So one thing that came up while I was working with this API in the fuzzer is that its really awkward that the update_id in the ChannelMonitorUpdate is a different type from the update_id passed to the persister (and provided via list_pending_monitor_updates). I'm not sure users are gonna hit that all that often, but it would be really nice if they were the same type (one way or another).

@G8XSU
Copy link
Contributor Author

G8XSU commented Apr 15, 2024

Discussed couple of things offline,

  • Will remove concept of MonitorUpdateId altogether, will use u64 everywhere.
  • Will remove update_id from pub api of persist interface, i.e. both persist_new_channel and update_persisted_channel
  • Doc to notify channel_monitor_updated using monitor.getlatestUpdateId or update.update_id.
  • and to not notify when an update is absent in update_persisted_channel

@G8XSU G8XSU force-pushed the pause-events branch 6 times, most recently from 1d42927 to e1d5921 Compare April 25, 2024 19:17
Copy link
Collaborator

@TheBlueMatt TheBlueMatt left a comment

Choose a reason for hiding this comment

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

CI is failing and lots of docs are stale.

lightning/src/chain/chainmonitor.rs Outdated Show resolved Hide resolved
We used to wait on ChannelMonitor persistence to avoid
duplicate payment events. But this can still happen in cases where
ChannelMonitor handed the event to ChannelManager and we did not persist
ChannelManager after event handling.
It is expected to receive payment duplicate events and clients should handle these
events in an idempotent manner. Removing this hold-up of events simplifies
the logic and makes it easier to not persist ChannelMonitors on every block connect.
@G8XSU G8XSU force-pushed the pause-events branch 2 times, most recently from 8a10e83 to 45de321 Compare April 26, 2024 22:59
We only used to store last_chain_persist_height to release
events held for more than LATENCY_GRACE_PERIOD_BLOCKS due to
pending monitor update with UpdateOrigin::ChainSync. Since we no
longer pause events for ChainSync persistence, we no longer need to
store last_chain_persist_height.
We no longer need to track them since we no longer hold events for
pending MonitorUpdates resulting from ChainSync.
@G8XSU G8XSU force-pushed the pause-events branch 2 times, most recently from b72e897 to bd15c45 Compare April 27, 2024 00:21
MonitorUpdateId was an opaque abstraction for id's generated by
UpdateOrigin:Offchain and UpdateOrigin::ChainSync monitor updates.
It was mainly needed to map calls made to
ChainMonitor::channel_monitor_updated. We no longer track
UpdateOrigin::ChainSync MonitorUpdates and can directly use
ChannelMonitor::get_latest_update_id() for tracking
UpdateOrigin::Offchain monitor updates.
It was used earlier for generating unique MonitorUpdateId for
UpdateOrigin::ChainSync monitor updates.
Copy link
Collaborator

@TheBlueMatt TheBlueMatt left a comment

Choose a reason for hiding this comment

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

One comment that can be a followup.

lightning/src/util/test_utils.rs Show resolved Hide resolved
lightning/src/util/test_utils.rs Show resolved Hide resolved
lightning/src/chain/chainmonitor.rs Show resolved Hide resolved
lightning/src/chain/chainmonitor.rs Show resolved Hide resolved
G8XSU added a commit to G8XSU/rust-lightning that referenced this pull request May 6, 2024
@G8XSU G8XSU mentioned this pull request May 6, 2024
@G8XSU
Copy link
Contributor Author

G8XSU commented May 6, 2024

Created a followup PR, I can merge that into this, if needed.

@TheBlueMatt TheBlueMatt merged commit b8d4ac1 into lightningdevkit:main May 6, 2024
15 of 16 checks passed
G8XSU added a commit to G8XSU/rust-lightning that referenced this pull request May 6, 2024
TheBlueMatt added a commit that referenced this pull request May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants