Skip to content

Commit 9baeb2c

Browse files
committed
frame/benchmark-cli: Pass relay parent offset to create parainherent
data Signed-off-by: Alexandru Vasile <[email protected]>
1 parent 0bb4f59 commit 9baeb2c

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

substrate/utils/frame/benchmarking-cli/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ clap = { features = ["derive"], workspace = true }
2323
codec = { workspace = true, default-features = true }
2424
comfy-table = { workspace = true }
2525
cumulus-client-parachain-inherent = { workspace = true, default-features = true }
26+
cumulus-primitives-core = { workspace = true, default-features = true }
2627
cumulus-primitives-proof-size-hostfunction = { workspace = true, default-features = true }
2728
env_filter = { workspace = true }
2829
frame-benchmarking = { workspace = true, default-features = true }

substrate/utils/frame/benchmarking-cli/src/overhead/command.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ use crate::{
3838
use clap::{error::ErrorKind, Args, CommandFactory, Parser};
3939
use codec::{Decode, Encode};
4040
use cumulus_client_parachain_inherent::MockValidationDataInherentDataProvider;
41+
use cumulus_primitives_core::RelayParentOffsetApi;
4142
use fake_runtime_api::RuntimeApi as FakeRuntimeApi;
4243
use frame_support::Deserialize;
4344
use genesis_state::WARN_SPEC_GENESIS_CTOR;
@@ -204,6 +205,7 @@ type OverheadClient<Block, HF> = TFullClient<Block, FakeRuntimeApi, WasmExecutor
204205
fn create_inherent_data<Client: UsageProvider<Block> + HeaderBackend<Block>, Block: BlockT>(
205206
client: &Arc<Client>,
206207
chain_type: &ChainType,
208+
relay_parent_offset: u32,
207209
) -> InherentData {
208210
let genesis = client.usage_info().chain.best_hash;
209211
let header = client.header(genesis).unwrap().unwrap();
@@ -216,6 +218,7 @@ fn create_inherent_data<Client: UsageProvider<Block> + HeaderBackend<Block>, Blo
216218
para_id: ParaId::from(*para_id),
217219
current_para_block_head: Some(header.encode().into()),
218220
relay_offset: 0,
221+
relay_parent_offset,
219222
..Default::default()
220223
};
221224
let _ = futures::executor::block_on(
@@ -457,7 +460,19 @@ impl OverheadCmd {
457460
&chain_type,
458461
)?;
459462

460-
let inherent_data = create_inherent_data(&client, &chain_type);
463+
// Fetch the relay parent offset from the runtime.
464+
let relay_parent_offset = {
465+
let genesis = client.usage_info().chain.best_hash;
466+
client.runtime_api().relay_parent_offset(genesis).unwrap_or_else(|_| {
467+
log::debug!(
468+
target: LOG_TARGET,
469+
"Runtime does not implement RelayParentOffsetApi, using default offset of 0"
470+
);
471+
0
472+
})
473+
};
474+
475+
let inherent_data = create_inherent_data(&client, &chain_type, relay_parent_offset);
461476

462477
let (ext_builder, runtime_name) = {
463478
let genesis = client.usage_info().chain.best_hash;

substrate/utils/frame/benchmarking-cli/src/overhead/fake_runtime_api.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,10 @@ sp_api::impl_runtime_apis! {
109109
unimplemented!()
110110
}
111111
}
112+
113+
impl cumulus_primitives_core::RelayParentOffsetApi<Block> for Runtime {
114+
fn relay_parent_offset() -> u32 {
115+
unimplemented!()
116+
}
117+
}
112118
}

0 commit comments

Comments
 (0)