@@ -780,6 +780,9 @@ pub struct ChannelMonitor<ChanSigner: ChannelKeys> {
780
780
// Used just for ChannelManager to make sure it has the latest channel data during
781
781
// deserialization
782
782
current_remote_commitment_number : u64 ,
783
+ // Used just for ChannelManager to make sure it has the latest channel data during
784
+ // deserialization
785
+ current_local_commitment_number : u64 ,
783
786
784
787
payment_preimages : HashMap < PaymentHash , PaymentPreimage > ,
785
788
@@ -836,6 +839,7 @@ impl<ChanSigner: ChannelKeys> PartialEq for ChannelMonitor<ChanSigner> {
836
839
self . remote_hash_commitment_number != other. remote_hash_commitment_number ||
837
840
self . prev_local_signed_commitment_tx != other. prev_local_signed_commitment_tx ||
838
841
self . current_remote_commitment_number != other. current_remote_commitment_number ||
842
+ self . current_local_commitment_number != other. current_local_commitment_number ||
839
843
self . current_local_signed_commitment_tx != other. current_local_signed_commitment_tx ||
840
844
self . payment_preimages != other. payment_preimages ||
841
845
self . pending_htlcs_updated != other. pending_htlcs_updated ||
@@ -1008,6 +1012,12 @@ impl<ChanSigner: ChannelKeys + Writeable> ChannelMonitor<ChanSigner> {
1008
1012
writer. write_all ( & byte_utils:: be48_to_array ( 0 ) ) ?;
1009
1013
}
1010
1014
1015
+ if for_local_storage {
1016
+ writer. write_all ( & byte_utils:: be48_to_array ( self . current_local_commitment_number ) ) ?;
1017
+ } else {
1018
+ writer. write_all ( & byte_utils:: be48_to_array ( 0 ) ) ?;
1019
+ }
1020
+
1011
1021
writer. write_all ( & byte_utils:: be64_to_array ( self . payment_preimages . len ( ) as u64 ) ) ?;
1012
1022
for payment_preimage in self . payment_preimages . values ( ) {
1013
1023
writer. write_all ( & payment_preimage. 0 [ ..] ) ?;
@@ -1126,6 +1136,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1126
1136
prev_local_signed_commitment_tx : None ,
1127
1137
current_local_signed_commitment_tx : None ,
1128
1138
current_remote_commitment_number : 1 << 48 ,
1139
+ current_local_commitment_number : 0xffff_ffff_ffff ,
1129
1140
1130
1141
payment_preimages : HashMap :: new ( ) ,
1131
1142
pending_htlcs_updated : Vec :: new ( ) ,
@@ -1262,6 +1273,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1262
1273
if let Err ( _) = self . onchain_tx_handler . provide_latest_local_tx ( commitment_tx. clone ( ) ) {
1263
1274
return Err ( MonitorUpdateError ( "Local commitment signed has already been signed, no further update of LOCAL commitment transaction is allowed" ) ) ;
1264
1275
}
1276
+ self . current_local_commitment_number = 0xffff_ffff_ffff - ( ( ( ( commitment_tx. without_valid_witness ( ) . input [ 0 ] . sequence as u64 & 0xffffff ) << 3 * 8 ) | ( commitment_tx. without_valid_witness ( ) . lock_time as u64 & 0xffffff ) ) ^ self . commitment_transaction_number_obscure_factor ) ;
1265
1277
self . prev_local_signed_commitment_tx = self . current_local_signed_commitment_tx . take ( ) ;
1266
1278
self . current_local_signed_commitment_tx = Some ( LocalSignedTx {
1267
1279
txid : commitment_tx. txid ( ) ,
@@ -1415,9 +1427,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1415
1427
}
1416
1428
1417
1429
pub ( super ) fn get_cur_local_commitment_number ( & self ) -> u64 {
1418
- if let & Some ( ref local_tx) = & self . current_local_signed_commitment_tx {
1419
- 0xffff_ffff_ffff - ( ( ( ( local_tx. tx . without_valid_witness ( ) . input [ 0 ] . sequence as u64 & 0xffffff ) << 3 * 8 ) | ( local_tx. tx . without_valid_witness ( ) . lock_time as u64 & 0xffffff ) ) ^ self . commitment_transaction_number_obscure_factor )
1420
- } else { 0xffff_ffff_ffff }
1430
+ self . current_local_commitment_number
1421
1431
}
1422
1432
1423
1433
/// Attempts to claim a remote commitment transaction's outputs using the revocation key and
@@ -2415,6 +2425,7 @@ impl<ChanSigner: ChannelKeys + Readable> ReadableArgs<Arc<Logger>> for (Sha256dH
2415
2425
} ;
2416
2426
2417
2427
let current_remote_commitment_number = <U48 as Readable >:: read ( reader) ?. 0 ;
2428
+ let current_local_commitment_number = <U48 as Readable >:: read ( reader) ?. 0 ;
2418
2429
2419
2430
let payment_preimages_len: u64 = Readable :: read ( reader) ?;
2420
2431
let mut payment_preimages = HashMap :: with_capacity ( cmp:: min ( payment_preimages_len as usize , MAX_ALLOC_SIZE / 32 ) ) ;
@@ -2512,6 +2523,7 @@ impl<ChanSigner: ChannelKeys + Readable> ReadableArgs<Arc<Logger>> for (Sha256dH
2512
2523
prev_local_signed_commitment_tx,
2513
2524
current_local_signed_commitment_tx,
2514
2525
current_remote_commitment_number,
2526
+ current_local_commitment_number,
2515
2527
2516
2528
payment_preimages,
2517
2529
pending_htlcs_updated,
0 commit comments