Skip to content

Commit 97e4344

Browse files
committed
Fix off-by-one finalized transaction locktime
While these transactions were still valid, we incorrectly assumed that they would propagate with a locktime of `current_height + 1`, when in reality, only those with a locktime strictly lower than the next height in the chain are allowed to enter the mempool.
1 parent e904d68 commit 97e4344

10 files changed

+46
-43
lines changed

lightning/src/chain/onchaintx.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -748,8 +748,8 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
748748
preprocessed_requests.push(req);
749749
}
750750

751-
// Claim everything up to and including cur_height + 1
752-
let remaining_locked_packages = self.locktimed_packages.split_off(&(cur_height + 2));
751+
// Claim everything up to and including `cur_height`
752+
let remaining_locked_packages = self.locktimed_packages.split_off(&(cur_height + 1));
753753
for (pop_height, mut entry) in self.locktimed_packages.iter_mut() {
754754
log_trace!(logger, "Restoring delayed claim of package(s) at their timelock at {}.", pop_height);
755755
preprocessed_requests.append(&mut entry);

lightning/src/chain/package.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -460,13 +460,13 @@ impl PackageSolvingData {
460460
}
461461
}
462462
fn absolute_tx_timelock(&self, current_height: u32) -> u32 {
463-
// We use `current_height + 1` as our default locktime to discourage fee sniping and because
463+
// We use `current_height` as our default locktime to discourage fee sniping and because
464464
// transactions with it always propagate.
465465
let absolute_timelock = match self {
466-
PackageSolvingData::RevokedOutput(_) => current_height + 1,
467-
PackageSolvingData::RevokedHTLCOutput(_) => current_height + 1,
468-
PackageSolvingData::CounterpartyOfferedHTLCOutput(_) => current_height + 1,
469-
PackageSolvingData::CounterpartyReceivedHTLCOutput(ref outp) => cmp::max(outp.htlc.cltv_expiry, current_height + 1),
466+
PackageSolvingData::RevokedOutput(_) => current_height,
467+
PackageSolvingData::RevokedHTLCOutput(_) => current_height,
468+
PackageSolvingData::CounterpartyOfferedHTLCOutput(_) => current_height,
469+
PackageSolvingData::CounterpartyReceivedHTLCOutput(ref outp) => cmp::max(outp.htlc.cltv_expiry, current_height),
470470
// HTLC timeout/success transactions rely on a fixed timelock due to the counterparty's
471471
// signature.
472472
PackageSolvingData::HolderHTLCOutput(ref outp) => {
@@ -475,7 +475,7 @@ impl PackageSolvingData {
475475
}
476476
outp.cltv_expiry
477477
},
478-
PackageSolvingData::HolderFundingOutput(_) => current_height + 1,
478+
PackageSolvingData::HolderFundingOutput(_) => current_height,
479479
};
480480
absolute_timelock
481481
}

lightning/src/ln/channelmanager.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -3006,10 +3006,11 @@ where
30063006
}
30073007
{
30083008
let height = self.best_block.read().unwrap().height();
3009-
// Transactions are evaluated as final by network mempools at the next block. However, the modules
3010-
// constituting our Lightning node might not have perfect sync about their blockchain views. Thus, if
3011-
// the wallet module is in advance on the LDK view, allow one more block of headroom.
3012-
if !funding_transaction.input.iter().all(|input| input.sequence == Sequence::MAX) && LockTime::from(funding_transaction.lock_time).is_block_height() && funding_transaction.lock_time.0 > height + 2 {
3009+
// Transactions are evaluated as final by network mempools if their locktime is strictly
3010+
// lower than the next block height. However, the modules constituting our Lightning
3011+
// node might not have perfect sync about their blockchain views. Thus, if the wallet
3012+
// module is ahead of LDK, only allow one more block of headroom.
3013+
if !funding_transaction.input.iter().all(|input| input.sequence == Sequence::MAX) && LockTime::from(funding_transaction.lock_time).is_block_height() && funding_transaction.lock_time.0 > height + 1 {
30133014
return Err(APIError::APIMisuseError {
30143015
err: "Funding transaction absolute timelock is non-final".to_owned()
30153016
});

lightning/src/ln/functional_test_utils.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,9 @@ fn do_connect_block<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, block: Block, sk
230230
#[cfg(feature = "std")] {
231231
eprintln!("Connecting block using Block Connection Style: {:?}", *node.connect_style.borrow());
232232
}
233+
// Update the block internally before handing it over to LDK, to ensure our assertions regarding
234+
// transaction broadcast are correct.
235+
node.blocks.lock().unwrap().push((block.clone(), height));
233236
if !skip_intermediaries {
234237
let txdata: Vec<_> = block.txdata.iter().enumerate().collect();
235238
match *node.connect_style.borrow() {
@@ -279,7 +282,6 @@ fn do_connect_block<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, block: Block, sk
279282
}
280283
call_claimable_balances(node);
281284
node.node.test_process_background_events();
282-
node.blocks.lock().unwrap().push((block, height));
283285
}
284286

285287
pub fn disconnect_blocks<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, count: u32) {

lightning/src/ln/functional_tests.rs

+20-20
Original file line numberDiff line numberDiff line change
@@ -1284,7 +1284,7 @@ fn test_duplicate_htlc_different_direction_onchain() {
12841284
mine_transaction(&nodes[0], &remote_txn[0]);
12851285
check_added_monitors!(nodes[0], 1);
12861286
check_closed_event!(nodes[0], 1, ClosureReason::CommitmentTxConfirmed);
1287-
connect_blocks(&nodes[0], TEST_FINAL_CLTV - 1); // Confirm blocks until the HTLC expires
1287+
connect_blocks(&nodes[0], TEST_FINAL_CLTV); // Confirm blocks until the HTLC expires
12881288

12891289
let claim_txn = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().clone();
12901290
assert_eq!(claim_txn.len(), 3);
@@ -2438,7 +2438,7 @@ fn test_justice_tx_htlc_timeout() {
24382438
test_txn_broadcast(&nodes[1], &chan_5, Some(revoked_local_txn[0].clone()), HTLCType::NONE);
24392439

24402440
mine_transaction(&nodes[0], &revoked_local_txn[0]);
2441-
connect_blocks(&nodes[0], TEST_FINAL_CLTV - 1); // Confirm blocks until the HTLC expires
2441+
connect_blocks(&nodes[0], TEST_FINAL_CLTV); // Confirm blocks until the HTLC expires
24422442
// Verify broadcast of revoked HTLC-timeout
24432443
let node_txn = test_txn_broadcast(&nodes[0], &chan_5, Some(revoked_local_txn[0].clone()), HTLCType::TIMEOUT);
24442444
check_added_monitors!(nodes[0], 1);
@@ -2765,7 +2765,7 @@ fn test_htlc_on_chain_success() {
27652765
// Verify that B's ChannelManager is able to extract preimage from HTLC Success tx and pass it backward
27662766
let header = BlockHeader { version: 0x20000000, prev_blockhash: nodes[1].best_block_hash(), merkle_root: TxMerkleNode::all_zeros(), time: 42, bits: 42, nonce: 42};
27672767
connect_block(&nodes[1], &Block { header, txdata: vec![commitment_tx[0].clone(), node_txn[0].clone(), node_txn[1].clone()]});
2768-
connect_blocks(&nodes[1], TEST_FINAL_CLTV - 1); // Confirm blocks until the HTLC expires
2768+
connect_blocks(&nodes[1], TEST_FINAL_CLTV); // Confirm blocks until the HTLC expires
27692769
{
27702770
let mut added_monitors = nodes[1].chain_monitor.added_monitors.lock().unwrap();
27712771
assert_eq!(added_monitors.len(), 1);
@@ -2894,15 +2894,15 @@ fn test_htlc_on_chain_success() {
28942894
assert_eq!(commitment_spend.input.len(), 2);
28952895
assert_eq!(commitment_spend.input[0].witness.last().unwrap().len(), OFFERED_HTLC_SCRIPT_WEIGHT);
28962896
assert_eq!(commitment_spend.input[1].witness.last().unwrap().len(), OFFERED_HTLC_SCRIPT_WEIGHT);
2897-
assert_eq!(commitment_spend.lock_time.0, nodes[1].best_block_info().1 + 1);
2897+
assert_eq!(commitment_spend.lock_time.0, nodes[1].best_block_info().1);
28982898
assert!(commitment_spend.output[0].script_pubkey.is_v0_p2wpkh()); // direct payment
28992899
// We don't bother to check that B can claim the HTLC output on its commitment tx here as
29002900
// we already checked the same situation with A.
29012901

29022902
// Verify that A's ChannelManager is able to extract preimage from preimage tx and generate PaymentSent
29032903
let mut header = BlockHeader { version: 0x20000000, prev_blockhash: nodes[0].best_block_hash(), merkle_root: TxMerkleNode::all_zeros(), time: 42, bits: 42, nonce: 42};
29042904
connect_block(&nodes[0], &Block { header, txdata: vec![node_a_commitment_tx[0].clone(), commitment_spend.clone()] });
2905-
connect_blocks(&nodes[0], TEST_FINAL_CLTV + MIN_CLTV_EXPIRY_DELTA as u32 - 1); // Confirm blocks until the HTLC expires
2905+
connect_blocks(&nodes[0], TEST_FINAL_CLTV + MIN_CLTV_EXPIRY_DELTA as u32); // Confirm blocks until the HTLC expires
29062906
check_closed_broadcast!(nodes[0], true);
29072907
check_added_monitors!(nodes[0], 1);
29082908
let events = nodes[0].node.get_and_clear_pending_events();
@@ -3024,7 +3024,7 @@ fn do_test_htlc_on_chain_timeout(connect_style: ConnectStyle) {
30243024
check_spends!(commitment_tx[0], chan_1.3);
30253025

30263026
mine_transaction(&nodes[0], &commitment_tx[0]);
3027-
connect_blocks(&nodes[0], TEST_FINAL_CLTV + MIN_CLTV_EXPIRY_DELTA as u32 - 1); // Confirm blocks until the HTLC expires
3027+
connect_blocks(&nodes[0], TEST_FINAL_CLTV + MIN_CLTV_EXPIRY_DELTA as u32); // Confirm blocks until the HTLC expires
30283028

30293029
check_closed_broadcast!(nodes[0], true);
30303030
check_added_monitors!(nodes[0], 1);
@@ -4446,7 +4446,7 @@ fn test_static_spendable_outputs_timeout_tx() {
44464446
MessageSendEvent::BroadcastChannelUpdate { .. } => {},
44474447
_ => panic!("Unexpected event"),
44484448
}
4449-
connect_blocks(&nodes[1], TEST_FINAL_CLTV - 1); // Confirm blocks until the HTLC expires
4449+
connect_blocks(&nodes[1], TEST_FINAL_CLTV); // Confirm blocks until the HTLC expires
44504450

44514451
// Check B's monitor was able to send back output descriptor event for timeout tx on A's commitment tx
44524452
let node_txn = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0);
@@ -4524,7 +4524,7 @@ fn test_static_spendable_outputs_justice_tx_revoked_htlc_timeout_tx() {
45244524
check_closed_broadcast!(nodes[0], true);
45254525
check_added_monitors!(nodes[0], 1);
45264526
check_closed_event!(nodes[0], 1, ClosureReason::CommitmentTxConfirmed);
4527-
connect_blocks(&nodes[0], TEST_FINAL_CLTV - 1); // Confirm blocks until the HTLC expires
4527+
connect_blocks(&nodes[0], TEST_FINAL_CLTV); // Confirm blocks until the HTLC expires
45284528

45294529
let revoked_htlc_txn = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0);
45304530
assert_eq!(revoked_htlc_txn.len(), 1);
@@ -4756,7 +4756,7 @@ fn test_onchain_to_onchain_claim() {
47564756
check_spends!(b_txn[0], commitment_tx[0]);
47574757
assert_eq!(b_txn[0].input[0].witness.clone().last().unwrap().len(), OFFERED_HTLC_SCRIPT_WEIGHT);
47584758
assert!(b_txn[0].output[0].script_pubkey.is_v0_p2wpkh()); // direct payment
4759-
assert_eq!(b_txn[0].lock_time.0, nodes[1].best_block_info().1 + 1); // Success tx
4759+
assert_eq!(b_txn[0].lock_time.0, nodes[1].best_block_info().1); // Success tx
47604760

47614761
check_closed_broadcast!(nodes[1], true);
47624762
check_added_monitors!(nodes[1], 1);
@@ -4807,7 +4807,7 @@ fn test_duplicate_payment_hash_one_failure_one_success() {
48074807
check_closed_broadcast!(nodes[1], true);
48084808
check_added_monitors!(nodes[1], 1);
48094809
check_closed_event!(nodes[1], 1, ClosureReason::CommitmentTxConfirmed);
4810-
connect_blocks(&nodes[1], TEST_FINAL_CLTV - 40 + MIN_CLTV_EXPIRY_DELTA as u32 - 1); // Confirm blocks until the HTLC expires
4810+
connect_blocks(&nodes[1], TEST_FINAL_CLTV - 40 + MIN_CLTV_EXPIRY_DELTA as u32); // Confirm blocks until the HTLC expires
48114811

48124812
let htlc_timeout_tx;
48134813
{ // Extract one of the two HTLC-Timeout transaction
@@ -5287,7 +5287,7 @@ fn test_dynamic_spendable_outputs_local_htlc_timeout_tx() {
52875287
check_closed_broadcast!(nodes[0], true);
52885288
check_added_monitors!(nodes[0], 1);
52895289
check_closed_event!(nodes[0], 1, ClosureReason::CommitmentTxConfirmed);
5290-
connect_blocks(&nodes[0], TEST_FINAL_CLTV - 1); // Confirm blocks until the HTLC expires
5290+
connect_blocks(&nodes[0], TEST_FINAL_CLTV); // Confirm blocks until the HTLC expires
52915291

52925292
let htlc_timeout = {
52935293
let node_txn = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap();
@@ -5370,7 +5370,7 @@ fn test_key_derivation_params() {
53705370

53715371
// Timeout HTLC on A's chain and so it can generate a HTLC-Timeout tx
53725372
mine_transaction(&nodes[0], &local_txn_1[0]);
5373-
connect_blocks(&nodes[0], TEST_FINAL_CLTV - 1); // Confirm blocks until the HTLC expires
5373+
connect_blocks(&nodes[0], TEST_FINAL_CLTV); // Confirm blocks until the HTLC expires
53745374
check_closed_broadcast!(nodes[0], true);
53755375
check_added_monitors!(nodes[0], 1);
53765376
check_closed_event!(nodes[0], 1, ClosureReason::CommitmentTxConfirmed);
@@ -6927,7 +6927,7 @@ fn do_test_sweep_outbound_htlc_failure_update(revoked: bool, local: bool) {
69276927
check_closed_event!(nodes[0], 1, ClosureReason::CommitmentTxConfirmed);
69286928
assert_eq!(nodes[0].node.get_and_clear_pending_events().len(), 0);
69296929

6930-
connect_blocks(&nodes[0], TEST_FINAL_CLTV - 1); // Confirm blocks until the HTLC expires
6930+
connect_blocks(&nodes[0], TEST_FINAL_CLTV); // Confirm blocks until the HTLC expires
69316931
timeout_tx = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().drain(..)
69326932
.filter(|tx| tx.input[0].previous_output.txid == bs_commitment_tx[0].txid()).collect();
69336933
check_spends!(timeout_tx[0], bs_commitment_tx[0]);
@@ -6938,7 +6938,7 @@ fn do_test_sweep_outbound_htlc_failure_update(revoked: bool, local: bool) {
69386938
if !revoked {
69396939
assert_eq!(timeout_tx[0].input[0].witness.last().unwrap().len(), ACCEPTED_HTLC_SCRIPT_WEIGHT);
69406940
} else {
6941-
assert_eq!(timeout_tx[0].lock_time.0, 12);
6941+
assert_eq!(timeout_tx[0].lock_time.0, 11);
69426942
}
69436943
// We fail non-dust-HTLC 2 by broadcast of local timeout/revocation-claim tx
69446944
mine_transaction(&nodes[0], &timeout_tx[0]);
@@ -7318,7 +7318,7 @@ fn test_bump_penalty_txn_on_revoked_htlcs() {
73187318
check_closed_broadcast!(nodes[1], true);
73197319
check_added_monitors!(nodes[1], 1);
73207320
check_closed_event!(nodes[1], 1, ClosureReason::CommitmentTxConfirmed);
7321-
connect_blocks(&nodes[1], 49); // Confirm blocks until the HTLC expires (note CLTV was explicitly 50 above)
7321+
connect_blocks(&nodes[1], 50); // Confirm blocks until the HTLC expires (note CLTV was explicitly 50 above)
73227322

73237323
let revoked_htlc_txn = {
73247324
let txn = nodes[1].tx_broadcaster.unique_txn_broadcast();
@@ -7464,7 +7464,7 @@ fn test_bump_penalty_txn_on_remote_commitment() {
74647464
expect_payment_claimed!(nodes[1], payment_hash, 3_000_000);
74657465
mine_transaction(&nodes[1], &remote_txn[0]);
74667466
check_added_monitors!(nodes[1], 2);
7467-
connect_blocks(&nodes[1], TEST_FINAL_CLTV - 1); // Confirm blocks until the HTLC expires
7467+
connect_blocks(&nodes[1], TEST_FINAL_CLTV); // Confirm blocks until the HTLC expires
74687468

74697469
// One or more claim tx should have been broadcast, check it
74707470
let timeout;
@@ -8660,7 +8660,7 @@ fn test_htlc_no_detection() {
86608660
check_closed_broadcast!(nodes[0], true);
86618661
check_added_monitors!(nodes[0], 1);
86628662
check_closed_event!(nodes[0], 1, ClosureReason::CommitmentTxConfirmed);
8663-
connect_blocks(&nodes[0], TEST_FINAL_CLTV - 1);
8663+
connect_blocks(&nodes[0], TEST_FINAL_CLTV);
86648664

86658665
let htlc_timeout = {
86668666
let node_txn = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap();
@@ -9836,8 +9836,8 @@ fn test_non_final_funding_tx() {
98369836
assert_eq!(events.len(), 1);
98379837
let mut tx = match events[0] {
98389838
Event::FundingGenerationReady { ref channel_value_satoshis, ref output_script, .. } => {
9839-
// Timelock the transaction _beyond_ the best client height + 2.
9840-
Transaction { version: chan_id as i32, lock_time: PackedLockTime(best_height + 3), input: vec![input], output: vec![TxOut {
9839+
// Timelock the transaction _beyond_ the best client height + 1.
9840+
Transaction { version: chan_id as i32, lock_time: PackedLockTime(best_height + 2), input: vec![input], output: vec![TxOut {
98419841
value: *channel_value_satoshis, script_pubkey: output_script.clone(),
98429842
}]}
98439843
},
@@ -9851,7 +9851,7 @@ fn test_non_final_funding_tx() {
98519851
_ => panic!()
98529852
}
98539853

9854-
// However, transaction should be accepted if it's in a +2 headroom from best block.
9854+
// However, transaction should be accepted if it's in a +1 headroom from best block.
98559855
tx.lock_time = PackedLockTime(tx.lock_time.0 - 1);
98569856
assert!(nodes[0].node.funding_transaction_generated(&temp_channel_id, &nodes[1].node.get_our_node_id(), tx.clone()).is_ok());
98579857
get_event_msg!(nodes[0], MessageSendEvent::SendFundingCreated, nodes[1].node.get_our_node_id());

lightning/src/ln/monitor_tests.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ fn do_test_claim_value_force_close(prev_commitment_tx: bool) {
497497
nodes[0].chain_monitor.chain_monitor.get_monitor(funding_outpoint).unwrap().get_claimable_balances());
498498

499499
// When the HTLC timeout output is spendable in the next block, A should broadcast it
500-
connect_blocks(&nodes[0], htlc_cltv_timeout - nodes[0].best_block_info().1 - 1);
500+
connect_blocks(&nodes[0], htlc_cltv_timeout - nodes[0].best_block_info().1);
501501
let a_broadcast_txn = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0);
502502
assert_eq!(a_broadcast_txn.len(), 2);
503503
assert_eq!(a_broadcast_txn[0].input.len(), 1);
@@ -887,7 +887,7 @@ fn test_no_preimage_inbound_htlc_balances() {
887887
// HTLC has been spent, even after the HTLC expires. We'll also fail the inbound HTLC, but it
888888
// won't do anything as the channel is already closed.
889889

890-
connect_blocks(&nodes[0], TEST_FINAL_CLTV - 1);
890+
connect_blocks(&nodes[0], TEST_FINAL_CLTV);
891891
let as_htlc_timeout_claim = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0);
892892
assert_eq!(as_htlc_timeout_claim.len(), 1);
893893
check_spends!(as_htlc_timeout_claim[0], as_txn[0]);
@@ -908,7 +908,7 @@ fn test_no_preimage_inbound_htlc_balances() {
908908

909909
// The next few blocks for B look the same as for A, though for the opposite HTLC
910910
nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap().clear();
911-
connect_blocks(&nodes[1], TEST_FINAL_CLTV - (ANTI_REORG_DELAY - 1) - 1);
911+
connect_blocks(&nodes[1], TEST_FINAL_CLTV - (ANTI_REORG_DELAY - 1));
912912
expect_pending_htlcs_forwardable_conditions!(nodes[1],
913913
[HTLCDestination::FailedPayment { payment_hash: to_b_failed_payment_hash }]);
914914
let bs_htlc_timeout_claim = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0);
@@ -1734,7 +1734,7 @@ fn do_test_restored_packages_retry(check_old_monitor_retries_after_upgrade: bool
17341734
mine_transaction(&nodes[0], &commitment_tx);
17351735

17361736
// Connect blocks until the HTLC's expiration is met, expecting a transaction broadcast.
1737-
connect_blocks(&nodes[0], TEST_FINAL_CLTV - 1);
1737+
connect_blocks(&nodes[0], TEST_FINAL_CLTV);
17381738
let htlc_timeout_tx = {
17391739
let mut txn = nodes[0].tx_broadcaster.txn_broadcast();
17401740
assert_eq!(txn.len(), 1);
@@ -1885,7 +1885,7 @@ fn do_test_monitor_rebroadcast_pending_claims(anchors: bool) {
18851885
};
18861886

18871887
// Connect blocks up to one before the HTLC expires. This should not result in a claim/retry.
1888-
connect_blocks(&nodes[0], htlc_expiry - nodes[0].best_block_info().1 - 2);
1888+
connect_blocks(&nodes[0], htlc_expiry - nodes[0].best_block_info().1 - 1);
18891889
check_htlc_retry(false, false);
18901890

18911891
// Connect one more block, producing our first claim.

lightning/src/ln/payment_tests.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -562,8 +562,8 @@ fn do_test_completed_payment_not_retryable_on_reload(use_dust: bool) {
562562
mine_transaction(&nodes[0], &bs_commitment_tx[0]);
563563
mine_transaction(&nodes[1], &bs_commitment_tx[0]);
564564
if !use_dust {
565-
connect_blocks(&nodes[0], TEST_FINAL_CLTV - 1 + (MIN_CLTV_EXPIRY_DELTA as u32));
566-
connect_blocks(&nodes[1], TEST_FINAL_CLTV - 1 + (MIN_CLTV_EXPIRY_DELTA as u32));
565+
connect_blocks(&nodes[0], TEST_FINAL_CLTV + (MIN_CLTV_EXPIRY_DELTA as u32));
566+
connect_blocks(&nodes[1], TEST_FINAL_CLTV + (MIN_CLTV_EXPIRY_DELTA as u32));
567567
let as_htlc_timeout = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0);
568568
check_spends!(as_htlc_timeout[0], bs_commitment_tx[0]);
569569
assert_eq!(as_htlc_timeout.len(), 1);

lightning/src/ln/reload_tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,7 @@ fn do_forwarded_payment_no_manager_persistence(use_cs_commitment: bool, claim_ht
948948
if claim_htlc {
949949
confirm_transaction(&nodes[1], &cs_commitment_tx[1]);
950950
} else {
951-
connect_blocks(&nodes[1], htlc_expiry - nodes[1].best_block_info().1);
951+
connect_blocks(&nodes[1], htlc_expiry - nodes[1].best_block_info().1 + 1);
952952
let bs_htlc_timeout_tx = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0);
953953
assert_eq!(bs_htlc_timeout_tx.len(), 1);
954954
confirm_transaction(&nodes[1], &bs_htlc_timeout_tx[0]);

lightning/src/ln/reorg_tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ fn do_test_onchain_htlc_reorg(local_commitment: bool, claim: bool) {
103103

104104
// Give node 1 node 2's commitment transaction and get its response (timing the HTLC out)
105105
mine_transaction(&nodes[1], &node_2_commitment_txn[0]);
106-
connect_blocks(&nodes[1], TEST_FINAL_CLTV - 1); // Confirm blocks until the HTLC expires
106+
connect_blocks(&nodes[1], TEST_FINAL_CLTV); // Confirm blocks until the HTLC expires
107107
let node_1_commitment_txn = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap().clone();
108108
assert_eq!(node_1_commitment_txn.len(), 1); // ChannelMonitor: 1 offered HTLC-Timeout
109109
check_spends!(node_1_commitment_txn[0], node_2_commitment_txn[0]);

lightning/src/util/test_utils.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ impl chaininterface::BroadcasterInterface for TestBroadcaster {
335335
fn broadcast_transaction(&self, tx: &Transaction) {
336336
let lock_time = tx.lock_time.0;
337337
assert!(lock_time < 1_500_000_000);
338-
if lock_time > self.blocks.lock().unwrap().len() as u32 + 1 && lock_time < 500_000_000 {
338+
if bitcoin::LockTime::from(tx.lock_time).is_block_height() && lock_time > self.blocks.lock().unwrap().last().unwrap().1 {
339339
for inp in tx.input.iter() {
340340
if inp.sequence != Sequence::MAX {
341341
panic!("We should never broadcast a transaction before its locktime ({})!", tx.lock_time);

0 commit comments

Comments
 (0)