File tree Expand file tree Collapse file tree 5 files changed +23
-29
lines changed Expand file tree Collapse file tree 5 files changed +23
-29
lines changed Original file line number Diff line number Diff line change @@ -184,17 +184,19 @@ impl BlockChain {
184
184
let new_header = new_block. header_view ( ) ;
185
185
let parent_hash_of_new_block = new_header. parent_hash ( ) ;
186
186
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 ( ) ;
188
+ let prev_best_hash = self . best_block_hash ( ) ;
187
189
188
190
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)
191
+ && engine. can_change_canon_chain ( & new_header, prev_best_hash , prev_best_proposal_hash )
190
192
{
191
193
cinfo ! (
192
194
BLOCKCHAIN ,
193
195
"Block #{}({}) has higher total score, changing the best proposal/canonical chain." ,
194
196
new_header. number( ) ,
195
197
new_header. hash( )
196
198
) ;
197
- let prev_best_hash = self . best_block_hash ( ) ;
199
+
198
200
let route = tree_route ( self , prev_best_hash, parent_hash_of_new_block)
199
201
. expect ( "blocks being imported always within recent history; qed" ) ;
200
202
Original file line number Diff line number Diff line change @@ -242,9 +242,11 @@ impl HeaderChain {
242
242
fn best_header_changed ( & self , new_header : & HeaderView , engine : & dyn CodeChainEngine ) -> BestHeaderChanged {
243
243
let parent_hash_of_new_header = new_header. parent_hash ( ) ;
244
244
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 ( ) ;
246
+ let prev_best_hash = self . best_header_hash ( ) ;
245
247
let is_new_best = parent_details_of_new_header. total_score + new_header. score ( )
246
248
> self . best_proposal_header_detail ( ) . total_score
247
- && engine. can_change_canon_chain ( & new_header) ;
249
+ && engine. can_change_canon_chain ( & new_header, prev_best_hash , prev_best_proposal_hash ) ;
248
250
249
251
if is_new_best {
250
252
ctrace ! (
@@ -256,7 +258,6 @@ impl HeaderChain {
256
258
// on new best block we need to make sure that all ancestors
257
259
// are moved to "canon chain"
258
260
// find the route between old best block and the new one
259
- let prev_best_hash = self . best_header_hash ( ) ;
260
261
let route = tree_route ( self , prev_best_hash, parent_hash_of_new_header)
261
262
. expect ( "blocks being imported always within recent history; qed" ) ;
262
263
Original file line number Diff line number Diff line change @@ -266,10 +266,15 @@ pub trait ConsensusEngine: Sync + Send {
266
266
header. hash ( )
267
267
}
268
268
269
- /// In PoW consensus, the higher scored block became the best block.
269
+ /// In PoW consensus, the higher scored block becomes the best block.
270
270
/// In Tendermint consensus, the highest scored block may not be the best block.
271
- /// 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 {
271
+ /// Only the descendant of the current best block could be the next best block in Tendermint consensus.
272
+ fn can_change_canon_chain (
273
+ & self ,
274
+ _new_header : & HeaderView ,
275
+ _previous_best_hash : H256 ,
276
+ _previous_best_proposal_hash : H256 ,
277
+ ) -> bool {
273
278
true
274
279
}
275
280
Original file line number Diff line number Diff line change @@ -308,15 +308,14 @@ impl ConsensusEngine for Tendermint {
308
308
header. parent_hash ( )
309
309
}
310
310
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 (
313
+ & self ,
314
+ new_header : & HeaderView ,
315
+ prev_best_hash : H256 ,
316
+ prev_best_proposal_hash : H256 ,
317
+ ) -> bool {
318
+ new_header. parent_hash ( ) == prev_best_hash || new_header. parent_hash ( ) == prev_best_proposal_hash
320
319
}
321
320
322
321
fn action_handlers ( & self ) -> & [ Arc < dyn ActionHandler > ] {
Original file line number Diff line number Diff line change @@ -133,9 +133,6 @@ pub enum Event {
133
133
ap : Arc < AccountProvider > ,
134
134
address : Address ,
135
135
} ,
136
- AllowedHeight {
137
- result : crossbeam:: Sender < Height > ,
138
- } ,
139
136
Restore ( crossbeam:: Sender < ( ) > ) ,
140
137
ProposalBlock {
141
138
signature : SchnorrSignature ,
@@ -307,16 +304,6 @@ impl Worker {
307
304
} ) => {
308
305
inner. set_signer( ap, address) ;
309
306
}
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
- }
320
307
Ok ( Event :: Restore ( result) ) => {
321
308
inner. restore( ) ;
322
309
result. send( ( ) ) . unwrap( ) ;
You can’t perform that action at this time.
0 commit comments