@@ -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 ( ) ,
@@ -1266,6 +1277,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1266
1277
feerate_per_kw,
1267
1278
htlc_outputs,
1268
1279
} ) ;
1280
+ 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 ) ;
1269
1281
self . onchain_tx_handler . provide_latest_local_tx ( commitment_tx) ;
1270
1282
Ok ( ( ) )
1271
1283
}
@@ -1408,9 +1420,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1408
1420
}
1409
1421
1410
1422
pub ( super ) fn get_cur_local_commitment_number ( & self ) -> u64 {
1411
- if let & Some ( ref local_tx) = & self . current_local_signed_commitment_tx {
1412
- 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 )
1413
- } else { 0xffff_ffff_ffff }
1423
+ self . current_local_commitment_number
1414
1424
}
1415
1425
1416
1426
/// Attempts to claim a remote commitment transaction's outputs using the revocation key and
@@ -2408,6 +2418,7 @@ impl<ChanSigner: ChannelKeys + Readable> ReadableArgs<Arc<Logger>> for (Sha256dH
2408
2418
} ;
2409
2419
2410
2420
let current_remote_commitment_number = <U48 as Readable >:: read ( reader) ?. 0 ;
2421
+ let current_local_commitment_number = <U48 as Readable >:: read ( reader) ?. 0 ;
2411
2422
2412
2423
let payment_preimages_len: u64 = Readable :: read ( reader) ?;
2413
2424
let mut payment_preimages = HashMap :: with_capacity ( cmp:: min ( payment_preimages_len as usize , MAX_ALLOC_SIZE / 32 ) ) ;
@@ -2505,6 +2516,7 @@ impl<ChanSigner: ChannelKeys + Readable> ReadableArgs<Arc<Logger>> for (Sha256dH
2505
2516
prev_local_signed_commitment_tx,
2506
2517
current_local_signed_commitment_tx,
2507
2518
current_remote_commitment_number,
2519
+ current_local_commitment_number,
2508
2520
2509
2521
payment_preimages,
2510
2522
pending_htlcs_updated,
0 commit comments