mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-09 21:21:11 +00:00
Support custom fork choice rule (#1339)
* Support custom fork choice rule * Remove unneeded reexport * Fix network compile
This commit is contained in:
committed by
Robert Habermeier
parent
771a8127c2
commit
ac1be0665e
@@ -25,7 +25,7 @@ use runtime_primitives::{
|
||||
Justification,
|
||||
generic::{BlockId, SignedBlock},
|
||||
};
|
||||
use consensus::{Error as ConsensusError, ErrorKind as ConsensusErrorKind, ImportBlock, ImportResult, BlockOrigin};
|
||||
use consensus::{Error as ConsensusError, ErrorKind as ConsensusErrorKind, ImportBlock, ImportResult, BlockOrigin, ForkChoiceStrategy};
|
||||
use runtime_primitives::traits::{
|
||||
Block as BlockT, Header as HeaderT, Zero, As, NumberFor, CurrentHeight, BlockNumberToHash,
|
||||
ApiRef, ProvideRuntimeApi, Digest, DigestItem,
|
||||
@@ -544,6 +544,7 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
|
||||
authorities: Option<Vec<AuthorityId>>,
|
||||
finalized: bool,
|
||||
aux: Vec<(Vec<u8>, Option<Vec<u8>>)>,
|
||||
fork_choice: ForkChoiceStrategy,
|
||||
) -> error::Result<ImportResult> where
|
||||
E: CallExecutor<Block, Blake2Hasher> + Send + Sync + Clone,
|
||||
{
|
||||
@@ -608,7 +609,10 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
|
||||
};
|
||||
|
||||
// TODO: non longest-chain rule.
|
||||
let is_new_best = finalized || import_headers.post().number() > &last_best_number;
|
||||
let is_new_best = finalized || match fork_choice {
|
||||
ForkChoiceStrategy::LongestChain => import_headers.post().number() > &last_best_number,
|
||||
ForkChoiceStrategy::Custom(v) => v,
|
||||
};
|
||||
let leaf_state = if finalized {
|
||||
::backend::NewBlockState::Final
|
||||
} else if is_new_best {
|
||||
@@ -1038,6 +1042,7 @@ impl<B, E, Block, RA> consensus::BlockImport<Block> for Client<B, E, Block, RA>
|
||||
body,
|
||||
finalized,
|
||||
auxiliary,
|
||||
fork_choice,
|
||||
} = import_block;
|
||||
|
||||
assert!(justification.is_some() && finalized || justification.is_none());
|
||||
@@ -1074,6 +1079,7 @@ impl<B, E, Block, RA> consensus::BlockImport<Block> for Client<B, E, Block, RA>
|
||||
new_authorities,
|
||||
finalized,
|
||||
auxiliary,
|
||||
fork_choice,
|
||||
);
|
||||
|
||||
*self.importing_block.write() = None;
|
||||
|
||||
Reference in New Issue
Block a user