Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
1da1683
Update dependencies to v0.9.38
sea212 Aug 20, 2023
398d8f7
More dependency updates
sea212 Aug 20, 2023
ab47324
Update standalone runtimes
sea212 Aug 20, 2023
2a60e3c
Fix build with feature runtime-benchmark
sea212 Aug 21, 2023
2fd134e
Update Zeitgeist parachain runtime
sea212 Aug 21, 2023
45b86e7
Update Battery Station parachain runtime
sea212 Aug 22, 2023
3237a78
Deduplicated dependencies
sea212 Aug 22, 2023
5ce5bb8
Make tests succeed for parachain runtime
sea212 Aug 22, 2023
37d6aee
Partially fix Zeitgeist xcm tests
sea212 Aug 22, 2023
2ad2d88
Make all runtime tests succeed
sea212 Aug 23, 2023
4089ecd
Update standalone client
sea212 Aug 23, 2023
504d3f1
Update parachain node
sea212 Aug 23, 2023
6a6f9ea
Add migrations
sea212 Aug 23, 2023
2d54592
Cargo fmt
sea212 Aug 23, 2023
b11c260
Satisfy Clippy
sea212 Aug 23, 2023
30af891
Cargo fmt
sea212 Aug 23, 2023
21ce803
Taplo format
sea212 Aug 23, 2023
9646a85
Update licenses
sea212 Aug 23, 2023
fe589a5
Reduce runtime test dependencies by half
sea212 Aug 23, 2023
41d09c5
Add missing runtime-benchmark feature
sea212 Aug 23, 2023
ab0e64a
Use upper case copyright name
sea212 Aug 23, 2023
2599c7d
Remove test logger
sea212 Aug 23, 2023
c684f28
Revert "Reduce runtime test dependencies by half"
sea212 Aug 24, 2023
9ad7516
Update weight templates
sea212 Aug 24, 2023
a4a7648
Use header option for benchmarks
sea212 Aug 24, 2023
c586c61
Update rust-toolchain
sea212 Aug 24, 2023
4d0cc4d
Satisfy clippy
sea212 Aug 25, 2023
abd7ed5
Use patched wasm-builder for new rustc
sea212 Aug 25, 2023
a3a18db
Format
sea212 Aug 25, 2023
9dd8010
Update licenses
sea212 Aug 25, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update Zeitgeist parachain runtime
  • Loading branch information
sea212 committed Aug 21, 2023
commit 2fd134e50fea8bf36f4d1594c505f98fcdf76ba6
82 changes: 57 additions & 25 deletions runtime/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,9 @@ macro_rules! impl_config_traits {
type ChannelInfo = ParachainSystem;
type ControllerOrigin = EnsureRootOrTwoThirdsTechnicalCommittee;
type ControllerOriginConverter = XcmOriginToTransactDispatchOrigin;
type RuntimeEvent = RuntimeEvent;
type ExecuteOverweightOrigin = EnsureRootOrHalfTechnicalCommittee;
type PriceForSiblingDelivery = ();
type RuntimeEvent = RuntimeEvent;
type VersionWrapper = ();
type WeightInfo = weights::cumulus_pallet_xcmp_queue::WeightInfo<Runtime>;
type XcmExecutor = xcm_executor::XcmExecutor<XcmConfig>;
Expand Down Expand Up @@ -479,20 +480,29 @@ macro_rules! impl_config_traits {

#[cfg(feature = "parachain")]
impl pallet_xcm::Config for Runtime {
type ExecuteXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
type RuntimeCall = RuntimeCall;
type RuntimeEvent = RuntimeEvent;
type RuntimeOrigin = RuntimeOrigin;
type SendXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
type XcmRouter = XcmRouter;
type ExecuteXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
type UniversalLocation = UniversalLocation;
type Weigher = FixedWeightBounds<UnitWeightCost, RuntimeCall, MaxInstructions>;
type XcmExecuteFilter = Nothing;
// ^ Disable dispatchable execute on the XCM pallet.
// Needs to be `Everything` for local testing.
type XcmExecutor = xcm_executor::XcmExecutor<XcmConfig>;
type XcmTeleportFilter = Everything;
type XcmReserveTransferFilter = Nothing;
type Weigher = FixedWeightBounds<UnitWeightCost, RuntimeCall, MaxInstructions>;
type LocationInverter = LocationInverter<Ancestry>;
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type XcmRouter = XcmRouter;

type Currency = Balances;
type CurrencyMatcher = ();
type TrustedLockers = ();
type SovereignAccountOf = LocationToAccountId;
type MaxLockers = ConstU32<8>;
type WeightInfo = pallet_xcm::TestWeightInfo;
#[cfg(feature = "runtime-benchmarks")]
type ReachableDest = ReachableDest;

const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;
// ^ Override for AdvertisedXcmVersion default
Expand Down Expand Up @@ -583,12 +593,12 @@ macro_rules! impl_config_traits {
type CurrencyId = CurrencyId;
type CurrencyIdConvert = AssetConvert;
type RuntimeEvent = RuntimeEvent;
type LocationInverter = LocationInverter<Ancestry>;
type MaxAssetsForTransfer = MaxAssetsForTransfer;
type MinXcmFee = ParachainMinFee;
type MultiLocationsFilter = Everything;
type ReserveProvider = orml_traits::location::AbsoluteReserveProvider;
type SelfLocation = SelfLocation;
type UniversalLocation = UniversalLocation;
type Weigher = FixedWeightBounds<UnitWeightCost, RuntimeCall, MaxInstructions>;
type XcmExecutor = xcm_executor::XcmExecutor<XcmConfig>;
}
Expand Down Expand Up @@ -1327,23 +1337,45 @@ macro_rules! create_runtime_api {
impl BaselineConfig for Runtime {}

let whitelist: Vec<TrackedStorageKey> = vec![
hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac")
.to_vec()
.into(),
hex_literal::hex!("c2261276cc9d1f8598ea4b6a74b15c2f57c875e4cff74148e4628f264b974c80")
.to_vec()
.into(),
hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef7ff553b5a9862a516939d82b3d3d8661a")
.to_vec()
.into(),
hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef70a98fdbe9ce6c55837576c60c7af3850")
.to_vec()
.into(),
hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7")
.to_vec()
.into(),
hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef7b99d880ec681799c0cf30e8886371da946c154ffd9992e395af90b5b13cc6f295c77033fce8a9045824a6690bbf99c6db269502f0a8d1d2a008542d5690a0749").to_vec().into(),
hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef7b99d880ec681799c0cf30e8886371da95ecffd7b6c0f78751baa9d281e0bfa3a6d6f646c70792f74727372790000000000000000000000000000000000000000").to_vec().into(),
// Block Number
hex_literal::hex!( "26aa394eea5630e07c48ae0c9558cef7"
"02a5c1b19ab7a04f536c519aca4983ac")
.to_vec().into(),
// Total Issuance
hex_literal::hex!( "c2261276cc9d1f8598ea4b6a74b15c2f"
"57c875e4cff74148e4628f264b974c80")
.to_vec().into(),
// Execution Phase
hex_literal::hex!( "26aa394eea5630e07c48ae0c9558cef7"
"ff553b5a9862a516939d82b3d3d8661a")
.to_vec().into(),
// Event Count
hex_literal::hex!( "26aa394eea5630e07c48ae0c9558cef7"
"0a98fdbe9ce6c55837576c60c7af3850")
.to_vec().into(),
// System Events
hex_literal::hex!( "26aa394eea5630e07c48ae0c9558cef7"
"80d41e5e16056765bc8461851072c9d7")
.to_vec().into(),
// System BlockWeight
hex_literal::hex!( "26aa394eea5630e07c48ae0c9558cef7"
"34abf5cb34d6244378cddbf18e849d96")
.to_vec().into(),
// ParachainStaking Round
hex_literal::hex!( "a686a3043d0adcf2fa655e57bc595a78"
"13792e785168f725b60e2969c7fc2552")
.to_vec().into(),
// Treasury Account (zhe/tsry)
hex_literal::hex!( "26aa394eea5630e07c48ae0c9558cef7"
"b99d880ec681799c0cf30e8886371da9"
"7be2919ac397ba499ea5e57132180ec6"
"6d6f646c7a67652f7473727900000000"
"00000000000000000000000000000000"
).to_vec().into(),
// ParachainInfo ParachainId
hex_literal::hex!( "0d715f2646c8f85767b5d2764bb27826"
"04a74d81251e398fd8a0a4d55023bb3f")
.to_vec().into(),
];

let mut batches = Vec::<BenchmarkBatch>::new();
Expand Down
2 changes: 1 addition & 1 deletion runtime/zeitgeist/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ use zrml_rikiddo::types::{EmaMarketVolume, FeeSigmoid, RikiddoSigmoidMV};
#[cfg(feature = "parachain")]
use {
frame_support::traits::{AsEnsureOriginWithArg, Everything},
xcm_builder::{EnsureXcmOrigin, FixedWeightBounds, LocationInverter},
xcm_builder::{EnsureXcmOrigin, FixedWeightBounds},
xcm_config::{
asset_registry::CustomAssetProcessor,
config::{LocalOriginToLocation, XcmConfig, XcmOriginToTransactDispatchOrigin, XcmRouter},
Expand Down
27 changes: 19 additions & 8 deletions runtime/zeitgeist/src/parachain_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,24 @@ use super::{parameters::MAXIMUM_BLOCK_WEIGHT, ParachainInfo, RuntimeOrigin};
use frame_support::{parameter_types, weights::Weight};
use orml_traits::parameter_type_with_key;
use sp_runtime::{Perbill, Percent};
use xcm::latest::{prelude::X1, Junction::Parachain, MultiLocation, NetworkId};
use xcm::latest::{prelude::{X1, X2, GlobalConsensus, InteriorMultiLocation}, Junction::Parachain, MultiLocation, NetworkId};
use zeitgeist_primitives::{
constants::{BASE, BLOCKS_PER_MINUTE},
types::Balance,
};

parameter_types! {
// Author-Mapping
/// The amount that should be taken as a security deposit when registering a NimbusId.
/// The amount that should be taken as a security deposit when registering a NimbusId
pub const CollatorDeposit: Balance = 2 * BASE;

// Cumulus and Polkadot
pub Ancestry: MultiLocation = Parachain(ParachainInfo::parachain_id().into()).into();
pub const RelayLocation: MultiLocation = MultiLocation::parent();
pub const RelayNetwork: NetworkId = NetworkId::Polkadot;
pub const ReservedDmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT.saturating_div(4);
pub const ReservedXcmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT.saturating_div(4);
pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into();
pub UnitWeightCost: u64 = 200_000_000;
pub UnitWeightCost: Weight = Weight::from_parts(200_000_000u64, 0);


// Staking
/// Rounds before the candidate bond increase/decrease can be executed
Expand Down Expand Up @@ -83,14 +82,26 @@ parameter_types! {

// XCM
/// Base weight for XCM execution
pub const BaseXcmWeight: u64 = 200_000_000;
pub const BaseXcmWeight: Weight = Weight::from_parts(200_000_000u64, 0);
/// The maximum number of distinct assets allowed to be transferred in a
/// single helper extrinsic.
/// single helper extrinsic
pub const MaxAssetsForTransfer: usize = 2;
/// Maximum amount of tokens the holding register can store
pub const MaxAssetsIntoHolding: u32 = 64;
/// Max instructions per XCM
pub const MaxInstructions: u32 = 100;
// Relative self location

/// Relative self location
pub SelfLocation: MultiLocation = MultiLocation::new(1, X1(Parachain(ParachainInfo::parachain_id().into())));
/// This chain's Universal Location
pub UniversalLocation: InteriorMultiLocation = X2(GlobalConsensus(RelayNetwork::get()), Parachain(ParachainInfo::parachain_id().into())).into();
}

#[cfg(feature = "runtime-benchmarks")]
parameter_types! {
// XCM
/// A `MultiLocation` that can be reached via `XcmRouter`. Used only in benchmarks.
pub ReachableDest: Option<MultiLocation> = Some(xcm::latest::prelude::Parent.into());
}

parameter_type_with_key! {
Expand Down
88 changes: 65 additions & 23 deletions runtime/zeitgeist/src/xcm_config/config.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright 2022-2023 Forecasting Technologies LTD.
// Copyright 2023 Centrifuge Foundation (centrifuge.io).
//
// This file is part of Zeitgeist.
//
Expand All @@ -17,16 +18,16 @@

use super::fees::{native_per_second, FixedConversionRateProvider};
use crate::{
AccountId, Ancestry, AssetManager, AssetRegistry, Balance, CurrencyId, MaxInstructions,
AccountId, AssetManager, AssetRegistry, Balance, CurrencyId, MaxInstructions,
ParachainInfo, ParachainSystem, PolkadotXcm, RelayChainOrigin, RelayNetwork, RuntimeCall,
RuntimeOrigin, UnitWeightCost, UnknownTokens, XcmpQueue, ZeitgeistTreasuryAccount,
RuntimeOrigin, UnitWeightCost, UnknownTokens, XcmpQueue, ZeitgeistTreasuryAccount,UniversalLocation,MaxAssetsIntoHolding
};

use core::marker::PhantomData;
use alloc::vec::Vec;
use core::{cmp::min, marker::PhantomData};
use frame_support::{
parameter_types,
traits::{ConstU8, Everything, Get},
WeakBoundedVec,
traits::{ConstU8, Everything, Nothing, Get},
};
use orml_asset_registry::{AssetRegistryTrader, FixedRateAssetRegistryTrader};
use orml_traits::{asset_registry::Inspect, location::AbsoluteReserveProvider, MultiCurrency};
Expand All @@ -38,14 +39,14 @@ use polkadot_parachain::primitives::Sibling;
use sp_runtime::traits::Convert;
use xcm::{
latest::{
prelude::{AccountId32, AssetId, Concrete, GeneralKey, MultiAsset, NetworkId, X1, X2},
prelude::{XcmContext, AccountId32, AssetId, Concrete, GeneralKey, MultiAsset, X1, X2},
Error as XcmError, Junction, MultiLocation, Result as XcmResult,
},
opaque::latest::Fungibility::Fungible,
};
use xcm_builder::{
AccountId32Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom,
AllowTopLevelPaidExecutionFrom, FixedRateOfFungible, FixedWeightBounds, LocationInverter,
AllowTopLevelPaidExecutionFrom, FixedRateOfFungible, FixedWeightBounds,
ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia,
SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeRevenue,
TakeWeightCredit,
Expand Down Expand Up @@ -81,8 +82,6 @@ impl Config for XcmConfig {
type IsReserve = MultiNativeAsset<AbsoluteReserveProvider>;
/// Combinations of (Location, Asset) pairs which we trust as teleporters.
type IsTeleporter = ();
/// Means of inverting a location.
type LocationInverter = LocationInverter<Ancestry>;
/// How to get a call origin from a `OriginKind` value.
type OriginConverter = XcmOriginToTransactDispatchOrigin;
/// Module that handles responses of queries.
Expand All @@ -91,12 +90,33 @@ impl Config for XcmConfig {
type SubscriptionService = PolkadotXcm;
/// The means of purchasing weight credit for XCM execution.
type Trader = Trader;
/// This chain's Universal Location.
type UniversalLocation = UniversalLocation;
/// The means of determining an XCM message's weight.
// Adds UnitWeightCost per instruction plus the weight of each instruction.
// The total number of instructions are bounded by MaxInstructions
type Weigher = FixedWeightBounds<UnitWeightCost, RuntimeCall, MaxInstructions>;
/// How to send an onward XCM message.
type XcmSender = XcmRouter;
/// XCM will use this to dispatch any calls
type CallDispatcher = RuntimeCall;
/// Information on all pallets.
type PalletInstancesInfo = crate::AllPalletsWithSystem;
/// Maximum amount of tokens the holding register can store
type MaxAssetsIntoHolding = MaxAssetsIntoHolding;
/// Handler for asset locking.
type AssetLocker = ();
/// Handler for exchanging assets.
type AssetExchanger = ();
/// Configure the fees.
type FeeManager = ();
/// The method of exporting a message.
type MessageExporter = ();
/// The origin locations and specific universal junctions to which they are allowed to elevate
/// themselves.
type UniversalAliases = Nothing;
/// The safe call filter for `Transact`.
type SafeCallFilter = Nothing;
}

/// Additional filters that specify whether the XCM instruction should be executed at all.
Expand Down Expand Up @@ -146,20 +166,22 @@ impl TakeRevenue for ToTreasury {
parameter_types! {
pub CheckAccount: AccountId = PolkadotXcm::check_account();
/// The amount of ZTG charged per second of execution (canonical multilocation).
pub ZtgPerSecondCanonical: (AssetId, u128) = (
pub ZtgPerSecondCanonical: (AssetId, u128, u128) = (
MultiLocation::new(
0,
X1(general_key(zeitgeist::KEY)),
).into(),
native_per_second(),
0
);
/// The amount of ZTG charged per second of execution.
pub ZtgPerSecond: (AssetId, u128) = (
pub ZtgPerSecond: (AssetId, u128, u128) = (
MultiLocation::new(
1,
X2(Junction::Parachain(ParachainInfo::parachain_id().into()), general_key(zeitgeist::KEY)),
).into(),
native_per_second(),
0
);
}

Expand Down Expand Up @@ -238,23 +260,24 @@ impl<
TransactAssetDelegate,
>
{
fn deposit_asset(asset: &MultiAsset, location: &MultiLocation) -> XcmResult {
fn deposit_asset(asset: &MultiAsset, location: &MultiLocation, context: &XcmContext) -> XcmResult {
let asset_adjusted = Self::adjust_fractional_places(asset);
TransactAssetDelegate::deposit_asset(&asset_adjusted, location)
TransactAssetDelegate::deposit_asset(&asset_adjusted, location, context)
}

fn withdraw_asset(asset: &MultiAsset, location: &MultiLocation) -> Result<Assets, XcmError> {
fn withdraw_asset(asset: &MultiAsset, location: &MultiLocation, maybe_context: Option<&XcmContext>) -> Result<Assets, XcmError> {
let asset_adjusted = Self::adjust_fractional_places(asset);
TransactAssetDelegate::withdraw_asset(&asset_adjusted, location)
TransactAssetDelegate::withdraw_asset(&asset_adjusted, location, maybe_context)
}

fn transfer_asset(
asset: &MultiAsset,
from: &MultiLocation,
to: &MultiLocation,
context: &XcmContext
) -> Result<Assets, XcmError> {
let asset_adjusted = Self::adjust_fractional_places(asset);
TransactAssetDelegate::transfer_asset(&asset_adjusted, from, to)
TransactAssetDelegate::transfer_asset(&asset_adjusted, from, to, context)
}
}

Expand Down Expand Up @@ -317,7 +340,9 @@ impl Convert<CurrencyId, Option<MultiLocation>> for AssetConvert {
impl xcm_executor::traits::Convert<MultiLocation, CurrencyId> for AssetConvert {
fn convert(location: MultiLocation) -> Result<CurrencyId, MultiLocation> {
match location.clone() {
MultiLocation { parents: 0, interior: X1(GeneralKey(key)) } => {
MultiLocation { parents: 0, interior: X1(GeneralKey { data, length }) } => {
let key = &data[..data.len().min(length as usize)];

if &key[..] == zeitgeist::KEY {
return Ok(CurrencyId::Ztg);
}
Expand All @@ -326,8 +351,10 @@ impl xcm_executor::traits::Convert<MultiLocation, CurrencyId> for AssetConvert {
}
MultiLocation {
parents: 1,
interior: X2(Junction::Parachain(para_id), GeneralKey(key)),
interior: X2(Junction::Parachain(para_id), GeneralKey { data, length }),
} => {
let key = &data[..data.len().min(length as usize)];

if para_id == u32::from(ParachainInfo::parachain_id()) {
if &key[..] == zeitgeist::KEY {
return Ok(CurrencyId::Ztg);
Expand Down Expand Up @@ -363,7 +390,7 @@ pub struct AccountIdToMultiLocation;

impl Convert<AccountId, MultiLocation> for AccountIdToMultiLocation {
fn convert(account: AccountId) -> MultiLocation {
X1(AccountId32 { network: NetworkId::Any, id: account.into() }).into()
X1(AccountId32 { network: None, id: account.into() }).into()
}
}

Expand Down Expand Up @@ -407,12 +434,27 @@ pub type XcmOriginToTransactDispatchOrigin = (
/// queues.
pub type XcmRouter = (
// Two routers - use UMP to communicate with the relay chain:
cumulus_primitives_utility::ParentAsUmp<ParachainSystem, ()>,
cumulus_primitives_utility::ParentAsUmp<ParachainSystem, PolkadotXcm, ()>,
// ..and XCMP to communicate with the sibling chains.
XcmpQueue,
);

#[inline]
pub(crate) fn general_key(key: &[u8]) -> Junction {
GeneralKey(WeakBoundedVec::force_from(key.to_vec(), None))
/// Build a fixed-size array using as many elements from `src` as possible
/// without overflowing and ensuring that the array is 0 padded in the case
/// where `src.len()` is smaller than S.
fn vec_to_fixed_array<const S: usize>(src: Vec<u8>) -> [u8; S] {
let mut dest = [0; S];
let len = min(src.len(), S);
dest[..len].copy_from_slice(&src.as_slice()[..len]);

dest
}

/// A utils function to un-bloat and simplify the instantiation of
/// `GeneralKey` values
pub fn general_key(data: &[u8]) -> Junction {
GeneralKey {
length: data.len().min(32) as u8,
data: vec_to_fixed_array(data.to_vec()),
}
}