Skip to content

Commit 13a3340

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 2db1f1f commit 13a3340

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
@@ -1303,6 +1303,30 @@ impl<Signer: Sign> ChannelMonitor<Signer> {
13031303
self.inner.lock().unwrap().block_disconnected(
13041304
header, height, broadcaster, fee_estimator, logger)
13051305
}
1306+
1307+
/// Processes transactions from a block with the given header and height, returning new outputs
1308+
/// to watch. See [`block_connected`] for details.
1309+
///
1310+
/// TODO: Expand docs.
1311+
///
1312+
/// [`block_connected`]: Self::block_connected
1313+
pub fn transactions_confirmed<B: Deref, F: Deref, L: Deref>(
1314+
&self,
1315+
header: &BlockHeader,
1316+
txdata: &TransactionData,
1317+
height: u32,
1318+
broadcaster: B,
1319+
fee_estimator: F,
1320+
logger: L,
1321+
) -> Vec<(Txid, Vec<(u32, TxOut)>)>
1322+
where
1323+
B::Target: BroadcasterInterface,
1324+
F::Target: FeeEstimator,
1325+
L::Target: Logger,
1326+
{
1327+
self.inner.lock().unwrap().transactions_confirmed(
1328+
header, txdata, height, broadcaster, fee_estimator, logger)
1329+
}
13061330
}
13071331

13081332
impl<Signer: Sign> ChannelMonitorImpl<Signer> {
@@ -2003,6 +2027,24 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
20032027
where B::Target: BroadcasterInterface,
20042028
F::Target: FeeEstimator,
20052029
L::Target: Logger,
2030+
{
2031+
self.best_block = BestBlock::new(header.block_hash(), height);
2032+
self.transactions_confirmed(header, txdata, height, broadcaster, fee_estimator, logger)
2033+
}
2034+
2035+
fn transactions_confirmed<B: Deref, F: Deref, L: Deref>(
2036+
&mut self,
2037+
header: &BlockHeader,
2038+
txdata: &TransactionData,
2039+
height: u32,
2040+
broadcaster: B,
2041+
fee_estimator: F,
2042+
logger: L,
2043+
) -> Vec<(Txid, Vec<(u32, TxOut)>)>
2044+
where
2045+
B::Target: BroadcasterInterface,
2046+
F::Target: FeeEstimator,
2047+
L::Target: Logger,
20062048
{
20072049
let txn_matched = self.filter_block(txdata);
20082050
for tx in &txn_matched {
@@ -2135,7 +2177,6 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
21352177
}
21362178

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

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

0 commit comments

Comments
 (0)