diff --git a/INV4/pallet-inv4/src/lib.rs b/INV4/pallet-inv4/src/lib.rs index a67f9704..1b72cd38 100644 --- a/INV4/pallet-inv4/src/lib.rs +++ b/INV4/pallet-inv4/src/lib.rs @@ -70,7 +70,9 @@ pub mod pallet { fungibles::{Balanced, Inspect}, Currency, Get, GetCallMetadata, ReservableCurrency, }, - transactional, Parameter, + transactional, + weights::WeightToFee, + Parameter, }; use frame_system::{pallet_prelude::*, RawOrigin}; use primitives::CoreInfo; @@ -172,6 +174,9 @@ pub mod pallet { /// Weight info for dispatchable calls type WeightInfo: WeightInfo; + + /// Weight to fee conversion provider, from pallet_transaction_payment + type LengthToFee: WeightToFee>; } /// The current storage version. diff --git a/INV4/pallet-inv4/src/multisig.rs b/INV4/pallet-inv4/src/multisig.rs index 1ef7d575..6689c5e9 100644 --- a/INV4/pallet-inv4/src/multisig.rs +++ b/INV4/pallet-inv4/src/multisig.rs @@ -13,7 +13,7 @@ use super::pallet::{self, *}; use crate::{ account_derivation::CoreAccountDerivation, - fee_handling::FeeAsset, + fee_handling::{FeeAsset, FeeAssetNegativeImbalance, MultisigFeeHandler}, origin::{ensure_multisig, INV4Origin}, voting::{Tally, Vote}, }; @@ -27,8 +27,9 @@ use frame_support::{ traits::{ fungibles::{Inspect, Mutate}, tokens::{Fortitude, Precision}, - Currency, VoteTally, + Currency, ExistenceRequirement, VoteTally, WithdrawReasons, }, + weights::WeightToFee, BoundedBTreeMap, }; use frame_system::{ensure_signed, pallet_prelude::*}; @@ -169,6 +170,21 @@ where .try_into() .map_err(|_| Error::::MaxCallLengthExceeded)?; + let total_lenght = (bounded_call.len() as u64) + .saturating_add(metadata.clone().unwrap_or_default().len() as u64); + + let storage_cost: BalanceOf = + T::LengthToFee::weight_to_fee(&Weight::from_parts(total_lenght as u64, 0)); + + T::FeeCharger::handle_creation_fee(FeeAssetNegativeImbalance::Native( + ::Currency::withdraw( + &owner, + storage_cost, + WithdrawReasons::TRANSACTION_PAYMENT, + ExistenceRequirement::KeepAlive, + )?, + )); + // Insert proposal in storage, it's now in the voting stage Multisig::::insert( core_id, diff --git a/INV4/pallet-inv4/src/tests/mock.rs b/INV4/pallet-inv4/src/tests/mock.rs index 4af34722..e391a184 100644 --- a/INV4/pallet-inv4/src/tests/mock.rs +++ b/INV4/pallet-inv4/src/tests/mock.rs @@ -7,6 +7,7 @@ use frame_support::{ fungibles::Credit, ConstU128, ConstU32, ConstU64, Contains, Currency, EnsureOrigin, EnsureOriginWithArg, }, + weights::ConstantMultiplier, }; use frame_system::EnsureRoot; use orml_asset_registry::AssetMetadata; @@ -87,6 +88,7 @@ impl pallet_balances::Config for Test { } const UNIT: u128 = 1000000000000; +const MICROUNIT: Balance = 1_000_000; pub struct CoreDustRemovalWhitelist; impl Contains for CoreDustRemovalWhitelist { @@ -208,6 +210,8 @@ parameter_types! { pub const MaxReserves: u32 = 1; pub const MaxCallSize: u32 = 50 * 1024; pub const StringLimit: u32 = 2125; + pub const TransactionByteFee: Balance = 10 * MICROUNIT; + } pub struct AssetAuthority; @@ -220,6 +224,18 @@ impl EnsureOriginWithArg> for AssetAuthority { ) -> Result { as EnsureOrigin>::try_origin(origin) } + + fn ensure_origin( + o: RuntimeOrigin, + a: &Option, + ) -> Result { + Self::try_origin(o, a).map_err(|_| sp_runtime::traits::BadOrigin) + } + + #[cfg(feature = "runtime-benchmarks")] + fn try_successful_origin(_o: &Option) -> Result { + Err(()) + } } impl orml_asset_registry::Config for Test { @@ -340,6 +356,7 @@ impl pallet::Config for Test { type MaxCallSize = MaxCallSize; type ParaId = ConstU32<2125>; + type LengthToFee = ConstantMultiplier; } pub struct ExtBuilder; diff --git a/OCIF/staking/src/lib.rs b/OCIF/staking/src/lib.rs index c85f64e2..1046d094 100644 --- a/OCIF/staking/src/lib.rs +++ b/OCIF/staking/src/lib.rs @@ -565,7 +565,7 @@ pub mod pallet { let _total_stakers = _core_stake_info.number_of_stakers; let message = primitives::UnregisterMessage:: { - core_id: core_id.clone(), + core_id, era: current_era, stakers_to_unstake: _total_stakers, } @@ -1329,7 +1329,7 @@ pub mod pallet { let total_remaning_stakers = stakers.saturating_sub(chunk_size as u32); if total_remaning_stakers != 0 { let _call: Vec = primitives::UnregisterMessage:: { - core_id: core_id.clone(), + core_id, stakers_to_unstake: total_remaning_stakers, era: start_era, } diff --git a/OCIF/staking/src/testing/mock.rs b/OCIF/staking/src/testing/mock.rs index 3d9f6af8..98101c8b 100644 --- a/OCIF/staking/src/testing/mock.rs +++ b/OCIF/staking/src/testing/mock.rs @@ -10,7 +10,7 @@ use frame_support::{ }, weights::{ constants::{BlockExecutionWeight, ExtrinsicBaseWeight, WEIGHT_REF_TIME_PER_SECOND}, - Weight, + ConstantMultiplier, Weight, }, PalletId, }; @@ -39,6 +39,7 @@ pub(crate) const UNBONDING_PERIOD: EraIndex = 3; pub(crate) const MAX_ERA_STAKE_VALUES: u32 = 8; pub(crate) const BLOCKS_PER_ERA: BlockNumber = 3; pub(crate) const REGISTER_DEPOSIT: Balance = 10; +const MICROUNIT: Balance = 1_000_000; construct_runtime!( pub struct Test { @@ -245,6 +246,7 @@ impl pallet_inv4::Config for Test { type MaxCallSize = ConstU32<51200>; type ParaId = ConstU32<2125>; + type LengthToFee = ConstantMultiplier; } impl pallet_ocif_staking::Config for Test { @@ -304,6 +306,7 @@ parameter_types! { pub MessageQueueServiceWeight: Weight = Perbill::from_percent(35) * RuntimeBlockWeights::get().max_block; pub const MessageQueueMaxStale: u32 = 8; pub const MessageQueueHeapSize: u32 = 128 * 1048; + pub const TransactionByteFee: Balance = 10 * MICROUNIT; } impl pallet_message_queue::Config for Test { diff --git a/pallet-rings/src/tests/mock.rs b/pallet-rings/src/tests/mock.rs index 4e75548c..b6ff8f31 100644 --- a/pallet-rings/src/tests/mock.rs +++ b/pallet-rings/src/tests/mock.rs @@ -10,6 +10,7 @@ use frame_support::{ fungibles::Credit, ConstU128, ConstU32, ConstU64, Contains, Currency, EnsureOrigin, EnsureOriginWithArg, Everything, Nothing, }, + weights::ConstantMultiplier, }; use frame_system::EnsureRoot; use orml_asset_registry::AssetMetadata; @@ -34,6 +35,8 @@ type Balance = u128; type AccountId = AccountId32; +const MICROUNIT: Balance = 1_000_000; + pub const EXISTENTIAL_DEPOSIT: Balance = 1_000_000_000; pub const ALICE: AccountId = AccountId32::new([ @@ -324,6 +327,7 @@ parameter_types! { pub const ExistentialDeposit: u128 = 100000000000; pub const MaxLocks: u32 = 1; pub const MaxReserves: u32 = 1; + pub const TransactionByteFee: Balance = 10 * MICROUNIT; } pub struct AssetAuthority; @@ -455,6 +459,7 @@ impl pallet_inv4::Config for Test { type MaxCallSize = ConstU32<51200>; type ParaId = ConstU32<2125>; + type LengthToFee = ConstantMultiplier; } parameter_types! {