Skip to content
Snippets Groups Projects
Unverified Commit 3f391a6c authored by wangjj9219's avatar wangjj9219 Committed by GitHub
Browse files

update db read and write (#242)

parent 89141df1
No related branches found
No related tags found
No related merge requests found
......@@ -14,7 +14,7 @@
use frame_support::{
decl_error, decl_event, decl_module, decl_storage, ensure, traits::Get, weights::constants::WEIGHT_PER_MICROS,
IterableStorageDoubleMap, Parameter,
weights::Weight, IterableStorageDoubleMap, Parameter,
};
use frame_system::ensure_signed;
use orml_traits::{Auction, AuctionHandler, AuctionInfo, Change};
......@@ -76,21 +76,39 @@ decl_module! {
/// - T::Handler is module_auction_manager of Acala
/// - Indirectly needs orml_currencies and module_cdp_treasury of Acala
/// - Complexity: `O(1)`
/// - Db reads: `Auctions`, 2 items of module_auction_manager, 4 items of orml_currencies, 2 items of module_cdp_treasury
/// - Db writes: `Auctions`, 2 items of module_auction_manager, 4 items of orml_currencies, 2 items of module_cdp_treasury
/// - Db reads:
/// - collateral auction:
/// - best cases: 7
/// - worst cases: 14
/// - surplus auction:
/// - best cases: 5
/// - worst cases: 6
/// - debit auction:
/// - best cases: 8
/// - worst cases: 7
/// - Db writes:
/// - collateral auction:
/// - best cases: 7
/// - worst cases: 14
/// - surplus auction:
/// - best cases: 3
/// - worst cases: 5
/// - debit auction:
/// - best cases: 8
/// - worst cases: 8
/// -------------------
/// Base Weight:
/// - collateral auction:
/// - best cases: 49.61 µs
/// - worst cases: 83.65 µs
/// - best cases: 134 µs
/// - worst cases: 300.4 µs
/// - surplus auction:
/// - best cases: 42.67 µs
/// - worst cases: 49.76 µs
/// - best cases: 97.9 µs
/// - worst cases: 157.6 µs
/// - debit auction:
/// - best cases: 45.96 µs
/// - worst cases: 48.55 µs
/// - best cases: 140.7 µs
/// - worst cases: 142.8 µs
/// # </weight>
#[weight = 84 * WEIGHT_PER_MICROS + T::DbWeight::get().reads_writes(9, 9)]
#[weight = 300 * WEIGHT_PER_MICROS + T::DbWeight::get().reads_writes(14, 14)]
pub fn bid(origin, id: T::AuctionId, #[compact] value: T::Balance) {
let from = ensure_signed(origin)?;
......@@ -135,6 +153,12 @@ decl_module! {
Self::deposit_event(RawEvent::Bid(id, from, value));
}
/// dummy `on_initialize` to return the weight used in `on_finalize`.
fn on_initialize() -> Weight {
// weight of `on_finalize`
0
}
fn on_finalize(now: T::BlockNumber) {
Self::_on_finalize(now);
}
......
......@@ -134,14 +134,14 @@ decl_module! {
/// - T::MultiCurrency is orml_tokens
/// - T::NativeCurrency is pallet_balances
/// - Complexity: `O(1)`
/// - Db reads: 2 * `Accounts`
/// - Db writes: 2 * `Accounts`
/// - Db reads: 5
/// - Db writes: 2
/// -------------------
/// Base Weight:
/// - non-native currency: 26.72 µs
/// - native currency in worst case: 29.9 µs
/// - non-native currency: 90.23 µs
/// - native currency in worst case: 70 µs
/// # </weight>
#[weight = 30 * WEIGHT_PER_MICROS + T::DbWeight::get().reads_writes(2, 2)]
#[weight = 90 * WEIGHT_PER_MICROS + T::DbWeight::get().reads_writes(2, 2)]
pub fn transfer(
origin,
dest: <T::Lookup as StaticLookup>::Source,
......@@ -165,9 +165,9 @@ decl_module! {
/// - Db reads: 2 * `Accounts`
/// - Db writes: 2 * `Accounts`
/// -------------------
/// Base Weight: 29.53 µs
/// Base Weight: 70 µs
/// # </weight>
#[weight = 30 * WEIGHT_PER_MICROS + T::DbWeight::get().reads_writes(2, 2)]
#[weight = 70 * WEIGHT_PER_MICROS + T::DbWeight::get().reads_writes(2, 2)]
pub fn transfer_native_currency(
origin,
dest: <T::Lookup as StaticLookup>::Source,
......@@ -189,15 +189,17 @@ decl_module! {
/// - T::MultiCurrency is orml_tokens
/// - T::NativeCurrency is pallet_balances
/// - Complexity: `O(1)`
/// - Db reads: `Accounts`
/// - Db writes: `Accounts`
/// - Db reads:
/// - non-native currency: 5
/// - Db writes:
/// - non-native currency: 2
/// -------------------
/// Base Weight:
/// - non-native currency: 25.36 µs
/// - non-native currency: 66.24 µs
/// - native currency and killing account: 26.33 µs
/// - native currency and create account: 27.39 µs
/// # </weight>
#[weight = 27 * WEIGHT_PER_MICROS + T::DbWeight::get().reads_writes(1, 1)]
#[weight = 66 * WEIGHT_PER_MICROS + T::DbWeight::get().reads_writes(5, 2)]
pub fn update_balance(
origin,
who: <T::Lookup as StaticLookup>::Source,
......
......@@ -199,12 +199,12 @@ decl_module! {
///
/// # <weight>
/// - Complexity: `O(1)`
/// - Db reads: 2 * `Accounts`
/// - Db writes: 2 * `Accounts`
/// - Db reads: 4
/// - Db writes: 2
/// -------------------
/// Base Weight: 26.65 µs
/// Base Weight: 84.08 µs
/// # </weight>
#[weight = 27 * WEIGHT_PER_MICROS + T::DbWeight::get().reads_writes(2, 2)]
#[weight = 84 * WEIGHT_PER_MICROS + T::DbWeight::get().reads_writes(4, 2)]
pub fn transfer(
origin,
dest: <T::Lookup as StaticLookup>::Source,
......@@ -224,12 +224,12 @@ decl_module! {
///
/// # <weight>
/// - Complexity: `O(1)`
/// - Db reads: 2 * `Accounts`
/// - Db writes: 2 * `Accounts`
/// - Db reads: 4
/// - Db writes: 2
/// -------------------
/// Base Weight: 26.99 µs
/// Base Weight: 87.71 µs
/// # </weight>
#[weight = 27 * WEIGHT_PER_MICROS + T::DbWeight::get().reads_writes(2, 2)]
#[weight = 88 * WEIGHT_PER_MICROS + T::DbWeight::get().reads_writes(4, 2)]
pub fn transfer_all(
origin,
dest: <T::Lookup as StaticLookup>::Source,
......
......@@ -179,12 +179,12 @@ decl_module! {
/// - Preconditions:
/// - T::Currency is orml_currencies
/// - Complexity: `O(1)`
/// - Db reads: `VestingSchedules`, 3 items of orml_currencies
/// - Db writes: `VestingSchedules`, 3 items of orml_currencies
/// - Db reads: 3
/// - Db writes: 3
/// -------------------
/// Base Weight: 29.86 µs
/// Base Weight: 65.23 µs
/// # </weight>
#[weight = 30 * WEIGHT_PER_MICROS + T::DbWeight::get().reads_writes(2, 2)]
#[weight = 30 * WEIGHT_PER_MICROS + T::DbWeight::get().reads_writes(3, 3)]
pub fn claim(origin) {
let who = ensure_signed(origin)?;
let locked_amount = Self::do_claim(&who);
......@@ -196,12 +196,12 @@ decl_module! {
/// - Preconditions:
/// - T::Currency is orml_currencies
/// - Complexity: `O(1)`
/// - Db reads: `VestingSchedules`, 3 items of orml_currencies
/// - Db writes: `VestingSchedules`, 3 items of orml_currencies
/// - Db reads: 4
/// - Db writes: 4
/// -------------------
/// Base Weight: 47.26 µs
/// Base Weight: 150.4 µs
/// # </weight>
#[weight = 48 * WEIGHT_PER_MICROS + T::DbWeight::get().reads_writes(4, 4)]
#[weight = 150 * WEIGHT_PER_MICROS + T::DbWeight::get().reads_writes(4, 4)]
pub fn vested_transfer(
origin,
dest: <T::Lookup as StaticLookup>::Source,
......@@ -218,12 +218,12 @@ decl_module! {
/// - Preconditions:
/// - T::Currency is orml_currencies
/// - Complexity: `O(1)`
/// - Db reads: `VestingSchedules`, 3 items of orml_currencies
/// - Db writes: `VestingSchedules`, 3 items of orml_currencies
/// - Db reads: 2
/// - Db writes: 3
/// -------------------
/// Base Weight: 27.96 µs
/// Base Weight: 61.87 µs
/// # </weight>
#[weight = 28 * WEIGHT_PER_MICROS + T::DbWeight::get().reads_writes(4, 4)]
#[weight = 62 * WEIGHT_PER_MICROS + T::DbWeight::get().reads_writes(2, 3)]
pub fn update_vesting_schedules(
origin,
who: <T::Lookup as StaticLookup>::Source,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment