@@ -115,24 +115,19 @@ impl HeaderChain {
115115 }
116116 }
117117
118- /// Inserts a bootstrap header into backing cache database.
119- /// Makes the imported header the best header.
120- /// Expects the header to be valid and already verified.
118+ /// Inserts a floating header into backing cache database.
119+ /// Expects the header to be valid.
121120 /// If the header is already known, does nothing.
122- // FIXME: Find better return type. Returning `None` at duplication is not natural
123- pub fn insert_bootstrap_header ( & self , batch : & mut DBTransaction , header : & HeaderView ) {
121+ pub fn insert_floating_header ( & self , batch : & mut DBTransaction , header : & HeaderView ) {
124122 let hash = header. hash ( ) ;
125123
126- ctrace ! ( HEADERCHAIN , "Inserting bootstrap block header #{}({}) to the headerchain." , header. number( ) , hash) ;
124+ ctrace ! ( HEADERCHAIN , "Inserting a floating block header #{}({}) to the headerchain." , header. number( ) , hash) ;
127125
128126 if self . is_known_header ( & hash) {
129127 ctrace ! ( HEADERCHAIN , "Block header #{}({}) is already known." , header. number( ) , hash) ;
130128 return
131129 }
132130
133- assert ! ( self . pending_best_header_hash. read( ) . is_none( ) ) ;
134- assert ! ( self . pending_best_proposal_block_hash. read( ) . is_none( ) ) ;
135-
136131 let compressed_header = compress ( header. rlp ( ) . as_raw ( ) , blocks_swapper ( ) ) ;
137132 batch. put ( db:: COL_HEADERS , & hash, & compressed_header) ;
138133
@@ -145,18 +140,25 @@ impl HeaderChain {
145140 parent : header. parent_hash ( ) ,
146141 } ) ;
147142
148- batch. put ( db:: COL_EXTRA , BEST_HEADER_KEY , & hash) ;
149- * self . pending_best_header_hash . write ( ) = Some ( hash) ;
150- batch. put ( db:: COL_EXTRA , BEST_PROPOSAL_HEADER_KEY , & hash) ;
151- * self . pending_best_proposal_block_hash . write ( ) = Some ( hash) ;
152-
153143 let mut pending_hashes = self . pending_hashes . write ( ) ;
154144 let mut pending_details = self . pending_details . write ( ) ;
155145
156146 batch. extend_with_cache ( db:: COL_EXTRA , & mut * pending_details, new_details, CacheUpdatePolicy :: Overwrite ) ;
157147 batch. extend_with_cache ( db:: COL_EXTRA , & mut * pending_hashes, new_hashes, CacheUpdatePolicy :: Overwrite ) ;
158148 }
159149
150+ pub fn force_update_best_header ( & self , batch : & mut DBTransaction , hash : & BlockHash ) {
151+ ctrace ! ( HEADERCHAIN , "Forcefully updating the best header to {}" , hash) ;
152+ assert ! ( self . is_known_header( hash) ) ;
153+ assert ! ( self . pending_best_header_hash. read( ) . is_none( ) ) ;
154+ assert ! ( self . pending_best_proposal_block_hash. read( ) . is_none( ) ) ;
155+
156+ batch. put ( db:: COL_EXTRA , BEST_HEADER_KEY , hash) ;
157+ * self . pending_best_header_hash . write ( ) = Some ( * hash) ;
158+ batch. put ( db:: COL_EXTRA , BEST_PROPOSAL_HEADER_KEY , hash) ;
159+ * self . pending_best_proposal_block_hash . write ( ) = Some ( * hash) ;
160+ }
161+
160162 /// Inserts the header into backing cache database.
161163 /// Expects the header to be valid and already verified.
162164 /// If the header is already known, does nothing.
0 commit comments