Skip to content

Commit a9d73c2

Browse files
authored
Merge pull request #2873 from tnull/2024-02-expose-channel-details-in-bte
Expose `channel_id` / `counterparty_node_id` in `BumpTransaction` event
2 parents 36429e8 + 5b5c874 commit a9d73c2

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

lightning/src/chain/channelmonitor.rs

+16-2
Original file line numberDiff line numberDiff line change
@@ -1416,8 +1416,8 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitor<Signer> {
14161416
/// Loads the funding txo and outputs to watch into the given `chain::Filter` by repeatedly
14171417
/// calling `chain::Filter::register_output` and `chain::Filter::register_tx` until all outputs
14181418
/// have been registered.
1419-
pub fn load_outputs_to_watch<F: Deref, L: Deref>(&self, filter: &F, logger: &L)
1420-
where
1419+
pub fn load_outputs_to_watch<F: Deref, L: Deref>(&self, filter: &F, logger: &L)
1420+
where
14211421
F::Target: chain::Filter, L::Target: Logger,
14221422
{
14231423
let lock = self.inner.lock().unwrap();
@@ -2931,12 +2931,19 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
29312931
ClaimEvent::BumpCommitment {
29322932
package_target_feerate_sat_per_1000_weight, commitment_tx, anchor_output_idx,
29332933
} => {
2934+
let channel_id = self.channel_id;
2935+
// unwrap safety: `ClaimEvent`s are only available for Anchor channels,
2936+
// introduced with v0.0.116. counterparty_node_id is guaranteed to be `Some`
2937+
// since v0.0.110.
2938+
let counterparty_node_id = self.counterparty_node_id.unwrap();
29342939
let commitment_txid = commitment_tx.txid();
29352940
debug_assert_eq!(self.current_holder_commitment_tx.txid, commitment_txid);
29362941
let pending_htlcs = self.current_holder_commitment_tx.non_dust_htlcs();
29372942
let commitment_tx_fee_satoshis = self.channel_value_satoshis -
29382943
commitment_tx.output.iter().fold(0u64, |sum, output| sum + output.value);
29392944
ret.push(Event::BumpTransaction(BumpTransactionEvent::ChannelClose {
2945+
channel_id,
2946+
counterparty_node_id,
29402947
claim_id,
29412948
package_target_feerate_sat_per_1000_weight,
29422949
commitment_tx,
@@ -2958,6 +2965,11 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
29582965
ClaimEvent::BumpHTLC {
29592966
target_feerate_sat_per_1000_weight, htlcs, tx_lock_time,
29602967
} => {
2968+
let channel_id = self.channel_id;
2969+
// unwrap safety: `ClaimEvent`s are only available for Anchor channels,
2970+
// introduced with v0.0.116. counterparty_node_id is guaranteed to be `Some`
2971+
// since v0.0.110.
2972+
let counterparty_node_id = self.counterparty_node_id.unwrap();
29612973
let mut htlc_descriptors = Vec::with_capacity(htlcs.len());
29622974
for htlc in htlcs {
29632975
htlc_descriptors.push(HTLCDescriptor {
@@ -2978,6 +2990,8 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
29782990
});
29792991
}
29802992
ret.push(Event::BumpTransaction(BumpTransactionEvent::HTLCResolution {
2993+
channel_id,
2994+
counterparty_node_id,
29812995
claim_id,
29822996
target_feerate_sat_per_1000_weight,
29832997
htlc_descriptors,

lightning/src/events/bump_transaction.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use crate::chain::chaininterface::{BroadcasterInterface, fee_for_weight};
1818
use crate::chain::ClaimId;
1919
use crate::io_extras::sink;
2020
use crate::ln::channel::ANCHOR_OUTPUT_VALUE_SATOSHI;
21+
use crate::ln::ChannelId;
2122
use crate::ln::chan_utils;
2223
use crate::ln::chan_utils::{
2324
ANCHOR_INPUT_WITNESS_WEIGHT, HTLC_SUCCESS_INPUT_ANCHOR_WITNESS_WEIGHT,
@@ -37,7 +38,7 @@ use bitcoin::blockdata::locktime::absolute::LockTime;
3738
use bitcoin::consensus::Encodable;
3839
use bitcoin::psbt::PartiallySignedTransaction;
3940
use bitcoin::secp256k1;
40-
use bitcoin::secp256k1::Secp256k1;
41+
use bitcoin::secp256k1::{PublicKey, Secp256k1};
4142
use bitcoin::secp256k1::ecdsa::Signature;
4243

4344
const EMPTY_SCRIPT_SIG_WEIGHT: u64 = 1 /* empty script_sig */ * WITNESS_SCALE_FACTOR as u64;
@@ -147,6 +148,10 @@ pub enum BumpTransactionEvent {
147148
/// [`EcdsaChannelSigner::sign_holder_anchor_input`]: crate::sign::ecdsa::EcdsaChannelSigner::sign_holder_anchor_input
148149
/// [`build_anchor_input_witness`]: crate::ln::chan_utils::build_anchor_input_witness
149150
ChannelClose {
151+
/// The `channel_id` of the channel which has been closed.
152+
channel_id: ChannelId,
153+
/// Counterparty in the closed channel.
154+
counterparty_node_id: PublicKey,
150155
/// The unique identifier for the claim of the anchor output in the commitment transaction.
151156
///
152157
/// The identifier must map to the set of external UTXOs assigned to the claim, such that
@@ -200,6 +205,10 @@ pub enum BumpTransactionEvent {
200205
/// [`EcdsaChannelSigner`]: crate::sign::ecdsa::EcdsaChannelSigner
201206
/// [`EcdsaChannelSigner::sign_holder_htlc_transaction`]: crate::sign::ecdsa::EcdsaChannelSigner::sign_holder_htlc_transaction
202207
HTLCResolution {
208+
/// The `channel_id` of the channel which has been closed.
209+
channel_id: ChannelId,
210+
/// Counterparty in the closed channel.
211+
counterparty_node_id: PublicKey,
203212
/// The unique identifier for the claim of the HTLCs in the confirmed commitment
204213
/// transaction.
205214
///
@@ -797,7 +806,7 @@ where
797806
}
798807
}
799808
BumpTransactionEvent::HTLCResolution {
800-
claim_id, target_feerate_sat_per_1000_weight, htlc_descriptors, tx_lock_time,
809+
claim_id, target_feerate_sat_per_1000_weight, htlc_descriptors, tx_lock_time, ..
801810
} => {
802811
log_info!(self.logger, "Handling HTLC bump (claim_id = {}, htlcs_to_claim = {})",
803812
log_bytes!(claim_id.0), log_iter!(htlc_descriptors.iter().map(|d| d.outpoint())));

0 commit comments

Comments
 (0)