Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'origin/master' into bkchr-benchmarking-cli
Browse files Browse the repository at this point in the history
  • Loading branch information
bkchr committed Jun 28, 2023
2 parents 5893f62 + 52595c8 commit bddd3ca
Show file tree
Hide file tree
Showing 15 changed files with 334 additions and 19 deletions.
193 changes: 189 additions & 4 deletions Cargo.lock

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions runtime/kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
//! The Kusama runtime. This can be compiled with `#[no_std]`, ready for Wasm.

#![cfg_attr(not(feature = "std"), no_std)]
// `construct_runtime!` does a lot of recursion and requires us to increase the limit to 256.
#![recursion_limit = "256"]
// `construct_runtime!` does a lot of recursion and requires us to increase the limit.
#![recursion_limit = "512"]

use pallet_nis::WithMaximumOf;
use parity_scale_codec::{Decode, Encode, MaxEncodedLen};
Expand Down Expand Up @@ -1145,6 +1145,7 @@ impl pallet_message_queue::Config for Runtime {
type MessageProcessor =
pallet_message_queue::mock_helpers::NoopMessageProcessor<AggregateMessageOrigin>;
type QueueChangeHandler = ParaInclusion;
type QueuePausedQuery = ();
type WeightInfo = weights::pallet_message_queue::WeightInfo<Runtime>;
}

Expand Down
9 changes: 7 additions & 2 deletions runtime/kusama/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ use xcm_builder::{
ChildParachainConvertsVia, ChildSystemParachainAsSuperuser,
CurrencyAdapter as XcmCurrencyAdapter, FixedWeightBounds, IsChildSystemParachain, IsConcrete,
MintLocation, OriginToPluralityVoice, SignedAccountId32AsNative, SignedToAccountId32,
SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, UsingComponents,
WeightInfoBounds, WithComputedOrigin, WithUniqueTopic,
SovereignSignedViaLocation, TakeWeightCredit, TinkernetMultisigAsAccountId,
TinkernetMultisigAsNative, TrailingSetTopicAsId, UsingComponents, WeightInfoBounds,
WithComputedOrigin, WithUniqueTopic,
};
use xcm_executor::traits::WithOriginFilter;

Expand Down Expand Up @@ -70,6 +71,8 @@ pub type SovereignAccountOf = (
ChildParachainConvertsVia<ParaId, AccountId>,
// We can directly alias an `AccountId32` into a local account.
AccountId32Aliases<ThisNetwork, AccountId>,
// We can derive a local account from a Tinkernet XCMultisig MultiLocation.
TinkernetMultisigAsAccountId<AccountId>,
);

/// Our asset transactor. This is what allows us to interest with the runtime facilities from the point of
Expand Down Expand Up @@ -99,6 +102,8 @@ type LocalOriginConverter = (
SignedAccountId32AsNative<ThisNetwork, RuntimeOrigin>,
// A system child parachain, expressed as a Superuser, converts to the `Root` origin.
ChildSystemParachainAsSuperuser<ParaId, RuntimeOrigin>,
// Converts a Tinkernet XCMultisig MultiLocation into a `Signed` origin.
TinkernetMultisigAsNative<RuntimeOrigin>,
);

parameter_types! {
Expand Down
1 change: 1 addition & 0 deletions runtime/parachains/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ impl pallet_message_queue::Config for Test {
type WeightInfo = TestMessageQueueWeight;
type MessageProcessor = TestProcessMessage;
type QueueChangeHandler = ParaInclusion;
type QueuePausedQuery = ();
type HeapSize = ConstU32<65536>;
type MaxStale = ConstU32<8>;
type ServiceWeight = MessageQueueServiceWeight;
Expand Down
12 changes: 10 additions & 2 deletions runtime/parachains/src/ump_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -573,13 +573,21 @@ fn overweight_queue_works() {
.into(),
);

// ... and if we try to service a message with index that doesn't exist it will error
// out.
// But servicing again will not work.
assert_noop!(
<MessageQueue as ServiceQueues>::execute_overweight(
Weight::from_parts(501, 501),
(Ump(UmpQueueId::Para(para_a)), 0, 2)
),
ExecuteOverweightError::AlreadyProcessed,
);

// Using an invalid index does not work.
assert_noop!(
<MessageQueue as ServiceQueues>::execute_overweight(
Weight::from_parts(501, 501),
(Ump(UmpQueueId::Para(para_a)), 0, 3)
),
ExecuteOverweightError::NotFound,
);
});
Expand Down
3 changes: 2 additions & 1 deletion runtime/polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

#![cfg_attr(not(feature = "std"), no_std)]
// `construct_runtime!` does a lot of recursion and requires us to increase the limit to 256.
#![recursion_limit = "256"]
#![recursion_limit = "512"]

use pallet_transaction_payment::CurrencyAdapter;
use runtime_common::{
Expand Down Expand Up @@ -1161,6 +1161,7 @@ impl pallet_message_queue::Config for Runtime {
type MessageProcessor =
pallet_message_queue::mock_helpers::NoopMessageProcessor<AggregateMessageOrigin>;
type QueueChangeHandler = ParaInclusion;
type QueuePausedQuery = ();
type WeightInfo = weights::pallet_message_queue::WeightInfo<Runtime>;
}

Expand Down
5 changes: 3 additions & 2 deletions runtime/rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
//! The Rococo runtime for v1 parachains.

#![cfg_attr(not(feature = "std"), no_std)]
// `construct_runtime!` does a lot of recursion and requires us to increase the limit to 256.
#![recursion_limit = "256"]
// `construct_runtime!` does a lot of recursion and requires us to increase the limit.
#![recursion_limit = "512"]

use pallet_nis::WithMaximumOf;
use parity_scale_codec::{Decode, Encode, MaxEncodedLen};
Expand Down Expand Up @@ -1076,6 +1076,7 @@ impl pallet_message_queue::Config for Runtime {
type MessageProcessor =
pallet_message_queue::mock_helpers::NoopMessageProcessor<AggregateMessageOrigin>;
type QueueChangeHandler = ParaInclusion;
type QueuePausedQuery = ();
type WeightInfo = weights::pallet_message_queue::WeightInfo<Runtime>;
}

Expand Down
14 changes: 10 additions & 4 deletions runtime/rococo/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ use xcm_builder::{
ChildParachainAsNative, ChildParachainConvertsVia, ChildSystemParachainAsSuperuser,
CurrencyAdapter as XcmCurrencyAdapter, FixedWeightBounds, IsChildSystemParachain, IsConcrete,
MintLocation, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation,
TakeWeightCredit, TrailingSetTopicAsId, UsingComponents, WeightInfoBounds, WithComputedOrigin,
WithUniqueTopic,
TakeWeightCredit, TinkernetMultisigAsAccountId, TinkernetMultisigAsNative,
TrailingSetTopicAsId, UsingComponents, WeightInfoBounds, WithComputedOrigin, WithUniqueTopic,
};
use xcm_executor::{traits::WithOriginFilter, XcmExecutor};

Expand All @@ -53,8 +53,12 @@ parameter_types! {
pub LocalCheckAccount: (AccountId, MintLocation) = (CheckAccount::get(), MintLocation::Local);
}

pub type LocationConverter =
(ChildParachainConvertsVia<ParaId, AccountId>, AccountId32Aliases<ThisNetwork, AccountId>);
pub type LocationConverter = (
ChildParachainConvertsVia<ParaId, AccountId>,
AccountId32Aliases<ThisNetwork, AccountId>,
// We can derive a local account from a Tinkernet XCMultisig MultiLocation.
TinkernetMultisigAsAccountId<AccountId>,
);

/// Our asset transactor. This is what allows us to interest with the runtime facilities from the point of
/// view of XCM-only concepts like `MultiLocation` and `MultiAsset`.
Expand Down Expand Up @@ -83,6 +87,8 @@ type LocalOriginConverter = (
SignedAccountId32AsNative<ThisNetwork, RuntimeOrigin>,
// A system child parachain, expressed as a Superuser, converts to the `Root` origin.
ChildSystemParachainAsSuperuser<ParaId, RuntimeOrigin>,
// Converts a Tinkernet XCMultisig MultiLocation into a `Signed` origin.
TinkernetMultisigAsNative<RuntimeOrigin>,
);

parameter_types! {
Expand Down
1 change: 1 addition & 0 deletions runtime/westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -974,6 +974,7 @@ impl pallet_message_queue::Config for Runtime {
type MessageProcessor =
pallet_message_queue::mock_helpers::NoopMessageProcessor<AggregateMessageOrigin>;
type QueueChangeHandler = ParaInclusion;
type QueuePausedQuery = ();
type WeightInfo = weights::pallet_message_queue::WeightInfo<Runtime>;
}

Expand Down
2 changes: 2 additions & 0 deletions xcm/xcm-builder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ sp-std = { git = "https://github.com/paritytech/substrate", branch = "master", d
sp-arithmetic = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
sp-io = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
sp-weights = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
frame-support = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
frame-system = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
Expand Down Expand Up @@ -49,6 +50,7 @@ std = [
"sp-arithmetic/std",
"sp-io/std",
"sp-runtime/std",
"sp-core/std",
"sp-weights/std",
"frame-support/std",
"frame-system/std",
Expand Down
4 changes: 2 additions & 2 deletions xcm/xcm-builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ pub use location_conversion::{
ChildParachainConvertsVia, DescribeAccountId32Terminal, DescribeAccountIdTerminal,
DescribeAccountKey20Terminal, DescribeAllTerminal, DescribeFamily, DescribeLocation,
DescribePalletTerminal, DescribeTerminus, GlobalConsensusParachainConvertsFor,
HashedDescription, ParentIsPreset, SiblingParachainConvertsVia,
HashedDescription, ParentIsPreset, SiblingParachainConvertsVia, TinkernetMultisigAsAccountId,
};

mod origin_conversion;
pub use origin_conversion::{
BackingToPlurality, ChildParachainAsNative, ChildSystemParachainAsSuperuser, EnsureXcmOrigin,
OriginToPluralityVoice, ParentAsSuperuser, RelayChainAsNative, SiblingParachainAsNative,
SiblingSystemParachainAsSuperuser, SignedAccountId32AsNative, SignedAccountKey20AsNative,
SignedToAccountId32, SovereignSignedViaLocation,
SignedToAccountId32, SovereignSignedViaLocation, TinkernetMultisigAsNative,
};

mod asset_conversion;
Expand Down
67 changes: 67 additions & 0 deletions xcm/xcm-builder/src/location_conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use crate::universal_exports::ensure_is_remote;
use frame_support::traits::Get;
use parity_scale_codec::{Compact, Decode, Encode};
use sp_core::H256;
use sp_io::hashing::blake2_256;
use sp_runtime::traits::{AccountIdConversion, Convert, TrailingZeroInput};
use sp_std::{marker::PhantomData, prelude::*};
Expand Down Expand Up @@ -345,6 +346,52 @@ impl<Network: Get<Option<NetworkId>>, AccountId: From<[u8; 20]> + Into<[u8; 20]>
}
}

/// Tinkernet ParaId used when matching Multisig MultiLocations.
pub const KUSAMA_TINKERNET_PARA_ID: u32 = 2125;

/// Tinkernet Multisig pallet instance used when matching Multisig MultiLocations.
pub const KUSAMA_TINKERNET_MULTISIG_PALLET: u8 = 71;

/// Constant derivation function for Tinkernet Multisigs.
/// Uses the Tinkernet genesis hash as a salt.
pub fn derive_tinkernet_multisig<AccountId: Decode>(id: u128) -> Result<AccountId, ()> {
AccountId::decode(&mut TrailingZeroInput::new(
&(
// The constant salt used to derive Tinkernet Multisigs, this is Tinkernet's genesis hash.
H256([
212, 46, 150, 6, 169, 149, 223, 228, 51, 220, 121, 85, 220, 42, 112, 244, 149, 243,
80, 243, 115, 218, 162, 0, 9, 138, 232, 68, 55, 129, 106, 210,
]),
// The actual multisig integer id.
u32::try_from(id).map_err(|_| ())?,
)
.using_encoded(blake2_256),
))
.map_err(|_| ())
}

/// Convert a Tinkernet Multisig `MultiLocation` value into a local `AccountId`.
pub struct TinkernetMultisigAsAccountId<AccountId>(PhantomData<AccountId>);
impl<AccountId: Decode + Clone> ConvertLocation<AccountId>
for TinkernetMultisigAsAccountId<AccountId>
{
fn convert_location(location: &MultiLocation) -> Option<AccountId> {
match location {
MultiLocation {
parents: _,
interior:
X3(
Parachain(KUSAMA_TINKERNET_PARA_ID),
PalletInstance(KUSAMA_TINKERNET_MULTISIG_PALLET),
// Index from which the multisig account is derived.
GeneralIndex(id),
),
} => derive_tinkernet_multisig(*id).ok(),
_ => None,
}
}
}

/// Converts a location which is a top-level parachain (i.e. a parachain held on a
/// Relay-chain which provides its own consensus) into a 32-byte `AccountId`.
///
Expand Down Expand Up @@ -789,4 +836,24 @@ mod tests {
};
assert!(ForeignChainAliasAccount::<[u8; 32]>::convert_location(&mul).is_none());
}

#[test]
fn remote_tinkernet_multisig_convert_to_account() {
let mul = MultiLocation {
parents: 0,
interior: X3(
Parachain(KUSAMA_TINKERNET_PARA_ID),
PalletInstance(KUSAMA_TINKERNET_MULTISIG_PALLET),
GeneralIndex(0),
),
};

assert_eq!(
[
97, 160, 244, 60, 133, 145, 170, 26, 202, 108, 203, 156, 114, 116, 175, 30, 156,
195, 43, 101, 243, 51, 193, 162, 152, 188, 30, 165, 244, 81, 70, 90
],
TinkernetMultisigAsAccountId::<[u8; 32]>::convert_location(&mul).unwrap()
);
}
}
35 changes: 35 additions & 0 deletions xcm/xcm-builder/src/origin_conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@

//! Various implementations for `ConvertOrigin`.

use crate::location_conversion::{
derive_tinkernet_multisig, KUSAMA_TINKERNET_MULTISIG_PALLET, KUSAMA_TINKERNET_PARA_ID,
};
use frame_support::traits::{EnsureOrigin, Get, GetBacking, OriginTrait};
use frame_system::RawOrigin as SystemRawOrigin;
use parity_scale_codec::Decode;
use polkadot_parachain::primitives::IsSystem;
use sp_runtime::traits::TryConvert;
use sp_std::marker::PhantomData;
Expand Down Expand Up @@ -241,6 +245,37 @@ where
}
}

/// Convert a Tinkernet Multisig `MultiLocation` value into a `Signed` origin.
pub struct TinkernetMultisigAsNative<RuntimeOrigin>(PhantomData<RuntimeOrigin>);
impl<RuntimeOrigin: OriginTrait> ConvertOrigin<RuntimeOrigin>
for TinkernetMultisigAsNative<RuntimeOrigin>
where
RuntimeOrigin::AccountId: Decode,
{
fn convert_origin(
origin: impl Into<MultiLocation>,
kind: OriginKind,
) -> Result<RuntimeOrigin, MultiLocation> {
let origin = origin.into();
match (kind, origin) {
(
OriginKind::Native,
MultiLocation {
parents: _,
interior:
X3(
Junction::Parachain(KUSAMA_TINKERNET_PARA_ID),
Junction::PalletInstance(KUSAMA_TINKERNET_MULTISIG_PALLET),
// Index from which the multisig account is derived.
Junction::GeneralIndex(id),
),
},
) => Ok(RuntimeOrigin::signed(derive_tinkernet_multisig(id).map_err(|_| origin)?)),
(_, origin) => Err(origin),
}
}
}

/// `EnsureOrigin` barrier to convert from dispatch origin to XCM origin, if one exists.
pub struct EnsureXcmOrigin<RuntimeOrigin, Conversion>(PhantomData<(RuntimeOrigin, Conversion)>);
impl<RuntimeOrigin: OriginTrait + Clone, Conversion: TryConvert<RuntimeOrigin, MultiLocation>>
Expand Down
1 change: 1 addition & 0 deletions xcm/xcm-simulator/example/src/relay_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ impl pallet_message_queue::Config for Runtime {
type ServiceWeight = MessageQueueServiceWeight;
type MessageProcessor = MessageProcessor;
type QueueChangeHandler = ();
type QueuePausedQuery = ();
type WeightInfo = ();
}

Expand Down
1 change: 1 addition & 0 deletions xcm/xcm-simulator/fuzzer/src/relay_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ impl pallet_message_queue::Config for Runtime {
type MessageProcessor =
pallet_message_queue::mock_helpers::NoopMessageProcessor<AggregateMessageOrigin>;
type QueueChangeHandler = ();
type QueuePausedQuery = ();
type WeightInfo = ();
}

Expand Down

0 comments on commit bddd3ca

Please sign in to comment.