@@ -276,12 +276,16 @@ pub struct UpdateFee {
276
276
pub feerate_per_kw : u32 ,
277
277
}
278
278
279
+ pub struct DataLossProtect {
280
+ pub your_last_per_commitment_secret : [ u8 ; 32 ] ,
281
+ pub my_current_per_commitment_point : PublicKey ,
282
+ }
283
+
279
284
pub struct ChannelReestablish {
280
285
pub channel_id : [ u8 ; 32 ] ,
281
286
pub next_local_commitment_number : u64 ,
282
287
pub next_remote_commitment_number : u64 ,
283
- pub your_last_per_commitment_secret : Option < [ u8 ; 32 ] > ,
284
- pub my_current_per_commitment_point : Option < PublicKey > ,
288
+ pub data_loss_protect : Option < DataLossProtect > ,
285
289
}
286
290
287
291
#[ derive( Clone ) ]
@@ -1122,38 +1126,37 @@ impl MsgDecodable for ChannelReestablish {
1122
1126
return Err ( DecodeError :: ShortRead ) ;
1123
1127
}
1124
1128
1125
- let ( your_last_per_commitment_secret , my_current_per_commitment_point ) = if v. len ( ) > 32 +2 * 8 {
1129
+ let data_loss_protect = if v. len ( ) > 32 +2 * 8 {
1126
1130
if v. len ( ) < 32 +2 * 8 + 33 +32 {
1127
1131
return Err ( DecodeError :: ShortRead ) ;
1128
1132
}
1129
1133
let mut inner_array = [ 0 ; 32 ] ;
1130
1134
inner_array. copy_from_slice ( & v[ 48 ..48 +32 ] ) ;
1131
- ( Some ( inner_array ) , {
1132
- let ctx = Secp256k1 :: without_caps ( ) ;
1133
- Some ( secp_pubkey ! ( & ctx , & v[ 48 +32 ..48 +32 +33 ] ) )
1135
+ Some ( DataLossProtect {
1136
+ your_last_per_commitment_secret : inner_array ,
1137
+ my_current_per_commitment_point : secp_pubkey ! ( & Secp256k1 :: without_caps ( ) , & v[ 48 +32 ..48 +32 +33 ] ) ,
1134
1138
} )
1135
- } else { ( None , None ) } ;
1139
+ } else { None } ;
1136
1140
1137
1141
Ok ( Self {
1138
1142
channel_id : deserialize ( & v[ 0 ..32 ] ) . unwrap ( ) ,
1139
1143
next_local_commitment_number : byte_utils:: slice_to_be64 ( & v[ 32 ..40 ] ) ,
1140
1144
next_remote_commitment_number : byte_utils:: slice_to_be64 ( & v[ 40 ..48 ] ) ,
1141
- your_last_per_commitment_secret : your_last_per_commitment_secret,
1142
- my_current_per_commitment_point : my_current_per_commitment_point,
1145
+ data_loss_protect : data_loss_protect,
1143
1146
} )
1144
1147
}
1145
1148
}
1146
1149
impl MsgEncodable for ChannelReestablish {
1147
1150
fn encode ( & self ) -> Vec < u8 > {
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 } ) ;
1151
+ let mut res = Vec :: with_capacity ( if self . data_loss_protect . is_some ( ) { 32 +2 * 8 +33 +32 } else { 32 +2 * 8 } ) ;
1149
1152
1150
1153
res. extend_from_slice ( & serialize ( & self . channel_id ) . unwrap ( ) [ ..] ) ;
1151
1154
res. extend_from_slice ( & byte_utils:: be64_to_array ( self . next_local_commitment_number ) ) ;
1152
1155
res. extend_from_slice ( & byte_utils:: be64_to_array ( self . next_remote_commitment_number ) ) ;
1153
1156
1154
- if let & Some ( ref ary ) = & self . your_last_per_commitment_secret {
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 ( ) ) ;
1157
+ if let & Some ( ref data_loss_protect ) = & self . data_loss_protect {
1158
+ res. extend_from_slice ( & data_loss_protect . your_last_per_commitment_secret [ ..] ) ;
1159
+ res. extend_from_slice ( & data_loss_protect . my_current_per_commitment_point . serialize ( ) ) ;
1157
1160
}
1158
1161
res
1159
1162
}
@@ -1663,8 +1666,7 @@ mod tests {
1663
1666
channel_id : [ 4 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 5 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 6 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 7 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ,
1664
1667
next_local_commitment_number : 3 ,
1665
1668
next_remote_commitment_number : 4 ,
1666
- your_last_per_commitment_secret : None ,
1667
- my_current_per_commitment_point : None ,
1669
+ data_loss_protect : None ,
1668
1670
} ;
1669
1671
1670
1672
let encoded_value = cr. encode ( ) ;
@@ -1685,8 +1687,7 @@ mod tests {
1685
1687
channel_id : [ 4 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 5 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 6 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 7 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ,
1686
1688
next_local_commitment_number : 3 ,
1687
1689
next_remote_commitment_number : 4 ,
1688
- your_last_per_commitment_secret : Some ( [ 9 ; 32 ] ) ,
1689
- my_current_per_commitment_point : Some ( public_key) ,
1690
+ data_loss_protect : Some ( msgs:: DataLossProtect { your_last_per_commitment_secret : [ 9 ; 32 ] , my_current_per_commitment_point : public_key} ) ,
1690
1691
} ;
1691
1692
1692
1693
let encoded_value = cr. encode ( ) ;
0 commit comments