mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 23:21:06 +00:00
BlockId removal: runtime-api refactor (#13255)
* BlockId removal: refactor of runtime API It changes the arguments of: - `ApiExt` methods: `has_api`, `has_api_with`, `api_version` - `CallApiAt` method: `runtime_version_at` from: `BlockId<Block>` to: `Block::Hash` It also changes the first argument of all generated runtime API calls from: `BlockId<Block>` to: `Block::Hash` This PR is part of BlockId::Number refactoring analysis (paritytech/substrate#11292) * BlockId removal: refactor of runtime API - tests - tests adjusted to new runtime API, - some tests migrated from block number to block hash * benchmarking-cli: BlockId(0) migrated to info().genesis_hash `runtime_api.call()` now requires the block hash instead of BlockId::Number. To access the genesis hash widely used in benchmarking engine the Client was constrained to satisfy `sp_blockchain::HeaderBackend<Block>` trait which provides `info().genesis_hash`. * trivial: api.call(BlockId) -> api.call(Hash) - Migrated all `runtime_api.calls` to use Hash - Noteworthy (?): -- `validate_transaction_blocking` in transaction pool, * CallApiAtParams::at changed to Block::Hash * missed doc updated * Apply suggestions from code review Co-authored-by: Bastian Köcher <git@kchr.de> * ".git/.scripts/commands/fmt/fmt.sh" * BlockId removal: Benchmark::consumed_weight Little refactor around `Benchmark::consumed_weight`: `BlockId` removed. * at_hash renamed * wrong merge fixed * beefy worker: merged with master * beefy: tests: missing block problem fixed * Apply review suggestion * fix --------- Co-authored-by: Bastian Köcher <git@kchr.de> Co-authored-by: command-bot <>
This commit is contained in:
committed by
GitHub
parent
ac13aaeb2f
commit
7a10154188
@@ -137,7 +137,6 @@ pub struct BlockBuilder<'a, Block: BlockT, A: ProvideRuntimeApi<Block>, B> {
|
||||
extrinsics: Vec<Block::Extrinsic>,
|
||||
api: ApiRef<'a, A::Api>,
|
||||
version: u32,
|
||||
block_id: BlockId<Block>,
|
||||
parent_hash: Block::Hash,
|
||||
backend: &'a B,
|
||||
/// The estimated size of the block header.
|
||||
@@ -181,12 +180,14 @@ where
|
||||
api.record_proof();
|
||||
}
|
||||
|
||||
let block_id = BlockId::Hash(parent_hash);
|
||||
|
||||
api.initialize_block_with_context(&block_id, ExecutionContext::BlockConstruction, &header)?;
|
||||
api.initialize_block_with_context(
|
||||
parent_hash,
|
||||
ExecutionContext::BlockConstruction,
|
||||
&header,
|
||||
)?;
|
||||
|
||||
let version = api
|
||||
.api_version::<dyn BlockBuilderApi<Block>>(&block_id)?
|
||||
.api_version::<dyn BlockBuilderApi<Block>>(parent_hash)?
|
||||
.ok_or_else(|| Error::VersionInvalid("BlockBuilderApi".to_string()))?;
|
||||
|
||||
Ok(Self {
|
||||
@@ -194,7 +195,6 @@ where
|
||||
extrinsics: Vec::new(),
|
||||
api,
|
||||
version,
|
||||
block_id,
|
||||
backend,
|
||||
estimated_header_size,
|
||||
})
|
||||
@@ -204,7 +204,7 @@ where
|
||||
///
|
||||
/// This will ensure the extrinsic can be validly executed (by executing it).
|
||||
pub fn push(&mut self, xt: <Block as BlockT>::Extrinsic) -> Result<(), Error> {
|
||||
let block_id = &self.block_id;
|
||||
let parent_hash = self.parent_hash;
|
||||
let extrinsics = &mut self.extrinsics;
|
||||
let version = self.version;
|
||||
|
||||
@@ -212,14 +212,14 @@ where
|
||||
let res = if version < 6 {
|
||||
#[allow(deprecated)]
|
||||
api.apply_extrinsic_before_version_6_with_context(
|
||||
block_id,
|
||||
parent_hash,
|
||||
ExecutionContext::BlockConstruction,
|
||||
xt.clone(),
|
||||
)
|
||||
.map(legacy::byte_sized_error::convert_to_latest)
|
||||
} else {
|
||||
api.apply_extrinsic_with_context(
|
||||
block_id,
|
||||
parent_hash,
|
||||
ExecutionContext::BlockConstruction,
|
||||
xt.clone(),
|
||||
)
|
||||
@@ -246,7 +246,7 @@ where
|
||||
pub fn build(mut self) -> Result<BuiltBlock<Block, backend::StateBackendFor<B, Block>>, Error> {
|
||||
let header = self
|
||||
.api
|
||||
.finalize_block_with_context(&self.block_id, ExecutionContext::BlockConstruction)?;
|
||||
.finalize_block_with_context(self.parent_hash, ExecutionContext::BlockConstruction)?;
|
||||
|
||||
debug_assert_eq!(
|
||||
header.extrinsics_root().clone(),
|
||||
@@ -279,13 +279,13 @@ where
|
||||
&mut self,
|
||||
inherent_data: sp_inherents::InherentData,
|
||||
) -> Result<Vec<Block::Extrinsic>, Error> {
|
||||
let block_id = self.block_id;
|
||||
let parent_hash = self.parent_hash;
|
||||
self.api
|
||||
.execute_in_transaction(move |api| {
|
||||
// `create_inherents` should not change any state, to ensure this we always rollback
|
||||
// the transaction.
|
||||
TransactionOutcome::Rollback(api.inherent_extrinsics_with_context(
|
||||
&block_id,
|
||||
parent_hash,
|
||||
ExecutionContext::BlockConstruction,
|
||||
inherent_data,
|
||||
))
|
||||
|
||||
Reference in New Issue
Block a user