Skip to content

Commit 66224ce

Browse files
author
Antoine Riard
committed
Bump default CSV delay on counterparty states to 3 days of blocks
1 parent 2c57878 commit 66224ce

File tree

4 files changed

+27
-24
lines changed

4 files changed

+27
-24
lines changed

lightning-background-processor/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1019,7 +1019,7 @@ mod tests {
10191019
// Force close the channel and check that the SpendableOutputs event was handled.
10201020
nodes[0].node.force_close_broadcasting_latest_txn(&nodes[0].node.list_channels()[0].channel_id, &nodes[1].node.get_our_node_id()).unwrap();
10211021
let commitment_tx = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().pop().unwrap();
1022-
confirm_transaction_depth(&mut nodes[0], &commitment_tx, BREAKDOWN_TIMEOUT as u32);
1022+
confirm_transaction_depth(&mut nodes[0], &commitment_tx, (BREAKDOWN_TIMEOUT * 4) as u32);
10231023

10241024
let event = receiver
10251025
.recv_timeout(Duration::from_secs(EVENT_DEADLINE))

lightning/src/ln/functional_tests.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4222,13 +4222,13 @@ fn test_claim_sizeable_push_msat() {
42224222
assert_eq!(node_txn[0].output.len(), 2); // We can't force trimming of to_remote output as channel_reserve_satoshis block us to do so at channel opening
42234223

42244224
mine_transaction(&nodes[1], &node_txn[0]);
4225-
connect_blocks(&nodes[1], BREAKDOWN_TIMEOUT as u32 - 1);
4225+
connect_blocks(&nodes[1], (BREAKDOWN_TIMEOUT * 4) as u32 - 1);
42264226

42274227
let spend_txn = check_spendable_outputs!(nodes[1], node_cfgs[1].keys_manager);
42284228
assert_eq!(spend_txn.len(), 1);
42294229
assert_eq!(spend_txn[0].input.len(), 1);
42304230
check_spends!(spend_txn[0], node_txn[0]);
4231-
assert_eq!(spend_txn[0].input[0].sequence.0, BREAKDOWN_TIMEOUT as u32);
4231+
assert_eq!(spend_txn[0].input[0].sequence.0, (BREAKDOWN_TIMEOUT * 4) as u32);
42324232
}
42334233

42344234
#[test]
@@ -4894,14 +4894,14 @@ fn test_dynamic_spendable_outputs_local_htlc_success_tx() {
48944894
};
48954895

48964896
mine_transaction(&nodes[1], &node_tx);
4897-
connect_blocks(&nodes[1], BREAKDOWN_TIMEOUT as u32 - 1);
4897+
connect_blocks(&nodes[1], (BREAKDOWN_TIMEOUT * 4) as u32 - 1);
48984898

48994899
// Verify that B is able to spend its own HTLC-Success tx thanks to spendable output event given back by its ChannelMonitor
49004900
let spend_txn = check_spendable_outputs!(nodes[1], node_cfgs[1].keys_manager);
49014901
assert_eq!(spend_txn.len(), 1);
49024902
assert_eq!(spend_txn[0].input.len(), 1);
49034903
check_spends!(spend_txn[0], node_tx);
4904-
assert_eq!(spend_txn[0].input[0].sequence.0, BREAKDOWN_TIMEOUT as u32);
4904+
assert_eq!(spend_txn[0].input[0].sequence.0, (BREAKDOWN_TIMEOUT * 4) as u32);
49054905
}
49064906

49074907
fn do_test_fail_backwards_unrevoked_remote_announce(deliver_last_raa: bool, announce_latest: bool) {
@@ -5240,7 +5240,7 @@ fn test_dynamic_spendable_outputs_local_htlc_timeout_tx() {
52405240
};
52415241

52425242
mine_transaction(&nodes[0], &htlc_timeout);
5243-
connect_blocks(&nodes[0], BREAKDOWN_TIMEOUT as u32 - 1);
5243+
connect_blocks(&nodes[0], (BREAKDOWN_TIMEOUT * 4) as u32 - 1);
52445244
expect_payment_failed!(nodes[0], our_payment_hash, false);
52455245

52465246
// Verify that A is able to spend its own HTLC-Timeout tx thanks to spendable output event given back by its ChannelMonitor
@@ -5249,11 +5249,11 @@ fn test_dynamic_spendable_outputs_local_htlc_timeout_tx() {
52495249
check_spends!(spend_txn[0], local_txn[0]);
52505250
assert_eq!(spend_txn[1].input.len(), 1);
52515251
check_spends!(spend_txn[1], htlc_timeout);
5252-
assert_eq!(spend_txn[1].input[0].sequence.0, BREAKDOWN_TIMEOUT as u32);
5252+
assert_eq!(spend_txn[1].input[0].sequence.0, (BREAKDOWN_TIMEOUT * 4) as u32);
52535253
assert_eq!(spend_txn[2].input.len(), 2);
52545254
check_spends!(spend_txn[2], local_txn[0], htlc_timeout);
5255-
assert!(spend_txn[2].input[0].sequence.0 == BREAKDOWN_TIMEOUT as u32 ||
5256-
spend_txn[2].input[1].sequence.0 == BREAKDOWN_TIMEOUT as u32);
5255+
assert!(spend_txn[2].input[0].sequence.0 == (BREAKDOWN_TIMEOUT * 4) as u32 ||
5256+
spend_txn[2].input[1].sequence.0 == (BREAKDOWN_TIMEOUT * 4) as u32);
52575257
}
52585258

52595259
#[test]
@@ -5322,7 +5322,7 @@ fn test_key_derivation_params() {
53225322
};
53235323

53245324
mine_transaction(&nodes[0], &htlc_timeout);
5325-
connect_blocks(&nodes[0], BREAKDOWN_TIMEOUT as u32 - 1);
5325+
connect_blocks(&nodes[0], (BREAKDOWN_TIMEOUT * 4) as u32 - 1);
53265326
expect_payment_failed!(nodes[0], our_payment_hash, false);
53275327

53285328
// Verify that A is able to spend its own HTLC-Timeout tx thanks to spendable output event given back by its ChannelMonitor
@@ -5332,11 +5332,11 @@ fn test_key_derivation_params() {
53325332
check_spends!(spend_txn[0], local_txn_1[0]);
53335333
assert_eq!(spend_txn[1].input.len(), 1);
53345334
check_spends!(spend_txn[1], htlc_timeout);
5335-
assert_eq!(spend_txn[1].input[0].sequence.0, BREAKDOWN_TIMEOUT as u32);
5335+
assert_eq!(spend_txn[1].input[0].sequence.0, (BREAKDOWN_TIMEOUT * 4) as u32);
53365336
assert_eq!(spend_txn[2].input.len(), 2);
53375337
check_spends!(spend_txn[2], local_txn_1[0], htlc_timeout);
5338-
assert!(spend_txn[2].input[0].sequence.0 == BREAKDOWN_TIMEOUT as u32 ||
5339-
spend_txn[2].input[1].sequence.0 == BREAKDOWN_TIMEOUT as u32);
5338+
assert!(spend_txn[2].input[0].sequence.0 == (BREAKDOWN_TIMEOUT * 4) as u32 ||
5339+
spend_txn[2].input[1].sequence.0 == (BREAKDOWN_TIMEOUT * 4) as u32);
53405340
}
53415341

53425342
#[test]
@@ -5574,7 +5574,7 @@ fn bolt2_open_channel_sending_node_checks_part2() {
55745574

55755575
// BOLT #2 spec: Sending node should set to_self_delay sufficient to ensure the sender can irreversibly spend a commitment transaction output, in case of misbehaviour by the receiver.
55765576
assert!(BREAKDOWN_TIMEOUT>0);
5577-
assert!(node0_to_1_send_open_channel.to_self_delay==BREAKDOWN_TIMEOUT);
5577+
assert!(node0_to_1_send_open_channel.to_self_delay==BREAKDOWN_TIMEOUT*4);
55785578

55795579
// BOLT #2 spec: Sending node must ensure the chain_hash value identifies the chain it wishes to open the channel within.
55805580
let chain_hash=genesis_block(Network::Testnet).header.block_hash();
@@ -8889,7 +8889,7 @@ fn do_test_tx_confirmed_skipping_blocks_immediate_broadcast(test_height_before_t
88898889

88908890
let conf_height = nodes[1].best_block_info().1;
88918891
if !test_height_before_timelock {
8892-
connect_blocks(&nodes[1], 24 * 6);
8892+
connect_blocks(&nodes[1], 24 * 6 * 4);
88938893
}
88948894
nodes[1].chain_monitor.chain_monitor.transactions_confirmed(
88958895
&nodes[1].get_block_header(conf_height), &[(0, &node_txn[0])], conf_height);

lightning/src/ln/monitor_tests.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ fn do_test_claim_value_force_close(prev_commitment_tx: bool) {
359359

360360
// Broadcast the closing transaction (which has both pending HTLCs in it) and get B's
361361
// broadcasted HTLC claim transaction with preimage.
362-
let node_b_commitment_claimable = nodes[1].best_block_info().1 + BREAKDOWN_TIMEOUT as u32;
362+
let node_b_commitment_claimable = nodes[1].best_block_info().1 + (BREAKDOWN_TIMEOUT * 4) as u32;
363363
mine_transaction(&nodes[0], &remote_txn[0]);
364364
mine_transaction(&nodes[1], &remote_txn[0]);
365365

@@ -515,7 +515,7 @@ fn do_test_claim_value_force_close(prev_commitment_tx: bool) {
515515
// Node B will no longer consider the HTLC "contentious" after the HTLC claim transaction
516516
// confirms, and consider it simply "awaiting confirmations". Note that it has to wait for the
517517
// standard revocable transaction CSV delay before receiving a `SpendableOutputs`.
518-
let node_b_htlc_claimable = nodes[1].best_block_info().1 + BREAKDOWN_TIMEOUT as u32;
518+
let node_b_htlc_claimable = nodes[1].best_block_info().1 + (BREAKDOWN_TIMEOUT * 4) as u32;
519519
mine_transaction(&nodes[1], &b_broadcast_txn[0]);
520520

521521
assert_eq!(sorted_vec(vec![Balance::ClaimableAwaitingConfirmations {
@@ -645,7 +645,7 @@ fn test_balances_on_local_commitment_htlcs() {
645645

646646
// First confirm the commitment transaction on nodes[0], which should leave us with three
647647
// claimable balances.
648-
let node_a_commitment_claimable = nodes[0].best_block_info().1 + BREAKDOWN_TIMEOUT as u32;
648+
let node_a_commitment_claimable = nodes[0].best_block_info().1 + (BREAKDOWN_TIMEOUT * 4) as u32;
649649
mine_transaction(&nodes[0], &as_txn[0]);
650650
check_added_monitors!(nodes[0], 1);
651651
check_closed_broadcast!(nodes[0], true);
@@ -694,7 +694,7 @@ fn test_balances_on_local_commitment_htlcs() {
694694

695695
// Now confirm nodes[0]'s HTLC-Timeout transaction, which changes the claimable balance to an
696696
// "awaiting confirmations" one.
697-
let node_a_htlc_claimable = nodes[0].best_block_info().1 + BREAKDOWN_TIMEOUT as u32;
697+
let node_a_htlc_claimable = nodes[0].best_block_info().1 + (BREAKDOWN_TIMEOUT * 4) as u32;
698698
mine_transaction(&nodes[0], &as_txn[1]);
699699
// Note that prior to the fix in the commit which introduced this test, this (and the next
700700
// balance) check failed. With this check removed, the code panicked in the `connect_blocks`
@@ -825,7 +825,7 @@ fn test_no_preimage_inbound_htlc_balances() {
825825

826826
// Now close the channel by confirming A's commitment transaction on both nodes, checking the
827827
// claimable balances remain the same except for the non-HTLC balance changing variant.
828-
let node_a_commitment_claimable = nodes[0].best_block_info().1 + BREAKDOWN_TIMEOUT as u32;
828+
let node_a_commitment_claimable = nodes[0].best_block_info().1 + (BREAKDOWN_TIMEOUT * 4) as u32;
829829
let as_pre_spend_claims = sorted_vec(vec![Balance::ClaimableAwaitingConfirmations {
830830
claimable_amount_satoshis: 1_000_000 - 500_000 - 10_000 - chan_feerate *
831831
(channel::commitment_tx_base_weight(opt_anchors) + 2 * channel::COMMITMENT_TX_WEIGHT_PER_HTLC) / 1000,
@@ -909,7 +909,7 @@ fn test_no_preimage_inbound_htlc_balances() {
909909
// Now confirm the two HTLC timeout transactions for A, checking that the inbound HTLC resolves
910910
// after ANTI_REORG_DELAY confirmations and the other takes BREAKDOWN_TIMEOUT confirmations.
911911
mine_transaction(&nodes[0], &as_htlc_timeout_claim[0]);
912-
let as_timeout_claimable_height = nodes[0].best_block_info().1 + (BREAKDOWN_TIMEOUT as u32) - 1;
912+
let as_timeout_claimable_height = nodes[0].best_block_info().1 + ((BREAKDOWN_TIMEOUT * 4) as u32) - 1;
913913
assert_eq!(sorted_vec(vec![Balance::ClaimableAwaitingConfirmations {
914914
claimable_amount_satoshis: 1_000_000 - 500_000 - 10_000 - chan_feerate *
915915
(channel::commitment_tx_base_weight(opt_anchors) + 2 * channel::COMMITMENT_TX_WEIGHT_PER_HTLC) / 1000,

lightning/src/util/config.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,11 @@ pub struct ChannelHandshakeConfig {
4545
/// case of an honest unilateral channel close, which implicitly decrease the economic value of
4646
/// our channel.
4747
///
48-
/// Default value: [`BREAKDOWN_TIMEOUT`], we enforce it as a minimum at channel opening so you
49-
/// can tweak config to ask for more security, not less.
48+
/// Default value: [`BREAKDOWN_TIMEOUT`] * 4, we enforce [`BREAKDOWN_TIMEOUT`] as a minimum at
49+
/// channel opening so you can tweak config to ask for less security than the default of 4 days
50+
/// of block. When setting this value, consider how long it may take to upgrade node(s) after
51+
/// a bug was discovered a patch releaaed. While not all potential sources of error can be
52+
/// recovered, some classes of bugs may allow this much time to react.
5053
pub our_to_self_delay: u16,
5154
/// Set to the smallest value HTLC we will accept to process.
5255
///
@@ -156,7 +159,7 @@ impl Default for ChannelHandshakeConfig {
156159
fn default() -> ChannelHandshakeConfig {
157160
ChannelHandshakeConfig {
158161
minimum_depth: 6,
159-
our_to_self_delay: BREAKDOWN_TIMEOUT,
162+
our_to_self_delay: BREAKDOWN_TIMEOUT * 4,
160163
our_htlc_minimum_msat: 1,
161164
max_inbound_htlc_value_in_flight_percent_of_channel: 10,
162165
negotiate_scid_privacy: false,

0 commit comments

Comments
 (0)