]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Add ChannelMonitor::get_relevant_txids
authorJeffrey Czyz <jkczyz@gmail.com>
Mon, 5 Apr 2021 20:18:27 +0000 (13:18 -0700)
committerJeffrey Czyz <jkczyz@gmail.com>
Wed, 14 Apr 2021 19:57:05 +0000 (12:57 -0700)
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.

lightning/src/chain/channelmonitor.rs
lightning/src/ln/onchaintx.rs

index 650191dacdd8b58fee82715842b2825b23ca8aa1..cc80de6c02db713baa9d92a737ab46dced9310e5 100644 (file)
@@ -1385,6 +1385,19 @@ impl<Signer: Sign> ChannelMonitor<Signer> {
                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<Txid> {
+               let inner = self.inner.lock().unwrap();
+               let mut txids: Vec<Txid> = 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<Signer: Sign> ChannelMonitorImpl<Signer> {
index e0aa6eddd9e5ea7ccc60dc6b4f358838128ae58a..8121136c0e443edfd3ce6b8fb2075fafdda8aecd 100644 (file)
@@ -945,6 +945,16 @@ impl<ChannelSigner: Sign> OnchainTxHandler<ChannelSigner> {
                }
        }
 
+       pub(crate) fn get_relevant_txids(&self) -> Vec<Txid> {
+               let mut txids: Vec<Txid> = 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;