Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Also version initialize_block
Browse files Browse the repository at this point in the history
Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
  • Loading branch information
ggwpez committed Jul 6, 2023
1 parent 708ede6 commit b7869da
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
27 changes: 18 additions & 9 deletions client/block-builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,20 +175,29 @@ where
let estimated_header_size = header.encoded_size();

let mut api = api.runtime_api();
let version = api
.api_version::<dyn BlockBuilderApi<Block>>(parent_hash)?
.ok_or_else(|| Error::VersionInvalid("BlockBuilderApi".to_string()))?;

if record_proof.yes() {
api.record_proof();
}

let executive_mode = api.initialize_block_with_context(
parent_hash,
ExecutionContext::BlockConstruction,
&header,
)?;

let version = api
.api_version::<dyn BlockBuilderApi<Block>>(parent_hash)?
.ok_or_else(|| Error::VersionInvalid("BlockBuilderApi".to_string()))?;
let executive_mode = if version >= 5 {
api.initialize_block_with_context(
parent_hash,
ExecutionContext::BlockConstruction,
&header,
)?
} else {
#[allow(deprecated)]
api.initialize_block_before_version_5_with_context(
parent_hash,
ExecutionContext::BlockConstruction,
&header,
)?;
RuntimeExecutiveMode::Normal
};

Ok(Self {
parent_hash,
Expand Down
2 changes: 1 addition & 1 deletion frame/support/test/tests/runtime_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ fn runtime_metadata() {
ty: meta_type::<&<Block as BlockT>::Header>(),
}],
output: meta_type::<sp_runtime::RuntimeExecutiveMode>(),
docs: maybe_docs(vec![" Initialize a block with the given header."]),
docs: maybe_docs(vec![" Initialize a block with the given header and return the runtime executive mode."]),
},
],
docs: maybe_docs(vec![
Expand Down
3 changes: 3 additions & 0 deletions primitives/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,9 @@ decl_runtime_apis! {
/// Execute the given block.
fn execute_block(block: Block);
/// Initialize a block with the given header.
#[changed_in(5)]
fn initialize_block(header: &<Block as BlockT>::Header);
/// Initialize a block with the given header and return the runtime executive mode.
#[renamed("initialise_block", 2)]
fn initialize_block(header: &<Block as BlockT>::Header) -> RuntimeExecutiveMode;
}
Expand Down

0 comments on commit b7869da

Please sign in to comment.