diff --git a/substrate/bin/node-template/runtime/src/lib.rs b/substrate/bin/node-template/runtime/src/lib.rs index fed1ee36db..62e6515807 100644 --- a/substrate/bin/node-template/runtime/src/lib.rs +++ b/substrate/bin/node-template/runtime/src/lib.rs @@ -130,8 +130,8 @@ parameter_types! { /// This probably should not be changed unless you have specific /// disk i/o conditions for the node. pub const DbWeight: RuntimeDbWeight = RuntimeDbWeight { - read: 60_000_000, // ~0.06 ms = ~60 µs - write: 200_000_000, // ~0.2 ms = 200 µs + read: 25_000_000, // ~25 µs + write: 100_000_000, // ~100 µs }; } diff --git a/substrate/bin/node/executor/tests/basic.rs b/substrate/bin/node/executor/tests/basic.rs index 21117f0a4f..0cb3dea420 100644 --- a/substrate/bin/node/executor/tests/basic.rs +++ b/substrate/bin/node/executor/tests/basic.rs @@ -339,7 +339,7 @@ fn full_native_block_import_works() { phase: Phase::ApplyExtrinsic(0), // timestamp set call with weight 9_000_000 + 2 read + 1 write event: Event::frame_system(frame_system::RawEvent::ExtrinsicSuccess( - DispatchInfo { weight: 9_000_000 + 2 * 60_000_000 + 1 * 200_000_000, class: DispatchClass::Mandatory, ..Default::default() } + DispatchInfo { weight: 9_000_000 + 2 * 25_000_000 + 1 * 100_000_000, class: DispatchClass::Mandatory, ..Default::default() } )), topics: vec![], }, @@ -359,8 +359,9 @@ fn full_native_block_import_works() { }, EventRecord { phase: Phase::ApplyExtrinsic(1), + // Balance Transfer 80_000_000 + 1 Read + 1 Write event: Event::frame_system(frame_system::RawEvent::ExtrinsicSuccess( - DispatchInfo { weight: 460_000_000, ..Default::default() } + DispatchInfo { weight: 80_000_000 + 25_000_000 + 100_000_000, ..Default::default() } )), topics: vec![], }, @@ -393,7 +394,7 @@ fn full_native_block_import_works() { phase: Phase::ApplyExtrinsic(0), // timestamp set call with weight 9_000_000 + 2 read + 1 write event: Event::frame_system(frame_system::RawEvent::ExtrinsicSuccess( - DispatchInfo { weight: 9_000_000 + 2 * 60_000_000 + 1 * 200_000_000, class: DispatchClass::Mandatory, ..Default::default() } + DispatchInfo { weight: 9_000_000 + 2 * 25_000_000 + 1 * 100_000_000, class: DispatchClass::Mandatory, ..Default::default() } )), topics: vec![], }, @@ -415,8 +416,9 @@ fn full_native_block_import_works() { }, EventRecord { phase: Phase::ApplyExtrinsic(1), + // Balance Transfer 80_000_000 + 1 Read + 1 Write event: Event::frame_system(frame_system::RawEvent::ExtrinsicSuccess( - DispatchInfo { weight: 460_000_000, ..Default::default() } + DispatchInfo { weight: 80_000_000 + 25_000_000 + 100_000_000, ..Default::default() } )), topics: vec![], }, @@ -438,8 +440,9 @@ fn full_native_block_import_works() { }, EventRecord { phase: Phase::ApplyExtrinsic(2), + // Balance Transfer 80_000_000 + 1 Read + 1 Write event: Event::frame_system(frame_system::RawEvent::ExtrinsicSuccess( - DispatchInfo { weight: 460_000_000, ..Default::default() } + DispatchInfo { weight: 80_000_000 + 25_000_000 + 100_000_000, ..Default::default() } )), topics: vec![], }, diff --git a/substrate/bin/node/executor/tests/submit_transaction.rs b/substrate/bin/node/executor/tests/submit_transaction.rs index a4e89ca738..a48eea9ce8 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_411_390_000_000, + priority: 1_410_625_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 1458c00d81..704778cc7a 100644 --- a/substrate/bin/node/runtime/src/lib.rs +++ b/substrate/bin/node/runtime/src/lib.rs @@ -124,8 +124,8 @@ parameter_types! { pub const Version: RuntimeVersion = VERSION; pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75); pub const DbWeight: RuntimeDbWeight = RuntimeDbWeight { - read: 60_000_000, // ~0.06 ms = ~60 µs - write: 200_000_000, // ~0.2 ms = 200 µs + read: 25_000_000, // ~25 µs + write: 100_000_000, // ~100 µs }; } diff --git a/substrate/frame/balances/src/lib.rs b/substrate/frame/balances/src/lib.rs index 94dbd3730f..f3a6868722 100644 --- a/substrate/frame/balances/src/lib.rs +++ b/substrate/frame/balances/src/lib.rs @@ -431,9 +431,12 @@ decl_module! { /// - Removing enough funds from an account will trigger `T::DustRemoval::on_unbalanced`. /// - `transfer_keep_alive` works the same way as `transfer`, but has an additional /// check that the transfer will not kill the origin account. - /// + /// --------------------------------- + /// - Base Weight: 80 µs, worst case scenario (account created, account removed) + /// - DB Weight: 1 Read and 1 Write to destination account + /// - Origin account is already in memory, so no DB operations for them. /// # - #[weight = T::DbWeight::get().reads_writes(1, 1) + 200_000_000] + #[weight = T::DbWeight::get().reads_writes(1, 1) + 80_000_000] pub fn transfer( origin, dest: ::Source, @@ -456,8 +459,11 @@ decl_module! { /// # /// - Independent of the arguments. /// - Contains a limited number of reads and writes. + /// --------------------- + /// - Base Weight: 32.6 µs + /// - DB Weight: 1 Read, 1 Write to `who` /// # - #[weight = T::DbWeight::get().reads_writes(1, 1) + 100_000_000] + #[weight = T::DbWeight::get().reads_writes(1, 1) + 35_000_000] fn set_balance( origin, who: ::Source, @@ -499,7 +505,7 @@ decl_module! { /// - Same as transfer, but additional read and write because the source account is /// not assumed to be in the overlay. /// # - #[weight = T::DbWeight::get().reads_writes(2, 2) + 200_000_000] + #[weight = T::DbWeight::get().reads_writes(2, 2) + 80_000_000] pub fn force_transfer( origin, source: ::Source, @@ -518,7 +524,12 @@ decl_module! { /// 99% of the time you want [`transfer`] instead. /// /// [`transfer`]: struct.Module.html#method.transfer - #[weight = T::DbWeight::get().reads_writes(1, 1) + 150_000_000] + /// # + /// - Cheaper than transfer because account cannot be killed. + /// - Base Weight: 57.36 µs + /// - DB Weight: 1 Read and 1 Write to dest (sender is in overlay already) + /// # + #[weight = T::DbWeight::get().reads_writes(1, 1) + 60_000_000] pub fn transfer_keep_alive( origin, dest: ::Source, diff --git a/substrate/frame/utility/src/lib.rs b/substrate/frame/utility/src/lib.rs index 39109a6f6a..4fa001177b 100644 --- a/substrate/frame/utility/src/lib.rs +++ b/substrate/frame/utility/src/lib.rs @@ -205,17 +205,17 @@ mod weight_of { use super::*; /// - Base Weight: - /// - Create: 137.5 + 0.274 * S µs - /// - Approve: 103.8 + .266 * S µs - /// - Complete: 116.2 + .754 * S µs + /// - Create: 59.2 + 0.096 * S µs + /// - Approve: 42.27 + .116 * S µs + /// - Complete: 50.91 + .232 * S µs /// - DB Weight: /// - Reads: Multisig Storage, [Caller Account] /// - Writes: Multisig Storage, [Caller Account] /// - Plus Call Weight pub fn as_multi(other_sig_len: usize, call_weight: Weight) -> Weight { call_weight - .saturating_add(150_000_000) - .saturating_add((other_sig_len as Weight).saturating_mul(750_000)) + .saturating_add(60_000_000) + .saturating_add((other_sig_len as Weight).saturating_mul(250_000)) .saturating_add(T::DbWeight::get().reads_writes(1, 1)) } } @@ -236,7 +236,7 @@ decl_module! { /// - `calls`: The calls to be dispatched from the same origin. /// /// # - /// - Base weight: 63.78 µs + /// - Base weight: 15.64 + .987 * c µs /// - Plus the sum of the weights of the `calls`. /// - Plus one additional event. (repeat read/write) /// # @@ -250,7 +250,7 @@ decl_module! { |args: (&Vec<::Call>,)| { args.0.iter() .map(|call| call.get_dispatch_info().weight) - .fold(65_000_000, |a: Weight, n| a.saturating_add(n)) + .fold(15_000_000, |a: Weight, n| a.saturating_add(n).saturating_add(1_000_000)) }, |args: (&Vec<::Call>,)| { let all_operational = args.0.iter() @@ -280,12 +280,12 @@ decl_module! { /// The dispatch origin for this call must be _Signed_. /// /// # - /// - Base weight: 5.1 µs + /// - Base weight: 2.863 µs /// - Plus the weight of the `call` /// # #[weight = FunctionOf( |args: (&u16, &Box<::Call>)| { - args.1.get_dispatch_info().weight.saturating_add(5_000_000) + args.1.get_dispatch_info().weight.saturating_add(3_000_000) }, |args: (&u16, &Box<::Call>)| args.1.get_dispatch_info().class, Pays::Yes, @@ -339,9 +339,9 @@ decl_module! { /// `MultisigDepositBase + threshold * MultisigDepositFactor`. /// ------------------------------- /// - Base Weight: - /// - Create: 137.5 + 0.274 * S µs - /// - Approve: 103.8 + .266 * S µs - /// - Complete: 116.2 + .754 * S µs + /// - Create: 59.2 + 0.096 * S µs + /// - Approve: 42.27 + .116 * S µs + /// - Complete: 50.91 + .232 * S µs /// - DB Weight: /// - Reads: Multisig Storage, [Caller Account] /// - Writes: Multisig Storage, [Caller Account] @@ -471,8 +471,8 @@ decl_module! { /// `MultisigDepositBase + threshold * MultisigDepositFactor`. /// ---------------------------------- /// - Base Weight: - /// - Create: 139.1 + 0.202 * S - /// - Approve: 96.6 + 0.328 * S + /// - Create: 56.3 + 0.107 * S + /// - Approve: 39.25 + 0.121 * S /// - DB Weight: /// - Read: Multisig Storage, [Caller Account] /// - Write: Multisig Storage, [Caller Account] @@ -480,8 +480,8 @@ decl_module! { #[weight = FunctionOf( |args: (&u16, &Vec, &Option>, &[u8; 32])| { T::DbWeight::get().reads_writes(1, 1) - .saturating_add(140_000_000) - .saturating_add((args.1.len() as Weight).saturating_mul(350_000)) + .saturating_add(60_000_000) + .saturating_add((args.1.len() as Weight).saturating_mul(120_000)) }, DispatchClass::Normal, Pays::Yes, @@ -554,7 +554,7 @@ decl_module! { /// - I/O: 1 read `O(S)`, one remove. /// - Storage: removes one item. /// ---------------------------------- - /// - Base Weight: 126.6 + 0.126 * S + /// - Base Weight: 46.71 + 0.09 * S /// - DB Weight: /// - Read: Multisig Storage, [Caller Account] /// - Write: Multisig Storage, [Caller Account] @@ -562,8 +562,8 @@ decl_module! { #[weight = FunctionOf( |args: (&u16, &Vec, &Timepoint, &[u8; 32])| { T::DbWeight::get().reads_writes(1, 1) - .saturating_add(130_000_000) - .saturating_add((args.1.len() as Weight).saturating_mul(130_000)) + .saturating_add(50_000_000) + .saturating_add((args.1.len() as Weight).saturating_mul(100_000)) }, DispatchClass::Normal, Pays::Yes, diff --git a/substrate/frame/vesting/src/lib.rs b/substrate/frame/vesting/src/lib.rs index d8e937d550..05aee08c31 100644 --- a/substrate/frame/vesting/src/lib.rs +++ b/substrate/frame/vesting/src/lib.rs @@ -193,10 +193,12 @@ decl_module! { /// - DbWeight: 2 Reads, 2 Writes /// - Reads: Vesting Storage, Balances Locks, [Sender Account] /// - Writes: Vesting Storage, Balances Locks, [Sender Account] - /// - Benchmark: 147.5 µs (min square analysis) - /// - Assuming less than 50 locks on any user, else we may want factor in number of locks. + /// - Benchmark: + /// - Unlocked: 56.1 + .098 * l µs (min square analysis) + /// - Locked: 54.37 + .254 * l µs (min square analysis) + /// - Using 60 µs fixed. Assuming less than 50 locks on any user, else we may want factor in number of locks. /// # - #[weight = 150_000_000 + T::DbWeight::get().reads_writes(2, 2)] + #[weight = 60_000_000 + T::DbWeight::get().reads_writes(2, 2)] fn vest(origin) -> DispatchResult { let who = ensure_signed(origin)?; Self::update_lock(who) @@ -216,10 +218,12 @@ decl_module! { /// - DbWeight: 3 Reads, 3 Writes /// - Reads: Vesting Storage, Balances Locks, Target Account /// - Writes: Vesting Storage, Balances Locks, Target Account - /// - Benchmark: 150.4 µs (min square analysis) - /// - Assuming less than 50 locks on any user, else we may want factor in number of locks. + /// - Benchmark: + /// - Unlocked: 58.09 + .104 * l µs (min square analysis) + /// - Locked: 55.35 + .255 * l µs (min square analysis) + /// - Using 60 µs fixed. Assuming less than 50 locks on any user, else we may want factor in number of locks. /// # - #[weight = 150_000_000 + T::DbWeight::get().reads_writes(3, 3)] + #[weight = 60_000_000 + T::DbWeight::get().reads_writes(3, 3)] fn vest_other(origin, target: ::Source) -> DispatchResult { ensure_signed(origin)?; Self::update_lock(T::Lookup::lookup(target)?) @@ -240,10 +244,10 @@ decl_module! { /// - DbWeight: 3 Reads, 3 Writes /// - Reads: Vesting Storage, Balances Locks, Target Account, [Sender Account] /// - Writes: Vesting Storage, Balances Locks, Target Account, [Sender Account] - /// - Benchmark: 263 µs (min square analysis) - /// - Assuming less than 50 locks on any user, else we may want factor in number of locks. + /// - Benchmark: 111.4 + .345 * l µs (min square analysis) + /// - Using 115 µs fixed. Assuming less than 50 locks on any user, else we may want factor in number of locks. /// # - #[weight = 300_000_000 + T::DbWeight::get().reads_writes(3, 3)] + #[weight = 115_000_000 + T::DbWeight::get().reads_writes(3, 3)] pub fn vested_transfer( origin, target: ::Source,