Skip to content

Commit 9effd92

Browse files
committed
Add ChannelMonitor::transactions_confirmed
Define an Electrum-friendly interface for ChannelMonitor where transactions are confirmed independently of updating the last connected block.
1 parent 2933900 commit 9effd92

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1305,6 +1305,30 @@ impl<Signer: Sign> ChannelMonitor<Signer> {
13051305
self.inner.lock().unwrap().block_disconnected(
13061306
header, height, broadcaster, fee_estimator, logger)
13071307
}
1308+
1309+
/// Processes transactions from a block with the given header and height, returning new outputs
1310+
/// to watch. See [`block_connected`] for details.
1311+
///
1312+
/// TODO: Expand docs.
1313+
///
1314+
/// [`block_connected`]: Self::block_connected
1315+
pub fn transactions_confirmed<B: Deref, F: Deref, L: Deref>(
1316+
&self,
1317+
header: &BlockHeader,
1318+
txdata: &TransactionData,
1319+
height: u32,
1320+
broadcaster: B,
1321+
fee_estimator: F,
1322+
logger: L,
1323+
) -> Vec<(Txid, Vec<(u32, TxOut)>)>
1324+
where
1325+
B::Target: BroadcasterInterface,
1326+
F::Target: FeeEstimator,
1327+
L::Target: Logger,
1328+
{
1329+
self.inner.lock().unwrap().transactions_confirmed(
1330+
header, txdata, height, broadcaster, fee_estimator, logger)
1331+
}
13081332
}
13091333

13101334
impl<Signer: Sign> ChannelMonitorImpl<Signer> {
@@ -2005,6 +2029,24 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
20052029
where B::Target: BroadcasterInterface,
20062030
F::Target: FeeEstimator,
20072031
L::Target: Logger,
2032+
{
2033+
self.best_block = BestBlock::new(header.block_hash(), height);
2034+
self.transactions_confirmed(header, txdata, height, broadcaster, fee_estimator, logger)
2035+
}
2036+
2037+
fn transactions_confirmed<B: Deref, F: Deref, L: Deref>(
2038+
&mut self,
2039+
header: &BlockHeader,
2040+
txdata: &TransactionData,
2041+
height: u32,
2042+
broadcaster: B,
2043+
fee_estimator: F,
2044+
logger: L,
2045+
) -> Vec<(Txid, Vec<(u32, TxOut)>)>
2046+
where
2047+
B::Target: BroadcasterInterface,
2048+
F::Target: FeeEstimator,
2049+
L::Target: Logger,
20082050
{
20092051
let txn_matched = self.filter_block(txdata);
20102052
for tx in &txn_matched {
@@ -2127,7 +2169,6 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
21272169
}
21282170

21292171
self.onchain_tx_handler.update_claims_view(&txn_matched, claimable_outpoints, Some(height), &&*broadcaster, &&*fee_estimator, &&*logger);
2130-
self.best_block = BestBlock::new(block_hash, height);
21312172

21322173
// Determine new outputs to watch by comparing against previously known outputs to watch,
21332174
// updating the latter in the process.

0 commit comments

Comments
 (0)