From c57bf73a020d546c9b31508ec0de5939e4ebfd44 Mon Sep 17 00:00:00 2001 From: Jeffrey Czyz Date: Mon, 5 Apr 2021 13:18:27 -0700 Subject: [PATCH] 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. --- lightning/src/chain/channelmonitor.rs | 13 +++++++++++++ lightning/src/ln/onchaintx.rs | 10 ++++++++++ 2 files changed, 23 insertions(+) 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; -- 2.39.5