@@ -329,9 +329,9 @@ pub(super) struct Channel<ChanSigner: ChannelKeys> {
329
329
#[ cfg( not( test) ) ]
330
330
their_max_htlc_value_in_flight_msat : u64 ,
331
331
//get_our_max_htlc_value_in_flight_msat(): u64,
332
- /// minimum channel reserve for ** self** to maintain - set by them.
333
- their_channel_reserve_satoshis : u64 ,
334
- //get_our_channel_reserve_satoshis( ): u64,
332
+ /// minimum channel reserve for self to maintain - set by them.
333
+ local_channel_reserve_satoshis : u64 ,
334
+ // get_remote_channel_reserve_satoshis(channel_value_sats: u64 ): u64
335
335
their_htlc_minimum_msat : u64 ,
336
336
our_htlc_minimum_msat : u64 ,
337
337
their_to_self_delay : u16 ,
@@ -420,10 +420,11 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
420
420
channel_value_satoshis * 1000 / 10 //TODO
421
421
}
422
422
423
- /// Returns a minimum channel reserve value **they** need to maintain
423
+ /// Returns a minimum channel reserve value the remote needs to maintain,
424
+ /// required by us.
424
425
///
425
426
/// Guaranteed to return a value no larger than channel_value_satoshis
426
- pub ( crate ) fn get_our_channel_reserve_satoshis ( channel_value_satoshis : u64 ) -> u64 {
427
+ pub ( crate ) fn get_remote_channel_reserve_satoshis ( channel_value_satoshis : u64 ) -> u64 {
427
428
let ( q, _) = channel_value_satoshis. overflowing_div ( 100 ) ;
428
429
cmp:: min ( channel_value_satoshis, cmp:: max ( q, 1000 ) ) //TODO
429
430
}
@@ -452,7 +453,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
452
453
453
454
454
455
let background_feerate = fee_estimator. get_est_sat_per_1000_weight ( ConfirmationTarget :: Background ) ;
455
- if Channel :: < ChanSigner > :: get_our_channel_reserve_satoshis ( channel_value_satoshis) < Channel :: < ChanSigner > :: derive_our_dust_limit_satoshis ( background_feerate) {
456
+ if Channel :: < ChanSigner > :: get_remote_channel_reserve_satoshis ( channel_value_satoshis) < Channel :: < ChanSigner > :: derive_our_dust_limit_satoshis ( background_feerate) {
456
457
return Err ( APIError :: FeeRateTooHigh { err : format ! ( "Not enough reserve above dust limit can be found at current fee rate({})" , background_feerate) , feerate : background_feerate} ) ;
457
458
}
458
459
@@ -512,7 +513,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
512
513
their_dust_limit_satoshis : 0 ,
513
514
our_dust_limit_satoshis : Channel :: < ChanSigner > :: derive_our_dust_limit_satoshis ( background_feerate) ,
514
515
their_max_htlc_value_in_flight_msat : 0 ,
515
- their_channel_reserve_satoshis : 0 ,
516
+ local_channel_reserve_satoshis : 0 ,
516
517
their_htlc_minimum_msat : 0 ,
517
518
our_htlc_minimum_msat : if config. own_channel_config . our_htlc_minimum_msat == 0 { 1 } else { config. own_channel_config . our_htlc_minimum_msat } ,
518
519
their_to_self_delay : 0 ,
@@ -638,15 +639,15 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
638
639
let background_feerate = fee_estimator. get_est_sat_per_1000_weight ( ConfirmationTarget :: Background ) ;
639
640
640
641
let our_dust_limit_satoshis = Channel :: < ChanSigner > :: derive_our_dust_limit_satoshis ( background_feerate) ;
641
- let our_channel_reserve_satoshis = Channel :: < ChanSigner > :: get_our_channel_reserve_satoshis ( msg. funding_satoshis ) ;
642
- if our_channel_reserve_satoshis < our_dust_limit_satoshis {
642
+ let remote_channel_reserve_satoshis = Channel :: < ChanSigner > :: get_remote_channel_reserve_satoshis ( msg. funding_satoshis ) ;
643
+ if remote_channel_reserve_satoshis < our_dust_limit_satoshis {
643
644
return Err ( ChannelError :: Close ( "Suitable channel reserve not found. aborting" ) ) ;
644
645
}
645
646
if msg. channel_reserve_satoshis < our_dust_limit_satoshis {
646
647
return Err ( ChannelError :: Close ( "channel_reserve_satoshis too small" ) ) ;
647
648
}
648
- if our_channel_reserve_satoshis < msg. dust_limit_satoshis {
649
- return Err ( ChannelError :: Close ( "Dust limit too high for our channel reserve" ) ) ;
649
+ if remote_channel_reserve_satoshis < msg. dust_limit_satoshis {
650
+ return Err ( ChannelError :: Close ( "Dust limit too high for the channel reserve we require the remote to keep " ) ) ;
650
651
}
651
652
652
653
// check if the funder's amount for the initial commitment tx is sufficient
@@ -658,7 +659,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
658
659
659
660
let to_local_msat = msg. push_msat ;
660
661
let to_remote_msat = funders_amount_msat - background_feerate * COMMITMENT_TX_BASE_WEIGHT ;
661
- if to_local_msat <= msg. channel_reserve_satoshis * 1000 && to_remote_msat <= our_channel_reserve_satoshis * 1000 {
662
+ if to_local_msat <= msg. channel_reserve_satoshis * 1000 && to_remote_msat <= remote_channel_reserve_satoshis * 1000 {
662
663
return Err ( ChannelError :: Close ( "Insufficient funding amount for initial commitment" ) ) ;
663
664
}
664
665
@@ -737,7 +738,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
737
738
their_dust_limit_satoshis : msg. dust_limit_satoshis ,
738
739
our_dust_limit_satoshis : our_dust_limit_satoshis,
739
740
their_max_htlc_value_in_flight_msat : cmp:: min ( msg. max_htlc_value_in_flight_msat , msg. funding_satoshis * 1000 ) ,
740
- their_channel_reserve_satoshis : msg. channel_reserve_satoshis ,
741
+ local_channel_reserve_satoshis : msg. channel_reserve_satoshis ,
741
742
their_htlc_minimum_msat : msg. htlc_minimum_msat ,
742
743
our_htlc_minimum_msat : if config. own_channel_config . our_htlc_minimum_msat == 0 { 1 } else { config. own_channel_config . our_htlc_minimum_msat } ,
743
744
their_to_self_delay : msg. to_self_delay ,
@@ -952,9 +953,9 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
952
953
} else {
953
954
self . max_commitment_tx_output_remote . lock ( ) . unwrap ( )
954
955
} ;
955
- debug_assert ! ( max_commitment_tx_output. 0 <= value_to_self_msat as u64 || value_to_self_msat / 1000 >= self . their_channel_reserve_satoshis as i64 ) ;
956
+ debug_assert ! ( max_commitment_tx_output. 0 <= value_to_self_msat as u64 || value_to_self_msat / 1000 >= self . local_channel_reserve_satoshis as i64 ) ;
956
957
max_commitment_tx_output. 0 = cmp:: max ( max_commitment_tx_output. 0 , value_to_self_msat as u64 ) ;
957
- debug_assert ! ( max_commitment_tx_output. 1 <= value_to_remote_msat as u64 || value_to_remote_msat / 1000 >= Channel :: <ChanSigner >:: get_our_channel_reserve_satoshis ( self . channel_value_satoshis) as i64 ) ;
958
+ debug_assert ! ( max_commitment_tx_output. 1 <= value_to_remote_msat as u64 || value_to_remote_msat / 1000 >= Channel :: <ChanSigner >:: get_remote_channel_reserve_satoshis ( self . channel_value_satoshis) as i64 ) ;
958
959
max_commitment_tx_output. 1 = cmp:: max ( max_commitment_tx_output. 1 , value_to_remote_msat as u64 ) ;
959
960
}
960
961
@@ -1362,7 +1363,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
1362
1363
if msg. channel_reserve_satoshis < self . our_dust_limit_satoshis {
1363
1364
return Err ( ChannelError :: Close ( "Peer never wants payout outputs?" ) ) ;
1364
1365
}
1365
- if msg. dust_limit_satoshis > Channel :: < ChanSigner > :: get_our_channel_reserve_satoshis ( self . channel_value_satoshis ) {
1366
+ if msg. dust_limit_satoshis > Channel :: < ChanSigner > :: get_remote_channel_reserve_satoshis ( self . channel_value_satoshis ) {
1366
1367
return Err ( ChannelError :: Close ( "Dust limit is bigger than our channel reverse" ) ) ;
1367
1368
}
1368
1369
if msg. htlc_minimum_msat >= ( self . channel_value_satoshis - msg. channel_reserve_satoshis ) * 1000 {
@@ -1424,7 +1425,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
1424
1425
1425
1426
self . their_dust_limit_satoshis = msg. dust_limit_satoshis ;
1426
1427
self . their_max_htlc_value_in_flight_msat = cmp:: min ( msg. max_htlc_value_in_flight_msat , self . channel_value_satoshis * 1000 ) ;
1427
- self . their_channel_reserve_satoshis = msg. channel_reserve_satoshis ;
1428
+ self . local_channel_reserve_satoshis = msg. channel_reserve_satoshis ;
1428
1429
self . their_htlc_minimum_msat = msg. htlc_minimum_msat ;
1429
1430
self . their_to_self_delay = msg. to_self_delay ;
1430
1431
self . their_max_accepted_htlcs = msg. max_accepted_htlcs ;
@@ -1696,7 +1697,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
1696
1697
if htlc_inbound_value_msat + msg. amount_msat > Channel :: < ChanSigner > :: get_our_max_htlc_value_in_flight_msat ( self . channel_value_satoshis ) {
1697
1698
return Err ( ChannelError :: Close ( "Remote HTLC add would put them over our max HTLC value" ) ) ;
1698
1699
}
1699
- // Check our_channel_reserve_satoshis (we're getting paid, so they have to at least meet
1700
+ // Check remote_channel_reserve_satoshis (we're getting paid, so they have to at least meet
1700
1701
// the reserve_satoshis we told them to always have as direct payment so that they lose
1701
1702
// something if we punish them for broadcasting an old state).
1702
1703
// Note that we don't really care about having a small/no to_remote output in our local
@@ -1716,8 +1717,8 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
1716
1717
removed_outbound_total_msat += htlc. amount_msat ;
1717
1718
}
1718
1719
}
1719
- if htlc_inbound_value_msat + msg. amount_msat + self . value_to_self_msat > ( self . channel_value_satoshis - Channel :: < ChanSigner > :: get_our_channel_reserve_satoshis ( self . channel_value_satoshis ) ) * 1000 + removed_outbound_total_msat {
1720
- return Err ( ChannelError :: Close ( "Remote HTLC add would put them over their reserve value" ) ) ;
1720
+ if htlc_inbound_value_msat + msg. amount_msat + self . value_to_self_msat > ( self . channel_value_satoshis - Channel :: < ChanSigner > :: get_remote_channel_reserve_satoshis ( self . channel_value_satoshis ) ) * 1000 + removed_outbound_total_msat {
1721
+ return Err ( ChannelError :: Close ( "Remote HTLC add would put them under their reserve value" ) ) ;
1721
1722
}
1722
1723
if self . next_remote_htlc_id != msg. htlc_id {
1723
1724
return Err ( ChannelError :: Close ( "Remote skipped HTLC ID" ) ) ;
@@ -1847,7 +1848,8 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
1847
1848
let num_htlcs = local_commitment_tx. 1 ;
1848
1849
let total_fee: u64 = feerate_per_kw as u64 * ( COMMITMENT_TX_BASE_WEIGHT + ( num_htlcs as u64 ) * COMMITMENT_TX_WEIGHT_PER_HTLC ) / 1000 ;
1849
1850
1850
- if self . channel_value_satoshis - self . value_to_self_msat / 1000 < total_fee + self . their_channel_reserve_satoshis {
1851
+ let remote_reserve_we_require = Channel :: < ChanSigner > :: get_remote_channel_reserve_satoshis ( self . channel_value_satoshis ) ;
1852
+ if self . channel_value_satoshis - self . value_to_self_msat / 1000 < total_fee + remote_reserve_we_require {
1851
1853
return Err ( ( None , ChannelError :: Close ( "Funding remote cannot afford proposed new fee" ) ) ) ;
1852
1854
}
1853
1855
}
@@ -3033,7 +3035,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
3033
3035
ChannelValueStat {
3034
3036
value_to_self_msat : self . value_to_self_msat ,
3035
3037
channel_value_msat : self . channel_value_satoshis * 1000 ,
3036
- channel_reserve_msat : self . their_channel_reserve_satoshis * 1000 ,
3038
+ channel_reserve_msat : self . local_channel_reserve_satoshis * 1000 ,
3037
3039
pending_outbound_htlcs_amount_msat : self . pending_outbound_htlcs . iter ( ) . map ( |ref h| h. amount_msat ) . sum :: < u64 > ( ) ,
3038
3040
pending_inbound_htlcs_amount_msat : self . pending_inbound_htlcs . iter ( ) . map ( |ref h| h. amount_msat ) . sum :: < u64 > ( ) ,
3039
3041
holding_cell_outbound_amount_msat : {
@@ -3321,7 +3323,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
3321
3323
push_msat : self . channel_value_satoshis * 1000 - self . value_to_self_msat ,
3322
3324
dust_limit_satoshis : self . our_dust_limit_satoshis ,
3323
3325
max_htlc_value_in_flight_msat : Channel :: < ChanSigner > :: get_our_max_htlc_value_in_flight_msat ( self . channel_value_satoshis ) ,
3324
- channel_reserve_satoshis : Channel :: < ChanSigner > :: get_our_channel_reserve_satoshis ( self . channel_value_satoshis ) ,
3326
+ channel_reserve_satoshis : Channel :: < ChanSigner > :: get_remote_channel_reserve_satoshis ( self . channel_value_satoshis ) ,
3325
3327
htlc_minimum_msat : self . our_htlc_minimum_msat ,
3326
3328
feerate_per_kw : fee_estimator. get_est_sat_per_1000_weight ( ConfirmationTarget :: Background ) as u32 ,
3327
3329
to_self_delay : self . our_to_self_delay ,
@@ -3354,7 +3356,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
3354
3356
temporary_channel_id : self . channel_id ,
3355
3357
dust_limit_satoshis : self . our_dust_limit_satoshis ,
3356
3358
max_htlc_value_in_flight_msat : Channel :: < ChanSigner > :: get_our_max_htlc_value_in_flight_msat ( self . channel_value_satoshis ) ,
3357
- channel_reserve_satoshis : Channel :: < ChanSigner > :: get_our_channel_reserve_satoshis ( self . channel_value_satoshis ) ,
3359
+ channel_reserve_satoshis : Channel :: < ChanSigner > :: get_remote_channel_reserve_satoshis ( self . channel_value_satoshis ) ,
3358
3360
htlc_minimum_msat : self . our_htlc_minimum_msat ,
3359
3361
minimum_depth : self . minimum_depth ,
3360
3362
to_self_delay : self . our_to_self_delay ,
@@ -3550,10 +3552,10 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
3550
3552
return Err ( ChannelError :: Ignore ( "Cannot send value that would put us over the max HTLC value in flight our peer will accept" ) ) ;
3551
3553
}
3552
3554
3553
- // Check self.their_channel_reserve_satoshis (the amount we must keep as
3554
- // reserve for them to have something to claim if we misbehave)
3555
- if self . value_to_self_msat < self . their_channel_reserve_satoshis * 1000 + amount_msat + htlc_outbound_value_msat {
3556
- return Err ( ChannelError :: Ignore ( "Cannot send value that would put us over their reserve value" ) ) ;
3555
+ // Check self.local_channel_reserve_satoshis (the amount we must keep as
3556
+ // reserve for the remote to have something to claim if we misbehave)
3557
+ if self . value_to_self_msat < self . local_channel_reserve_satoshis * 1000 + amount_msat + htlc_outbound_value_msat {
3558
+ return Err ( ChannelError :: Ignore ( "Cannot send value that would put us under local channel reserve value" ) ) ;
3557
3559
}
3558
3560
3559
3561
// Now update local state:
@@ -4019,7 +4021,7 @@ impl<ChanSigner: ChannelKeys + Writeable> Writeable for Channel<ChanSigner> {
4019
4021
self . their_dust_limit_satoshis . write ( writer) ?;
4020
4022
self . our_dust_limit_satoshis . write ( writer) ?;
4021
4023
self . their_max_htlc_value_in_flight_msat . write ( writer) ?;
4022
- self . their_channel_reserve_satoshis . write ( writer) ?;
4024
+ self . local_channel_reserve_satoshis . write ( writer) ?;
4023
4025
self . their_htlc_minimum_msat . write ( writer) ?;
4024
4026
self . our_htlc_minimum_msat . write ( writer) ?;
4025
4027
self . their_to_self_delay . write ( writer) ?;
@@ -4175,7 +4177,7 @@ impl<ChanSigner: ChannelKeys + Readable> ReadableArgs<Arc<Logger>> for Channel<C
4175
4177
let their_dust_limit_satoshis = Readable :: read ( reader) ?;
4176
4178
let our_dust_limit_satoshis = Readable :: read ( reader) ?;
4177
4179
let their_max_htlc_value_in_flight_msat = Readable :: read ( reader) ?;
4178
- let their_channel_reserve_satoshis = Readable :: read ( reader) ?;
4180
+ let local_channel_reserve_satoshis = Readable :: read ( reader) ?;
4179
4181
let their_htlc_minimum_msat = Readable :: read ( reader) ?;
4180
4182
let our_htlc_minimum_msat = Readable :: read ( reader) ?;
4181
4183
let their_to_self_delay = Readable :: read ( reader) ?;
@@ -4254,7 +4256,7 @@ impl<ChanSigner: ChannelKeys + Readable> ReadableArgs<Arc<Logger>> for Channel<C
4254
4256
their_dust_limit_satoshis,
4255
4257
our_dust_limit_satoshis,
4256
4258
their_max_htlc_value_in_flight_msat,
4257
- their_channel_reserve_satoshis ,
4259
+ local_channel_reserve_satoshis ,
4258
4260
their_htlc_minimum_msat,
4259
4261
our_htlc_minimum_msat,
4260
4262
their_to_self_delay,
0 commit comments