Expose HTLC transaction locktime in BumpTransactionEvent::HTLCResolution
authorWilmer Paulino <wilmer@wilmerpaulino.com>
Tue, 7 Mar 2023 01:01:21 +0000 (17:01 -0800)
committerWilmer Paulino <wilmer@wilmerpaulino.com>
Tue, 28 Mar 2023 19:42:25 +0000 (12:42 -0700)
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
lightning/src/chain/onchaintx.rs
lightning/src/events/bump_transaction.rs
lightning/src/ln/monitor_tests.rs

index 7a69be7dcdf5f7daad8ae6425c076403b1aea3ab..9044eec63e4a3c5b4a23700647c571d38f51cb4e 100644 (file)
@@ -2426,7 +2426,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
                                        }));
                                },
                                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<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
                                        ret.push(Event::BumpTransaction(BumpTransactionEvent::HTLCResolution {
                                                target_feerate_sat_per_1000_weight,
                                                htlc_descriptors,
+                                               tx_lock_time,
                                        }));
                                }
                        }
index c95aec9774a09481554ba5e89f6c1f29a97570c1..f690d3664273b94e8ee9fe8d6d4c9f16d44ece0e 100644 (file)
@@ -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<ExternalHTLCClaim>,
+               tx_lock_time: PackedLockTime,
        },
 }
 
@@ -544,6 +547,7 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
                                                        OnchainClaim::Event(ClaimEvent::BumpHTLC {
                                                                target_feerate_sat_per_1000_weight,
                                                                htlcs,
+                                                               tx_lock_time: PackedLockTime(cached_request.package_locktime(cur_height)),
                                                        }),
                                                ));
                                        } else {
index f56a99df8f280b955f43b9ee5561718cbf492dda..6a3360a4d7eef76bcbfa8a01ff9491b03bd92d04 100644 (file)
@@ -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<HTLCDescriptor>,
+               /// The locktime required for the resulting HTLC transaction.
+               tx_lock_time: PackedLockTime,
        },
 }
index f4dedd89eb907dcf557161737c054cb78f8f75d1..15d0167ad46c6eabf6a3a9d0413a97538fe0df00 100644 (file)
@@ -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");
                        }