Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Move weight values to frame_support
  • Loading branch information
shawntabrizi committed May 4, 2020
commit a7c058dce7d9a09e30fd19cd6b77a37cd5930ac2
13 changes: 2 additions & 11 deletions bin/node-template/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub use sp_runtime::{Permill, Perbill};
pub use frame_support::{
StorageValue, construct_runtime, parameter_types,
traits::Randomness,
weights::{Weight, RuntimeDbWeight},
weights::{Weight, constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight}},
};

/// Importing a template pallet
Expand Down Expand Up @@ -124,18 +124,9 @@ parameter_types! {
/// We allow for 2 seconds of compute with a 6 second average block time.
pub const MaximumBlockWeight: Weight = 2_000_000_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 @ 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 {
Expand Down Expand Up @@ -164,7 +155,7 @@ impl system::Trait for Runtime {
/// Maximum weight of each block.
type MaximumBlockWeight = MaximumBlockWeight;
/// The weight of database operations that the runtime can invoke.
type DbWeight = DbWeight;
type DbWeight = RocksDbWeight;
/// The weight of the overhead invoked on the block import process, independent of the
/// extrinsics included in that block.
type BlockExecutionWeight = BlockExecutionWeight;
Expand Down
12 changes: 2 additions & 10 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
use sp_std::prelude::*;
use frame_support::{
construct_runtime, parameter_types, debug,
weights::{Weight, RuntimeDbWeight},
weights::{Weight, constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight}},
traits::{Currency, Randomness, OnUnbalanced, Imbalance, LockIdentifier},
};
use sp_core::u32_trait::{_1, _2, _3, _4};
Expand Down Expand Up @@ -120,17 +120,9 @@ 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;
/// 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 @ 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 {
Expand All @@ -146,7 +138,7 @@ impl frame_system::Trait for Runtime {
type Event = Event;
type BlockHashCount = BlockHashCount;
type MaximumBlockWeight = MaximumBlockWeight;
type DbWeight = DbWeight;
type DbWeight = RocksDbWeight;
type BlockExecutionWeight = BlockExecutionWeight;
type ExtrinsicBaseWeight = ExtrinsicBaseWeight;
type MaximumBlockLength = MaximumBlockLength;
Expand Down
28 changes: 28 additions & 0 deletions frame/support/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,34 @@ pub use sp_runtime::transaction_validity::TransactionPriority;
/// Numeric range of a transaction weight.
pub type Weight = u64;

/// These constants are specific to the current pallet selection in the Substrate node.
/// For example: Frame System, Pallet Balances, Pallet Staking, etc...
/// Any significant changes to your runtime setup should probably use weights specific to your own
/// runtime benchmarks.
pub mod constants {
use super::*;
use crate::parameter_types;

parameter_types! {
/// Importing a block with 0 txs takes ~5 ms
pub const BlockExecutionWeight: Weight = 5_000_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;
/// By default, Substrate uses RocksDB, so this will be the weight used throughout
/// the runtime.
pub const RocksDbWeight: RuntimeDbWeight = RuntimeDbWeight {
read: 25_000_000, // ~25 µs @ 200,000 items
write: 100_000_000, // ~100 µs @ 200,000 items
};
/// ParityDB can be enabled with a feature flag, but is still experimental. These weights
/// are available for brave runtime engineers who may want to try this out as default.
pub const ParityDbWeight: RuntimeDbWeight = RuntimeDbWeight {
read: 8_000_000, // ~8 µs @ 200,000 items
write: 50_000_000, // ~50 µs @ 200,000 items
};
}
}

/// Means of weighing some particular kind of data (`T`).
pub trait WeighData<T> {
/// Weigh the data `T` given by `target`. When implementing this for a dispatchable, `T` will be
Expand Down