Skip to content

Commit

Permalink
CU-200y9ka - Auction: generate a file with weights
Browse files Browse the repository at this point in the history
  • Loading branch information
andor0 committed Jan 11, 2022
1 parent 526263a commit fd57666
Show file tree
Hide file tree
Showing 6 changed files with 148 additions and 27 deletions.
5 changes: 3 additions & 2 deletions frame/dutch-auction/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ pub mod weights;

#[frame_support::pallet]
pub mod pallet {
pub use crate::weights::WeightInfo;
use codec::{Decode, Encode};
use composable_traits::{
auction::AuctionStepFunction,
Expand All @@ -75,7 +76,7 @@ pub mod pallet {
use num_traits::Zero;
use scale_info::TypeInfo;

use crate::{math::*, weights::WeightInfo};
use crate::math::*;
use orml_traits::{MultiCurrency, MultiReservableCurrency};
use sp_runtime::{
traits::{AccountIdConversion, Saturating},
Expand Down Expand Up @@ -211,7 +212,7 @@ pub mod pallet {
}

/// adds take to list, does not execute take immediately
#[pallet::weight(T::WeightInfo::take())]
#[pallet::weight(T::WeightInfo::take(42))] // FIXME: need to use correct a value instead of 42
pub fn take(
origin: OriginFor<T>,
order_id: T::OrderId,
Expand Down
78 changes: 67 additions & 11 deletions frame/dutch-auction/src/weights.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,83 @@
use frame_support::dispatch::Weight;
use frame_support::{pallet_prelude::Weight, traits::Get, weights::constants::RocksDbWeight};
use sp_std::marker::PhantomData;

pub trait WeightInfo {
fn ask() -> Weight;
fn take() -> Weight;
fn take(_x: u32) -> Weight;
fn liquidate() -> Weight;
fn known_overhead_for_on_finalize() -> Weight;
}

/// no weight
impl WeightInfo for () {
/// Weight functions for `dutch_auction`.
pub struct SubstrateWeight<T>(PhantomData<T>);
impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Storage: DutchAuction OrdersIndex (r:1 w:1)
// Storage: Timestamp Now (r:1 w:0)
// Storage: Tokens Accounts (r:1 w:1)
// Storage: DutchAuction SellOrders (r:0 w:1)
fn ask() -> Weight {
0
(164_004_000 as Weight)
.saturating_add(T::DbWeight::get().reads(3 as Weight))
.saturating_add(T::DbWeight::get().writes(3 as Weight))
}

fn take() -> Weight {
0
// Storage: DutchAuction SellOrders (r:1 w:0)
// Storage: Timestamp Now (r:1 w:0)
// Storage: Tokens Accounts (r:1 w:1)
// Storage: DutchAuction Takes (r:1 w:1)
fn take(_x: u32) -> Weight {
(158_860_000 as Weight)
.saturating_add(T::DbWeight::get().reads(4 as Weight))
.saturating_add(T::DbWeight::get().writes(2 as Weight))
}

// Storage: DutchAuction SellOrders (r:1 w:1)
// Storage: Tokens Accounts (r:1 w:1)
fn liquidate() -> Weight {
0
(105_812_000 as Weight)
.saturating_add(T::DbWeight::get().reads(2 as Weight))
.saturating_add(T::DbWeight::get().writes(2 as Weight))
}
// Storage: DutchAuction Takes (r:2 w:1)
// Storage: DutchAuction SellOrders (r:1 w:1)
// Storage: Tokens Accounts (r:2 w:2)
fn known_overhead_for_on_finalize() -> Weight {
(287_359_000 as Weight)
.saturating_add(T::DbWeight::get().reads(5 as Weight))
.saturating_add(T::DbWeight::get().writes(4 as Weight))
}
}

impl WeightInfo for () {
// Storage: DutchAuction OrdersIndex (r:1 w:1)
// Storage: Timestamp Now (r:1 w:0)
// Storage: Tokens Accounts (r:1 w:1)
// Storage: DutchAuction SellOrders (r:0 w:1)
fn ask() -> Weight {
(164_004_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(3 as Weight))
.saturating_add(RocksDbWeight::get().writes(3 as Weight))
}
// Storage: DutchAuction SellOrders (r:1 w:0)
// Storage: Timestamp Now (r:1 w:0)
// Storage: Tokens Accounts (r:1 w:1)
// Storage: DutchAuction Takes (r:1 w:1)
fn take(_x: u32) -> Weight {
(158_860_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(4 as Weight))
.saturating_add(RocksDbWeight::get().writes(2 as Weight))
}
// Storage: DutchAuction SellOrders (r:1 w:1)
// Storage: Tokens Accounts (r:1 w:1)
fn liquidate() -> Weight {
(105_812_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(2 as Weight))
.saturating_add(RocksDbWeight::get().writes(2 as Weight))
}
// Storage: DutchAuction Takes (r:2 w:1)
// Storage: DutchAuction SellOrders (r:1 w:1)
// Storage: Tokens Accounts (r:2 w:2)
fn known_overhead_for_on_finalize() -> Weight {
0
(287_359_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(5 as Weight))
.saturating_add(RocksDbWeight::get().writes(4 as Weight))
}
}
7 changes: 4 additions & 3 deletions runtime/dali/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ smallvec = "1.6.1"
assets-registry = { package = "pallet-assets-registry", path = '../../frame/assets-registry', default-features = false }
assets = { package = "pallet-assets", path = '../../frame/assets', default-features = false }
crowdloan-rewards = { package = "pallet-crowdloan-rewards", path = '../../frame/crowdloan-rewards', default-features = false }
pallet-bonded-finance = { path = "../../frame/bonded-finance", default-features = false }
bonded-finance = { package = "pallet-bonded-finance", path = "../../frame/bonded-finance", default-features = false }
vesting = { package = "pallet-vesting", path = "../../frame/vesting", default-features = false }
pallet-dutch-auction = { package = "pallet-dutch-auction", path = "../../frame/dutch-auction", default-features = false }
dutch-auction = { package = "pallet-dutch-auction", path = "../../frame/dutch-auction", default-features = false }
common = { path = "../common", default-features = false }
primitives = { path = "../primitives", default-features = false }
oracle = { package = "pallet-oracle", path = "../../frame/oracle", default-features = false }
Expand Down Expand Up @@ -190,6 +190,7 @@ runtime-benchmarks = [
"xcm-builder/runtime-benchmarks",
"indices/runtime-benchmarks",
"crowdloan-rewards/runtime-benchmarks",
"dutch-auction/runtime-benchmarks",
"identity/runtime-benchmarks",
"multisig/runtime-benchmarks",
"membership/runtime-benchmarks",
Expand All @@ -198,5 +199,5 @@ runtime-benchmarks = [
"collective/runtime-benchmarks",
"democracy/runtime-benchmarks",
"utility/runtime-benchmarks",
"vault/runtime-benchmarks"
"vault/runtime-benchmarks"
]
21 changes: 10 additions & 11 deletions runtime/dali/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,7 @@ parameter_types! {
pub const Stake: Balance = 10_000;
}

impl pallet_bonded_finance::Config for Runtime {
impl bonded_finance::Config for Runtime {
type AdminOrigin = EnsureRoot<AccountId>;
type BondOfferId = u64;
type Convert = sp_runtime::traits::ConvertInto;
Expand All @@ -841,15 +841,15 @@ impl composable_traits::defi::DeFiComposableConfig for Runtime {
type Balance = Balance;
}

impl pallet_dutch_auction::Config for Runtime {
impl dutch_auction::Config for Runtime {
type NativeCurrency = Balances;
type Event = Event;
type MultiCurrency = Assets;
type PalletId = DutchAuctionId;
type WeightToFee = WeightToFee;
type OrderId = u128;
type UnixTime = Timestamp;
type WeightInfo = ();
type WeightInfo = weights::dutch_auction::WeightInfo<Runtime>;
}

construct_runtime!(
Expand Down Expand Up @@ -904,8 +904,8 @@ construct_runtime!(
Assets: assets::{Pallet, Call, Storage} = 57,
CrowdloanRewards: crowdloan_rewards::{Pallet, Call, Storage, Event<T>} = 58,
Vesting: vesting::{Call, Event<T>, Pallet, Storage} = 59,
BondedFinance: pallet_bonded_finance::{Call, Event<T>, Pallet, Storage} = 60,
DutchAuction: pallet_dutch_auction::{Pallet, Call, Storage, Event<T>} = 61,
BondedFinance: bonded_finance::{Call, Event<T>, Pallet, Storage} = 60,
DutchAuction: dutch_auction::{Pallet, Call, Storage, Event<T>} = 61,

CallFilter: call_filter::{Pallet, Call, Storage, Event<T>} = 100,
}
Expand Down Expand Up @@ -1064,12 +1064,10 @@ impl_runtime_apis! {
list_benchmark!(list, extra, utility, Utility);
list_benchmark!(list, extra, identity, Identity);
list_benchmark!(list, extra, multisig, Multisig);

{
list_benchmark!(list, extra, vault, Vault);
list_benchmark!(list, extra, oracle, Oracle);
list_benchmark!(list, extra, crowdloan_rewards, CrowdloanRewards);
}
list_benchmark!(list, extra, vault, Vault);
list_benchmark!(list, extra, oracle, Oracle);
list_benchmark!(list, extra, crowdloan_rewards, CrowdloanRewards);
list_benchmark!(list, extra, dutch_auction, DutchAuction);

let storage_info = AllPalletsWithSystem::storage_info();

Expand Down Expand Up @@ -1120,6 +1118,7 @@ impl_runtime_apis! {
add_benchmark!(params, batches, vault, Vault);
add_benchmark!(params, batches, oracle, Oracle);
add_benchmark!(params, batches, crowdloan_rewards, CrowdloanRewards);
add_benchmark!(params, batches, dutch_auction, DutchAuction);

if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) }
Ok(batches)
Expand Down
63 changes: 63 additions & 0 deletions runtime/dali/src/weights/dutch_auction.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
//! Autogenerated weights for `dutch_auction`
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
//! DATE: 2022-01-11, STEPS: `5`, REPEAT: 2, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dali-dev"), DB CACHE: 128
// Executed Command:
// ./target/release/composable
// benchmark
// --chain=dali-dev
// --execution=wasm
// --wasm-execution=compiled
// --pallet=dutch_auction
// --extrinsic=*
// --steps=5
// --repeat=2
// --raw
// --output=./runtime/dali/src/weights

#![cfg_attr(rustfmt, rustfmt_skip)]
#![allow(unused_parens)]
#![allow(unused_imports)]

use sp_std::marker::PhantomData;
use support::{traits::Get, weights::Weight};

/// Weight functions for `dutch_auction`.
pub struct WeightInfo<T>(PhantomData<T>);
impl<T: frame_system::Config> dutch_auction::WeightInfo for WeightInfo<T> {
// Storage: DutchAuction OrdersIndex (r:1 w:1)
// Storage: Timestamp Now (r:1 w:0)
// Storage: Tokens Accounts (r:1 w:1)
// Storage: DutchAuction SellOrders (r:0 w:1)
fn ask() -> Weight {
(164_004_000 as Weight)
.saturating_add(T::DbWeight::get().reads(3 as Weight))
.saturating_add(T::DbWeight::get().writes(3 as Weight))
}
// Storage: DutchAuction SellOrders (r:1 w:0)
// Storage: Timestamp Now (r:1 w:0)
// Storage: Tokens Accounts (r:1 w:1)
// Storage: DutchAuction Takes (r:1 w:1)
fn take(_x: u32, ) -> Weight {
(158_860_000 as Weight)
.saturating_add(T::DbWeight::get().reads(4 as Weight))
.saturating_add(T::DbWeight::get().writes(2 as Weight))
}
// Storage: DutchAuction SellOrders (r:1 w:1)
// Storage: Tokens Accounts (r:1 w:1)
fn liquidate() -> Weight {
(105_812_000 as Weight)
.saturating_add(T::DbWeight::get().reads(2 as Weight))
.saturating_add(T::DbWeight::get().writes(2 as Weight))
}
// Storage: DutchAuction Takes (r:2 w:1)
// Storage: DutchAuction SellOrders (r:1 w:1)
// Storage: Tokens Accounts (r:2 w:2)
fn known_overhead_for_on_finalize() -> Weight {
(287_359_000 as Weight)
.saturating_add(T::DbWeight::get().reads(5 as Weight))
.saturating_add(T::DbWeight::get().writes(4 as Weight))
}
}
1 change: 1 addition & 0 deletions runtime/dali/src/weights/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pub mod collator_selection;
pub mod collective;
pub mod crowdloan_rewards;
pub mod democracy;
pub mod dutch_auction;
pub mod frame_system;
pub mod identity;
pub mod indices;
Expand Down

0 comments on commit fd57666

Please sign in to comment.