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

Wake background-processor from ChainMonitor on new blocks #3033

Merged

Conversation

TheBlueMatt
Copy link
Collaborator

When we receive a new block we may generate
Event::SpendableOutputs in ChannelMonitors which then need to be processed by the background processor. While it will do so eventually when its normal loop goes around, this may cause user tests to be delayed in finding events, so we should notify the BP immediately to wake it on new blocks.

We implement that here, unconditionally notifying the background-processor whenever we receive a new block or confirmed transactions.

@TheBlueMatt TheBlueMatt added this to the 0.0.123 milestone Apr 30, 2024
@valentinewallace
Copy link
Contributor

Would this have adverse effects if someone's on regtest and mines 100+ blocks at once? Or testnet blockstorms. That's the only reason I could see we'd want more precise notifications for pending events.

@TheBlueMatt TheBlueMatt force-pushed the 2024-04-notify-bp-on-blocks branch from 0348de2 to 8f4a107 Compare May 1, 2024 18:56
@TheBlueMatt
Copy link
Collaborator Author

It shouldn't - if we're too slow the BP won't always loop 100 times but rather will ensure it loops at least once after the last notify.

@codecov-commenter
Copy link

codecov-commenter commented May 1, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.13%. Comparing base (2b14cc4) to head (8f4a107).
Report is 4 commits behind head on main.

❗ Current head 8f4a107 differs from pull request most recent head 021979b. Consider uploading reports for the commit 021979b to get more accurate results

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

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3033      +/-   ##
==========================================
- Coverage   89.14%   89.13%   -0.02%     
==========================================
  Files         118      118              
  Lines       97850    97972     +122     
  Branches    97850    97972     +122     
==========================================
+ Hits        87230    87325      +95     
- Misses       8376     8400      +24     
- Partials     2244     2247       +3     

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

lightning/src/chain/chainmonitor.rs Outdated Show resolved Hide resolved
@@ -738,6 +740,8 @@ where
monitor.block_connected(
header, txdata, height, &*self.broadcaster, &*self.fee_estimator, &self.logger)
});
// Assume we may have some new events and wake the event processor
Copy link
Contributor

@G8XSU G8XSU May 1, 2024

Choose a reason for hiding this comment

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

usually, i see that we notify event_notifier just after publishing the event to chainmonitor::pending_monitor_events.
but i see that we don't do so for channelmonitor::pending_monitor_events when we push new actionable events and we don't have access to event_notifier in channelmonitor.

Can you help me understand this pattern?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Right, we don't have access to the event_notifier so we just assume there may be new events and wake. Not much reason to worry too much about it, a BP loop is pretty cheap so having to do a few extra won't kill us.

When we receive a new block we may generate
`Event::SpendableOutputs` in `ChannelMonitor`s which then need to
be processed by the background processor. While it will do so
eventually when its normal loop goes around, this may cause user
tests to be delayed in finding events, so we should notify the BP
immediately to wake it on new blocks.

We implement that here, unconditionally notifying the
`background-processor` whenever we receive a new block or confirmed
transactions.
@TheBlueMatt TheBlueMatt merged commit bd3cc00 into lightningdevkit:main May 1, 2024
15 of 16 checks passed
TheBlueMatt added a commit to TheBlueMatt/rust-lightning that referenced this pull request May 6, 2024
…fy-bp-on-blocks

Wake `background-processor` from `ChainMonitor` on new blocks
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.

None yet

4 participants