@@ -5384,10 +5384,16 @@ impl<Signer: Sign> Channel<Signer> {
5384
5384
if msg. contents . htlc_minimum_msat >= self . channel_value_satoshis * 1000 {
5385
5385
return Err ( ChannelError :: Close ( "Minimum htlc value is greater than channel value" . to_string ( ) ) ) ;
5386
5386
}
5387
+ let htlc_maximum_msat = match msg. contents . htlc_maximum_msat {
5388
+ OptionalField :: Present ( htcl_max) => Some ( htcl_max) ,
5389
+ OptionalField :: Absent => None
5390
+ } ;
5387
5391
self . counterparty_forwarding_info = Some ( CounterpartyForwardingInfo {
5388
5392
fee_base_msat : msg. contents . fee_base_msat ,
5389
5393
fee_proportional_millionths : msg. contents . fee_proportional_millionths ,
5390
- cltv_expiry_delta : msg. contents . cltv_expiry_delta
5394
+ cltv_expiry_delta : msg. contents . cltv_expiry_delta ,
5395
+ htlc_minimum_msat : msg. contents . htlc_minimum_msat ,
5396
+ htlc_maximum_msat,
5391
5397
} ) ;
5392
5398
5393
5399
Ok ( ( ) )
@@ -5774,12 +5780,16 @@ impl<Signer: Sign> Writeable for Channel<Signer> {
5774
5780
// Note that this field is ignored by 0.0.99+ as the TLV Optional variant is used instead.
5775
5781
self . minimum_depth . unwrap_or ( 0 ) . write ( writer) ?;
5776
5782
5783
+ let mut htlc_maximum_msat = None ;
5777
5784
match & self . counterparty_forwarding_info {
5778
5785
Some ( info) => {
5779
5786
1u8 . write ( writer) ?;
5780
5787
info. fee_base_msat . write ( writer) ?;
5781
5788
info. fee_proportional_millionths . write ( writer) ?;
5782
5789
info. cltv_expiry_delta . write ( writer) ?;
5790
+ // Note that this field is ignored by 0.0.99+ as the TLV Optional variant is used instead.
5791
+ info. htlc_maximum_msat . unwrap_or ( 0 ) . write ( writer) ?;
5792
+ htlc_maximum_msat = info. htlc_maximum_msat ;
5783
5793
} ,
5784
5794
None => 0u8 . write ( writer) ?
5785
5795
}
@@ -5842,6 +5852,7 @@ impl<Signer: Sign> Writeable for Channel<Signer> {
5842
5852
( 17 , self . announcement_sigs_state, required) ,
5843
5853
( 19 , self . latest_inbound_scid_alias, option) ,
5844
5854
( 21 , self . outbound_scid_alias, required) ,
5855
+ ( 23 , htlc_maximum_msat, option) ,
5845
5856
} ) ;
5846
5857
5847
5858
Ok ( ( ) )
@@ -6040,13 +6051,29 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<(&'a K, u32)> for Channel<Signer>
6040
6051
let _dummy: u32 = Readable :: read ( reader) ?;
6041
6052
}
6042
6053
6043
- let counterparty_forwarding_info = match <u8 as Readable >:: read ( reader) ? {
6044
- 0 => None ,
6045
- 1 => Some ( CounterpartyForwardingInfo {
6046
- fee_base_msat : Readable :: read ( reader) ?,
6047
- fee_proportional_millionths : Readable :: read ( reader) ?,
6048
- cltv_expiry_delta : Readable :: read ( reader) ?,
6049
- } ) ,
6054
+ // Read fields for `CounterpartyForwardingInfo`. As the `htlc_maximum_msat` may be
6055
+ // updated after the TLV Optional variant has been read depending on if they're used,
6056
+ // we construct the `CounterpartyForwardingInfo` struct after TLV Optional variants
6057
+ // have been read.
6058
+ let mut fee_base_msat: u32 = 0 ;
6059
+ let mut fee_proportional_millionths: u32 = 0 ;
6060
+ let mut cltv_expiry_delta: u16 = 0 ;
6061
+ let mut htlc_maximum_msat = None ;
6062
+ let has_forwarding_info = match <u8 as Readable >:: read ( reader) ? {
6063
+ 0 => false ,
6064
+ 1 => {
6065
+ fee_base_msat = Readable :: read ( reader) ?;
6066
+ fee_proportional_millionths = Readable :: read ( reader) ?;
6067
+ cltv_expiry_delta = Readable :: read ( reader) ?;
6068
+ if ver == 1 {
6069
+ // Read the old serialization from version 0.0.98.
6070
+ htlc_maximum_msat = Some ( Readable :: read ( reader) ?) ;
6071
+ } else {
6072
+ // Read the 8 bytes of backwards-compatibility data.
6073
+ let _dummy: u64 = Readable :: read ( reader) ?;
6074
+ }
6075
+ true
6076
+ } ,
6050
6077
_ => return Err ( DecodeError :: InvalidValue ) ,
6051
6078
} ;
6052
6079
@@ -6116,8 +6143,22 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<(&'a K, u32)> for Channel<Signer>
6116
6143
( 17 , announcement_sigs_state, option) ,
6117
6144
( 19 , latest_inbound_scid_alias, option) ,
6118
6145
( 21 , outbound_scid_alias, option) ,
6146
+ ( 23 , htlc_maximum_msat, option) ,
6119
6147
} ) ;
6120
6148
6149
+ // Construct the `CounterpartyForwardingInfo` after the TLV Optional variant for
6150
+ // `htlc_maximum_msat` has been read.
6151
+ let counterparty_forwarding_info = match has_forwarding_info {
6152
+ false => None ,
6153
+ true => Some ( CounterpartyForwardingInfo {
6154
+ fee_base_msat,
6155
+ fee_proportional_millionths,
6156
+ cltv_expiry_delta,
6157
+ htlc_minimum_msat : counterparty_htlc_minimum_msat,
6158
+ htlc_maximum_msat
6159
+ } )
6160
+ } ;
6161
+
6121
6162
if let Some ( preimages) = preimages_opt {
6122
6163
let mut iter = preimages. into_iter ( ) ;
6123
6164
for htlc in pending_outbound_htlcs. iter_mut ( ) {
0 commit comments