@@ -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 : PublicKey ,
288
+ pub data_loss_protect : Option < DataLossProtect > ,
285
289
}
286
290
287
291
#[ derive( Clone ) ]
@@ -1118,48 +1122,42 @@ impl MsgEncodable for UpdateFee {
1118
1122
1119
1123
impl MsgDecodable for ChannelReestablish {
1120
1124
fn decode ( v : & [ u8 ] ) -> Result < Self , DecodeError > {
1121
- if v. len ( ) < 32 +2 * 8 + 33 {
1125
+ if v. len ( ) < 32 +2 * 8 {
1122
1126
return Err ( DecodeError :: ShortRead ) ;
1123
1127
}
1124
1128
1125
- let your_last_per_commitment_secret = if v. len ( ) > 32 +2 * 8 + 33 {
1126
- if v. len ( ) < 32 +2 * 8 + 33 + 32 {
1129
+ let data_loss_protect = if v. len ( ) > 32 +2 * 8 {
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)
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 ] ) ,
1138
+ } )
1132
1139
} else { None } ;
1133
1140
1134
- let option_size = match & your_last_per_commitment_secret {
1135
- & Some ( ref _ary) => 32 ,
1136
- & None => 0 ,
1137
- } ;
1138
1141
Ok ( Self {
1139
1142
channel_id : deserialize ( & v[ 0 ..32 ] ) . unwrap ( ) ,
1140
1143
next_local_commitment_number : byte_utils:: slice_to_be64 ( & v[ 32 ..40 ] ) ,
1141
1144
next_remote_commitment_number : byte_utils:: slice_to_be64 ( & v[ 40 ..48 ] ) ,
1142
- 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
- }
1145
+ data_loss_protect : data_loss_protect,
1147
1146
} )
1148
1147
}
1149
1148
}
1150
1149
impl MsgEncodable for ChannelReestablish {
1151
1150
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 } ) ;
1151
+ let mut res = Vec :: with_capacity ( if self . data_loss_protect . is_some ( ) { 32 +2 * 8 +33 + 32 } else { 32 +2 * 8 } ) ;
1153
1152
1154
1153
res. extend_from_slice ( & serialize ( & self . channel_id ) . unwrap ( ) [ ..] ) ;
1155
1154
res. extend_from_slice ( & byte_utils:: be64_to_array ( self . next_local_commitment_number ) ) ;
1156
1155
res. extend_from_slice ( & byte_utils:: be64_to_array ( self . next_remote_commitment_number ) ) ;
1157
1156
1158
- if let & Some ( ref ary) = & self . your_last_per_commitment_secret {
1159
- res. extend_from_slice ( & ary[ ..] ) ;
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 ( ) ) ;
1160
1160
}
1161
-
1162
- res. extend_from_slice ( & self . my_current_per_commitment_point . serialize ( ) ) ;
1163
1161
res
1164
1162
}
1165
1163
}
@@ -1668,14 +1666,13 @@ mod tests {
1668
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 ] ,
1669
1667
next_local_commitment_number : 3 ,
1670
1668
next_remote_commitment_number : 4 ,
1671
- your_last_per_commitment_secret : None ,
1672
- my_current_per_commitment_point : public_key,
1669
+ data_loss_protect : None ,
1673
1670
} ;
1674
1671
1675
1672
let encoded_value = cr. encode ( ) ;
1676
1673
assert_eq ! (
1677
1674
encoded_value,
1678
- vec![ 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 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 3 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 4 , 3 , 27 , 132 , 197 , 86 , 123 , 18 , 100 , 64 , 153 , 93 , 62 , 213 , 170 , 186 , 5 , 101 , 215 , 30 , 24 , 52 , 96 , 72 , 25 , 255 , 156 , 23 , 245 , 233 , 213 , 221 , 7 , 143 ]
1675
+ vec![ 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 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 3 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 4 ]
1679
1676
) ;
1680
1677
}
1681
1678
@@ -1690,8 +1687,7 @@ mod tests {
1690
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 ] ,
1691
1688
next_local_commitment_number : 3 ,
1692
1689
next_remote_commitment_number : 4 ,
1693
- your_last_per_commitment_secret : Some ( [ 9 ; 32 ] ) ,
1694
- my_current_per_commitment_point : public_key,
1690
+ data_loss_protect : Some ( msgs:: DataLossProtect { your_last_per_commitment_secret : [ 9 ; 32 ] , my_current_per_commitment_point : public_key} ) ,
1695
1691
} ;
1696
1692
1697
1693
let encoded_value = cr. encode ( ) ;
0 commit comments