From: Elias Rohrer Date: Mon, 5 Feb 2024 13:47:39 +0000 (+0100) Subject: Expose `channel_id` / `counterparty_node_id` in `BumpTransaction` event X-Git-Tag: v0.0.123-beta~76^2 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=5b5c87464ab7615d31c16c7e8c8554ff48fdb3cd;p=rust-lightning Expose `channel_id` / `counterparty_node_id` in `BumpTransaction` event A client node might choose not to handle `Event::BumptTransaction` events and leave bumping / Anchor output spending to a trusted counterparty. However, `Event::BumptTransaction` currently doesn't offer any clear indication what channel and/or counterparty it is referring to. In order to allow filtering these events, we here expose the `channel_id` and `counterparty_node_id` fields. --- diff --git a/lightning/src/chain/channelmonitor.rs b/lightning/src/chain/channelmonitor.rs index e65b54f57..cadc3524e 100644 --- a/lightning/src/chain/channelmonitor.rs +++ b/lightning/src/chain/channelmonitor.rs @@ -1416,8 +1416,8 @@ impl ChannelMonitor { /// Loads the funding txo and outputs to watch into the given `chain::Filter` by repeatedly /// calling `chain::Filter::register_output` and `chain::Filter::register_tx` until all outputs /// have been registered. - pub fn load_outputs_to_watch(&self, filter: &F, logger: &L) - where + pub fn load_outputs_to_watch(&self, filter: &F, logger: &L) + where F::Target: chain::Filter, L::Target: Logger, { let lock = self.inner.lock().unwrap(); @@ -2931,12 +2931,19 @@ impl ChannelMonitorImpl { ClaimEvent::BumpCommitment { package_target_feerate_sat_per_1000_weight, commitment_tx, anchor_output_idx, } => { + let channel_id = self.channel_id; + // unwrap safety: `ClaimEvent`s are only available for Anchor channels, + // introduced with v0.0.116. counterparty_node_id is guaranteed to be `Some` + // since v0.0.110. + let counterparty_node_id = self.counterparty_node_id.unwrap(); let commitment_txid = commitment_tx.txid(); debug_assert_eq!(self.current_holder_commitment_tx.txid, commitment_txid); let pending_htlcs = self.current_holder_commitment_tx.non_dust_htlcs(); let commitment_tx_fee_satoshis = self.channel_value_satoshis - commitment_tx.output.iter().fold(0u64, |sum, output| sum + output.value); ret.push(Event::BumpTransaction(BumpTransactionEvent::ChannelClose { + channel_id, + counterparty_node_id, claim_id, package_target_feerate_sat_per_1000_weight, commitment_tx, @@ -2958,6 +2965,11 @@ impl ChannelMonitorImpl { ClaimEvent::BumpHTLC { target_feerate_sat_per_1000_weight, htlcs, tx_lock_time, } => { + let channel_id = self.channel_id; + // unwrap safety: `ClaimEvent`s are only available for Anchor channels, + // introduced with v0.0.116. counterparty_node_id is guaranteed to be `Some` + // since v0.0.110. + let counterparty_node_id = self.counterparty_node_id.unwrap(); let mut htlc_descriptors = Vec::with_capacity(htlcs.len()); for htlc in htlcs { htlc_descriptors.push(HTLCDescriptor { @@ -2978,6 +2990,8 @@ impl ChannelMonitorImpl { }); } ret.push(Event::BumpTransaction(BumpTransactionEvent::HTLCResolution { + channel_id, + counterparty_node_id, claim_id, target_feerate_sat_per_1000_weight, htlc_descriptors, diff --git a/lightning/src/events/bump_transaction.rs b/lightning/src/events/bump_transaction.rs index 1b019ba34..cb011b79a 100644 --- a/lightning/src/events/bump_transaction.rs +++ b/lightning/src/events/bump_transaction.rs @@ -18,6 +18,7 @@ use crate::chain::chaininterface::{BroadcasterInterface, fee_for_weight}; use crate::chain::ClaimId; use crate::io_extras::sink; use crate::ln::channel::ANCHOR_OUTPUT_VALUE_SATOSHI; +use crate::ln::ChannelId; use crate::ln::chan_utils; use crate::ln::chan_utils::{ ANCHOR_INPUT_WITNESS_WEIGHT, HTLC_SUCCESS_INPUT_ANCHOR_WITNESS_WEIGHT, @@ -37,7 +38,7 @@ use bitcoin::blockdata::locktime::absolute::LockTime; use bitcoin::consensus::Encodable; use bitcoin::psbt::PartiallySignedTransaction; use bitcoin::secp256k1; -use bitcoin::secp256k1::Secp256k1; +use bitcoin::secp256k1::{PublicKey, Secp256k1}; use bitcoin::secp256k1::ecdsa::Signature; const EMPTY_SCRIPT_SIG_WEIGHT: u64 = 1 /* empty script_sig */ * WITNESS_SCALE_FACTOR as u64; @@ -147,6 +148,10 @@ pub enum BumpTransactionEvent { /// [`EcdsaChannelSigner::sign_holder_anchor_input`]: crate::sign::ecdsa::EcdsaChannelSigner::sign_holder_anchor_input /// [`build_anchor_input_witness`]: crate::ln::chan_utils::build_anchor_input_witness ChannelClose { + /// The `channel_id` of the channel which has been closed. + channel_id: ChannelId, + /// Counterparty in the closed channel. + counterparty_node_id: PublicKey, /// The unique identifier for the claim of the anchor output in the commitment transaction. /// /// The identifier must map to the set of external UTXOs assigned to the claim, such that @@ -200,6 +205,10 @@ pub enum BumpTransactionEvent { /// [`EcdsaChannelSigner`]: crate::sign::ecdsa::EcdsaChannelSigner /// [`EcdsaChannelSigner::sign_holder_htlc_transaction`]: crate::sign::ecdsa::EcdsaChannelSigner::sign_holder_htlc_transaction HTLCResolution { + /// The `channel_id` of the channel which has been closed. + channel_id: ChannelId, + /// Counterparty in the closed channel. + counterparty_node_id: PublicKey, /// The unique identifier for the claim of the HTLCs in the confirmed commitment /// transaction. /// @@ -797,7 +806,7 @@ where } } BumpTransactionEvent::HTLCResolution { - claim_id, target_feerate_sat_per_1000_weight, htlc_descriptors, tx_lock_time, + claim_id, target_feerate_sat_per_1000_weight, htlc_descriptors, tx_lock_time, .. } => { log_info!(self.logger, "Handling HTLC bump (claim_id = {}, htlcs_to_claim = {})", log_bytes!(claim_id.0), log_iter!(htlc_descriptors.iter().map(|d| d.outpoint())));