Skip to content

Commit

Permalink
Merge pull request #2873 from tnull/2024-02-expose-channel-details-in…
Browse files Browse the repository at this point in the history
…-bte

Expose `channel_id` / `counterparty_node_id` in `BumpTransaction` event
  • Loading branch information
TheBlueMatt authored Feb 7, 2024
2 parents 36429e8 + 5b5c874 commit a9d73c2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
18 changes: 16 additions & 2 deletions lightning/src/chain/channelmonitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1416,8 +1416,8 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitor<Signer> {
/// 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<F: Deref, L: Deref>(&self, filter: &F, logger: &L)
where
pub fn load_outputs_to_watch<F: Deref, L: Deref>(&self, filter: &F, logger: &L)
where
F::Target: chain::Filter, L::Target: Logger,
{
let lock = self.inner.lock().unwrap();
Expand Down Expand Up @@ -2931,12 +2931,19 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
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,
Expand All @@ -2958,6 +2965,11 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
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 {
Expand All @@ -2978,6 +2990,8 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
});
}
ret.push(Event::BumpTransaction(BumpTransactionEvent::HTLCResolution {
channel_id,
counterparty_node_id,
claim_id,
target_feerate_sat_per_1000_weight,
htlc_descriptors,
Expand Down
13 changes: 11 additions & 2 deletions lightning/src/events/bump_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
///
Expand Down Expand Up @@ -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())));
Expand Down

0 comments on commit a9d73c2

Please sign in to comment.