Skip to content

Commit

Permalink
chore: revert nesting_budget logic
Browse files Browse the repository at this point in the history
  • Loading branch information
mrshiposha committed Oct 11, 2023
1 parent 85147ac commit 053b43b
Show file tree
Hide file tree
Showing 21 changed files with 165 additions and 266 deletions.
18 changes: 5 additions & 13 deletions pallets/balances-adapter/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,12 @@ pub struct CommonWeights<T: Config>(PhantomData<T>);

// All implementations with `Weight::default` used in methods that return error `UnsupportedOperation`.
impl<T: Config> CommonWeightInfo<T::CrossAccountId> for CommonWeights<T> {
fn create_multiple_items(
_amount: &[up_data_structs::CreateItemData],
_nesting_budget: &dyn up_data_structs::budget::Budget,
) -> Weight {
fn create_multiple_items(_amount: &[up_data_structs::CreateItemData]) -> Weight {
Weight::default()
}

fn create_multiple_items_ex(
_cost: &up_data_structs::CreateItemExData<T::CrossAccountId>,
_nesting_budget: &dyn up_data_structs::budget::Budget,
) -> Weight {
Weight::default()
}
Expand All @@ -34,18 +30,15 @@ impl<T: Config> CommonWeightInfo<T::CrossAccountId> for CommonWeights<T> {
Weight::default()
}

fn set_token_properties(
_amount: u32,
_nesting_budget: &dyn up_data_structs::budget::Budget,
) -> Weight {
fn set_token_properties(_amount: u32) -> Weight {
Weight::default()
}

fn set_token_property_permissions(_amount: u32) -> Weight {
Weight::default()
}

fn transfer(_nesting_budget: &dyn up_data_structs::budget::Budget) -> Weight {
fn transfer() -> Weight {
<BalancesWeight<T> as WeightInfo>::transfer_allow_death()
}

Expand All @@ -57,12 +50,11 @@ impl<T: Config> CommonWeightInfo<T::CrossAccountId> for CommonWeights<T> {
Weight::default()
}

fn transfer_from(nesting_budget: &dyn up_data_structs::budget::Budget) -> Weight {
fn transfer_from() -> Weight {
<BalancesWeight<T> as WeightInfo>::transfer_allow_death()
.saturating_add(nesting_budget.predispatch_weight())
}

fn burn_from(_nesting_budget: &dyn up_data_structs::budget::Budget) -> Weight {
fn burn_from() -> Weight {
Weight::default()
}

Expand Down
28 changes: 10 additions & 18 deletions pallets/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1881,18 +1881,15 @@ macro_rules! unsupported {
/// Return weights for various worst-case operations.
pub trait CommonWeightInfo<CrossAccountId> {
/// Weight of item creation.
fn create_item(data: &CreateItemData, nesting_budget: &dyn Budget) -> Weight {
Self::create_multiple_items(from_ref(data), nesting_budget)
fn create_item(data: &CreateItemData) -> Weight {
Self::create_multiple_items(from_ref(data))
}

/// Weight of items creation.
fn create_multiple_items(amount: &[CreateItemData], nesting_budget: &dyn Budget) -> Weight;
fn create_multiple_items(amount: &[CreateItemData]) -> Weight;

/// Weight of items creation.
fn create_multiple_items_ex(
cost: &CreateItemExData<CrossAccountId>,
nesting_budget: &dyn Budget,
) -> Weight;
fn create_multiple_items_ex(cost: &CreateItemExData<CrossAccountId>) -> Weight;

/// The weight of the burning item.
fn burn_item() -> Weight;
Expand All @@ -1912,15 +1909,13 @@ pub trait CommonWeightInfo<CrossAccountId> {
/// Token property setting weight.
///
/// * `amount`- The number of properties to set.
/// * `nesting_budget` - The maximum nesting budget that can be spent.
fn set_token_properties(amount: u32, nesting_budget: &dyn Budget) -> Weight;
fn set_token_properties(amount: u32) -> Weight;

/// Token property deletion weight.
///
/// * `amount`- The number of properties to delete.
/// * `nesting_budget` - The maximum nesting budget that can be spent.
fn delete_token_properties(amount: u32, nesting_budget: &dyn Budget) -> Weight {
Self::set_token_properties(amount, nesting_budget)
fn delete_token_properties(amount: u32) -> Weight {
Self::set_token_properties(amount)
}

/// Token property permissions set weight.
Expand All @@ -1929,8 +1924,7 @@ pub trait CommonWeightInfo<CrossAccountId> {
fn set_token_property_permissions(amount: u32) -> Weight;

/// Transfer price of the token or its parts.
/// * `nesting_budget` - The maximum nesting budget that can be spent.
fn transfer(nesting_budget: &dyn Budget) -> Weight;
fn transfer() -> Weight;

/// The price of setting the permission of the operation from another user.
fn approve() -> Weight;
Expand All @@ -1939,12 +1933,10 @@ pub trait CommonWeightInfo<CrossAccountId> {
fn approve_from() -> Weight;

/// Transfer price from another user.
/// * `nesting_budget` - The maximum nesting budget that can be spent.
fn transfer_from(nesting_budget: &dyn Budget) -> Weight;
fn transfer_from() -> Weight;

/// The price of burning a token from another user.
/// * `nesting_budget` - The maximum nesting budget that can be spent.
fn burn_from(nesting_budget: &dyn Budget) -> Weight;
fn burn_from() -> Weight;

/// Differs from burn_item in case of Fungible and Refungible, as it should burn
/// whole users's balance.
Expand Down
4 changes: 0 additions & 4 deletions pallets/evm-coder-substrate/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,6 @@ impl<T: Config> budget::Budget for GasCallsBudget<'_, T> {
}
self.recorder.consume_gas(gas).is_ok()
}

fn predispatch_weight(&self) -> Weight {
Weight::zero()
}
}

#[derive(Default)]
Expand Down
2 changes: 0 additions & 2 deletions pallets/foreign-assets/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ orml-tokens = { workspace = true }
pallet-balances = { features = ["insecure_zero_ed"], workspace = true }
pallet-common = { workspace = true }
pallet-fungible = { workspace = true }
pallet-structure = { workspace = true }
serde = { workspace = true }
sp-runtime = { workspace = true }
sp-std = { workspace = true }
Expand All @@ -36,7 +35,6 @@ std = [
"pallet-common/std",
"pallet-fungible/std",
"parity-scale-codec/std",
"pallet-structure/std",
"scale-info/std",
"sp-runtime/std",
"sp-std/std",
Expand Down
6 changes: 3 additions & 3 deletions pallets/foreign-assets/src/impl_fungibles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ use frame_support::traits::tokens::{
use frame_system::Config as SystemConfig;
use pallet_common::{CollectionHandle, CommonCollectionOperations};
use pallet_fungible::FungibleHandle;
use pallet_structure::NestingBudgetValue;
use sp_runtime::traits::{CheckedAdd, CheckedSub};
use up_data_structs::budget;

use super::*;

Expand Down Expand Up @@ -327,7 +327,7 @@ where
&collection,
&account,
amount_data,
&<NestingBudgetValue<T::StructureWeightInfo>>::new(0),
&budget::Value::new(0),
)?;

Ok(amount)
Expand Down Expand Up @@ -440,7 +440,7 @@ where
&T::CrossAccountId::from_sub(source.clone()),
&T::CrossAccountId::from_sub(dest.clone()),
amount.into(),
&<NestingBudgetValue<T::StructureWeightInfo>>::new(0),
&budget::Value::new(0),
)
.map_err(|e| e.error)?;

Expand Down
3 changes: 0 additions & 3 deletions pallets/foreign-assets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,6 @@ pub mod module {

/// Weight information for the extrinsics in this module.
type WeightInfo: WeightInfo;

/// Weight information for NFT structures.
type StructureWeightInfo: pallet_structure::weights::WeightInfo;
}

pub type AssetName = BoundedVec<u8, ConstU32<32>>;
Expand Down
31 changes: 13 additions & 18 deletions pallets/fungible/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,15 @@ use crate::{

pub struct CommonWeights<T: Config>(PhantomData<T>);
impl<T: Config> CommonWeightInfo<T::CrossAccountId> for CommonWeights<T> {
fn create_multiple_items(_data: &[CreateItemData], nesting_budget: &dyn Budget) -> Weight {
fn create_multiple_items(_data: &[CreateItemData]) -> Weight {
// All items minted for the same user, so it works same as create_item
<SelfWeightOf<T>>::create_item().saturating_add(nesting_budget.predispatch_weight())
<SelfWeightOf<T>>::create_item()
}

fn create_multiple_items_ex(
data: &CreateItemExData<T::CrossAccountId>,
nesting_budget: &dyn Budget,
) -> Weight {
fn create_multiple_items_ex(data: &CreateItemExData<T::CrossAccountId>) -> Weight {
match data {
CreateItemExData::Fungible(f) => {
<SelfWeightOf<T>>::create_multiple_items_ex(f.len() as u32)
.saturating_add(nesting_budget.predispatch_weight())
}
_ => Weight::zero(),
}
Expand All @@ -64,7 +60,7 @@ impl<T: Config> CommonWeightInfo<T::CrossAccountId> for CommonWeights<T> {
<pallet_common::SelfWeightOf<T>>::set_collection_properties(amount)
}

fn set_token_properties(_amount: u32, _nesting_budget: &dyn Budget) -> Weight {
fn set_token_properties(_amount: u32) -> Weight {
// Error
Weight::zero()
}
Expand All @@ -74,10 +70,9 @@ impl<T: Config> CommonWeightInfo<T::CrossAccountId> for CommonWeights<T> {
Weight::zero()
}

fn transfer(nesting_budget: &dyn Budget) -> Weight {
fn transfer() -> Weight {
<SelfWeightOf<T>>::transfer_raw()
.saturating_add(<PalletCommonWeightOf<T>>::check_accesslist().saturating_mul(2))
.saturating_add(nesting_budget.predispatch_weight())
}

fn approve() -> Weight {
Expand All @@ -88,14 +83,14 @@ impl<T: Config> CommonWeightInfo<T::CrossAccountId> for CommonWeights<T> {
<SelfWeightOf<T>>::approve_from()
}

fn transfer_from(nesting_budget: &dyn Budget) -> Weight {
Self::transfer(nesting_budget)
fn transfer_from() -> Weight {
Self::transfer()
.saturating_add(<SelfWeightOf<T>>::check_allowed_raw())
.saturating_add(<SelfWeightOf<T>>::set_allowance_unchecked_raw())
}

fn burn_from(nesting_budget: &dyn Budget) -> Weight {
<SelfWeightOf<T>>::burn_from().saturating_add(nesting_budget.predispatch_weight())
fn burn_from() -> Weight {
<SelfWeightOf<T>>::burn_from()
}

fn burn_recursively_self_raw() -> Weight {
Expand Down Expand Up @@ -134,7 +129,7 @@ impl<T: Config> CommonCollectionOperations<T> for FungibleHandle<T> {
match &data {
up_data_structs::CreateItemData::Fungible(fungible_data) => with_weight(
<Pallet<T>>::create_item(self, &sender, (to, fungible_data.value), nesting_budget),
<CommonWeights<T>>::create_item(&data, nesting_budget),
<CommonWeights<T>>::create_item(&data),
),
_ => fail!(<Error<T>>::NotFungibleDataUsedToMintFungibleCollectionToken),
}
Expand All @@ -161,7 +156,7 @@ impl<T: Config> CommonCollectionOperations<T> for FungibleHandle<T> {

with_weight(
<Pallet<T>>::create_item(self, &sender, (to, sum), nesting_budget),
<CommonWeights<T>>::create_multiple_items(&data, nesting_budget),
<CommonWeights<T>>::create_multiple_items(&data),
)
}

Expand All @@ -171,7 +166,7 @@ impl<T: Config> CommonCollectionOperations<T> for FungibleHandle<T> {
data: up_data_structs::CreateItemExData<<T>::CrossAccountId>,
nesting_budget: &dyn Budget,
) -> DispatchResultWithPostInfo {
let weight = <CommonWeights<T>>::create_multiple_items_ex(&data, nesting_budget);
let weight = <CommonWeights<T>>::create_multiple_items_ex(&data);
let data = match data {
up_data_structs::CreateItemExData::Fungible(f) => f,
_ => fail!(<Error<T>>::NotFungibleDataUsedToMintFungibleCollectionToken),
Expand Down Expand Up @@ -305,7 +300,7 @@ impl<T: Config> CommonCollectionOperations<T> for FungibleHandle<T> {

with_weight(
<Pallet<T>>::burn_from(self, &sender, &from, amount, nesting_budget),
<CommonWeights<T>>::burn_from(nesting_budget),
<CommonWeights<T>>::burn_from(),
)
}

Expand Down
13 changes: 5 additions & 8 deletions pallets/fungible/src/erc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ use pallet_evm_coder_substrate::{
use pallet_structure::{weights::WeightInfo as _, SelfWeightOf as StructureWeight};
use sp_core::{Get, U256};
use sp_std::vec::Vec;
use up_data_structs::{
budget::{Budget, Unlimited},
CollectionMode,
};
use up_data_structs::{budget::Budget, CollectionMode};

use crate::{
common::CommonWeights, weights::WeightInfo, Allowance, Balance, Config, FungibleHandle, Pallet,
Expand Down Expand Up @@ -108,7 +105,7 @@ impl<T: Config> FungibleHandle<T> {
let balance = <Balance<T>>::get((self.id, owner));
Ok(balance.into())
}
#[weight(<CommonWeights<T>>::transfer(&Unlimited))]
#[weight(<CommonWeights<T>>::transfer())]
fn transfer(&mut self, caller: Caller, to: Address, amount: U256) -> Result<bool> {
let caller = T::CrossAccountId::from_eth(caller);
let to = T::CrossAccountId::from_eth(to);
Expand All @@ -119,7 +116,7 @@ impl<T: Config> FungibleHandle<T> {
Ok(true)
}

#[weight(<CommonWeights<T>>::transfer_from(&Unlimited))]
#[weight(<CommonWeights<T>>::transfer_from())]
fn transfer_from(
&mut self,
caller: Caller,
Expand Down Expand Up @@ -299,7 +296,7 @@ where
Ok(true)
}

#[weight(<CommonWeights<T>>::transfer(&Unlimited))]
#[weight(<CommonWeights<T>>::transfer())]
fn transfer_cross(&mut self, caller: Caller, to: CrossAddress, amount: U256) -> Result<bool> {
let caller = T::CrossAccountId::from_eth(caller);
let to = to.into_sub_cross_account::<T>()?;
Expand All @@ -310,7 +307,7 @@ where
Ok(true)
}

#[weight(<CommonWeights<T>>::transfer_from(&Unlimited))]
#[weight(<CommonWeights<T>>::transfer_from())]
fn transfer_from_cross(
&mut self,
caller: Caller,
Expand Down
Loading

0 comments on commit 053b43b

Please sign in to comment.