Skip to content

Commit 7fa50a7

Browse files
committed
Add ChannelMonitor::transaction_unconfirmed
Define an Electrum-friendly interface for ChannelMonitor where transactions are unconfirmed independently from updating the latest block.
1 parent 30c4ede commit 7fa50a7

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,6 +1322,22 @@ impl<Signer: Sign> ChannelMonitor<Signer> {
13221322
header, txdata, height, broadcaster, fee_estimator, &logger)
13231323
}
13241324

1325+
/// TODO: Write docs
1326+
pub fn transaction_unconfirmed<B: Deref, F: Deref, L: Deref>(
1327+
&self,
1328+
txid: &Txid,
1329+
broadcaster: B,
1330+
fee_estimator: F,
1331+
logger: L,
1332+
) where
1333+
B::Target: BroadcasterInterface,
1334+
F::Target: FeeEstimator,
1335+
L::Target: Logger,
1336+
{
1337+
self.inner.lock().unwrap().transaction_unconfirmed(
1338+
txid, broadcaster, fee_estimator, logger);
1339+
}
1340+
13251341
/// Updates the monitor with the current best chain tip.
13261342
///
13271343
/// TODO: Expand docs.
@@ -2192,6 +2208,21 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
21922208
self.last_block_hash = header.prev_blockhash;
21932209
}
21942210

2211+
fn transaction_unconfirmed<B: Deref, F: Deref, L: Deref>(
2212+
&mut self,
2213+
txid: &Txid,
2214+
broadcaster: B,
2215+
fee_estimator: F,
2216+
logger: L,
2217+
) where
2218+
B::Target: BroadcasterInterface,
2219+
F::Target: FeeEstimator,
2220+
L::Target: Logger,
2221+
{
2222+
self.onchain_events_waiting_threshold_conf.retain(|ref entry| entry.txid != *txid);
2223+
self.onchain_tx_handler.transaction_unconfirmed(txid, broadcaster, fee_estimator, logger);
2224+
}
2225+
21952226
/// Filters a block's `txdata` for transactions spending watched outputs or for any child
21962227
/// transactions thereof.
21972228
fn filter_block<'a>(&self, txdata: &TransactionData<'a>) -> Vec<&'a Transaction> {

lightning/src/ln/onchaintx.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -866,6 +866,30 @@ impl<ChannelSigner: Sign> OnchainTxHandler<ChannelSigner> {
866866
}
867867
}
868868

869+
pub(crate) fn transaction_unconfirmed<B: Deref, F: Deref, L: Deref>(
870+
&mut self,
871+
txid: &Txid,
872+
broadcaster: B,
873+
fee_estimator: F,
874+
logger: L,
875+
) where
876+
B::Target: BroadcasterInterface,
877+
F::Target: FeeEstimator,
878+
L::Target: Logger,
879+
{
880+
let mut height = None;
881+
for entry in self.onchain_events_waiting_threshold_conf.iter() {
882+
if entry.txid == *txid {
883+
height = Some(entry.height);
884+
break;
885+
}
886+
}
887+
888+
if let Some(height) = height {
889+
self.block_disconnected(height, broadcaster, fee_estimator, logger);
890+
}
891+
}
892+
869893
pub(crate) fn block_disconnected<B: Deref, F: Deref, L: Deref>(&mut self, height: u32, broadcaster: B, fee_estimator: F, logger: L)
870894
where B::Target: BroadcasterInterface,
871895
F::Target: FeeEstimator,

0 commit comments

Comments
 (0)