From: Jeffrey Czyz Date: Mon, 5 Apr 2021 20:18:27 +0000 (-0700) Subject: Add ChannelMonitor::get_relevant_txids X-Git-Tag: v0.0.14~24^2~7 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=c57bf73a020d546c9b31508ec0de5939e4ebfd44;p=rust-lightning Add ChannelMonitor::get_relevant_txids Define an Electrum-friendly interface for ChannelMonitor where txids of relevant transactions can be obtained. For any of these transactions that are re-orged out of the chain, users must call transaction_unconfirmed. --- diff --git a/lightning/src/chain/channelmonitor.rs b/lightning/src/chain/channelmonitor.rs index 650191dac..cc80de6c0 100644 --- a/lightning/src/chain/channelmonitor.rs +++ b/lightning/src/chain/channelmonitor.rs @@ -1385,6 +1385,19 @@ impl ChannelMonitor { self.inner.lock().unwrap().update_best_block( header, height, broadcaster, fee_estimator, logger) } + + /// Returns the set of txids that should be monitored for re-organization out of the chain. + pub fn get_relevant_txids(&self) -> Vec { + let inner = self.inner.lock().unwrap(); + let mut txids: Vec = inner.onchain_events_waiting_threshold_conf + .iter() + .map(|entry| entry.txid) + .chain(inner.onchain_tx_handler.get_relevant_txids().into_iter()) + .collect(); + txids.sort_unstable(); + txids.dedup(); + txids + } } impl ChannelMonitorImpl { diff --git a/lightning/src/ln/onchaintx.rs b/lightning/src/ln/onchaintx.rs index e0aa6eddd..8121136c0 100644 --- a/lightning/src/ln/onchaintx.rs +++ b/lightning/src/ln/onchaintx.rs @@ -945,6 +945,16 @@ impl OnchainTxHandler { } } + pub(crate) fn get_relevant_txids(&self) -> Vec { + let mut txids: Vec = self.onchain_events_waiting_threshold_conf + .iter() + .map(|entry| entry.txid) + .collect(); + txids.sort_unstable(); + txids.dedup(); + txids + } + pub(crate) fn provide_latest_holder_tx(&mut self, tx: HolderCommitmentTransaction) { self.prev_holder_commitment = Some(replace(&mut self.holder_commitment, tx)); self.holder_htlc_sigs = None;