diff --git a/substrate/bin/node-template/runtime/src/lib.rs b/substrate/bin/node-template/runtime/src/lib.rs index 62e6515807..20780511ae 100644 --- a/substrate/bin/node-template/runtime/src/lib.rs +++ b/substrate/bin/node-template/runtime/src/lib.rs @@ -123,16 +123,19 @@ parameter_types! { pub const BlockHashCount: BlockNumber = 250; /// We allow for 2 seconds of compute with a 6 second average block time. pub const MaximumBlockWeight: Weight = 2_000_000_000_000; - pub const ExtrinsicBaseWeight: Weight = 10_000_000; + /// Executing 10,000 System remarks (no-op) txs takes ~1.26 seconds -> ~125 µs per tx + pub const ExtrinsicBaseWeight: Weight = 125_000_000; pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75); pub const MaximumBlockLength: u32 = 5 * 1024 * 1024; pub const Version: RuntimeVersion = VERSION; /// This probably should not be changed unless you have specific /// disk i/o conditions for the node. pub const DbWeight: RuntimeDbWeight = RuntimeDbWeight { - read: 25_000_000, // ~25 µs - write: 100_000_000, // ~100 µs + read: 25_000_000, // ~25 µs @ 200,000 items + write: 100_000_000, // ~100 µs @ 200,000 items }; + /// Importing a block with 0 txs takes ~5 ms + pub const BlockExecutionWeight: Weight = 5_000_000_000; } impl system::Trait for Runtime { @@ -164,7 +167,7 @@ impl system::Trait for Runtime { type DbWeight = DbWeight; /// The weight of the overhead invoked on the block import process, independent of the /// extrinsics included in that block. - type BlockExecutionWeight = (); + type BlockExecutionWeight = BlockExecutionWeight; /// The base weight of any extrinsic processed by the runtime, independent of the /// logic of that extrinsic. (Signature verification, nonce increment, fee, etc...) type ExtrinsicBaseWeight = ExtrinsicBaseWeight; diff --git a/substrate/bin/node/bench/src/import.rs b/substrate/bin/node/bench/src/import.rs index ed40f1b459..1fd2bbdecc 100644 --- a/substrate/bin/node/bench/src/import.rs +++ b/substrate/bin/node/bench/src/import.rs @@ -49,16 +49,20 @@ pub enum SizeType { Large, #[display(fmt = "full")] Full, + #[display(fmt = "custom")] + Custom, } impl SizeType { - fn transactions(&self) -> usize { + pub fn transactions(&self) -> usize { match self { SizeType::Empty => 0, SizeType::Small => 10, SizeType::Medium => 100, SizeType::Large => 500, SizeType::Full => 4000, + // Custom SizeType will use the `--transactions` input parameter + SizeType::Custom => 0, } } } @@ -66,6 +70,7 @@ impl SizeType { pub struct ImportBenchmarkDescription { pub profile: Profile, pub key_types: KeyTypes, + pub block_type: BlockType, pub size: SizeType, } @@ -90,6 +95,12 @@ impl core::BenchmarkDescription for ImportBenchmarkDescription { KeyTypes::Ed25519 => path.push("ed25519"), } + match self.block_type { + BlockType::RandomTransfersKeepAlive(_) => path.push("transfer_keep_alive"), + BlockType::RandomTransfersReaping(_) => path.push("transfer_reaping"), + BlockType::Noop(_) => path.push("noop"), + } + path.push(&format!("{}", self.size)); path @@ -101,7 +112,7 @@ impl core::BenchmarkDescription for ImportBenchmarkDescription { 50_000, self.key_types ); - let block = bench_db.generate_block(BlockType::RandomTransfers(self.size.transactions())); + let block = bench_db.generate_block(self.block_type); Box::new(ImportBenchmark { database: bench_db, block, @@ -110,16 +121,11 @@ impl core::BenchmarkDescription for ImportBenchmarkDescription { } fn name(&self) -> Cow<'static, str> { - match self.profile { - Profile::Wasm => format!( - "Import benchmark (random transfers, wasm, {} block)", - self.size, - ).into(), - Profile::Native => format!( - "Import benchmark (random transfers, native, {} block)", - self.size, - ).into(), - } + format!( + "Import benchmark ({:?}, {:?})", + self.block_type, + self.profile, + ).into() } } @@ -159,4 +165,4 @@ impl core::Benchmark for ImportBenchmark { elapsed } -} \ No newline at end of file +} diff --git a/substrate/bin/node/bench/src/main.rs b/substrate/bin/node/bench/src/main.rs index 27c9358f9d..e627f07c3d 100644 --- a/substrate/bin/node/bench/src/main.rs +++ b/substrate/bin/node/bench/src/main.rs @@ -26,7 +26,7 @@ use crate::core::{run_benchmark, Mode as BenchmarkMode}; use crate::tempdb::DatabaseType; use import::{ImportBenchmarkDescription, SizeType}; use trie::{TrieReadBenchmarkDescription, TrieWriteBenchmarkDescription, DatabaseSize}; -use node_testing::bench::{Profile, KeyTypes}; +use node_testing::bench::{Profile, KeyTypes, BlockType}; use structopt::StructOpt; #[derive(Debug, StructOpt)] @@ -49,9 +49,13 @@ struct Opt { /// Run with `--list` for the hint of what to filter. filter: Option, + /// Number of transactions for block import with `custom` size. + #[structopt(long)] + transactions: Option, + /// Mode /// - /// "regular" for regular becnhmark + /// "regular" for regular benchmark /// /// "profile" mode adds pauses between measurable runs, /// so that actual interval can be selected in the profiler of choice. @@ -66,38 +70,38 @@ fn main() { sc_cli::init_logger(""); } + let mut import_benchmarks = Vec::new(); + + for profile in [Profile::Wasm, Profile::Native].iter() { + for size in [ + SizeType::Empty, + SizeType::Small, + SizeType::Medium, + SizeType::Large, + SizeType::Full, + SizeType::Custom, + ].iter() { + let txs = match size { + SizeType::Custom => opt.transactions.unwrap_or(0), + _ => size.transactions() + }; + for block_type in [ + BlockType::RandomTransfersKeepAlive(txs), + BlockType::RandomTransfersReaping(txs), + BlockType::Noop(txs), + ].iter() { + import_benchmarks.push((profile.clone(), size.clone(), block_type.clone())); + } + } + } + let benchmarks = matrix!( - profile in [Profile::Wasm, Profile::Native].iter() => + (profile, size, block_type) in import_benchmarks.iter() => ImportBenchmarkDescription { profile: *profile, key_types: KeyTypes::Sr25519, - size: SizeType::Medium, - }, - ImportBenchmarkDescription { - profile: Profile::Wasm, - key_types: KeyTypes::Sr25519, - size: SizeType::Empty, - }, - ImportBenchmarkDescription { - profile: Profile::Native, - key_types: KeyTypes::Ed25519, - size: SizeType::Medium, - }, - ImportBenchmarkDescription { - profile: Profile::Wasm, - key_types: KeyTypes::Sr25519, - size: SizeType::Full, - }, - ImportBenchmarkDescription { - profile: Profile::Native, - key_types: KeyTypes::Sr25519, - size: SizeType::Full, - }, - size in [SizeType::Small, SizeType::Large].iter() => - ImportBenchmarkDescription { - profile: Profile::Native, - key_types: KeyTypes::Sr25519, size: *size, + block_type: *block_type, }, (size, db_type) in [ @@ -145,4 +149,4 @@ fn main() { let json_result: String = serde_json::to_string(&results).expect("Failed to construct json"); println!("{}", json_result); } -} \ No newline at end of file +} diff --git a/substrate/bin/node/executor/tests/submit_transaction.rs b/substrate/bin/node/executor/tests/submit_transaction.rs index a48eea9ce8..ced85d2d4a 100644 --- a/substrate/bin/node/executor/tests/submit_transaction.rs +++ b/substrate/bin/node/executor/tests/submit_transaction.rs @@ -230,7 +230,7 @@ fn submitted_transaction_should_be_valid() { let res = Executive::validate_transaction(source, extrinsic); assert_eq!(res.unwrap(), ValidTransaction { - priority: 1_410_625_000_000, + priority: 1_410_740_000_000, requires: vec![], provides: vec![(address, 0).encode()], longevity: 128, diff --git a/substrate/bin/node/runtime/src/lib.rs b/substrate/bin/node/runtime/src/lib.rs index 704778cc7a..d256d116d3 100644 --- a/substrate/bin/node/runtime/src/lib.rs +++ b/substrate/bin/node/runtime/src/lib.rs @@ -56,6 +56,7 @@ use sp_inherents::{InherentData, CheckInherentsResult}; pub use sp_runtime::BuildStorage; pub use pallet_timestamp::Call as TimestampCall; pub use pallet_balances::Call as BalancesCall; +pub use frame_system::Call as SystemCall; pub use pallet_contracts::Gas; pub use frame_support::StorageValue; pub use pallet_staking::StakerStatus; @@ -119,14 +120,17 @@ parameter_types! { pub const BlockHashCount: BlockNumber = 250; /// We allow for 2 seconds of compute with a 6 second average block time. pub const MaximumBlockWeight: Weight = 2_000_000_000_000; - pub const ExtrinsicBaseWeight: Weight = 10_000_000; + /// Executing 10,000 System remarks (no-op) txs takes ~1.26 seconds -> ~125 µs per tx + pub const ExtrinsicBaseWeight: Weight = 125_000_000; pub const MaximumBlockLength: u32 = 5 * 1024 * 1024; pub const Version: RuntimeVersion = VERSION; pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75); pub const DbWeight: RuntimeDbWeight = RuntimeDbWeight { - read: 25_000_000, // ~25 µs - write: 100_000_000, // ~100 µs + read: 25_000_000, // ~25 µs @ 200,000 items + write: 100_000_000, // ~100 µs @ 200,000 items }; + /// Importing a block with 0 txs takes ~5 ms + pub const BlockExecutionWeight: Weight = 5_000_000_000; } impl frame_system::Trait for Runtime { @@ -143,7 +147,7 @@ impl frame_system::Trait for Runtime { type BlockHashCount = BlockHashCount; type MaximumBlockWeight = MaximumBlockWeight; type DbWeight = DbWeight; - type BlockExecutionWeight = (); + type BlockExecutionWeight = BlockExecutionWeight; type ExtrinsicBaseWeight = ExtrinsicBaseWeight; type MaximumBlockLength = MaximumBlockLength; type AvailableBlockRatio = AvailableBlockRatio; diff --git a/substrate/bin/node/testing/src/bench.rs b/substrate/bin/node/testing/src/bench.rs index d05bb9a095..cdc9cc86e5 100644 --- a/substrate/bin/node/testing/src/bench.rs +++ b/substrate/bin/node/testing/src/bench.rs @@ -43,6 +43,7 @@ use node_runtime::{ constants::currency::DOLLARS, UncheckedExtrinsic, MinimumPeriod, + SystemCall, BalancesCall, AccountId, Signature, @@ -129,16 +130,18 @@ impl Clone for BenchDb { #[derive(Debug, PartialEq, Clone, Copy)] pub enum BlockType { /// Bunch of random transfers. - RandomTransfers(usize), + RandomTransfersKeepAlive(usize), /// Bunch of random transfers that drain all of the source balance. RandomTransfersReaping(usize), + /// Bunch of "no-op" calls. + Noop(usize), } impl BlockType { /// Number of transactions for this block type. pub fn transactions(&self) -> usize { match self { - Self::RandomTransfers(v) | Self::RandomTransfersReaping(v) => *v, + Self::RandomTransfersKeepAlive(v) | Self::RandomTransfersReaping(v) | Self::Noop(v) => *v, } } } @@ -287,15 +290,31 @@ impl BenchDb { let signed = self.keyring.sign( CheckedExtrinsic { signed: Some((sender, signed_extra(0, node_runtime::ExistentialDeposit::get() + 1))), - function: Call::Balances( - BalancesCall::transfer( - pallet_indices::address::Address::Id(receiver), - match block_type { - BlockType::RandomTransfers(_) => node_runtime::ExistentialDeposit::get() + 1, - BlockType::RandomTransfersReaping(_) => 100*DOLLARS - node_runtime::ExistentialDeposit::get() - 1, - } - ) - ), + function: match block_type { + BlockType::RandomTransfersKeepAlive(_) => { + Call::Balances( + BalancesCall::transfer_keep_alive( + pallet_indices::address::Address::Id(receiver), + node_runtime::ExistentialDeposit::get() + 1, + ) + ) + }, + BlockType::RandomTransfersReaping(_) => { + Call::Balances( + BalancesCall::transfer( + pallet_indices::address::Address::Id(receiver), + // Transfer so that ending balance would be 1 less than existential deposit + // so that we kill the sender account. + 100*DOLLARS - (node_runtime::ExistentialDeposit::get() - 1), + ) + ) + }, + BlockType::Noop(_) => { + Call::System( + SystemCall::remark(Vec::new()) + ) + }, + }, }, version, genesis_hash,