Skip to content
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
7ef950a
add storage to call weight
zqhxuyuan Apr 19, 2022
34c9d6a
add storage to other dispatch call
zqhxuyuan Apr 19, 2022
fc778b3
reserve weight to fee
zqhxuyuan Apr 25, 2022
00d0e1a
evm reserve and unreserve use payment
zqhxuyuan Apr 25, 2022
617193d
option named reserve and unreserve
zqhxuyuan Apr 25, 2022
c2a908c
fix CI
zqhxuyuan Apr 25, 2022
32b895f
mock reserved payment
zqhxuyuan Apr 25, 2022
13f4bc6
fix benchmark
zqhxuyuan Apr 25, 2022
b572e16
refactor
zqhxuyuan Apr 26, 2022
ed7d36c
clean
zqhxuyuan Apr 26, 2022
a6178eb
payment reserve fee testcase
zqhxuyuan Apr 26, 2022
718a9b7
clean
zqhxuyuan Apr 26, 2022
23563af
add intergration test
zqhxuyuan Apr 28, 2022
5cc11dc
reserve fee consider multiplier
zqhxuyuan Apr 28, 2022
d03adf3
testcase of reserve fee consider multiplier
zqhxuyuan Apr 28, 2022
6e25d44
consider multiplier for other method
zqhxuyuan Apr 28, 2022
8dfe9aa
fee multiplier flag
zqhxuyuan May 2, 2022
6d5f635
add option Multiplier to cal_final_fee
zqhxuyuan May 3, 2022
d6e6a1f
remove noop
zqhxuyuan May 4, 2022
2986ed3
merge master
zqhxuyuan May 4, 2022
e60fec0
update dep
zqhxuyuan May 4, 2022
c7a2651
revert orml
zqhxuyuan May 4, 2022
da9375e
pub weight_to_fee
zqhxuyuan May 4, 2022
20f5a42
fix dead code in test
zqhxuyuan May 4, 2022
2ec2adf
allow dead code
zqhxuyuan May 4, 2022
8025756
fix import
zqhxuyuan May 4, 2022
effd916
rename calculate_final_fee to apply_multiplier_to_fee and change defa…
zqhxuyuan May 5, 2022
8399183
fix clippy
zqhxuyuan May 5, 2022
1f3c91f
add more methods to trait
zqhxuyuan May 7, 2022
adecaf9
update
zqhxuyuan May 7, 2022
35cadb0
merge master
zqhxuyuan May 10, 2022
5ed4f1f
update evm-tests
zqhxuyuan May 10, 2022
bb012d0
merge master and evm bench add payment
zqhxuyuan May 15, 2022
b494b7e
fix beanch compile CI
zqhxuyuan May 15, 2022
7bcc209
fix dep
zqhxuyuan May 15, 2022
1f2b6f1
use real ChargeTransactionPayment
zqhxuyuan May 16, 2022
53661fa
merge master
zqhxuyuan May 16, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion modules/asset-registry/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl module_evm::Config for Runtime {
type PrecompilesValue = ();
type ChainId = ();
type GasToWeight = ();
type ChargeTransactionPayment = ();
type ChargeTransactionPayment = module_support::mocks::MockReservedTransactionPayment<Balances>;
type NetworkContractOrigin = EnsureSignedBy<NetworkContractAccount, AccountId>;
type NetworkContractSource = NetworkContractSource;

Expand Down
2 changes: 1 addition & 1 deletion modules/currencies/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ impl module_evm::Config for Runtime {
type PrecompilesValue = ();
type ChainId = ();
type GasToWeight = GasToWeight;
type ChargeTransactionPayment = ();
type ChargeTransactionPayment = support::mocks::MockReservedTransactionPayment<Balances>;
type NetworkContractOrigin = EnsureSignedBy<NetworkContractAccount, AccountId>;
type NetworkContractSource = NetworkContractSource;

Expand Down
2 changes: 1 addition & 1 deletion modules/evm-bridge/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ impl module_evm::Config for Runtime {
type PrecompilesValue = ();
type ChainId = ();
type GasToWeight = ();
type ChargeTransactionPayment = ();
type ChargeTransactionPayment = support::mocks::MockReservedTransactionPayment<Balances>;
type NetworkContractOrigin = EnsureSignedBy<NetworkContractAccount, AccountId32>;
type NetworkContractSource = NetworkContractSource;

Expand Down
32 changes: 20 additions & 12 deletions modules/evm/src/bench/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use super::super::*;

use frame_support::{
construct_runtime, ord_parameter_types, parameter_types,
traits::{ConstU128, ConstU32, ConstU64, Everything, FindAuthor, Nothing},
traits::{ConstU128, ConstU32, ConstU64, Everything, FindAuthor, Imbalance, Nothing},
ConsensusEngineId,
};
use frame_system::EnsureSignedBy;
Expand All @@ -37,6 +37,7 @@ use sp_runtime::{
traits::{BlakeTwo256, BlockNumberProvider, IdentityLookup},
AccountId32,
};
use std::marker::PhantomData;

type Balance = u128;

Expand Down Expand Up @@ -128,7 +129,6 @@ define_combined_task! {
}

pub struct MockBlockNumberProvider;

impl BlockNumberProvider for MockBlockNumberProvider {
type BlockNumber = u32;

Expand All @@ -147,7 +147,6 @@ impl module_idle_scheduler::Config for Runtime {
}

pub struct GasToWeight;

impl Convert<u64, u64> for GasToWeight {
fn convert(a: u64) -> u64 {
a
Expand Down Expand Up @@ -188,7 +187,7 @@ impl Config for Runtime {
type PrecompilesValue = ();
type ChainId = ConstU64<1>;
type GasToWeight = GasToWeight;
type ChargeTransactionPayment = DefaultTransactionPayment;
type ChargeTransactionPayment = DefaultTransactionPayment<Balances>;
Comment thread
zqhxuyuan marked this conversation as resolved.
Outdated

type NetworkContractOrigin = EnsureSignedBy<NetworkContractAccount, AccountId32>;
type NetworkContractSource = NetworkContractSource;
Expand All @@ -204,17 +203,26 @@ impl Config for Runtime {
type WeightInfo = ();
}

pub struct DefaultTransactionPayment;

use frame_support::traits::Imbalance;
impl<AccountId, Balance: Default + Copy, NegativeImbalance: Imbalance<Balance>>
TransactionPayment<AccountId, Balance, NegativeImbalance> for DefaultTransactionPayment
pub struct DefaultTransactionPayment<Currency>(PhantomData<Currency>);
impl<
AccountId,
Balance: Default + Copy,
NegativeImbalance: Imbalance<Balance>,
Currency: frame_support::traits::NamedReservableCurrency<
AccountId,
ReserveIdentifier = ReserveIdentifier,
Balance = Balance,
>,
> TransactionPayment<AccountId, Balance, NegativeImbalance> for DefaultTransactionPayment<Currency>
{
fn reserve_fee(_who: &AccountId, _weight: Weight) -> Result<Balance, DispatchError> {
Ok(Default::default())
fn reserve_fee(who: &AccountId, fee: Balance, named: Option<ReserveIdentifier>) -> Result<Balance, DispatchError> {
Currency::reserve_named(&named.unwrap(), who, fee)?;
Ok(fee)
}

fn unreserve_fee(_who: &AccountId, _fee: Balance) {}
fn unreserve_fee(_who: &AccountId, _fee: Balance, _named: Option<ReserveIdentifier>) -> Balance {
Default::default()
}

fn unreserve_and_charge_fee(
_who: &AccountId,
Expand Down
19 changes: 10 additions & 9 deletions modules/evm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1476,7 +1476,7 @@ impl<T: Config> Pallet<T> {
///
/// - Ensures signer is maintainer or root.
/// - Update codes info.
/// - Save `code`if not saved yet.
/// - Save `code` if not saved yet.
fn do_set_code(root_or_signed: Either<(), T::AccountId>, contract: EvmAddress, code: Vec<u8>) -> DispatchResult {
Accounts::<T>::mutate(contract, |maybe_account_info| -> DispatchResult {
let account_info = maybe_account_info.as_mut().ok_or(Error::<T>::ContractNotFound)?;
Expand All @@ -1501,20 +1501,20 @@ impl<T: Config> Pallet<T> {
let code_hash = code_hash(bounded_code.as_slice());
let code_size = bounded_code.len() as u32;
// The code_hash of the same contract is definitely different.
// The `contract_info.code_hash` hashed by on_contract_initialization which constructored.
// The `contract_info.code_hash` hashed by on_contract_initialization which constructed.
// Still check it here.
if code_hash == contract_info.code_hash {
return Ok(());
}

let storage_size_chainged: i32 =
let storage_size_changed: i32 =
code_size.saturating_add(T::NewContractExtraBytes::get()) as i32 - old_code_info.code_size as i32;

if storage_size_chainged.is_positive() {
Self::reserve_storage(&source, storage_size_chainged as u32)?;
if storage_size_changed.is_positive() {
Self::reserve_storage(&source, storage_size_changed as u32)?;
}
Self::charge_storage(&source, &contract, storage_size_chainged)?;
Self::update_contract_storage_size(&contract, storage_size_chainged);
Self::charge_storage(&source, &contract, storage_size_changed)?;
Self::update_contract_storage_size(&contract, storage_size_changed);

// try remove old codes
CodeInfos::<T>::mutate_exists(&contract_info.code_hash, |maybe_code_info| -> DispatchResult {
Expand Down Expand Up @@ -1577,7 +1577,7 @@ impl<T: Config> Pallet<T> {
// when rpc is called, from is empty, allowing the call
published || maintainer == *caller || Self::is_developer_or_contract(caller) || *caller == H160::default()
} else {
// contract non exist, we don't override defualt evm behaviour
// contract non exist, we don't override default evm behaviour
true
}
}
Expand Down Expand Up @@ -1606,7 +1606,8 @@ impl<T: Config> Pallet<T> {
caller, user, limit, amount
);

T::Currency::reserve_named(&RESERVE_ID_STORAGE_DEPOSIT, &user, amount)
T::ChargeTransactionPayment::reserve_fee(&user, amount, Some(RESERVE_ID_STORAGE_DEPOSIT))?;
Comment thread
zqhxuyuan marked this conversation as resolved.
Ok(())
}

fn unreserve_storage(caller: &H160, limit: u32, used: u32, refunded: u32) -> DispatchResult {
Expand Down
2 changes: 1 addition & 1 deletion modules/evm/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ impl Config for Runtime {
type PrecompilesValue = ();
type ChainId = ConstU64<1>;
type GasToWeight = GasToWeight;
type ChargeTransactionPayment = ();
type ChargeTransactionPayment = module_support::mocks::MockReservedTransactionPayment<Balances>;

type NetworkContractOrigin = EnsureSignedBy<NetworkContractAccount, AccountId32>;
type NetworkContractSource = NetworkContractSource;
Expand Down
19 changes: 11 additions & 8 deletions modules/idle-scheduler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub mod module {
/// Weight information for the extrinsics in this module.
type WeightInfo: WeightInfo;

/// Dispatchable tasks
/// Dispatchable tasks.
type Task: DispatchableTask + FullCodec + Debug + Clone + PartialEq + TypeInfo;

/// The minimum weight that should remain before idle tasks are dispatched.
Expand All @@ -63,9 +63,9 @@ pub mod module {
/// Gets RelayChain Block Number
type RelayChainBlockNumberProvider: BlockNumberProvider<BlockNumber = BlockNumber>;

/// Number of Relay Chain blocks skipped to disable `on_idle` dispatching scheduled tasks
/// Number of Relay Chain blocks skipped to disable `on_idle` dispatching scheduled tasks,
/// this shuts down idle-scheduler when block production is slower than this number of
/// relaychain blocks
/// relaychain blocks.
#[pallet::constant]
type DisableBlockThreshold: Get<BlockNumber>;
}
Expand All @@ -79,16 +79,19 @@ pub mod module {
TaskAdded { task_id: Nonce, task: T::Task },
}

/// Some documentation
/// The schedule tasks waiting to dispatch. After task is dispatched, it's removed.
///
/// Tasks: map Nonce => Task
#[pallet::storage]
#[pallet::getter(fn tasks)]
pub type Tasks<T: Config> = StorageMap<_, Twox64Concat, Nonce, T::Task, OptionQuery>;

/// The task id used to index tasks.
#[pallet::storage]
#[pallet::getter(fn next_task_id)]
pub type NextTaskId<T: Config> = StorageValue<_, Nonce, ValueQuery>;

///
/// A temporary variable used to check if should skip dispatch schedule task or not.
#[pallet::storage]
#[pallet::getter(fn previous_relay_block)]
pub type PreviousRelayBlockNumber<T: Config> = StorageValue<_, BlockNumber, ValueQuery>;
Expand Down Expand Up @@ -121,7 +124,7 @@ pub mod module {
current_relay_block_number,
previous_relay_block_number
);
// something is not correct so exaust all remaining weight (note: any on_idle hooks after
// something is not correct so exhaust all remaining weight (note: any on_idle hooks after
// IdleScheduler won't execute)
remaining_weight
} else {
Expand All @@ -146,7 +149,7 @@ pub mod module {
}

impl<T: Config> Pallet<T> {
/// Add the task to the queue to be dispatched later
/// Add the task to the queue to be dispatched later.
fn do_schedule_task(task: T::Task) -> DispatchResult {
let id = Self::get_next_task_id()?;
Tasks::<T>::insert(id, &task);
Expand Down Expand Up @@ -192,7 +195,7 @@ impl<T: Config> Pallet<T> {
total_weight.saturating_sub(weight_remaining)
}

// Removes completed tasks and deposits events
/// Removes completed tasks and deposits events.
pub fn remove_completed_tasks(completed_tasks: Vec<(Nonce, TaskResult)>) {
// Deposit event and remove completed tasks.
for (id, result) in completed_tasks {
Expand Down
46 changes: 3 additions & 43 deletions modules/support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@

use codec::FullCodec;
use frame_support::pallet_prelude::{DispatchClass, Pays, Weight};
use primitives::{task::TaskResult, CurrencyId};
use primitives::{task::TaskResult, CurrencyId, ReserveIdentifier};
use sp_runtime::{
traits::CheckedDiv, transaction_validity::TransactionValidityError, DispatchError, DispatchResult, FixedU128,
};
use sp_std::prelude::*;

use xcm::latest::prelude::*;

pub mod dex;
Expand Down Expand Up @@ -84,8 +83,8 @@ impl<AccountId, CurrencyId, Balance> DEXIncentives<AccountId, CurrencyId, Balanc
}

pub trait TransactionPayment<AccountId, Balance, NegativeImbalance> {
fn reserve_fee(who: &AccountId, weight: Weight) -> Result<Balance, DispatchError>;
fn unreserve_fee(who: &AccountId, fee: Balance);
fn reserve_fee(who: &AccountId, fee: Balance, named: Option<ReserveIdentifier>) -> Result<Balance, DispatchError>;
fn unreserve_fee(who: &AccountId, fee: Balance, named: Option<ReserveIdentifier>) -> Balance;
fn unreserve_and_charge_fee(
who: &AccountId,
weight: Weight,
Expand All @@ -101,45 +100,6 @@ pub trait TransactionPayment<AccountId, Balance, NegativeImbalance> {
) -> Result<(), TransactionValidityError>;
}

#[cfg(feature = "std")]
use frame_support::traits::Imbalance;
#[cfg(feature = "std")]
impl<AccountId, Balance: Default + Copy, NegativeImbalance: Imbalance<Balance>>
TransactionPayment<AccountId, Balance, NegativeImbalance> for ()
{
fn reserve_fee(_who: &AccountId, _weight: Weight) -> Result<Balance, DispatchError> {
Ok(Default::default())
}

fn unreserve_fee(_who: &AccountId, _fee: Balance) {}

fn unreserve_and_charge_fee(
_who: &AccountId,
_weight: Weight,
) -> Result<(Balance, NegativeImbalance), TransactionValidityError> {
Ok((Default::default(), Imbalance::zero()))
}

fn refund_fee(
_who: &AccountId,
_weight: Weight,
_payed: NegativeImbalance,
) -> Result<(), TransactionValidityError> {
Ok(())
}

fn charge_fee(
_who: &AccountId,
_len: u32,
_weight: Weight,
_tip: Balance,
_pays_fee: Pays,
_class: DispatchClass,
) -> Result<(), TransactionValidityError> {
Ok(())
}
}

/// Used to interface with the Compound's Cash module
pub trait CompoundCashTrait<Balance, Moment> {
fn set_future_yield(next_cash_yield: Balance, yield_index: u128, timestamp_effective: Moment) -> DispatchResult;
Expand Down
Loading