Skip to content

Commit 468d8cf

Browse files
author
Antoine Riard
committed
Bump default CSV delay on counterparty states to 7 days of blocks
1 parent 56b0c96 commit 468d8cf

File tree

4 files changed

+33
-30
lines changed

4 files changed

+33
-30
lines changed

lightning/src/ln/functional_tests.rs

+19-19
Original file line numberDiff line numberDiff line change
@@ -2395,11 +2395,11 @@ fn test_justice_tx_htlc_timeout() {
23952395
let mut alice_config = UserConfig::default();
23962396
alice_config.channel_handshake_config.announced_channel = true;
23972397
alice_config.channel_handshake_limits.force_announced_channel_preference = false;
2398-
alice_config.channel_handshake_config.our_to_self_delay = 6 * 24 * 5;
2398+
alice_config.channel_handshake_config.our_to_self_delay = 1008 + 288;
23992399
let mut bob_config = UserConfig::default();
24002400
bob_config.channel_handshake_config.announced_channel = true;
24012401
bob_config.channel_handshake_limits.force_announced_channel_preference = false;
2402-
bob_config.channel_handshake_config.our_to_self_delay = 6 * 24 * 3;
2402+
bob_config.channel_handshake_config.our_to_self_delay = 1008 + 144;
24032403
let user_cfgs = [Some(alice_config), Some(bob_config)];
24042404
let mut chanmon_cfgs = create_chanmon_cfgs(2);
24052405
chanmon_cfgs[0].keys_manager.disable_revocation_policy_check = true;
@@ -2458,11 +2458,11 @@ fn test_justice_tx_htlc_success() {
24582458
let mut alice_config = UserConfig::default();
24592459
alice_config.channel_handshake_config.announced_channel = true;
24602460
alice_config.channel_handshake_limits.force_announced_channel_preference = false;
2461-
alice_config.channel_handshake_config.our_to_self_delay = 6 * 24 * 5;
2461+
alice_config.channel_handshake_config.our_to_self_delay = 1008 + 288;
24622462
let mut bob_config = UserConfig::default();
24632463
bob_config.channel_handshake_config.announced_channel = true;
24642464
bob_config.channel_handshake_limits.force_announced_channel_preference = false;
2465-
bob_config.channel_handshake_config.our_to_self_delay = 6 * 24 * 3;
2465+
bob_config.channel_handshake_config.our_to_self_delay = 1008 + 144;
24662466
let user_cfgs = [Some(alice_config), Some(bob_config)];
24672467
let mut chanmon_cfgs = create_chanmon_cfgs(2);
24682468
chanmon_cfgs[0].keys_manager.disable_revocation_policy_check = true;
@@ -4299,13 +4299,13 @@ fn test_claim_sizeable_push_msat() {
42994299
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
43004300

43014301
mine_transaction(&nodes[1], &node_txn[0]);
4302-
connect_blocks(&nodes[1], BREAKDOWN_TIMEOUT as u32 - 1);
4302+
connect_blocks(&nodes[1], (BREAKDOWN_TIMEOUT * 7) as u32 - 1);
43034303

43044304
let spend_txn = check_spendable_outputs!(nodes[1], node_cfgs[1].keys_manager);
43054305
assert_eq!(spend_txn.len(), 1);
43064306
assert_eq!(spend_txn[0].input.len(), 1);
43074307
check_spends!(spend_txn[0], node_txn[0]);
4308-
assert_eq!(spend_txn[0].input[0].sequence.0, BREAKDOWN_TIMEOUT as u32);
4308+
assert_eq!(spend_txn[0].input[0].sequence.0, (BREAKDOWN_TIMEOUT * 7) as u32);
43094309
}
43104310

43114311
#[test]
@@ -4951,14 +4951,14 @@ fn test_dynamic_spendable_outputs_local_htlc_success_tx() {
49514951
};
49524952

49534953
mine_transaction(&nodes[1], &node_tx);
4954-
connect_blocks(&nodes[1], BREAKDOWN_TIMEOUT as u32 - 1);
4954+
connect_blocks(&nodes[1], (BREAKDOWN_TIMEOUT * 7) as u32 - 1);
49554955

49564956
// Verify that B is able to spend its own HTLC-Success tx thanks to spendable output event given back by its ChannelMonitor
49574957
let spend_txn = check_spendable_outputs!(nodes[1], node_cfgs[1].keys_manager);
49584958
assert_eq!(spend_txn.len(), 1);
49594959
assert_eq!(spend_txn[0].input.len(), 1);
49604960
check_spends!(spend_txn[0], node_tx);
4961-
assert_eq!(spend_txn[0].input[0].sequence.0, BREAKDOWN_TIMEOUT as u32);
4961+
assert_eq!(spend_txn[0].input[0].sequence.0, (BREAKDOWN_TIMEOUT * 7) as u32);
49624962
}
49634963

49644964
fn do_test_fail_backwards_unrevoked_remote_announce(deliver_last_raa: bool, announce_latest: bool) {
@@ -5299,7 +5299,7 @@ fn test_dynamic_spendable_outputs_local_htlc_timeout_tx() {
52995299
};
53005300

53015301
mine_transaction(&nodes[0], &htlc_timeout);
5302-
connect_blocks(&nodes[0], BREAKDOWN_TIMEOUT as u32 - 1);
5302+
connect_blocks(&nodes[0], (BREAKDOWN_TIMEOUT * 7) as u32 - 1);
53035303
expect_payment_failed!(nodes[0], our_payment_hash, false);
53045304

53055305
// Verify that A is able to spend its own HTLC-Timeout tx thanks to spendable output event given back by its ChannelMonitor
@@ -5308,11 +5308,11 @@ fn test_dynamic_spendable_outputs_local_htlc_timeout_tx() {
53085308
check_spends!(spend_txn[0], local_txn[0]);
53095309
assert_eq!(spend_txn[1].input.len(), 1);
53105310
check_spends!(spend_txn[1], htlc_timeout);
5311-
assert_eq!(spend_txn[1].input[0].sequence.0, BREAKDOWN_TIMEOUT as u32);
5311+
assert_eq!(spend_txn[1].input[0].sequence.0, (BREAKDOWN_TIMEOUT * 7) as u32);
53125312
assert_eq!(spend_txn[2].input.len(), 2);
53135313
check_spends!(spend_txn[2], local_txn[0], htlc_timeout);
5314-
assert!(spend_txn[2].input[0].sequence.0 == BREAKDOWN_TIMEOUT as u32 ||
5315-
spend_txn[2].input[1].sequence.0 == BREAKDOWN_TIMEOUT as u32);
5314+
assert!(spend_txn[2].input[0].sequence.0 == (BREAKDOWN_TIMEOUT * 7) as u32 ||
5315+
spend_txn[2].input[1].sequence.0 == (BREAKDOWN_TIMEOUT * 7) as u32);
53165316
}
53175317

53185318
#[test]
@@ -5385,7 +5385,7 @@ fn test_key_derivation_params() {
53855385
};
53865386

53875387
mine_transaction(&nodes[0], &htlc_timeout);
5388-
connect_blocks(&nodes[0], BREAKDOWN_TIMEOUT as u32 - 1);
5388+
connect_blocks(&nodes[0], (BREAKDOWN_TIMEOUT * 7) as u32 - 1);
53895389
expect_payment_failed!(nodes[0], our_payment_hash, false);
53905390

53915391
// Verify that A is able to spend its own HTLC-Timeout tx thanks to spendable output event given back by its ChannelMonitor
@@ -5395,11 +5395,11 @@ fn test_key_derivation_params() {
53955395
check_spends!(spend_txn[0], local_txn_1[0]);
53965396
assert_eq!(spend_txn[1].input.len(), 1);
53975397
check_spends!(spend_txn[1], htlc_timeout);
5398-
assert_eq!(spend_txn[1].input[0].sequence.0, BREAKDOWN_TIMEOUT as u32);
5398+
assert_eq!(spend_txn[1].input[0].sequence.0, (BREAKDOWN_TIMEOUT * 7) as u32);
53995399
assert_eq!(spend_txn[2].input.len(), 2);
54005400
check_spends!(spend_txn[2], local_txn_1[0], htlc_timeout);
5401-
assert!(spend_txn[2].input[0].sequence.0 == BREAKDOWN_TIMEOUT as u32 ||
5402-
spend_txn[2].input[1].sequence.0 == BREAKDOWN_TIMEOUT as u32);
5401+
assert!(spend_txn[2].input[0].sequence.0 == (BREAKDOWN_TIMEOUT * 7) as u32 ||
5402+
spend_txn[2].input[1].sequence.0 == (BREAKDOWN_TIMEOUT * 7) as u32);
54035403
}
54045404

54055405
#[test]
@@ -5637,8 +5637,8 @@ fn bolt2_open_channel_sending_node_checks_part2() {
56375637
assert!(node0_to_1_send_open_channel.channel_flags<=1);
56385638

56395639
// 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.
5640-
assert!(BREAKDOWN_TIMEOUT>0);
5641-
assert!(node0_to_1_send_open_channel.to_self_delay==BREAKDOWN_TIMEOUT);
5640+
assert!((BREAKDOWN_TIMEOUT*7)>0);
5641+
assert!(node0_to_1_send_open_channel.to_self_delay==(BREAKDOWN_TIMEOUT*7));
56425642

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

92469246
let conf_height = nodes[1].best_block_info().1;
92479247
if !test_height_before_timelock {
9248-
connect_blocks(&nodes[1], 24 * 6);
9248+
connect_blocks(&nodes[1], (BREAKDOWN_TIMEOUT*7) as u32);
92499249
}
92509250
nodes[1].chain_monitor.chain_monitor.transactions_confirmed(
92519251
&nodes[1].get_block_header(conf_height), &[(0, &node_txn[0])], conf_height);

lightning/src/ln/monitor_tests.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ fn do_test_claim_value_force_close(prev_commitment_tx: bool) {
398398

399399
// Broadcast the closing transaction (which has both pending HTLCs in it) and get B's
400400
// broadcasted HTLC claim transaction with preimage.
401-
let node_b_commitment_claimable = nodes[1].best_block_info().1 + BREAKDOWN_TIMEOUT as u32;
401+
let node_b_commitment_claimable = nodes[1].best_block_info().1 + (BREAKDOWN_TIMEOUT * 7) as u32;
402402
mine_transaction(&nodes[0], &remote_txn[0]);
403403
mine_transaction(&nodes[1], &remote_txn[0]);
404404

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

519519
assert_eq!(sorted_vec(vec![Balance::ClaimableAwaitingConfirmations {
@@ -633,7 +633,7 @@ fn test_balances_on_local_commitment_htlcs() {
633633

634634
// First confirm the commitment transaction on nodes[0], which should leave us with three
635635
// claimable balances.
636-
let node_a_commitment_claimable = nodes[0].best_block_info().1 + BREAKDOWN_TIMEOUT as u32;
636+
let node_a_commitment_claimable = nodes[0].best_block_info().1 + (BREAKDOWN_TIMEOUT * 7) as u32;
637637
mine_transaction(&nodes[0], &as_txn[0]);
638638
check_added_monitors!(nodes[0], 1);
639639
check_closed_broadcast!(nodes[0], true);
@@ -679,7 +679,7 @@ fn test_balances_on_local_commitment_htlcs() {
679679

680680
// Now confirm nodes[0]'s HTLC-Timeout transaction, which changes the claimable balance to an
681681
// "awaiting confirmations" one.
682-
let node_a_htlc_claimable = nodes[0].best_block_info().1 + BREAKDOWN_TIMEOUT as u32;
682+
let node_a_htlc_claimable = nodes[0].best_block_info().1 + (BREAKDOWN_TIMEOUT * 7) as u32;
683683
mine_transaction(&nodes[0], &as_txn[1]);
684684
// Note that prior to the fix in the commit which introduced this test, this (and the next
685685
// balance) check failed. With this check removed, the code panicked in the `connect_blocks`
@@ -813,7 +813,7 @@ fn test_no_preimage_inbound_htlc_balances() {
813813

814814
// Now close the channel by confirming A's commitment transaction on both nodes, checking the
815815
// claimable balances remain the same except for the non-HTLC balance changing variant.
816-
let node_a_commitment_claimable = nodes[0].best_block_info().1 + BREAKDOWN_TIMEOUT as u32;
816+
let node_a_commitment_claimable = nodes[0].best_block_info().1 + (BREAKDOWN_TIMEOUT * 7) as u32;
817817
let as_pre_spend_claims = sorted_vec(vec![Balance::ClaimableAwaitingConfirmations {
818818
claimable_amount_satoshis: 1_000_000 - 500_000 - 10_000 - chan_feerate *
819819
(channel::commitment_tx_base_weight(opt_anchors) + 2 * channel::COMMITMENT_TX_WEIGHT_PER_HTLC) / 1000,
@@ -885,7 +885,7 @@ fn test_no_preimage_inbound_htlc_balances() {
885885
// Now confirm the two HTLC timeout transactions for A, checking that the inbound HTLC resolves
886886
// after ANTI_REORG_DELAY confirmations and the other takes BREAKDOWN_TIMEOUT confirmations.
887887
mine_transaction(&nodes[0], &as_htlc_timeout_claim[0]);
888-
let as_timeout_claimable_height = nodes[0].best_block_info().1 + (BREAKDOWN_TIMEOUT as u32) - 1;
888+
let as_timeout_claimable_height = nodes[0].best_block_info().1 + (BREAKDOWN_TIMEOUT * 7) as u32 - 1;
889889
assert_eq!(sorted_vec(vec![Balance::ClaimableAwaitingConfirmations {
890890
claimable_amount_satoshis: 1_000_000 - 500_000 - 10_000 - chan_feerate *
891891
(channel::commitment_tx_base_weight(opt_anchors) + 2 * channel::COMMITMENT_TX_WEIGHT_PER_HTLC) / 1000,
@@ -1998,7 +1998,7 @@ fn test_yield_anchors_events() {
19981998

19991999
assert!(nodes[0].chain_monitor.chain_monitor.get_and_clear_pending_events().is_empty());
20002000

2001-
connect_blocks(&nodes[0], BREAKDOWN_TIMEOUT as u32);
2001+
connect_blocks(&nodes[0], (BREAKDOWN_TIMEOUT * 7) as u32);
20022002

20032003
let holder_events = nodes[0].chain_monitor.chain_monitor.get_and_clear_pending_events();
20042004
assert_eq!(holder_events.len(), 3);

lightning/src/ln/payment_tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,7 @@ fn do_test_dup_htlc_onchain_fails_on_reload(persist_manager_post_event: bool, co
706706
connect_block(&nodes[0], &Block { header, txdata: vec![node_txn[1].clone()]});
707707

708708
if confirm_commitment_tx {
709-
connect_blocks(&nodes[0], BREAKDOWN_TIMEOUT as u32 - 1);
709+
connect_blocks(&nodes[0], (BREAKDOWN_TIMEOUT * 7) as u32 - 1);
710710
}
711711

712712
header.prev_blockhash = nodes[0].best_block_hash();

lightning/src/util/config.rs

+6-3
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`], we enforce [`BREAKDOWN_TIMEOUT`] * 7 as a minimum at
49+
/// channel opening so you can tweak config to ask for less security than the default of 7 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
///
@@ -189,7 +192,7 @@ impl Default for ChannelHandshakeConfig {
189192
fn default() -> ChannelHandshakeConfig {
190193
ChannelHandshakeConfig {
191194
minimum_depth: 6,
192-
our_to_self_delay: BREAKDOWN_TIMEOUT,
195+
our_to_self_delay: BREAKDOWN_TIMEOUT * 7,
193196
our_htlc_minimum_msat: 1,
194197
max_inbound_htlc_value_in_flight_percent_of_channel: 10,
195198
negotiate_scid_privacy: false,

0 commit comments

Comments
 (0)