@@ -647,8 +647,8 @@ pub struct UnsignedChannelUpdate {
647647 pub cltv_expiry_delta : u16 ,
648648 /// The minimum HTLC size incoming to sender, in milli-satoshi
649649 pub htlc_minimum_msat : u64 ,
650- /// Optionally, the maximum HTLC value incoming to sender, in milli-satoshi
651- pub htlc_maximum_msat : OptionalField < u64 > ,
650+ /// The maximum HTLC value incoming to sender, in milli-satoshi. Used to be optional.
651+ pub htlc_maximum_msat : u64 ,
652652 /// The base HTLC fee charged by sender, in milli-satoshi
653653 pub fee_base_msat : u32 ,
654654 /// The amount to fee multiplier, in micro-satoshi
@@ -1514,14 +1514,12 @@ impl_writeable!(ChannelAnnouncement, {
15141514
15151515impl Writeable for UnsignedChannelUpdate {
15161516 fn write < W : Writer > ( & self , w : & mut W ) -> Result < ( ) , io:: Error > {
1517- let mut message_flags: u8 = 0 ;
1518- if let OptionalField :: Present ( _) = self . htlc_maximum_msat {
1519- message_flags = 1 ;
1520- }
1517+ // `message_flags` used to indicate presence of `htlc_maximum_msat`, but was deprecated in the spec.
1518+ const MESSAGE_FLAGS : u8 = 1 ;
15211519 self . chain_hash . write ( w) ?;
15221520 self . short_channel_id . write ( w) ?;
15231521 self . timestamp . write ( w) ?;
1524- let all_flags = self . flags as u16 | ( ( message_flags as u16 ) << 8 ) ;
1522+ let all_flags = self . flags as u16 | ( ( MESSAGE_FLAGS as u16 ) << 8 ) ;
15251523 all_flags. write ( w) ?;
15261524 self . cltv_expiry_delta . write ( w) ?;
15271525 self . htlc_minimum_msat . write ( w) ?;
@@ -1535,22 +1533,20 @@ impl Writeable for UnsignedChannelUpdate {
15351533
15361534impl Readable for UnsignedChannelUpdate {
15371535 fn read < R : Read > ( r : & mut R ) -> Result < Self , DecodeError > {
1538- let has_htlc_maximum_msat;
15391536 Ok ( Self {
15401537 chain_hash : Readable :: read ( r) ?,
15411538 short_channel_id : Readable :: read ( r) ?,
15421539 timestamp : Readable :: read ( r) ?,
15431540 flags : {
15441541 let flags: u16 = Readable :: read ( r) ?;
1545- let message_flags = flags >> 8 ;
1546- has_htlc_maximum_msat = ( message_flags as i32 & 1 ) == 1 ;
1542+ // Note: we ignore the `message_flags` for now, since it was deprecated by the spec.
15471543 flags as u8
15481544 } ,
15491545 cltv_expiry_delta : Readable :: read ( r) ?,
15501546 htlc_minimum_msat : Readable :: read ( r) ?,
15511547 fee_base_msat : Readable :: read ( r) ?,
15521548 fee_proportional_millionths : Readable :: read ( r) ?,
1553- htlc_maximum_msat : if has_htlc_maximum_msat { Readable :: read ( r) ? } else { OptionalField :: Absent } ,
1549+ htlc_maximum_msat : Readable :: read ( r) ?,
15541550 excess_data : read_to_end ( r) ?,
15551551 } )
15561552 }
@@ -2103,7 +2099,7 @@ mod tests {
21032099 do_encoding_node_announcement ( false , false , true , false , true , false , false , false ) ;
21042100 }
21052101
2106- fn do_encoding_channel_update ( direction : bool , disable : bool , htlc_maximum_msat : bool , excess_data : bool ) {
2102+ fn do_encoding_channel_update ( direction : bool , disable : bool , excess_data : bool ) {
21072103 let secp_ctx = Secp256k1 :: new ( ) ;
21082104 let ( privkey_1, _) = get_keys_from ! ( "0101010101010101010101010101010101010101010101010101010101010101" , secp_ctx) ;
21092105 let sig_1 = get_sig_on ! ( privkey_1, secp_ctx, String :: from( "01010101010101010101010101010101" ) ) ;
@@ -2114,7 +2110,7 @@ mod tests {
21142110 flags : if direction { 1 } else { 0 } | if disable { 1 << 1 } else { 0 } ,
21152111 cltv_expiry_delta : 144 ,
21162112 htlc_minimum_msat : 1000000 ,
2117- htlc_maximum_msat : if htlc_maximum_msat { OptionalField :: Present ( 131355275467161 ) } else { OptionalField :: Absent } ,
2113+ htlc_maximum_msat : 131355275467161 ,
21182114 fee_base_msat : 10000 ,
21192115 fee_proportional_millionths : 20 ,
21202116 excess_data : if excess_data { vec ! [ 0 , 0 , 0 , 0 , 59 , 154 , 202 , 0 ] } else { Vec :: new ( ) }
@@ -2127,11 +2123,7 @@ mod tests {
21272123 let mut target_value = hex:: decode ( "d977cb9b53d93a6ff64bb5f1e158b4094b66e798fb12911168a3ccdf80a83096340a6a95da0ae8d9f776528eecdbb747eb6b545495a4319ed5378e35b21e073a" ) . unwrap ( ) ;
21282124 target_value. append ( & mut hex:: decode ( "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f" ) . unwrap ( ) ) ;
21292125 target_value. append ( & mut hex:: decode ( "00083a840000034d013413a7" ) . unwrap ( ) ) ;
2130- if htlc_maximum_msat {
2131- target_value. append ( & mut hex:: decode ( "01" ) . unwrap ( ) ) ;
2132- } else {
2133- target_value. append ( & mut hex:: decode ( "00" ) . unwrap ( ) ) ;
2134- }
2126+ target_value. append ( & mut hex:: decode ( "01" ) . unwrap ( ) ) ;
21352127 target_value. append ( & mut hex:: decode ( "00" ) . unwrap ( ) ) ;
21362128 if direction {
21372129 let flag = target_value. last_mut ( ) . unwrap ( ) ;
@@ -2142,9 +2134,7 @@ mod tests {
21422134 * flag = * flag | 1 << 1 ;
21432135 }
21442136 target_value. append ( & mut hex:: decode ( "009000000000000f42400000271000000014" ) . unwrap ( ) ) ;
2145- if htlc_maximum_msat {
2146- target_value. append ( & mut hex:: decode ( "0000777788889999" ) . unwrap ( ) ) ;
2147- }
2137+ target_value. append ( & mut hex:: decode ( "0000777788889999" ) . unwrap ( ) ) ;
21482138 if excess_data {
21492139 target_value. append ( & mut hex:: decode ( "000000003b9aca00" ) . unwrap ( ) ) ;
21502140 }
@@ -2153,16 +2143,14 @@ mod tests {
21532143
21542144 #[ test]
21552145 fn encoding_channel_update ( ) {
2156- do_encoding_channel_update ( false , false , false , false ) ;
2157- do_encoding_channel_update ( false , false , false , true ) ;
2158- do_encoding_channel_update ( true , false , false , false ) ;
2159- do_encoding_channel_update ( true , false , false , true ) ;
2160- do_encoding_channel_update ( false , true , false , false ) ;
2161- do_encoding_channel_update ( false , true , false , true ) ;
2162- do_encoding_channel_update ( false , false , true , false ) ;
2163- do_encoding_channel_update ( false , false , true , true ) ;
2164- do_encoding_channel_update ( true , true , true , false ) ;
2165- do_encoding_channel_update ( true , true , true , true ) ;
2146+ do_encoding_channel_update ( false , false , false ) ;
2147+ do_encoding_channel_update ( false , false , true ) ;
2148+ do_encoding_channel_update ( true , false , false ) ;
2149+ do_encoding_channel_update ( true , false , true ) ;
2150+ do_encoding_channel_update ( false , true , false ) ;
2151+ do_encoding_channel_update ( false , true , true ) ;
2152+ do_encoding_channel_update ( true , true , false ) ;
2153+ do_encoding_channel_update ( true , true , true ) ;
21662154 }
21672155
21682156 fn do_encoding_open_channel ( random_bit : bool , shutdown : bool , incl_chan_type : bool ) {
0 commit comments