@@ -3186,6 +3186,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3186
3186
pub fn block_connected ( & self , header : & BlockHeader , txdata : & TransactionData , height : u32 ) {
3187
3187
let block_hash = header. block_hash ( ) ;
3188
3188
log_trace ! ( self . logger, "Block {} at height {} connected" , block_hash, height) ;
3189
+
3189
3190
let _persistence_guard = PersistenceNotifierGuard :: new ( & self . total_consistency_lock , & self . persistence_notifier ) ;
3190
3191
let mut failed_channels = Vec :: new ( ) ;
3191
3192
let mut timed_out_htlcs = Vec :: new ( ) ;
@@ -3270,16 +3271,19 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3270
3271
} ) ;
3271
3272
!htlcs. is_empty ( ) // Only retain this entry if htlcs has at least one entry.
3272
3273
} ) ;
3274
+
3275
+ * self . last_block_hash . lock ( ) . unwrap ( ) = block_hash;
3276
+ self . latest_block_height . store ( height as usize , Ordering :: Release ) ;
3273
3277
}
3278
+
3274
3279
for failure in failed_channels. drain ( ..) {
3275
3280
self . finish_force_close_channel ( failure) ;
3276
3281
}
3277
3282
3278
3283
for ( source, payment_hash, reason) in timed_out_htlcs. drain ( ..) {
3279
3284
self . fail_htlc_backwards_internal ( self . channel_state . lock ( ) . unwrap ( ) , source, & payment_hash, reason) ;
3280
3285
}
3281
- self . latest_block_height . store ( height as usize , Ordering :: Release ) ;
3282
- * self . last_block_hash . try_lock ( ) . expect ( "block_(dis)connected must not be called in parallel" ) = block_hash;
3286
+
3283
3287
loop {
3284
3288
// Update last_node_announcement_serial to be the max of its current value and the
3285
3289
// block timestamp. This should keep us close to the current time without relying on
@@ -3322,12 +3326,14 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3322
3326
true
3323
3327
}
3324
3328
} ) ;
3329
+
3330
+ * self . last_block_hash . lock ( ) . unwrap ( ) = header. block_hash ( ) ;
3331
+ self . latest_block_height . fetch_sub ( 1 , Ordering :: AcqRel ) ;
3325
3332
}
3333
+
3326
3334
for failure in failed_channels. drain ( ..) {
3327
3335
self . finish_force_close_channel ( failure) ;
3328
3336
}
3329
- self . latest_block_height . fetch_sub ( 1 , Ordering :: AcqRel ) ;
3330
- * self . last_block_hash . try_lock ( ) . expect ( "block_(dis)connected must not be called in parallel" ) = header. block_hash ( ) ;
3331
3337
}
3332
3338
3333
3339
/// Blocks until ChannelManager needs to be persisted or a timeout is reached. It returns a bool
@@ -3881,11 +3887,12 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> Writeable f
3881
3887
writer. write_all ( & [ SERIALIZATION_VERSION ; 1 ] ) ?;
3882
3888
writer. write_all ( & [ MIN_SERIALIZATION_VERSION ; 1 ] ) ?;
3883
3889
3890
+ let channel_state = self . channel_state . lock ( ) . unwrap ( ) ;
3891
+
3884
3892
self . genesis_hash . write ( writer) ?;
3885
3893
( self . latest_block_height . load ( Ordering :: Acquire ) as u32 ) . write ( writer) ?;
3886
3894
self . last_block_hash . lock ( ) . unwrap ( ) . write ( writer) ?;
3887
3895
3888
- let channel_state = self . channel_state . lock ( ) . unwrap ( ) ;
3889
3896
let mut unfunded_channels = 0 ;
3890
3897
for ( _, channel) in channel_state. by_id . iter ( ) {
3891
3898
if !channel. is_funding_initiated ( ) {
0 commit comments