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
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lightning/src/chain/chainmonitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,8 @@ pub struct ChainMonitor<ChannelSigner: WriteableEcdsaChannelSigner, C: Deref, T:
/// The best block height seen, used as a proxy for the passage of time.
highest_chain_height: AtomicUsize,

/// A [`Notifier`] used to wake up the background processor in case we have any [`Event`]s for
/// it to give to users (or [`MonitorEvent`]s for `ChannelManager` to process).
event_notifier: Notifier,
}

Expand Down Expand Up @@ -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.

self.event_notifier.notify();
TheBlueMatt marked this conversation as resolved.
Show resolved Hide resolved
}

fn block_disconnected(&self, header: &Header, height: u32) {
Expand Down Expand Up @@ -765,6 +769,8 @@ where
monitor.transactions_confirmed(
header, txdata, height, &*self.broadcaster, &*self.fee_estimator, &self.logger)
});
// Assume we may have some new events and wake the event processor
self.event_notifier.notify();
}

fn transaction_unconfirmed(&self, txid: &Txid) {
Expand All @@ -785,6 +791,8 @@ where
header, height, &*self.broadcaster, &*self.fee_estimator, &self.logger
)
});
// Assume we may have some new events and wake the event processor
self.event_notifier.notify();
}

fn get_relevant_txids(&self) -> Vec<(Txid, u32, Option<BlockHash>)> {
Expand Down
Loading