From 23e233ba257c27b14d0d6167f1d87d9c1bf5e344 Mon Sep 17 00:00:00 2001 From: Wilmer Paulino Date: Mon, 6 Mar 2023 17:01:21 -0800 Subject: [PATCH] Expose HTLC transaction locktime in BumpTransactionEvent::HTLCResolution While users could easily figure it out based on the set of HTLC descriptors included within, we already track it within the `OnchainTxHandler`, so we might as well expose it to users as a nice-to-have. It's also yet another thing they must get right to ensure their HTLC transaction broadcasts are valid. --- lightning/src/chain/channelmonitor.rs | 3 ++- lightning/src/chain/onchaintx.rs | 4 ++++ lightning/src/events/bump_transaction.rs | 2 ++ lightning/src/ln/monitor_tests.rs | 11 ++++------- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/lightning/src/chain/channelmonitor.rs b/lightning/src/chain/channelmonitor.rs index 7a69be7dc..9044eec63 100644 --- a/lightning/src/chain/channelmonitor.rs +++ b/lightning/src/chain/channelmonitor.rs @@ -2426,7 +2426,7 @@ impl ChannelMonitorImpl { })); }, ClaimEvent::BumpHTLC { - target_feerate_sat_per_1000_weight, htlcs, + target_feerate_sat_per_1000_weight, htlcs, tx_lock_time, } => { let mut htlc_descriptors = Vec::with_capacity(htlcs.len()); for htlc in htlcs { @@ -2444,6 +2444,7 @@ impl ChannelMonitorImpl { ret.push(Event::BumpTransaction(BumpTransactionEvent::HTLCResolution { target_feerate_sat_per_1000_weight, htlc_descriptors, + tx_lock_time, })); } } diff --git a/lightning/src/chain/onchaintx.rs b/lightning/src/chain/onchaintx.rs index c95aec977..f690d3664 100644 --- a/lightning/src/chain/onchaintx.rs +++ b/lightning/src/chain/onchaintx.rs @@ -12,6 +12,8 @@ //! OnchainTxHandler objects are fully-part of ChannelMonitor and encapsulates all //! building, tracking, bumping and notifications functions. +#[cfg(anchors)] +use bitcoin::PackedLockTime; use bitcoin::blockdata::transaction::Transaction; use bitcoin::blockdata::transaction::OutPoint as BitcoinOutPoint; use bitcoin::blockdata::script::Script; @@ -201,6 +203,7 @@ pub(crate) enum ClaimEvent { BumpHTLC { target_feerate_sat_per_1000_weight: u32, htlcs: Vec, + tx_lock_time: PackedLockTime, }, } @@ -544,6 +547,7 @@ impl OnchainTxHandler OnchainClaim::Event(ClaimEvent::BumpHTLC { target_feerate_sat_per_1000_weight, htlcs, + tx_lock_time: PackedLockTime(cached_request.package_locktime(cur_height)), }), )); } else { diff --git a/lightning/src/events/bump_transaction.rs b/lightning/src/events/bump_transaction.rs index f56a99df8..6a3360a4d 100644 --- a/lightning/src/events/bump_transaction.rs +++ b/lightning/src/events/bump_transaction.rs @@ -227,5 +227,7 @@ pub enum BumpTransactionEvent { /// The set of pending HTLCs on the confirmed commitment that need to be claimed, preferably /// by the same transaction. htlc_descriptors: Vec, + /// The locktime required for the resulting HTLC transaction. + tx_lock_time: PackedLockTime, }, } diff --git a/lightning/src/ln/monitor_tests.rs b/lightning/src/ln/monitor_tests.rs index f4dedd89e..15d0167ad 100644 --- a/lightning/src/ln/monitor_tests.rs +++ b/lightning/src/ln/monitor_tests.rs @@ -1775,7 +1775,7 @@ fn test_yield_anchors_events() { let mut htlc_txs = Vec::with_capacity(2); for event in holder_events { match event { - Event::BumpTransaction(BumpTransactionEvent::HTLCResolution { htlc_descriptors, .. }) => { + Event::BumpTransaction(BumpTransactionEvent::HTLCResolution { htlc_descriptors, tx_lock_time, .. }) => { assert_eq!(htlc_descriptors.len(), 1); let htlc_descriptor = &htlc_descriptors[0]; let signer = nodes[0].keys_manager.derive_channel_keys( @@ -1784,11 +1784,7 @@ fn test_yield_anchors_events() { let per_commitment_point = signer.get_per_commitment_point(htlc_descriptor.per_commitment_number, &secp); let mut htlc_tx = Transaction { version: 2, - lock_time: if htlc_descriptor.htlc.offered { - PackedLockTime(htlc_descriptor.htlc.cltv_expiry) - } else { - PackedLockTime::ZERO - }, + lock_time: tx_lock_time, input: vec![ htlc_descriptor.unsigned_tx_input(), // HTLC input TxIn { ..Default::default() } // Fee input @@ -2064,7 +2060,7 @@ fn test_anchors_aggregated_revoked_htlc_tx() { }; let mut descriptors = Vec::with_capacity(4); for event in events { - if let Event::BumpTransaction(BumpTransactionEvent::HTLCResolution { mut htlc_descriptors, .. }) = event { + if let Event::BumpTransaction(BumpTransactionEvent::HTLCResolution { mut htlc_descriptors, tx_lock_time, .. }) = event { assert_eq!(htlc_descriptors.len(), 2); for htlc_descriptor in &htlc_descriptors { assert!(!htlc_descriptor.htlc.offered); @@ -2076,6 +2072,7 @@ fn test_anchors_aggregated_revoked_htlc_tx() { htlc_tx.output.push(htlc_descriptor.tx_output(&per_commitment_point, &secp)); } descriptors.append(&mut htlc_descriptors); + htlc_tx.lock_time = tx_lock_time; } else { panic!("Unexpected event"); } -- 2.39.5