@@ -107,7 +107,7 @@ where
107
107
lsps2_client_handler : Option < LSPS2ClientHandler < ES > > ,
108
108
service_config : Option < LiquidityServiceConfig > ,
109
109
_client_config : Option < LiquidityClientConfig > ,
110
- best_block : Option < RwLock < BestBlock > > ,
110
+ best_block : RwLock < Option < BestBlock > > ,
111
111
_chain_source : Option < C > ,
112
112
}
113
113
@@ -215,7 +215,7 @@ where {
215
215
lsps2_service_handler,
216
216
service_config,
217
217
_client_config : client_config,
218
- best_block : chain_params. map ( |chain_params| RwLock :: new ( chain_params. best_block ) ) ,
218
+ best_block : RwLock :: new ( chain_params. map ( |chain_params| chain_params. best_block ) ) ,
219
219
_chain_source : chain_source,
220
220
}
221
221
}
@@ -642,8 +642,7 @@ where
642
642
& self , header : & bitcoin:: block:: Header , txdata : & chain:: transaction:: TransactionData ,
643
643
height : u32 ,
644
644
) {
645
- if let Some ( best_block) = & self . best_block {
646
- let best_block = best_block. read ( ) . unwrap ( ) ;
645
+ if let Some ( best_block) = self . best_block . read ( ) . unwrap ( ) . as_ref ( ) {
647
646
assert_eq ! ( best_block. block_hash, header. prev_blockhash,
648
647
"Blocks must be connected in chain-order - the connected header must build on the last connected header" ) ;
649
648
assert_eq ! ( best_block. height, height - 1 ,
@@ -656,8 +655,7 @@ where
656
655
657
656
fn block_disconnected ( & self , header : & bitcoin:: block:: Header , height : u32 ) {
658
657
let new_height = height - 1 ;
659
- if let Some ( best_block) = & self . best_block {
660
- let mut best_block = best_block. write ( ) . unwrap ( ) ;
658
+ if let Some ( best_block) = self . best_block . write ( ) . unwrap ( ) . as_mut ( ) {
661
659
assert_eq ! ( best_block. block_hash, header. block_hash( ) ,
662
660
"Blocks must be disconnected in chain-order - the disconnected header must be the last connected header" ) ;
663
661
assert_eq ! ( best_block. height, height,
@@ -690,7 +688,10 @@ where
690
688
// confirmed at a height <= the one we now unconfirmed.
691
689
}
692
690
693
- fn best_block_updated ( & self , _header : & bitcoin:: block:: Header , _height : u32 ) {
691
+ fn best_block_updated ( & self , header : & bitcoin:: block:: Header , height : u32 ) {
692
+ let new_best_block = BestBlock :: new ( header. block_hash ( ) , height) ;
693
+ * self . best_block . write ( ) . unwrap ( ) = Some ( new_best_block) ;
694
+
694
695
// TODO: Call best_block_updated on all sub-modules that require it, e.g., LSPS1MessageHandler.
695
696
if let Some ( lsps2_service_handler) = self . lsps2_service_handler . as_ref ( ) {
696
697
lsps2_service_handler. prune_peer_state ( ) ;
0 commit comments