Skip to content

Commit 8f4a107

Browse files
committed
Wake background-processor from ChainMonitor on new blocks
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.
1 parent 2b14cc4 commit 8f4a107

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

lightning/src/chain/chainmonitor.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,8 @@ pub struct ChainMonitor<ChannelSigner: WriteableEcdsaChannelSigner, C: Deref, T:
296296
/// The best block height seen, used as a proxy for the passage of time.
297297
highest_chain_height: AtomicUsize,
298298

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

@@ -738,6 +740,8 @@ where
738740
monitor.block_connected(
739741
header, txdata, height, &*self.broadcaster, &*self.fee_estimator, &self.logger)
740742
});
743+
// Assume we may have some new events and wake the event processor
744+
self.event_notifier.notify();
741745
}
742746

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

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

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

0 commit comments

Comments
 (0)