@@ -631,7 +631,6 @@ pub(super) struct Channel<Signer: Sign> {
631
631
#[ cfg( not( test) ) ]
632
632
holder_selected_channel_reserve_satoshis : u64 ,
633
633
634
- counterparty_htlc_minimum_msat : u64 ,
635
634
holder_htlc_minimum_msat : u64 ,
636
635
#[ cfg( test) ]
637
636
pub counterparty_max_accepted_htlcs : u16 ,
@@ -924,7 +923,6 @@ impl<Signer: Sign> Channel<Signer> {
924
923
holder_max_htlc_value_in_flight_msat : Self :: get_holder_max_htlc_value_in_flight_msat ( channel_value_satoshis) ,
925
924
counterparty_selected_channel_reserve_satoshis : None , // Filled in in accept_channel
926
925
holder_selected_channel_reserve_satoshis,
927
- counterparty_htlc_minimum_msat : 0 ,
928
926
holder_htlc_minimum_msat : if config. own_channel_config . our_htlc_minimum_msat == 0 { 1 } else { config. own_channel_config . our_htlc_minimum_msat } ,
929
927
counterparty_max_accepted_htlcs : 0 ,
930
928
minimum_depth : None , // Filled in in accept_channel
@@ -1230,12 +1228,17 @@ impl<Signer: Sign> Channel<Signer> {
1230
1228
holder_max_htlc_value_in_flight_msat : Self :: get_holder_max_htlc_value_in_flight_msat ( msg. funding_satoshis ) ,
1231
1229
counterparty_selected_channel_reserve_satoshis : Some ( msg. channel_reserve_satoshis ) ,
1232
1230
holder_selected_channel_reserve_satoshis,
1233
- counterparty_htlc_minimum_msat : msg. htlc_minimum_msat ,
1234
1231
holder_htlc_minimum_msat : if config. own_channel_config . our_htlc_minimum_msat == 0 { 1 } else { config. own_channel_config . our_htlc_minimum_msat } ,
1235
1232
counterparty_max_accepted_htlcs : msg. max_accepted_htlcs ,
1236
1233
minimum_depth : Some ( config. own_channel_config . minimum_depth ) ,
1237
1234
1238
- counterparty_forwarding_info : None ,
1235
+ counterparty_forwarding_info : Some ( CounterpartyForwardingInfo {
1236
+ fee_base_msat : 0 ,
1237
+ fee_proportional_millionths : 0 ,
1238
+ cltv_expiry_delta : 0 ,
1239
+ outbound_htlc_minimum_msat : Some ( msg. htlc_minimum_msat ) ,
1240
+ outbound_htlc_maximum_msat : None ,
1241
+ } ) ,
1239
1242
1240
1243
channel_transaction_parameters : ChannelTransactionParameters {
1241
1244
holder_pubkeys : pubkeys,
@@ -1949,8 +1952,15 @@ impl<Signer: Sign> Channel<Signer> {
1949
1952
self . counterparty_dust_limit_satoshis = msg. dust_limit_satoshis ;
1950
1953
self . counterparty_max_htlc_value_in_flight_msat = cmp:: min ( msg. max_htlc_value_in_flight_msat , self . channel_value_satoshis * 1000 ) ;
1951
1954
self . counterparty_selected_channel_reserve_satoshis = Some ( msg. channel_reserve_satoshis ) ;
1952
- self . counterparty_htlc_minimum_msat = msg. htlc_minimum_msat ;
1953
1955
self . counterparty_max_accepted_htlcs = msg. max_accepted_htlcs ;
1956
+ self . counterparty_forwarding_info = Some ( CounterpartyForwardingInfo {
1957
+ fee_base_msat : 0 ,
1958
+ fee_proportional_millionths : 0 ,
1959
+ cltv_expiry_delta : 0 ,
1960
+ outbound_htlc_minimum_msat : Some ( msg. htlc_minimum_msat ) ,
1961
+ outbound_htlc_maximum_msat : self . get_counterparty_htlc_maximum_msat ( ) ,
1962
+ } ) ;
1963
+
1954
1964
self . minimum_depth = Some ( msg. minimum_depth ) ;
1955
1965
1956
1966
let counterparty_pubkeys = ChannelPublicKeys {
@@ -4307,7 +4317,7 @@ impl<Signer: Sign> Channel<Signer> {
4307
4317
4308
4318
/// Allowed in any state (including after shutdown)
4309
4319
pub fn get_counterparty_htlc_minimum_msat ( & self ) -> u64 {
4310
- self . counterparty_htlc_minimum_msat
4320
+ self . counterparty_forwarding_info . as_ref ( ) . map ( |info| info . outbound_htlc_minimum_msat . unwrap_or ( 0 ) ) . unwrap_or ( 0 )
4311
4321
}
4312
4322
4313
4323
/// Allowed in any state (including after shutdown), but will return none before TheirInitSent
@@ -5103,8 +5113,9 @@ impl<Signer: Sign> Channel<Signer> {
5103
5113
return Err ( ChannelError :: Ignore ( "Cannot send 0-msat HTLC" . to_owned ( ) ) ) ;
5104
5114
}
5105
5115
5106
- if amount_msat < self . counterparty_htlc_minimum_msat {
5107
- return Err ( ChannelError :: Ignore ( format ! ( "Cannot send less than their minimum HTLC value ({})" , self . counterparty_htlc_minimum_msat) ) ) ;
5116
+ let counterparty_htlc_minimum_msat = self . get_counterparty_htlc_minimum_msat ( ) ;
5117
+ if amount_msat < counterparty_htlc_minimum_msat {
5118
+ return Err ( ChannelError :: Ignore ( format ! ( "Cannot send less than their minimum HTLC value ({})" , counterparty_htlc_minimum_msat) ) ) ;
5108
5119
}
5109
5120
5110
5121
if ( self . channel_state & ( ChannelState :: PeerDisconnected as u32 ) ) != 0 {
@@ -5775,7 +5786,11 @@ impl<Signer: Sign> Writeable for Channel<Signer> {
5775
5786
// Note that this field is ignored by 0.0.99+ as the TLV Optional variant is used instead.
5776
5787
self . counterparty_selected_channel_reserve_satoshis . unwrap_or ( 0 ) . write ( writer) ?;
5777
5788
5778
- self . counterparty_htlc_minimum_msat . write ( writer) ?;
5789
+ // Versions prior to 0.0.107, stored the `outbound_htlc_minimum_msat` field as a
5790
+ // non-optional field of the `Channel` struct, which was written here. It has since been
5791
+ // refactored to be part of the `CounterpartyForwardingInfo` struct.
5792
+ self . counterparty_forwarding_info . as_ref ( )
5793
+ . map ( |info| info. outbound_htlc_minimum_msat . unwrap_or ( 0 ) ) . unwrap_or ( 0 ) . write ( writer) ?;
5779
5794
self . holder_htlc_minimum_msat . write ( writer) ?;
5780
5795
self . counterparty_max_accepted_htlcs . write ( writer) ?;
5781
5796
@@ -6036,7 +6051,10 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<(&'a K, u32)> for Channel<Signer>
6036
6051
// Read the 8 bytes of backwards-compatibility data.
6037
6052
let _dummy: u64 = Readable :: read ( reader) ?;
6038
6053
}
6039
- let counterparty_htlc_minimum_msat = Readable :: read ( reader) ?;
6054
+ // Versions prior to 0.0.107, stored the `outbound_htlc_minimum_msat` field as a
6055
+ // non-optional field of the `Channel` struct, which has since been refactored to be part
6056
+ // of the `CounterpartyForwardingInfo` struct. It's therefore read here.
6057
+ let outbound_htlc_minimum_msat = Readable :: read ( reader) ?;
6040
6058
let holder_htlc_minimum_msat = Readable :: read ( reader) ?;
6041
6059
let counterparty_max_accepted_htlcs = Readable :: read ( reader) ?;
6042
6060
@@ -6055,7 +6073,7 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<(&'a K, u32)> for Channel<Signer>
6055
6073
fee_base_msat : Readable :: read ( reader) ?,
6056
6074
fee_proportional_millionths : Readable :: read ( reader) ?,
6057
6075
cltv_expiry_delta : Readable :: read ( reader) ?,
6058
- outbound_htlc_minimum_msat : Some ( counterparty_htlc_minimum_msat ) ,
6076
+ outbound_htlc_minimum_msat : Some ( outbound_htlc_minimum_msat ) ,
6059
6077
outbound_htlc_maximum_msat : None ,
6060
6078
} ) ,
6061
6079
_ => return Err ( DecodeError :: InvalidValue ) ,
@@ -6238,7 +6256,6 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<(&'a K, u32)> for Channel<Signer>
6238
6256
holder_max_htlc_value_in_flight_msat : holder_max_htlc_value_in_flight_msat. unwrap ( ) ,
6239
6257
counterparty_selected_channel_reserve_satoshis,
6240
6258
holder_selected_channel_reserve_satoshis : holder_selected_channel_reserve_satoshis. unwrap ( ) ,
6241
- counterparty_htlc_minimum_msat,
6242
6259
holder_htlc_minimum_msat,
6243
6260
counterparty_max_accepted_htlcs,
6244
6261
minimum_depth,
0 commit comments