Skip to content

Commit

Permalink
feat: update all pallets for polkadot v1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ashutoshvarma committed Jan 26, 2024
1 parent 72e0462 commit 2b2da4a
Show file tree
Hide file tree
Showing 46 changed files with 382 additions and 402 deletions.
4 changes: 3 additions & 1 deletion pallets/astar-xcm-benchmarks/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ frame-system = { workspace = true }
parity-scale-codec = { workspace = true, optional = true, features = ["derive"] }
scale-info = { workspace = true }
sp-std = { workspace = true }
sp-runtime = { workspace = true }

# Polkadot / XCM
pallet-xcm-benchmarks = { workspace = true }
Expand All @@ -36,7 +37,6 @@ pallet-assets = { workspace = true, features = ["std"] }
pallet-balances = { workspace = true, features = ["std"] }
sp-core = { workspace = true, features = ["std"] }
sp-io = { workspace = true, features = ["std"] }
sp-runtime = { workspace = true, features = ["std"] }
xcm-builder = { workspace = true, features = ["std"] }

[features]
Expand All @@ -50,6 +50,7 @@ std = [
"parity-scale-codec/std",
"serde",
"sp-std/std",
"sp-runtime/std",
"xcm/std",
]

Expand All @@ -58,6 +59,7 @@ try-runtime = ["frame-support/try-runtime"]
runtime-benchmarks = [
"frame-benchmarking",
"frame-system/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"pallet-assets/runtime-benchmarks",
"pallet-xcm-benchmarks/runtime-benchmarks",
"parity-scale-codec",
Expand Down
40 changes: 7 additions & 33 deletions pallets/astar-xcm-benchmarks/src/fungible/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,14 @@
use super::{Pallet as AstarBenchmarks, *};
use crate::WrappedBenchmark;
use frame_benchmarking::v2::*;
use frame_support::{
dispatch::Weight,
traits::{fungible::Inspect, Get},
};
use frame_support::{traits::fungible::Inspect, weights::Weight};
use pallet_xcm_benchmarks::{
account_and_location, fungible::Pallet as PalletXcmBenchmarks, new_executor, AssetTransactorOf,
};
use sp_runtime::traits::Zero;
use sp_std::vec;
use xcm::latest::prelude::*;
use xcm_executor::traits::{Convert, TransactAsset};
use xcm_executor::traits::{ConvertLocation, TransactAsset};

#[benchmarks(
where
Expand Down Expand Up @@ -58,14 +56,14 @@ mod benchmarks {
// this xcm doesn't use holding

let dest_location = T::valid_destination()?;
let dest_account = T::AccountIdConverter::convert(dest_location.clone()).unwrap();
let dest_account = T::AccountIdConverter::convert_location(&dest_location).unwrap();

<AssetTransactorOf<T>>::deposit_asset(
&asset_to_deposit,
&sender_location,
&XcmContext {
origin: Some(sender_location.clone()),
message_hash: [0; 32],
message_id: [0; 32],
topic: None,
},
)
Expand Down Expand Up @@ -94,7 +92,7 @@ mod benchmarks {
fn transfer_reserve_asset() -> Result<(), BenchmarkError> {
let (sender_account, sender_location) = account_and_location::<T>(1);
let dest_location = T::valid_destination()?;
let dest_account = T::AccountIdConverter::convert(dest_location.clone()).unwrap();
let dest_account = T::AccountIdConverter::convert_location(&dest_location).unwrap();

let asset_to_deposit = T::get_multi_asset();
// take out ED from given asset
Expand All @@ -107,7 +105,7 @@ mod benchmarks {
&sender_location,
&XcmContext {
origin: Some(sender_location.clone()),
message_hash: [0; 32],
message_id: [0; 32],
topic: None,
},
)
Expand All @@ -132,30 +130,6 @@ mod benchmarks {
Ok(())
}

/// The benchmarks for `reserve_asset_deposited` was added in later versions of
/// `pallet-xcm-benchmarks` (in v1.x.x versions).
/// TODO: remove this once we uplift to new polkadot release
#[benchmark]
fn reserve_asset_deposited() -> Result<(), BenchmarkError> {
let (trusted_reserve, transferable_reserve_asset) = T::TrustedReserve::get().ok_or(
BenchmarkError::Override(BenchmarkResult::from_weight(Weight::MAX)),
)?;

let assets: MultiAssets = vec![transferable_reserve_asset].into();

let mut executor = new_executor::<T>(trusted_reserve);
let instruction = Instruction::ReserveAssetDeposited(assets.clone());
let xcm = Xcm(vec![instruction]);

#[block]
{
executor.bench_process(xcm)?;
}

assert!(executor.holding().ensure_contains(&assets).is_ok());
Ok(())
}

#[benchmark]
fn receive_teleported_asset() -> Result<(), BenchmarkError> {
#[block]
Expand Down
5 changes: 0 additions & 5 deletions pallets/astar-xcm-benchmarks/src/fungible/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ pub mod pallet {
pub trait Config<I: 'static = ()>:
frame_system::Config + crate::Config + pallet_xcm_benchmarks::fungible::Config
{
/// A trusted location where reserve assets are stored, and the asset we allow to be
/// reserves.
type TrustedReserve: frame_support::traits::Get<
Option<(xcm::latest::MultiLocation, xcm::latest::MultiAsset)>,
>;
}

#[pallet::pallet]
Expand Down
2 changes: 1 addition & 1 deletion pallets/astar-xcm-benchmarks/src/generic/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use super::{Pallet as AstarBenchmarks, *};
use crate::WrappedBenchmark;
use frame_benchmarking::v2::*;
use frame_support::dispatch::Weight;
use frame_support::weights::Weight;
use pallet_xcm_benchmarks::{generic::Pallet as PalletXcmBenchmarks, new_executor, XcmCallOf};
use sp_std::vec;
use xcm::latest::prelude::*;
Expand Down
2 changes: 1 addition & 1 deletion pallets/astar-xcm-benchmarks/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ where
fn run_benchmark(
name: &[u8],
c: &[(frame_benchmarking::BenchmarkParameter, u32)],
whitelist: &[frame_benchmarking::TrackedStorageKey],
whitelist: &[frame_support::traits::TrackedStorageKey],
verify: bool,
internal_repeats: u32,
) -> Result<Vec<frame_benchmarking::BenchmarkResult>, frame_benchmarking::BenchmarkError> {
Expand Down
57 changes: 24 additions & 33 deletions pallets/astar-xcm-benchmarks/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,51 +30,40 @@ use frame_system::{EnsureRoot, EnsureSigned};

use core::marker::PhantomData;
use sp_core::{ConstU32, ConstU64, Get, H256};
use sp_runtime::{
testing::Header,
traits::{BlakeTwo256, IdentityLookup},
};
use sp_runtime::traits::{BlakeTwo256, IdentityLookup};
use xcm::latest::prelude::*;
use xcm_builder::{AllowUnpaidExecutionFrom, FungiblesAdapter, MintLocation, NoChecking};

type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
type Balance = u64;
type AccountId = u64;
type AssetId = u128;

// For testing the pallet, we construct a mock runtime.
frame_support::construct_runtime!(
pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
pub enum Test
{
System: frame_system::{Pallet, Call, Config, Storage, Event<T>} = 10,
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
Assets: pallet_assets::{Pallet, Call, Storage, Event<T>},
PolkadotXcmGenericBenchmarks: pallet_xcm_benchmarks::generic::{Pallet},
PolkadotXcmFungibleBenchmarks: pallet_xcm_benchmarks::fungible::{Pallet},
XcmAssetsBenchmark: fungible::{Pallet},
XcmGenericBenchmarks: generic::{Pallet},
System: frame_system = 10,
Balances: pallet_balances,
Assets: pallet_assets,
PolkadotXcmGenericBenchmarks: pallet_xcm_benchmarks::generic,
PolkadotXcmFungibleBenchmarks: pallet_xcm_benchmarks::fungible,
XcmAssetsBenchmark: fungible,
XcmGenericBenchmarks: generic,
}
);

pub struct AccountIdConverter;
impl xcm_executor::traits::Convert<MultiLocation, u64> for AccountIdConverter {
fn convert(ml: MultiLocation) -> Result<u64, MultiLocation> {
impl xcm_executor::traits::ConvertLocation<u64> for AccountIdConverter {
fn convert_location(ml: &MultiLocation) -> Option<u64> {
match ml {
MultiLocation {
parents: 0,
interior: X1(Junction::AccountId32 { id, .. }),
} => Ok(<u64 as parity_scale_codec::Decode>::decode(&mut &*id.to_vec()).unwrap()),
_ => Err(ml),
} => <u64 as parity_scale_codec::Decode>::decode(&mut &*id.to_vec()).ok(),
_ => None,
}
}

fn reverse(acc: u64) -> Result<MultiLocation, u64> {
Err(acc)
}
}

// An xcm sender/receiver akin to > /dev/null
Expand Down Expand Up @@ -120,16 +109,15 @@ impl frame_system::Config for Test {
type BaseCallFilter = Everything;
type BlockWeights = ();
type BlockLength = ();
type Block = Block;
type DbWeight = ();
type RuntimeOrigin = RuntimeOrigin;
type Index = u64;
type BlockNumber = u64;
type Nonce = u64;
type Hash = H256;
type RuntimeCall = RuntimeCall;
type Hashing = BlakeTwo256;
type AccountId = AccountId;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = BlockHashCount;
type Version = ();
Expand Down Expand Up @@ -157,7 +145,7 @@ impl pallet_balances::Config for Test {
type ExistentialDeposit = ExistentialDeposit;
type AccountStore = System;
type WeightInfo = ();
type HoldIdentifier = ();
type RuntimeHoldReason = RuntimeHoldReason;
type FreezeIdentifier = ();
type MaxHolds = ConstU32<0>;
type MaxFreezes = ConstU32<0>;
Expand Down Expand Up @@ -257,6 +245,7 @@ impl xcm_executor::Config for XcmConfig {
type UniversalAliases = Nothing;
type CallDispatcher = RuntimeCall;
type SafeCallFilter = Everything;
type Aliasers = ();
}

impl pallet_xcm_benchmarks::Config for Test {
Expand Down Expand Up @@ -324,6 +313,10 @@ impl pallet_xcm_benchmarks::generic::Config for Test {
fn unlockable_asset() -> Result<(MultiLocation, MultiLocation, MultiAsset), BenchmarkError> {
Err(BenchmarkError::Skip)
}

fn alias_origin() -> Result<(MultiLocation, MultiLocation), BenchmarkError> {
Err(BenchmarkError::Skip)
}
}

parameter_types! {
Expand All @@ -335,6 +328,7 @@ impl pallet_xcm_benchmarks::fungible::Config for Test {
type TransactAsset = ItemOf<Assets, TransactAssetId, AccountId>;
type CheckedAccount = CheckingAccount;
type TrustedTeleporter = TrustedTeleporter;
type TrustedReserve = TrustedReserve;

fn get_multi_asset() -> MultiAsset {
let min_balance = 100u64;
Expand All @@ -361,17 +355,14 @@ parameter_types! {
pub TrustedReserve: Option<(MultiLocation, MultiAsset)> = Some((TrustedReserveLocation::get(), TrustedReserveAsset::get()));
}

impl fungible::Config for Test {
type TrustedReserve = TrustedReserve;
}

impl fungible::Config for Test {}
impl generic::Config for Test {}
impl Config for Test {}

#[cfg(feature = "runtime-benchmarks")]
pub fn new_test_ext() -> sp_io::TestExternalities {
use sp_runtime::BuildStorage;
let t = GenesisConfig {
let t = RuntimeGenesisConfig {
..Default::default()
}
.build_storage()
Expand Down
4 changes: 4 additions & 0 deletions pallets/block-rewards-hybrid/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ homepage.workspace = true
repository.workspace = true

[dependencies]
log = { workspace = true }
parity-scale-codec = { workspace = true }
serde = { workspace = true }

Expand All @@ -19,6 +20,7 @@ scale-info = { workspace = true }
sp-arithmetic = { workspace = true }
sp-runtime = { workspace = true }
sp-std = { workspace = true }
sp-io = { workspace = true }

frame-benchmarking = { workspace = true, optional = true }

Expand All @@ -34,7 +36,9 @@ std = [
"sp-core/std",
"scale-info/std",
"sp-std/std",
"sp-io/std",
"serde/std",
"log/std",
"frame-support/std",
"frame-system/std",
"pallet-timestamp/std",
Expand Down
2 changes: 1 addition & 1 deletion pallets/block-rewards-hybrid/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ mod benchmarks {
#[cfg(test)]
mod tests {
use crate::mock;
use frame_support::sp_io::TestExternalities;
use sp_io::TestExternalities;

pub fn new_test_ext() -> TestExternalities {
mock::ExternalityBuilder::build()
Expand Down
13 changes: 6 additions & 7 deletions pallets/block-rewards-hybrid/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,7 @@ pub use pallet::*;

use astar_primitives::Balance;
use frame_support::pallet_prelude::*;
use frame_support::{
log,
traits::{Currency, Get, Imbalance, OnTimestampSet},
};
use frame_support::traits::{Currency, Get, Imbalance, OnTimestampSet};
use frame_system::{ensure_root, pallet_prelude::*};
use sp_runtime::{
traits::{CheckedAdd, Zero},
Expand Down Expand Up @@ -155,13 +152,15 @@ pub mod pallet {
}

#[pallet::genesis_config]
#[cfg_attr(feature = "std", derive(Default))]
pub struct GenesisConfig {
#[derive(frame_support::DefaultNoBound)]
pub struct GenesisConfig<T: Config> {
pub reward_config: RewardDistributionConfig,
#[serde(skip)]
pub _config: sp_std::marker::PhantomData<T>,
}

#[pallet::genesis_build]
impl<T: Config> GenesisBuild<T> for GenesisConfig {
impl<T: Config> BuildGenesisConfig for GenesisConfig<T> {
fn build(&self) {
assert!(self.reward_config.is_consistent());
RewardDistributionConfigStorage::<T>::put(self.reward_config.clone())
Expand Down
Loading

0 comments on commit 2b2da4a

Please sign in to comment.