File tree Expand file tree Collapse file tree 4 files changed +21
-9
lines changed Expand file tree Collapse file tree 4 files changed +21
-9
lines changed Original file line number Diff line number Diff line change @@ -184,11 +184,16 @@ 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_proposal_hash = self . best_proposal_block_hash ( ) ;
187+ let grandparent_hash_of_new_block = parent_details_of_new_block . parent ;
188188 let prev_best_hash = self . best_block_hash ( ) ;
189189
190190 if parent_details_of_new_block. total_score + new_header. score ( ) > self . best_proposal_block_detail ( ) . total_score
191- && engine. can_change_canon_chain ( & new_header, prev_best_hash, prev_best_proposal_hash)
191+ && engine. can_change_canon_chain (
192+ new_header. hash ( ) ,
193+ parent_hash_of_new_block,
194+ grandparent_hash_of_new_block,
195+ prev_best_hash,
196+ )
192197 {
193198 cinfo ! (
194199 BLOCKCHAIN ,
Original file line number Diff line number Diff line change @@ -242,11 +242,16 @@ 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_proposal_hash = self . best_proposal_header_hash ( ) ;
245+ let grandparent_hash_of_new_header = parent_details_of_new_header . parent ;
246246 let prev_best_hash = self . best_header_hash ( ) ;
247247 let is_new_best = parent_details_of_new_header. total_score + new_header. score ( )
248248 > self . best_proposal_header_detail ( ) . total_score
249- && engine. can_change_canon_chain ( & new_header, prev_best_hash, prev_best_proposal_hash) ;
249+ && engine. can_change_canon_chain (
250+ new_header. hash ( ) ,
251+ parent_hash_of_new_header,
252+ grandparent_hash_of_new_header,
253+ prev_best_hash,
254+ ) ;
250255
251256 if is_new_best {
252257 ctrace ! (
Original file line number Diff line number Diff line change @@ -271,9 +271,10 @@ pub trait ConsensusEngine: Sync + Send {
271271 /// Only the descendant of the current best block could be the next best block in Tendermint consensus.
272272 fn can_change_canon_chain (
273273 & self ,
274- _new_header : & HeaderView ,
274+ _new_block_hash : H256 ,
275+ _parent_hash_of_new_header : H256 ,
276+ _grandparent_hash_of_new_header : H256 ,
275277 _previous_best_hash : H256 ,
276- _previous_best_proposal_hash : H256 ,
277278 ) -> bool {
278279 true
279280 }
Original file line number Diff line number Diff line change @@ -311,11 +311,12 @@ impl ConsensusEngine for Tendermint {
311311
312312 fn can_change_canon_chain (
313313 & self ,
314- new_header : & HeaderView ,
314+ _new_header_hash : H256 ,
315+ parent_hash_of_new_header : H256 ,
316+ grandparent_hash_of_new_header : H256 ,
315317 prev_best_hash : H256 ,
316- prev_best_proposal_hash : H256 ,
317318 ) -> bool {
318- new_header . parent_hash ( ) == prev_best_hash || new_header . parent_hash ( ) == prev_best_proposal_hash
319+ parent_hash_of_new_header == prev_best_hash || grandparent_hash_of_new_header == prev_best_hash
319320 }
320321
321322 fn action_handlers ( & self ) -> & [ Arc < dyn ActionHandler > ] {
You can’t perform that action at this time.
0 commit comments