Skip to content

Commit 23e233b

Browse files
committed
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.
1 parent 68122bd commit 23e233b

File tree

4 files changed

+12
-8
lines changed

4 files changed

+12
-8
lines changed

lightning/src/chain/channelmonitor.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -2426,7 +2426,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
24262426
}));
24272427
},
24282428
ClaimEvent::BumpHTLC {
2429-
target_feerate_sat_per_1000_weight, htlcs,
2429+
target_feerate_sat_per_1000_weight, htlcs, tx_lock_time,
24302430
} => {
24312431
let mut htlc_descriptors = Vec::with_capacity(htlcs.len());
24322432
for htlc in htlcs {
@@ -2444,6 +2444,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
24442444
ret.push(Event::BumpTransaction(BumpTransactionEvent::HTLCResolution {
24452445
target_feerate_sat_per_1000_weight,
24462446
htlc_descriptors,
2447+
tx_lock_time,
24472448
}));
24482449
}
24492450
}

lightning/src/chain/onchaintx.rs

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
//! OnchainTxHandler objects are fully-part of ChannelMonitor and encapsulates all
1313
//! building, tracking, bumping and notifications functions.
1414
15+
#[cfg(anchors)]
16+
use bitcoin::PackedLockTime;
1517
use bitcoin::blockdata::transaction::Transaction;
1618
use bitcoin::blockdata::transaction::OutPoint as BitcoinOutPoint;
1719
use bitcoin::blockdata::script::Script;
@@ -201,6 +203,7 @@ pub(crate) enum ClaimEvent {
201203
BumpHTLC {
202204
target_feerate_sat_per_1000_weight: u32,
203205
htlcs: Vec<ExternalHTLCClaim>,
206+
tx_lock_time: PackedLockTime,
204207
},
205208
}
206209

@@ -544,6 +547,7 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
544547
OnchainClaim::Event(ClaimEvent::BumpHTLC {
545548
target_feerate_sat_per_1000_weight,
546549
htlcs,
550+
tx_lock_time: PackedLockTime(cached_request.package_locktime(cur_height)),
547551
}),
548552
));
549553
} else {

lightning/src/events/bump_transaction.rs

+2
Original file line numberDiff line numberDiff line change
@@ -227,5 +227,7 @@ pub enum BumpTransactionEvent {
227227
/// The set of pending HTLCs on the confirmed commitment that need to be claimed, preferably
228228
/// by the same transaction.
229229
htlc_descriptors: Vec<HTLCDescriptor>,
230+
/// The locktime required for the resulting HTLC transaction.
231+
tx_lock_time: PackedLockTime,
230232
},
231233
}

lightning/src/ln/monitor_tests.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -1775,7 +1775,7 @@ fn test_yield_anchors_events() {
17751775
let mut htlc_txs = Vec::with_capacity(2);
17761776
for event in holder_events {
17771777
match event {
1778-
Event::BumpTransaction(BumpTransactionEvent::HTLCResolution { htlc_descriptors, .. }) => {
1778+
Event::BumpTransaction(BumpTransactionEvent::HTLCResolution { htlc_descriptors, tx_lock_time, .. }) => {
17791779
assert_eq!(htlc_descriptors.len(), 1);
17801780
let htlc_descriptor = &htlc_descriptors[0];
17811781
let signer = nodes[0].keys_manager.derive_channel_keys(
@@ -1784,11 +1784,7 @@ fn test_yield_anchors_events() {
17841784
let per_commitment_point = signer.get_per_commitment_point(htlc_descriptor.per_commitment_number, &secp);
17851785
let mut htlc_tx = Transaction {
17861786
version: 2,
1787-
lock_time: if htlc_descriptor.htlc.offered {
1788-
PackedLockTime(htlc_descriptor.htlc.cltv_expiry)
1789-
} else {
1790-
PackedLockTime::ZERO
1791-
},
1787+
lock_time: tx_lock_time,
17921788
input: vec![
17931789
htlc_descriptor.unsigned_tx_input(), // HTLC input
17941790
TxIn { ..Default::default() } // Fee input
@@ -2064,7 +2060,7 @@ fn test_anchors_aggregated_revoked_htlc_tx() {
20642060
};
20652061
let mut descriptors = Vec::with_capacity(4);
20662062
for event in events {
2067-
if let Event::BumpTransaction(BumpTransactionEvent::HTLCResolution { mut htlc_descriptors, .. }) = event {
2063+
if let Event::BumpTransaction(BumpTransactionEvent::HTLCResolution { mut htlc_descriptors, tx_lock_time, .. }) = event {
20682064
assert_eq!(htlc_descriptors.len(), 2);
20692065
for htlc_descriptor in &htlc_descriptors {
20702066
assert!(!htlc_descriptor.htlc.offered);
@@ -2076,6 +2072,7 @@ fn test_anchors_aggregated_revoked_htlc_tx() {
20762072
htlc_tx.output.push(htlc_descriptor.tx_output(&per_commitment_point, &secp));
20772073
}
20782074
descriptors.append(&mut htlc_descriptors);
2075+
htlc_tx.lock_time = tx_lock_time;
20792076
} else {
20802077
panic!("Unexpected event");
20812078
}

0 commit comments

Comments
 (0)