diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 0455a10b4..3a88ae70b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -93,7 +93,7 @@ jobs: ${{ github.workspace }}/artifacts/bifrost_polkadot_runtime.compact.compressed.wasm - uses: 8398a7/action-slack@v3 - if: failure() + if: always() with: status: ${{ job.status }} fields: repo,author,eventName,workflow,ref,commit diff --git a/Cargo.lock b/Cargo.lock index c59217f2b..e5a4927f4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1640,9 +1640,10 @@ dependencies = [ name = "bifrost-vtoken-voting" version = "0.8.0" dependencies = [ + "assert_matches", "bifrost-currencies", + "bifrost-slp", "cumulus-primitives-core", - "env_logger 0.10.0", "frame-benchmarking", "frame-support", "frame-system", diff --git a/integration-tests/bifrost-kusama/src/kusama_cross_chain_transact.rs b/integration-tests/bifrost-kusama/src/kusama_cross_chain_transact.rs index 1c9047b56..064828546 100644 --- a/integration-tests/bifrost-kusama/src/kusama_cross_chain_transact.rs +++ b/integration-tests/bifrost-kusama/src/kusama_cross_chain_transact.rs @@ -67,9 +67,7 @@ fn relaychain_transact_works() { }); Bifrost::execute_with(|| { - // QueryStatus::Pending { responder: V3(MultiLocation { parents: 1, interior: Here }), - // maybe_match_querier: Some(V3(MultiLocation { parents: 0, interior: Here })), - // maybe_notify: Some((0, 7)), timeout: 100 } let query_id = + let notify_vote_call_weight = notify_vote_call.get_dispatch_info().weight; let query_id = pallet_xcm::Pallet::::new_notify_query( MultiLocation::parent(), notify_vote_call, @@ -77,23 +75,20 @@ fn relaychain_transact_works() { Here, ); - // QueryResponse { query_id: 0, response: DispatchResult(Success), max_weight: Weight { - // ref_time: 4000000000, proof_size: 0 }, querier: Some(MultiLocation { parents: 0, - // interior: Here }) } let asset: MultiAsset = - MultiAsset { id: Concrete(MultiLocation::here()), fun: Fungible(4000000000) }; + MultiAsset { id: Concrete(MultiLocation::here()), fun: Fungible(517318631) }; let msg = Xcm(vec![ WithdrawAsset(asset.clone().into()), BuyExecution { fees: asset, weight_limit: Unlimited }, Transact { origin_kind: OriginKind::SovereignAccount, - require_weight_at_most: Weight::from_parts(4000000000, 100000), + require_weight_at_most: Weight::from_parts(961496000, 83866), call: vote_call.encode().into(), }, ReportTransactStatus(QueryResponseInfo { destination: MultiLocation::from(X1(Parachain(2001))), query_id, - max_weight: Weight::from_parts(3000000, 0), + max_weight: notify_vote_call_weight, }), RefundSurplus, DepositAsset { diff --git a/integration-tests/bifrost-kusama/src/vtoken_voting.rs b/integration-tests/bifrost-kusama/src/vtoken_voting.rs index 878bf57ff..63b45c705 100644 --- a/integration-tests/bifrost-kusama/src/vtoken_voting.rs +++ b/integration-tests/bifrost-kusama/src/vtoken_voting.rs @@ -63,7 +63,7 @@ fn vote_works() { RuntimeOrigin::root(), MultiAddress::Id(ALICE.into()), VKSM, - 10_000_000_000_000u64.into(), + u64::MAX.into(), Zero::zero(), )); let token = CurrencyId::to_token(&vtoken).unwrap(); @@ -86,7 +86,7 @@ fn vote_works() { delegator_active_staking_maximum: 0u32.into(), validators_reward_maximum: 0u32, delegation_amount_minimum: 0u32.into(), - delegators_maximum: 10u16, + delegators_maximum: u16::MAX, validators_maximum: 0u16, }) )); diff --git a/node/primitives/Cargo.toml b/node/primitives/Cargo.toml index 47447d30b..dd44acaaf 100644 --- a/node/primitives/Cargo.toml +++ b/node/primitives/Cargo.toml @@ -43,3 +43,4 @@ with-bifrost-runtime = [ with-bifrost-kusama-runtime = [] with-bifrost-polkadot-runtime = [] with-all-runtime = ["with-bifrost-runtime"] +runtime-benchmarks = [] \ No newline at end of file diff --git a/node/primitives/src/lib.rs b/node/primitives/src/lib.rs index f74a23b72..702e71796 100644 --- a/node/primitives/src/lib.rs +++ b/node/primitives/src/lib.rs @@ -136,6 +136,8 @@ pub type TrieIndex = u32; /// Distribution Id pub type DistributionId = u32; +pub type DerivativeIndex = u16; + #[derive( Encode, Decode, Eq, PartialEq, Copy, Clone, RuntimeDebug, PartialOrd, Ord, scale_info::TypeInfo, )] diff --git a/node/primitives/src/traits.rs b/node/primitives/src/traits.rs index 00b2dafd6..6d1a6c292 100644 --- a/node/primitives/src/traits.rs +++ b/node/primitives/src/traits.rs @@ -21,8 +21,8 @@ #![allow(clippy::unnecessary_cast)] use crate::{ - AssetIds, ExtraFeeInfo, LeasePeriod, ParaId, PoolId, RedeemType, TokenId, TokenSymbol, - XcmInterfaceOperation, + AssetIds, DerivativeIndex, ExtraFeeInfo, LeasePeriod, ParaId, PoolId, RedeemType, TokenId, + TokenSymbol, XcmInterfaceOperation, }; use codec::{Decode, Encode, FullCodec}; use frame_support::{ @@ -463,3 +463,26 @@ where pub trait FeeGetter { fn get_fee_info(call: &RuntimeCall) -> ExtraFeeInfo; } + +pub trait DerivativeAccountHandler { + fn check_derivative_index_exists(token: CurrencyId, derivative_index: DerivativeIndex) -> bool; + + fn get_multilocation( + token: CurrencyId, + derivative_index: DerivativeIndex, + ) -> Option; + + fn get_stake_info( + token: CurrencyId, + derivative_index: DerivativeIndex, + ) -> Option<(Balance, Balance)>; + + #[cfg(feature = "runtime-benchmarks")] + fn init_minimums_and_maximums(token: CurrencyId); + + #[cfg(feature = "runtime-benchmarks")] + fn new_delegator_ledger(token: CurrencyId, who: xcm::v3::MultiLocation); + + #[cfg(feature = "runtime-benchmarks")] + fn add_delegator(token: CurrencyId, index: DerivativeIndex, who: xcm::v3::MultiLocation); +} diff --git a/pallets/slp/Cargo.toml b/pallets/slp/Cargo.toml index 04a433740..3a259dd69 100644 --- a/pallets/slp/Cargo.toml +++ b/pallets/slp/Cargo.toml @@ -81,5 +81,6 @@ runtime-benchmarks = [ "frame-system/runtime-benchmarks", "pallet-xcm/runtime-benchmarks", "xcm-builder/runtime-benchmarks", + "node-primitives/runtime-benchmarks", ] try-runtime = [ "frame-support/try-runtime" ] diff --git a/pallets/slp/src/lib.rs b/pallets/slp/src/lib.rs index ee207f01a..e70888a7c 100644 --- a/pallets/slp/src/lib.rs +++ b/pallets/slp/src/lib.rs @@ -32,7 +32,7 @@ pub use crate::{ Junctions::X1, }; use cumulus_primitives_core::{relay_chain::HashT, ParaId}; -use frame_support::{pallet_prelude::*, weights::Weight}; +use frame_support::{pallet_prelude::*, traits::Contains, weights::Weight}; use frame_system::{ pallet_prelude::{BlockNumberFor, OriginFor}, RawOrigin, @@ -40,8 +40,8 @@ use frame_system::{ use node_primitives::{ currency::{BNC, KSM, MOVR, PHA}, traits::XcmDestWeightAndFeeHandler, - CurrencyId, CurrencyIdExt, SlpOperator, TimeUnit, VtokenMintingOperator, - XcmInterfaceOperation as XcmOperation, ASTR, DOT, FIL, GLMR, + CurrencyId, CurrencyIdExt, DerivativeAccountHandler, DerivativeIndex, SlpOperator, TimeUnit, + VtokenMintingOperator, XcmInterfaceOperation as XcmOperation, ASTR, DOT, FIL, GLMR, }; use orml_traits::MultiCurrency; use parachain_staking::ParachainStakingInterface; @@ -2383,3 +2383,74 @@ pub mod pallet { } } } + +pub struct DerivativeAccountProvider(PhantomData<(T, F)>); + +impl>> + DerivativeAccountHandler, BalanceOf> for DerivativeAccountProvider +{ + fn check_derivative_index_exists( + token: CurrencyIdOf, + derivative_index: DerivativeIndex, + ) -> bool { + Pallet::::get_delegator_multilocation_by_index(token, derivative_index).is_some() + } + + fn get_multilocation( + token: CurrencyIdOf, + derivative_index: DerivativeIndex, + ) -> Option { + Pallet::::get_delegator_multilocation_by_index(token, derivative_index) + } + + fn get_stake_info( + token: CurrencyIdOf, + derivative_index: DerivativeIndex, + ) -> Option<(BalanceOf, BalanceOf)> { + Self::get_multilocation(token, derivative_index).and_then(|location| { + Pallet::::get_delegator_ledger(token, location).and_then(|ledger| match ledger { + Ledger::Substrate(l) if F::contains(&token) => Some((l.total, l.active)), + _ => None, + }) + }) + } + + #[cfg(feature = "runtime-benchmarks")] + fn init_minimums_and_maximums(currency_id: CurrencyIdOf) { + MinimumsAndMaximums::::insert( + currency_id, + MinimumsMaximums { + delegator_bonded_minimum: 0u32.into(), + bond_extra_minimum: 0u32.into(), + unbond_minimum: 0u32.into(), + rebond_minimum: 0u32.into(), + unbond_record_maximum: 0u32, + validators_back_maximum: 0u32, + delegator_active_staking_maximum: 0u32.into(), + validators_reward_maximum: 0u32, + delegation_amount_minimum: 0u32.into(), + delegators_maximum: u16::MAX, + validators_maximum: 0u16, + }, + ); + } + + #[cfg(feature = "runtime-benchmarks")] + fn new_delegator_ledger(currency_id: CurrencyIdOf, who: MultiLocation) { + DelegatorLedgers::::insert( + currency_id, + &who, + Ledger::Substrate(SubstrateLedger { + account: Parent.into(), + total: u32::MAX.into(), + active: u32::MAX.into(), + unlocking: vec![], + }), + ); + } + + #[cfg(feature = "runtime-benchmarks")] + fn add_delegator(currency_id: CurrencyIdOf, index: DerivativeIndex, who: MultiLocation) { + Pallet::::inner_add_delegator(index, &who, currency_id).unwrap(); + } +} diff --git a/pallets/vtoken-voting/Cargo.toml b/pallets/vtoken-voting/Cargo.toml index 70a142695..b1e7ca04c 100644 --- a/pallets/vtoken-voting/Cargo.toml +++ b/pallets/vtoken-voting/Cargo.toml @@ -8,6 +8,7 @@ edition = "2021" targets = ["x86_64-unknown-linux-gnu"] [dependencies] +assert_matches = "1.3.0" codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = [ "derive", ] } @@ -27,13 +28,12 @@ sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0 sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42", default-features = false } sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42", default-features = false } xcm = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.42", default-features = false } +bifrost-slp = { path = "../slp", default-features = false } [dev-dependencies] -env_logger = "0.10.0" orml-tokens = "0.4.1-dev" bifrost-currencies = { workspace = true } pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42"} -pallet-xcm = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.42" } sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42" } xcm-executor = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.42" } xcm-builder = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.42" } @@ -54,6 +54,7 @@ std = [ "sp-io/std", "sp-runtime/std", "xcm/std", + "bifrost-slp/std", ] kusama = [] polkadot = [] @@ -61,5 +62,7 @@ runtime-benchmarks = [ "frame-benchmarking/runtime-benchmarks", "pallet-conviction-voting/runtime-benchmarks", "pallet-xcm/runtime-benchmarks", + "xcm-builder/runtime-benchmarks", + "bifrost-slp/runtime-benchmarks", ] try-runtime = ["frame-support/try-runtime"] diff --git a/pallets/vtoken-voting/src/benchmarking.rs b/pallets/vtoken-voting/src/benchmarking.rs index 475161618..2aecac291 100644 --- a/pallets/vtoken-voting/src/benchmarking.rs +++ b/pallets/vtoken-voting/src/benchmarking.rs @@ -17,10 +17,20 @@ // along with this program. If not, see . use crate::*; +use assert_matches::assert_matches; use frame_benchmarking::v2::*; use frame_system::RawOrigin; -use node_primitives::currency::VKSM; +use node_primitives::{currency::VKSM, XcmInterfaceOperation as XcmOperation}; use pallet_conviction_voting::{Conviction, Vote}; +use sp_runtime::traits::Bounded; + +const SEED: u32 = 0; + +fn funded_account(name: &'static str, index: u32) -> AccountIdOf { + let caller = account(name, index, SEED); + T::MultiCurrency::deposit(VKSM, &caller, BalanceOf::::max_value()).unwrap(); + caller +} fn account_vote(b: BalanceOf) -> AccountVote> { let v = Vote { aye: true, conviction: Conviction::Locked1x }; @@ -28,30 +38,128 @@ fn account_vote(b: BalanceOf) -> AccountVote> { AccountVote::Standard { vote: v, balance: b } } -#[benchmarks] +fn init_vote(vtoken: CurrencyIdOf) -> Result<(), BenchmarkError> { + let derivative_index = 0; + let token = CurrencyId::to_token(&vtoken).unwrap(); + T::XcmDestWeightAndFee::set_xcm_dest_weight_and_fee( + token, + XcmOperation::VoteVtoken, + Some((Weight::from_parts(4000000000, 100000), 4000000000u32.into())), + )?; + T::DerivativeAccount::init_minimums_and_maximums(token); + T::DerivativeAccount::add_delegator(token, derivative_index, Parent.into()); + T::DerivativeAccount::new_delegator_ledger(token, Parent.into()); + Pallet::::set_undeciding_timeout(RawOrigin::Root.into(), vtoken, Zero::zero())?; + Pallet::::set_delegator_role( + RawOrigin::Root.into(), + vtoken, + derivative_index, + VoteRole::Standard { aye: true, conviction: Conviction::Locked1x }, + )?; + + Ok(()) +} + +#[benchmarks(where T::MaxVotes: core::fmt::Debug)] mod benchmarks { use super::*; #[benchmark] - fn vote() -> Result<(), BenchmarkError> { - let caller = whitelisted_caller(); - let origin = RawOrigin::Signed(caller); + fn vote_new() -> Result<(), BenchmarkError> { + let caller = funded_account::("caller", 0); + whitelist_account!(caller); let vtoken = VKSM; let poll_index = 0u32; - let account_vote = account_vote::(100u32.into()); + let vote = account_vote::(100u32.into()); + let control_origin = + T::ControlOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?; + + init_vote::(vtoken)?; + let r = T::MaxVotes::get() - 1; + let response = Response::DispatchResult(MaybeErrorCode::Success); + for (i, index) in (0..T::MaxVotes::get()).collect::>().iter().skip(1).enumerate() { + Pallet::::on_initialize(Zero::zero()); + Pallet::::vote(RawOrigin::Signed(caller.clone()).into(), vtoken, *index, vote)?; + Pallet::::notify_vote( + control_origin.clone() as ::RuntimeOrigin, + i as QueryId, + response.clone(), + )?; + } + let votes = match VotingFor::::get(&caller) { + Voting::Casting(Casting { votes, .. }) => votes, + _ => return Err("Votes are not direct".into()), + }; + assert_eq!(votes.len(), r as usize, "Votes were not recorded."); + + #[extrinsic_call] + Pallet::::vote(RawOrigin::Signed(caller.clone()), vtoken, poll_index, vote); + + assert_matches!( + VotingFor::::get(&caller), + Voting::Casting(Casting { votes, .. }) if votes.len() == (r + 1) as usize + ); + + Ok(()) + } + + #[benchmark] + fn vote_existing() -> Result<(), BenchmarkError> { + let caller = funded_account::("caller", 0); + whitelist_account!(caller); + let vtoken = VKSM; + let old_vote = account_vote::(100u32.into()); + let control_origin = + T::ControlOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?; + + init_vote::(vtoken)?; + let r = 50; + let response = Response::DispatchResult(MaybeErrorCode::Success); + for index in (0..r).collect::>().iter() { + Pallet::::vote(RawOrigin::Signed(caller.clone()).into(), vtoken, *index, old_vote)?; + Pallet::::notify_vote( + control_origin.clone() as ::RuntimeOrigin, + *index as QueryId, + response.clone(), + )?; + } + let votes = match VotingFor::::get(&caller) { + Voting::Casting(Casting { votes, .. }) => votes, + _ => return Err("Votes are not direct".into()), + }; + assert_eq!(votes.len(), r as usize, "Votes were not recorded."); + let poll_index = 1u32; + let new_vote = account_vote::(200u32.into()); #[extrinsic_call] - vote(origin, vtoken, poll_index, account_vote); + Pallet::::vote(RawOrigin::Signed(caller.clone()), vtoken, poll_index, new_vote); + + assert_matches!( + VotingFor::::get(&caller), + Voting::Casting(Casting { votes, .. }) if votes.len() == r as usize + ); Ok(()) } #[benchmark] pub fn unlock() -> Result<(), BenchmarkError> { - let caller = whitelisted_caller(); + let caller = funded_account::("caller", 0); + whitelist_account!(caller); let origin = RawOrigin::Signed(caller); let vtoken = VKSM; let poll_index = 0u32; + let vote = account_vote::(100u32.into()); + + init_vote::(vtoken)?; + Pallet::::vote(origin.clone().into(), vtoken, poll_index, vote)?; + Pallet::::set_referendum_status( + RawOrigin::Root.into(), + vtoken, + poll_index, + ReferendumInfo::Completed(0u32.into()), + )?; + Pallet::::set_vote_locking_period(RawOrigin::Root.into(), vtoken, 0u32.into())?; #[extrinsic_call] _(origin, vtoken, poll_index); @@ -59,6 +167,181 @@ mod benchmarks { Ok(()) } + #[benchmark] + pub fn remove_delegator_vote() -> Result<(), BenchmarkError> { + let caller = funded_account::("caller", 0); + whitelist_account!(caller); + let origin = RawOrigin::Signed(caller); + let vtoken = VKSM; + let poll_index = 0u32; + let vote = account_vote::(100u32.into()); + let derivative_index = 0u16; + + init_vote::(vtoken)?; + Pallet::::vote(origin.clone().into(), vtoken, poll_index, vote)?; + Pallet::::set_referendum_status( + RawOrigin::Root.into(), + vtoken, + poll_index, + ReferendumInfo::Completed(0u32.into()), + )?; + Pallet::::set_vote_locking_period(RawOrigin::Root.into(), vtoken, 0u32.into())?; + let token = CurrencyId::to_token(&vtoken).unwrap(); + T::XcmDestWeightAndFee::set_xcm_dest_weight_and_fee( + token, + XcmOperation::VoteRemoveDelegatorVote, + Some((Weight::from_parts(4000000000, 100000), 4000000000u32.into())), + )?; + + #[extrinsic_call] + _(origin, vtoken, poll_index, derivative_index); + + Ok(()) + } + + #[benchmark] + pub fn kill_referendum() -> Result<(), BenchmarkError> { + let origin = + T::ControlOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?; + let vtoken = VKSM; + let poll_index = 0u32; + let vote = account_vote::(100u32.into()); + + init_vote::(vtoken)?; + let caller = funded_account::("caller", 0); + whitelist_account!(caller); + let origin_caller = RawOrigin::Signed(caller); + Pallet::::vote(origin_caller.into(), vtoken, poll_index, vote)?; + Pallet::::set_referendum_status( + RawOrigin::Root.into(), + vtoken, + poll_index, + ReferendumInfo::Completed(0u32.into()), + )?; + + #[extrinsic_call] + _(origin as ::RuntimeOrigin, vtoken, poll_index); + + Ok(()) + } + + #[benchmark] + pub fn set_delegator_role() -> Result<(), BenchmarkError> { + let origin = + T::ControlOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?; + let vtoken = VKSM; + let derivative_index = 10; + let vote_role = VoteRole::SplitAbstain; + + init_vote::(vtoken)?; + T::DerivativeAccount::add_delegator( + CurrencyId::to_token(&vtoken).unwrap(), + derivative_index, + Parent.into(), + ); + + #[extrinsic_call] + _( + origin as ::RuntimeOrigin, + vtoken, + derivative_index, + vote_role, + ); + + Ok(()) + } + + #[benchmark] + pub fn set_referendum_status() -> Result<(), BenchmarkError> { + let origin = + T::ControlOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?; + let vtoken = VKSM; + let poll_index = 0u32; + let info = ReferendumInfo::Completed(>::block_number()); + + init_vote::(vtoken)?; + let caller = funded_account::("caller", 0); + whitelist_account!(caller); + let origin_caller = RawOrigin::Signed(caller); + let vote = account_vote::(100u32.into()); + Pallet::::vote(origin_caller.into(), vtoken, poll_index, vote)?; + + #[extrinsic_call] + _(origin as ::RuntimeOrigin, vtoken, poll_index, info); + + Ok(()) + } + + #[benchmark] + pub fn set_undeciding_timeout() -> Result<(), BenchmarkError> { + let origin = + T::ControlOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?; + let vtoken = VKSM; + let vote_locking_period = 100u32.into(); + + #[extrinsic_call] + _(origin as ::RuntimeOrigin, vtoken, vote_locking_period); + + Ok(()) + } + + #[benchmark] + pub fn set_vote_locking_period() -> Result<(), BenchmarkError> { + let origin = + T::ControlOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?; + let vtoken = VKSM; + let undeciding_timeout = 100u32.into(); + + #[extrinsic_call] + _(origin as ::RuntimeOrigin, vtoken, undeciding_timeout); + + Ok(()) + } + + #[benchmark] + pub fn notify_vote() -> Result<(), BenchmarkError> { + let origin = + T::ResponseOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?; + let vtoken = VKSM; + let poll_index = 0u32; + let query_id = 1u64; + let response = Response::DispatchResult(MaybeErrorCode::Success); + + init_vote::(vtoken)?; + let caller = funded_account::("caller", 0); + whitelist_account!(caller); + let origin_caller = RawOrigin::Signed(caller); + let vote = account_vote::(100u32.into()); + Pallet::::vote(origin_caller.into(), vtoken, poll_index, vote)?; + + #[extrinsic_call] + _(origin as ::RuntimeOrigin, query_id, response); + + Ok(()) + } + + #[benchmark] + pub fn notify_remove_delegator_vote() -> Result<(), BenchmarkError> { + let origin = + T::ResponseOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?; + let vtoken = VKSM; + let poll_index = 0u32; + let query_id = 1u64; + let response = Response::DispatchResult(MaybeErrorCode::Success); + + init_vote::(vtoken)?; + let caller = funded_account::("caller", 0); + whitelist_account!(caller); + let origin_caller = RawOrigin::Signed(caller); + let vote = account_vote::(100u32.into()); + Pallet::::vote(origin_caller.into(), vtoken, poll_index, vote)?; + + #[extrinsic_call] + _(origin as ::RuntimeOrigin, query_id, response); + + Ok(()) + } + // This line generates test cases for benchmarking, and could be run by: // `cargo test -p pallet-example-basic --all-features`, you will see one line per case: // `test benchmarking::bench_sort_vector ... ok` diff --git a/pallets/vtoken-voting/src/lib.rs b/pallets/vtoken-voting/src/lib.rs index 5e0446e42..5f352eb59 100644 --- a/pallets/vtoken-voting/src/lib.rs +++ b/pallets/vtoken-voting/src/lib.rs @@ -28,7 +28,6 @@ mod mock; mod tests; mod call; -pub mod traits; mod vote; pub mod weights; @@ -39,14 +38,15 @@ pub use crate::{ }; use cumulus_primitives_core::{ParaId, QueryId, Response}; use frame_support::{ + dispatch::GetDispatchInfo, pallet_prelude::*, traits::{Get, LockIdentifier}, }; use frame_system::pallet_prelude::{BlockNumberFor, *}; use node_primitives::{ currency::{VDOT, VKSM}, - traits::XcmDestWeightAndFeeHandler, - CurrencyId, XcmInterfaceOperation, + traits::{DerivativeAccountHandler, XcmDestWeightAndFeeHandler}, + CurrencyId, DerivativeIndex, XcmInterfaceOperation, }; use orml_traits::{MultiCurrency, MultiLockableCurrency}; pub use pallet::*; @@ -56,14 +56,11 @@ use sp_runtime::{ ArithmeticError, }; use sp_std::prelude::*; -pub use traits::*; use weights::WeightInfo; use xcm::v3::{prelude::*, Weight as XcmWeight}; const CONVICTION_VOTING_ID: LockIdentifier = *b"vtvoting"; -pub type DerivativeIndex = u16; - type PollIndex = u32; pub type AccountIdOf = ::AccountId; @@ -94,7 +91,9 @@ pub mod pallet { type RuntimeOrigin: IsType<::RuntimeOrigin> + Into::RuntimeOrigin>>; - type RuntimeCall: IsType<::RuntimeCall> + From>; + type RuntimeCall: IsType<::RuntimeCall> + + From> + + GetDispatchInfo; type MultiCurrency: MultiLockableCurrency, CurrencyId = CurrencyId>; @@ -105,9 +104,9 @@ pub mod pallet { Success = MultiLocation, >; - type XcmDestWeightAndFee: XcmDestWeightAndFeeHandler>; + type XcmDestWeightAndFee: XcmDestWeightAndFeeHandler, BalanceOf>; - type DerivativeAccount: DerivativeAccountHandler; + type DerivativeAccount: DerivativeAccountHandler, BalanceOf>; type RelaychainBlockNumberProvider: BlockNumberProvider>; @@ -331,9 +330,12 @@ pub mod pallet { #[pallet::hooks] impl Hooks> for Pallet { fn on_initialize(_: BlockNumberFor) -> Weight { + let mut weight = T::DbWeight::get().reads(1); let relay_current_block_number = T::RelaychainBlockNumberProvider::current_block_number(); - ReferendumTimeout::::get(relay_current_block_number).iter().for_each( + + weight += T::DbWeight::get().reads(1); + ReferendumTimeout::::take(relay_current_block_number).iter().for_each( |(vtoken, poll_index)| { ReferendumInfoFor::::mutate( vtoken, @@ -341,21 +343,25 @@ pub mod pallet { |maybe_info| match maybe_info { Some(info) => if let ReferendumInfo::Ongoing(_) = info { - *info = ReferendumInfo::Completed(relay_current_block_number); + *info = ReferendumInfo::Completed( + relay_current_block_number.into(), + ); }, None => {}, }, ); + weight += T::DbWeight::get().reads_writes(1, 1); }, ); - Zero::zero() + + weight } } #[pallet::call] impl Pallet { #[pallet::call_index(0)] - #[pallet::weight(::WeightInfo::vote())] + #[pallet::weight(::WeightInfo::vote_new().max(::WeightInfo::vote_existing()))] pub fn vote( origin: OriginFor, vtoken: CurrencyIdOf, @@ -872,16 +878,18 @@ pub mod pallet { derivative_index: DerivativeIndex, call: RelayCall, notify_call: Call, - weight: XcmWeight, + transact_weight: XcmWeight, extra_fee: BalanceOf, f: impl FnOnce(QueryId) -> (), ) -> DispatchResult { let responder = MultiLocation::parent(); let now = frame_system::Pallet::::block_number(); let timeout = now.saturating_add(T::QueryTimeout::get()); + let notify_runtime_call = ::RuntimeCall::from(notify_call); + let notify_call_weight = notify_runtime_call.get_dispatch_info().weight; let query_id = pallet_xcm::Pallet::::new_notify_query( responder, - ::RuntimeCall::from(notify_call), + notify_runtime_call, timeout, Here, ); @@ -891,7 +899,8 @@ pub mod pallet { as UtilityCall>>::as_derivative(derivative_index, call) .encode(), extra_fee, - weight, + transact_weight, + notify_call_weight, query_id, )?; @@ -904,7 +913,8 @@ pub mod pallet { fn construct_xcm_message( call: Vec, extra_fee: BalanceOf, - weight: XcmWeight, + transact_weight: XcmWeight, + notify_call_weight: XcmWeight, query_id: QueryId, ) -> Result, Error> { let para_id = T::ParachainId::get().into(); @@ -917,13 +927,13 @@ pub mod pallet { BuyExecution { fees: asset, weight_limit: Unlimited }, Transact { origin_kind: OriginKind::SovereignAccount, - require_weight_at_most: weight, + require_weight_at_most: transact_weight, call: call.into(), }, ReportTransactStatus(QueryResponseInfo { destination: MultiLocation::from(X1(Parachain(para_id))), query_id, - max_weight: weight, + max_weight: notify_call_weight, }), RefundSurplus, DepositAsset { diff --git a/pallets/vtoken-voting/src/mock.rs b/pallets/vtoken-voting/src/mock.rs index 25c41b2b3..a83c0f3eb 100644 --- a/pallets/vtoken-voting/src/mock.rs +++ b/pallets/vtoken-voting/src/mock.rs @@ -19,7 +19,7 @@ // Ensure we're `no_std` when compiling for Wasm. use crate as vtoken_voting; -use crate::{traits::DerivativeAccountHandler, BalanceOf, DerivativeIndex, DispatchResult}; +use crate::{BalanceOf, DerivativeAccountHandler, DerivativeIndex, DispatchResult}; use cumulus_primitives_core::ParaId; use frame_support::{ ord_parameter_types, @@ -255,7 +255,7 @@ impl XcmDestWeightAndFeeHandler> for XcmDestWeigh } pub struct DerivativeAccount; -impl DerivativeAccountHandler for DerivativeAccount { +impl DerivativeAccountHandler for DerivativeAccount { fn check_derivative_index_exists( _token: CurrencyId, _derivative_index: DerivativeIndex, @@ -275,7 +275,7 @@ impl DerivativeAccountHandler for DerivativeAccount { derivative_index: DerivativeIndex, ) -> Option<(Balance, Balance)> { Self::get_multilocation(token, derivative_index) - .and_then(|_location| Some((100u32.into(), 100u32.into()))) + .and_then(|_location| Some((u32::MAX.into(), u32::MAX.into()))) } } @@ -309,7 +309,7 @@ impl vtoken_voting::Config for Runtime { type XcmDestWeightAndFee = XcmDestWeightAndFee; type DerivativeAccount = DerivativeAccount; type RelaychainBlockNumberProvider = RelaychainDataProvider; - type MaxVotes = ConstU32<3>; + type MaxVotes = ConstU32<256>; type ParachainId = ParachainId; type QueryTimeout = QueryTimeout; type WeightInfo = (); diff --git a/pallets/vtoken-voting/src/tests.rs b/pallets/vtoken-voting/src/tests.rs index 109e81998..acd4cac82 100644 --- a/pallets/vtoken-voting/src/tests.rs +++ b/pallets/vtoken-voting/src/tests.rs @@ -55,10 +55,6 @@ fn tally(vtoken: CurrencyId, poll_index: u32) -> TallyOf { .tally } -fn class(_vtoken: CurrencyId, poll_index: u32) -> PollIndex { - poll_index -} - fn usable_balance(vtoken: CurrencyId, who: &AccountId) -> Balance { Tokens::reducible_balance(vtoken, who, Expendable, Polite) } @@ -130,7 +126,7 @@ fn basic_voting_works() { assert_ok!(VtokenVoting::try_remove_vote(&ALICE, vtoken, poll_index, UnvoteScope::Any)); assert_eq!(tally(vtoken, poll_index), Tally::from_parts(0, 0, 0)); - assert_ok!(VtokenVoting::update_lock(&ALICE, vtoken, &class(vtoken, poll_index))); + assert_ok!(VtokenVoting::update_lock(&ALICE, vtoken, &poll_index)); assert_eq!(usable_balance(vtoken, &ALICE), 10); }); } @@ -168,7 +164,7 @@ fn split_voting_works() { assert_ok!(VtokenVoting::try_remove_vote(&ALICE, vtoken, poll_index, UnvoteScope::Any)); assert_eq!(tally(vtoken, poll_index), Tally::from_parts(0, 0, 0)); - assert_ok!(VtokenVoting::update_lock(&ALICE, vtoken, &class(vtoken, poll_index))); + assert_ok!(VtokenVoting::update_lock(&ALICE, vtoken, &poll_index)); assert_eq!(usable_balance(vtoken, &ALICE), 10); }); } @@ -224,10 +220,10 @@ fn abstain_voting_works() { assert_ok!(VtokenVoting::try_remove_vote(&BOB, vtoken, poll_index, UnvoteScope::Any)); assert_eq!(tally(vtoken, poll_index), Tally::from_parts(0, 0, 0)); - assert_ok!(VtokenVoting::update_lock(&ALICE, vtoken, &class(vtoken, poll_index))); + assert_ok!(VtokenVoting::update_lock(&ALICE, vtoken, &poll_index)); assert_eq!(usable_balance(vtoken, &ALICE), 10); - assert_ok!(VtokenVoting::update_lock(&BOB, vtoken, &class(vtoken, poll_index))); + assert_ok!(VtokenVoting::update_lock(&BOB, vtoken, &poll_index)); assert_eq!(usable_balance(vtoken, &BOB), 20); }); } @@ -275,7 +271,7 @@ fn voting_balance_gets_locked() { assert_ok!(VtokenVoting::try_remove_vote(&ALICE, vtoken, poll_index, UnvoteScope::Any)); assert_eq!(tally(vtoken, poll_index), Tally::from_parts(0, 0, 0)); - assert_ok!(VtokenVoting::update_lock(&ALICE, vtoken, &class(vtoken, poll_index))); + assert_ok!(VtokenVoting::update_lock(&ALICE, vtoken, &poll_index)); assert_eq!(usable_balance(vtoken, &ALICE), 10); }); } @@ -291,7 +287,6 @@ fn successful_but_zero_conviction_vote_balance_can_be_unlocked() { assert_ok!(VtokenVoting::vote(RuntimeOrigin::signed(BOB), vtoken, poll_index, nay(20, 0))); assert_ok!(VtokenVoting::notify_vote(origin_response(), 1, response_success())); - let c = class(vtoken, poll_index); assert_ok!(VtokenVoting::set_referendum_status( RuntimeOrigin::signed(CONTROLLER), vtoken, @@ -299,7 +294,7 @@ fn successful_but_zero_conviction_vote_balance_can_be_unlocked() { ReferendumInfoOf::::Completed(3), )); assert_ok!(VtokenVoting::try_remove_vote(&BOB, vtoken, poll_index, UnvoteScope::Any)); - assert_ok!(VtokenVoting::update_lock(&BOB, vtoken, &c)); + assert_ok!(VtokenVoting::update_lock(&BOB, vtoken, &poll_index)); assert_eq!(usable_balance(vtoken, &BOB), 20); }); } @@ -315,7 +310,6 @@ fn unsuccessful_conviction_vote_balance_can_be_unlocked() { assert_ok!(VtokenVoting::vote(RuntimeOrigin::signed(BOB), vtoken, poll_index, nay(20, 0))); assert_ok!(VtokenVoting::notify_vote(origin_response(), 1, response_success())); - let c = class(vtoken, poll_index); assert_ok!(VtokenVoting::set_referendum_status( RuntimeOrigin::signed(CONTROLLER), vtoken, @@ -323,7 +317,7 @@ fn unsuccessful_conviction_vote_balance_can_be_unlocked() { ReferendumInfoOf::::Completed(3), )); assert_ok!(VtokenVoting::try_remove_vote(&ALICE, vtoken, poll_index, UnvoteScope::Any)); - assert_ok!(VtokenVoting::update_lock(&ALICE, vtoken, &c)); + assert_ok!(VtokenVoting::update_lock(&ALICE, vtoken, &poll_index)); assert_eq!(usable_balance(vtoken, &ALICE), 10); }); } @@ -343,7 +337,6 @@ fn successful_conviction_vote_balance_stays_locked_for_correct_time() { )); assert_ok!(VtokenVoting::notify_vote(origin_response(), i - 1, response_success())); } - let c = class(vtoken, poll_index); assert_ok!(VtokenVoting::set_referendum_status( RuntimeOrigin::signed(CONTROLLER), vtoken, @@ -354,7 +347,7 @@ fn successful_conviction_vote_balance_stays_locked_for_correct_time() { assert_ok!(VtokenVoting::try_remove_vote(&i, vtoken, poll_index, UnvoteScope::Any)); } for i in 1..=5 { - assert_ok!(VtokenVoting::update_lock(&i, vtoken, &c)); + assert_ok!(VtokenVoting::update_lock(&i, vtoken, &poll_index)); assert_eq!(usable_balance(vtoken, &i), 10 * i as u128); } }); @@ -429,11 +422,16 @@ fn errors_with_vote_works() { Error::::InsufficientFunds ); - assert_ok!(VtokenVoting::vote(RuntimeOrigin::signed(1), vtoken, 0, aye(10, 0))); - assert_ok!(VtokenVoting::vote(RuntimeOrigin::signed(1), vtoken, 1, aye(10, 0))); - assert_ok!(VtokenVoting::vote(RuntimeOrigin::signed(1), vtoken, 2, aye(10, 0))); + for poll_index in 0..256 { + assert_ok!(VtokenVoting::vote( + RuntimeOrigin::signed(1), + vtoken, + poll_index, + aye(10, 0) + )); + } assert_noop!( - VtokenVoting::vote(RuntimeOrigin::signed(1), vtoken, 3, aye(10, 0)), + VtokenVoting::vote(RuntimeOrigin::signed(1), vtoken, 256, aye(10, 0)), Error::::MaxVotesReached ); }); @@ -678,6 +676,61 @@ fn notify_vote_success_works() { }); } +#[test] +fn notify_vote_success_max_works() { + new_test_ext().execute_with(|| { + let vtoken = VKSM; + + for poll_index in 0..256 { + RelaychainDataProvider::set_block_number(1); + + assert_ok!(VtokenVoting::vote( + RuntimeOrigin::signed(ALICE), + vtoken, + poll_index, + aye(2, 5) + )); + assert_ok!(VtokenVoting::notify_vote( + origin_response(), + poll_index as QueryId, + response_success() + )); + + RelaychainDataProvider::set_block_number( + 1 + UndecidingTimeout::::get(vtoken).unwrap(), + ); + VtokenVoting::on_initialize(Zero::zero()); + } + }); +} + +#[test] +fn notify_vote_success_exceed_max_fail() { + new_test_ext().execute_with(|| { + let vtoken = VKSM; + + for poll_index in 0..50 { + assert_ok!(VtokenVoting::vote( + RuntimeOrigin::signed(ALICE), + vtoken, + poll_index, + aye(2, 5) + )); + assert_ok!(VtokenVoting::notify_vote( + origin_response(), + poll_index as QueryId, + response_success() + ),); + } + let poll_index = 50; + assert_ok!(VtokenVoting::vote(RuntimeOrigin::signed(ALICE), vtoken, poll_index, aye(2, 5))); + assert_noop!( + VtokenVoting::notify_vote(origin_response(), poll_index as QueryId, response_success()), + Error::::TooMany + ); + }); +} + #[test] fn notify_vote_fail_works() { new_test_ext().execute_with(|| { diff --git a/pallets/vtoken-voting/src/traits.rs b/pallets/vtoken-voting/src/traits.rs deleted file mode 100644 index d1cab95fd..000000000 --- a/pallets/vtoken-voting/src/traits.rs +++ /dev/null @@ -1,19 +0,0 @@ -use crate::{BalanceOf, Config, CurrencyIdOf, DerivativeIndex}; -use xcm::v3::MultiLocation; - -pub trait DerivativeAccountHandler { - fn check_derivative_index_exists( - token: CurrencyIdOf, - derivative_index: DerivativeIndex, - ) -> bool; - - fn get_multilocation( - token: CurrencyIdOf, - derivative_index: DerivativeIndex, - ) -> Option; - - fn get_stake_info( - token: CurrencyIdOf, - derivative_index: DerivativeIndex, - ) -> Option<(BalanceOf, BalanceOf)>; -} diff --git a/pallets/vtoken-voting/src/weights.rs b/pallets/vtoken-voting/src/weights.rs index 3773adc49..84719d0c2 100644 --- a/pallets/vtoken-voting/src/weights.rs +++ b/pallets/vtoken-voting/src/weights.rs @@ -25,7 +25,7 @@ //! Autogenerated weights for bifrost_vtoken_voting //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-08-02, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-09-07, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` //! HOSTNAME: `EdwindeMBP`, CPU: `` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("bifrost-kusama-local"), DB CACHE: 1024 @@ -55,199 +55,446 @@ use core::marker::PhantomData; /// Weight functions needed for bifrost_vtoken_voting. pub trait WeightInfo { - fn vote() -> Weight; + fn vote_new() -> Weight; + fn vote_existing() -> Weight; fn unlock() -> Weight; - fn update_referendum_status() -> Weight; fn remove_delegator_vote() -> Weight; + fn kill_referendum() -> Weight; fn set_delegator_role() -> Weight; fn set_referendum_status() -> Weight; - fn set_vote_locking_period() -> Weight; fn set_undeciding_timeout() -> Weight; - fn kill_referendum() -> Weight; + fn set_vote_locking_period() -> Weight; fn notify_vote() -> Weight; - fn notify_update_referendum_status() -> Weight; fn notify_remove_delegator_vote() -> Weight; } /// Weights for bifrost_vtoken_voting using the Bifrost node and recommended hardware. pub struct BifrostWeight(PhantomData); impl WeightInfo for BifrostWeight { - fn vote() -> Weight { + /// Storage: VtokenVoting UndecidingTimeout (r:1 w:0) + /// Proof: VtokenVoting UndecidingTimeout (max_values: None, max_size: Some(26), added: 2501, mode: MaxEncodedLen) + /// Storage: VtokenVoting DelegatorVote (r:2 w:1) + /// Proof: VtokenVoting DelegatorVote (max_values: None, max_size: Some(81), added: 2556, mode: MaxEncodedLen) + /// Storage: Slp DelegatorsIndex2Multilocation (r:1 w:0) + /// Proof Skipped: Slp DelegatorsIndex2Multilocation (max_values: None, max_size: None, mode: Measured) + /// Storage: Slp DelegatorLedgers (r:1 w:0) + /// Proof Skipped: Slp DelegatorLedgers (max_values: None, max_size: None, mode: Measured) + /// Storage: VtokenVoting PendingVotingInfo (r:1 w:1) + /// Proof: VtokenVoting PendingVotingInfo (max_values: None, max_size: Some(117), added: 2592, mode: MaxEncodedLen) + /// Storage: VtokenVoting ReferendumInfoFor (r:1 w:1) + /// Proof: VtokenVoting ReferendumInfoFor (max_values: None, max_size: Some(88), added: 2563, mode: MaxEncodedLen) + /// Storage: Tokens Accounts (r:1 w:1) + /// Proof: Tokens Accounts (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) + /// Storage: VtokenVoting VotingFor (r:1 w:1) + /// Proof: VtokenVoting VotingFor (max_values: None, max_size: Some(13663), added: 16138, mode: MaxEncodedLen) + /// Storage: VtokenVoting ClassLocksFor (r:1 w:1) + /// Proof: VtokenVoting ClassLocksFor (max_values: None, max_size: Some(5162), added: 7637, mode: MaxEncodedLen) + /// Storage: Tokens Locks (r:1 w:1) + /// Proof: Tokens Locks (max_values: None, max_size: Some(1271), added: 3746, mode: MaxEncodedLen) + /// Storage: AssetRegistry CurrencyMetadatas (r:1 w:0) + /// Proof Skipped: AssetRegistry CurrencyMetadatas (max_values: None, max_size: None, mode: Measured) + /// Storage: XcmInterface XcmWeightAndFee (r:1 w:0) + /// Proof Skipped: XcmInterface XcmWeightAndFee (max_values: None, max_size: None, mode: Measured) + /// Storage: PolkadotXcm QueryCounter (r:1 w:1) + /// Proof Skipped: PolkadotXcm QueryCounter (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: ParachainInfo ParachainId (r:1 w:0) + /// Proof: ParachainInfo ParachainId (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Storage: VtokenVoting PendingReferendumInfo (r:0 w:1) + /// Proof: VtokenVoting PendingReferendumInfo (max_values: None, max_size: Some(34), added: 2509, mode: MaxEncodedLen) + /// Storage: PolkadotXcm Queries (r:0 w:1) + /// Proof Skipped: PolkadotXcm Queries (max_values: None, max_size: None, mode: Measured) + fn vote_new() -> Weight { // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 7_000_000 picoseconds. - Weight::from_parts(7_000_000, 0) + // Measured: `14411` + // Estimated: `17876` + // Minimum execution time: 128_000_000 picoseconds. + Weight::from_parts(133_000_000, 17876) + .saturating_add(T::DbWeight::get().reads(15_u64)) + .saturating_add(T::DbWeight::get().writes(10_u64)) } - fn unlock() -> Weight { + /// Storage: VtokenVoting UndecidingTimeout (r:1 w:0) + /// Proof: VtokenVoting UndecidingTimeout (max_values: None, max_size: Some(26), added: 2501, mode: MaxEncodedLen) + /// Storage: VtokenVoting DelegatorVote (r:2 w:1) + /// Proof: VtokenVoting DelegatorVote (max_values: None, max_size: Some(81), added: 2556, mode: MaxEncodedLen) + /// Storage: Slp DelegatorsIndex2Multilocation (r:1 w:0) + /// Proof Skipped: Slp DelegatorsIndex2Multilocation (max_values: None, max_size: None, mode: Measured) + /// Storage: Slp DelegatorLedgers (r:1 w:0) + /// Proof Skipped: Slp DelegatorLedgers (max_values: None, max_size: None, mode: Measured) + /// Storage: VtokenVoting PendingVotingInfo (r:1 w:1) + /// Proof: VtokenVoting PendingVotingInfo (max_values: None, max_size: Some(117), added: 2592, mode: MaxEncodedLen) + /// Storage: VtokenVoting ReferendumInfoFor (r:1 w:1) + /// Proof: VtokenVoting ReferendumInfoFor (max_values: None, max_size: Some(88), added: 2563, mode: MaxEncodedLen) + /// Storage: Tokens Accounts (r:1 w:1) + /// Proof: Tokens Accounts (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) + /// Storage: VtokenVoting VotingFor (r:1 w:1) + /// Proof: VtokenVoting VotingFor (max_values: None, max_size: Some(13663), added: 16138, mode: MaxEncodedLen) + /// Storage: VtokenVoting ClassLocksFor (r:1 w:1) + /// Proof: VtokenVoting ClassLocksFor (max_values: None, max_size: Some(5162), added: 7637, mode: MaxEncodedLen) + /// Storage: Tokens Locks (r:1 w:1) + /// Proof: Tokens Locks (max_values: None, max_size: Some(1271), added: 3746, mode: MaxEncodedLen) + /// Storage: AssetRegistry CurrencyMetadatas (r:1 w:0) + /// Proof Skipped: AssetRegistry CurrencyMetadatas (max_values: None, max_size: None, mode: Measured) + /// Storage: XcmInterface XcmWeightAndFee (r:1 w:0) + /// Proof Skipped: XcmInterface XcmWeightAndFee (max_values: None, max_size: None, mode: Measured) + /// Storage: PolkadotXcm QueryCounter (r:1 w:1) + /// Proof Skipped: PolkadotXcm QueryCounter (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: ParachainInfo ParachainId (r:1 w:0) + /// Proof: ParachainInfo ParachainId (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Storage: PolkadotXcm Queries (r:0 w:1) + /// Proof Skipped: PolkadotXcm Queries (max_values: None, max_size: None, mode: Measured) + fn vote_existing() -> Weight { // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 7_000_000 picoseconds. - Weight::from_parts(7_000_000, 0) + // Measured: `14786` + // Estimated: `18251` + // Minimum execution time: 133_000_000 picoseconds. + Weight::from_parts(135_000_000, 18251) + .saturating_add(T::DbWeight::get().reads(15_u64)) + .saturating_add(T::DbWeight::get().writes(9_u64)) } - fn update_referendum_status() -> Weight { + /// Storage: VtokenVoting ReferendumInfoFor (r:1 w:0) + /// Proof: VtokenVoting ReferendumInfoFor (max_values: None, max_size: Some(88), added: 2563, mode: MaxEncodedLen) + /// Storage: VtokenVoting VoteLockingPeriod (r:1 w:0) + /// Proof: VtokenVoting VoteLockingPeriod (max_values: None, max_size: Some(26), added: 2501, mode: MaxEncodedLen) + /// Storage: ParachainSystem ValidationData (r:1 w:0) + /// Proof Skipped: ParachainSystem ValidationData (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: VtokenVoting VotingFor (r:1 w:1) + /// Proof: VtokenVoting VotingFor (max_values: None, max_size: Some(13663), added: 16138, mode: MaxEncodedLen) + /// Storage: VtokenVoting ClassLocksFor (r:1 w:1) + /// Proof: VtokenVoting ClassLocksFor (max_values: None, max_size: Some(5162), added: 7637, mode: MaxEncodedLen) + /// Storage: Tokens Locks (r:1 w:1) + /// Proof: Tokens Locks (max_values: None, max_size: Some(1271), added: 3746, mode: MaxEncodedLen) + /// Storage: Tokens Accounts (r:1 w:1) + /// Proof: Tokens Accounts (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) + /// Storage: AssetRegistry CurrencyMetadatas (r:1 w:0) + /// Proof Skipped: AssetRegistry CurrencyMetadatas (max_values: None, max_size: None, mode: Measured) + fn unlock() -> Weight { // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 7_000_000 picoseconds. - Weight::from_parts(8_000_000, 0) + // Measured: `2032` + // Estimated: `17128` + // Minimum execution time: 65_000_000 picoseconds. + Weight::from_parts(67_000_000, 17128) + .saturating_add(T::DbWeight::get().reads(8_u64)) + .saturating_add(T::DbWeight::get().writes(4_u64)) } + /// Storage: VtokenVoting ReferendumInfoFor (r:1 w:0) + /// Proof: VtokenVoting ReferendumInfoFor (max_values: None, max_size: Some(88), added: 2563, mode: MaxEncodedLen) + /// Storage: VtokenVoting VoteLockingPeriod (r:1 w:0) + /// Proof: VtokenVoting VoteLockingPeriod (max_values: None, max_size: Some(26), added: 2501, mode: MaxEncodedLen) + /// Storage: ParachainSystem ValidationData (r:1 w:0) + /// Proof Skipped: ParachainSystem ValidationData (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: VtokenVoting DelegatorVote (r:1 w:0) + /// Proof: VtokenVoting DelegatorVote (max_values: None, max_size: Some(81), added: 2556, mode: MaxEncodedLen) + /// Storage: XcmInterface XcmWeightAndFee (r:1 w:0) + /// Proof Skipped: XcmInterface XcmWeightAndFee (max_values: None, max_size: None, mode: Measured) + /// Storage: PolkadotXcm QueryCounter (r:1 w:1) + /// Proof Skipped: PolkadotXcm QueryCounter (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: ParachainInfo ParachainId (r:1 w:0) + /// Proof: ParachainInfo ParachainId (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Storage: VtokenVoting PendingRemoveDelegatorVote (r:0 w:1) + /// Proof: VtokenVoting PendingRemoveDelegatorVote (max_values: None, max_size: Some(36), added: 2511, mode: MaxEncodedLen) + /// Storage: PolkadotXcm Queries (r:0 w:1) + /// Proof Skipped: PolkadotXcm Queries (max_values: None, max_size: None, mode: Measured) fn remove_delegator_vote() -> Weight { // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 7_000_000 picoseconds. - Weight::from_parts(7_000_000, 0) + // Measured: `965` + // Estimated: `4430` + // Minimum execution time: 40_000_000 picoseconds. + Weight::from_parts(41_000_000, 4430) + .saturating_add(T::DbWeight::get().reads(7_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) } - fn set_delegator_role() -> Weight { + /// Storage: VtokenVoting ReferendumInfoFor (r:1 w:1) + /// Proof: VtokenVoting ReferendumInfoFor (max_values: None, max_size: Some(88), added: 2563, mode: MaxEncodedLen) + /// Storage: ParachainSystem ValidationData (r:1 w:0) + /// Proof Skipped: ParachainSystem ValidationData (max_values: Some(1), max_size: None, mode: Measured) + fn kill_referendum() -> Weight { // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 6_000_000 picoseconds. - Weight::from_parts(7_000_000, 0) + // Measured: `370` + // Estimated: `3553` + // Minimum execution time: 16_000_000 picoseconds. + Weight::from_parts(17_000_000, 3553) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) } - fn set_referendum_status() -> Weight { + /// Storage: Slp DelegatorsIndex2Multilocation (r:1 w:0) + /// Proof Skipped: Slp DelegatorsIndex2Multilocation (max_values: None, max_size: None, mode: Measured) + /// Storage: VtokenVoting DelegatorVote (r:1 w:1) + /// Proof: VtokenVoting DelegatorVote (max_values: None, max_size: Some(81), added: 2556, mode: MaxEncodedLen) + fn set_delegator_role() -> Weight { // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 7_000_000 picoseconds. - Weight::from_parts(7_000_000, 0) + // Measured: `372` + // Estimated: `3837` + // Minimum execution time: 18_000_000 picoseconds. + Weight::from_parts(19_000_000, 3837) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) } - fn set_vote_locking_period() -> Weight { + /// Storage: VtokenVoting ReferendumInfoFor (r:1 w:1) + /// Proof: VtokenVoting ReferendumInfoFor (max_values: None, max_size: Some(88), added: 2563, mode: MaxEncodedLen) + fn set_referendum_status() -> Weight { // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 6_000_000 picoseconds. - Weight::from_parts(7_000_000, 0) + // Measured: `321` + // Estimated: `3553` + // Minimum execution time: 13_000_000 picoseconds. + Weight::from_parts(14_000_000, 3553) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) } + /// Storage: VtokenVoting UndecidingTimeout (r:0 w:1) + /// Proof: VtokenVoting UndecidingTimeout (max_values: None, max_size: Some(26), added: 2501, mode: MaxEncodedLen) fn set_undeciding_timeout() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 6_000_000 picoseconds. - Weight::from_parts(7_000_000, 0) + // Minimum execution time: 7_000_000 picoseconds. + Weight::from_parts(8_000_000, 0) + .saturating_add(T::DbWeight::get().writes(1_u64)) } - /// Storage: VtokenVoting ReferendumInfos (r:0 w:1) - /// Proof: VtokenVoting ReferendumInfos (max_values: None, max_size: Some(56), added: 2531, mode: MaxEncodedLen) - fn kill_referendum() -> Weight { + /// Storage: VtokenVoting VoteLockingPeriod (r:0 w:1) + /// Proof: VtokenVoting VoteLockingPeriod (max_values: None, max_size: Some(26), added: 2501, mode: MaxEncodedLen) + fn set_vote_locking_period() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 8_000_000 picoseconds. - Weight::from_parts(9_000_000, 0) + // Minimum execution time: 7_000_000 picoseconds. + Weight::from_parts(8_000_000, 0) .saturating_add(T::DbWeight::get().writes(1_u64)) } + /// Storage: VtokenVoting PendingVotingInfo (r:1 w:0) + /// Proof: VtokenVoting PendingVotingInfo (max_values: None, max_size: Some(117), added: 2592, mode: MaxEncodedLen) + /// Storage: VtokenVoting PendingReferendumInfo (r:1 w:0) + /// Proof: VtokenVoting PendingReferendumInfo (max_values: None, max_size: Some(34), added: 2509, mode: MaxEncodedLen) fn notify_vote() -> Weight { // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 2_000_000 picoseconds. - Weight::from_parts(3_000_000, 0) - } - fn notify_update_referendum_status() -> Weight { - // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 2_000_000 picoseconds. - Weight::from_parts(3_000_000, 0) + // Measured: `361` + // Estimated: `3582` + // Minimum execution time: 15_000_000 picoseconds. + Weight::from_parts(16_000_000, 3582) + .saturating_add(T::DbWeight::get().reads(2_u64)) } + /// Storage: VtokenVoting PendingRemoveDelegatorVote (r:1 w:0) + /// Proof: VtokenVoting PendingRemoveDelegatorVote (max_values: None, max_size: Some(36), added: 2511, mode: MaxEncodedLen) fn notify_remove_delegator_vote() -> Weight { // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 2_000_000 picoseconds. - Weight::from_parts(3_000_000, 0) + // Measured: `329` + // Estimated: `3501` + // Minimum execution time: 12_000_000 picoseconds. + Weight::from_parts(13_000_000, 3501) + .saturating_add(T::DbWeight::get().reads(1_u64)) } } // For backwards compatibility and tests impl WeightInfo for () { - fn vote() -> Weight { + /// Storage: VtokenVoting UndecidingTimeout (r:1 w:0) + /// Proof: VtokenVoting UndecidingTimeout (max_values: None, max_size: Some(26), added: 2501, mode: MaxEncodedLen) + /// Storage: VtokenVoting DelegatorVote (r:2 w:1) + /// Proof: VtokenVoting DelegatorVote (max_values: None, max_size: Some(81), added: 2556, mode: MaxEncodedLen) + /// Storage: Slp DelegatorsIndex2Multilocation (r:1 w:0) + /// Proof Skipped: Slp DelegatorsIndex2Multilocation (max_values: None, max_size: None, mode: Measured) + /// Storage: Slp DelegatorLedgers (r:1 w:0) + /// Proof Skipped: Slp DelegatorLedgers (max_values: None, max_size: None, mode: Measured) + /// Storage: VtokenVoting PendingVotingInfo (r:1 w:1) + /// Proof: VtokenVoting PendingVotingInfo (max_values: None, max_size: Some(117), added: 2592, mode: MaxEncodedLen) + /// Storage: VtokenVoting ReferendumInfoFor (r:1 w:1) + /// Proof: VtokenVoting ReferendumInfoFor (max_values: None, max_size: Some(88), added: 2563, mode: MaxEncodedLen) + /// Storage: Tokens Accounts (r:1 w:1) + /// Proof: Tokens Accounts (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) + /// Storage: VtokenVoting VotingFor (r:1 w:1) + /// Proof: VtokenVoting VotingFor (max_values: None, max_size: Some(13663), added: 16138, mode: MaxEncodedLen) + /// Storage: VtokenVoting ClassLocksFor (r:1 w:1) + /// Proof: VtokenVoting ClassLocksFor (max_values: None, max_size: Some(5162), added: 7637, mode: MaxEncodedLen) + /// Storage: Tokens Locks (r:1 w:1) + /// Proof: Tokens Locks (max_values: None, max_size: Some(1271), added: 3746, mode: MaxEncodedLen) + /// Storage: AssetRegistry CurrencyMetadatas (r:1 w:0) + /// Proof Skipped: AssetRegistry CurrencyMetadatas (max_values: None, max_size: None, mode: Measured) + /// Storage: XcmInterface XcmWeightAndFee (r:1 w:0) + /// Proof Skipped: XcmInterface XcmWeightAndFee (max_values: None, max_size: None, mode: Measured) + /// Storage: PolkadotXcm QueryCounter (r:1 w:1) + /// Proof Skipped: PolkadotXcm QueryCounter (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: ParachainInfo ParachainId (r:1 w:0) + /// Proof: ParachainInfo ParachainId (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Storage: VtokenVoting PendingReferendumInfo (r:0 w:1) + /// Proof: VtokenVoting PendingReferendumInfo (max_values: None, max_size: Some(34), added: 2509, mode: MaxEncodedLen) + /// Storage: PolkadotXcm Queries (r:0 w:1) + /// Proof Skipped: PolkadotXcm Queries (max_values: None, max_size: None, mode: Measured) + fn vote_new() -> Weight { // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 7_000_000 picoseconds. - Weight::from_parts(7_000_000, 0) + // Measured: `14411` + // Estimated: `17876` + // Minimum execution time: 128_000_000 picoseconds. + Weight::from_parts(133_000_000, 17876) + .saturating_add(RocksDbWeight::get().reads(15_u64)) + .saturating_add(RocksDbWeight::get().writes(10_u64)) } - fn unlock() -> Weight { + /// Storage: VtokenVoting UndecidingTimeout (r:1 w:0) + /// Proof: VtokenVoting UndecidingTimeout (max_values: None, max_size: Some(26), added: 2501, mode: MaxEncodedLen) + /// Storage: VtokenVoting DelegatorVote (r:2 w:1) + /// Proof: VtokenVoting DelegatorVote (max_values: None, max_size: Some(81), added: 2556, mode: MaxEncodedLen) + /// Storage: Slp DelegatorsIndex2Multilocation (r:1 w:0) + /// Proof Skipped: Slp DelegatorsIndex2Multilocation (max_values: None, max_size: None, mode: Measured) + /// Storage: Slp DelegatorLedgers (r:1 w:0) + /// Proof Skipped: Slp DelegatorLedgers (max_values: None, max_size: None, mode: Measured) + /// Storage: VtokenVoting PendingVotingInfo (r:1 w:1) + /// Proof: VtokenVoting PendingVotingInfo (max_values: None, max_size: Some(117), added: 2592, mode: MaxEncodedLen) + /// Storage: VtokenVoting ReferendumInfoFor (r:1 w:1) + /// Proof: VtokenVoting ReferendumInfoFor (max_values: None, max_size: Some(88), added: 2563, mode: MaxEncodedLen) + /// Storage: Tokens Accounts (r:1 w:1) + /// Proof: Tokens Accounts (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) + /// Storage: VtokenVoting VotingFor (r:1 w:1) + /// Proof: VtokenVoting VotingFor (max_values: None, max_size: Some(13663), added: 16138, mode: MaxEncodedLen) + /// Storage: VtokenVoting ClassLocksFor (r:1 w:1) + /// Proof: VtokenVoting ClassLocksFor (max_values: None, max_size: Some(5162), added: 7637, mode: MaxEncodedLen) + /// Storage: Tokens Locks (r:1 w:1) + /// Proof: Tokens Locks (max_values: None, max_size: Some(1271), added: 3746, mode: MaxEncodedLen) + /// Storage: AssetRegistry CurrencyMetadatas (r:1 w:0) + /// Proof Skipped: AssetRegistry CurrencyMetadatas (max_values: None, max_size: None, mode: Measured) + /// Storage: XcmInterface XcmWeightAndFee (r:1 w:0) + /// Proof Skipped: XcmInterface XcmWeightAndFee (max_values: None, max_size: None, mode: Measured) + /// Storage: PolkadotXcm QueryCounter (r:1 w:1) + /// Proof Skipped: PolkadotXcm QueryCounter (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: ParachainInfo ParachainId (r:1 w:0) + /// Proof: ParachainInfo ParachainId (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Storage: PolkadotXcm Queries (r:0 w:1) + /// Proof Skipped: PolkadotXcm Queries (max_values: None, max_size: None, mode: Measured) + fn vote_existing() -> Weight { // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 7_000_000 picoseconds. - Weight::from_parts(7_000_000, 0) + // Measured: `14786` + // Estimated: `18251` + // Minimum execution time: 133_000_000 picoseconds. + Weight::from_parts(135_000_000, 18251) + .saturating_add(RocksDbWeight::get().reads(15_u64)) + .saturating_add(RocksDbWeight::get().writes(9_u64)) } - fn update_referendum_status() -> Weight { + /// Storage: VtokenVoting ReferendumInfoFor (r:1 w:0) + /// Proof: VtokenVoting ReferendumInfoFor (max_values: None, max_size: Some(88), added: 2563, mode: MaxEncodedLen) + /// Storage: VtokenVoting VoteLockingPeriod (r:1 w:0) + /// Proof: VtokenVoting VoteLockingPeriod (max_values: None, max_size: Some(26), added: 2501, mode: MaxEncodedLen) + /// Storage: ParachainSystem ValidationData (r:1 w:0) + /// Proof Skipped: ParachainSystem ValidationData (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: VtokenVoting VotingFor (r:1 w:1) + /// Proof: VtokenVoting VotingFor (max_values: None, max_size: Some(13663), added: 16138, mode: MaxEncodedLen) + /// Storage: VtokenVoting ClassLocksFor (r:1 w:1) + /// Proof: VtokenVoting ClassLocksFor (max_values: None, max_size: Some(5162), added: 7637, mode: MaxEncodedLen) + /// Storage: Tokens Locks (r:1 w:1) + /// Proof: Tokens Locks (max_values: None, max_size: Some(1271), added: 3746, mode: MaxEncodedLen) + /// Storage: Tokens Accounts (r:1 w:1) + /// Proof: Tokens Accounts (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) + /// Storage: AssetRegistry CurrencyMetadatas (r:1 w:0) + /// Proof Skipped: AssetRegistry CurrencyMetadatas (max_values: None, max_size: None, mode: Measured) + fn unlock() -> Weight { // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 7_000_000 picoseconds. - Weight::from_parts(8_000_000, 0) + // Measured: `2032` + // Estimated: `17128` + // Minimum execution time: 65_000_000 picoseconds. + Weight::from_parts(67_000_000, 17128) + .saturating_add(RocksDbWeight::get().reads(8_u64)) + .saturating_add(RocksDbWeight::get().writes(4_u64)) } + /// Storage: VtokenVoting ReferendumInfoFor (r:1 w:0) + /// Proof: VtokenVoting ReferendumInfoFor (max_values: None, max_size: Some(88), added: 2563, mode: MaxEncodedLen) + /// Storage: VtokenVoting VoteLockingPeriod (r:1 w:0) + /// Proof: VtokenVoting VoteLockingPeriod (max_values: None, max_size: Some(26), added: 2501, mode: MaxEncodedLen) + /// Storage: ParachainSystem ValidationData (r:1 w:0) + /// Proof Skipped: ParachainSystem ValidationData (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: VtokenVoting DelegatorVote (r:1 w:0) + /// Proof: VtokenVoting DelegatorVote (max_values: None, max_size: Some(81), added: 2556, mode: MaxEncodedLen) + /// Storage: XcmInterface XcmWeightAndFee (r:1 w:0) + /// Proof Skipped: XcmInterface XcmWeightAndFee (max_values: None, max_size: None, mode: Measured) + /// Storage: PolkadotXcm QueryCounter (r:1 w:1) + /// Proof Skipped: PolkadotXcm QueryCounter (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: ParachainInfo ParachainId (r:1 w:0) + /// Proof: ParachainInfo ParachainId (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Storage: VtokenVoting PendingRemoveDelegatorVote (r:0 w:1) + /// Proof: VtokenVoting PendingRemoveDelegatorVote (max_values: None, max_size: Some(36), added: 2511, mode: MaxEncodedLen) + /// Storage: PolkadotXcm Queries (r:0 w:1) + /// Proof Skipped: PolkadotXcm Queries (max_values: None, max_size: None, mode: Measured) fn remove_delegator_vote() -> Weight { // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 7_000_000 picoseconds. - Weight::from_parts(7_000_000, 0) + // Measured: `965` + // Estimated: `4430` + // Minimum execution time: 40_000_000 picoseconds. + Weight::from_parts(41_000_000, 4430) + .saturating_add(RocksDbWeight::get().reads(7_u64)) + .saturating_add(RocksDbWeight::get().writes(3_u64)) } - fn set_delegator_role() -> Weight { + /// Storage: VtokenVoting ReferendumInfoFor (r:1 w:1) + /// Proof: VtokenVoting ReferendumInfoFor (max_values: None, max_size: Some(88), added: 2563, mode: MaxEncodedLen) + /// Storage: ParachainSystem ValidationData (r:1 w:0) + /// Proof Skipped: ParachainSystem ValidationData (max_values: Some(1), max_size: None, mode: Measured) + fn kill_referendum() -> Weight { // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 6_000_000 picoseconds. - Weight::from_parts(7_000_000, 0) + // Measured: `370` + // Estimated: `3553` + // Minimum execution time: 16_000_000 picoseconds. + Weight::from_parts(17_000_000, 3553) + .saturating_add(RocksDbWeight::get().reads(2_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) } - fn set_referendum_status() -> Weight { + /// Storage: Slp DelegatorsIndex2Multilocation (r:1 w:0) + /// Proof Skipped: Slp DelegatorsIndex2Multilocation (max_values: None, max_size: None, mode: Measured) + /// Storage: VtokenVoting DelegatorVote (r:1 w:1) + /// Proof: VtokenVoting DelegatorVote (max_values: None, max_size: Some(81), added: 2556, mode: MaxEncodedLen) + fn set_delegator_role() -> Weight { // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 7_000_000 picoseconds. - Weight::from_parts(7_000_000, 0) + // Measured: `372` + // Estimated: `3837` + // Minimum execution time: 18_000_000 picoseconds. + Weight::from_parts(19_000_000, 3837) + .saturating_add(RocksDbWeight::get().reads(2_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) } - fn set_vote_locking_period() -> Weight { + /// Storage: VtokenVoting ReferendumInfoFor (r:1 w:1) + /// Proof: VtokenVoting ReferendumInfoFor (max_values: None, max_size: Some(88), added: 2563, mode: MaxEncodedLen) + fn set_referendum_status() -> Weight { // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 6_000_000 picoseconds. - Weight::from_parts(7_000_000, 0) + // Measured: `321` + // Estimated: `3553` + // Minimum execution time: 13_000_000 picoseconds. + Weight::from_parts(14_000_000, 3553) + .saturating_add(RocksDbWeight::get().reads(1_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) } + /// Storage: VtokenVoting UndecidingTimeout (r:0 w:1) + /// Proof: VtokenVoting UndecidingTimeout (max_values: None, max_size: Some(26), added: 2501, mode: MaxEncodedLen) fn set_undeciding_timeout() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 6_000_000 picoseconds. - Weight::from_parts(7_000_000, 0) + // Minimum execution time: 7_000_000 picoseconds. + Weight::from_parts(8_000_000, 0) + .saturating_add(RocksDbWeight::get().writes(1_u64)) } - /// Storage: VtokenVoting ReferendumInfos (r:0 w:1) - /// Proof: VtokenVoting ReferendumInfos (max_values: None, max_size: Some(56), added: 2531, mode: MaxEncodedLen) - fn kill_referendum() -> Weight { + /// Storage: VtokenVoting VoteLockingPeriod (r:0 w:1) + /// Proof: VtokenVoting VoteLockingPeriod (max_values: None, max_size: Some(26), added: 2501, mode: MaxEncodedLen) + fn set_vote_locking_period() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 8_000_000 picoseconds. - Weight::from_parts(9_000_000, 0) + // Minimum execution time: 7_000_000 picoseconds. + Weight::from_parts(8_000_000, 0) .saturating_add(RocksDbWeight::get().writes(1_u64)) } + /// Storage: VtokenVoting PendingVotingInfo (r:1 w:0) + /// Proof: VtokenVoting PendingVotingInfo (max_values: None, max_size: Some(117), added: 2592, mode: MaxEncodedLen) + /// Storage: VtokenVoting PendingReferendumInfo (r:1 w:0) + /// Proof: VtokenVoting PendingReferendumInfo (max_values: None, max_size: Some(34), added: 2509, mode: MaxEncodedLen) fn notify_vote() -> Weight { // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 2_000_000 picoseconds. - Weight::from_parts(3_000_000, 0) - } - fn notify_update_referendum_status() -> Weight { - // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 2_000_000 picoseconds. - Weight::from_parts(3_000_000, 0) + // Measured: `361` + // Estimated: `3582` + // Minimum execution time: 15_000_000 picoseconds. + Weight::from_parts(16_000_000, 3582) + .saturating_add(RocksDbWeight::get().reads(2_u64)) } + /// Storage: VtokenVoting PendingRemoveDelegatorVote (r:1 w:0) + /// Proof: VtokenVoting PendingRemoveDelegatorVote (max_values: None, max_size: Some(36), added: 2511, mode: MaxEncodedLen) fn notify_remove_delegator_vote() -> Weight { // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 2_000_000 picoseconds. - Weight::from_parts(3_000_000, 0) + // Measured: `329` + // Estimated: `3501` + // Minimum execution time: 12_000_000 picoseconds. + Weight::from_parts(13_000_000, 3501) + .saturating_add(RocksDbWeight::get().reads(1_u64)) } } diff --git a/runtime/bifrost-kusama/src/lib.rs b/runtime/bifrost-kusama/src/lib.rs index 3eae12927..1661562eb 100644 --- a/runtime/bifrost-kusama/src/lib.rs +++ b/runtime/bifrost-kusama/src/lib.rs @@ -27,7 +27,7 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); pub mod migration; -use bifrost_slp::{Ledger, QueryResponseManager}; +use bifrost_slp::{DerivativeAccountProvider, QueryResponseManager}; use core::convert::TryInto; use frame_support::pallet_prelude::StorageVersion; // A few exports that help ease life for downstream crates. @@ -110,7 +110,6 @@ use governance::{custom_origins, CoreAdmin, TechAdmin}; // xcm config mod xcm_config; -use bifrost_vtoken_voting::{traits::DerivativeAccountHandler, DerivativeIndex}; use pallet_xcm::{EnsureResponse, QueryStatus}; use xcm::v3::prelude::*; pub use xcm_config::{ @@ -1481,30 +1480,10 @@ parameter_types! { pub const QueryTimeout: BlockNumber = 100; } -pub struct DerivativeAccount; -impl DerivativeAccountHandler for DerivativeAccount { - fn check_derivative_index_exists(token: CurrencyId, derivative_index: DerivativeIndex) -> bool { - Slp::get_delegator_multilocation_by_index(token, derivative_index).is_some() - } - - fn get_multilocation( - token: CurrencyId, - derivative_index: DerivativeIndex, - ) -> Option { - Slp::get_delegator_multilocation_by_index(token, derivative_index) - } - - fn get_stake_info( - token: CurrencyId, - derivative_index: DerivativeIndex, - ) -> Option<(Balance, Balance)> { - Self::get_multilocation(token, derivative_index).and_then(|location| { - Slp::get_delegator_ledger(token, location).and_then(|ledger| match ledger { - Ledger::Substrate(l) if token == CurrencyId::Token(TokenSymbol::KSM) => - Some((l.total, l.active)), - _ => None, - }) - }) +pub struct DerivativeAccountTokenFilter; +impl Contains for DerivativeAccountTokenFilter { + fn contains(token: &CurrencyId) -> bool { + *token == RelayCurrencyId::get() } } @@ -1516,10 +1495,10 @@ impl bifrost_vtoken_voting::Config for Runtime { type ControlOrigin = EitherOfDiverse; type ResponseOrigin = EnsureResponse; type XcmDestWeightAndFee = XcmInterface; - type DerivativeAccount = DerivativeAccount; + type DerivativeAccount = DerivativeAccountProvider; type RelaychainBlockNumberProvider = RelaychainDataProvider; type ParachainId = SelfParaChainId; - type MaxVotes = ConstU32<512>; + type MaxVotes = ConstU32<256>; type QueryTimeout = QueryTimeout; type WeightInfo = bifrost_vtoken_voting::weights::BifrostWeight; } diff --git a/runtime/bifrost-polkadot/src/lib.rs b/runtime/bifrost-polkadot/src/lib.rs index 8b022d026..829616d70 100644 --- a/runtime/bifrost-polkadot/src/lib.rs +++ b/runtime/bifrost-polkadot/src/lib.rs @@ -27,7 +27,7 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); pub mod migration; -use bifrost_slp::{Ledger, QueryResponseManager}; +use bifrost_slp::{DerivativeAccountProvider, QueryResponseManager}; use core::convert::TryInto; use frame_support::pallet_prelude::StorageVersion; // A few exports that help ease life for downstream crates. @@ -106,7 +106,6 @@ use zenlink_protocol::{ }; // xcm config mod xcm_config; -use bifrost_vtoken_voting::{traits::DerivativeAccountHandler, DerivativeIndex}; use orml_traits::{currency::MutationHooks, location::RelativeReserveProvider}; use pallet_xcm::{EnsureResponse, QueryStatus}; use static_assertions::const_assert; @@ -1329,30 +1328,10 @@ parameter_types! { pub const QueryTimeout: BlockNumber = 100; } -pub struct DerivativeAccount; -impl DerivativeAccountHandler for DerivativeAccount { - fn check_derivative_index_exists(token: CurrencyId, derivative_index: DerivativeIndex) -> bool { - Slp::get_delegator_multilocation_by_index(token, derivative_index).is_some() - } - - fn get_multilocation( - token: CurrencyId, - derivative_index: DerivativeIndex, - ) -> Option { - Slp::get_delegator_multilocation_by_index(token, derivative_index) - } - - fn get_stake_info( - token: CurrencyId, - derivative_index: DerivativeIndex, - ) -> Option<(Balance, Balance)> { - Self::get_multilocation(token, derivative_index).and_then(|location| { - Slp::get_delegator_ledger(token, location).and_then(|ledger| match ledger { - Ledger::Substrate(l) if token == CurrencyId::Token(TokenSymbol::KSM) => - Some((l.total, l.active)), - _ => None, - }) - }) +pub struct DerivativeAccountTokenFilter; +impl Contains for DerivativeAccountTokenFilter { + fn contains(token: &CurrencyId) -> bool { + *token == RelayCurrencyId::get() } } @@ -1364,10 +1343,10 @@ impl bifrost_vtoken_voting::Config for Runtime { type ControlOrigin = EitherOfDiverse; type ResponseOrigin = EnsureResponse; type XcmDestWeightAndFee = XcmInterface; - type DerivativeAccount = DerivativeAccount; + type DerivativeAccount = DerivativeAccountProvider; type RelaychainBlockNumberProvider = RelaychainDataProvider; type ParachainId = SelfParaChainId; - type MaxVotes = ConstU32<512>; + type MaxVotes = ConstU32<256>; type QueryTimeout = QueryTimeout; type WeightInfo = bifrost_vtoken_voting::weights::BifrostWeight; }