Skip to content

Commit e52497d

Browse files
authored
Merge pull request paritytech#34 from mangata-finance/feature/block-execution-benchmarks
introduce compile time switch for omitting extrinsics execution
2 parents f778a05 + c3fdef5 commit e52497d

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

frame/executive/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ sp-arithmetic = { version = "4.0.0-dev", default-features = false, path = "../..
3030
sp-keystore = { version = "0.10.0-dev", default-features = false, path = "../../primitives/keystore", optional=true}
3131
schnorrkel = { version = "0.9.1", features = ["preaudit_deprecated", "u64_backend"], default-features = false}
3232
merlin = { version = "2.0", default-features = false }
33-
3433

3534
[dev-dependencies]
3635
hex-literal = "0.3.4"
@@ -44,6 +43,7 @@ sp-inherents = { version = "4.0.0-dev", path = "../../primitives/inherents" }
4443

4544
[features]
4645
default = ["std"]
46+
disable-execution = []
4747
with-tracing = ["sp-tracing/with-tracing"]
4848
std = [
4949
"codec/std",

frame/executive/src/lib.rs

+34-1
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,7 @@ where
411411

412412
// execute extrinsics
413413
let (header, extrinsics) = block.deconstruct();
414+
414415
Self::execute_extrinsics_with_book_keeping(extrinsics, *header.number());
415416

416417
if !signature_batching.verify() {
@@ -459,7 +460,7 @@ where
459460
).collect();
460461
let shuffled_extrinsics = extrinsic_shuffler::shuffle_using_seed(extrinsics_with_author, &header.seed().seed);
461462

462-
Self::execute_extrinsics_with_book_keeping(shuffled_extrinsics, *header.number());
463+
Self::execute_extrinsics_impl(shuffled_extrinsics, *header.number());
463464

464465
if !signature_batching.verify() {
465466
panic!("Signature verification failed.");
@@ -488,6 +489,38 @@ where
488489
Self::idle_and_finalize_hook(block_number);
489490
}
490491

492+
#[cfg(not(feature = "disable-execution"))]
493+
/// regular impl execute inherents & extrinsics
494+
fn execute_extrinsics_impl(
495+
extrinsics: Vec<Block::Extrinsic>,
496+
block_number: NumberFor<Block>,
497+
) {
498+
Self::execute_extrinsics_with_book_keeping(extrinsics, block_number)
499+
}
500+
501+
#[cfg(feature = "disable-execution")]
502+
/// impl for benchmark - execute inherents only
503+
fn execute_extrinsics_impl(
504+
extrinsics: Vec<Block::Extrinsic>,
505+
block_number: NumberFor<Block>,
506+
) {
507+
extrinsics.into_iter()
508+
.filter(|e| !e.is_signed().unwrap())
509+
.for_each(|e| {
510+
if let Err(e) = Self::apply_extrinsic(e) {
511+
let err: &'static str = e.into();
512+
panic!("{}", err)
513+
}
514+
});
515+
516+
// post-extrinsics book-keeping
517+
<frame_system::Pallet<System>>::note_finished_extrinsics();
518+
519+
Self::idle_and_finalize_hook(block_number);
520+
}
521+
522+
523+
491524
/// Finalize the block - it is up the caller to ensure that all header fields are valid
492525
/// except state-root.
493526
pub fn finalize_block() -> System::Header {

0 commit comments

Comments
 (0)