@@ -4310,6 +4310,11 @@ impl<Signer: Sign> Channel<Signer> {
4310
4310
self . counterparty_htlc_minimum_msat
4311
4311
}
4312
4312
4313
+ /// Allowed in any state (including after shutdown), but will return none before TheirInitSent
4314
+ pub fn get_counterparty_htlc_max_msat ( & self ) -> Option < u64 > {
4315
+ self . get_htlc_max_msat ( self . counterparty_max_htlc_value_in_flight_msat )
4316
+ }
4317
+
4313
4318
/// Allowed in any state (including after shutdown), but will return none before TheirInitSent
4314
4319
fn get_htlc_max_msat ( & self , inflight_value_of_party : u64 ) -> Option < u64 > {
4315
4320
if self . channel_state >= ChannelState :: TheirInitSent as u32 {
@@ -5389,10 +5394,16 @@ impl<Signer: Sign> Channel<Signer> {
5389
5394
if msg. contents . htlc_minimum_msat >= self . channel_value_satoshis * 1000 {
5390
5395
return Err ( ChannelError :: Close ( "Minimum htlc value is greater than channel value" . to_string ( ) ) ) ;
5391
5396
}
5397
+ let htlc_maximum_msat = match msg. contents . htlc_maximum_msat {
5398
+ OptionalField :: Present ( htcl_max) => Some ( htcl_max) ,
5399
+ OptionalField :: Absent => None
5400
+ } ;
5392
5401
self . counterparty_forwarding_info = Some ( CounterpartyForwardingInfo {
5393
5402
fee_base_msat : msg. contents . fee_base_msat ,
5394
5403
fee_proportional_millionths : msg. contents . fee_proportional_millionths ,
5395
- cltv_expiry_delta : msg. contents . cltv_expiry_delta
5404
+ cltv_expiry_delta : msg. contents . cltv_expiry_delta ,
5405
+ htlc_minimum_msat : msg. contents . htlc_minimum_msat ,
5406
+ htlc_maximum_msat,
5396
5407
} ) ;
5397
5408
5398
5409
Ok ( ( ) )
@@ -5779,12 +5790,16 @@ impl<Signer: Sign> Writeable for Channel<Signer> {
5779
5790
// Note that this field is ignored by 0.0.99+ as the TLV Optional variant is used instead.
5780
5791
self . minimum_depth . unwrap_or ( 0 ) . write ( writer) ?;
5781
5792
5793
+ let mut htlc_maximum_msat = None ;
5782
5794
match & self . counterparty_forwarding_info {
5783
5795
Some ( info) => {
5784
5796
1u8 . write ( writer) ?;
5785
5797
info. fee_base_msat . write ( writer) ?;
5786
5798
info. fee_proportional_millionths . write ( writer) ?;
5787
5799
info. cltv_expiry_delta . write ( writer) ?;
5800
+ // Note that this field is ignored by 0.0.99+ as the TLV Optional variant is used instead.
5801
+ info. htlc_maximum_msat . unwrap_or ( 0 ) . write ( writer) ?;
5802
+ htlc_maximum_msat = info. htlc_maximum_msat ;
5788
5803
} ,
5789
5804
None => 0u8 . write ( writer) ?
5790
5805
}
@@ -5847,6 +5862,7 @@ impl<Signer: Sign> Writeable for Channel<Signer> {
5847
5862
( 17 , self . announcement_sigs_state, required) ,
5848
5863
( 19 , self . latest_inbound_scid_alias, option) ,
5849
5864
( 21 , self . outbound_scid_alias, required) ,
5865
+ ( 23 , htlc_maximum_msat, option) ,
5850
5866
} ) ;
5851
5867
5852
5868
Ok ( ( ) )
@@ -6045,13 +6061,29 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<(&'a K, u32)> for Channel<Signer>
6045
6061
let _dummy: u32 = Readable :: read ( reader) ?;
6046
6062
}
6047
6063
6048
- let counterparty_forwarding_info = match <u8 as Readable >:: read ( reader) ? {
6049
- 0 => None ,
6050
- 1 => Some ( CounterpartyForwardingInfo {
6051
- fee_base_msat : Readable :: read ( reader) ?,
6052
- fee_proportional_millionths : Readable :: read ( reader) ?,
6053
- cltv_expiry_delta : Readable :: read ( reader) ?,
6054
- } ) ,
6064
+ // Read fields for `CounterpartyForwardingInfo`. As the `htlc_maximum_msat` may be
6065
+ // updated after the TLV Optional variant has been read depending on if they're used,
6066
+ // we construct the `CounterpartyForwardingInfo` struct after TLV Optional variants
6067
+ // have been read.
6068
+ let mut fee_base_msat: u32 = 0 ;
6069
+ let mut fee_proportional_millionths: u32 = 0 ;
6070
+ let mut cltv_expiry_delta: u16 = 0 ;
6071
+ let mut htlc_maximum_msat = None ;
6072
+ let has_forwarding_info = match <u8 as Readable >:: read ( reader) ? {
6073
+ 0 => false ,
6074
+ 1 => {
6075
+ fee_base_msat = Readable :: read ( reader) ?;
6076
+ fee_proportional_millionths = Readable :: read ( reader) ?;
6077
+ cltv_expiry_delta = Readable :: read ( reader) ?;
6078
+ if ver == 1 {
6079
+ // Read the old serialization from version 0.0.98.
6080
+ htlc_maximum_msat = Some ( Readable :: read ( reader) ?) ;
6081
+ } else {
6082
+ // Read the 8 bytes of backwards-compatibility data.
6083
+ let _dummy: u64 = Readable :: read ( reader) ?;
6084
+ }
6085
+ true
6086
+ } ,
6055
6087
_ => return Err ( DecodeError :: InvalidValue ) ,
6056
6088
} ;
6057
6089
@@ -6121,8 +6153,22 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<(&'a K, u32)> for Channel<Signer>
6121
6153
( 17 , announcement_sigs_state, option) ,
6122
6154
( 19 , latest_inbound_scid_alias, option) ,
6123
6155
( 21 , outbound_scid_alias, option) ,
6156
+ ( 23 , htlc_maximum_msat, option) ,
6124
6157
} ) ;
6125
6158
6159
+ // Construct the `CounterpartyForwardingInfo` after the TLV Optional variant for
6160
+ // `htlc_maximum_msat` has been read.
6161
+ let counterparty_forwarding_info = match has_forwarding_info {
6162
+ false => None ,
6163
+ true => Some ( CounterpartyForwardingInfo {
6164
+ fee_base_msat,
6165
+ fee_proportional_millionths,
6166
+ cltv_expiry_delta,
6167
+ htlc_minimum_msat : counterparty_htlc_minimum_msat,
6168
+ htlc_maximum_msat
6169
+ } )
6170
+ } ;
6171
+
6126
6172
if let Some ( preimages) = preimages_opt {
6127
6173
let mut iter = preimages. into_iter ( ) ;
6128
6174
for htlc in pending_outbound_htlcs. iter_mut ( ) {
0 commit comments