@@ -281,7 +281,7 @@ pub struct ChannelReestablish {
281
281
pub next_local_commitment_number : u64 ,
282
282
pub next_remote_commitment_number : u64 ,
283
283
pub your_last_per_commitment_secret : Option < [ u8 ; 32 ] > ,
284
- pub my_current_per_commitment_point : PublicKey ,
284
+ pub my_current_per_commitment_point : Option < PublicKey > ,
285
285
}
286
286
287
287
#[ derive( Clone ) ]
@@ -1118,48 +1118,43 @@ impl MsgEncodable for UpdateFee {
1118
1118
1119
1119
impl MsgDecodable for ChannelReestablish {
1120
1120
fn decode ( v : & [ u8 ] ) -> Result < Self , DecodeError > {
1121
- if v. len ( ) < 32 +2 * 8 + 33 {
1121
+ if v. len ( ) < 32 +2 * 8 {
1122
1122
return Err ( DecodeError :: ShortRead ) ;
1123
1123
}
1124
1124
1125
- let your_last_per_commitment_secret = if v. len ( ) > 32 +2 * 8 + 33 {
1126
- if v. len ( ) < 32 +2 * 8 + 33 + 32 {
1125
+ let ( your_last_per_commitment_secret, my_current_per_commitment_point ) = if v. len ( ) > 32 +2 * 8 {
1126
+ if v. len ( ) < 32 +2 * 8 + 33 + 32 {
1127
1127
return Err ( DecodeError :: ShortRead ) ;
1128
1128
}
1129
1129
let mut inner_array = [ 0 ; 32 ] ;
1130
1130
inner_array. copy_from_slice ( & v[ 48 ..48 +32 ] ) ;
1131
- Some ( inner_array)
1132
- } else { None } ;
1131
+ ( Some ( inner_array) , {
1132
+ let ctx = Secp256k1 :: without_caps ( ) ;
1133
+ Some ( secp_pubkey ! ( & ctx, & v[ 48 +32 ..48 +32 +33 ] ) )
1134
+ } )
1135
+ } else { ( None , None ) } ;
1133
1136
1134
- let option_size = match & your_last_per_commitment_secret {
1135
- & Some ( ref _ary) => 32 ,
1136
- & None => 0 ,
1137
- } ;
1138
1137
Ok ( Self {
1139
1138
channel_id : deserialize ( & v[ 0 ..32 ] ) . unwrap ( ) ,
1140
1139
next_local_commitment_number : byte_utils:: slice_to_be64 ( & v[ 32 ..40 ] ) ,
1141
1140
next_remote_commitment_number : byte_utils:: slice_to_be64 ( & v[ 40 ..48 ] ) ,
1142
1141
your_last_per_commitment_secret : your_last_per_commitment_secret,
1143
- my_current_per_commitment_point : {
1144
- let ctx = Secp256k1 :: without_caps ( ) ;
1145
- secp_pubkey ! ( & ctx, & v[ 48 +option_size..48 +option_size+33 ] )
1146
- }
1142
+ my_current_per_commitment_point : my_current_per_commitment_point,
1147
1143
} )
1148
1144
}
1149
1145
}
1150
1146
impl MsgEncodable for ChannelReestablish {
1151
1147
fn encode ( & self ) -> Vec < u8 > {
1152
- let mut res = Vec :: with_capacity ( if self . your_last_per_commitment_secret . is_some ( ) { 32 +2 * 3 +33 + 32 } else { 32 +2 * 8 + 33 } ) ;
1148
+ let mut res = Vec :: with_capacity ( if self . your_last_per_commitment_secret . is_some ( ) { 32 +2 * 8 +33 + 32 } else { 32 +2 * 8 } ) ;
1153
1149
1154
1150
res. extend_from_slice ( & serialize ( & self . channel_id ) . unwrap ( ) [ ..] ) ;
1155
1151
res. extend_from_slice ( & byte_utils:: be64_to_array ( self . next_local_commitment_number ) ) ;
1156
1152
res. extend_from_slice ( & byte_utils:: be64_to_array ( self . next_remote_commitment_number ) ) ;
1157
1153
1158
1154
if let & Some ( ref ary) = & self . your_last_per_commitment_secret {
1159
1155
res. extend_from_slice ( & ary[ ..] ) ;
1156
+ res. extend_from_slice ( & self . my_current_per_commitment_point . expect ( "my_current_per_commitment_point should have been filled" ) . serialize ( ) ) ;
1160
1157
}
1161
-
1162
- res. extend_from_slice ( & self . my_current_per_commitment_point . serialize ( ) ) ;
1163
1158
res
1164
1159
}
1165
1160
}
0 commit comments