@@ -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) ) ]
@@ -413,6 +413,9 @@ impl Channel {
413
413
if push_msat > channel_value_satoshis * 1000 {
414
414
return Err ( APIError :: APIMisuseError { err : "push value > channel value" } ) ;
415
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
+ }
416
419
417
420
418
421
let background_feerate = fee_estimator. get_est_sat_per_1000_weight ( ConfirmationTarget :: Background ) ;
@@ -481,6 +484,7 @@ impl Channel {
481
484
their_htlc_minimum_msat : 0 ,
482
485
our_htlc_minimum_msat : Channel :: derive_our_htlc_minimum_msat ( feerate) ,
483
486
their_to_self_delay : 0 ,
487
+ our_to_self_delay : config. own_channel_config . our_to_self_delay ,
484
488
their_max_accepted_htlcs : 0 ,
485
489
minimum_depth : 0 , // Filled in in accept_channel
486
490
@@ -518,6 +522,10 @@ impl Channel {
518
522
let chan_keys = keys_provider. get_channel_keys ( true ) ;
519
523
let mut local_config = ( * config) . channel_options . clone ( ) ;
520
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
+
521
529
// Check sanity of message fields:
522
530
if msg. funding_satoshis >= MAX_FUNDING_SATOSHIS {
523
531
return Err ( ChannelError :: Close ( "funding value > 2^24" ) ) ;
@@ -539,7 +547,7 @@ impl Channel {
539
547
}
540
548
Channel :: check_remote_fee ( fee_estimator, msg. feerate_per_kw ) ?;
541
549
542
- 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 {
543
551
return Err ( ChannelError :: Close ( "They wanted our payments to be delayed by a needlessly long period" ) ) ;
544
552
}
545
553
if msg. max_accepted_htlcs < 1 {
@@ -671,6 +679,7 @@ impl Channel {
671
679
their_htlc_minimum_msat : msg. htlc_minimum_msat ,
672
680
our_htlc_minimum_msat : Channel :: derive_our_htlc_minimum_msat ( msg. feerate_per_kw as u64 ) ,
673
681
their_to_self_delay : msg. to_self_delay ,
682
+ our_to_self_delay : config. own_channel_config . our_to_self_delay ,
674
683
their_max_accepted_htlcs : msg. max_accepted_htlcs ,
675
684
minimum_depth : config. own_channel_config . minimum_depth ,
676
685
@@ -1359,7 +1368,7 @@ impl Channel {
1359
1368
if msg. htlc_minimum_msat >= ( self . channel_value_satoshis - msg. channel_reserve_satoshis ) * 1000 {
1360
1369
return Err ( ChannelError :: Close ( "Minimum htlc value is full channel value" ) ) ;
1361
1370
}
1362
- if msg. to_self_delay > MAX_LOCAL_BREAKDOWN_TIMEOUT {
1371
+ if msg. to_self_delay > config . peer_channel_config_limits . their_to_self_delay || msg . to_self_delay > MAX_LOCAL_BREAKDOWN_TIMEOUT {
1363
1372
return Err ( ChannelError :: Close ( "They wanted our payments to be delayed by a needlessly long period" ) ) ;
1364
1373
}
1365
1374
if msg. max_accepted_htlcs < 1 {
@@ -3021,7 +3030,7 @@ impl Channel {
3021
3030
channel_reserve_satoshis : Channel :: get_our_channel_reserve_satoshis ( self . channel_value_satoshis ) ,
3022
3031
htlc_minimum_msat : self . our_htlc_minimum_msat ,
3023
3032
feerate_per_kw : fee_estimator. get_est_sat_per_1000_weight ( ConfirmationTarget :: Background ) as u32 ,
3024
- to_self_delay : BREAKDOWN_TIMEOUT ,
3033
+ to_self_delay : self . our_to_self_delay ,
3025
3034
max_accepted_htlcs : OUR_MAX_HTLCS ,
3026
3035
funding_pubkey : PublicKey :: from_secret_key ( & self . secp_ctx , & self . local_keys . funding_key ) ,
3027
3036
revocation_basepoint : PublicKey :: from_secret_key ( & self . secp_ctx , & self . local_keys . revocation_base_key ) ,
@@ -3054,7 +3063,7 @@ impl Channel {
3054
3063
channel_reserve_satoshis : Channel :: get_our_channel_reserve_satoshis ( self . channel_value_satoshis ) ,
3055
3064
htlc_minimum_msat : self . our_htlc_minimum_msat ,
3056
3065
minimum_depth : self . minimum_depth ,
3057
- to_self_delay : BREAKDOWN_TIMEOUT ,
3066
+ to_self_delay : self . our_to_self_delay ,
3058
3067
max_accepted_htlcs : OUR_MAX_HTLCS ,
3059
3068
funding_pubkey : PublicKey :: from_secret_key ( & self . secp_ctx , & self . local_keys . funding_key ) ,
3060
3069
revocation_basepoint : PublicKey :: from_secret_key ( & self . secp_ctx , & self . local_keys . revocation_base_key ) ,
@@ -3703,6 +3712,7 @@ impl Writeable for Channel {
3703
3712
self . their_htlc_minimum_msat . write ( writer) ?;
3704
3713
self . our_htlc_minimum_msat . write ( writer) ?;
3705
3714
self . their_to_self_delay . write ( writer) ?;
3715
+ self . our_to_self_delay . write ( writer) ?;
3706
3716
self . their_max_accepted_htlcs . write ( writer) ?;
3707
3717
self . minimum_depth . write ( writer) ?;
3708
3718
@@ -3864,6 +3874,7 @@ impl<R : ::std::io::Read> ReadableArgs<R, Arc<Logger>> for Channel {
3864
3874
let their_htlc_minimum_msat = Readable :: read ( reader) ?;
3865
3875
let our_htlc_minimum_msat = Readable :: read ( reader) ?;
3866
3876
let their_to_self_delay = Readable :: read ( reader) ?;
3877
+ let our_to_self_delay = Readable :: read ( reader) ?;
3867
3878
let their_max_accepted_htlcs = Readable :: read ( reader) ?;
3868
3879
let minimum_depth = Readable :: read ( reader) ?;
3869
3880
@@ -3941,6 +3952,7 @@ impl<R : ::std::io::Read> ReadableArgs<R, Arc<Logger>> for Channel {
3941
3952
their_htlc_minimum_msat,
3942
3953
our_htlc_minimum_msat,
3943
3954
their_to_self_delay,
3955
+ our_to_self_delay,
3944
3956
their_max_accepted_htlcs,
3945
3957
minimum_depth,
3946
3958
0 commit comments