Update Balances Pallet to use WeightInfo (#6610)

* Update balance benchmarks

* Update weight functions

* Remove user component

* make componentless

* Add support for `#[extra]` tag on benchmarks

* Update balances completely

* Apply suggestions from code review

Co-authored-by: Alexander Theißen <alex.theissen@me.com>

* Fix some tests

* Maybe fix to test. Need approval from @tomusdrw this is okay

* Make test better

* keep weights conservative

* Update macro for merge master

* Add headers

* Apply suggestions from code review

Co-authored-by: Alexander Popiak <alexander.popiak@parity.io>

Co-authored-by: Alexander Theißen <alex.theissen@me.com>
Co-authored-by: Alexander Popiak <alexander.popiak@parity.io>
This commit is contained in:
Shawn Tabrizi
2020-07-30 17:08:23 +02:00
committed by GitHub
parent b6dedd9016
commit 01d0d13fad
11 changed files with 244 additions and 87 deletions
+16 -14
View File
@@ -180,19 +180,19 @@ use frame_system::{self as system, ensure_signed, ensure_root};
pub use self::imbalances::{PositiveImbalance, NegativeImbalance};
pub trait WeightInfo {
fn transfer(u: u32, e: u32, ) -> Weight;
fn transfer_best_case(u: u32, e: u32, ) -> Weight;
fn transfer_keep_alive(u: u32, e: u32, ) -> Weight;
fn set_balance(u: u32, e: u32, ) -> Weight;
fn set_balance_killing(u: u32, e: u32, ) -> Weight;
fn transfer() -> Weight;
fn transfer_keep_alive() -> Weight;
fn set_balance_creating() -> Weight;
fn set_balance_killing() -> Weight;
fn force_transfer() -> Weight;
}
impl WeightInfo for () {
fn transfer(_u: u32, _e: u32, ) -> Weight { 1_000_000_000 }
fn transfer_best_case(_u: u32, _e: u32, ) -> Weight { 1_000_000_000 }
fn transfer_keep_alive(_u: u32, _e: u32, ) -> Weight { 1_000_000_000 }
fn set_balance(_u: u32, _e: u32, ) -> Weight { 1_000_000_000 }
fn set_balance_killing(_u: u32, _e: u32, ) -> Weight { 1_000_000_000 }
fn transfer() -> Weight { 1_000_000_000 }
fn transfer_keep_alive() -> Weight { 1_000_000_000 }
fn set_balance_creating() -> Weight { 1_000_000_000 }
fn set_balance_killing() -> Weight { 1_000_000_000 }
fn force_transfer() -> Weight { 1_000_000_000 }
}
pub trait Subtrait<I: Instance = DefaultInstance>: frame_system::Trait {
@@ -462,7 +462,7 @@ decl_module! {
/// - DB Weight: 1 Read and 1 Write to destination account
/// - Origin account is already in memory, so no DB operations for them.
/// # </weight>
#[weight = T::DbWeight::get().reads_writes(1, 1) + 70_000_000]
#[weight = T::WeightInfo::transfer()]
pub fn transfer(
origin,
dest: <T::Lookup as StaticLookup>::Source,
@@ -491,7 +491,9 @@ decl_module! {
/// - Killing: 35.11 µs
/// - DB Weight: 1 Read, 1 Write to `who`
/// # </weight>
#[weight = T::DbWeight::get().reads_writes(1, 1) + 35_000_000]
#[weight = T::WeightInfo::set_balance_creating() // Creates a new account.
.max(T::WeightInfo::set_balance_killing()) // Kills an existing account.
]
fn set_balance(
origin,
who: <T::Lookup as StaticLookup>::Source,
@@ -533,7 +535,7 @@ decl_module! {
/// - Same as transfer, but additional read and write because the source account is
/// not assumed to be in the overlay.
/// # </weight>
#[weight = T::DbWeight::get().reads_writes(2, 2) + 70_000_000]
#[weight = T::WeightInfo::force_transfer()]
pub fn force_transfer(
origin,
source: <T::Lookup as StaticLookup>::Source,
@@ -557,7 +559,7 @@ decl_module! {
/// - Base Weight: 51.4 µs
/// - DB Weight: 1 Read and 1 Write to dest (sender is in overlay already)
/// #</weight>
#[weight = T::DbWeight::get().reads_writes(1, 1) + 50_000_000]
#[weight = T::WeightInfo::transfer_keep_alive()]
pub fn transfer_keep_alive(
origin,
dest: <T::Lookup as StaticLookup>::Source,