From 3b24034ebbcb2b2cfa8735f05acab4e2695c47a3 Mon Sep 17 00:00:00 2001 From: "ron.yang" Date: Thu, 19 Aug 2021 09:51:45 +0800 Subject: [PATCH] Revamp salp xcm weight --- Cargo.lock | 8 +- node/cli/Cargo.toml | 2 +- pallets/salp/Cargo.toml | 3 + pallets/salp/src/lib.rs | 129 ++++++------------ pallets/salp/src/mock.rs | 113 ++++++++++++++- pallets/salp/src/tests.rs | 56 ++++---- pallets/vesting/src/benchmarking.rs | 2 + runtime/asgard/Cargo.toml | 3 + runtime/asgard/src/constants.rs | 27 ++++ runtime/asgard/src/lib.rs | 39 +++++- runtime/asgard/src/weights/bifrost_salp.rs | 41 +++++- runtime/bifrost/Cargo.toml | 1 + runtime/bifrost/src/lib.rs | 48 +++++-- .../bifrost/src/weights/pallet_balances.rs | 14 +- runtime/bifrost/src/weights/pallet_indices.rs | 12 +- .../bifrost/src/weights/pallet_timestamp.rs | 6 +- runtime/bifrost/src/weights/pallet_utility.rs | 16 +-- runtime/bifrost/src/weights/pallet_vesting.rs | 78 +++++------ runtime/dev/Cargo.toml | 2 + runtime/dev/src/constants.rs | 27 ++++ runtime/dev/src/lib.rs | 38 +++++- runtime/dev/src/weights/bifrost_salp.rs | 37 ++++- xcm-support/src/lib.rs | 6 +- xcm-support/src/traits.rs | 2 +- 24 files changed, 494 insertions(+), 216 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0d708521b9..a37d307d97 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -234,8 +234,10 @@ dependencies = [ "parachain-info", "parity-scale-codec", "polkadot-parachain", + "polkadot-primitives", "polkadot-runtime-parachains", "serde", + "smallvec 1.6.1", "sp-api", "sp-arithmetic", "sp-block-builder", @@ -854,9 +856,11 @@ dependencies = [ "orml-tokens", "orml-traits", "pallet-balances", + "pallet-multisig", "pallet-xcm", "parity-scale-codec", "polkadot-parachain", + "smallvec 1.6.1", "sp-arithmetic", "sp-core", "sp-io", @@ -2189,8 +2193,10 @@ dependencies = [ "parachain-info", "parity-scale-codec", "polkadot-parachain", + "polkadot-primitives", "polkadot-runtime-parachains", "serde", + "smallvec 1.6.1", "sp-api", "sp-arithmetic", "sp-block-builder", @@ -4933,7 +4939,7 @@ dependencies = [ [[package]] name = "node-cli" -version = "0.8.1" +version = "0.8.2" dependencies = [ "cumulus-client-cli", "cumulus-client-service", diff --git a/node/cli/Cargo.toml b/node/cli/Cargo.toml index d38fba66a6..43267a8fb6 100644 --- a/node/cli/Cargo.toml +++ b/node/cli/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "node-cli" -version = "0.8.1" +version = "0.8.2" authors = ["Liebi Technologies "] description = "Bifrost Parachain Node" build = "build.rs" diff --git a/pallets/salp/Cargo.toml b/pallets/salp/Cargo.toml index 1cd5e52bcd..3c3c09e1e8 100644 --- a/pallets/salp/Cargo.toml +++ b/pallets/salp/Cargo.toml @@ -24,8 +24,11 @@ polkadot-parachain = { git = "https://github.com/paritytech/polkadot", default-f [dev-dependencies] xcm-builder = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.8" } pallet-xcm = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.8" } +pallet-multisig = { version = "3.0.0"} +smallvec = "1.6.1" sp-io = "3.0.0" sp-core = "3.0.0" +sp-runtime = "3.0.0" orml-tokens = "0.4.1-dev" orml-currencies = "0.4.1-dev" pallet-balances = "3.0.0" diff --git a/pallets/salp/src/lib.rs b/pallets/salp/src/lib.rs index 3598d83895..db320b98c3 100644 --- a/pallets/salp/src/lib.rs +++ b/pallets/salp/src/lib.rs @@ -33,7 +33,7 @@ mod mock; mod tests; // Re-export pallet items so that they can be accessed from the crate namespace. -use frame_support::{pallet_prelude::*, sp_runtime::MultiSignature}; +use frame_support::{pallet_prelude::*, sp_runtime::MultiSignature, transactional}; use node_primitives::{ParaId, TokenInfo, TokenSymbol}; use orml_traits::MultiCurrency; pub use pallet::*; @@ -44,22 +44,12 @@ type TrieIndex = u32; pub trait WeightInfo { fn create() -> Weight; fn contribute() -> Weight; - fn on_finalize(n: u32) -> Weight; -} - -pub struct TestWeightInfo; -impl WeightInfo for TestWeightInfo { - fn create() -> Weight { - 0 - } - - fn contribute() -> Weight { - 0 - } - - fn on_finalize(_n: u32) -> Weight { - 0 - } + fn unlock() -> Weight; + fn withdraw() -> Weight; + fn refund() -> Weight; + fn redeem() -> Weight; + fn dissolve(n: u32) -> Weight; + fn on_initialize(n: u32) -> Weight; } #[allow(type_alias_bounds)] @@ -224,6 +214,7 @@ pub mod pallet { pallet_prelude::{storage::child, *}, sp_runtime::traits::{AccountIdConversion, CheckedAdd, Hash, Saturating, Zero}, storage::ChildTriePrefixIterator, + weights::WeightToFeePolynomial, PalletId, }; use frame_system::pallet_prelude::*; @@ -297,6 +288,8 @@ pub mod pallet { Success = MultiLocation, >; + type EnsureConfirmAsMultiSig: EnsureOrigin<::Origin>; + type BifrostXcmExecutor: BifrostXcmExecutor; #[pallet::constant] @@ -315,6 +308,8 @@ pub mod pallet { #[pallet::constant] type WithdrawWeight: Get; + + type WeightToFee: WeightToFeePolynomial>; } #[pallet::pallet] @@ -335,9 +330,9 @@ pub mod pallet { /// Withdrawing full balance of a contributor. [who, fund_index, amount] Withdrawing(AccountIdOf, ParaId, BalanceOf), /// Withdrew full balance of a contributor. [who, fund_index, amount] - Withdrew(AccountIdOf, ParaId, BalanceOf), + Withdrew(ParaId, BalanceOf), /// Fail on withdraw full balance of a contributor. [who, fund_index, amount] - WithdrawFailed(AccountIdOf, ParaId, BalanceOf), + WithdrawFailed(ParaId, BalanceOf), /// Refunding to account. [who, fund_index, amount] Refunding(AccountIdOf, ParaId, BalanceOf), /// Refunded to account. [who, fund_index, amount] @@ -453,13 +448,11 @@ pub mod pallet { origin: OriginFor, #[pallet::compact] index: ParaId, ) -> DispatchResult { - let owner = ensure_signed(origin)?; + T::EnsureConfirmAsMultiSig::ensure_origin(origin)?; let fund = Self::funds(index).ok_or(Error::::InvalidParaId)?; ensure!(fund.status == FundStatus::Ongoing, Error::::InvalidFundStatus); - ensure!(owner == fund.depositor, Error::::UnauthorizedAccount); - let fund_new = FundInfo { status: FundStatus::Success, ..fund }; Funds::::insert(index, Some(fund_new)); @@ -472,14 +465,12 @@ pub mod pallet { Pays::No ))] pub fn fund_fail(origin: OriginFor, #[pallet::compact] index: ParaId) -> DispatchResult { - let owner = ensure_signed(origin)?; + T::EnsureConfirmAsMultiSig::ensure_origin(origin)?; // crownload is failed, so enable the withdrawal function of vsToken/vsBond let fund = Self::funds(index).ok_or(Error::::InvalidParaId)?; ensure!(fund.status == FundStatus::Ongoing, Error::::InvalidFundStatus); - ensure!(owner == fund.depositor, Error::::UnauthorizedAccount); - let fund_new = FundInfo { status: FundStatus::Failed, ..fund }; Funds::::insert(index, Some(fund_new)); @@ -495,13 +486,11 @@ pub mod pallet { origin: OriginFor, #[pallet::compact] index: ParaId, ) -> DispatchResult { - let owner = ensure_signed(origin)?; + T::EnsureConfirmAsMultiSig::ensure_origin(origin)?; let fund = Self::funds(index).ok_or(Error::::InvalidParaId)?; ensure!(fund.status == FundStatus::Success, Error::::InvalidFundStatus); - ensure!(owner == fund.depositor, Error::::UnauthorizedAccount); - let fund_new = FundInfo { status: FundStatus::Retired, ..fund }; Funds::::insert(index, Some(fund_new)); @@ -514,7 +503,7 @@ pub mod pallet { Pays::No ))] pub fn fund_end(origin: OriginFor, #[pallet::compact] index: ParaId) -> DispatchResult { - let owner = ensure_signed(origin)?; + T::EnsureConfirmAsMultiSig::ensure_origin(origin)?; let fund = Self::funds(index).ok_or(Error::::InvalidParaId)?; ensure!( @@ -523,8 +512,6 @@ pub mod pallet { Error::::InvalidFundStatus ); - ensure!(owner == fund.depositor, Error::::UnauthorizedAccount); - let fund_new = FundInfo { status: FundStatus::End, ..fund }; Funds::::insert(index, Some(fund_new)); @@ -532,11 +519,7 @@ pub mod pallet { } /// Unlock the reserved vsToken/vsBond after fund success - #[pallet::weight(( - 0, - DispatchClass::Normal, - Pays::No - ))] + #[pallet::weight(T::WeightInfo::unlock())] pub fn unlock( _origin: OriginFor, who: AccountIdOf, @@ -574,13 +557,8 @@ pub mod pallet { Ok(()) } - /// TODO: Refactor the docs. /// Create a new crowdloaning campaign for a parachain slot deposit for the current auction. - #[pallet::weight(( - 0, - DispatchClass::Normal, - Pays::No - ))] + #[pallet::weight(T::WeightInfo::create())] pub fn create( origin: OriginFor, #[pallet::compact] index: ParaId, @@ -626,11 +604,8 @@ pub mod pallet { /// Contribute to a crowd sale. This will transfer some balance over to fund a parachain /// slot. It will be withdrawable in two instances: the parachain becomes retired; or the /// slot is unable to be purchased and the timeout expires. - #[pallet::weight(( - 0, - DispatchClass::Normal, - Pays::No - ))] + #[pallet::weight(T::WeightInfo::contribute())] + #[transactional] pub fn contribute( origin: OriginFor, #[pallet::compact] index: ParaId, @@ -675,7 +650,7 @@ pub mod pallet { #[pallet::compact] index: ParaId, is_success: bool, ) -> DispatchResult { - let owner = ensure_signed(origin)?; + T::EnsureConfirmAsMultiSig::ensure_origin(origin)?; let fund = Self::funds(index).ok_or(Error::::InvalidParaId)?; let can_confirm = fund.status == FundStatus::Ongoing || @@ -683,8 +658,6 @@ pub mod pallet { fund.status == FundStatus::Success; ensure!(can_confirm, Error::::InvalidFundStatus); - ensure!(owner == fund.depositor, Error::::UnauthorizedAccount); - let (contributed, status) = Self::contribution(fund.trie_index, &who); ensure!(status.is_contributing(), Error::::InvalidContributionStatus); let contributing = status.contributing(); @@ -736,11 +709,8 @@ pub mod pallet { /// Withdraw full balance of the parachain. this function may need to be called multiple /// times /// - `index`: The parachain to whose crowdloan the contribution was made. - #[pallet::weight(( - 0, - DispatchClass::Normal, - Pays::No - ))] + #[pallet::weight(T::WeightInfo::withdraw())] + #[transactional] pub fn withdraw(origin: OriginFor, #[pallet::compact] index: ParaId) -> DispatchResult { let owner = ensure_signed(origin.clone())?; @@ -768,14 +738,12 @@ pub mod pallet { #[pallet::compact] index: ParaId, is_success: bool, ) -> DispatchResult { - let owner = ensure_signed(origin)?; + T::EnsureConfirmAsMultiSig::ensure_origin(origin)?; let fund = Self::funds(index).ok_or(Error::::InvalidParaId)?; let can = fund.status == FundStatus::Failed || fund.status == FundStatus::Retired; ensure!(can, Error::::InvalidFundStatus); - ensure!(owner == fund.depositor, Error::::UnauthorizedAccount); - let amount_withdrew = fund.raised; if is_success { @@ -791,19 +759,16 @@ pub mod pallet { Funds::::insert(index, Some(fund_new)); } - Self::deposit_event(Event::Withdrew(owner, index, amount_withdrew)); + Self::deposit_event(Event::Withdrew(index, amount_withdrew)); } else { - Self::deposit_event(Event::WithdrawFailed(owner, index, amount_withdrew)); + Self::deposit_event(Event::WithdrawFailed(index, amount_withdrew)); } Ok(()) } - #[pallet::weight(( - 0, - DispatchClass::Normal, - Pays::No - ))] + #[pallet::weight(T::WeightInfo::refund())] + #[transactional] pub fn refund(origin: OriginFor, #[pallet::compact] index: ParaId) -> DispatchResult { let who = ensure_signed(origin.clone())?; @@ -854,13 +819,11 @@ pub mod pallet { #[pallet::compact] index: ParaId, is_success: bool, ) -> DispatchResult { - let owner = ensure_signed(origin)?; + T::EnsureConfirmAsMultiSig::ensure_origin(origin)?; let fund = Self::funds(index).ok_or(Error::::InvalidParaId)?; ensure!(fund.status == FundStatus::RefundWithdrew, Error::::InvalidFundStatus); - ensure!(owner == fund.depositor, Error::::UnauthorizedAccount); - let (contributed, status) = Self::contribution(fund.trie_index, &who); ensure!(status == ContributionStatus::Refunding, Error::::InvalidContributionStatus); @@ -898,11 +861,8 @@ pub mod pallet { Ok(()) } - #[pallet::weight(( - 0, - DispatchClass::Normal, - Pays::No - ))] + #[pallet::weight(T::WeightInfo::redeem())] + #[transactional] pub fn redeem( origin: OriginFor, #[pallet::compact] index: ParaId, @@ -961,7 +921,7 @@ pub mod pallet { ) -> DispatchResult { use RedeemStatus as RS; - ensure_root(origin).map_err(|_| Error::::UnauthorizedAccount)?; + T::EnsureConfirmAsMultiSig::ensure_origin(origin)?; let status = Self::redeem_status(who.clone(), (index, first_slot, last_slot)); ensure!(status.is_redeeming(), Error::::InvalidRedeemStatus); @@ -1002,11 +962,7 @@ pub mod pallet { } /// Remove a fund after the retirement period has ended and all funds have been returned. - #[pallet::weight(( - 0, - DispatchClass::Normal, - Pays::No - ))] + #[pallet::weight(T::WeightInfo::dissolve(T::RemoveKeysLimit::get()))] pub fn dissolve(origin: OriginFor, #[pallet::compact] index: ParaId) -> DispatchResult { let depositor = ensure_signed(origin)?; @@ -1043,7 +999,7 @@ pub mod pallet { #[pallet::hooks] impl Hooks> for Pallet { - fn on_finalize(n: BlockNumberFor) { + fn on_initialize(n: BlockNumberFor) -> Weight { // Release x% KSM/DOT from redeem-pool to bancor-pool per cycle if n != 0 && (n % T::ReleaseCycle::get()) == 0 { if let Ok(rp_balance) = TryInto::::try_into(Self::redeem_pool()) { @@ -1065,14 +1021,10 @@ pub mod pallet { } } } + ::WeightInfo::on_initialize(n) // TODO: Auto unlock vsToken/vsBond? } - - fn on_initialize(_n: BlockNumberFor) -> frame_support::weights::Weight { - // TODO estimate weight - Zero::zero() - } } impl Pallet { @@ -1173,8 +1125,13 @@ pub mod pallet { fn xcm_ump_contribute( _origin: OriginFor, index: ParaId, - value: BalanceOf, + mut value: BalanceOf, ) -> XcmResult { + let fee: BalanceOf = T::WeightToFee::calc(&T::BifrostXcmExecutor::transact_weight( + T::ContributionWeight::get(), + )); + value = value.saturating_sub(fee); + let contribution = Contribution { index, value, signature: None }; let call = CrowdloanContributeCall::CrowdloanContribute(ContributeCall::Contribute( diff --git a/pallets/salp/src/mock.rs b/pallets/salp/src/mock.rs index b0cd356230..f90b121c0f 100644 --- a/pallets/salp/src/mock.rs +++ b/pallets/salp/src/mock.rs @@ -18,7 +18,13 @@ // Ensure we're `no_std` when compiling for Wasm. -use frame_support::{construct_runtime, parameter_types, traits::GenesisBuild, PalletId}; +use frame_support::{ + construct_runtime, parameter_types, + traits::{EnsureOrigin, GenesisBuild}, + weights::{WeightToFeeCoefficient, WeightToFeeCoefficients, WeightToFeePolynomial}, + PalletId, +}; +use frame_system::RawOrigin; use node_primitives::{Amount, Balance, CurrencyId, TokenSymbol, TransferOriginType}; use sp_arithmetic::Percent; use sp_core::H256; @@ -31,9 +37,10 @@ use xcm::{ DoubleEncoded, }; use xcm_builder::{EnsureXcmOrigin, SignedToAccountId32}; -use xcm_support::BifrostXcmExecutor; +use xcm_support::{BifrostXcmExecutor, Weight}; use crate as salp; +use crate::WeightInfo; pub(crate) type AccountId = <::Signer as sp_runtime::traits::IdentifyAccount>::AccountId; pub(crate) type Block = frame_system::mocking::MockBlock; @@ -53,6 +60,7 @@ construct_runtime!( Currencies: orml_currencies::{Pallet, Call, Event}, Tokens: orml_tokens::{Pallet, Call, Storage, Event}, Bancor: bifrost_bancor::{Pallet, Call, Config, Storage, Event}, + Multisig: pallet_multisig::{Pallet, Call, Storage, Event}, Salp: salp::{Pallet, Call, Storage, Event}, } ); @@ -118,6 +126,22 @@ impl pallet_balances::Config for Test { type WeightInfo = pallet_balances::weights::SubstrateWeight; } +parameter_types! { + pub const DepositBase: Balance = 0; + pub const DepositFactor: Balance = 0; + pub const MaxSignatories: u16 = 100; +} + +impl pallet_multisig::Config for Test { + type Call = Call; + type Currency = Balances; + type DepositBase = DepositBase; + type DepositFactor = DepositFactor; + type Event = Event; + type MaxSignatories = MaxSignatories; + type WeightInfo = pallet_multisig::weights::SubstrateWeight; +} + orml_traits::parameter_type_with_key! { pub ExistentialDeposits: |_currency_id: CurrencyId| -> Balance { 0 @@ -165,7 +189,6 @@ parameter_types! { pub const BifrostCrowdloanId: PalletId = PalletId(*b"bf/salp#"); pub const RemoveKeysLimit: u32 = 50; pub const SlotLength: BlockNumber = 8u32 as BlockNumber; - pub const LeasePeriod: BlockNumber = 6 * WEEKS; pub const VSBondValidPeriod: BlockNumber = 30 * DAYS; pub const ReleaseCycle: BlockNumber = 1 * DAYS; @@ -176,6 +199,12 @@ parameter_types! { pub ContributionWeight:u64 = 1_000_000_000 as u64; pub WithdrawWeight:u64 = 1_000_000_000 as u64; pub const SelfParaId: u32 = 2001; + pub PrimaryAccount: AccountId = ALICE; + pub ConfirmMuitiSigAccount: AccountId = Multisig::multi_account_id(&vec![ + ALICE, + BRUCE, + CATHI + ],2); } parameter_types! { @@ -184,6 +213,43 @@ parameter_types! { type LocalOriginToLocation = (SignedToAccountId32,); +pub struct EnsureConfirmAsMultiSig; +impl EnsureOrigin for EnsureConfirmAsMultiSig { + type Success = AccountId; + + fn try_origin(o: Origin) -> Result { + Into::, Origin>>::into(o).and_then(|o| match o { + RawOrigin::Signed(who) => + if who == PrimaryAccount::get() || who == ConfirmMuitiSigAccount::get() { + Ok(who) + } else { + Err(Origin::from(Some(who))) + }, + r => Err(Origin::from(r)), + }) + } + + #[cfg(feature = "runtime-benchmarks")] + fn successful_origin() -> Origin { + Origin::from(RawOrigin::Signed(ConfirmMuitiSigAccount::get())) + } +} + +use smallvec::smallvec; +pub use sp_runtime::Perbill; +pub struct WeightToFee; +impl WeightToFeePolynomial for WeightToFee { + type Balance = Balance; + fn polynomial() -> WeightToFeeCoefficients { + smallvec![WeightToFeeCoefficient { + degree: 1, + negative: false, + coeff_frac: Perbill::from_rational(90u32, 100u32), + coeff_integer: 1, + }] + } +} + impl salp::Config for Test { type BancorPool = Bancor; type BifrostXcmExecutor = MockXcmExecutor; @@ -202,11 +268,48 @@ impl salp::Config for Test { type SubmissionDeposit = SubmissionDeposit; type VSBondValidPeriod = VSBondValidPeriod; type XcmTransferOrigin = XcmTransferOrigin; - type WeightInfo = salp::TestWeightInfo; + type WeightInfo = SalpWeightInfo; type SelfParaId = SelfParaId; type BaseXcmWeight = BaseXcmWeight; type ContributionWeight = ContributionWeight; type WithdrawWeight = WithdrawWeight; + type EnsureConfirmAsMultiSig = EnsureConfirmAsMultiSig; + type WeightToFee = WeightToFee; +} + +pub struct SalpWeightInfo; +impl WeightInfo for SalpWeightInfo { + fn create() -> Weight { + 0 + } + + fn contribute() -> Weight { + 0 + } + + fn unlock() -> Weight { + 0 + } + + fn withdraw() -> Weight { + 0 + } + + fn redeem() -> Weight { + 0 + } + + fn refund() -> Weight { + 0 + } + + fn dissolve(_n: u32) -> Weight { + 0 + } + + fn on_initialize(_n: u32) -> Weight { + 0 + } } // To control the result returned by `MockXcmExecutor` @@ -216,7 +319,7 @@ pub(crate) static mut MOCK_XCM_RESULT: (bool, bool) = (true, true); pub struct MockXcmExecutor; impl BifrostXcmExecutor for MockXcmExecutor { - fn transact_weight() -> u64 { + fn transact_weight(_: u64) -> u64 { return 0; } diff --git a/pallets/salp/src/tests.rs b/pallets/salp/src/tests.rs index ce10ef36e5..029873d174 100644 --- a/pallets/salp/src/tests.rs +++ b/pallets/salp/src/tests.rs @@ -97,10 +97,7 @@ fn set_fund_success_with_wrong_origin_should_fail() { assert_ok!(Salp::create(Some(ALICE).into(), 3_000, 1_000, 1, SlotLength::get())); assert_noop!(Salp::fund_success(Origin::root(), 3_000), DispatchError::BadOrigin); assert_noop!(Salp::fund_success(Origin::none(), 3_000), DispatchError::BadOrigin); - assert_noop!( - Salp::fund_success(Some(BRUCE).into(), 3_000), - Error::::UnauthorizedAccount - ); + assert_noop!(Salp::fund_success(Some(BRUCE).into(), 3_000), DispatchError::BadOrigin); }) } @@ -142,10 +139,7 @@ fn set_fund_fail_with_wrong_origin_should_fail() { assert_ok!(Salp::create(Some(ALICE).into(), 3_000, 1_000, 1, SlotLength::get())); assert_noop!(Salp::fund_fail(Origin::root(), 3_000), DispatchError::BadOrigin); assert_noop!(Salp::fund_fail(Origin::none(), 3_000), DispatchError::BadOrigin); - assert_noop!( - Salp::fund_fail(Some(BRUCE).into(), 3_000), - Error::::UnauthorizedAccount - ); + assert_noop!(Salp::fund_fail(Some(BRUCE).into(), 3_000), DispatchError::BadOrigin); }); } @@ -186,10 +180,7 @@ fn set_fund_retire_with_wrong_origin_should_fail() { assert_ok!(Salp::fund_success(Some(ALICE).into(), 3_000)); assert_noop!(Salp::fund_retire(Origin::root(), 3_000), DispatchError::BadOrigin); assert_noop!(Salp::fund_retire(Origin::none(), 3_000), DispatchError::BadOrigin); - assert_noop!( - Salp::fund_retire(Some(BRUCE).into(), 3_000), - Error::::UnauthorizedAccount - ); + assert_noop!(Salp::fund_retire(Some(BRUCE).into(), 3_000), DispatchError::BadOrigin); }); } @@ -240,7 +231,7 @@ fn set_fund_end_with_wrong_origin_should_fail() { assert_noop!(Salp::fund_end(Origin::root(), 3_000), DispatchError::BadOrigin); assert_noop!(Salp::fund_end(Origin::none(), 3_000), DispatchError::BadOrigin); - assert_noop!(Salp::fund_end(Some(BRUCE).into(), 3_000), Error::::UnauthorizedAccount); + assert_noop!(Salp::fund_end(Some(BRUCE).into(), 3_000), DispatchError::BadOrigin); }); } @@ -463,7 +454,7 @@ fn contribute_with_wrong_origin_should_fail() { ); assert_noop!( Salp::confirm_contribute(Some(BRUCE).into(), BRUCE, 3000, true), - Error::::UnauthorizedAccount, + DispatchError::BadOrigin, ); }); } @@ -942,7 +933,7 @@ fn refund_with_wrong_origin_should_fail() { ); assert_noop!( Salp::confirm_refund(Some(BRUCE).into(), BRUCE, 3_000, true), - Error::::UnauthorizedAccount + DispatchError::BadOrigin ); }); } @@ -1081,7 +1072,14 @@ fn redeem_should_work() { assert_ok!(>::transfer(vsBond, &BRUCE, &CATHI, 50)); assert_ok!(Salp::redeem(Some(BRUCE).into(), 3_000, 1, SlotLength::get(), 50)); - assert_ok!(Salp::confirm_redeem(Origin::root(), BRUCE, 3_000, 1, SlotLength::get(), true)); + assert_ok!(Salp::confirm_redeem( + Some(ALICE).into(), + BRUCE, + 3_000, + 1, + SlotLength::get(), + true + )); assert_eq!(Salp::redeem_pool(), 50); @@ -1093,7 +1091,14 @@ fn redeem_should_work() { assert_eq!(Tokens::accounts(BRUCE, vsBond).reserved, 0); assert_ok!(Salp::redeem(Some(CATHI).into(), 3_000, 1, SlotLength::get(), 50)); - assert_ok!(Salp::confirm_redeem(Origin::root(), CATHI, 3_000, 1, SlotLength::get(), true)); + assert_ok!(Salp::confirm_redeem( + Some(ALICE).into(), + CATHI, + 3_000, + 1, + SlotLength::get(), + true + )); assert_eq!(Salp::redeem_pool(), 0); @@ -1127,7 +1132,14 @@ fn redeem_when_xcm_error_should_work() { let (vsToken, vsBond) = Salp::vsAssets(3_000, 1, SlotLength::get()); assert_ok!(Salp::redeem(Some(BRUCE).into(), 3_000, 1, SlotLength::get(), 50)); - assert_ok!(Salp::confirm_redeem(Origin::root(), BRUCE, 3_000, 1, SlotLength::get(), false)); + assert_ok!(Salp::confirm_redeem( + Some(ALICE).into(), + BRUCE, + 3_000, + 1, + SlotLength::get(), + false + )); assert_eq!(Salp::redeem_pool(), 100); @@ -1181,7 +1193,7 @@ fn confirm_redeem_when_not_in_redeeming_should_fail() { assert_ok!(Salp::confirm_withdraw(Some(ALICE).into(), 3_000, true)); assert_noop!( - Salp::confirm_redeem(Origin::root(), BRUCE, 3_000, 1, SlotLength::get(), true), + Salp::confirm_redeem(Some(ALICE).into(), BRUCE, 3_000, 1, SlotLength::get(), true), Error::::InvalidRedeemStatus ); }); @@ -1215,11 +1227,7 @@ fn redeem_with_wrong_origin_should_fail() { assert_noop!( Salp::confirm_redeem(Origin::none(), BRUCE, 3_000, 1, SlotLength::get(), true), - Error::::UnauthorizedAccount - ); - assert_noop!( - Salp::confirm_redeem(Some(ALICE).into(), BRUCE, 3_000, 1, SlotLength::get(), true), - Error::::UnauthorizedAccount + DispatchError::BadOrigin ); }); } diff --git a/pallets/vesting/src/benchmarking.rs b/pallets/vesting/src/benchmarking.rs index b03daf47d9..1ecf748140 100644 --- a/pallets/vesting/src/benchmarking.rs +++ b/pallets/vesting/src/benchmarking.rs @@ -48,6 +48,8 @@ fn add_vesting_schedule(who: &T::AccountId) -> Result<(), &'static st System::::set_block_number(0u32.into()); + Vesting::::init_vesting_start_at(RawOrigin::Root.into(), 0u32.into())?; + // Add schedule to avoid `NotVesting` error. Vesting::::add_vesting_schedule( &who, diff --git a/runtime/asgard/Cargo.toml b/runtime/asgard/Cargo.toml index a363a7ccba..61ad5ef00a 100644 --- a/runtime/asgard/Cargo.toml +++ b/runtime/asgard/Cargo.toml @@ -12,6 +12,7 @@ log = { version = "0.4.14", default-features = false } serde = { version = "1.0.124", optional = true } static_assertions = "1.1.0" hex-literal = { version = "0.3.1"} +smallvec = "1.6.1" # primitives node-primitives = { default-features = false, path = "../../node/primitives" } @@ -71,6 +72,7 @@ parachain-info = { git = "https://github.com/paritytech/cumulus", default-featur pallet-collator-selection = { git = "https://github.com/paritytech/cumulus", default-features = false, branch = "polkadot-v0.9.8" } # Polkadot dependencies +polkadot-primitives = { git = "https://github.com/paritytech/polkadot", default-features = false,branch = "release-v0.9.8" } polkadot-parachain = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.8" } xcm = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.8" } xcm-builder = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.8" } @@ -160,6 +162,7 @@ std = [ "xcm/std", "xcm-builder/std", "xcm-executor/std", + "polkadot-primitives/std", "polkadot-runtime-parachains/std", "bifrost-bancor/std", "bifrost-bancor-runtime-api/std", diff --git a/runtime/asgard/src/constants.rs b/runtime/asgard/src/constants.rs index a5578d062e..b99e463429 100644 --- a/runtime/asgard/src/constants.rs +++ b/runtime/asgard/src/constants.rs @@ -25,6 +25,7 @@ pub mod currency { pub const BNCS: Balance = 1_000_000_000_000; pub const DOLLARS: Balance = BNCS; pub const CENTS: Balance = DOLLARS / 100; // assume this is worth about a cent. + pub const RELAY_CENTS: Balance = DOLLARS / 30_000; pub const MILLICENTS: Balance = CENTS / 1_000; pub const MILLIBNC: Balance = 1_000_000_000; pub const MICROBNC: Balance = 1_000_000; @@ -82,3 +83,29 @@ pub mod time { pub const ROCOCO_LEASE_PERIOD: BlockNumber = 1 * DAYS; pub const WESTEND_LEASE_PERIOD: BlockNumber = 28 * DAYS; } + +/// Relaychain Fee related. +pub mod relay_fee { + use frame_support::weights::{ + constants::ExtrinsicBaseWeight, WeightToFeeCoefficient, WeightToFeeCoefficients, + WeightToFeePolynomial, + }; + use polkadot_primitives::v0::Balance; + use smallvec::smallvec; + pub use sp_runtime::Perbill; + + pub struct WeightToFee; + impl WeightToFeePolynomial for WeightToFee { + type Balance = Balance; + fn polynomial() -> WeightToFeeCoefficients { + let p = super::currency::RELAY_CENTS; + let q = 10 * Balance::from(ExtrinsicBaseWeight::get()); + smallvec![WeightToFeeCoefficient { + degree: 1, + negative: false, + coeff_frac: Perbill::from_rational(p % q, q), + coeff_integer: p / q, + }] + } + } +} diff --git a/runtime/asgard/src/lib.rs b/runtime/asgard/src/lib.rs index 3dde2028a1..39d4d8b482 100644 --- a/runtime/asgard/src/lib.rs +++ b/runtime/asgard/src/lib.rs @@ -40,8 +40,9 @@ pub use frame_support::{ }; use frame_system::{ limits::{BlockLength, BlockWeights}, - EnsureOneOf, EnsureRoot, + EnsureOneOf, EnsureRoot, RawOrigin, }; +use hex_literal::hex; pub use pallet_balances::Call as BalancesCall; pub use pallet_timestamp::Call as TimestampCall; use sp_api::impl_runtime_apis; @@ -76,7 +77,7 @@ use bifrost_runtime_common::xcm_impl::{ use codec::{Decode, Encode}; use constants::{currency::*, time::*}; use cumulus_primitives_core::ParaId as CumulusParaId; -use frame_support::traits::OnRuntimeUpgrade; +use frame_support::traits::{EnsureOrigin, OnRuntimeUpgrade}; use node_primitives::{ Amount, CurrencyId, Moment, Nonce, TokenSymbol, TransferOriginType, XcmBaseWeight, }; @@ -103,6 +104,8 @@ use zenlink_protocol::{ ZenlinkMultiAssets, }; +use crate::constants::relay_fee::WeightToFee; + mod weights; pub type SessionHandlers = (); @@ -959,6 +962,35 @@ parameter_types! { pub XcmWeight: XcmBaseWeight = XCM_WEIGHT.into(); pub ContributionWeight:u64 = XCM_WEIGHT.into(); pub WithdrawWeight:u64 = XCM_WEIGHT.into(); + pub ConfirmMuitiSigAccount: AccountId = Multisig::multi_account_id(&vec![ + hex!["20b8de78cf83088dd5d8f1e05aeb7122635e5f00015e4cf03e961fe8cc7b9935"].into(), + hex!["0c5192dccfcab3a676d74d3aab838f4d1e6b4f490cf15703424c382c6a72401d"].into(), + hex!["3c7e936535c17ff1ab4c72e4d8bf7672fd8488e5a30a1b3305c959ee7f794f28"].into(), + hex!["eee4ed9bb0a1a72aa966a1a21c403835b5edac59de296be19bd8b2ad31d03f3b"].into(), + hex!["ce6072037670ca8e974fd571eae4f215a58d0bf823b998f619c3f87a911c3541"].into(),//5GjJNWYS6f2UQ9aiLexuB8qgjG8fRs2Ax4nHin1z1engpnNt + ],3); +} + +pub struct EnsureConfirmAsMultiSig; +impl EnsureOrigin for EnsureConfirmAsMultiSig { + type Success = AccountId; + + fn try_origin(o: Origin) -> Result { + Into::, Origin>>::into(o).and_then(|o| match o { + RawOrigin::Signed(who) => + if who == ConfirmMuitiSigAccount::get() { + Ok(who) + } else { + Err(Origin::from(Some(who))) + }, + r => Err(Origin::from(r)), + }) + } + + #[cfg(feature = "runtime-benchmarks")] + fn successful_origin() -> Origin { + Origin::from(RawOrigin::Signed(Default::default())) + } } impl bifrost_salp::Config for Runtime { @@ -984,6 +1016,9 @@ impl bifrost_salp::Config for Runtime { type ContributionWeight = ContributionWeight; type WithdrawWeight = WithdrawWeight; type BaseXcmWeight = XcmWeight; + type EnsureConfirmAsMultiSig = + EnsureOneOf; + type WeightToFee = WeightToFee; } parameter_types! { diff --git a/runtime/asgard/src/weights/bifrost_salp.rs b/runtime/asgard/src/weights/bifrost_salp.rs index 1fabc47330..799212a1be 100644 --- a/runtime/asgard/src/weights/bifrost_salp.rs +++ b/runtime/asgard/src/weights/bifrost_salp.rs @@ -19,7 +19,7 @@ //! Autogenerated weights for bifrost_salp //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 3.0.0 -//! DATE: 2021-08-11, STEPS: `[50, ]`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2021-08-18, STEPS: `[50, ]`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("asgard-local"), DB CACHE: 128 // Executed Command: @@ -42,24 +42,51 @@ use frame_support::{traits::Get, weights::Weight}; use sp_std::marker::PhantomData; -/// Weight functions for bifrost_salp. +/// Weight functions for bifrost_salp +/// @todo benchmark again later pub struct WeightInfo(PhantomData); impl bifrost_salp::WeightInfo for WeightInfo { fn create() -> Weight { - (60_954_000 as Weight) + (38_000_000 as Weight) .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } fn contribute() -> Weight { + (48_000_000 as Weight) + .saturating_add(T::DbWeight::get().reads(4 as Weight)) + .saturating_add(T::DbWeight::get().writes(2 as Weight)) + } + fn unlock() -> Weight { + (0 as Weight) + .saturating_add(T::DbWeight::get().reads(2 as Weight)) + .saturating_add(T::DbWeight::get().writes(2 as Weight)) + } + fn withdraw() -> Weight { (64_140_000 as Weight) .saturating_add(T::DbWeight::get().reads(4 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } - fn on_finalize(n: u32) -> Weight { + fn redeem() -> Weight { + (110_824_000 as Weight) + .saturating_add(T::DbWeight::get().reads(4 as Weight)) + .saturating_add(T::DbWeight::get().writes(4 as Weight)) + } + fn refund() -> Weight { + (110_824_000 as Weight) + .saturating_add(T::DbWeight::get().reads(4 as Weight)) + .saturating_add(T::DbWeight::get().writes(4 as Weight)) + } + fn dissolve(k: u32) -> Weight { + (0 as Weight) + .saturating_add((45_890_000 as Weight).saturating_mul(k as Weight)) + .saturating_add(T::DbWeight::get().reads(3 as Weight)) + .saturating_add(T::DbWeight::get().reads((2 as Weight).saturating_mul(k as Weight))) + .saturating_add(T::DbWeight::get().writes(2 as Weight)) + .saturating_add(T::DbWeight::get().writes((2 as Weight).saturating_mul(k as Weight))) + } + fn on_initialize(_n: u32) -> Weight { (9_002_000 as Weight) - // Standard Error: 0 - .saturating_add((235_000 as Weight).saturating_mul(n as Weight)) - .saturating_add(T::DbWeight::get().reads(1 as Weight)) + .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } } diff --git a/runtime/bifrost/Cargo.toml b/runtime/bifrost/Cargo.toml index 62324a5a6b..4eb35f5b72 100644 --- a/runtime/bifrost/Cargo.toml +++ b/runtime/bifrost/Cargo.toml @@ -149,6 +149,7 @@ runtime-benchmarks = [ "pallet-timestamp/runtime-benchmarks", "pallet-treasury/runtime-benchmarks", "pallet-utility/runtime-benchmarks", + "pallet-vesting/runtime-benchmarks", "pallet-xcm/runtime-benchmarks", "sp-runtime/runtime-benchmarks", "xcm-builder/runtime-benchmarks", diff --git a/runtime/bifrost/src/lib.rs b/runtime/bifrost/src/lib.rs index 939ea2d6ef..d73dd9f393 100644 --- a/runtime/bifrost/src/lib.rs +++ b/runtime/bifrost/src/lib.rs @@ -29,7 +29,7 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); // A few exports that help ease life for downstream crates. pub use frame_support::{ construct_runtime, match_type, parameter_types, - traits::{All, Filter, IsInVec, Randomness}, + traits::{All, Contains, Filter, IsInVec, Randomness}, weights::{ constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND}, DispatchClass, IdentityFee, Weight, @@ -46,7 +46,7 @@ use sp_core::OpaqueMetadata; pub use sp_runtime::BuildStorage; use sp_runtime::{ create_runtime_str, generic, impl_opaque_keys, - traits::{BlakeTwo256, Block as BlockT, Zero}, + traits::{AccountIdConversion, BlakeTwo256, Block as BlockT}, transaction_validity::{TransactionSource, TransactionValidity}, ApplyExtrinsicResult, }; @@ -95,7 +95,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("bifrost"), impl_name: create_runtime_str!("bifrost"), authoring_version: 1, - spec_version: 801, + spec_version: 802, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 1, @@ -156,11 +156,19 @@ impl Filter for CallFilter { } parameter_types! { - pub const NativeCurrencyId: CurrencyId = CurrencyId::Native(TokenSymbol::ASG); + pub const NativeCurrencyId: CurrencyId = CurrencyId::Native(TokenSymbol::BNC); pub const RelayCurrencyId: CurrencyId = CurrencyId::Token(TokenSymbol::KSM); pub const StableCurrencyId: CurrencyId = CurrencyId::Stable(TokenSymbol::KUSD); } +parameter_types! { + pub const TreasuryPalletId: PalletId = PalletId(*b"bf/trsry"); +} + +pub fn get_all_pallet_accounts() -> Vec { + vec![TreasuryPalletId::get().into_account()] +} + impl frame_system::Config for Runtime { type AccountData = pallet_balances::AccountData; /// The identifier used to distinguish between accounts. @@ -512,34 +520,46 @@ impl pallet_vesting::Config for Runtime { // orml runtime start -pub type BifrostToken = BasicCurrencyAdapter; - impl orml_currencies::Config for Runtime { type Event = Event; type GetNativeCurrencyId = NativeCurrencyId; type MultiCurrency = Tokens; - type NativeCurrency = BifrostToken; + type NativeCurrency = BasicCurrencyAdapter; type WeightInfo = (); } orml_traits::parameter_type_with_key! { pub ExistentialDeposits: |currency_id: CurrencyId| -> Balance { match currency_id { - &CurrencyId::Native(TokenSymbol::ASG) => 1 * CENTS, - _ => Zero::zero(), + &CurrencyId::Native(TokenSymbol::BNC) => 10 * MILLIBNC, + &CurrencyId::Token(TokenSymbol::KSM) => 10 * MILLICENTS, + &CurrencyId::VSToken(TokenSymbol::KSM) => 10 * MILLICENTS, + &CurrencyId::VSBond(TokenSymbol::BNC, ..) => 10 * MILLICENTS, + _ => Balance::max_value() // unsupported } }; } +pub struct DustRemovalWhitelist; +impl Contains for DustRemovalWhitelist { + fn contains(a: &AccountId) -> bool { + get_all_pallet_accounts().contains(a) + } +} + +parameter_types! { + pub BifrostTreasuryAccount: AccountId = TreasuryPalletId::get().into_account(); +} + impl orml_tokens::Config for Runtime { type Amount = Amount; type Balance = Balance; type CurrencyId = CurrencyId; - type DustRemovalWhitelist = (); + type DustRemovalWhitelist = DustRemovalWhitelist; type Event = Event; type ExistentialDeposits = ExistentialDeposits; type MaxLocks = MaxLocks; - type OnDust = (); + type OnDust = orml_tokens::TransferDust; type WeightInfo = (); } @@ -550,7 +570,6 @@ impl orml_tokens::Config for Runtime { // pub const ProposalBondMinimum: Balance = 50 * DOLLARS; // pub const SpendPeriod: BlockNumber = 6 * DAYS; // pub const Burn: Permill = Permill::from_perthousand(2); -// pub const TreasuryPalletId: PalletId = PalletId(*b"py/trsry"); // // pub const TipCountdown: BlockNumber = 1 * DAYS; // pub const TipFindersFee: Percent = Percent::from_percent(20); @@ -815,12 +834,13 @@ impl_runtime_apis! { // Adding the pallet you will perform thee benchmarking add_benchmark!(params, batches, pallet_balances, Balances); - add_benchmark!(params, batches, pallet_bounties, Bounties); + // add_benchmark!(params, batches, pallet_bounties, Bounties); add_benchmark!(params, batches, pallet_indices, Indices); add_benchmark!(params, batches, pallet_scheduler, Scheduler); add_benchmark!(params, batches, pallet_timestamp, Timestamp); - add_benchmark!(params, batches, pallet_treasury, Treasury); + // add_benchmark!(params, batches, pallet_treasury, Treasury); add_benchmark!(params, batches, pallet_utility, Utility); + add_benchmark!(params, batches, pallet_vesting, Vesting); if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) } Ok(batches) diff --git a/runtime/bifrost/src/weights/pallet_balances.rs b/runtime/bifrost/src/weights/pallet_balances.rs index a0aa9b6039..082f8bad67 100644 --- a/runtime/bifrost/src/weights/pallet_balances.rs +++ b/runtime/bifrost/src/weights/pallet_balances.rs @@ -19,7 +19,7 @@ //! Autogenerated weights for pallet_balances //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 3.0.0 -//! DATE: 2021-08-16, STEPS: `[50, ]`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2021-08-18, STEPS: `[50, ]`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("bifrost-genesis"), DB CACHE: 128 // Executed Command: @@ -46,32 +46,32 @@ use sp_std::marker::PhantomData; pub struct WeightInfo(PhantomData); impl pallet_balances::WeightInfo for WeightInfo { fn transfer() -> Weight { - (248_276_000 as Weight) + (186_397_000 as Weight) .saturating_add(T::DbWeight::get().reads(6 as Weight)) .saturating_add(T::DbWeight::get().writes(4 as Weight)) } fn transfer_keep_alive() -> Weight { - (184_967_000 as Weight) + (149_209_000 as Weight) .saturating_add(T::DbWeight::get().reads(5 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } fn set_balance_creating() -> Weight { - (95_890_000 as Weight) + (91_298_000 as Weight) .saturating_add(T::DbWeight::get().reads(6 as Weight)) .saturating_add(T::DbWeight::get().writes(4 as Weight)) } fn set_balance_killing() -> Weight { - (115_106_000 as Weight) + (102_324_000 as Weight) .saturating_add(T::DbWeight::get().reads(6 as Weight)) .saturating_add(T::DbWeight::get().writes(4 as Weight)) } fn force_transfer() -> Weight { - (246_112_000 as Weight) + (185_362_000 as Weight) .saturating_add(T::DbWeight::get().reads(7 as Weight)) .saturating_add(T::DbWeight::get().writes(5 as Weight)) } fn transfer_all() -> Weight { - (226_555_000 as Weight) + (168_296_000 as Weight) .saturating_add(T::DbWeight::get().reads(5 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } diff --git a/runtime/bifrost/src/weights/pallet_indices.rs b/runtime/bifrost/src/weights/pallet_indices.rs index 5342a9c9d2..219fc805df 100644 --- a/runtime/bifrost/src/weights/pallet_indices.rs +++ b/runtime/bifrost/src/weights/pallet_indices.rs @@ -19,7 +19,7 @@ //! Autogenerated weights for pallet_indices //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 3.0.0 -//! DATE: 2021-08-16, STEPS: `[50, ]`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2021-08-18, STEPS: `[50, ]`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("bifrost-genesis"), DB CACHE: 128 // Executed Command: @@ -46,27 +46,27 @@ use sp_std::marker::PhantomData; pub struct WeightInfo(PhantomData); impl pallet_indices::WeightInfo for WeightInfo { fn claim() -> Weight { - (130_555_000 as Weight) + (110_804_000 as Weight) .saturating_add(T::DbWeight::get().reads(5 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } fn transfer() -> Weight { - (164_299_000 as Weight) + (143_279_000 as Weight) .saturating_add(T::DbWeight::get().reads(6 as Weight)) .saturating_add(T::DbWeight::get().writes(4 as Weight)) } fn free() -> Weight { - (132_599_000 as Weight) + (112_222_000 as Weight) .saturating_add(T::DbWeight::get().reads(5 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } fn force_transfer() -> Weight { - (134_983_000 as Weight) + (114_400_000 as Weight) .saturating_add(T::DbWeight::get().reads(6 as Weight)) .saturating_add(T::DbWeight::get().writes(4 as Weight)) } fn freeze() -> Weight { - (120_396_000 as Weight) + (112_784_000 as Weight) .saturating_add(T::DbWeight::get().reads(6 as Weight)) .saturating_add(T::DbWeight::get().writes(4 as Weight)) } diff --git a/runtime/bifrost/src/weights/pallet_timestamp.rs b/runtime/bifrost/src/weights/pallet_timestamp.rs index 5d7aa90739..300a57b234 100644 --- a/runtime/bifrost/src/weights/pallet_timestamp.rs +++ b/runtime/bifrost/src/weights/pallet_timestamp.rs @@ -19,7 +19,7 @@ //! Autogenerated weights for pallet_timestamp //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 3.0.0 -//! DATE: 2021-08-16, STEPS: `[50, ]`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2021-08-18, STEPS: `[50, ]`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("bifrost-genesis"), DB CACHE: 128 // Executed Command: @@ -46,11 +46,11 @@ use sp_std::marker::PhantomData; pub struct WeightInfo(PhantomData); impl pallet_timestamp::WeightInfo for WeightInfo { fn set() -> Weight { - (24_637_000 as Weight) + (19_335_000 as Weight) .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } fn on_finalize() -> Weight { - (11_001_000 as Weight) + (10_593_000 as Weight) } } diff --git a/runtime/bifrost/src/weights/pallet_utility.rs b/runtime/bifrost/src/weights/pallet_utility.rs index 43b35b9219..3c1c131d47 100644 --- a/runtime/bifrost/src/weights/pallet_utility.rs +++ b/runtime/bifrost/src/weights/pallet_utility.rs @@ -19,7 +19,7 @@ //! Autogenerated weights for pallet_utility //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 3.0.0 -//! DATE: 2021-08-16, STEPS: `[50, ]`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2021-08-18, STEPS: `[50, ]`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("bifrost-genesis"), DB CACHE: 128 // Executed Command: @@ -46,19 +46,19 @@ use sp_std::marker::PhantomData; pub struct WeightInfo(PhantomData); impl pallet_utility::WeightInfo for WeightInfo { fn batch(c: u32) -> Weight { - (44_360_000 as Weight) - // Standard Error: 7_000 - .saturating_add((6_778_000 as Weight).saturating_mul(c as Weight)) + (41_767_000 as Weight) + // Standard Error: 1_000 + .saturating_add((4_248_000 as Weight).saturating_mul(c as Weight)) .saturating_add(T::DbWeight::get().reads(4 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } fn as_derivative() -> Weight { - (19_316_000 as Weight) + (11_279_000 as Weight) } fn batch_all(c: u32) -> Weight { - (638_011_000 as Weight) - // Standard Error: 79_000 - .saturating_add((6_251_000 as Weight).saturating_mul(c as Weight)) + (47_341_000 as Weight) + // Standard Error: 1_000 + .saturating_add((5_234_000 as Weight).saturating_mul(c as Weight)) .saturating_add(T::DbWeight::get().reads(4 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } diff --git a/runtime/bifrost/src/weights/pallet_vesting.rs b/runtime/bifrost/src/weights/pallet_vesting.rs index 86dac90d23..89c3da1b32 100644 --- a/runtime/bifrost/src/weights/pallet_vesting.rs +++ b/runtime/bifrost/src/weights/pallet_vesting.rs @@ -15,16 +15,17 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . + //! Autogenerated weights for pallet_vesting //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 3.0.0 -//! DATE: 2021-04-27, STEPS: `[50, ]`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` -//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("kusama-dev"), DB CACHE: 128 +//! DATE: 2021-08-18, STEPS: `[50, ]`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("bifrost-genesis"), DB CACHE: 128 // Executed Command: -// target/release/polkadot +// target/release/bifrost // benchmark -// --chain=kusama-dev +// --chain=bifrost-genesis // --steps=50 // --repeat=20 // --pallet=pallet_vesting @@ -32,8 +33,8 @@ // --execution=wasm // --wasm-execution=compiled // --heap-pages=4096 -// --header=./file_header.txt -// --output=./runtime/kusama/src/weights/ +// --header=./HEADER-GPL3 +// --output=./runtime/bifrost/src/weights/ #![allow(unused_parens)] #![allow(unused_imports)] @@ -45,50 +46,45 @@ use sp_std::marker::PhantomData; pub struct WeightInfo(PhantomData); impl pallet_vesting::WeightInfo for WeightInfo { fn vest_locked(l: u32) -> Weight { - (40_504_000 as Weight) - // Standard Error: 20_000 - .saturating_add((261_000 as Weight).saturating_mul(l as Weight)) - .saturating_add(T::DbWeight::get().reads(2 as Weight)) - .saturating_add(T::DbWeight::get().writes(1 as Weight)) + (139_430_000 as Weight) + // Standard Error: 29_000 + .saturating_add((723_000 as Weight).saturating_mul(l as Weight)) + .saturating_add(T::DbWeight::get().reads(7 as Weight)) + .saturating_add(T::DbWeight::get().writes(3 as Weight)) } - fn vest_unlocked(l: u32) -> Weight { - (44_880_000 as Weight) - // Standard Error: 2_000 - .saturating_add((138_000 as Weight).saturating_mul(l as Weight)) - .saturating_add(T::DbWeight::get().reads(2 as Weight)) - .saturating_add(T::DbWeight::get().writes(2 as Weight)) + (144_165_000 as Weight) + // Standard Error: 13_000 + .saturating_add((713_000 as Weight).saturating_mul(l as Weight)) + .saturating_add(T::DbWeight::get().reads(7 as Weight)) + .saturating_add(T::DbWeight::get().writes(4 as Weight)) } - fn vest_other_locked(l: u32) -> Weight { - (39_872_000 as Weight) - // Standard Error: 20_000 - .saturating_add((265_000 as Weight).saturating_mul(l as Weight)) - .saturating_add(T::DbWeight::get().reads(3 as Weight)) - .saturating_add(T::DbWeight::get().writes(2 as Weight)) + (132_758_000 as Weight) + // Standard Error: 24_000 + .saturating_add((752_000 as Weight).saturating_mul(l as Weight)) + .saturating_add(T::DbWeight::get().reads(8 as Weight)) + .saturating_add(T::DbWeight::get().writes(4 as Weight)) } - fn vest_other_unlocked(l: u32) -> Weight { - (44_683_000 as Weight) - // Standard Error: 1_000 - .saturating_add((137_000 as Weight).saturating_mul(l as Weight)) - .saturating_add(T::DbWeight::get().reads(3 as Weight)) - .saturating_add(T::DbWeight::get().writes(3 as Weight)) + (138_258_000 as Weight) + // Standard Error: 13_000 + .saturating_add((723_000 as Weight).saturating_mul(l as Weight)) + .saturating_add(T::DbWeight::get().reads(8 as Weight)) + .saturating_add(T::DbWeight::get().writes(5 as Weight)) } - fn vested_transfer(l: u32) -> Weight { - (95_999_000 as Weight) - // Standard Error: 17_000 - .saturating_add((242_000 as Weight).saturating_mul(l as Weight)) - .saturating_add(T::DbWeight::get().reads(3 as Weight)) - .saturating_add(T::DbWeight::get().writes(3 as Weight)) + (249_078_000 as Weight) + // Standard Error: 23_000 + .saturating_add((741_000 as Weight).saturating_mul(l as Weight)) + .saturating_add(T::DbWeight::get().reads(8 as Weight)) + .saturating_add(T::DbWeight::get().writes(5 as Weight)) } - fn force_vested_transfer(l: u32) -> Weight { - (95_418_000 as Weight) - // Standard Error: 17_000 - .saturating_add((242_000 as Weight).saturating_mul(l as Weight)) - .saturating_add(T::DbWeight::get().reads(4 as Weight)) - .saturating_add(T::DbWeight::get().writes(4 as Weight)) + (246_188_000 as Weight) + // Standard Error: 23_000 + .saturating_add((749_000 as Weight).saturating_mul(l as Weight)) + .saturating_add(T::DbWeight::get().reads(9 as Weight)) + .saturating_add(T::DbWeight::get().writes(6 as Weight)) } } diff --git a/runtime/dev/Cargo.toml b/runtime/dev/Cargo.toml index 97042e061d..ace5594ded 100644 --- a/runtime/dev/Cargo.toml +++ b/runtime/dev/Cargo.toml @@ -12,6 +12,7 @@ log = { version = "0.4.14", default-features = false } serde = { version = "1.0.124", optional = true } static_assertions = "1.1.0" hex-literal = { version = "0.3.1"} +smallvec = "1.6.1" # primitives node-primitives = { default-features = false, path = "../../node/primitives" } @@ -72,6 +73,7 @@ parachain-info = { git = "https://github.com/paritytech/cumulus", default-featur pallet-collator-selection = { git = "https://github.com/paritytech/cumulus", default-features = false, branch = "polkadot-v0.9.8" } # Polkadot dependencies +polkadot-primitives = { git = "https://github.com/paritytech/polkadot", default-features = false,branch = "release-v0.9.8" } polkadot-parachain = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.8" } xcm = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.8" } xcm-builder = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.8" } diff --git a/runtime/dev/src/constants.rs b/runtime/dev/src/constants.rs index 55c3881a59..26acb5eb92 100644 --- a/runtime/dev/src/constants.rs +++ b/runtime/dev/src/constants.rs @@ -25,6 +25,7 @@ pub mod currency { pub const BNCS: Balance = 1_000_000_000_000; pub const DOLLARS: Balance = BNCS; pub const CENTS: Balance = DOLLARS / 100; // assume this is worth about a cent. + pub const RELAY_CENTS: Balance = DOLLARS / 30_000; pub const MILLICENTS: Balance = CENTS / 1_000; pub const MILLIBNC: Balance = 1_000_000_000; pub const MICROBNC: Balance = 1_000_000; @@ -82,3 +83,29 @@ pub mod time { pub const ROCOCO_LEASE_PERIOD: BlockNumber = 1 * DAYS; pub const WESTEND_LEASE_PERIOD: BlockNumber = 28 * DAYS; } + +/// Relaychain Fee related. +pub mod relay_fee { + use frame_support::weights::{ + constants::ExtrinsicBaseWeight, WeightToFeeCoefficient, WeightToFeeCoefficients, + WeightToFeePolynomial, + }; + use polkadot_primitives::v0::Balance; + use smallvec::smallvec; + pub use sp_runtime::Perbill; + + pub struct WeightToFee; + impl WeightToFeePolynomial for WeightToFee { + type Balance = Balance; + fn polynomial() -> WeightToFeeCoefficients { + let p = super::currency::RELAY_CENTS; + let q = 10 * Balance::from(ExtrinsicBaseWeight::get()); + smallvec![WeightToFeeCoefficient { + degree: 1, + negative: false, + coeff_frac: Perbill::from_rational(p % q, q), + coeff_integer: p / q, + }] + } + } +} diff --git a/runtime/dev/src/lib.rs b/runtime/dev/src/lib.rs index 889cd3a7b4..c107835724 100644 --- a/runtime/dev/src/lib.rs +++ b/runtime/dev/src/lib.rs @@ -40,8 +40,9 @@ pub use frame_support::{ }; use frame_system::{ limits::{BlockLength, BlockWeights}, - EnsureOneOf, EnsureRoot, + EnsureOneOf, EnsureRoot, RawOrigin, }; +use hex_literal::hex; pub use pallet_balances::Call as BalancesCall; use pallet_grandpa::{ fg_primitives, AuthorityId as GrandpaId, AuthorityList as GrandpaAuthorityList, @@ -79,7 +80,10 @@ use bifrost_runtime_common::xcm_impl::{ use codec::{Decode, Encode}; use constants::{currency::*, time::*}; use cumulus_primitives_core::ParaId as CumulusParaId; -use frame_support::{sp_runtime::KeyTypeId, traits::KeyOwnerProofSystem}; +use frame_support::{ + sp_runtime::KeyTypeId, + traits::{EnsureOrigin, KeyOwnerProofSystem}, +}; use node_primitives::{ Amount, CurrencyId, Moment, Nonce, TokenSymbol, TransferOriginType, XcmBaseWeight, }; @@ -915,6 +919,8 @@ impl bifrost_minter_reward::Config for Runtime { type WeightInfo = weights::bifrost_minter_reward::WeightInfo; } +use crate::constants::relay_fee::WeightToFee; + parameter_types! { pub const SubmissionDeposit: Balance = 100 * DOLLARS; pub const MinContribution: Balance = 1 * DOLLARS; @@ -929,6 +935,32 @@ parameter_types! { pub XcmWeight: XcmBaseWeight = XCM_WEIGHT.into(); pub ContributionWeight:u64 = XCM_WEIGHT.into(); pub WithdrawWeight:u64 = XCM_WEIGHT.into(); + pub ConfirmMuitiSigAccount: AccountId = hex![ + "ce6072037670ca8e974fd571eae4f215a58d0bf823b998f619c3f87a911c3541" + ] + .into(); +} + +pub struct EnsureConfirmAsMultiSig; +impl EnsureOrigin for EnsureConfirmAsMultiSig { + type Success = AccountId; + + fn try_origin(o: Origin) -> Result { + Into::, Origin>>::into(o).and_then(|o| match o { + RawOrigin::Signed(who) => + if who == ConfirmMuitiSigAccount::get() { + Ok(who) + } else { + Err(Origin::from(Some(who))) + }, + r => Err(Origin::from(r)), + }) + } + + #[cfg(feature = "runtime-benchmarks")] + fn successful_origin() -> Origin { + Origin::from(RawOrigin::Signed(ConfirmMuitiSigAccount::get())) + } } impl bifrost_salp::Config for Runtime { @@ -954,6 +986,8 @@ impl bifrost_salp::Config for Runtime { type ContributionWeight = ContributionWeight; type WithdrawWeight = WithdrawWeight; type BaseXcmWeight = XcmWeight; + type EnsureConfirmAsMultiSig = EnsureConfirmAsMultiSig; + type WeightToFee = WeightToFee; } parameter_types! { diff --git a/runtime/dev/src/weights/bifrost_salp.rs b/runtime/dev/src/weights/bifrost_salp.rs index 1fabc47330..1ef5490cc6 100644 --- a/runtime/dev/src/weights/bifrost_salp.rs +++ b/runtime/dev/src/weights/bifrost_salp.rs @@ -42,7 +42,8 @@ use frame_support::{traits::Get, weights::Weight}; use sp_std::marker::PhantomData; -/// Weight functions for bifrost_salp. +/// Weight functions for bifrost_salp +/// @todo benchmark again later pub struct WeightInfo(PhantomData); impl bifrost_salp::WeightInfo for WeightInfo { fn create() -> Weight { @@ -55,11 +56,37 @@ impl bifrost_salp::WeightInfo for WeightInfo { .saturating_add(T::DbWeight::get().reads(4 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } - fn on_finalize(n: u32) -> Weight { + fn unlock() -> Weight { + (0 as Weight) + .saturating_add(T::DbWeight::get().reads(2 as Weight)) + .saturating_add(T::DbWeight::get().writes(2 as Weight)) + } + fn withdraw() -> Weight { + (64_140_000 as Weight) + .saturating_add(T::DbWeight::get().reads(4 as Weight)) + .saturating_add(T::DbWeight::get().writes(2 as Weight)) + } + fn redeem() -> Weight { + (110_824_000 as Weight) + .saturating_add(T::DbWeight::get().reads(4 as Weight)) + .saturating_add(T::DbWeight::get().writes(4 as Weight)) + } + fn refund() -> Weight { + (110_824_000 as Weight) + .saturating_add(T::DbWeight::get().reads(4 as Weight)) + .saturating_add(T::DbWeight::get().writes(4 as Weight)) + } + fn dissolve(k: u32) -> Weight { + (0 as Weight) + .saturating_add((45_890_000 as Weight).saturating_mul(k as Weight)) + .saturating_add(T::DbWeight::get().reads(3 as Weight)) + .saturating_add(T::DbWeight::get().reads((2 as Weight).saturating_mul(k as Weight))) + .saturating_add(T::DbWeight::get().writes(2 as Weight)) + .saturating_add(T::DbWeight::get().writes((2 as Weight).saturating_mul(k as Weight))) + } + fn on_initialize(_n: u32) -> Weight { (9_002_000 as Weight) - // Standard Error: 0 - .saturating_add((235_000 as Weight).saturating_mul(n as Weight)) - .saturating_add(T::DbWeight::get().reads(1 as Weight)) + .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } } diff --git a/xcm-support/src/lib.rs b/xcm-support/src/lib.rs index f9cbc48600..3de31d1de8 100644 --- a/xcm-support/src/lib.rs +++ b/xcm-support/src/lib.rs @@ -156,8 +156,8 @@ pub struct BifrostXcmAdaptor(PhantomData<(XcmSender, B impl> BifrostXcmExecutor for BifrostXcmAdaptor { - fn transact_weight() -> u64 { - return 4 * BaseXcmWeight::get(); + fn transact_weight(weight: u64) -> u64 { + return weight + 4 * BaseXcmWeight::get(); } fn ump_transact( @@ -169,7 +169,7 @@ impl> BifrostXcmExecutor let mut message = Xcm::WithdrawAsset { assets: vec![MultiAsset::ConcreteFungible { id: MultiLocation::Null, - amount: (weight + Self::transact_weight()) as u128, + amount: Self::transact_weight(weight) as u128, }], effects: vec![Order::BuyExecution { fees: MultiAsset::All, diff --git a/xcm-support/src/traits.rs b/xcm-support/src/traits.rs index 130a8bb316..0c91f4c1f1 100644 --- a/xcm-support/src/traits.rs +++ b/xcm-support/src/traits.rs @@ -43,7 +43,7 @@ pub trait HandleXcmpMessage { /// Bifrost Xcm Executor pub trait BifrostXcmExecutor { - fn transact_weight() -> u64; + fn transact_weight(weight: u64) -> u64; fn ump_transact( origin: MultiLocation,