Skip to content

Commit

Permalink
Wake background-processor from ChainMonitor on new blocks
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
TheBlueMatt committed May 1, 2024
1 parent 2b14cc4 commit 8f4a107
Showing 1 changed file with 8 additions and 0 deletions.
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
self.event_notifier.notify();
}

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

0 comments on commit 8f4a107

Please sign in to comment.