File tree Expand file tree Collapse file tree 5 files changed +10
-28
lines changed Expand file tree Collapse file tree 5 files changed +10
-28
lines changed Original file line number Diff line number Diff line change @@ -184,17 +184,18 @@ impl BlockChain {
184184 let new_header = new_block. header_view ( ) ;
185185 let parent_hash_of_new_block = new_header. parent_hash ( ) ;
186186 let parent_details_of_new_block = self . block_details ( & parent_hash_of_new_block) . expect ( "Invalid parent hash" ) ;
187+ let prev_best_hash = self . best_block_hash ( ) ;
187188
188189 if parent_details_of_new_block. total_score + new_header. score ( ) > self . best_proposal_block_detail ( ) . total_score
189- && engine. can_change_canon_chain ( & new_header)
190+ && engine. can_change_canon_chain ( & new_header, prev_best_hash )
190191 {
191192 cinfo ! (
192193 BLOCKCHAIN ,
193194 "Block #{}({}) has higher total score, changing the best proposal/canonical chain." ,
194195 new_header. number( ) ,
195196 new_header. hash( )
196197 ) ;
197- let prev_best_hash = self . best_block_hash ( ) ;
198+
198199 let route = tree_route ( self , prev_best_hash, parent_hash_of_new_block)
199200 . expect ( "blocks being imported always within recent history; qed" ) ;
200201
Original file line number Diff line number Diff line change @@ -242,9 +242,10 @@ impl HeaderChain {
242242 fn best_header_changed ( & self , new_header : & HeaderView , engine : & dyn CodeChainEngine ) -> BestHeaderChanged {
243243 let parent_hash_of_new_header = new_header. parent_hash ( ) ;
244244 let parent_details_of_new_header = self . block_details ( & parent_hash_of_new_header) . expect ( "Invalid parent hash" ) ;
245+ let prev_best_hash = self . best_header_hash ( ) ;
245246 let is_new_best = parent_details_of_new_header. total_score + new_header. score ( )
246247 > self . best_proposal_header_detail ( ) . total_score
247- && engine. can_change_canon_chain ( & new_header) ;
248+ && engine. can_change_canon_chain ( & new_header, prev_best_hash ) ;
248249
249250 if is_new_best {
250251 ctrace ! (
@@ -256,7 +257,6 @@ impl HeaderChain {
256257 // on new best block we need to make sure that all ancestors
257258 // are moved to "canon chain"
258259 // find the route between old best block and the new one
259- let prev_best_hash = self . best_header_hash ( ) ;
260260 let route = tree_route ( self , prev_best_hash, parent_hash_of_new_header)
261261 . expect ( "blocks being imported always within recent history; qed" ) ;
262262
Original file line number Diff line number Diff line change @@ -266,10 +266,10 @@ pub trait ConsensusEngine: Sync + Send {
266266 header. hash ( )
267267 }
268268
269- /// In PoW consensus, the higher scored block became the best block.
269+ /// In PoW consensus, the higher scored block becomes the best block.
270270 /// In Tendermint consensus, the highest scored block may not be the best block.
271271 /// Only the child of the current best block could be the next best block in Tendermint consensus.
272- fn can_change_canon_chain ( & self , _header : & HeaderView ) -> bool {
272+ fn can_change_canon_chain ( & self , _new_header : & HeaderView , _previous_best_hash : H256 ) -> bool {
273273 true
274274 }
275275
Original file line number Diff line number Diff line change @@ -308,15 +308,9 @@ impl ConsensusEngine for Tendermint {
308308 header. parent_hash ( )
309309 }
310310
311- fn can_change_canon_chain ( & self , header : & HeaderView ) -> bool {
312- let ( result, receiver) = crossbeam:: bounded ( 1 ) ;
313- self . inner
314- . send ( worker:: Event :: AllowedHeight {
315- result,
316- } )
317- . unwrap ( ) ;
318- let allowed_height = receiver. recv ( ) . unwrap ( ) ;
319- header. number ( ) >= allowed_height
311+
312+ fn can_change_canon_chain ( & self , new_header : & HeaderView , prev_best_hash : H256 ) -> bool {
313+ new_header. parent_hash ( ) == prev_best_hash
320314 }
321315
322316 fn action_handlers ( & self ) -> & [ Arc < dyn ActionHandler > ] {
Original file line number Diff line number Diff line change @@ -133,9 +133,6 @@ pub enum Event {
133133 ap : Arc < AccountProvider > ,
134134 address : Address ,
135135 } ,
136- AllowedHeight {
137- result : crossbeam:: Sender < Height > ,
138- } ,
139136 Restore ( crossbeam:: Sender < ( ) > ) ,
140137 ProposalBlock {
141138 signature : SchnorrSignature ,
@@ -307,16 +304,6 @@ impl Worker {
307304 } ) => {
308305 inner. set_signer( ap, address) ;
309306 }
310- Ok ( Event :: AllowedHeight {
311- result,
312- } ) => {
313- let allowed_height = if inner. step. is_commit( ) {
314- inner. height + 1
315- } else {
316- inner. height
317- } ;
318- result. send( allowed_height) . unwrap( ) ;
319- }
320307 Ok ( Event :: Restore ( result) ) => {
321308 inner. restore( ) ;
322309 result. send( ( ) ) . unwrap( ) ;
You can’t perform that action at this time.
0 commit comments