@@ -18,7 +18,7 @@ use secp256k1;
18
18
use ln:: msgs;
19
19
use ln:: msgs:: { DecodeError , OptionalField , LocalFeatures } ;
20
20
use ln:: channelmonitor:: ChannelMonitor ;
21
- use ln:: channelmanager:: { PendingHTLCStatus , HTLCSource , HTLCFailReason , HTLCFailureMsg , PendingForwardHTLCInfo , RAACommitmentOrder , PaymentPreimage , PaymentHash } ;
21
+ use ln:: channelmanager:: { PendingHTLCStatus , HTLCSource , HTLCFailReason , HTLCFailureMsg , PendingForwardHTLCInfo , RAACommitmentOrder , PaymentPreimage , PaymentHash , BREAKDOWN_TIMEOUT , MAX_LOCAL_BREAKDOWN_TIMEOUT } ;
22
22
use ln:: chan_utils:: { TxCreationKeys , HTLCOutputInCommitment , HTLC_SUCCESS_TX_WEIGHT , HTLC_TIMEOUT_TX_WEIGHT } ;
23
23
use ln:: chan_utils;
24
24
use chain:: chaininterface:: { FeeEstimator , ConfirmationTarget } ;
@@ -317,7 +317,7 @@ pub(super) struct Channel {
317
317
their_htlc_minimum_msat : u64 ,
318
318
our_htlc_minimum_msat : u64 ,
319
319
their_to_self_delay : u16 ,
320
- //implied by BREAKDOWN_TIMEOUT: our_to_self_delay: u16,
320
+ our_to_self_delay : u16 ,
321
321
#[ cfg( test) ]
322
322
pub their_max_accepted_htlcs : u16 ,
323
323
#[ cfg( not( test) ) ]
@@ -347,14 +347,6 @@ pub const OUR_MAX_HTLCS: u16 = 50; //TODO
347
347
/// on ice until the funding transaction gets more confirmations, but the LN protocol doesn't
348
348
/// really allow for this, so instead we're stuck closing it out at that point.
349
349
const UNCONF_THRESHOLD : u32 = 6 ;
350
- /// The amount of time we require our counterparty wait to claim their money (ie time between when
351
- /// we, or our watchtower, must check for them having broadcast a theft transaction).
352
- #[ cfg( not( test) ) ]
353
- const BREAKDOWN_TIMEOUT : u16 = 6 * 24 * 7 ; //TODO?
354
- #[ cfg( test) ]
355
- pub const BREAKDOWN_TIMEOUT : u16 = 6 * 24 * 7 ; //TODO?
356
- /// The amount of time we're willing to wait to claim money back to us
357
- const MAX_LOCAL_BREAKDOWN_TIMEOUT : u16 = 6 * 24 * 14 ;
358
350
/// Exposing these two constants for use in test in ChannelMonitor
359
351
pub const COMMITMENT_TX_BASE_WEIGHT : u64 = 724 ;
360
352
pub const COMMITMENT_TX_WEIGHT_PER_HTLC : u64 = 172 ;
@@ -421,6 +413,9 @@ impl Channel {
421
413
if push_msat > channel_value_satoshis * 1000 {
422
414
return Err ( APIError :: APIMisuseError { err : "push value > channel value" } ) ;
423
415
}
416
+ if config. own_channel_config . our_to_self_delay < BREAKDOWN_TIMEOUT {
417
+ return Err ( APIError :: APIMisuseError { err : "Configured with an unreasonable our_to_self_delay putting user funds at risks" } ) ;
418
+ }
424
419
425
420
426
421
let background_feerate = fee_estimator. get_est_sat_per_1000_weight ( ConfirmationTarget :: Background ) ;
@@ -432,7 +427,7 @@ impl Channel {
432
427
433
428
let secp_ctx = Secp256k1 :: new ( ) ;
434
429
let channel_monitor = ChannelMonitor :: new ( & chan_keys. revocation_base_key , & chan_keys. delayed_payment_base_key ,
435
- & chan_keys. htlc_base_key , & chan_keys. payment_base_key , & keys_provider. get_shutdown_pubkey ( ) , BREAKDOWN_TIMEOUT ,
430
+ & chan_keys. htlc_base_key , & chan_keys. payment_base_key , & keys_provider. get_shutdown_pubkey ( ) , config . own_channel_config . our_to_self_delay ,
436
431
keys_provider. get_destination_script ( ) , logger. clone ( ) ) ;
437
432
438
433
Ok ( Channel {
@@ -489,6 +484,7 @@ impl Channel {
489
484
their_htlc_minimum_msat : 0 ,
490
485
our_htlc_minimum_msat : Channel :: derive_our_htlc_minimum_msat ( feerate) ,
491
486
their_to_self_delay : 0 ,
487
+ our_to_self_delay : config. own_channel_config . our_to_self_delay ,
492
488
their_max_accepted_htlcs : 0 ,
493
489
minimum_depth : 0 , // Filled in in accept_channel
494
490
@@ -526,6 +522,10 @@ impl Channel {
526
522
let chan_keys = keys_provider. get_channel_keys ( true ) ;
527
523
let mut local_config = ( * config) . channel_options . clone ( ) ;
528
524
525
+ if config. own_channel_config . our_to_self_delay < BREAKDOWN_TIMEOUT {
526
+ return Err ( ChannelError :: Close ( "Configured with an unreasonable our_to_self_delay putting user funds at risks" ) ) ;
527
+ }
528
+
529
529
// Check sanity of message fields:
530
530
if msg. funding_satoshis >= MAX_FUNDING_SATOSHIS {
531
531
return Err ( ChannelError :: Close ( "funding value > 2^24" ) ) ;
@@ -547,7 +547,7 @@ impl Channel {
547
547
}
548
548
Channel :: check_remote_fee ( fee_estimator, msg. feerate_per_kw ) ?;
549
549
550
- if msg. to_self_delay > MAX_LOCAL_BREAKDOWN_TIMEOUT {
550
+ if msg. to_self_delay > config . peer_channel_config_limits . their_to_self_delay || msg . to_self_delay > MAX_LOCAL_BREAKDOWN_TIMEOUT {
551
551
return Err ( ChannelError :: Close ( "They wanted our payments to be delayed by a needlessly long period" ) ) ;
552
552
}
553
553
if msg. max_accepted_htlcs < 1 {
@@ -620,7 +620,7 @@ impl Channel {
620
620
621
621
let secp_ctx = Secp256k1 :: new ( ) ;
622
622
let mut channel_monitor = ChannelMonitor :: new ( & chan_keys. revocation_base_key , & chan_keys. delayed_payment_base_key ,
623
- & chan_keys. htlc_base_key , & chan_keys. payment_base_key , & keys_provider. get_shutdown_pubkey ( ) , BREAKDOWN_TIMEOUT ,
623
+ & chan_keys. htlc_base_key , & chan_keys. payment_base_key , & keys_provider. get_shutdown_pubkey ( ) , config . own_channel_config . our_to_self_delay ,
624
624
keys_provider. get_destination_script ( ) , logger. clone ( ) ) ;
625
625
channel_monitor. set_their_base_keys ( & msg. htlc_basepoint , & msg. delayed_payment_basepoint ) ;
626
626
channel_monitor. set_their_to_self_delay ( msg. to_self_delay ) ;
@@ -700,6 +700,7 @@ impl Channel {
700
700
their_htlc_minimum_msat : msg. htlc_minimum_msat ,
701
701
our_htlc_minimum_msat : Channel :: derive_our_htlc_minimum_msat ( msg. feerate_per_kw as u64 ) ,
702
702
their_to_self_delay : msg. to_self_delay ,
703
+ our_to_self_delay : config. own_channel_config . our_to_self_delay ,
703
704
their_max_accepted_htlcs : msg. max_accepted_htlcs ,
704
705
minimum_depth : config. own_channel_config . minimum_depth ,
705
706
@@ -935,7 +936,7 @@ impl Channel {
935
936
log_trace ! ( self , " ...including {} output with value {}" , if local { "to_local" } else { "to_remote" } , value_to_a) ;
936
937
txouts. push ( ( TxOut {
937
938
script_pubkey : chan_utils:: get_revokeable_redeemscript ( & keys. revocation_key ,
938
- if local { self . their_to_self_delay } else { BREAKDOWN_TIMEOUT } ,
939
+ if local { self . their_to_self_delay } else { self . our_to_self_delay } ,
939
940
& keys. a_delayed_payment_key ) . to_v0_p2wsh ( ) ,
940
941
value : value_to_a as u64
941
942
} , None ) ) ;
@@ -1134,7 +1135,7 @@ impl Channel {
1134
1135
/// @local is used only to convert relevant internal structures which refer to remote vs local
1135
1136
/// to decide value of outputs and direction of HTLCs.
1136
1137
fn build_htlc_transaction ( & self , prev_hash : & Sha256dHash , htlc : & HTLCOutputInCommitment , local : bool , keys : & TxCreationKeys , feerate_per_kw : u64 ) -> Transaction {
1137
- chan_utils:: build_htlc_transaction ( prev_hash, feerate_per_kw, if local { self . their_to_self_delay } else { BREAKDOWN_TIMEOUT } , htlc, & keys. a_delayed_payment_key , & keys. revocation_key )
1138
+ chan_utils:: build_htlc_transaction ( prev_hash, feerate_per_kw, if local { self . their_to_self_delay } else { self . our_to_self_delay } , htlc, & keys. a_delayed_payment_key , & keys. revocation_key )
1138
1139
}
1139
1140
1140
1141
fn create_htlc_tx_signature ( & self , tx : & Transaction , htlc : & HTLCOutputInCommitment , keys : & TxCreationKeys ) -> Result < ( Script , Signature , bool ) , ChannelError > {
@@ -1388,7 +1389,7 @@ impl Channel {
1388
1389
if msg. htlc_minimum_msat >= ( self . channel_value_satoshis - msg. channel_reserve_satoshis ) * 1000 {
1389
1390
return Err ( ChannelError :: Close ( "Minimum htlc value is full channel value" ) ) ;
1390
1391
}
1391
- if msg. to_self_delay > MAX_LOCAL_BREAKDOWN_TIMEOUT {
1392
+ if msg. to_self_delay > config . peer_channel_config_limits . their_to_self_delay || msg . to_self_delay > MAX_LOCAL_BREAKDOWN_TIMEOUT {
1392
1393
return Err ( ChannelError :: Close ( "They wanted our payments to be delayed by a needlessly long period" ) ) ;
1393
1394
}
1394
1395
if msg. max_accepted_htlcs < 1 {
@@ -3072,7 +3073,7 @@ impl Channel {
3072
3073
channel_reserve_satoshis : Channel :: get_our_channel_reserve_satoshis ( self . channel_value_satoshis ) ,
3073
3074
htlc_minimum_msat : self . our_htlc_minimum_msat ,
3074
3075
feerate_per_kw : fee_estimator. get_est_sat_per_1000_weight ( ConfirmationTarget :: Background ) as u32 ,
3075
- to_self_delay : BREAKDOWN_TIMEOUT ,
3076
+ to_self_delay : self . our_to_self_delay ,
3076
3077
max_accepted_htlcs : OUR_MAX_HTLCS ,
3077
3078
funding_pubkey : PublicKey :: from_secret_key ( & self . secp_ctx , & self . local_keys . funding_key ) ,
3078
3079
revocation_basepoint : PublicKey :: from_secret_key ( & self . secp_ctx , & self . local_keys . revocation_base_key ) ,
@@ -3105,7 +3106,7 @@ impl Channel {
3105
3106
channel_reserve_satoshis : Channel :: get_our_channel_reserve_satoshis ( self . channel_value_satoshis ) ,
3106
3107
htlc_minimum_msat : self . our_htlc_minimum_msat ,
3107
3108
minimum_depth : self . minimum_depth ,
3108
- to_self_delay : BREAKDOWN_TIMEOUT ,
3109
+ to_self_delay : self . our_to_self_delay ,
3109
3110
max_accepted_htlcs : OUR_MAX_HTLCS ,
3110
3111
funding_pubkey : PublicKey :: from_secret_key ( & self . secp_ctx , & self . local_keys . funding_key ) ,
3111
3112
revocation_basepoint : PublicKey :: from_secret_key ( & self . secp_ctx , & self . local_keys . revocation_base_key ) ,
@@ -3754,6 +3755,7 @@ impl Writeable for Channel {
3754
3755
self . their_htlc_minimum_msat . write ( writer) ?;
3755
3756
self . our_htlc_minimum_msat . write ( writer) ?;
3756
3757
self . their_to_self_delay . write ( writer) ?;
3758
+ self . our_to_self_delay . write ( writer) ?;
3757
3759
self . their_max_accepted_htlcs . write ( writer) ?;
3758
3760
self . minimum_depth . write ( writer) ?;
3759
3761
@@ -3915,6 +3917,7 @@ impl<R : ::std::io::Read> ReadableArgs<R, Arc<Logger>> for Channel {
3915
3917
let their_htlc_minimum_msat = Readable :: read ( reader) ?;
3916
3918
let our_htlc_minimum_msat = Readable :: read ( reader) ?;
3917
3919
let their_to_self_delay = Readable :: read ( reader) ?;
3920
+ let our_to_self_delay = Readable :: read ( reader) ?;
3918
3921
let their_max_accepted_htlcs = Readable :: read ( reader) ?;
3919
3922
let minimum_depth = Readable :: read ( reader) ?;
3920
3923
@@ -3992,6 +3995,7 @@ impl<R : ::std::io::Read> ReadableArgs<R, Arc<Logger>> for Channel {
3992
3995
their_htlc_minimum_msat,
3993
3996
our_htlc_minimum_msat,
3994
3997
their_to_self_delay,
3998
+ our_to_self_delay,
3995
3999
their_max_accepted_htlcs,
3996
4000
minimum_depth,
3997
4001
0 commit comments