From b1b36661ee21713873f07fcfa8b1bce5fdc81506 Mon Sep 17 00:00:00 2001 From: Elias Rohrer Date: Thu, 17 Nov 2022 11:31:35 +0100 Subject: [PATCH] Expose `confirmations` via `ChannelDetails` We expose the current number of confirmations in `ChannelDetails`. --- fuzz/src/router.rs | 1 + lightning/src/ln/channel.rs | 10 ++++++++++ lightning/src/ln/channelmanager.rs | 9 +++++++++ lightning/src/ln/reorg_tests.rs | 11 +++++++++++ lightning/src/routing/router.rs | 2 ++ 5 files changed, 33 insertions(+) diff --git a/fuzz/src/router.rs b/fuzz/src/router.rs index a5cd91f28..761f7bddc 100644 --- a/fuzz/src/router.rs +++ b/fuzz/src/router.rs @@ -225,6 +225,7 @@ pub fn do_test(data: &[u8], out: Out) { user_channel_id: 0, inbound_capacity_msat: 0, unspendable_punishment_reserve: None, confirmations_required: None, + confirmations: None, force_close_spend_delay: None, is_outbound: true, is_channel_ready: true, is_usable: true, is_public: true, diff --git a/lightning/src/ln/channel.rs b/lightning/src/ln/channel.rs index 70db91baf..5cc4f4a36 100644 --- a/lightning/src/ln/channel.rs +++ b/lightning/src/ln/channel.rs @@ -4495,6 +4495,16 @@ impl Channel { self.funding_tx_confirmed_in } + /// Returns the current number of confirmations on the funding transaction. + pub fn get_funding_tx_confirmations(&self, height: u32) -> u32 { + if self.funding_tx_confirmation_height == 0 { + // We either haven't seen any confirmation yet, or observed a reorg. + return 0; + } + + height.checked_sub(self.funding_tx_confirmation_height).map_or(0, |c| c + 1) + } + fn get_holder_selected_contest_delay(&self) -> u16 { self.channel_transaction_parameters.holder_selected_contest_delay } diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index c6bb961d4..7be667b92 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -1146,6 +1146,10 @@ pub struct ChannelDetails { /// [`ChannelHandshakeConfig::minimum_depth`]: crate::util::config::ChannelHandshakeConfig::minimum_depth /// [`ChannelHandshakeLimits::max_minimum_depth`]: crate::util::config::ChannelHandshakeLimits::max_minimum_depth pub confirmations_required: Option, + /// The current number of confirmations on the funding transaction. + /// + /// This value will be `None` for objects serialized with LDK versions prior to 0.0.113. + pub confirmations: Option, /// The number of blocks (after our commitment transaction confirms) that we will need to wait /// until we can claim our funds after we force-close the channel. During this time our /// counterparty is allowed to punish us if we broadcasted a stale state. If our counterparty @@ -1694,6 +1698,7 @@ impl ChannelManager ChannelManager