mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 08:11:03 +00:00
Refactor BlockImportParams to be non_exhaustive (#4936)
* Refactor BlockImportParams to be non_exhaustive * Fix cargo check compile
This commit is contained in:
@@ -398,7 +398,7 @@ impl<B, E, Block: BlockT, RA, SC> BlockImport<Block>
|
||||
mut block: BlockImportParams<Block, Self::Transaction>,
|
||||
new_cache: HashMap<well_known_cache_keys::Id, Vec<u8>>,
|
||||
) -> Result<ImportResult, Self::Error> {
|
||||
let hash = block.post_header().hash();
|
||||
let hash = block.post_hash();
|
||||
let number = block.header.number().clone();
|
||||
|
||||
// early exit if block already in chain, otherwise the check for
|
||||
|
||||
@@ -257,7 +257,7 @@ fn do_import_block<B, C, Block: BlockT, J>(
|
||||
DigestFor<Block>: Encode,
|
||||
J: ProvableJustification<Block::Header>,
|
||||
{
|
||||
let hash = block.post_header().hash();
|
||||
let hash = block.post_hash();
|
||||
let number = block.header.number().clone();
|
||||
|
||||
// we don't want to finalize on `inner.import_block`
|
||||
@@ -682,26 +682,19 @@ pub mod tests {
|
||||
authority_set: LightAuthoritySet::genesis(vec![(AuthorityId::from_slice(&[1; 32]), 1)]),
|
||||
consensus_changes: ConsensusChanges::empty(),
|
||||
};
|
||||
let block = BlockImportParams {
|
||||
origin: BlockOrigin::Own,
|
||||
header: Header {
|
||||
let mut block = BlockImportParams::new(
|
||||
BlockOrigin::Own,
|
||||
Header {
|
||||
number: 1,
|
||||
parent_hash: client.chain_info().best_hash,
|
||||
state_root: Default::default(),
|
||||
digest: Default::default(),
|
||||
extrinsics_root: Default::default(),
|
||||
},
|
||||
justification,
|
||||
post_digests: Vec::new(),
|
||||
body: None,
|
||||
storage_changes: None,
|
||||
finalized: false,
|
||||
auxiliary: Vec::new(),
|
||||
intermediates: Default::default(),
|
||||
fork_choice: Some(ForkChoiceStrategy::LongestChain),
|
||||
allow_missing_state: true,
|
||||
import_existing: false,
|
||||
};
|
||||
);
|
||||
block.justification = justification;
|
||||
block.fork_choice = Some(ForkChoiceStrategy::LongestChain);
|
||||
|
||||
do_import_block::<_, _, _, TestJustification>(
|
||||
&client,
|
||||
&mut import_data,
|
||||
|
||||
@@ -1011,20 +1011,11 @@ fn allows_reimporting_change_blocks() {
|
||||
|
||||
let block = || {
|
||||
let block = block.clone();
|
||||
BlockImportParams {
|
||||
origin: BlockOrigin::File,
|
||||
header: block.header,
|
||||
justification: None,
|
||||
post_digests: Vec::new(),
|
||||
body: Some(block.extrinsics),
|
||||
storage_changes: None,
|
||||
finalized: false,
|
||||
auxiliary: Vec::new(),
|
||||
intermediates: Default::default(),
|
||||
fork_choice: Some(ForkChoiceStrategy::LongestChain),
|
||||
allow_missing_state: false,
|
||||
import_existing: false,
|
||||
}
|
||||
let mut import = BlockImportParams::new(BlockOrigin::File, block.header);
|
||||
import.body = Some(block.extrinsics);
|
||||
import.fork_choice = Some(ForkChoiceStrategy::LongestChain);
|
||||
|
||||
import
|
||||
};
|
||||
|
||||
assert_eq!(
|
||||
@@ -1071,20 +1062,12 @@ fn test_bad_justification() {
|
||||
|
||||
let block = || {
|
||||
let block = block.clone();
|
||||
BlockImportParams {
|
||||
origin: BlockOrigin::File,
|
||||
header: block.header,
|
||||
justification: Some(Vec::new()),
|
||||
post_digests: Vec::new(),
|
||||
body: Some(block.extrinsics),
|
||||
storage_changes: None,
|
||||
finalized: false,
|
||||
auxiliary: Vec::new(),
|
||||
intermediates: Default::default(),
|
||||
fork_choice: Some(ForkChoiceStrategy::LongestChain),
|
||||
allow_missing_state: false,
|
||||
import_existing: false,
|
||||
}
|
||||
let mut import = BlockImportParams::new(BlockOrigin::File, block.header);
|
||||
import.justification = Some(Vec::new());
|
||||
import.body = Some(block.extrinsics);
|
||||
import.fork_choice = Some(ForkChoiceStrategy::LongestChain);
|
||||
|
||||
import
|
||||
};
|
||||
|
||||
assert_eq!(
|
||||
@@ -1805,23 +1788,13 @@ fn imports_justification_for_regular_blocks_on_import() {
|
||||
};
|
||||
|
||||
// we import the block with justification attached
|
||||
let block = BlockImportParams {
|
||||
origin: BlockOrigin::File,
|
||||
header: block.header,
|
||||
justification: Some(justification.encode()),
|
||||
post_digests: Vec::new(),
|
||||
body: Some(block.extrinsics),
|
||||
storage_changes: None,
|
||||
finalized: false,
|
||||
auxiliary: Vec::new(),
|
||||
intermediates: Default::default(),
|
||||
fork_choice: Some(ForkChoiceStrategy::LongestChain),
|
||||
allow_missing_state: false,
|
||||
import_existing: false,
|
||||
};
|
||||
let mut import = BlockImportParams::new(BlockOrigin::File, block.header);
|
||||
import.justification = Some(justification.encode());
|
||||
import.body = Some(block.extrinsics);
|
||||
import.fork_choice = Some(ForkChoiceStrategy::LongestChain);
|
||||
|
||||
assert_eq!(
|
||||
block_import.import_block(block, HashMap::new()).unwrap(),
|
||||
block_import.import_block(import, HashMap::new()).unwrap(),
|
||||
ImportResult::Imported(ImportedAux {
|
||||
needs_justification: false,
|
||||
clear_justification_requests: false,
|
||||
|
||||
Reference in New Issue
Block a user