diff --git a/pallets/automation-price/src/benchmarking.rs b/pallets/automation-price/src/benchmarking.rs index a44690f8..eb21bfe6 100644 --- a/pallets/automation-price/src/benchmarking.rs +++ b/pallets/automation-price/src/benchmarking.rs @@ -221,6 +221,8 @@ benchmarks! { // our task look up will always be O(1) for time let mut task_ids: Vec = vec![]; for i in 1..100 { + let account_min = T::Currency::minimum_balance().saturating_mul(ED_MULTIPLIER.into()); + T::Currency::deposit_creating(&creator, account_min.saturating_mul(DEPOSIT_MULTIPLIER.into())); direct_task_schedule::(creator.clone(), format!("{:?}", i).as_bytes().to_vec(), i, "gt".as_bytes().to_vec(), i, vec![100, 200, (i % 256) as u8]); task_ids.push(format!("{:?}", i).as_bytes().to_vec()); } @@ -252,11 +254,13 @@ benchmarks! { emit_event { let who: T::AccountId = account("call", 1, SEED); + let schedule_as: T::AccountId = account("schedule_as", 1, SEED); let task_id: TaskId = vec![1,2,3]; } : { AutomationPrice::::deposit_event(crate::Event::::TaskScheduled { - who: who, - task_id: task_id, + who, + task_id, + schedule_as: Some(schedule_as), }); } diff --git a/pallets/automation-price/src/fees.rs b/pallets/automation-price/src/fees.rs index 14ab9ef3..86870135 100644 --- a/pallets/automation-price/src/fees.rs +++ b/pallets/automation-price/src/fees.rs @@ -16,7 +16,7 @@ // limitations under the License. /// ! Traits and default implementation for paying execution fees. -use crate::{AccountOf, Action, ActionOf, Config, Error, MultiBalanceOf}; +use crate::{AccountOf, Action, ActionOf, Config, Error, MultiBalanceOf, Pallet}; use orml_traits::MultiCurrency; use pallet_xcmp_handler::{InstructionSequence, XcmpTransactor}; @@ -34,7 +34,6 @@ pub trait HandleFees { fn pay_checked_fees_for Result>( owner: &AccountOf, action: &ActionOf, - executions: u32, prereq: F, ) -> Result; } @@ -54,10 +53,9 @@ where fn pay_checked_fees_for Result>( owner: &AccountOf, action: &ActionOf, - executions: u32, prereq: F, ) -> Result { - let fee_handler = Self::new(owner, action, executions)?; + let fee_handler = Self::new(owner, action)?; fee_handler.can_pay_fee().map_err(|_| Error::::InsufficientBalance)?; let outcome = prereq()?; fee_handler.pay_fees()?; @@ -126,21 +124,16 @@ where } /// Builds an instance of the struct - pub fn new( - owner: &AccountOf, - action: &ActionOf, - executions: u32, - ) -> Result { + pub fn new(owner: &AccountOf, action: &ActionOf) -> Result { let schedule_fee_location = action.schedule_fee_location::(); - // TODO: FIX THIS BEFORE MERGE - let schedule_fee_amount: u128 = 1_000; - //Pallet::::calculate_schedule_fee_amount(action, executions)?.saturated_into(); + let schedule_fee_amount: u128 = + Pallet::::calculate_schedule_fee_amount(action)?.saturated_into(); let execution_fee_amount = match action.clone() { Action::XCMP { execution_fee, instruction_sequence, .. } if instruction_sequence == InstructionSequence::PayThroughSovereignAccount => - execution_fee.amount.saturating_mul(executions.into()).saturated_into(), + execution_fee.amount.saturating_mul(1_u32.into()).saturated_into(), _ => 0u32.saturated_into(), }; diff --git a/pallets/automation-price/src/lib.rs b/pallets/automation-price/src/lib.rs index 8c515d0b..d3efd6b8 100644 --- a/pallets/automation-price/src/lib.rs +++ b/pallets/automation-price/src/lib.rs @@ -56,6 +56,7 @@ use frame_support::{ pallet_prelude::*, traits::{Currency, ExistenceRequirement}, transactional, + weights::constants::WEIGHT_REF_TIME_PER_SECOND, }; use frame_system::pallet_prelude::*; use orml_traits::{FixedConversionRateProvider, MultiCurrency}; @@ -349,6 +350,9 @@ pub mod pallet { /// Too Many Assets Created AssetLimitReached, + FeePaymentError, + CannotReanchor, + UnsupportedFeePayment, /// The version of the `VersionedMultiLocation` value used is not able /// to be interpreted. BadVersion, @@ -361,6 +365,7 @@ pub mod pallet { TaskScheduled { who: AccountOf, task_id: TaskId, + schedule_as: Option>, }, // an event when we're about to run the task TaskTriggered { @@ -581,7 +586,6 @@ pub mod pallet { Ok(()) } - // TODO: correct weight #[pallet::call_index(4)] #[pallet::weight(::WeightInfo::schedule_xcmp_task_extrinsic())] #[transactional] @@ -608,7 +612,6 @@ pub mod pallet { // TODO: the value to be inserted into the BTree should come from a function that // extract value from param // - // TODO: HANDLE FEE to see user can pay fee let who = ensure_signed(origin)?; let task_id = Self::generate_task_id(); @@ -641,12 +644,9 @@ pub mod pallet { }; Self::validate_and_schedule_task(task)?; - // TODO withdraw fee - //T::FeeHandler::withdraw_fee(&who, fee).map_err(|_| Error::::InsufficientBalance)?; Ok(()) } - /// TODO: correct weight to use schedule_xcmp_task /// Schedule a task through XCMP through proxy account to fire an XCMP message with a provided call. /// /// Before the task can be scheduled the task must past validation checks. @@ -1076,34 +1076,107 @@ pub mod pallet { Err(Error::::InvalidTaskId)? } - >::insert(task.task_id.clone(), &task); - Self::push_task_to_account(&task); + match task.action.clone() { + Action::XCMP { execution_fee, instruction_sequence, .. } => { + let asset_location = MultiLocation::try_from(execution_fee.asset_location) + .map_err(|()| Error::::BadVersion)?; + let asset_location = asset_location + .reanchored( + &MultiLocation::new(1, X1(Parachain(T::SelfParaId::get().into()))), + T::UniversalLocation::get(), + ) + .map_err(|_| Error::::CannotReanchor)?; + // Only native token are supported as the XCMP fee for local deductions + if instruction_sequence == InstructionSequence::PayThroughSovereignAccount && + asset_location != MultiLocation::new(0, Here) + { + Err(Error::::UnsupportedFeePayment)? + } + }, + _ => (), + }; - let key = (&task.chain, &task.exchange, &task.asset_pair, &task.trigger_function); + let fee_result = + T::FeeHandler::pay_checked_fees_for(&task.owner_id, &task.action, || { + >::insert(task.task_id.clone(), &task); + Self::push_task_to_account(&task); - if let Some(mut sorted_task_index) = Self::get_sorted_tasks_index(key) { - // TODO: remove hard code and take right param - if let Some(tasks_by_price) = sorted_task_index.get_mut(&(task.trigger_params[0])) { - tasks_by_price.push(task.task_id.clone()); - } else { - sorted_task_index.insert(task.trigger_params[0], vec![task.task_id.clone()]); - } - SortedTasksIndex::::insert(key, sorted_task_index); - } else { - let mut sorted_task_index = BTreeMap::::new(); - sorted_task_index.insert(task.trigger_params[0], vec![task.task_id.clone()]); + let key = + (&task.chain, &task.exchange, &task.asset_pair, &task.trigger_function); + + if let Some(mut sorted_task_index) = Self::get_sorted_tasks_index(key) { + // TODO: remove hard code and take right param + if let Some(tasks_by_price) = + sorted_task_index.get_mut(&(task.trigger_params[0])) + { + tasks_by_price.push(task.task_id.clone()); + } else { + sorted_task_index + .insert(task.trigger_params[0], vec![task.task_id.clone()]); + } + SortedTasksIndex::::insert(key, sorted_task_index); + } else { + let mut sorted_task_index = BTreeMap::::new(); + sorted_task_index + .insert(task.trigger_params[0], vec![task.task_id.clone()]); - // TODO: sorted based on trigger_function comparison of the parameter - // then at the time of trigger we cut off all the left part of the tree - SortedTasksIndex::::insert(key, sorted_task_index); + // TODO: sorted based on trigger_function comparison of the parameter + // then at the time of trigger we cut off all the left part of the tree + SortedTasksIndex::::insert(key, sorted_task_index); + } + + Ok(task.task_id.clone()) + }); + + if let Err(e) = fee_result { + Err(Error::::FeePaymentError)? } + let schedule_as = match task.action.clone() { + Action::XCMP { schedule_as, .. } => schedule_as, + _ => None, + }; + Self::deposit_event(Event::TaskScheduled { who: task.owner_id, task_id: task.task_id.clone(), + schedule_as, }); Ok(()) } + + /// Calculates the execution fee for a given action based on weight and num of executions + /// + /// Fee saturates at Weight/BalanceOf when there are an unreasonable num of executions + /// In practice, executions is bounded by T::MaxExecutionTimes and unlikely to saturate + pub fn calculate_schedule_fee_amount( + action: &ActionOf, + ) -> Result, DispatchError> { + let total_weight = action.execution_weight::()?; + + let schedule_fee_location = action.schedule_fee_location::(); + let schedule_fee_location = schedule_fee_location + .reanchored( + &MultiLocation::new(1, X1(Parachain(T::SelfParaId::get().into()))), + T::UniversalLocation::get(), + ) + .map_err(|_| Error::::CannotReanchor)?; + + let fee = if schedule_fee_location == MultiLocation::default() { + T::ExecutionWeightFee::get() + .saturating_mul(>::saturated_from(total_weight)) + } else { + let raw_fee = + T::FeeConversionRateProvider::get_fee_per_second(&schedule_fee_location) + .ok_or("CouldNotDetermineFeePerSecond")? + .checked_mul(total_weight as u128) + .ok_or("FeeOverflow") + .map(|raw_fee| raw_fee / (WEIGHT_REF_TIME_PER_SECOND as u128))?; + >::saturated_from(raw_fee) + }; + + Ok(fee) + } } impl pallet_valve::Shutdown for Pallet { diff --git a/pallets/automation-price/src/mock.rs b/pallets/automation-price/src/mock.rs index 586cb379..8a696c69 100644 --- a/pallets/automation-price/src/mock.rs +++ b/pallets/automation-price/src/mock.rs @@ -274,7 +274,7 @@ impl pallet_automation_price::WeightInfo for MockWei } fn schedule_xcmp_task_extrinsic() -> Weight { - Weight::from_ref_time(200_000_000_u64) + Weight::from_ref_time(24_000_000_u64) } fn cancel_task_extrinsic() -> Weight { @@ -443,16 +443,10 @@ pub fn get_xcmp_funds(account: AccountId) { Balances::set_balance(RawOrigin::Root.into(), account, with_xcm_fees, 0).unwrap(); } -pub fn fund_account( - account: &AccountId, - action_weight: u64, - execution_count: usize, - additional_amount: Option, -) { - let amount: u128 = - u128::from(action_weight) * ExecutionWeightFee::get() * execution_count as u128 + - additional_amount.unwrap_or(0) + - u128::from(ExistentialDeposit::get()); +pub fn fund_account(account: &AccountId, action_weight: u64, additional_amount: Option) { + let amount: u128 = u128::from(action_weight) * ExecutionWeightFee::get() + + additional_amount.unwrap_or(0) + + u128::from(ExistentialDeposit::get()); _ = ::Currency::deposit_creating(account, amount); } diff --git a/pallets/automation-price/src/raw-weights.rs b/pallets/automation-price/src/raw-weights.rs new file mode 100644 index 00000000..e8244de4 --- /dev/null +++ b/pallets/automation-price/src/raw-weights.rs @@ -0,0 +1,174 @@ +// This file is part of Substrate. + +// Copyright (C) 2022 Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! Autogenerated weights for pallet_automation_price +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2023-09-28, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! HOSTNAME: `copvan.local`, CPU: `` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("turing-dev"), DB CACHE: 1024 + +// Executed Command: +// target/release/oak-collator +// benchmark +// pallet +// --chain +// turing-dev +// --execution +// wasm +// --wasm-execution +// compiled +// --pallet +// pallet_automation_price +// --extrinsic +// * +// --repeat +// 20 +// --steps +// 50 +// --output +// ./pallets/automation-price/src/raw-weights.rs +// --template +// ./.maintain/frame-weight-template.hbs + +// Summary: +//:initialize_asset_extrinsic 14_098_714 +//:asset_price_update_extrinsic 9_980_215 +//:schedule_xcmp_task_extrinsic 12_000_000 +//:cancel_task_extrinsic 20_000_000 +//:run_xcmp_task 30_000_000 +//:emit_event 4_000_000 + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] + +use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; +use sp_std::marker::PhantomData; + +/// Weight functions needed for pallet_automation_price. +pub trait WeightInfo { + fn initialize_asset_extrinsic(v: u32, ) -> Weight; + fn asset_price_update_extrinsic(v: u32, ) -> Weight; + fn schedule_xcmp_task_extrinsic() -> Weight; + fn cancel_task_extrinsic() -> Weight; + fn run_xcmp_task() -> Weight; + fn emit_event() -> Weight; +} + +/// Weights for pallet_automation_price using the Substrate node and recommended hardware. +pub struct SubstrateWeight(PhantomData); +impl WeightInfo for SubstrateWeight { + // Storage: AutomationPrice AssetRegistry (r:1 w:1) + // Proof Skipped: AutomationPrice AssetRegistry (max_values: None, max_size: None, mode: Measured) + /// The range of component `v` is `[1, 5]`. + fn initialize_asset_extrinsic(_v: u32, ) -> Weight { + Weight::from_ref_time(14_098_714 as u64) + .saturating_add(T::DbWeight::get().reads(1 as u64)) + .saturating_add(T::DbWeight::get().writes(1 as u64)) + } + // Storage: AutomationPrice AssetRegistry (r:1 w:0) + // Proof Skipped: AutomationPrice AssetRegistry (max_values: None, max_size: None, mode: Measured) + /// The range of component `v` is `[1, 100]`. + fn asset_price_update_extrinsic(v: u32, ) -> Weight { + Weight::from_ref_time(9_980_215 as u64) + // Standard Error: 617 + .saturating_add(Weight::from_ref_time(141_778 as u64).saturating_mul(v as u64)) + .saturating_add(T::DbWeight::get().reads(1 as u64)) + } + // Storage: ParachainInfo ParachainId (r:1 w:0) + // Proof: ParachainInfo ParachainId (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + fn schedule_xcmp_task_extrinsic() -> Weight { + Weight::from_ref_time(12_000_000 as u64) + .saturating_add(T::DbWeight::get().reads(1 as u64)) + } + // Storage: AutomationPrice Tasks (r:1 w:1) + // Proof Skipped: AutomationPrice Tasks (max_values: None, max_size: None, mode: Measured) + // Storage: AutomationPrice AccountTasks (r:0 w:1) + // Proof Skipped: AutomationPrice AccountTasks (max_values: None, max_size: None, mode: Measured) + // Storage: AutomationPrice SortedTasksIndex (r:0 w:1) + // Proof Skipped: AutomationPrice SortedTasksIndex (max_values: None, max_size: None, mode: Measured) + fn cancel_task_extrinsic() -> Weight { + Weight::from_ref_time(20_000_000 as u64) + .saturating_add(T::DbWeight::get().reads(1 as u64)) + .saturating_add(T::DbWeight::get().writes(3 as u64)) + } + // Storage: ParachainInfo ParachainId (r:1 w:0) + // Proof: ParachainInfo ParachainId (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + // Storage: UnknownTokens ConcreteFungibleBalances (r:1 w:0) + // Proof Skipped: UnknownTokens ConcreteFungibleBalances (max_values: None, max_size: None, mode: Measured) + // Storage: AssetRegistry LocationToAssetId (r:1 w:0) + // Proof Skipped: AssetRegistry LocationToAssetId (max_values: None, max_size: None, mode: Measured) + fn run_xcmp_task() -> Weight { + Weight::from_ref_time(30_000_000 as u64) + .saturating_add(T::DbWeight::get().reads(3 as u64)) + } + fn emit_event() -> Weight { + Weight::from_ref_time(4_000_000 as u64) + } +} + +// For backwards compatibility and tests +impl WeightInfo for () { + // Storage: AutomationPrice AssetRegistry (r:1 w:1) + // Proof Skipped: AutomationPrice AssetRegistry (max_values: None, max_size: None, mode: Measured) + /// The range of component `v` is `[1, 5]`. + fn initialize_asset_extrinsic(_v: u32, ) -> Weight { + Weight::from_ref_time(14_098_714 as u64) + .saturating_add(RocksDbWeight::get().reads(1 as u64)) + .saturating_add(RocksDbWeight::get().writes(1 as u64)) + } + // Storage: AutomationPrice AssetRegistry (r:1 w:0) + // Proof Skipped: AutomationPrice AssetRegistry (max_values: None, max_size: None, mode: Measured) + /// The range of component `v` is `[1, 100]`. + fn asset_price_update_extrinsic(v: u32, ) -> Weight { + Weight::from_ref_time(9_980_215 as u64) + // Standard Error: 617 + .saturating_add(Weight::from_ref_time(141_778 as u64).saturating_mul(v as u64)) + .saturating_add(RocksDbWeight::get().reads(1 as u64)) + } + // Storage: ParachainInfo ParachainId (r:1 w:0) + // Proof: ParachainInfo ParachainId (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + fn schedule_xcmp_task_extrinsic() -> Weight { + Weight::from_ref_time(12_000_000 as u64) + .saturating_add(RocksDbWeight::get().reads(1 as u64)) + } + // Storage: AutomationPrice Tasks (r:1 w:1) + // Proof Skipped: AutomationPrice Tasks (max_values: None, max_size: None, mode: Measured) + // Storage: AutomationPrice AccountTasks (r:0 w:1) + // Proof Skipped: AutomationPrice AccountTasks (max_values: None, max_size: None, mode: Measured) + // Storage: AutomationPrice SortedTasksIndex (r:0 w:1) + // Proof Skipped: AutomationPrice SortedTasksIndex (max_values: None, max_size: None, mode: Measured) + fn cancel_task_extrinsic() -> Weight { + Weight::from_ref_time(20_000_000 as u64) + .saturating_add(RocksDbWeight::get().reads(1 as u64)) + .saturating_add(RocksDbWeight::get().writes(3 as u64)) + } + // Storage: ParachainInfo ParachainId (r:1 w:0) + // Proof: ParachainInfo ParachainId (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + // Storage: UnknownTokens ConcreteFungibleBalances (r:1 w:0) + // Proof Skipped: UnknownTokens ConcreteFungibleBalances (max_values: None, max_size: None, mode: Measured) + // Storage: AssetRegistry LocationToAssetId (r:1 w:0) + // Proof Skipped: AssetRegistry LocationToAssetId (max_values: None, max_size: None, mode: Measured) + fn run_xcmp_task() -> Weight { + Weight::from_ref_time(30_000_000 as u64) + .saturating_add(RocksDbWeight::get().reads(3 as u64)) + } + fn emit_event() -> Weight { + Weight::from_ref_time(4_000_000 as u64) + } +} diff --git a/pallets/automation-price/src/tests.rs b/pallets/automation-price/src/tests.rs index cb37df40..94009204 100644 --- a/pallets/automation-price/src/tests.rs +++ b/pallets/automation-price/src/tests.rs @@ -291,7 +291,6 @@ fn test_update_asset_prices_multi() { #[test] fn test_schedule_xcmp_task_ok() { new_test_ext(START_BLOCK_TIME).execute_with(|| { - // TODO: Setup fund once we add fund check and weight let para_id: u32 = 1000; let creator = AccountId32::new(ALICE); let call: Vec = vec![2, 4, 5]; @@ -299,6 +298,7 @@ fn test_schedule_xcmp_task_ok() { setup_asset(&creator, chain1.to_vec()); + get_xcmp_funds(creator.clone()); assert_ok!(AutomationPrice::schedule_xcmp_task( RuntimeOrigin::signed(creator.clone()), chain1.to_vec(), @@ -312,7 +312,7 @@ fn test_schedule_xcmp_task_ok() { Box::new(NATIVE_LOCATION.into()), Box::new(AssetPayment { asset_location: MultiLocation::new(0, Here).into(), - amount: 10000000000000 + amount: 10_000_000 }), call.clone(), Weight::from_ref_time(100_000), @@ -346,6 +346,7 @@ fn test_schedule_xcmp_task_ok() { // Ensure task is inserted into the right SortedIndex // Create second task, and make sure both are recorded + get_xcmp_funds(creator.clone()); assert_ok!(AutomationPrice::schedule_xcmp_task( RuntimeOrigin::signed(creator), chain1.to_vec(), @@ -359,7 +360,7 @@ fn test_schedule_xcmp_task_ok() { Box::new(NATIVE_LOCATION.into()), Box::new(AssetPayment { asset_location: MultiLocation::new(0, Here).into(), - amount: 10000000000000 + amount: 10_000_000 }), call.clone(), Weight::from_ref_time(100_000), @@ -377,7 +378,44 @@ fn test_schedule_xcmp_task_ok() { )) .unwrap(); let task_ids: Vec = sorted_task_index.into_values().collect(); - assert_eq!(task_ids, vec!(vec!(vec!(49, 45, 48, 45, 49), vec!(49, 45, 48, 45, 50)))); + assert_eq!(task_ids, vec!(vec!("1-0-4".as_bytes().to_vec(), "1-0-7".as_bytes().to_vec(),))); + }) +} + +// Verify when user having not enough fund, we will fail with the right error code +#[test] +fn test_schedule_xcmp_task_fail_not_enough_balance() { + new_test_ext(START_BLOCK_TIME).execute_with(|| { + let para_id: u32 = 1000; + let creator = AccountId32::new(ALICE); + let call: Vec = vec![2, 4, 5]; + let destination = MultiLocation::new(1, X1(Parachain(para_id))); + + setup_asset(&creator, chain1.to_vec()); + + get_xcmp_funds(creator.clone()); + assert_noop!( + AutomationPrice::schedule_xcmp_task( + RuntimeOrigin::signed(creator.clone()), + chain1.to_vec(), + exchange1.to_vec(), + asset1.to_vec(), + asset2.to_vec(), + 1005u128, + "gt".as_bytes().to_vec(), + vec!(100), + Box::new(destination.into()), + Box::new(NATIVE_LOCATION.into()), + Box::new(AssetPayment { + asset_location: MultiLocation::new(0, Here).into(), + amount: 10_000_000_000 + }), + call.clone(), + Weight::from_ref_time(100_000), + Weight::from_ref_time(200_000) + ), + Error::::FeePaymentError, + ); }) } @@ -385,15 +423,14 @@ fn test_schedule_xcmp_task_ok() { #[test] fn test_shift_tasks_movement_through_price_changes() { new_test_ext(START_BLOCK_TIME).execute_with(|| { - // TODO: Setup fund once we add fund check and weight let para_id: u32 = 1000; let creator = AccountId32::new(ALICE); let call: Vec = vec![2, 4, 5]; let destination = MultiLocation::new(1, X1(Parachain(para_id))); setup_prices(&creator); - // Lets setup 3 tasks + get_xcmp_funds(creator.clone()); assert_ok!(AutomationPrice::schedule_xcmp_task( RuntimeOrigin::signed(creator.clone()), chain1.to_vec(), @@ -407,13 +444,14 @@ fn test_shift_tasks_movement_through_price_changes() { Box::new(NATIVE_LOCATION.into()), Box::new(AssetPayment { asset_location: MultiLocation::new(0, Here).into(), - amount: 10000000000000 + amount: 10 }), call.clone(), Weight::from_ref_time(100_000), Weight::from_ref_time(200_000) )); + get_xcmp_funds(creator.clone()); assert_ok!(AutomationPrice::schedule_xcmp_task( RuntimeOrigin::signed(creator.clone()), chain2.to_vec(), @@ -427,13 +465,14 @@ fn test_shift_tasks_movement_through_price_changes() { Box::new(NATIVE_LOCATION.into()), Box::new(AssetPayment { asset_location: MultiLocation::new(0, Here).into(), - amount: 10000000000000 + amount: 10 }), call.clone(), Weight::from_ref_time(100_000), Weight::from_ref_time(200_000) )); + get_xcmp_funds(creator.clone()); assert_ok!(AutomationPrice::schedule_xcmp_task( RuntimeOrigin::signed(creator.clone()), chain2.to_vec(), @@ -447,7 +486,7 @@ fn test_shift_tasks_movement_through_price_changes() { Box::new(NATIVE_LOCATION.into()), Box::new(AssetPayment { asset_location: MultiLocation::new(0, Here).into(), - amount: 10000000000000 + amount: 10 }), call.clone(), Weight::from_ref_time(100_000), @@ -533,6 +572,7 @@ fn test_shift_tasks_movement_through_price_changes() { // // Now if a task come with <, they can + get_xcmp_funds(creator.clone()); assert_ok!(AutomationPrice::schedule_xcmp_task( RuntimeOrigin::signed(creator.clone()), chain2.to_vec(), @@ -547,7 +587,7 @@ fn test_shift_tasks_movement_through_price_changes() { Box::new(NATIVE_LOCATION.into()), Box::new(AssetPayment { asset_location: MultiLocation::new(0, Here).into(), - amount: 10000000000000 + amount: 10_000_000 }), call.clone(), Weight::from_ref_time(100_000), diff --git a/pallets/automation-price/src/weights.rs b/pallets/automation-price/src/weights.rs index 5a0fd685..e8244de4 100644 --- a/pallets/automation-price/src/weights.rs +++ b/pallets/automation-price/src/weights.rs @@ -18,7 +18,7 @@ //! Autogenerated weights for pallet_automation_price //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-09-27, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-09-28, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` //! HOSTNAME: `copvan.local`, CPU: `` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("turing-dev"), DB CACHE: 1024 @@ -46,11 +46,11 @@ // ./.maintain/frame-weight-template.hbs // Summary: -//:initialize_asset_extrinsic 14_442_352 -//:asset_price_update_extrinsic 10_694_700 -//:schedule_xcmp_task_extrinsic 24_000_000 -//:cancel_task_extrinsic 21_000_000 -//:run_xcmp_task 28_000_000 +//:initialize_asset_extrinsic 14_098_714 +//:asset_price_update_extrinsic 9_980_215 +//:schedule_xcmp_task_extrinsic 12_000_000 +//:cancel_task_extrinsic 20_000_000 +//:run_xcmp_task 30_000_000 //:emit_event 4_000_000 #![cfg_attr(rustfmt, rustfmt_skip)] @@ -75,9 +75,9 @@ pub struct SubstrateWeight(PhantomData); impl WeightInfo for SubstrateWeight { // Storage: AutomationPrice AssetRegistry (r:1 w:1) // Proof Skipped: AutomationPrice AssetRegistry (max_values: None, max_size: None, mode: Measured) - /// The range of component `v` is `[1, 36]`. + /// The range of component `v` is `[1, 5]`. fn initialize_asset_extrinsic(_v: u32, ) -> Weight { - Weight::from_ref_time(14_442_352 as u64) + Weight::from_ref_time(14_098_714 as u64) .saturating_add(T::DbWeight::get().reads(1 as u64)) .saturating_add(T::DbWeight::get().writes(1 as u64)) } @@ -85,21 +85,16 @@ impl WeightInfo for SubstrateWeight { // Proof Skipped: AutomationPrice AssetRegistry (max_values: None, max_size: None, mode: Measured) /// The range of component `v` is `[1, 100]`. fn asset_price_update_extrinsic(v: u32, ) -> Weight { - Weight::from_ref_time(10_694_700 as u64) - // Standard Error: 982 - .saturating_add(Weight::from_ref_time(135_931 as u64).saturating_mul(v as u64)) + Weight::from_ref_time(9_980_215 as u64) + // Standard Error: 617 + .saturating_add(Weight::from_ref_time(141_778 as u64).saturating_mul(v as u64)) .saturating_add(T::DbWeight::get().reads(1 as u64)) } - // Storage: AutomationPrice SortedTasksIndex (r:1 w:1) - // Proof Skipped: AutomationPrice SortedTasksIndex (max_values: None, max_size: None, mode: Measured) - // Storage: AutomationPrice AccountTasks (r:0 w:1) - // Proof Skipped: AutomationPrice AccountTasks (max_values: None, max_size: None, mode: Measured) - // Storage: AutomationPrice Tasks (r:0 w:1) - // Proof Skipped: AutomationPrice Tasks (max_values: None, 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) fn schedule_xcmp_task_extrinsic() -> Weight { - Weight::from_ref_time(24_000_000 as u64) + Weight::from_ref_time(12_000_000 as u64) .saturating_add(T::DbWeight::get().reads(1 as u64)) - .saturating_add(T::DbWeight::get().writes(3 as u64)) } // Storage: AutomationPrice Tasks (r:1 w:1) // Proof Skipped: AutomationPrice Tasks (max_values: None, max_size: None, mode: Measured) @@ -108,7 +103,7 @@ impl WeightInfo for SubstrateWeight { // Storage: AutomationPrice SortedTasksIndex (r:0 w:1) // Proof Skipped: AutomationPrice SortedTasksIndex (max_values: None, max_size: None, mode: Measured) fn cancel_task_extrinsic() -> Weight { - Weight::from_ref_time(21_000_000 as u64) + Weight::from_ref_time(20_000_000 as u64) .saturating_add(T::DbWeight::get().reads(1 as u64)) .saturating_add(T::DbWeight::get().writes(3 as u64)) } @@ -119,7 +114,7 @@ impl WeightInfo for SubstrateWeight { // Storage: AssetRegistry LocationToAssetId (r:1 w:0) // Proof Skipped: AssetRegistry LocationToAssetId (max_values: None, max_size: None, mode: Measured) fn run_xcmp_task() -> Weight { - Weight::from_ref_time(28_000_000 as u64) + Weight::from_ref_time(30_000_000 as u64) .saturating_add(T::DbWeight::get().reads(3 as u64)) } fn emit_event() -> Weight { @@ -131,9 +126,9 @@ impl WeightInfo for SubstrateWeight { impl WeightInfo for () { // Storage: AutomationPrice AssetRegistry (r:1 w:1) // Proof Skipped: AutomationPrice AssetRegistry (max_values: None, max_size: None, mode: Measured) - /// The range of component `v` is `[1, 36]`. + /// The range of component `v` is `[1, 5]`. fn initialize_asset_extrinsic(_v: u32, ) -> Weight { - Weight::from_ref_time(14_442_352 as u64) + Weight::from_ref_time(14_098_714 as u64) .saturating_add(RocksDbWeight::get().reads(1 as u64)) .saturating_add(RocksDbWeight::get().writes(1 as u64)) } @@ -141,21 +136,16 @@ impl WeightInfo for () { // Proof Skipped: AutomationPrice AssetRegistry (max_values: None, max_size: None, mode: Measured) /// The range of component `v` is `[1, 100]`. fn asset_price_update_extrinsic(v: u32, ) -> Weight { - Weight::from_ref_time(10_694_700 as u64) - // Standard Error: 982 - .saturating_add(Weight::from_ref_time(135_931 as u64).saturating_mul(v as u64)) + Weight::from_ref_time(9_980_215 as u64) + // Standard Error: 617 + .saturating_add(Weight::from_ref_time(141_778 as u64).saturating_mul(v as u64)) .saturating_add(RocksDbWeight::get().reads(1 as u64)) } - // Storage: AutomationPrice SortedTasksIndex (r:1 w:1) - // Proof Skipped: AutomationPrice SortedTasksIndex (max_values: None, max_size: None, mode: Measured) - // Storage: AutomationPrice AccountTasks (r:0 w:1) - // Proof Skipped: AutomationPrice AccountTasks (max_values: None, max_size: None, mode: Measured) - // Storage: AutomationPrice Tasks (r:0 w:1) - // Proof Skipped: AutomationPrice Tasks (max_values: None, 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) fn schedule_xcmp_task_extrinsic() -> Weight { - Weight::from_ref_time(24_000_000 as u64) + Weight::from_ref_time(12_000_000 as u64) .saturating_add(RocksDbWeight::get().reads(1 as u64)) - .saturating_add(RocksDbWeight::get().writes(3 as u64)) } // Storage: AutomationPrice Tasks (r:1 w:1) // Proof Skipped: AutomationPrice Tasks (max_values: None, max_size: None, mode: Measured) @@ -164,7 +154,7 @@ impl WeightInfo for () { // Storage: AutomationPrice SortedTasksIndex (r:0 w:1) // Proof Skipped: AutomationPrice SortedTasksIndex (max_values: None, max_size: None, mode: Measured) fn cancel_task_extrinsic() -> Weight { - Weight::from_ref_time(21_000_000 as u64) + Weight::from_ref_time(20_000_000 as u64) .saturating_add(RocksDbWeight::get().reads(1 as u64)) .saturating_add(RocksDbWeight::get().writes(3 as u64)) } @@ -175,7 +165,7 @@ impl WeightInfo for () { // Storage: AssetRegistry LocationToAssetId (r:1 w:0) // Proof Skipped: AssetRegistry LocationToAssetId (max_values: None, max_size: None, mode: Measured) fn run_xcmp_task() -> Weight { - Weight::from_ref_time(28_000_000 as u64) + Weight::from_ref_time(30_000_000 as u64) .saturating_add(RocksDbWeight::get().reads(3 as u64)) } fn emit_event() -> Weight {