From 13a33409b519e57b7d14cd9e440223d3495d55eb Mon Sep 17 00:00:00 2001 From: Jeffrey Czyz Date: Wed, 24 Mar 2021 18:47:44 -0400 Subject: [PATCH] Add ChannelMonitor::transactions_confirmed Define an Electrum-friendly interface for ChannelMonitor where transactions are confirmed independently of updating the last connected block. --- lightning/src/chain/channelmonitor.rs | 43 ++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/lightning/src/chain/channelmonitor.rs b/lightning/src/chain/channelmonitor.rs index 0fb04c457..1a0b3dcdf 100644 --- a/lightning/src/chain/channelmonitor.rs +++ b/lightning/src/chain/channelmonitor.rs @@ -1303,6 +1303,30 @@ impl ChannelMonitor { self.inner.lock().unwrap().block_disconnected( header, height, broadcaster, fee_estimator, logger) } + + /// Processes transactions from a block with the given header and height, returning new outputs + /// to watch. See [`block_connected`] for details. + /// + /// TODO: Expand docs. + /// + /// [`block_connected`]: Self::block_connected + pub fn transactions_confirmed( + &self, + header: &BlockHeader, + txdata: &TransactionData, + height: u32, + broadcaster: B, + fee_estimator: F, + logger: L, + ) -> Vec<(Txid, Vec<(u32, TxOut)>)> + where + B::Target: BroadcasterInterface, + F::Target: FeeEstimator, + L::Target: Logger, + { + self.inner.lock().unwrap().transactions_confirmed( + header, txdata, height, broadcaster, fee_estimator, logger) + } } impl ChannelMonitorImpl { @@ -2003,6 +2027,24 @@ impl ChannelMonitorImpl { where B::Target: BroadcasterInterface, F::Target: FeeEstimator, L::Target: Logger, + { + self.best_block = BestBlock::new(header.block_hash(), height); + self.transactions_confirmed(header, txdata, height, broadcaster, fee_estimator, logger) + } + + fn transactions_confirmed( + &mut self, + header: &BlockHeader, + txdata: &TransactionData, + height: u32, + broadcaster: B, + fee_estimator: F, + logger: L, + ) -> Vec<(Txid, Vec<(u32, TxOut)>)> + where + B::Target: BroadcasterInterface, + F::Target: FeeEstimator, + L::Target: Logger, { let txn_matched = self.filter_block(txdata); for tx in &txn_matched { @@ -2135,7 +2177,6 @@ impl ChannelMonitorImpl { } self.onchain_tx_handler.update_claims_view(&txn_matched, claimable_outpoints, Some(height), &&*broadcaster, &&*fee_estimator, &&*logger); - self.best_block = BestBlock::new(block_hash, height); // Determine new outputs to watch by comparing against previously known outputs to watch, // updating the latter in the process. -- 2.39.5