From ac75f36f4e2bbd543f3204073ec8a2cf6dcac484 Mon Sep 17 00:00:00 2001 From: Dino Pacandi <dino.pacandi@gmail.com> Date: Wed, 7 Feb 2024 10:14:59 +0100 Subject: [PATCH 01/14] Integration --- Cargo.lock | 10 +- runtime/astar/Cargo.toml | 32 +- runtime/astar/src/lib.rs | 367 +++++++++++--- runtime/astar/src/precompiles.rs | 6 +- runtime/astar/src/weights/mod.rs | 2 + .../src/weights/pallet_dapp_staking_v3.rs | 453 ++++++++++++++++++ runtime/astar/src/weights/pallet_inflation.rs | 102 ++++ ...r_new.rs => dispatch_precompile_filter.rs} | 0 .../src/dispatch_precompile_filter_old.rs | 221 --------- tests/integration/src/lib.rs | 18 +- .../src/{proxy_new.rs => proxy.rs} | 0 tests/integration/src/proxy_old.rs | 213 -------- tests/integration/src/setup.rs | 9 - 13 files changed, 891 insertions(+), 542 deletions(-) create mode 100644 runtime/astar/src/weights/pallet_dapp_staking_v3.rs create mode 100644 runtime/astar/src/weights/pallet_inflation.rs rename tests/integration/src/{dispatch_precompile_filter_new.rs => dispatch_precompile_filter.rs} (100%) delete mode 100644 tests/integration/src/dispatch_precompile_filter_old.rs rename tests/integration/src/{proxy_new.rs => proxy.rs} (100%) delete mode 100644 tests/integration/src/proxy_old.rs diff --git a/Cargo.lock b/Cargo.lock index 295a1cd6de..06808a258e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -555,6 +555,7 @@ dependencies = [ "cumulus-primitives-core", "cumulus-primitives-timestamp", "cumulus-primitives-utility", + "dapp-staking-v3-runtime-api", "fp-rpc", "fp-self-contained", "frame-benchmarking", @@ -576,11 +577,11 @@ dependencies = [ "pallet-aura", "pallet-authorship", "pallet-balances", - "pallet-block-rewards-hybrid", "pallet-collator-selection", - "pallet-collective", "pallet-contracts", "pallet-contracts-primitives", + "pallet-dapp-staking-migration", + "pallet-dapp-staking-v3", "pallet-dapps-staking", "pallet-dynamic-evm-base-fee", "pallet-ethereum", @@ -588,7 +589,7 @@ dependencies = [ "pallet-evm-precompile-assets-erc20", "pallet-evm-precompile-blake2", "pallet-evm-precompile-bn128", - "pallet-evm-precompile-dapps-staking", + "pallet-evm-precompile-dapp-staking-v3", "pallet-evm-precompile-dispatch", "pallet-evm-precompile-ed25519", "pallet-evm-precompile-modexp", @@ -598,9 +599,11 @@ dependencies = [ "pallet-evm-precompile-substrate-ecdsa", "pallet-evm-precompile-xcm", "pallet-identity", + "pallet-inflation", "pallet-multisig", "pallet-proxy", "pallet-session", + "pallet-static-price-provider", "pallet-sudo", "pallet-timestamp", "pallet-transaction-payment", @@ -618,6 +621,7 @@ dependencies = [ "scale-info", "smallvec 1.11.0", "sp-api", + "sp-arithmetic", "sp-block-builder", "sp-consensus-aura", "sp-core", diff --git a/runtime/astar/Cargo.toml b/runtime/astar/Cargo.toml index 8ee6f6f5dd..9584ef1566 100644 --- a/runtime/astar/Cargo.toml +++ b/runtime/astar/Cargo.toml @@ -20,6 +20,7 @@ smallvec = { workspace = true } fp-rpc = { workspace = true } fp-self-contained = { workspace = true } sp-api = { workspace = true } +sp-arithmetic = { workspace = true } sp-block-builder = { workspace = true } sp-consensus-aura = { workspace = true } sp-core = { workspace = true } @@ -92,24 +93,28 @@ orml-xtokens = { workspace = true } array-bytes = { workspace = true } frame-benchmarking = { workspace = true, optional = true } frame-system-benchmarking = { workspace = true, optional = true } -pallet-collective = { workspace = true, optional = true } # try-runtime frame-try-runtime = { workspace = true, optional = true } # Astar pallets astar-primitives = { workspace = true } -pallet-block-rewards-hybrid = { workspace = true } pallet-collator-selection = { workspace = true } +pallet-dapp-staking-migration = { workspace = true } +pallet-dapp-staking-v3 = { workspace = true } pallet-dapps-staking = { workspace = true } pallet-evm-precompile-assets-erc20 = { workspace = true } -pallet-evm-precompile-dapps-staking = { workspace = true } +pallet-evm-precompile-dapp-staking-v3 = { workspace = true } pallet-evm-precompile-sr25519 = { workspace = true } pallet-evm-precompile-substrate-ecdsa = { workspace = true } pallet-evm-precompile-xcm = { workspace = true } +pallet-inflation = { workspace = true } +pallet-static-price-provider = { workspace = true } pallet-xc-asset-config = { workspace = true } pallet-xcm = { workspace = true } +dapp-staking-v3-runtime-api = { workspace = true } + # Moonbeam tracing moonbeam-evm-tracer = { workspace = true, optional = true } moonbeam-rpc-primitives-debug = { workspace = true, optional = true } @@ -129,6 +134,7 @@ std = [ "sp-api/std", "sp-core/std", "sp-consensus-aura/std", + "sp-arithmetic/std", "sp-io/std", "sp-runtime/std", "sp-runtime-interface/std", @@ -146,9 +152,12 @@ std = [ "pallet-aura/std", "pallet-balances/std", "pallet-proxy/std", - "pallet-block-rewards-hybrid/std", - "pallet-dapps-staking/std", - "pallet-evm-precompile-dapps-staking/std", + "pallet-static-price-provider/std", + "pallet-dapp-staking-v3/std", + "pallet-dapp-staking-migration/std", + "dapp-staking-v3-runtime-api/std", + "pallet-inflation/std", + "pallet-evm-precompile-dapp-staking-v3/std", "pallet-evm-precompile-sr25519/std", "pallet-evm-precompile-assets-erc20/std", "pallet-evm-precompile-substrate-ecdsa/std", @@ -212,10 +221,10 @@ runtime-benchmarks = [ 'pallet-balances/runtime-benchmarks', "pallet-proxy/runtime-benchmarks", 'pallet-timestamp/runtime-benchmarks', - 'pallet-collective/runtime-benchmarks', "pallet-ethereum/runtime-benchmarks", - "pallet-dapps-staking/runtime-benchmarks", - "pallet-block-rewards-hybrid/runtime-benchmarks", + "pallet-dapp-staking-v3/runtime-benchmarks", + "pallet-dapp-staking-migration/runtime-benchmarks", + "pallet-inflation/runtime-benchmarks", "pallet-xcm/runtime-benchmarks", "xcm-builder/runtime-benchmarks", "pallet-xc-asset-config/runtime-benchmarks", @@ -235,12 +244,15 @@ try-runtime = [ "pallet-aura/try-runtime", "pallet-balances/try-runtime", "pallet-proxy/try-runtime", - "pallet-block-rewards-hybrid/try-runtime", "pallet-dapps-staking/try-runtime", + "pallet-dapp-staking-v3/try-runtime", + "pallet-dapp-staking-migration/try-runtime", + "pallet-inflation/try-runtime", "pallet-sudo/try-runtime", "pallet-timestamp/try-runtime", "pallet-transaction-payment/try-runtime", "pallet-utility/try-runtime", + "pallet-static-price-provider/try-runtime", "pallet-vesting/try-runtime", "pallet-xc-asset-config/try-runtime", "pallet-ethereum/try-runtime", diff --git a/runtime/astar/src/lib.rs b/runtime/astar/src/lib.rs index 69c0a82561..cf8aff1740 100644 --- a/runtime/astar/src/lib.rs +++ b/runtime/astar/src/lib.rs @@ -22,11 +22,6 @@ // `construct_runtime!` does a lot of recursion and requires us to increase the limit to 256. #![recursion_limit = "256"] -pub use crate::precompiles::WhitelistedCalls; -pub use astar_primitives::{ - evm::EvmRevertCodeHandler, xcm::AssetLocationIdConverter, AccountId, Address, AssetId, Balance, - BlockNumber, Hash, Header, Index, Signature, -}; use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases; use frame_support::{ construct_runtime, @@ -49,7 +44,6 @@ use frame_system::{ limits::{BlockLength, BlockWeights}, EnsureRoot, EnsureSigned, }; -pub use pallet_block_rewards_hybrid::RewardDistributionConfig; use pallet_ethereum::PostLogContent; use pallet_evm::{FeeCalculator, GasWeightMapping, Runner}; use pallet_evm_precompile_assets_erc20::AddressToAssetId; @@ -70,7 +64,23 @@ use sp_runtime::{ transaction_validity::{TransactionSource, TransactionValidity, TransactionValidityError}, ApplyExtrinsicResult, FixedPointNumber, Perbill, Permill, Perquintill, RuntimeDebug, }; -use sp_std::prelude::*; +use sp_std::{collections::btree_map::BTreeMap, prelude::*}; + +use astar_primitives::{ + dapp_staking::{ + AccountCheck as DappStakingAccountCheck, CycleConfiguration, DAppId, EraNumber, + PeriodNumber, SmartContract, TierId, + }, + evm::EvmRevertCodeHandler, + xcm::AssetLocationIdConverter, + Address, AssetId, BlockNumber, Hash, Header, Index, +}; +pub use astar_primitives::{AccountId, Balance, Signature}; + +pub use pallet_dapp_staking_v3::TierThreshold; +pub use pallet_inflation::InflationParameters; + +pub use crate::precompiles::WhitelistedCalls; #[cfg(any(feature = "std", test))] use sp_version::NativeVersion; @@ -263,7 +273,7 @@ parameter_types! { impl pallet_timestamp::Config for Runtime { /// A timestamp: milliseconds since the unix epoch. type Moment = u64; - type OnTimestampSet = BlockReward; + type OnTimestampSet = (); type MinimumPeriod = MinimumPeriod; type WeightInfo = pallet_timestamp::weights::SubstrateWeight<Runtime>; } @@ -336,28 +346,115 @@ impl pallet_dapps_staking::Config for Runtime { type MaxEraStakeValues = MaxEraStakeValues; // Not allowed on Astar yet type UnregisteredDappRewardRetention = ConstU32<{ u32::MAX }>; + // Needed so benchmark can use the pallets extrinsics + #[cfg(feature = "runtime-benchmarks")] type ForcePalletDisabled = ConstBool<false>; + #[cfg(not(feature = "runtime-benchmarks"))] + type ForcePalletDisabled = ConstBool<true>; // Fee required to claim rewards for another account. Calculated & tested manually. type DelegateClaimFee = ConstU128<057_950_348_114_187_155>; } -/// Multi-VM pointer to smart contract instance. -#[derive( - PartialEq, Eq, Copy, Clone, Encode, Decode, RuntimeDebug, MaxEncodedLen, scale_info::TypeInfo, -)] -pub enum SmartContract<AccountId> { - /// EVM smart contract instance. - Evm(sp_core::H160), - /// Wasm smart contract instance. - Wasm(AccountId), +impl pallet_static_price_provider::Config for Runtime { + type RuntimeEvent = RuntimeEvent; } -impl<AccountId> Default for SmartContract<AccountId> { - fn default() -> Self { - SmartContract::Evm(H160::repeat_byte(0x00)) +#[cfg(feature = "runtime-benchmarks")] +pub struct BenchmarkHelper<SC, ACC>(sp_std::marker::PhantomData<(SC, ACC)>); +#[cfg(feature = "runtime-benchmarks")] +impl pallet_dapp_staking_v3::BenchmarkHelper<SmartContract<AccountId>, AccountId> + for BenchmarkHelper<SmartContract<AccountId>, AccountId> +{ + fn get_smart_contract(id: u32) -> SmartContract<AccountId> { + let id_bytes = id.to_le_bytes(); + let mut account = [0u8; 32]; + account[..id_bytes.len()].copy_from_slice(&id_bytes); + + SmartContract::Wasm(AccountId::from(account)) + } + + fn set_balance(account: &AccountId, amount: Balance) { + use frame_support::traits::fungible::Unbalanced as FunUnbalanced; + Balances::write_balance(account, amount) + .expect("Must succeed in test/benchmark environment."); } } +pub struct AccountCheck; +impl DappStakingAccountCheck<AccountId> for AccountCheck { + fn allowed_to_stake(account: &AccountId) -> bool { + !CollatorSelection::is_account_candidate(account) + } +} + +impl pallet_dapp_staking_v3::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type RuntimeFreezeReason = RuntimeFreezeReason; + type Currency = Balances; + type SmartContract = SmartContract<AccountId>; + type ManagerOrigin = frame_system::EnsureRoot<AccountId>; + type NativePriceProvider = StaticPriceProvider; + type StakingRewardHandler = Inflation; + type CycleConfiguration = InflationCycleConfig; + type Observers = Inflation; + type AccountCheck = AccountCheck; + type EraRewardSpanLength = ConstU32<16>; + type RewardRetentionInPeriods = ConstU32<4>; + type MaxNumberOfContracts = ConstU32<500>; + type MaxUnlockingChunks = ConstU32<8>; + type MinimumLockedAmount = MinimumStakingAmount; + type UnlockingPeriod = ConstU32<9>; + type MaxNumberOfStakedContracts = ConstU32<16>; + type MinimumStakeAmount = MinimumStakingAmount; + type NumberOfTiers = ConstU32<4>; + type WeightInfo = weights::pallet_dapp_staking_v3::SubstrateWeight<Runtime>; + #[cfg(feature = "runtime-benchmarks")] + type BenchmarkHelper = BenchmarkHelper<SmartContract<AccountId>, AccountId>; +} + +pub struct InflationPayoutPerBlock; +impl pallet_inflation::PayoutPerBlock<NegativeImbalance> for InflationPayoutPerBlock { + fn treasury(reward: NegativeImbalance) { + Balances::resolve_creating(&TreasuryPalletId::get().into_account_truncating(), reward); + } + + fn collators(reward: NegativeImbalance) { + ToStakingPot::on_unbalanced(reward); + } +} + +pub struct InflationCycleConfig; +impl CycleConfiguration for InflationCycleConfig { + fn periods_per_cycle() -> u32 { + 3 + } + + fn eras_per_voting_subperiod() -> u32 { + 11 + } + + fn eras_per_build_and_earn_subperiod() -> u32 { + 111 + } + + fn blocks_per_era() -> BlockNumber { + 24 * HOURS + } +} + +impl pallet_inflation::Config for Runtime { + type Currency = Balances; + type PayoutPerBlock = InflationPayoutPerBlock; + type CycleConfiguration = InflationCycleConfig; + type RuntimeEvent = RuntimeEvent; + type WeightInfo = weights::pallet_inflation::SubstrateWeight<Runtime>; +} + +impl pallet_dapp_staking_migration::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type WeightInfo = pallet_dapp_staking_migration::weights::SubstrateWeight<Runtime>; +} + impl pallet_utility::Config for Runtime { type RuntimeEvent = RuntimeEvent; type RuntimeCall = RuntimeCall; @@ -429,9 +526,8 @@ parameter_types! { pub struct CollatorSelectionAccountCheck; impl pallet_collator_selection::AccountCheck<AccountId> for CollatorSelectionAccountCheck { - fn allowed_candidacy(_account: &AccountId) -> bool { - // TODO: update this when dApp staking v3 is integrated - true + fn allowed_candidacy(account: &AccountId) -> bool { + !DappStaking::is_staker(account) } } @@ -469,41 +565,6 @@ impl OnUnbalanced<NegativeImbalance> for ToStakingPot { } } -pub struct DappsStakingTvlProvider(); -impl Get<Balance> for DappsStakingTvlProvider { - fn get() -> Balance { - DappsStaking::tvl() - } -} - -pub struct BeneficiaryPayout(); -impl pallet_block_rewards_hybrid::BeneficiaryPayout<NegativeImbalance> for BeneficiaryPayout { - fn treasury(reward: NegativeImbalance) { - Balances::resolve_creating(&TreasuryPalletId::get().into_account_truncating(), reward); - } - - fn collators(reward: NegativeImbalance) { - ToStakingPot::on_unbalanced(reward); - } - - fn dapps_staking(stakers: NegativeImbalance, dapps: NegativeImbalance) { - DappsStaking::rewards(stakers, dapps) - } -} - -parameter_types! { - pub const MaxBlockRewardAmount: Balance = 231_206_532 * MICROASTR; -} - -impl pallet_block_rewards_hybrid::Config for Runtime { - type Currency = Balances; - type DappsStakingTvlProvider = DappsStakingTvlProvider; - type BeneficiaryPayout = BeneficiaryPayout; - type MaxBlockRewardAmount = MaxBlockRewardAmount; - type RuntimeEvent = RuntimeEvent; - type WeightInfo = pallet_block_rewards_hybrid::weights::SubstrateWeight<Runtime>; -} - parameter_types! { pub const ExistentialDeposit: Balance = 1_000_000; pub const MaxLocks: u32 = 50; @@ -521,9 +582,9 @@ impl pallet_balances::Config for Runtime { type AccountStore = frame_system::Pallet<Runtime>; type WeightInfo = pallet_balances::weights::SubstrateWeight<Runtime>; type HoldIdentifier = (); - type FreezeIdentifier = (); + type FreezeIdentifier = RuntimeFreezeReason; type MaxHolds = ConstU32<0>; - type MaxFreezes = ConstU32<0>; + type MaxFreezes = ConstU32<1>; } impl AddressToAssetId<AssetId> for Runtime { @@ -876,7 +937,7 @@ pub enum ProxyType { /// Only reject_announcement call from pallet proxy allowed for proxy account CancelProxy, /// All runtime calls from pallet DappStaking allowed for proxy account - DappsStaking, + DappStaking, /// Only claim_staker call from pallet DappStaking allowed for proxy account StakerRewardClaim, } @@ -908,7 +969,7 @@ impl InstanceFilter<RuntimeCall> for ProxyType { | RuntimeCall::Vesting(pallet_vesting::Call::vest{..}) | RuntimeCall::Vesting(pallet_vesting::Call::vest_other{..}) // Specifically omitting Vesting `vested_transfer`, and `force_vested_transfer` - | RuntimeCall::DappsStaking(..) + | RuntimeCall::DappStaking(..) // Skip entire Assets pallet | RuntimeCall::CollatorSelection(..) | RuntimeCall::Session(..) @@ -940,13 +1001,15 @@ impl InstanceFilter<RuntimeCall> for ProxyType { RuntimeCall::Proxy(pallet_proxy::Call::reject_announcement { .. }) ) } - ProxyType::DappsStaking => { - matches!(c, RuntimeCall::DappsStaking(..)) + ProxyType::DappStaking => { + matches!(c, RuntimeCall::DappStaking(..)) } ProxyType::StakerRewardClaim => { matches!( c, - RuntimeCall::DappsStaking(pallet_dapps_staking::Call::claim_staker { .. }) + RuntimeCall::DappStaking( + pallet_dapp_staking_v3::Call::claim_staker_rewards { .. } + ) ) } } @@ -957,7 +1020,7 @@ impl InstanceFilter<RuntimeCall> for ProxyType { (x, y) if x == y => true, (ProxyType::Any, _) => true, (_, ProxyType::Any) => false, - (ProxyType::DappsStaking, ProxyType::StakerRewardClaim) => true, + (ProxyType::DappStaking, ProxyType::StakerRewardClaim) => true, _ => false, } } @@ -1008,8 +1071,12 @@ construct_runtime!( TransactionPayment: pallet_transaction_payment = 30, Balances: pallet_balances = 31, Vesting: pallet_vesting = 32, - DappsStaking: pallet_dapps_staking = 34, - BlockReward: pallet_block_rewards_hybrid = 35, +// Inflation needs to execute `on_initialize` as soon as possible, and `on_finalize` as late as possible. + // However, we need to execute Balance genesis before Inflation genesis, otherwise we'll have zero issuance when Inflation + // logic is executed. + // TODO: Address this later. It would be best if Inflation was first pallet. + Inflation: pallet_inflation = 33, + DappStaking: pallet_dapp_staking_v3 = 34, Assets: pallet_assets = 36, Authorship: pallet_authorship = 40, @@ -1032,6 +1099,13 @@ construct_runtime!( Contracts: pallet_contracts = 70, Sudo: pallet_sudo = 99, + +// To be removed & cleaned up once proper oracle is implemented +StaticPriceProvider: pallet_static_price_provider = 253, +// To be removed & cleaned up after migration has been finished +DappStakingMigration: pallet_dapp_staking_migration = 254, +// Legacy dApps staking v2, to be removed after migration has been finished +DappsStaking: pallet_dapps_staking = 255, } ); @@ -1069,7 +1143,136 @@ pub type Executive = frame_executive::Executive< Migrations, >; -pub type Migrations = (); +parameter_types! { + pub const BlockRewardName: &'static str = "BlockReward"; +} +/// All migrations that will run on the next runtime upgrade. +/// +/// Once done, migrations should be removed from the tuple. +pub type Migrations = ( + pallet_static_price_provider::InitActivePrice<Runtime, InitActivePriceGet>, + pallet_inflation::PalletInflationInitConfig<Runtime, InitInflationParamsHelper>, + pallet_dapp_staking_v3::migrations::DAppStakingV3InitConfig< + Runtime, + InitDappStakingV3Params, + InitActivePriceGet, + >, + // This will handle new pallet storage version setting & it will put the new pallet into maintenance mode. + // But it's most important for testing with try-runtime. + pallet_dapp_staking_migration::DappStakingMigrationHandler<Runtime>, + frame_support::migrations::RemovePallet< + BlockRewardName, + <Runtime as frame_system::Config>::DbWeight, + >, +); + +use sp_arithmetic::fixed_point::FixedU64; +pub struct InitActivePriceGet; +impl Get<FixedU64> for InitActivePriceGet { + fn get() -> FixedU64 { + // TODO: calculate this! + FixedU64::from_rational(15, 100) + } +} + +/// Used to initialize inflation parameters for the runtime. +pub struct InitInflationParamsHelper; +impl Get<(pallet_inflation::InflationParameters, EraNumber, Weight)> for InitInflationParamsHelper { + fn get() -> (pallet_inflation::InflationParameters, EraNumber, Weight) { + ( + pallet_inflation::InflationParameters { + // Recalculation is done every two weeks, hence the small %. + max_inflation_rate: Perquintill::from_percent(7), + treasury_part: Perquintill::from_percent(5), + collators_part: Perquintill::from_rational(32_u64, 1000), + dapps_part: Perquintill::from_percent(13), + base_stakers_part: Perquintill::from_percent(25), + adjustable_stakers_part: Perquintill::from_percent(40), + bonus_part: Perquintill::from_rational(138_u64, 1000), + ideal_staking_rate: Perquintill::from_percent(50), + }, + pallet_dapps_staking::CurrentEra::<Runtime>::get().saturating_add(1), + <Runtime as frame_system::Config>::DbWeight::get().reads(1), + ) + } +} + +use frame_support::BoundedVec; +use pallet_dapp_staking_v3::{TierParameters, TiersConfiguration}; +type NumberOfTiers = <Runtime as pallet_dapp_staking_v3::Config>::NumberOfTiers; +/// Used to initialize dApp staking parameters for the runtime. +pub struct InitDappStakingV3Params; +impl + Get<( + EraNumber, + TierParameters<NumberOfTiers>, + TiersConfiguration<NumberOfTiers>, + )> for InitDappStakingV3Params +{ + fn get() -> ( + EraNumber, + TierParameters<NumberOfTiers>, + TiersConfiguration<NumberOfTiers>, + ) { + // 1. Prepare init values + + // Init era of dApp staking v3 should be the next era after dApp staking v2 + let init_era = pallet_dapps_staking::CurrentEra::<Runtime>::get().saturating_add(1); + + // Reward portions according to the Tokenomics 2.0 report + let reward_portion = BoundedVec::try_from(vec![ + Permill::from_percent(25), + Permill::from_percent(47), + Permill::from_percent(25), + Permill::from_percent(3), + ]) + .unwrap_or_default(); + + // Tier thresholds adjusted according to numbers observed on Shibuya + let tier_thresholds = BoundedVec::try_from(vec![ + TierThreshold::DynamicTvlAmount { + amount: ASTR.saturating_mul(300_000_000), + minimum_amount: ASTR.saturating_mul(200_000_000), + }, + TierThreshold::DynamicTvlAmount { + amount: ASTR.saturating_mul(75_000_000), + minimum_amount: ASTR.saturating_mul(50_000_000), + }, + TierThreshold::DynamicTvlAmount { + amount: ASTR.saturating_mul(20_000_000), + minimum_amount: ASTR.saturating_mul(15_000_000), + }, + TierThreshold::FixedTvlAmount { + amount: ASTR.saturating_mul(1_500_000), + }, + ]) + .unwrap_or_default(); + + // 2. Tier params + let tier_params = + TierParameters::<<Runtime as pallet_dapp_staking_v3::Config>::NumberOfTiers> { + reward_portion: reward_portion.clone(), + slot_distribution: BoundedVec::try_from(vec![ + Permill::from_percent(5), + Permill::from_percent(20), + Permill::from_percent(30), + Permill::from_percent(45), + ]) + .unwrap_or_default(), + tier_thresholds: tier_thresholds.clone(), + }; + + // 3. Init tier config + let init_tier_config = TiersConfiguration { + number_of_slots: 100, + slots_per_tier: BoundedVec::try_from(vec![5, 20, 30, 45]).unwrap_or_default(), + reward_portion, + tier_thresholds, + }; + + (init_era, tier_params, init_tier_config) + } +} type EventRecord = frame_system::EventRecord< <Runtime as frame_system::Config>::RuntimeEvent, @@ -1147,7 +1350,9 @@ mod benches { [pallet_balances, Balances] [pallet_timestamp, Timestamp] [pallet_dapps_staking, DappsStaking] - [block_rewards_hybrid, BlockReward] + [pallet_dapp_staking_v3, DappStaking] + [pallet_inflation, Inflation] + [pallet_dapp_staking_migration, DappStakingMigration] [pallet_xc_asset_config, XcAssetConfig] [pallet_collator_selection, CollatorSelection] [pallet_xcm, PolkadotXcm] @@ -1609,6 +1814,28 @@ impl_runtime_apis! { } } + impl dapp_staking_v3_runtime_api::DappStakingApi<Block> for Runtime { + fn periods_per_cycle() -> PeriodNumber { + InflationCycleConfig::periods_per_cycle() + } + + fn eras_per_voting_subperiod() -> EraNumber { + InflationCycleConfig::eras_per_voting_subperiod() + } + + fn eras_per_build_and_earn_subperiod() -> EraNumber { + InflationCycleConfig::eras_per_build_and_earn_subperiod() + } + + fn blocks_per_era() -> BlockNumber { + InflationCycleConfig::blocks_per_era() + } + + fn get_dapp_tier_assignment() -> BTreeMap<DAppId, TierId> { + DappStaking::get_dapp_tier_assignment() + } + } + #[cfg(feature = "runtime-benchmarks")] impl frame_benchmarking::Benchmark<Block> for Runtime { fn benchmark_metadata(extra: bool) -> ( diff --git a/runtime/astar/src/precompiles.rs b/runtime/astar/src/precompiles.rs index 938f4fec06..2b483d85e9 100644 --- a/runtime/astar/src/precompiles.rs +++ b/runtime/astar/src/precompiles.rs @@ -24,7 +24,7 @@ use frame_support::{parameter_types, traits::Contains}; use pallet_evm_precompile_assets_erc20::Erc20AssetsPrecompileSet; use pallet_evm_precompile_blake2::Blake2F; use pallet_evm_precompile_bn128::{Bn128Add, Bn128Mul, Bn128Pairing}; -use pallet_evm_precompile_dapps_staking::DappsStakingWrapper; +use pallet_evm_precompile_dapp_staking_v3::DappStakingV3Precompile; use pallet_evm_precompile_dispatch::Dispatch; use pallet_evm_precompile_ed25519::Ed25519Verify; use pallet_evm_precompile_modexp::Modexp; @@ -57,7 +57,7 @@ impl Contains<RuntimeCall> for WhitelistedCalls { | RuntimeCall::Utility(pallet_utility::Call::batch_all { calls }) => { calls.iter().all(|call| WhitelistedCalls::contains(call)) } - RuntimeCall::DappsStaking(_) => true, + RuntimeCall::DappStaking(_) => true, RuntimeCall::Assets(pallet_assets::Call::transfer { .. }) => true, _ => false, } @@ -91,7 +91,7 @@ pub type AstarPrecompilesSetAt<R, C> = ( // Astar specific precompiles: PrecompileAt< AddressU64<20481>, - DappsStakingWrapper<R>, + DappStakingV3Precompile<R>, (CallableByContract, CallableByPrecompile), >, PrecompileAt< diff --git a/runtime/astar/src/weights/mod.rs b/runtime/astar/src/weights/mod.rs index 6471081ec8..23a0bb4e9b 100644 --- a/runtime/astar/src/weights/mod.rs +++ b/runtime/astar/src/weights/mod.rs @@ -17,4 +17,6 @@ // along with Astar. If not, see <http://www.gnu.org/licenses/>. pub mod pallet_assets; +pub mod pallet_dapp_staking_v3; +pub mod pallet_inflation; pub mod pallet_xcm; diff --git a/runtime/astar/src/weights/pallet_dapp_staking_v3.rs b/runtime/astar/src/weights/pallet_dapp_staking_v3.rs new file mode 100644 index 0000000000..a7067267f8 --- /dev/null +++ b/runtime/astar/src/weights/pallet_dapp_staking_v3.rs @@ -0,0 +1,453 @@ + +// This file is part of Astar. + +// Copyright (C) 2019-2023 Stake Technologies Pte.Ltd. +// SPDX-License-Identifier: GPL-3.0-or-later + +// Astar is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Astar is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Astar. If not, see <http://www.gnu.org/licenses/>. + +//! Autogenerated weights for pallet_dapp_staking_v3 +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2024-02-04, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `gh-runner-01-ovh`, CPU: `Intel(R) Xeon(R) E-2236 CPU @ 3.40GHz` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("shiden-dev"), DB CACHE: 1024 + +// Executed Command: +// ./target/release/astar-collator +// benchmark +// pallet +// --chain=shiden-dev +// --steps=50 +// --repeat=20 +// --pallet=pallet_dapp_staking_v3 +// --extrinsic=* +// --execution=wasm +// --wasm-execution=compiled +// --heap-pages=4096 +// --output=./benchmark-results/shiden-dev/dapp_staking_v3_weights.rs +// --template=./scripts/templates/weight-template.hbs + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] + +use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; +use core::marker::PhantomData; +use pallet_dapp_staking_v3::WeightInfo; + +/// Weights for pallet_dapp_staking_v3 using the Substrate node and recommended hardware. +pub struct SubstrateWeight<T>(PhantomData<T>); +impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { + fn maintenance_mode() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 8_967_000 picoseconds. + Weight::from_parts(9_242_000, 0) + } + /// Storage: DappStaking IntegratedDApps (r:1 w:1) + /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(116), added: 2096, mode: MaxEncodedLen) + /// Storage: DappStaking CounterForIntegratedDApps (r:1 w:1) + /// Proof: DappStaking CounterForIntegratedDApps (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Storage: DappStaking NextDAppId (r:1 w:1) + /// Proof: DappStaking NextDAppId (max_values: Some(1), max_size: Some(2), added: 497, mode: MaxEncodedLen) + fn register() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `3086` + // Minimum execution time: 17_044_000 picoseconds. + Weight::from_parts(17_328_000, 3086) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) + } + /// Storage: DappStaking IntegratedDApps (r:1 w:1) + /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(116), added: 2096, mode: MaxEncodedLen) + fn set_dapp_reward_beneficiary() -> Weight { + // Proof Size summary in bytes: + // Measured: `74` + // Estimated: `3086` + // Minimum execution time: 13_369_000 picoseconds. + Weight::from_parts(13_617_000, 3086) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: DappStaking IntegratedDApps (r:1 w:1) + /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(116), added: 2096, mode: MaxEncodedLen) + fn set_dapp_owner() -> Weight { + // Proof Size summary in bytes: + // Measured: `74` + // Estimated: `3086` + // Minimum execution time: 13_421_000 picoseconds. + Weight::from_parts(13_692_000, 3086) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: DappStaking IntegratedDApps (r:1 w:1) + /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(116), added: 2096, mode: MaxEncodedLen) + /// Storage: DappStaking CounterForIntegratedDApps (r:1 w:1) + /// Proof: DappStaking CounterForIntegratedDApps (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Storage: DappStaking ContractStake (r:0 w:1) + /// Proof: DappStaking ContractStake (max_values: Some(65535), max_size: Some(91), added: 2071, mode: MaxEncodedLen) + fn unregister() -> Weight { + // Proof Size summary in bytes: + // Measured: `74` + // Estimated: `3086` + // Minimum execution time: 18_458_000 picoseconds. + Weight::from_parts(18_864_000, 3086) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) + } + /// Storage: DappStaking Ledger (r:1 w:1) + /// Proof: DappStaking Ledger (max_values: None, max_size: Some(310), added: 2785, mode: MaxEncodedLen) + /// Storage: CollatorSelection Candidates (r:1 w:0) + /// Proof Skipped: CollatorSelection Candidates (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: Balances Freezes (r:1 w:1) + /// Proof: Balances Freezes (max_values: None, max_size: Some(67), added: 2542, mode: MaxEncodedLen) + /// Storage: Balances Locks (r:1 w:0) + /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) + /// Storage: DappStaking CurrentEraInfo (r:1 w:1) + /// Proof: DappStaking CurrentEraInfo (max_values: Some(1), max_size: Some(112), added: 607, mode: MaxEncodedLen) + fn lock_new_account() -> Weight { + // Proof Size summary in bytes: + // Measured: `138` + // Estimated: `4764` + // Minimum execution time: 62_743_000 picoseconds. + Weight::from_parts(64_992_000, 4764) + .saturating_add(T::DbWeight::get().reads(5_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) + } + /// Storage: DappStaking Ledger (r:1 w:1) + /// Proof: DappStaking Ledger (max_values: None, max_size: Some(310), added: 2785, mode: MaxEncodedLen) + /// Storage: Balances Freezes (r:1 w:1) + /// Proof: Balances Freezes (max_values: None, max_size: Some(67), added: 2542, mode: MaxEncodedLen) + /// Storage: Balances Locks (r:1 w:0) + /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) + /// Storage: DappStaking CurrentEraInfo (r:1 w:1) + /// Proof: DappStaking CurrentEraInfo (max_values: Some(1), max_size: Some(112), added: 607, mode: MaxEncodedLen) + fn lock_existing_account() -> Weight { + // Proof Size summary in bytes: + // Measured: `158` + // Estimated: `4764` + // Minimum execution time: 38_250_000 picoseconds. + Weight::from_parts(38_835_000, 4764) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) + } + /// Storage: DappStaking Ledger (r:1 w:1) + /// Proof: DappStaking Ledger (max_values: None, max_size: Some(310), added: 2785, mode: MaxEncodedLen) + /// Storage: Balances Freezes (r:1 w:1) + /// Proof: Balances Freezes (max_values: None, max_size: Some(67), added: 2542, mode: MaxEncodedLen) + /// Storage: Balances Locks (r:1 w:0) + /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) + /// Storage: DappStaking CurrentEraInfo (r:1 w:1) + /// Proof: DappStaking CurrentEraInfo (max_values: Some(1), max_size: Some(112), added: 607, mode: MaxEncodedLen) + fn unlock() -> Weight { + // Proof Size summary in bytes: + // Measured: `158` + // Estimated: `4764` + // Minimum execution time: 34_582_000 picoseconds. + Weight::from_parts(35_126_000, 4764) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) + } + /// Storage: DappStaking Ledger (r:1 w:1) + /// Proof: DappStaking Ledger (max_values: None, max_size: Some(310), added: 2785, mode: MaxEncodedLen) + /// Storage: Balances Freezes (r:1 w:1) + /// Proof: Balances Freezes (max_values: None, max_size: Some(67), added: 2542, mode: MaxEncodedLen) + /// Storage: Balances Locks (r:1 w:0) + /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) + /// Storage: DappStaking CurrentEraInfo (r:1 w:1) + /// Proof: DappStaking CurrentEraInfo (max_values: Some(1), max_size: Some(112), added: 607, mode: MaxEncodedLen) + /// The range of component `x` is `[0, 16]`. + fn claim_unlocked(x: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `191` + // Estimated: `4764` + // Minimum execution time: 37_740_000 picoseconds. + Weight::from_parts(39_064_684, 4764) + // Standard Error: 2_750 + .saturating_add(Weight::from_parts(120_539, 0).saturating_mul(x.into())) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) + } + /// Storage: DappStaking Ledger (r:1 w:1) + /// Proof: DappStaking Ledger (max_values: None, max_size: Some(310), added: 2785, mode: MaxEncodedLen) + /// Storage: Balances Freezes (r:1 w:1) + /// Proof: Balances Freezes (max_values: None, max_size: Some(67), added: 2542, mode: MaxEncodedLen) + /// Storage: Balances Locks (r:1 w:0) + /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) + /// Storage: DappStaking CurrentEraInfo (r:1 w:1) + /// Proof: DappStaking CurrentEraInfo (max_values: Some(1), max_size: Some(112), added: 607, mode: MaxEncodedLen) + fn relock_unlocking() -> Weight { + // Proof Size summary in bytes: + // Measured: `200` + // Estimated: `4764` + // Minimum execution time: 33_298_000 picoseconds. + Weight::from_parts(33_903_000, 4764) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) + } + /// Storage: DappStaking IntegratedDApps (r:1 w:0) + /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(116), added: 2096, mode: MaxEncodedLen) + /// Storage: DappStaking Ledger (r:1 w:1) + /// Proof: DappStaking Ledger (max_values: None, max_size: Some(310), added: 2785, mode: MaxEncodedLen) + /// Storage: DappStaking StakerInfo (r:1 w:1) + /// Proof: DappStaking StakerInfo (max_values: None, max_size: Some(138), added: 2613, mode: MaxEncodedLen) + /// Storage: DappStaking ContractStake (r:1 w:1) + /// Proof: DappStaking ContractStake (max_values: Some(65535), max_size: Some(91), added: 2071, mode: MaxEncodedLen) + /// Storage: DappStaking CurrentEraInfo (r:1 w:1) + /// Proof: DappStaking CurrentEraInfo (max_values: Some(1), max_size: Some(112), added: 607, mode: MaxEncodedLen) + /// Storage: Balances Freezes (r:1 w:1) + /// Proof: Balances Freezes (max_values: None, max_size: Some(67), added: 2542, mode: MaxEncodedLen) + /// Storage: Balances Locks (r:1 w:0) + /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) + fn stake() -> Weight { + // Proof Size summary in bytes: + // Measured: `251` + // Estimated: `4764` + // Minimum execution time: 44_905_000 picoseconds. + Weight::from_parts(45_261_000, 4764) + .saturating_add(T::DbWeight::get().reads(7_u64)) + .saturating_add(T::DbWeight::get().writes(5_u64)) + } + /// Storage: DappStaking IntegratedDApps (r:1 w:0) + /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(116), added: 2096, mode: MaxEncodedLen) + /// Storage: DappStaking Ledger (r:1 w:1) + /// Proof: DappStaking Ledger (max_values: None, max_size: Some(310), added: 2785, mode: MaxEncodedLen) + /// Storage: DappStaking StakerInfo (r:1 w:1) + /// Proof: DappStaking StakerInfo (max_values: None, max_size: Some(138), added: 2613, mode: MaxEncodedLen) + /// Storage: DappStaking ContractStake (r:1 w:1) + /// Proof: DappStaking ContractStake (max_values: Some(65535), max_size: Some(91), added: 2071, mode: MaxEncodedLen) + /// Storage: DappStaking CurrentEraInfo (r:1 w:1) + /// Proof: DappStaking CurrentEraInfo (max_values: Some(1), max_size: Some(112), added: 607, mode: MaxEncodedLen) + /// Storage: Balances Freezes (r:1 w:1) + /// Proof: Balances Freezes (max_values: None, max_size: Some(67), added: 2542, mode: MaxEncodedLen) + /// Storage: Balances Locks (r:1 w:0) + /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) + fn unstake() -> Weight { + // Proof Size summary in bytes: + // Measured: `432` + // Estimated: `4764` + // Minimum execution time: 48_594_000 picoseconds. + Weight::from_parts(49_441_000, 4764) + .saturating_add(T::DbWeight::get().reads(7_u64)) + .saturating_add(T::DbWeight::get().writes(5_u64)) + } + /// Storage: DappStaking Ledger (r:1 w:1) + /// Proof: DappStaking Ledger (max_values: None, max_size: Some(310), added: 2785, mode: MaxEncodedLen) + /// Storage: DappStaking EraRewards (r:1 w:0) + /// Proof: DappStaking EraRewards (max_values: None, max_size: Some(789), added: 3264, mode: MaxEncodedLen) + /// Storage: DappStaking PeriodEnd (r:1 w:0) + /// Proof: DappStaking PeriodEnd (max_values: None, max_size: Some(48), added: 2523, mode: MaxEncodedLen) + /// Storage: Balances Freezes (r:1 w:1) + /// Proof: Balances Freezes (max_values: None, max_size: Some(67), added: 2542, mode: MaxEncodedLen) + /// Storage: Balances Locks (r:1 w:0) + /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) + /// The range of component `x` is `[1, 16]`. + fn claim_staker_rewards_past_period(x: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `541` + // Estimated: `4764` + // Minimum execution time: 52_182_000 picoseconds. + Weight::from_parts(50_073_700, 4764) + // Standard Error: 4_907 + .saturating_add(Weight::from_parts(3_301_788, 0).saturating_mul(x.into())) + .saturating_add(T::DbWeight::get().reads(5_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + } + /// Storage: DappStaking Ledger (r:1 w:1) + /// Proof: DappStaking Ledger (max_values: None, max_size: Some(310), added: 2785, mode: MaxEncodedLen) + /// Storage: DappStaking EraRewards (r:1 w:0) + /// Proof: DappStaking EraRewards (max_values: None, max_size: Some(789), added: 3264, mode: MaxEncodedLen) + /// Storage: Balances Freezes (r:1 w:1) + /// Proof: Balances Freezes (max_values: None, max_size: Some(67), added: 2542, mode: MaxEncodedLen) + /// Storage: Balances Locks (r:1 w:0) + /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) + /// The range of component `x` is `[1, 16]`. + fn claim_staker_rewards_ongoing_period(x: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `519` + // Estimated: `4764` + // Minimum execution time: 49_637_000 picoseconds. + Weight::from_parts(47_809_537, 4764) + // Standard Error: 5_850 + .saturating_add(Weight::from_parts(3_304_857, 0).saturating_mul(x.into())) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + } + /// Storage: DappStaking StakerInfo (r:1 w:1) + /// Proof: DappStaking StakerInfo (max_values: None, max_size: Some(138), added: 2613, mode: MaxEncodedLen) + /// Storage: DappStaking PeriodEnd (r:1 w:0) + /// Proof: DappStaking PeriodEnd (max_values: None, max_size: Some(48), added: 2523, mode: MaxEncodedLen) + /// Storage: DappStaking Ledger (r:1 w:1) + /// Proof: DappStaking Ledger (max_values: None, max_size: Some(310), added: 2785, mode: MaxEncodedLen) + fn claim_bonus_reward() -> Weight { + // Proof Size summary in bytes: + // Measured: `271` + // Estimated: `3775` + // Minimum execution time: 41_926_000 picoseconds. + Weight::from_parts(42_718_000, 3775) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + } + /// Storage: DappStaking IntegratedDApps (r:1 w:0) + /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(116), added: 2096, mode: MaxEncodedLen) + /// Storage: DappStaking DAppTiers (r:1 w:1) + /// Proof: DappStaking DAppTiers (max_values: None, max_size: Some(1583), added: 4058, mode: MaxEncodedLen) + fn claim_dapp_reward() -> Weight { + // Proof Size summary in bytes: + // Measured: `2584` + // Estimated: `5048` + // Minimum execution time: 57_183_000 picoseconds. + Weight::from_parts(58_197_000, 5048) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: DappStaking IntegratedDApps (r:1 w:0) + /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(116), added: 2096, mode: MaxEncodedLen) + /// Storage: DappStaking StakerInfo (r:1 w:1) + /// Proof: DappStaking StakerInfo (max_values: None, max_size: Some(138), added: 2613, mode: MaxEncodedLen) + /// Storage: DappStaking Ledger (r:1 w:1) + /// Proof: DappStaking Ledger (max_values: None, max_size: Some(310), added: 2785, mode: MaxEncodedLen) + /// Storage: DappStaking CurrentEraInfo (r:1 w:1) + /// Proof: DappStaking CurrentEraInfo (max_values: Some(1), max_size: Some(112), added: 607, mode: MaxEncodedLen) + /// Storage: Balances Freezes (r:1 w:1) + /// Proof: Balances Freezes (max_values: None, max_size: Some(67), added: 2542, mode: MaxEncodedLen) + /// Storage: Balances Locks (r:1 w:0) + /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) + fn unstake_from_unregistered() -> Weight { + // Proof Size summary in bytes: + // Measured: `318` + // Estimated: `4764` + // Minimum execution time: 41_858_000 picoseconds. + Weight::from_parts(42_476_000, 4764) + .saturating_add(T::DbWeight::get().reads(6_u64)) + .saturating_add(T::DbWeight::get().writes(4_u64)) + } + /// Storage: DappStaking StakerInfo (r:17 w:16) + /// Proof: DappStaking StakerInfo (max_values: None, max_size: Some(138), added: 2613, mode: MaxEncodedLen) + /// Storage: DappStaking Ledger (r:1 w:1) + /// Proof: DappStaking Ledger (max_values: None, max_size: Some(310), added: 2785, mode: MaxEncodedLen) + /// Storage: Balances Freezes (r:1 w:1) + /// Proof: Balances Freezes (max_values: None, max_size: Some(67), added: 2542, mode: MaxEncodedLen) + /// Storage: Balances Locks (r:1 w:0) + /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) + /// The range of component `x` is `[1, 16]`. + fn cleanup_expired_entries(x: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `256 + x * (69 ±0)` + // Estimated: `4764 + x * (2613 ±0)` + // Minimum execution time: 43_103_000 picoseconds. + Weight::from_parts(39_876_215, 4764) + // Standard Error: 8_123 + .saturating_add(Weight::from_parts(5_014_232, 0).saturating_mul(x.into())) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(x.into()))) + .saturating_add(T::DbWeight::get().writes(2_u64)) + .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(x.into()))) + .saturating_add(Weight::from_parts(0, 2613).saturating_mul(x.into())) + } + fn force() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 11_543_000 picoseconds. + Weight::from_parts(11_735_000, 0) + } + /// Storage: DappStaking CurrentEraInfo (r:1 w:1) + /// Proof: DappStaking CurrentEraInfo (max_values: Some(1), max_size: Some(112), added: 607, mode: MaxEncodedLen) + /// Storage: DappStaking EraRewards (r:1 w:1) + /// Proof: DappStaking EraRewards (max_values: None, max_size: Some(789), added: 3264, mode: MaxEncodedLen) + fn on_initialize_voting_to_build_and_earn() -> Weight { + // Proof Size summary in bytes: + // Measured: `16` + // Estimated: `4254` + // Minimum execution time: 17_687_000 picoseconds. + Weight::from_parts(18_283_000, 4254) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + } + /// Storage: DappStaking CurrentEraInfo (r:1 w:1) + /// Proof: DappStaking CurrentEraInfo (max_values: Some(1), max_size: Some(112), added: 607, mode: MaxEncodedLen) + /// Storage: DappStaking StaticTierParams (r:1 w:0) + /// Proof: DappStaking StaticTierParams (max_values: Some(1), max_size: Some(167), added: 662, mode: MaxEncodedLen) + /// Storage: DappStaking TierConfig (r:1 w:1) + /// Proof: DappStaking TierConfig (max_values: Some(1), max_size: Some(161), added: 656, mode: MaxEncodedLen) + /// Storage: DappStaking PeriodEnd (r:1 w:2) + /// Proof: DappStaking PeriodEnd (max_values: None, max_size: Some(48), added: 2523, mode: MaxEncodedLen) + /// Storage: DappStaking HistoryCleanupMarker (r:1 w:1) + /// Proof: DappStaking HistoryCleanupMarker (max_values: Some(1), max_size: Some(12), added: 507, mode: MaxEncodedLen) + /// Storage: DappStaking EraRewards (r:1 w:1) + /// Proof: DappStaking EraRewards (max_values: None, max_size: Some(789), added: 3264, mode: MaxEncodedLen) + /// Storage: DappStaking DAppTiers (r:0 w:1) + /// Proof: DappStaking DAppTiers (max_values: None, max_size: Some(1583), added: 4058, mode: MaxEncodedLen) + fn on_initialize_build_and_earn_to_voting() -> Weight { + // Proof Size summary in bytes: + // Measured: `839` + // Estimated: `4254` + // Minimum execution time: 47_901_000 picoseconds. + Weight::from_parts(49_554_000, 4254) + .saturating_add(T::DbWeight::get().reads(6_u64)) + .saturating_add(T::DbWeight::get().writes(7_u64)) + } + /// Storage: DappStaking CurrentEraInfo (r:1 w:1) + /// Proof: DappStaking CurrentEraInfo (max_values: Some(1), max_size: Some(112), added: 607, mode: MaxEncodedLen) + /// Storage: DappStaking EraRewards (r:1 w:1) + /// Proof: DappStaking EraRewards (max_values: None, max_size: Some(789), added: 3264, mode: MaxEncodedLen) + /// Storage: DappStaking DAppTiers (r:0 w:1) + /// Proof: DappStaking DAppTiers (max_values: None, max_size: Some(1583), added: 4058, mode: MaxEncodedLen) + fn on_initialize_build_and_earn_to_build_and_earn() -> Weight { + // Proof Size summary in bytes: + // Measured: `68` + // Estimated: `4254` + // Minimum execution time: 23_705_000 picoseconds. + Weight::from_parts(24_313_000, 4254) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) + } + /// Storage: DappStaking ContractStake (r:101 w:0) + /// Proof: DappStaking ContractStake (max_values: Some(65535), max_size: Some(91), added: 2071, mode: MaxEncodedLen) + /// Storage: DappStaking TierConfig (r:1 w:0) + /// Proof: DappStaking TierConfig (max_values: Some(1), max_size: Some(161), added: 656, mode: MaxEncodedLen) + /// The range of component `x` is `[0, 100]`. + fn dapp_tier_assignment(x: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `152 + x * (32 ±0)` + // Estimated: `3061 + x * (2071 ±0)` + // Minimum execution time: 7_549_000 picoseconds. + Weight::from_parts(12_476_634, 3061) + // Standard Error: 3_594 + .saturating_add(Weight::from_parts(2_387_577, 0).saturating_mul(x.into())) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(x.into()))) + .saturating_add(Weight::from_parts(0, 2071).saturating_mul(x.into())) + } + /// Storage: DappStaking HistoryCleanupMarker (r:1 w:1) + /// Proof: DappStaking HistoryCleanupMarker (max_values: Some(1), max_size: Some(12), added: 507, mode: MaxEncodedLen) + /// Storage: DappStaking EraRewards (r:1 w:1) + /// Proof: DappStaking EraRewards (max_values: None, max_size: Some(789), added: 3264, mode: MaxEncodedLen) + /// Storage: DappStaking DAppTiers (r:0 w:1) + /// Proof: DappStaking DAppTiers (max_values: None, max_size: Some(1583), added: 4058, mode: MaxEncodedLen) + fn on_idle_cleanup() -> Weight { + // Proof Size summary in bytes: + // Measured: `293` + // Estimated: `4254` + // Minimum execution time: 8_529_000 picoseconds. + Weight::from_parts(8_772_000, 4254) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) + } +} diff --git a/runtime/astar/src/weights/pallet_inflation.rs b/runtime/astar/src/weights/pallet_inflation.rs new file mode 100644 index 0000000000..beaa686a86 --- /dev/null +++ b/runtime/astar/src/weights/pallet_inflation.rs @@ -0,0 +1,102 @@ + +// This file is part of Astar. + +// Copyright (C) 2019-2023 Stake Technologies Pte.Ltd. +// SPDX-License-Identifier: GPL-3.0-or-later + +// Astar is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Astar is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Astar. If not, see <http://www.gnu.org/licenses/>. + +//! Autogenerated weights for pallet_inflation +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2024-02-04, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `gh-runner-01-ovh`, CPU: `Intel(R) Xeon(R) E-2236 CPU @ 3.40GHz` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("shiden-dev"), DB CACHE: 1024 + +// Executed Command: +// ./target/release/astar-collator +// benchmark +// pallet +// --chain=shiden-dev +// --steps=50 +// --repeat=20 +// --pallet=pallet_inflation +// --extrinsic=* +// --execution=wasm +// --wasm-execution=compiled +// --heap-pages=4096 +// --output=./benchmark-results/shiden-dev/inflation_weights.rs +// --template=./scripts/templates/weight-template.hbs + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] + +use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; +use core::marker::PhantomData; +use pallet_inflation::WeightInfo; + +/// Weights for pallet_inflation using the Substrate node and recommended hardware. +pub struct SubstrateWeight<T>(PhantomData<T>); +impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { + /// Storage: Inflation InflationParams (r:0 w:1) + /// Proof: Inflation InflationParams (max_values: Some(1), max_size: Some(64), added: 559, mode: MaxEncodedLen) + fn force_set_inflation_params() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 9_034_000 picoseconds. + Weight::from_parts(9_303_000, 0) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + fn force_set_inflation_config() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 9_559_000 picoseconds. + Weight::from_parts(9_789_000, 0) + } + /// Storage: Inflation InflationParams (r:1 w:0) + /// Proof: Inflation InflationParams (max_values: Some(1), max_size: Some(64), added: 559, mode: MaxEncodedLen) + fn force_inflation_recalculation() -> Weight { + // Proof Size summary in bytes: + // Measured: `40` + // Estimated: `1549` + // Minimum execution time: 13_548_000 picoseconds. + Weight::from_parts(13_796_000, 1549) + .saturating_add(T::DbWeight::get().reads(1_u64)) + } + /// Storage: Inflation InflationParams (r:1 w:0) + /// Proof: Inflation InflationParams (max_values: Some(1), max_size: Some(64), added: 559, mode: MaxEncodedLen) + fn recalculation() -> Weight { + // Proof Size summary in bytes: + // Measured: `58` + // Estimated: `1549` + // Minimum execution time: 13_421_000 picoseconds. + Weight::from_parts(13_808_000, 1549) + .saturating_add(T::DbWeight::get().reads(1_u64)) + } + /// Storage: System Account (r:2 w:2) + /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) + fn hooks_without_recalculation() -> Weight { + // Proof Size summary in bytes: + // Measured: `39` + // Estimated: `6196` + // Minimum execution time: 40_566_000 picoseconds. + Weight::from_parts(40_980_000, 6196) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + } +} diff --git a/tests/integration/src/dispatch_precompile_filter_new.rs b/tests/integration/src/dispatch_precompile_filter.rs similarity index 100% rename from tests/integration/src/dispatch_precompile_filter_new.rs rename to tests/integration/src/dispatch_precompile_filter.rs diff --git a/tests/integration/src/dispatch_precompile_filter_old.rs b/tests/integration/src/dispatch_precompile_filter_old.rs deleted file mode 100644 index 95d04bcfba..0000000000 --- a/tests/integration/src/dispatch_precompile_filter_old.rs +++ /dev/null @@ -1,221 +0,0 @@ -// This file is part of Astar. - -// Copyright (C) 2019-2023 Stake Technologies Pte.Ltd. -// SPDX-License-Identifier: GPL-3.0-or-later - -// Astar is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Astar is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Astar. If not, see <http://www.gnu.org/licenses/>. -#![cfg(test)] - -use crate::setup::*; -use astar_primitives::precompiles::DispatchFilterValidate; -use fp_evm::{ExitError, PrecompileFailure}; -use frame_support::{ - dispatch::{DispatchClass, DispatchInfo, GetDispatchInfo, Pays}, - traits::Contains, -}; -use pallet_evm_precompile_dispatch::DispatchValidateT; -use parity_scale_codec::Compact; - -/// Whitelisted Calls are defined in the runtime -#[test] -fn filter_accepts_batch_call_with_whitelisted_calls() { - ExtBuilder::default().build().execute_with(|| { - let contract = SmartContract::Evm(H160::repeat_byte(0x01)); - let inner_call = RuntimeCall::DappsStaking(DappsStakingCall::Call::claim_staker { - contract_id: contract.clone(), - }); - let call = RuntimeCall::Utility(UtilityCall::batch { - calls: vec![inner_call], - }); - assert!(WhitelistedCalls::contains(&call)); - }); -} - -#[test] -fn filter_rejects_non_whitelisted_batch_calls() { - ExtBuilder::default().build().execute_with(|| { - // CASE1 - only non whitelisted calls - let transfer_call = RuntimeCall::Balances(BalancesCall::transfer { - dest: MultiAddress::Id(CAT), - value: 100_000_000_000, - }); - let transfer = Box::new(transfer_call); - let call = Box::new(RuntimeCall::Utility(UtilityCall::batch { - calls: vec![*transfer.clone()], - })); - - // Utility call containing Balances Call - assert!(!WhitelistedCalls::contains(&call)); - - // CASE 2 - now whitelisted mixed with whitelisted calls - - let contract = SmartContract::Evm(H160::repeat_byte(0x01)); - let staking_call = RuntimeCall::DappsStaking(DappsStakingCall::Call::claim_staker { - contract_id: contract.clone(), - }); - let staking = Box::new(staking_call); - - let call = Box::new(RuntimeCall::Utility(UtilityCall::batch { - calls: vec![*transfer, *staking.clone()], - })); - - // Utility call containing Balances Call and Dappsstaking Call Fails filter - assert!(!WhitelistedCalls::contains(&call)); - }); -} - -#[test] -fn filter_accepts_whitelisted_calls() { - ExtBuilder::default().build().execute_with(|| { - // Dappstaking call works - let contract = SmartContract::Evm(H160::repeat_byte(0x01)); - let stake_call = RuntimeCall::DappsStaking(DappsStakingCall::Call::claim_staker { - contract_id: contract.clone(), - }); - assert!(WhitelistedCalls::contains(&stake_call)); - - // Pallet::Assets transfer call works - let transfer_call = RuntimeCall::Assets(pallet_assets::Call::transfer { - id: Compact(0), - target: MultiAddress::Address20(H160::repeat_byte(0x01).into()), - amount: 100, - }); - assert!(WhitelistedCalls::contains(&transfer_call)); - }); -} - -#[test] -fn filter_rejects_non_whitelisted_calls() { - ExtBuilder::default().build().execute_with(|| { - // Random call from non whitelisted pallet doesn't work - let transfer_call = RuntimeCall::Balances(BalancesCall::transfer { - dest: MultiAddress::Id(CAT), - value: 100_000_000_000, - }); - assert!(!WhitelistedCalls::contains(&transfer_call)); - - // Only `transfer` call from pallet assets work - // Other random call from Pallet Assets doesn't work - let thaw_asset_call = - RuntimeCall::Assets(pallet_assets::Call::thaw_asset { id: Compact(0) }); - assert!(!WhitelistedCalls::contains(&thaw_asset_call)); - }) -} - -#[test] -fn filter_accepts_whitelisted_batch_all_calls() { - ExtBuilder::default().build().execute_with(|| { - let contract = SmartContract::Evm(H160::repeat_byte(0x01)); - let inner_call1 = RuntimeCall::DappsStaking(DappsStakingCall::Call::claim_staker { - contract_id: contract.clone(), - }); - let inner_call2 = RuntimeCall::DappsStaking(DappsStakingCall::Call::claim_staker { - contract_id: contract.clone(), - }); - let transfer_call = RuntimeCall::Assets(pallet_assets::Call::transfer { - id: Compact(0), - target: MultiAddress::Address20(H160::repeat_byte(0x01).into()), - amount: 100, - }); - let call = RuntimeCall::Utility(UtilityCall::batch_all { - calls: vec![inner_call1, inner_call2, transfer_call], - }); - assert!(WhitelistedCalls::contains(&call)); - }); -} - -#[test] -fn test_correct_dispatch_info_works() { - ExtBuilder::default().build().execute_with(|| { - // Mock implementation - struct Filter; - struct AccountId; - enum RuntimeCall { - System, - DappsStaking, - } - impl GetDispatchInfo for RuntimeCall { - fn get_dispatch_info(&self) -> DispatchInfo { - // Default is Pays::Yes and DispatchCall::Normal - DispatchInfo::default() - } - } - impl Contains<RuntimeCall> for Filter { - fn contains(t: &RuntimeCall) -> bool { - match t { - RuntimeCall::DappsStaking => true, - _ => false, - } - } - } - // Case 1: Whitelisted Call with correct Dispatch info - assert_eq!( - DispatchFilterValidate::<RuntimeCall, Filter>::validate_before_dispatch( - &AccountId, - &RuntimeCall::DappsStaking - ), - Option::None - ); - // Case 2: Non-Whitelisted Call with correct Dispatch Info - assert_eq!( - DispatchFilterValidate::<RuntimeCall, Filter>::validate_before_dispatch( - &AccountId, - &RuntimeCall::System - ), - Option::Some(PrecompileFailure::Error { - exit_status: ExitError::Other("call filtered out".into()), - }) - ); - }); -} - -#[test] -fn test_incorrect_dispatch_info_fails() { - ExtBuilder::default().build().execute_with(|| { - // Mock implementation - struct Filter; - struct AccountId; - enum RuntimeCall { - DappsStaking, - } - impl GetDispatchInfo for RuntimeCall { - fn get_dispatch_info(&self) -> DispatchInfo { - DispatchInfo { - weight: Weight::default(), - class: DispatchClass::Normal, - // Should have been Pays::Yes for call to pass - pays_fee: Pays::No, - } - } - } - impl Contains<RuntimeCall> for Filter { - fn contains(t: &RuntimeCall) -> bool { - match t { - RuntimeCall::DappsStaking => true, - } - } - } - - // WhiteListed Call fails because of incorrect DispatchInfo - assert_eq!( - DispatchFilterValidate::<RuntimeCall, Filter>::validate_before_dispatch( - &AccountId, - &RuntimeCall::DappsStaking - ), - Option::Some(PrecompileFailure::Error { - exit_status: ExitError::Other("invalid call".into()), - }) - ); - }) -} diff --git a/tests/integration/src/lib.rs b/tests/integration/src/lib.rs index 7f12e9903d..8693ee2c63 100644 --- a/tests/integration/src/lib.rs +++ b/tests/integration/src/lib.rs @@ -23,12 +23,8 @@ #[cfg(any(feature = "shibuya", feature = "shiden", feature = "astar"))] mod setup; -#[cfg(any(feature = "shibuya", feature = "shiden"))] -mod proxy_new; - -// Remove this once dApp staking v3 is integrated into Shiden & Astar -#[cfg(any(feature = "astar"))] -mod proxy_old; +#[cfg(any(feature = "shibuya", feature = "shiden", feature = "astar"))] +mod proxy; #[cfg(any(feature = "shibuya", feature = "shiden", feature = "astar"))] mod assets; @@ -36,17 +32,13 @@ mod assets; #[cfg(feature = "shibuya")] mod xvm; -#[cfg(any(feature = "shibuya", feature = "shiden"))] -mod dispatch_precompile_filter_new; - -// Remove this once dApp staking v3 is integrated into Shiden & Astar -#[cfg(any(feature = "astar"))] -mod dispatch_precompile_filter_old; +#[cfg(any(feature = "shibuya", feature = "shiden", feature = "astar"))] +mod dispatch_precompile_filter; #[cfg(feature = "shibuya")] mod unified_accounts; -#[cfg(any(feature = "shibuya", feature = "shiden"))] +#[cfg(any(feature = "shibuya", feature = "shiden", feature = "astar"))] mod dapp_staking_v3; #[cfg(any(feature = "shibuya"))] diff --git a/tests/integration/src/proxy_new.rs b/tests/integration/src/proxy.rs similarity index 100% rename from tests/integration/src/proxy_new.rs rename to tests/integration/src/proxy.rs diff --git a/tests/integration/src/proxy_old.rs b/tests/integration/src/proxy_old.rs deleted file mode 100644 index d6d9479a82..0000000000 --- a/tests/integration/src/proxy_old.rs +++ /dev/null @@ -1,213 +0,0 @@ -// This file is part of Astar. - -// Copyright (C) 2019-2023 Stake Technologies Pte.Ltd. -// SPDX-License-Identifier: GPL-3.0-or-later - -// Astar is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Astar is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Astar. If not, see <http://www.gnu.org/licenses/>. - -use crate::setup::*; - -#[test] -fn test_utility_call_pass_for_any() { - new_test_ext().execute_with(|| { - // Any proxy should be allowed to make balance transfer call - assert_ok!(Proxy::add_proxy( - RuntimeOrigin::signed(ALICE), - MultiAddress::Id(BOB), - ProxyType::Any, - 0 - )); - - // Preparing Utility call - let transfer_call = RuntimeCall::Balances(BalancesCall::transfer { - dest: MultiAddress::Id(CAT), - value: 100_000_000_000, - }); - let inner = Box::new(transfer_call); - let call = Box::new(RuntimeCall::Utility(UtilityCall::batch { - calls: vec![*inner], - })); - - // Utility call passed through filter - assert_ok!(Proxy::proxy( - RuntimeOrigin::signed(BOB), - MultiAddress::Id(ALICE), - None, - call.clone() - )); - expect_events(vec![ - UtilityEvent::BatchCompleted.into(), - ProxyEvent::ProxyExecuted { result: Ok(()) }.into(), - ]); - }); -} - -#[test] -fn test_utility_call_pass_for_balances() { - new_test_ext().execute_with(|| { - // Balances proxy should be allowed to make balance transfer call - assert_ok!(Proxy::add_proxy( - RuntimeOrigin::signed(ALICE), - MultiAddress::Id(BOB), - ProxyType::Balances, - 0 - )); - - // Preparing Utility call - let transfer_call = RuntimeCall::Balances(BalancesCall::transfer { - dest: MultiAddress::Id(CAT), - value: 100_000_000_000, - }); - let inner = Box::new(transfer_call); - let call = Box::new(RuntimeCall::Utility(UtilityCall::batch { - calls: vec![*inner], - })); - - // Utility call passed through filter - assert_ok!(Proxy::proxy( - RuntimeOrigin::signed(BOB), - MultiAddress::Id(ALICE), - None, - call.clone() - )); - expect_events(vec![ - UtilityEvent::BatchCompleted.into(), - ProxyEvent::ProxyExecuted { result: Ok(()) }.into(), - ]); - }); -} - -#[test] -fn test_utility_call_fail_non_transfer() { - new_test_ext().execute_with(|| { - // NonTransfer proxy shouldn't be allowed to make balance transfer call - assert_ok!(Proxy::add_proxy( - RuntimeOrigin::signed(ALICE), - MultiAddress::Id(BOB), - ProxyType::NonTransfer, - 0 - )); - - // Preparing Utility call - let transfer_call = RuntimeCall::Balances(BalancesCall::transfer { - dest: MultiAddress::Id(CAT), - value: 100_000_000_000, - }); - let inner = Box::new(transfer_call); - let call = Box::new(RuntimeCall::Utility(UtilityCall::batch { - calls: vec![*inner], - })); - - assert_ok!(Proxy::proxy( - RuntimeOrigin::signed(BOB), - MultiAddress::Id(ALICE), - None, - call.clone() - )); - - // Utility call filtered out - expect_events(vec![ - UtilityEvent::BatchInterrupted { - index: 0, - error: SystemError::CallFiltered.into(), - } - .into(), - ProxyEvent::ProxyExecuted { result: Ok(()) }.into(), - ]); - }); -} - -#[test] -fn test_utility_call_fail_for_dappstaking() { - new_test_ext().execute_with(|| { - // Dappstaking proxy shouldn't be allowed to make balance transfer call - assert_ok!(Proxy::add_proxy( - RuntimeOrigin::signed(ALICE), - MultiAddress::Id(BOB), - ProxyType::DappsStaking, - 0 - )); - - // Preparing Utility call - let transfer_call = RuntimeCall::Balances(BalancesCall::transfer { - dest: MultiAddress::Id(CAT), - value: 100_000_000_000, - }); - let inner = Box::new(transfer_call); - let call = Box::new(RuntimeCall::Utility(UtilityCall::batch { - calls: vec![*inner], - })); - - assert_ok!(Proxy::proxy( - RuntimeOrigin::signed(BOB), - MultiAddress::Id(ALICE), - None, - call.clone() - )); - // Utility call filtered out - expect_events(vec![ - UtilityEvent::BatchInterrupted { - index: 0, - error: SystemError::CallFiltered.into(), - } - .into(), - ProxyEvent::ProxyExecuted { result: Ok(()) }.into(), - ]); - }); -} - -#[test] -fn test_staker_reward_claim_proxy_works() { - new_test_ext().execute_with(|| { - // Make CAT delegate for StakerRewardClaim proxy - assert_ok!(Proxy::add_proxy( - RuntimeOrigin::signed(BOB), - MultiAddress::Id(CAT), - ProxyType::StakerRewardClaim, - 0 - )); - - let contract = SmartContract::Evm(H160::repeat_byte(0x01)); - let staker_reward_claim_call = - RuntimeCall::DappsStaking(DappsStakingCall::Call::claim_staker { - contract_id: contract.clone(), - }); - let call = Box::new(staker_reward_claim_call); - - // contract must be registered - assert_ok!(DappsStaking::register( - RuntimeOrigin::root(), - ALICE.clone(), - contract.clone() - )); - - // some amount must be staked - assert_ok!(DappsStaking::bond_and_stake( - RuntimeOrigin::signed(BOB), - contract.clone(), - 600 * UNIT - )); - run_to_block(10); - - // CAT making proxy call on behalf of staker (BOB) - assert_ok!(Proxy::proxy( - RuntimeOrigin::signed(CAT), - MultiAddress::Id(BOB), - None, - call.clone() - )); - - expect_events(vec![ProxyEvent::ProxyExecuted { result: Ok(()) }.into()]); - }) -} diff --git a/tests/integration/src/setup.rs b/tests/integration/src/setup.rs index 2bca834b28..c217da98de 100644 --- a/tests/integration/src/setup.rs +++ b/tests/integration/src/setup.rs @@ -191,7 +191,6 @@ impl ExtBuilder { .assimilate_storage(&mut t) .unwrap(); - #[cfg(any(feature = "shibuya", feature = "shiden"))] // Needed to trigger initial inflation config setting. <pallet_inflation::GenesisConfig as GenesisBuild<Runtime>>::assimilate_storage( &pallet_inflation::GenesisConfig::default(), @@ -222,10 +221,7 @@ pub fn run_to_block(n: BlockNumber) { while System::block_number() < n { let block_number = System::block_number(); TransactionPayment::on_finalize(block_number); - #[cfg(any(feature = "shibuya", feature = "shiden"))] DappStaking::on_finalize(block_number); - #[cfg(any(feature = "astar"))] - DappsStaking::on_finalize(block_number); Authorship::on_finalize(block_number); Session::on_finalize(block_number); AuraExt::on_finalize(block_number); @@ -233,20 +229,15 @@ pub fn run_to_block(n: BlockNumber) { Ethereum::on_finalize(block_number); CollatorSelection::on_finalize(block_number); DynamicEvmBaseFee::on_finalize(block_number); - #[cfg(any(feature = "shibuya", feature = "shiden"))] Inflation::on_finalize(block_number); System::set_block_number(block_number + 1); let block_number = System::block_number(); - #[cfg(any(feature = "shibuya", feature = "shiden"))] Inflation::on_initialize(block_number); Timestamp::set_timestamp(block_number as u64 * BLOCK_TIME); TransactionPayment::on_initialize(block_number); - #[cfg(any(feature = "shibuya", feature = "shiden"))] DappStaking::on_initialize(block_number); - #[cfg(any(feature = "astar"))] - DappsStaking::on_initialize(block_number); Authorship::on_initialize(block_number); Aura::on_initialize(block_number); AuraExt::on_initialize(block_number); From fe2f92178a30ed006d3f2818c81adaa66b50b287 Mon Sep 17 00:00:00 2001 From: Dino Pacandi <dino.pacandi@gmail.com> Date: Wed, 7 Feb 2024 10:28:43 +0100 Subject: [PATCH 02/14] Shiden cleanup --- Cargo.lock | 2 - runtime/astar/src/xcm_config.rs | 2 +- runtime/shiden/Cargo.toml | 6 -- runtime/shiden/src/lib.rs | 176 ++----------------------------- runtime/shiden/src/xcm_config.rs | 2 +- 5 files changed, 10 insertions(+), 178 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 06808a258e..73f91819fd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13347,7 +13347,6 @@ dependencies = [ "pallet-contracts-primitives", "pallet-dapp-staking-migration", "pallet-dapp-staking-v3", - "pallet-dapps-staking", "pallet-dynamic-evm-base-fee", "pallet-ethereum", "pallet-evm", @@ -13387,7 +13386,6 @@ dependencies = [ "scale-info", "smallvec 1.11.0", "sp-api", - "sp-arithmetic", "sp-block-builder", "sp-consensus-aura", "sp-core", diff --git a/runtime/astar/src/xcm_config.rs b/runtime/astar/src/xcm_config.rs index 8cc1ba9c06..53d8723600 100644 --- a/runtime/astar/src/xcm_config.rs +++ b/runtime/astar/src/xcm_config.rs @@ -162,7 +162,7 @@ impl SafeCallFilter { | RuntimeCall::Identity(..) | RuntimeCall::Balances(..) | RuntimeCall::Vesting(..) - | RuntimeCall::DappsStaking(..) + | RuntimeCall::DappStaking(..) | RuntimeCall::Assets(..) | RuntimeCall::PolkadotXcm(..) | RuntimeCall::Session(..) diff --git a/runtime/shiden/Cargo.toml b/runtime/shiden/Cargo.toml index 9a2a4d850e..426da87482 100644 --- a/runtime/shiden/Cargo.toml +++ b/runtime/shiden/Cargo.toml @@ -21,7 +21,6 @@ fp-rpc = { workspace = true } fp-self-contained = { workspace = true } sp-api = { workspace = true } -sp-arithmetic = { workspace = true } sp-block-builder = { workspace = true } sp-consensus-aura = { workspace = true } sp-core = { workspace = true } @@ -105,7 +104,6 @@ astar-primitives = { workspace = true } pallet-collator-selection = { workspace = true } pallet-dapp-staking-migration = { workspace = true } pallet-dapp-staking-v3 = { workspace = true } -pallet-dapps-staking = { workspace = true } pallet-evm-precompile-assets-erc20 = { workspace = true } pallet-evm-precompile-dapp-staking-v3 = { workspace = true } pallet-evm-precompile-sr25519 = { workspace = true } @@ -138,7 +136,6 @@ std = [ "sp-api/std", "sp-core/std", "sp-consensus-aura/std", - "sp-arithmetic/std", "sp-io/std", "sp-runtime/std", "pallet-static-price-provider/std", @@ -168,7 +165,6 @@ std = [ "pallet-evm-precompile-ed25519/std", "pallet-evm-precompile-modexp/std", "pallet-evm-precompile-sha3fips/std", - "pallet-dapps-staking/std", "pallet-dapp-staking-v3/std", "pallet-dapp-staking-migration/std", "dapp-staking-v3-runtime-api/std", @@ -226,7 +222,6 @@ runtime-benchmarks = [ "frame-system/runtime-benchmarks", "sp-runtime/runtime-benchmarks", "pallet-balances/runtime-benchmarks", - "pallet-dapps-staking/runtime-benchmarks", "pallet-dapp-staking-v3/runtime-benchmarks", "pallet-dapp-staking-migration/runtime-benchmarks", "pallet-inflation/runtime-benchmarks", @@ -253,7 +248,6 @@ try-runtime = [ "pallet-dapp-staking-v3/try-runtime", "pallet-dapp-staking-migration/try-runtime", "pallet-inflation/try-runtime", - "pallet-dapps-staking/try-runtime", "pallet-sudo/try-runtime", "pallet-timestamp/try-runtime", "pallet-transaction-payment/try-runtime", diff --git a/runtime/shiden/src/lib.rs b/runtime/shiden/src/lib.rs index ed4f714f26..0711b26367 100644 --- a/runtime/shiden/src/lib.rs +++ b/runtime/shiden/src/lib.rs @@ -28,7 +28,7 @@ use frame_support::{ dispatch::DispatchClass, parameter_types, traits::{ - AsEnsureOriginWithArg, ConstU128, ConstU32, Contains, Currency, FindAuthor, Get, Imbalance, + AsEnsureOriginWithArg, ConstU32, Contains, Currency, FindAuthor, Get, Imbalance, InstanceFilter, Nothing, OnFinalize, OnUnbalanced, WithdrawReasons, }, weights::{ @@ -323,41 +323,6 @@ impl pallet_multisig::Config for Runtime { type WeightInfo = pallet_multisig::weights::SubstrateWeight<Runtime>; } -parameter_types! { - pub const BlockPerEra: BlockNumber = DAYS; - pub const RegisterDeposit: Balance = 100 * SDN; - pub const MaxNumberOfStakersPerContract: u32 = 1024; - pub const MinimumStakingAmount: Balance = 50 * SDN; - pub const MinimumRemainingAmount: Balance = SDN; - pub const MaxUnlockingChunks: u32 = 5; - pub const UnbondingPeriod: u32 = 5; - pub const MaxEraStakeValues: u32 = 5; -} - -impl pallet_dapps_staking::Config for Runtime { - type Currency = Balances; - type BlockPerEra = BlockPerEra; - type SmartContract = SmartContract<AccountId>; - type RegisterDeposit = RegisterDeposit; - type RuntimeEvent = RuntimeEvent; - type WeightInfo = pallet_dapps_staking::weights::SubstrateWeight<Runtime>; - type MaxNumberOfStakersPerContract = MaxNumberOfStakersPerContract; - type MinimumStakingAmount = MinimumStakingAmount; - type PalletId = DappsStakingPalletId; - type MinimumRemainingAmount = MinimumRemainingAmount; - type MaxUnlockingChunks = MaxUnlockingChunks; - type UnbondingPeriod = UnbondingPeriod; - type MaxEraStakeValues = MaxEraStakeValues; - type UnregisteredDappRewardRetention = ConstU32<7>; - // Needed so benchmark can use the pallets extrinsics - #[cfg(feature = "runtime-benchmarks")] - type ForcePalletDisabled = ConstBool<false>; - #[cfg(not(feature = "runtime-benchmarks"))] - type ForcePalletDisabled = ConstBool<true>; - // Fee required to claim rewards for another account. Calculated & tested manually. - type DelegateClaimFee = ConstU128<000_579_268_481_141_871>; -} - impl pallet_static_price_provider::Config for Runtime { type RuntimeEvent = RuntimeEvent; } @@ -390,6 +355,10 @@ impl DappStakingAccountCheck<AccountId> for AccountCheck { } } +parameter_types! { + pub const MinimumStakingAmount: Balance = 50 * SDN; +} + impl pallet_dapp_staking_v3::Config for Runtime { type RuntimeEvent = RuntimeEvent; type RuntimeFreezeReason = RuntimeFreezeReason; @@ -453,11 +422,6 @@ impl pallet_inflation::Config for Runtime { type WeightInfo = weights::pallet_inflation::SubstrateWeight<Runtime>; } -impl pallet_dapp_staking_migration::Config for Runtime { - type RuntimeEvent = RuntimeEvent; - type WeightInfo = pallet_dapp_staking_migration::weights::SubstrateWeight<Runtime>; -} - impl pallet_utility::Config for Runtime { type RuntimeEvent = RuntimeEvent; type RuntimeCall = RuntimeCall; @@ -554,7 +518,6 @@ impl pallet_collator_selection::Config for Runtime { parameter_types! { pub const TreasuryPalletId: PalletId = PalletId(*b"py/trsry"); - pub const DappsStakingPalletId: PalletId = PalletId(*b"py/dpsst"); pub TreasuryAccountId: AccountId = TreasuryPalletId::get().into_account_truncating(); } @@ -1094,10 +1057,6 @@ construct_runtime!( // To be removed & cleaned up once proper oracle is implemented StaticPriceProvider: pallet_static_price_provider = 253, - // To be removed & cleaned up after migration has been finished - DappStakingMigration: pallet_dapp_staking_migration = 254, - // Legacy dApps staking v2, to be removed after migration has been finished - DappsStaking: pallet_dapps_staking = 255, } ); @@ -1136,136 +1095,19 @@ pub type Executive = frame_executive::Executive< >; parameter_types! { - pub const BlockRewardName: &'static str = "BlockReward"; + pub const DappStakingMigrationName: &'static str = "DappStakingMigration"; } /// All migrations that will run on the next runtime upgrade. /// /// Once done, migrations should be removed from the tuple. pub type Migrations = ( - pallet_static_price_provider::InitActivePrice<Runtime, InitActivePriceGet>, - pallet_inflation::PalletInflationInitConfig<Runtime, InitInflationParamsHelper>, - pallet_dapp_staking_v3::migrations::DAppStakingV3InitConfig< - Runtime, - InitDappStakingV3Params, - InitActivePriceGet, - >, - // This will handle new pallet storage version setting & it will put the new pallet into maintenance mode. - // But it's most important for testing with try-runtime. - pallet_dapp_staking_migration::DappStakingMigrationHandler<Runtime>, + // Part of shiden-119 frame_support::migrations::RemovePallet< - BlockRewardName, + DappStakingMigrationName, <Runtime as frame_system::Config>::DbWeight, >, ); -use sp_arithmetic::fixed_point::FixedU64; -pub struct InitActivePriceGet; -impl Get<FixedU64> for InitActivePriceGet { - fn get() -> FixedU64 { - // Roughly the average price, taken from CoinMarketCap data. - FixedU64::from_rational(32, 100) - } -} - -/// Used to initialize inflation parameters for the runtime. -pub struct InitInflationParamsHelper; -impl Get<(pallet_inflation::InflationParameters, EraNumber, Weight)> for InitInflationParamsHelper { - fn get() -> (pallet_inflation::InflationParameters, EraNumber, Weight) { - ( - pallet_inflation::InflationParameters { - // Recalculation is done every two weeks, hence the small %. - max_inflation_rate: Perquintill::from_percent(7), - treasury_part: Perquintill::from_percent(5), - collators_part: Perquintill::from_rational(32_u64, 1000), - dapps_part: Perquintill::from_percent(13), - base_stakers_part: Perquintill::from_percent(10), - adjustable_stakers_part: Perquintill::from_rational(588_u64, 1000), - bonus_part: Perquintill::from_percent(10), - ideal_staking_rate: Perquintill::from_percent(50), - }, - pallet_dapps_staking::CurrentEra::<Runtime>::get().saturating_add(1), - <Runtime as frame_system::Config>::DbWeight::get().reads(1), - ) - } -} - -use frame_support::BoundedVec; -use pallet_dapp_staking_v3::{TierParameters, TiersConfiguration}; -type NumberOfTiers = <Runtime as pallet_dapp_staking_v3::Config>::NumberOfTiers; -/// Used to initialize dApp staking parameters for the runtime. -pub struct InitDappStakingV3Params; -impl - Get<( - EraNumber, - TierParameters<NumberOfTiers>, - TiersConfiguration<NumberOfTiers>, - )> for InitDappStakingV3Params -{ - fn get() -> ( - EraNumber, - TierParameters<NumberOfTiers>, - TiersConfiguration<NumberOfTiers>, - ) { - // 1. Prepare init values - - // Init era of dApp staking v3 should be the next era after dApp staking v2 - let init_era = pallet_dapps_staking::CurrentEra::<Runtime>::get().saturating_add(1); - - // Reward portions according to the Tokenomics 2.0 report - let reward_portion = BoundedVec::try_from(vec![ - Permill::from_percent(25), - Permill::from_percent(47), - Permill::from_percent(25), - Permill::from_percent(3), - ]) - .unwrap_or_default(); - - // Tier thresholds adjusted according to numbers observed on Shibuya - let tier_thresholds = BoundedVec::try_from(vec![ - TierThreshold::DynamicTvlAmount { - amount: SDN.saturating_mul(3_000_000), - minimum_amount: SDN.saturating_mul(2_000_000), - }, - TierThreshold::DynamicTvlAmount { - amount: SDN.saturating_mul(750_000), - minimum_amount: SDN.saturating_mul(500_000), - }, - TierThreshold::DynamicTvlAmount { - amount: SDN.saturating_mul(200_000), - minimum_amount: SDN.saturating_mul(150_000), - }, - TierThreshold::FixedTvlAmount { - amount: SDN.saturating_mul(50_000), - }, - ]) - .unwrap_or_default(); - - // 2. Tier params - let tier_params = - TierParameters::<<Runtime as pallet_dapp_staking_v3::Config>::NumberOfTiers> { - reward_portion: reward_portion.clone(), - slot_distribution: BoundedVec::try_from(vec![ - Permill::from_percent(5), - Permill::from_percent(20), - Permill::from_percent(30), - Permill::from_percent(45), - ]) - .unwrap_or_default(), - tier_thresholds: tier_thresholds.clone(), - }; - - // 3. Init tier config - let init_tier_config = TiersConfiguration { - number_of_slots: 100, - slots_per_tier: BoundedVec::try_from(vec![5, 20, 30, 45]).unwrap_or_default(), - reward_portion, - tier_thresholds, - }; - - (init_era, tier_params, init_tier_config) - } -} - type EventRecord = frame_system::EventRecord< <Runtime as frame_system::Config>::RuntimeEvent, <Runtime as frame_system::Config>::Hash, @@ -1341,10 +1183,8 @@ mod benches { [pallet_assets, Assets] [pallet_balances, Balances] [pallet_timestamp, Timestamp] - [pallet_dapps_staking, DappsStaking] [pallet_dapp_staking_v3, DappStaking] [pallet_inflation, Inflation] - [pallet_dapp_staking_migration, DappStakingMigration] [pallet_xc_asset_config, XcAssetConfig] [pallet_collator_selection, CollatorSelection] [pallet_xcm, PolkadotXcm] diff --git a/runtime/shiden/src/xcm_config.rs b/runtime/shiden/src/xcm_config.rs index b1c512c41f..a28758ec62 100644 --- a/runtime/shiden/src/xcm_config.rs +++ b/runtime/shiden/src/xcm_config.rs @@ -164,7 +164,7 @@ impl SafeCallFilter { | RuntimeCall::Identity(..) | RuntimeCall::Balances(..) | RuntimeCall::Vesting(..) - | RuntimeCall::DappsStaking(..) + | RuntimeCall::DappStaking(..) | RuntimeCall::Assets(..) | RuntimeCall::PolkadotXcm(..) | RuntimeCall::Session(..) From 875decfa05f9681081d14f4794bd55e6d4d100f9 Mon Sep 17 00:00:00 2001 From: Dino Pacandi <dino.pacandi@gmail.com> Date: Wed, 7 Feb 2024 10:32:56 +0100 Subject: [PATCH 03/14] chain spec update --- .../src/parachain/chain_spec/astar.rs | 53 ++++++++++++++----- 1 file changed, 39 insertions(+), 14 deletions(-) diff --git a/bin/collator/src/parachain/chain_spec/astar.rs b/bin/collator/src/parachain/chain_spec/astar.rs index cce4ef9514..fcecc45635 100644 --- a/bin/collator/src/parachain/chain_spec/astar.rs +++ b/bin/collator/src/parachain/chain_spec/astar.rs @@ -19,15 +19,16 @@ //! Astar chain specifications. use astar_runtime::{ - wasm_binary_unwrap, AccountId, AuraId, Balance, BlockRewardConfig, EVMConfig, - ParachainInfoConfig, Precompiles, RewardDistributionConfig, Signature, SystemConfig, ASTR, + wasm_binary_unwrap, AccountId, AuraId, Balance, DappStakingConfig, EVMConfig, InflationConfig, + InflationParameters, ParachainInfoConfig, Precompiles, Signature, SystemConfig, TierThreshold, + ASTR, }; use cumulus_primitives_core::ParaId; use sc_service::ChainType; use sp_core::{sr25519, Pair, Public}; use sp_runtime::{ traits::{IdentifyAccount, Verify}, - Perbill, + Permill, }; use super::{get_from_seed, Extensions}; @@ -110,17 +111,6 @@ fn make_genesis( }, parachain_info: ParachainInfoConfig { parachain_id }, balances: astar_runtime::BalancesConfig { balances }, - block_reward: BlockRewardConfig { - // Make sure sum is 100 - reward_config: RewardDistributionConfig { - treasury_percent: Perbill::from_percent(10), - base_staker_percent: Perbill::from_percent(20), - dapps_percent: Perbill::from_percent(20), - collators_percent: Perbill::from_percent(5), - adjustable_percent: Perbill::from_percent(45), - ideal_dapps_staking_tvl: Perbill::from_percent(40), - }, - }, vesting: astar_runtime::VestingConfig { vesting: vec![] }, session: astar_runtime::SessionConfig { keys: authorities @@ -159,6 +149,41 @@ fn make_genesis( assets: Default::default(), parachain_system: Default::default(), transaction_payment: Default::default(), + dapp_staking: DappStakingConfig { + reward_portion: vec![ + Permill::from_percent(40), + Permill::from_percent(30), + Permill::from_percent(20), + Permill::from_percent(10), + ], + slot_distribution: vec![ + Permill::from_percent(10), + Permill::from_percent(20), + Permill::from_percent(30), + Permill::from_percent(40), + ], + tier_thresholds: vec![ + TierThreshold::DynamicTvlAmount { + amount: 30000 * ASTR, + minimum_amount: 20000 * ASTR, + }, + TierThreshold::DynamicTvlAmount { + amount: 7500 * ASTR, + minimum_amount: 5000 * ASTR, + }, + TierThreshold::DynamicTvlAmount { + amount: 20000 * ASTR, + minimum_amount: 15000 * ASTR, + }, + TierThreshold::FixedTvlAmount { + amount: 5000 * ASTR, + }, + ], + slots_per_tier: vec![10, 20, 30, 40], + }, + inflation: InflationConfig { + params: InflationParameters::default(), + }, } } From 15809d44140dd58e3cff668a249af71d9977e79c Mon Sep 17 00:00:00 2001 From: Dino Pacandi <dino.pacandi@gmail.com> Date: Wed, 7 Feb 2024 14:13:37 +0100 Subject: [PATCH 04/14] Minor changes --- Cargo.lock | 2 +- pallets/dapp-staking-migration/src/lib.rs | 9 +++++++++ pallets/dapp-staking-v3/rpc/runtime-api/Cargo.toml | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 73f91819fd..dd3a755f9e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2465,7 +2465,7 @@ dependencies = [ [[package]] name = "dapp-staking-v3-runtime-api" -version = "0.0.1-alpha" +version = "0.1.0" dependencies = [ "astar-primitives", "sp-api", diff --git a/pallets/dapp-staking-migration/src/lib.rs b/pallets/dapp-staking-migration/src/lib.rs index 68dc8c0230..56c343dcfe 100644 --- a/pallets/dapp-staking-migration/src/lib.rs +++ b/pallets/dapp-staking-migration/src/lib.rs @@ -580,10 +580,13 @@ pub mod pallet { // Get the stakers and their active locked (staked) amount. + use sp_runtime::traits::Zero; + let mut total_locked = Balance::zero(); let min_lock_amount: Balance = <T as pallet_dapp_staking_v3::Config>::MinimumLockedAmount::get(); let stakers: Vec<_> = pallet_dapps_staking::Ledger::<T>::iter() .filter_map(|(staker, ledger)| { + total_locked.saturating_accrue(ledger.locked); if ledger.locked >= min_lock_amount { Some((staker, ledger.locked)) } else { @@ -592,6 +595,12 @@ pub mod pallet { }) .collect(); + log::info!( + target: LOG_TARGET, + "Total locked amount in the old pallet: {:?}.", + total_locked, + ); + log::info!( target: LOG_TARGET, "Out of {} stakers, {} have sufficient amount to lock.", diff --git a/pallets/dapp-staking-v3/rpc/runtime-api/Cargo.toml b/pallets/dapp-staking-v3/rpc/runtime-api/Cargo.toml index 244715aa13..37b20002ab 100644 --- a/pallets/dapp-staking-v3/rpc/runtime-api/Cargo.toml +++ b/pallets/dapp-staking-v3/rpc/runtime-api/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "dapp-staking-v3-runtime-api" -version = "0.0.1-alpha" +version = "0.1.0" description = "dApp Staking v3 runtime API" authors.workspace = true edition.workspace = true From 8b2013c2133b03559374519d2325f8053f53843f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dino=20Pa=C4=8Dandi?= <3002868+Dinonard@users.noreply.github.com> Date: Wed, 7 Feb 2024 15:21:51 +0100 Subject: [PATCH 05/14] Fix for incorrect eras per cycle function (#1166) --- pallets/inflation/src/tests.rs | 12 +++++++++--- primitives/src/dapp_staking.rs | 18 ++++++++++++++---- runtime/shiden/src/lib.rs | 19 +++++++++++++++++++ 3 files changed, 42 insertions(+), 7 deletions(-) diff --git a/pallets/inflation/src/tests.rs b/pallets/inflation/src/tests.rs index e7529c36a9..cea9a2c7c1 100644 --- a/pallets/inflation/src/tests.rs +++ b/pallets/inflation/src/tests.rs @@ -460,14 +460,20 @@ fn cycle_configuration_works() { ExternalityBuilder::build().execute_with(|| { type CycleConfig = <Test as Config>::CycleConfiguration; - let eras_per_period = CycleConfig::eras_per_voting_subperiod() - + CycleConfig::eras_per_build_and_earn_subperiod(); + let eras_per_period = CycleConfig::eras_per_build_and_earn_subperiod() + 1; assert_eq!(CycleConfig::eras_per_period(), eras_per_period); + let period_in_era_lengths = CycleConfig::eras_per_voting_subperiod() + + CycleConfig::eras_per_build_and_earn_subperiod(); + assert_eq!(CycleConfig::period_in_era_lengths(), period_in_era_lengths); + let eras_per_cycle = eras_per_period * CycleConfig::periods_per_cycle(); assert_eq!(CycleConfig::eras_per_cycle(), eras_per_cycle); - let blocks_per_cycle = eras_per_cycle * CycleConfig::blocks_per_era(); + let cycle_in_era_lengths = period_in_era_lengths * CycleConfig::periods_per_cycle(); + assert_eq!(CycleConfig::cycle_in_era_lengths(), cycle_in_era_lengths); + + let blocks_per_cycle = cycle_in_era_lengths * CycleConfig::blocks_per_era(); assert_eq!(CycleConfig::blocks_per_cycle(), blocks_per_cycle); let build_and_earn_eras_per_cycle = diff --git a/primitives/src/dapp_staking.rs b/primitives/src/dapp_staking.rs index 23638089a7..8042a2f4d5 100644 --- a/primitives/src/dapp_staking.rs +++ b/primitives/src/dapp_staking.rs @@ -62,24 +62,34 @@ pub trait CycleConfiguration { fn blocks_per_era() -> BlockNumber; /// For how many standard era lengths does the period last. - fn eras_per_period() -> EraNumber { + fn period_in_era_lengths() -> EraNumber { Self::eras_per_voting_subperiod().saturating_add(Self::eras_per_build_and_earn_subperiod()) } /// For how many standard era lengths does the cycle (a 'year') last. - fn eras_per_cycle() -> EraNumber { - Self::eras_per_period().saturating_mul(Self::periods_per_cycle()) + fn cycle_in_era_lengths() -> EraNumber { + Self::period_in_era_lengths().saturating_mul(Self::periods_per_cycle()) } /// How many blocks are there per cycle (a 'year'). fn blocks_per_cycle() -> BlockNumber { - Self::blocks_per_era().saturating_mul(Self::eras_per_cycle()) + Self::blocks_per_era().saturating_mul(Self::cycle_in_era_lengths()) } /// For how many standard era lengths do all the build&earn subperiods in a cycle last. fn build_and_earn_eras_per_cycle() -> EraNumber { Self::eras_per_build_and_earn_subperiod().saturating_mul(Self::periods_per_cycle()) } + + /// How many distinct eras are there in a single period. + fn eras_per_period() -> EraNumber { + Self::eras_per_build_and_earn_subperiod().saturating_add(1) + } + + /// How many distinct eras are there in a cycle. + fn eras_per_cycle() -> EraNumber { + Self::eras_per_period().saturating_mul(Self::periods_per_cycle()) + } } /// Trait for observers (listeners) of various events related to dApp staking protocol. diff --git a/runtime/shiden/src/lib.rs b/runtime/shiden/src/lib.rs index 0711b26367..1f6e995129 100644 --- a/runtime/shiden/src/lib.rs +++ b/runtime/shiden/src/lib.rs @@ -1106,8 +1106,27 @@ pub type Migrations = ( DappStakingMigrationName, <Runtime as frame_system::Config>::DbWeight, >, + // Part of shiden-119 + RecalculationEraFix, ); +use frame_support::traits::OnRuntimeUpgrade; +pub struct RecalculationEraFix; +impl OnRuntimeUpgrade for RecalculationEraFix { + fn on_runtime_upgrade() -> Weight { + let first_dapp_staking_v3_era = 743; + + let expected_recalculation_era = + InflationCycleConfig::eras_per_cycle().saturating_add(first_dapp_staking_v3_era); + + pallet_inflation::ActiveInflationConfig::<Runtime>::mutate(|config| { + config.recalculation_era = expected_recalculation_era; + }); + + <Runtime as frame_system::Config>::DbWeight::get().reads_writes(1, 1) + } +} + type EventRecord = frame_system::EventRecord< <Runtime as frame_system::Config>::RuntimeEvent, <Runtime as frame_system::Config>::Hash, From 72fa2ee76a61d750c2962229b5f1a381d20d3a7f Mon Sep 17 00:00:00 2001 From: Dino Pacandi <dino.pacandi@gmail.com> Date: Wed, 7 Feb 2024 15:56:50 +0100 Subject: [PATCH 06/14] Adjustments --- pallets/dapp-staking-v3/src/lib.rs | 48 +++++-------------- pallets/inflation/src/benchmarking.rs | 21 -------- pallets/inflation/src/lib.rs | 24 ---------- pallets/inflation/src/tests.rs | 33 ------------- pallets/inflation/src/weights.rs | 15 ------ runtime/astar/src/weights/pallet_inflation.rs | 7 --- .../shibuya/src/weights/pallet_inflation.rs | 7 --- .../shiden/src/weights/pallet_inflation.rs | 7 --- 8 files changed, 13 insertions(+), 149 deletions(-) diff --git a/pallets/dapp-staking-v3/src/lib.rs b/pallets/dapp-staking-v3/src/lib.rs index ff243de881..e40fb68372 100644 --- a/pallets/dapp-staking-v3/src/lib.rs +++ b/pallets/dapp-staking-v3/src/lib.rs @@ -363,9 +363,8 @@ pub mod pallet { TooManyStakedContracts, /// There are no expired entries to cleanup for the account. NoExpiredEntries, - // TODO: remove this prior to the launch - /// Tier parameters aren't valid. - InvalidTierParameters, + /// Force call is not allowed in production. + ForceNotAllowed, } /// General information about dApp staking protocol state. @@ -458,6 +457,15 @@ pub mod pallet { #[pallet::storage] pub type HistoryCleanupMarker<T: Config> = StorageValue<_, CleanupMarker, ValueQuery>; + #[pallet::type_value] + pub fn DefaultSafeguard<T: Config>() -> bool { + // In production, safeguard is enabled by default. + !cfg!(feature = "runtime-benchmarks") && !cfg!(test) + } + + #[pallet::storage] + pub type Safeguard<T: Config> = StorageValue<_, bool, ValueQuery, DefaultSafeguard<T>>; + #[pallet::genesis_config] #[derive(frame_support::DefaultNoBound)] pub struct GenesisConfig { @@ -1510,7 +1518,6 @@ pub mod pallet { .into()) } - // TODO: make this unavailable in production, to be only used for testing /// Used to force a change of era or subperiod. /// The effect isn't immediate but will happen on the next block. /// @@ -1524,6 +1531,8 @@ pub mod pallet { Self::ensure_pallet_enabled()?; T::ManagerOrigin::ensure_origin(origin)?; + ensure!(!Safeguard::<T>::get(), Error::<T>::ForceNotAllowed); + // Ensure a 'change' happens on the next block ActiveProtocolState::<T>::mutate(|state| { let current_block = frame_system::Pallet::<T>::block_number(); @@ -1547,37 +1556,6 @@ pub mod pallet { Ok(()) } - - // TODO: remove this prior to Astar launch, to be only used for testing - #[pallet::call_index(100)] - #[pallet::weight(T::DbWeight::get().writes(1))] - pub fn force_set_tier_params( - origin: OriginFor<T>, - value: TierParameters<T::NumberOfTiers>, - ) -> DispatchResult { - Self::ensure_pallet_enabled()?; - T::ManagerOrigin::ensure_origin(origin)?; - ensure!(value.is_valid(), Error::<T>::InvalidTierParameters); - - StaticTierParams::<T>::put(value); - - Ok(()) - } - - // TODO: remove this prior to Astar launch, to be only used for testing - #[pallet::call_index(101)] - #[pallet::weight(T::DbWeight::get().writes(1))] - pub fn force_set_tier_config( - origin: OriginFor<T>, - value: TiersConfiguration<T::NumberOfTiers>, - ) -> DispatchResult { - Self::ensure_pallet_enabled()?; - T::ManagerOrigin::ensure_origin(origin)?; - - TierConfig::<T>::put(value); - - Ok(()) - } } impl<T: Config> Pallet<T> { diff --git a/pallets/inflation/src/benchmarking.rs b/pallets/inflation/src/benchmarking.rs index 6f38537996..e774b1497f 100644 --- a/pallets/inflation/src/benchmarking.rs +++ b/pallets/inflation/src/benchmarking.rs @@ -84,27 +84,6 @@ mod benchmarks { assert_last_event::<T>(Event::<T>::InflationParametersForceChanged.into()); } - #[benchmark] - fn force_set_inflation_config() { - initial_config::<T>(); - let config = InflationConfiguration { - recalculation_era: 456, - issuance_safety_cap: 112233, - collator_reward_per_block: 777, - treasury_reward_per_block: 444, - dapp_reward_pool_per_era: 55555, - base_staker_reward_pool_per_era: 77777, - adjustable_staker_reward_pool_per_era: 99999, - bonus_reward_pool_per_period: 123987, - ideal_staking_rate: Perquintill::from_percent(37), - }; - - #[extrinsic_call] - _(RawOrigin::Root, config.clone()); - - assert_last_event::<T>(Event::<T>::InflationConfigurationForceChanged { config }.into()); - } - #[benchmark] fn force_inflation_recalculation() { initial_config::<T>(); diff --git a/pallets/inflation/src/lib.rs b/pallets/inflation/src/lib.rs index 1ea770ab2b..1af12ca815 100644 --- a/pallets/inflation/src/lib.rs +++ b/pallets/inflation/src/lib.rs @@ -301,30 +301,6 @@ pub mod pallet { Ok(().into()) } - - /// Used to force-set the inflation configuration. - /// The parameters aren't checked for validity, since essentially anything can be valid. - /// - /// Must be called by `root` origin. - /// - /// Purpose of the call is testing & handling unforeseen circumstances. - /// - /// **NOTE:** and a TODO, remove this before deploying on mainnet. - #[pallet::call_index(2)] - #[pallet::weight(T::WeightInfo::force_set_inflation_config())] - pub fn force_set_inflation_config( - origin: OriginFor<T>, - config: InflationConfiguration, - ) -> DispatchResult { - ensure_root(origin)?; - - config.sanity_check(); - ActiveInflationConfig::<T>::put(config.clone()); - - Self::deposit_event(Event::<T>::InflationConfigurationForceChanged { config }); - - Ok(().into()) - } } impl<T: Config> Pallet<T> { diff --git a/pallets/inflation/src/tests.rs b/pallets/inflation/src/tests.rs index cea9a2c7c1..8270429daa 100644 --- a/pallets/inflation/src/tests.rs +++ b/pallets/inflation/src/tests.rs @@ -74,39 +74,6 @@ fn force_set_inflation_params_fails() { }) } -#[test] -fn force_set_inflation_config_work() { - ExternalityBuilder::build().execute_with(|| { - let mut new_config = ActiveInflationConfig::<Test>::get(); - new_config.recalculation_era = new_config.recalculation_era + 50; - - // Execute call, ensure it works - assert_ok!(Inflation::force_set_inflation_config( - RuntimeOrigin::root(), - new_config - )); - System::assert_last_event( - Event::InflationConfigurationForceChanged { config: new_config }.into(), - ); - - assert_eq!(ActiveInflationConfig::<Test>::get(), new_config); - }) -} - -#[test] -fn force_set_inflation_config_fails() { - ExternalityBuilder::build().execute_with(|| { - let mut new_config = ActiveInflationConfig::<Test>::get(); - new_config.recalculation_era = new_config.recalculation_era + 50; - - // Make sure action is privileged - assert_noop!( - Inflation::force_set_inflation_config(RuntimeOrigin::signed(1), new_config), - BadOrigin - ); - }) -} - #[test] fn force_inflation_recalculation_work() { ExternalityBuilder::build().execute_with(|| { diff --git a/pallets/inflation/src/weights.rs b/pallets/inflation/src/weights.rs index 702c0f11bf..7eeb43f311 100644 --- a/pallets/inflation/src/weights.rs +++ b/pallets/inflation/src/weights.rs @@ -50,7 +50,6 @@ use core::marker::PhantomData; /// Weight functions needed for pallet_inflation. pub trait WeightInfo { fn force_set_inflation_params() -> Weight; - fn force_set_inflation_config() -> Weight; fn force_inflation_recalculation() -> Weight; fn recalculation() -> Weight; fn hooks_without_recalculation() -> Weight; @@ -69,13 +68,6 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { Weight::from_parts(9_652_000, 0) .saturating_add(T::DbWeight::get().writes(1_u64)) } - fn force_set_inflation_config() -> Weight { - // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 9_168_000 picoseconds. - Weight::from_parts(9_436_000, 0) - } /// Storage: Inflation InflationParams (r:1 w:0) /// Proof: Inflation InflationParams (max_values: Some(1), max_size: Some(64), added: 559, mode: MaxEncodedLen) fn force_inflation_recalculation() -> Weight { @@ -121,13 +113,6 @@ impl WeightInfo for () { Weight::from_parts(9_652_000, 0) .saturating_add(RocksDbWeight::get().writes(1_u64)) } - fn force_set_inflation_config() -> Weight { - // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 9_168_000 picoseconds. - Weight::from_parts(9_436_000, 0) - } /// Storage: Inflation InflationParams (r:1 w:0) /// Proof: Inflation InflationParams (max_values: Some(1), max_size: Some(64), added: 559, mode: MaxEncodedLen) fn force_inflation_recalculation() -> Weight { diff --git a/runtime/astar/src/weights/pallet_inflation.rs b/runtime/astar/src/weights/pallet_inflation.rs index beaa686a86..b68ce70eec 100644 --- a/runtime/astar/src/weights/pallet_inflation.rs +++ b/runtime/astar/src/weights/pallet_inflation.rs @@ -61,13 +61,6 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { Weight::from_parts(9_303_000, 0) .saturating_add(T::DbWeight::get().writes(1_u64)) } - fn force_set_inflation_config() -> Weight { - // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 9_559_000 picoseconds. - Weight::from_parts(9_789_000, 0) - } /// Storage: Inflation InflationParams (r:1 w:0) /// Proof: Inflation InflationParams (max_values: Some(1), max_size: Some(64), added: 559, mode: MaxEncodedLen) fn force_inflation_recalculation() -> Weight { diff --git a/runtime/shibuya/src/weights/pallet_inflation.rs b/runtime/shibuya/src/weights/pallet_inflation.rs index 1fdb896f5c..2fb6509303 100644 --- a/runtime/shibuya/src/weights/pallet_inflation.rs +++ b/runtime/shibuya/src/weights/pallet_inflation.rs @@ -61,13 +61,6 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { Weight::from_parts(9_652_000, 0) .saturating_add(T::DbWeight::get().writes(1_u64)) } - fn force_set_inflation_config() -> Weight { - // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 9_168_000 picoseconds. - Weight::from_parts(9_436_000, 0) - } /// Storage: Inflation InflationParams (r:1 w:0) /// Proof: Inflation InflationParams (max_values: Some(1), max_size: Some(64), added: 559, mode: MaxEncodedLen) fn force_inflation_recalculation() -> Weight { diff --git a/runtime/shiden/src/weights/pallet_inflation.rs b/runtime/shiden/src/weights/pallet_inflation.rs index beaa686a86..b68ce70eec 100644 --- a/runtime/shiden/src/weights/pallet_inflation.rs +++ b/runtime/shiden/src/weights/pallet_inflation.rs @@ -61,13 +61,6 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { Weight::from_parts(9_303_000, 0) .saturating_add(T::DbWeight::get().writes(1_u64)) } - fn force_set_inflation_config() -> Weight { - // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 9_559_000 picoseconds. - Weight::from_parts(9_789_000, 0) - } /// Storage: Inflation InflationParams (r:1 w:0) /// Proof: Inflation InflationParams (max_values: Some(1), max_size: Some(64), added: 559, mode: MaxEncodedLen) fn force_inflation_recalculation() -> Weight { From c530b05809b93cddf3c1019e22d0a3ce0d75259d Mon Sep 17 00:00:00 2001 From: Dino Pacandi <dino.pacandi@gmail.com> Date: Wed, 7 Feb 2024 16:11:54 +0100 Subject: [PATCH 07/14] Safeguard test --- pallets/dapp-staking-v3/src/test/tests.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/pallets/dapp-staking-v3/src/test/tests.rs b/pallets/dapp-staking-v3/src/test/tests.rs index 5f83eb7b52..337508de96 100644 --- a/pallets/dapp-staking-v3/src/test/tests.rs +++ b/pallets/dapp-staking-v3/src/test/tests.rs @@ -19,7 +19,8 @@ use crate::test::{mock::*, testing_utils::*}; use crate::{ pallet::Config, ActiveProtocolState, DAppId, EraRewards, Error, Event, ForcingType, - IntegratedDApps, Ledger, NextDAppId, PeriodNumber, StakerInfo, Subperiod, TierConfig, + IntegratedDApps, Ledger, NextDAppId, PeriodNumber, Safeguard, StakerInfo, Subperiod, + TierConfig, }; use frame_support::{ @@ -2312,6 +2313,17 @@ fn force_with_incorrect_origin_fails() { }) } +#[test] +fn force_with_safeguard_on_fails() { + ExtBuilder::build().execute_with(|| { + Safeguard::<Test>::put(true); + assert_noop!( + DappStaking::force(RuntimeOrigin::root(), ForcingType::Era), + Error::<Test>::ForceNotAllowed + ); + }) +} + #[test] fn get_dapp_tier_assignment_and_rewards_basic_example_works() { ExtBuilder::build().execute_with(|| { From 2cf9a4a23480dd30a07f1a0c83e67bf1f0723c3d Mon Sep 17 00:00:00 2001 From: Dino Pacandi <dino.pacandi@gmail.com> Date: Wed, 7 Feb 2024 16:15:25 +0100 Subject: [PATCH 08/14] Docs --- pallets/dapp-staking-v3/src/lib.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pallets/dapp-staking-v3/src/lib.rs b/pallets/dapp-staking-v3/src/lib.rs index e40fb68372..58bc34fb9f 100644 --- a/pallets/dapp-staking-v3/src/lib.rs +++ b/pallets/dapp-staking-v3/src/lib.rs @@ -463,6 +463,9 @@ pub mod pallet { !cfg!(feature = "runtime-benchmarks") && !cfg!(test) } + /// Safeguard to prevent unwanted operations in production. + /// Kept as a storage without extrinsic setter, so we can still enable it for some + /// chain-fork debugging if required. #[pallet::storage] pub type Safeguard<T: Config> = StorageValue<_, bool, ValueQuery, DefaultSafeguard<T>>; From a64dec5b933625db69d124c0636ed63a6f1c8373 Mon Sep 17 00:00:00 2001 From: Dino Pacandi <dino.pacandi@gmail.com> Date: Wed, 7 Feb 2024 18:22:33 +0100 Subject: [PATCH 09/14] Fixes --- .../dapp-staking-v3/src/benchmarking/utils.rs | 2 ++ pallets/dapp-staking-v3/src/lib.rs | 2 +- pallets/dapp-staking-v3/src/test/mock.rs | 1 + runtime/astar/src/lib.rs | 12 +++++----- tests/integration/src/dapp_staking_v3.rs | 1 - tests/integration/src/setup.rs | 24 +++++++++++++++++-- 6 files changed, 32 insertions(+), 10 deletions(-) diff --git a/pallets/dapp-staking-v3/src/benchmarking/utils.rs b/pallets/dapp-staking-v3/src/benchmarking/utils.rs index 83651decfc..e7d9cd7dd5 100644 --- a/pallets/dapp-staking-v3/src/benchmarking/utils.rs +++ b/pallets/dapp-staking-v3/src/benchmarking/utils.rs @@ -203,6 +203,8 @@ pub(super) fn initial_config<T: Config>() { StaticTierParams::<T>::put(tier_params); TierConfig::<T>::put(init_tier_config.clone()); + + Safeguard::<T>::put(false); } /// Maximum number of contracts that 'makes sense' - considers both contract number limit & number of slots. diff --git a/pallets/dapp-staking-v3/src/lib.rs b/pallets/dapp-staking-v3/src/lib.rs index 58bc34fb9f..7e9d8d7d7a 100644 --- a/pallets/dapp-staking-v3/src/lib.rs +++ b/pallets/dapp-staking-v3/src/lib.rs @@ -460,7 +460,7 @@ pub mod pallet { #[pallet::type_value] pub fn DefaultSafeguard<T: Config>() -> bool { // In production, safeguard is enabled by default. - !cfg!(feature = "runtime-benchmarks") && !cfg!(test) + true } /// Safeguard to prevent unwanted operations in production. diff --git a/pallets/dapp-staking-v3/src/test/mock.rs b/pallets/dapp-staking-v3/src/test/mock.rs index ae7e1c5046..c1cc3d6788 100644 --- a/pallets/dapp-staking-v3/src/test/mock.rs +++ b/pallets/dapp-staking-v3/src/test/mock.rs @@ -326,6 +326,7 @@ impl ExtBuilder { pallet_dapp_staking::StaticTierParams::<Test>::put(tier_params); pallet_dapp_staking::TierConfig::<Test>::put(init_tier_config.clone()); + pallet_dapp_staking::Safeguard::<Test>::put(false); DappStaking::on_initialize(System::block_number()); }); diff --git a/runtime/astar/src/lib.rs b/runtime/astar/src/lib.rs index cf8aff1740..9d3e9948e1 100644 --- a/runtime/astar/src/lib.rs +++ b/runtime/astar/src/lib.rs @@ -1100,12 +1100,12 @@ construct_runtime!( Sudo: pallet_sudo = 99, -// To be removed & cleaned up once proper oracle is implemented -StaticPriceProvider: pallet_static_price_provider = 253, -// To be removed & cleaned up after migration has been finished -DappStakingMigration: pallet_dapp_staking_migration = 254, -// Legacy dApps staking v2, to be removed after migration has been finished -DappsStaking: pallet_dapps_staking = 255, + // To be removed & cleaned up once proper oracle is implemented + StaticPriceProvider: pallet_static_price_provider = 253, + // To be removed & cleaned up after migration has been finished + DappStakingMigration: pallet_dapp_staking_migration = 254, + // Legacy dApps staking v2, to be removed after migration has been finished + DappsStaking: pallet_dapps_staking = 255, } ); diff --git a/tests/integration/src/dapp_staking_v3.rs b/tests/integration/src/dapp_staking_v3.rs index 5fa769ea1f..167e4d4aa8 100644 --- a/tests/integration/src/dapp_staking_v3.rs +++ b/tests/integration/src/dapp_staking_v3.rs @@ -27,7 +27,6 @@ use pallet_dapp_staking_v3::*; fn dapp_staking_triggers_inflation_recalculation() { new_test_ext().execute_with(|| { let init_inflation_config = pallet_inflation::ActiveInflationConfig::<Runtime>::get(); - let recalculation_era = init_inflation_config.recalculation_era; // It's not feasible to run through all the blocks needed to trigger all the eras. diff --git a/tests/integration/src/setup.rs b/tests/integration/src/setup.rs index c217da98de..1454d40c0a 100644 --- a/tests/integration/src/setup.rs +++ b/tests/integration/src/setup.rs @@ -28,7 +28,9 @@ pub use sp_core::{H160, H256, U256}; pub use sp_io::hashing::keccak_256; pub use sp_runtime::{AccountId32, MultiAddress}; -pub use astar_primitives::{evm::UnifiedAddressMapper, BlockNumber}; +pub use astar_primitives::{ + dapp_staking::CycleConfiguration, evm::UnifiedAddressMapper, BlockNumber, +}; #[cfg(feature = "shibuya")] pub use shibuya::*; @@ -199,7 +201,25 @@ impl ExtBuilder { .unwrap(); let mut ext = sp_io::TestExternalities::new(t); - ext.execute_with(|| System::set_block_number(1)); + ext.execute_with(|| { + System::set_block_number(1); + + let era_length = <Runtime as pallet_dapp_staking_v3::Config>::CycleConfiguration::blocks_per_era(); + let voting_period_length_in_eras = + <Runtime as pallet_dapp_staking_v3::Config>::CycleConfiguration::eras_per_voting_subperiod(); + + pallet_dapp_staking_v3::ActiveProtocolState::<Runtime>::put(pallet_dapp_staking_v3::ProtocolState { + era: 1, + next_era_start: era_length.saturating_mul(voting_period_length_in_eras.into()) + 1, + period_info: pallet_dapp_staking_v3::PeriodInfo { + number: 1, + subperiod: pallet_dapp_staking_v3::Subperiod::Voting, + next_subperiod_start_era: 2, + }, + maintenance: false, + }); + pallet_dapp_staking_v3::Safeguard::<Runtime>::put(false); + }); ext } } From 6319c21c0d22ed50cc747f494cefbc14f633fdc9 Mon Sep 17 00:00:00 2001 From: Dino Pacandi <dino.pacandi@gmail.com> Date: Wed, 7 Feb 2024 18:26:01 +0100 Subject: [PATCH 10/14] Extra test --- pallets/dapp-staking-v3/src/test/tests.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pallets/dapp-staking-v3/src/test/tests.rs b/pallets/dapp-staking-v3/src/test/tests.rs index 337508de96..f196dab81a 100644 --- a/pallets/dapp-staking-v3/src/test/tests.rs +++ b/pallets/dapp-staking-v3/src/test/tests.rs @@ -2762,3 +2762,15 @@ fn unregister_after_max_number_of_contracts_allows_register_again() { assert_register(developer, &smart_contract); }) } + +#[test] +fn safeguard_on_by_default() { + let storage = frame_system::GenesisConfig::default() + .build_storage::<Test>() + .unwrap(); + + let mut ext = sp_io::TestExternalities::from(storage); + ext.execute_with(|| { + assert!(Safeguard::<Test>::get()); + }); +} From 70e100406822ca030168f8206f47a5bfa68d59a0 Mon Sep 17 00:00:00 2001 From: Dino Pacandi <dino.pacandi@gmail.com> Date: Wed, 7 Feb 2024 18:30:13 +0100 Subject: [PATCH 11/14] Update weights --- pallets/dapp-staking-migration/src/weights.rs | 76 +++++----- .../src/weights/pallet_dapp_staking_v3.rs | 136 +++++++++--------- runtime/astar/src/weights/pallet_inflation.rs | 26 ++-- 3 files changed, 122 insertions(+), 116 deletions(-) diff --git a/pallets/dapp-staking-migration/src/weights.rs b/pallets/dapp-staking-migration/src/weights.rs index 15db668cc8..87250d7fa7 100644 --- a/pallets/dapp-staking-migration/src/weights.rs +++ b/pallets/dapp-staking-migration/src/weights.rs @@ -20,16 +20,16 @@ //! Autogenerated weights for pallet_dapp_staking_migration //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2024-02-04, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2024-02-07, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` //! HOSTNAME: `gh-runner-01-ovh`, CPU: `Intel(R) Xeon(R) E-2236 CPU @ 3.40GHz` -//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("shiden-dev"), DB CACHE: 1024 +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("astar-dev"), DB CACHE: 1024 // Executed Command: // ./target/release/astar-collator // benchmark // pallet -// --chain=shiden-dev +// --chain=astar-dev // --steps=50 // --repeat=20 // --pallet=pallet_dapp_staking_migration @@ -37,7 +37,7 @@ // --execution=wasm // --wasm-execution=compiled // --heap-pages=4096 -// --output=./benchmark-results/shiden-dev/dapp_staking_migration_weights.rs +// --output=./benchmark-results/astar-dev/dapp_staking_migration_weights.rs // --template=./scripts/templates/weight-template.hbs #![cfg_attr(rustfmt, rustfmt_skip)] @@ -74,8 +74,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { // Proof Size summary in bytes: // Measured: `558` // Estimated: `6112` - // Minimum execution time: 48_037_000 picoseconds. - Weight::from_parts(49_209_000, 6112) + // Minimum execution time: 47_762_000 picoseconds. + Weight::from_parts(48_426_000, 6112) .saturating_add(T::DbWeight::get().reads(6_u64)) .saturating_add(T::DbWeight::get().writes(5_u64)) } @@ -85,8 +85,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { // Proof Size summary in bytes: // Measured: `0` // Estimated: `3551` - // Minimum execution time: 3_226_000 picoseconds. - Weight::from_parts(3_424_000, 3551) + // Minimum execution time: 3_150_000 picoseconds. + Weight::from_parts(3_368_000, 3551) .saturating_add(T::DbWeight::get().reads(1_u64)) } /// Storage: DappsStaking Ledger (r:2 w:1) @@ -99,15 +99,17 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) /// Storage: DappStaking Ledger (r:1 w:1) /// Proof: DappStaking Ledger (max_values: None, max_size: Some(310), added: 2785, mode: MaxEncodedLen) + /// Storage: CollatorSelection Candidates (r:1 w:0) + /// Proof Skipped: CollatorSelection Candidates (max_values: Some(1), max_size: None, mode: Measured) /// Storage: DappStaking CurrentEraInfo (r:1 w:1) /// Proof: DappStaking CurrentEraInfo (max_values: Some(1), max_size: Some(112), added: 607, mode: MaxEncodedLen) fn migrate_ledger_success() -> Weight { // Proof Size summary in bytes: - // Measured: `1749` + // Measured: `1875` // Estimated: `6472` - // Minimum execution time: 69_988_000 picoseconds. - Weight::from_parts(70_437_000, 6472) - .saturating_add(T::DbWeight::get().reads(7_u64)) + // Minimum execution time: 70_640_000 picoseconds. + Weight::from_parts(72_730_000, 6472) + .saturating_add(T::DbWeight::get().reads(8_u64)) .saturating_add(T::DbWeight::get().writes(6_u64)) } /// Storage: DappsStaking Ledger (r:1 w:0) @@ -116,8 +118,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { // Proof Size summary in bytes: // Measured: `0` // Estimated: `3731` - // Minimum execution time: 3_019_000 picoseconds. - Weight::from_parts(3_197_000, 3731) + // Minimum execution time: 2_769_000 picoseconds. + Weight::from_parts(2_894_000, 3731) .saturating_add(T::DbWeight::get().reads(1_u64)) } /// Storage: DappsStaking Ledger (r:6 w:5) @@ -127,10 +129,10 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { // Proof Size summary in bytes: // Measured: `700 + x * (40 ±0)` // Estimated: `3731 + x * (2741 ±0)` - // Minimum execution time: 6_873_000 picoseconds. - Weight::from_parts(6_629_732, 3731) - // Standard Error: 7_063 - .saturating_add(Weight::from_parts(688_886, 0).saturating_mul(x.into())) + // Minimum execution time: 6_830_000 picoseconds. + Weight::from_parts(6_598_680, 3731) + // Standard Error: 6_203 + .saturating_add(Weight::from_parts(686_141, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(x.into()))) .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(x.into()))) @@ -140,8 +142,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 2_144_000 picoseconds. - Weight::from_parts(2_233_000, 0) + // Minimum execution time: 2_017_000 picoseconds. + Weight::from_parts(2_116_000, 0) } } @@ -161,8 +163,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `558` // Estimated: `6112` - // Minimum execution time: 48_037_000 picoseconds. - Weight::from_parts(49_209_000, 6112) + // Minimum execution time: 47_762_000 picoseconds. + Weight::from_parts(48_426_000, 6112) .saturating_add(RocksDbWeight::get().reads(6_u64)) .saturating_add(RocksDbWeight::get().writes(5_u64)) } @@ -172,8 +174,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `0` // Estimated: `3551` - // Minimum execution time: 3_226_000 picoseconds. - Weight::from_parts(3_424_000, 3551) + // Minimum execution time: 3_150_000 picoseconds. + Weight::from_parts(3_368_000, 3551) .saturating_add(RocksDbWeight::get().reads(1_u64)) } /// Storage: DappsStaking Ledger (r:2 w:1) @@ -186,15 +188,17 @@ impl WeightInfo for () { /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) /// Storage: DappStaking Ledger (r:1 w:1) /// Proof: DappStaking Ledger (max_values: None, max_size: Some(310), added: 2785, mode: MaxEncodedLen) + /// Storage: CollatorSelection Candidates (r:1 w:0) + /// Proof Skipped: CollatorSelection Candidates (max_values: Some(1), max_size: None, mode: Measured) /// Storage: DappStaking CurrentEraInfo (r:1 w:1) /// Proof: DappStaking CurrentEraInfo (max_values: Some(1), max_size: Some(112), added: 607, mode: MaxEncodedLen) fn migrate_ledger_success() -> Weight { // Proof Size summary in bytes: - // Measured: `1749` + // Measured: `1875` // Estimated: `6472` - // Minimum execution time: 69_988_000 picoseconds. - Weight::from_parts(70_437_000, 6472) - .saturating_add(RocksDbWeight::get().reads(7_u64)) + // Minimum execution time: 70_640_000 picoseconds. + Weight::from_parts(72_730_000, 6472) + .saturating_add(RocksDbWeight::get().reads(8_u64)) .saturating_add(RocksDbWeight::get().writes(6_u64)) } /// Storage: DappsStaking Ledger (r:1 w:0) @@ -203,8 +207,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `0` // Estimated: `3731` - // Minimum execution time: 3_019_000 picoseconds. - Weight::from_parts(3_197_000, 3731) + // Minimum execution time: 2_769_000 picoseconds. + Weight::from_parts(2_894_000, 3731) .saturating_add(RocksDbWeight::get().reads(1_u64)) } /// Storage: DappsStaking Ledger (r:6 w:5) @@ -214,10 +218,10 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `700 + x * (40 ±0)` // Estimated: `3731 + x * (2741 ±0)` - // Minimum execution time: 6_873_000 picoseconds. - Weight::from_parts(6_629_732, 3731) - // Standard Error: 7_063 - .saturating_add(Weight::from_parts(688_886, 0).saturating_mul(x.into())) + // Minimum execution time: 6_830_000 picoseconds. + Weight::from_parts(6_598_680, 3731) + // Standard Error: 6_203 + .saturating_add(Weight::from_parts(686_141, 0).saturating_mul(x.into())) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().reads((1_u64).saturating_mul(x.into()))) .saturating_add(RocksDbWeight::get().writes((1_u64).saturating_mul(x.into()))) @@ -227,7 +231,7 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 2_144_000 picoseconds. - Weight::from_parts(2_233_000, 0) + // Minimum execution time: 2_017_000 picoseconds. + Weight::from_parts(2_116_000, 0) } } diff --git a/runtime/astar/src/weights/pallet_dapp_staking_v3.rs b/runtime/astar/src/weights/pallet_dapp_staking_v3.rs index a7067267f8..d07b37ab13 100644 --- a/runtime/astar/src/weights/pallet_dapp_staking_v3.rs +++ b/runtime/astar/src/weights/pallet_dapp_staking_v3.rs @@ -1,4 +1,3 @@ - // This file is part of Astar. // Copyright (C) 2019-2023 Stake Technologies Pte.Ltd. @@ -20,16 +19,16 @@ //! Autogenerated weights for pallet_dapp_staking_v3 //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2024-02-04, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2024-02-07, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` //! HOSTNAME: `gh-runner-01-ovh`, CPU: `Intel(R) Xeon(R) E-2236 CPU @ 3.40GHz` -//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("shiden-dev"), DB CACHE: 1024 +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("astar-dev"), DB CACHE: 1024 // Executed Command: // ./target/release/astar-collator // benchmark // pallet -// --chain=shiden-dev +// --chain=astar-dev // --steps=50 // --repeat=20 // --pallet=pallet_dapp_staking_v3 @@ -37,7 +36,7 @@ // --execution=wasm // --wasm-execution=compiled // --heap-pages=4096 -// --output=./benchmark-results/shiden-dev/dapp_staking_v3_weights.rs +// --output=./benchmark-results/astar-dev/dapp_staking_v3_weights.rs // --template=./scripts/templates/weight-template.hbs #![cfg_attr(rustfmt, rustfmt_skip)] @@ -55,8 +54,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 8_967_000 picoseconds. - Weight::from_parts(9_242_000, 0) + // Minimum execution time: 9_172_000 picoseconds. + Weight::from_parts(9_411_000, 0) } /// Storage: DappStaking IntegratedDApps (r:1 w:1) /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(116), added: 2096, mode: MaxEncodedLen) @@ -68,8 +67,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { // Proof Size summary in bytes: // Measured: `0` // Estimated: `3086` - // Minimum execution time: 17_044_000 picoseconds. - Weight::from_parts(17_328_000, 3086) + // Minimum execution time: 16_953_000 picoseconds. + Weight::from_parts(17_223_000, 3086) .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -79,8 +78,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { // Proof Size summary in bytes: // Measured: `74` // Estimated: `3086` - // Minimum execution time: 13_369_000 picoseconds. - Weight::from_parts(13_617_000, 3086) + // Minimum execution time: 13_226_000 picoseconds. + Weight::from_parts(13_585_000, 3086) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -90,8 +89,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { // Proof Size summary in bytes: // Measured: `74` // Estimated: `3086` - // Minimum execution time: 13_421_000 picoseconds. - Weight::from_parts(13_692_000, 3086) + // Minimum execution time: 13_029_000 picoseconds. + Weight::from_parts(13_242_000, 3086) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -105,8 +104,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { // Proof Size summary in bytes: // Measured: `74` // Estimated: `3086` - // Minimum execution time: 18_458_000 picoseconds. - Weight::from_parts(18_864_000, 3086) + // Minimum execution time: 17_784_000 picoseconds. + Weight::from_parts(18_196_000, 3086) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -124,8 +123,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { // Proof Size summary in bytes: // Measured: `138` // Estimated: `4764` - // Minimum execution time: 62_743_000 picoseconds. - Weight::from_parts(64_992_000, 4764) + // Minimum execution time: 34_451_000 picoseconds. + Weight::from_parts(35_062_000, 4764) .saturating_add(T::DbWeight::get().reads(5_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -141,8 +140,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { // Proof Size summary in bytes: // Measured: `158` // Estimated: `4764` - // Minimum execution time: 38_250_000 picoseconds. - Weight::from_parts(38_835_000, 4764) + // Minimum execution time: 37_185_000 picoseconds. + Weight::from_parts(37_955_000, 4764) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -158,8 +157,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { // Proof Size summary in bytes: // Measured: `158` // Estimated: `4764` - // Minimum execution time: 34_582_000 picoseconds. - Weight::from_parts(35_126_000, 4764) + // Minimum execution time: 33_457_000 picoseconds. + Weight::from_parts(33_833_000, 4764) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -174,12 +173,12 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { /// The range of component `x` is `[0, 16]`. fn claim_unlocked(x: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `191` + // Measured: `190` // Estimated: `4764` - // Minimum execution time: 37_740_000 picoseconds. - Weight::from_parts(39_064_684, 4764) - // Standard Error: 2_750 - .saturating_add(Weight::from_parts(120_539, 0).saturating_mul(x.into())) + // Minimum execution time: 36_715_000 picoseconds. + Weight::from_parts(38_253_697, 4764) + // Standard Error: 4_195 + .saturating_add(Weight::from_parts(173_577, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -195,8 +194,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { // Proof Size summary in bytes: // Measured: `200` // Estimated: `4764` - // Minimum execution time: 33_298_000 picoseconds. - Weight::from_parts(33_903_000, 4764) + // Minimum execution time: 33_049_000 picoseconds. + Weight::from_parts(33_731_000, 4764) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -218,8 +217,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { // Proof Size summary in bytes: // Measured: `251` // Estimated: `4764` - // Minimum execution time: 44_905_000 picoseconds. - Weight::from_parts(45_261_000, 4764) + // Minimum execution time: 44_722_000 picoseconds. + Weight::from_parts(44_977_000, 4764) .saturating_add(T::DbWeight::get().reads(7_u64)) .saturating_add(T::DbWeight::get().writes(5_u64)) } @@ -241,8 +240,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { // Proof Size summary in bytes: // Measured: `432` // Estimated: `4764` - // Minimum execution time: 48_594_000 picoseconds. - Weight::from_parts(49_441_000, 4764) + // Minimum execution time: 48_465_000 picoseconds. + Weight::from_parts(49_098_000, 4764) .saturating_add(T::DbWeight::get().reads(7_u64)) .saturating_add(T::DbWeight::get().writes(5_u64)) } @@ -261,10 +260,10 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { // Proof Size summary in bytes: // Measured: `541` // Estimated: `4764` - // Minimum execution time: 52_182_000 picoseconds. - Weight::from_parts(50_073_700, 4764) - // Standard Error: 4_907 - .saturating_add(Weight::from_parts(3_301_788, 0).saturating_mul(x.into())) + // Minimum execution time: 51_303_000 picoseconds. + Weight::from_parts(49_440_154, 4764) + // Standard Error: 4_315 + .saturating_add(Weight::from_parts(3_164_288, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(5_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -281,10 +280,10 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { // Proof Size summary in bytes: // Measured: `519` // Estimated: `4764` - // Minimum execution time: 49_637_000 picoseconds. - Weight::from_parts(47_809_537, 4764) - // Standard Error: 5_850 - .saturating_add(Weight::from_parts(3_304_857, 0).saturating_mul(x.into())) + // Minimum execution time: 48_956_000 picoseconds. + Weight::from_parts(46_951_013, 4764) + // Standard Error: 4_800 + .saturating_add(Weight::from_parts(3_195_446, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -298,8 +297,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { // Proof Size summary in bytes: // Measured: `271` // Estimated: `3775` - // Minimum execution time: 41_926_000 picoseconds. - Weight::from_parts(42_718_000, 3775) + // Minimum execution time: 41_373_000 picoseconds. + Weight::from_parts(42_446_000, 3775) .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -311,8 +310,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { // Proof Size summary in bytes: // Measured: `2584` // Estimated: `5048` - // Minimum execution time: 57_183_000 picoseconds. - Weight::from_parts(58_197_000, 5048) + // Minimum execution time: 57_307_000 picoseconds. + Weight::from_parts(58_880_000, 5048) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -332,8 +331,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { // Proof Size summary in bytes: // Measured: `318` // Estimated: `4764` - // Minimum execution time: 41_858_000 picoseconds. - Weight::from_parts(42_476_000, 4764) + // Minimum execution time: 41_250_000 picoseconds. + Weight::from_parts(41_849_000, 4764) .saturating_add(T::DbWeight::get().reads(6_u64)) .saturating_add(T::DbWeight::get().writes(4_u64)) } @@ -348,24 +347,27 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { /// The range of component `x` is `[1, 16]`. fn cleanup_expired_entries(x: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `256 + x * (69 ±0)` + // Measured: `257 + x * (69 ±0)` // Estimated: `4764 + x * (2613 ±0)` - // Minimum execution time: 43_103_000 picoseconds. - Weight::from_parts(39_876_215, 4764) - // Standard Error: 8_123 - .saturating_add(Weight::from_parts(5_014_232, 0).saturating_mul(x.into())) + // Minimum execution time: 42_815_000 picoseconds. + Weight::from_parts(39_631_627, 4764) + // Standard Error: 6_828 + .saturating_add(Weight::from_parts(4_984_583, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(x.into()))) .saturating_add(T::DbWeight::get().writes(2_u64)) .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(x.into()))) .saturating_add(Weight::from_parts(0, 2613).saturating_mul(x.into())) } + /// Storage: DappStaking Safeguard (r:1 w:0) + /// Proof: DappStaking Safeguard (max_values: Some(1), max_size: Some(1), added: 496, mode: MaxEncodedLen) fn force() -> Weight { // Proof Size summary in bytes: // Measured: `0` - // Estimated: `0` - // Minimum execution time: 11_543_000 picoseconds. - Weight::from_parts(11_735_000, 0) + // Estimated: `1486` + // Minimum execution time: 11_946_000 picoseconds. + Weight::from_parts(12_108_000, 1486) + .saturating_add(T::DbWeight::get().reads(1_u64)) } /// Storage: DappStaking CurrentEraInfo (r:1 w:1) /// Proof: DappStaking CurrentEraInfo (max_values: Some(1), max_size: Some(112), added: 607, mode: MaxEncodedLen) @@ -375,8 +377,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { // Proof Size summary in bytes: // Measured: `16` // Estimated: `4254` - // Minimum execution time: 17_687_000 picoseconds. - Weight::from_parts(18_283_000, 4254) + // Minimum execution time: 17_411_000 picoseconds. + Weight::from_parts(17_960_000, 4254) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -396,10 +398,10 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { /// Proof: DappStaking DAppTiers (max_values: None, max_size: Some(1583), added: 4058, mode: MaxEncodedLen) fn on_initialize_build_and_earn_to_voting() -> Weight { // Proof Size summary in bytes: - // Measured: `839` + // Measured: `837` // Estimated: `4254` - // Minimum execution time: 47_901_000 picoseconds. - Weight::from_parts(49_554_000, 4254) + // Minimum execution time: 47_150_000 picoseconds. + Weight::from_parts(49_622_000, 4254) .saturating_add(T::DbWeight::get().reads(6_u64)) .saturating_add(T::DbWeight::get().writes(7_u64)) } @@ -413,8 +415,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { // Proof Size summary in bytes: // Measured: `68` // Estimated: `4254` - // Minimum execution time: 23_705_000 picoseconds. - Weight::from_parts(24_313_000, 4254) + // Minimum execution time: 23_567_000 picoseconds. + Weight::from_parts(24_230_000, 4254) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -427,10 +429,10 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { // Proof Size summary in bytes: // Measured: `152 + x * (32 ±0)` // Estimated: `3061 + x * (2071 ±0)` - // Minimum execution time: 7_549_000 picoseconds. - Weight::from_parts(12_476_634, 3061) - // Standard Error: 3_594 - .saturating_add(Weight::from_parts(2_387_577, 0).saturating_mul(x.into())) + // Minimum execution time: 7_476_000 picoseconds. + Weight::from_parts(12_571_316, 3061) + // Standard Error: 3_559 + .saturating_add(Weight::from_parts(2_337_771, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(x.into()))) .saturating_add(Weight::from_parts(0, 2071).saturating_mul(x.into())) @@ -445,8 +447,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { // Proof Size summary in bytes: // Measured: `293` // Estimated: `4254` - // Minimum execution time: 8_529_000 picoseconds. - Weight::from_parts(8_772_000, 4254) + // Minimum execution time: 8_101_000 picoseconds. + Weight::from_parts(8_272_000, 4254) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } diff --git a/runtime/astar/src/weights/pallet_inflation.rs b/runtime/astar/src/weights/pallet_inflation.rs index b68ce70eec..98814451a7 100644 --- a/runtime/astar/src/weights/pallet_inflation.rs +++ b/runtime/astar/src/weights/pallet_inflation.rs @@ -20,16 +20,16 @@ //! Autogenerated weights for pallet_inflation //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2024-02-04, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2024-02-07, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` //! HOSTNAME: `gh-runner-01-ovh`, CPU: `Intel(R) Xeon(R) E-2236 CPU @ 3.40GHz` -//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("shiden-dev"), DB CACHE: 1024 +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("astar-dev"), DB CACHE: 1024 // Executed Command: // ./target/release/astar-collator // benchmark // pallet -// --chain=shiden-dev +// --chain=astar-dev // --steps=50 // --repeat=20 // --pallet=pallet_inflation @@ -37,7 +37,7 @@ // --execution=wasm // --wasm-execution=compiled // --heap-pages=4096 -// --output=./benchmark-results/shiden-dev/inflation_weights.rs +// --output=./benchmark-results/astar-dev/inflation_weights.rs // --template=./scripts/templates/weight-template.hbs #![cfg_attr(rustfmt, rustfmt_skip)] @@ -57,8 +57,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 9_034_000 picoseconds. - Weight::from_parts(9_303_000, 0) + // Minimum execution time: 8_868_000 picoseconds. + Weight::from_parts(9_183_000, 0) .saturating_add(T::DbWeight::get().writes(1_u64)) } /// Storage: Inflation InflationParams (r:1 w:0) @@ -67,8 +67,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { // Proof Size summary in bytes: // Measured: `40` // Estimated: `1549` - // Minimum execution time: 13_548_000 picoseconds. - Weight::from_parts(13_796_000, 1549) + // Minimum execution time: 13_226_000 picoseconds. + Weight::from_parts(13_460_000, 1549) .saturating_add(T::DbWeight::get().reads(1_u64)) } /// Storage: Inflation InflationParams (r:1 w:0) @@ -77,8 +77,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { // Proof Size summary in bytes: // Measured: `58` // Estimated: `1549` - // Minimum execution time: 13_421_000 picoseconds. - Weight::from_parts(13_808_000, 1549) + // Minimum execution time: 13_150_000 picoseconds. + Weight::from_parts(13_395_000, 1549) .saturating_add(T::DbWeight::get().reads(1_u64)) } /// Storage: System Account (r:2 w:2) @@ -87,9 +87,9 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { // Proof Size summary in bytes: // Measured: `39` // Estimated: `6196` - // Minimum execution time: 40_566_000 picoseconds. - Weight::from_parts(40_980_000, 6196) + // Minimum execution time: 39_539_000 picoseconds. + Weight::from_parts(40_043_000, 6196) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } -} +} \ No newline at end of file From 217bb833808380079ec3c424271d36cc8e33c489 Mon Sep 17 00:00:00 2001 From: Dino Pacandi <dino.pacandi@gmail.com> Date: Thu, 8 Feb 2024 07:15:12 +0100 Subject: [PATCH 12/14] Ensure benchmark tests work --- pallets/dapp-staking-v3/src/benchmarking/mod.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pallets/dapp-staking-v3/src/benchmarking/mod.rs b/pallets/dapp-staking-v3/src/benchmarking/mod.rs index af1cf1034a..56d62a252f 100644 --- a/pallets/dapp-staking-v3/src/benchmarking/mod.rs +++ b/pallets/dapp-staking-v3/src/benchmarking/mod.rs @@ -245,6 +245,8 @@ mod benchmarks { #[benchmark] fn claim_unlocked(x: Linear<0, { T::MaxNumberOfStakedContracts::get() }>) { + initial_config::<T>(); + // Prepare staker account and lock some amount let staker: T::AccountId = whitelisted_caller(); let amount = (T::MinimumStakeAmount::get() + 1) From 95f8e40220b5ee26b719c900754c4d5e557df3e0 Mon Sep 17 00:00:00 2001 From: Dino Pacandi <dino.pacandi@gmail.com> Date: Thu, 8 Feb 2024 07:43:42 +0100 Subject: [PATCH 13/14] Formatting --- pallets/dapp-staking-v3/src/benchmarking/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pallets/dapp-staking-v3/src/benchmarking/mod.rs b/pallets/dapp-staking-v3/src/benchmarking/mod.rs index 56d62a252f..49efbc979b 100644 --- a/pallets/dapp-staking-v3/src/benchmarking/mod.rs +++ b/pallets/dapp-staking-v3/src/benchmarking/mod.rs @@ -246,7 +246,7 @@ mod benchmarks { #[benchmark] fn claim_unlocked(x: Linear<0, { T::MaxNumberOfStakedContracts::get() }>) { initial_config::<T>(); - + // Prepare staker account and lock some amount let staker: T::AccountId = whitelisted_caller(); let amount = (T::MinimumStakeAmount::get() + 1) From 800ac24698706745eea7f9b7ae1df6ba3168b4b2 Mon Sep 17 00:00:00 2001 From: Dino Pacandi <dino.pacandi@gmail.com> Date: Fri, 9 Feb 2024 07:08:44 +0100 Subject: [PATCH 14/14] Init price --- runtime/astar/src/lib.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/runtime/astar/src/lib.rs b/runtime/astar/src/lib.rs index 9d3e9948e1..fa9b733b11 100644 --- a/runtime/astar/src/lib.rs +++ b/runtime/astar/src/lib.rs @@ -1170,8 +1170,7 @@ use sp_arithmetic::fixed_point::FixedU64; pub struct InitActivePriceGet; impl Get<FixedU64> for InitActivePriceGet { fn get() -> FixedU64 { - // TODO: calculate this! - FixedU64::from_rational(15, 100) + FixedU64::from_rational(18, 100) } }