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

XCM: Tools for uniquely referencing messages #7234

Merged
merged 37 commits into from
May 25, 2023
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
9540a98
Tools for unique topic references
gavofyork May 15, 2023
56b0df6
Formatting
gavofyork May 15, 2023
0f31fa6
Naming
gavofyork May 15, 2023
6ff9860
Repot into routing.rs.
gavofyork May 16, 2023
7a14617
More things done
gavofyork May 16, 2023
95c68e5
Universal Exporter supports topic-as-reference
gavofyork May 16, 2023
d78faba
Some tests for the topic routing
gavofyork May 17, 2023
d3301c7
More tests
gavofyork May 17, 2023
e0782f9
Paid bridge tests
gavofyork May 18, 2023
1ed9851
Add message ID to sending events
gavofyork May 19, 2023
8a2ed2a
Formatting
gavofyork May 19, 2023
c31e62e
fix and integrate into test nets
gavofyork May 19, 2023
88cc42f
Move DenyThenTry and friend from Cumulus
gavofyork May 19, 2023
e493a04
Merge remote-tracking branch 'origin/master' into gav-unique-topics
gavofyork May 19, 2023
db53caf
Append SetTopic rather than prepend
gavofyork May 21, 2023
fc437ed
Docs
gavofyork May 21, 2023
0476580
Merge remote-tracking branch 'origin/master' into gav-unique-topics
gavofyork May 21, 2023
1deacc6
Docs
gavofyork May 21, 2023
8247ae9
Work with new ProcessMessage ID API
gavofyork May 21, 2023
f44a4cd
Formatting
gavofyork May 21, 2023
23424e5
Fix build
gavofyork May 21, 2023
02794fa
Fixes
gavofyork May 21, 2023
7465a1c
Merge remote-tracking branch 'origin/master' into gav-unique-topics
gavofyork May 21, 2023
8d4f53a
Formatting
gavofyork May 21, 2023
9dc95f6
Update xcm/xcm-builder/src/barriers.rs
gavofyork May 22, 2023
bee9da3
Update xcm/xcm-builder/src/routing.rs
gavofyork May 22, 2023
1fa45d9
Docs
gavofyork May 23, 2023
98c6f86
Rename message_hash
gavofyork May 23, 2023
f4d7d7c
Merge branch 'gav-unique-topics' of github.com:paritytech/polkadot in…
gavofyork May 23, 2023
5d03354
Formatting
gavofyork May 23, 2023
2adf2f7
".git/.scripts/commands/fmt/fmt.sh"
May 24, 2023
207f8fd
Rename
gavofyork May 24, 2023
b49b43c
Another Rename
gavofyork May 24, 2023
523a7dc
".git/.scripts/commands/fmt/fmt.sh"
May 24, 2023
739b3b1
Merge remote-tracking branch 'origin/master' into gav-unique-topics
gavofyork May 24, 2023
24141b2
".git/.scripts/commands/fmt/fmt.sh"
May 24, 2023
ca065f4
Update xcm/xcm-builder/src/routing.rs
gavofyork May 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
368 changes: 184 additions & 184 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ runtime-metrics = [ "polkadot-cli/runtime-metrics" ]
pyroscope = ["polkadot-cli/pyroscope"]
jemalloc-allocator = ["polkadot-node-core-pvf-worker/jemalloc-allocator", "polkadot-overseer/jemalloc-allocator"]


# Configuration for building a .deb package - for use with `cargo-deb`
[package.metadata.deb]
name = "polkadot"
Expand Down
12 changes: 6 additions & 6 deletions runtime/kusama/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ use runtime_common::{
use sp_core::ConstU32;
use xcm::latest::prelude::*;
use xcm_builder::{
AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses,
AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses, AllowSetTopic,
AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom, ChildParachainAsNative,
ChildParachainConvertsVia, ChildSystemParachainAsSuperuser,
CurrencyAdapter as XcmCurrencyAdapter, FixedWeightBounds, IsChildSystemParachain, IsConcrete,
MintLocation, OriginToPluralityVoice, SignedAccountId32AsNative, SignedToAccountId32,
SovereignSignedViaLocation, TakeWeightCredit, UsingComponents, WeightInfoBounds,
WithComputedOrigin,
WithComputedOrigin, WithUniqueTopic,
};
use xcm_executor::traits::WithOriginFilter;

Expand Down Expand Up @@ -115,14 +115,14 @@ parameter_types! {

/// The XCM router. When we want to send an XCM message, we use this type. It amalgamates all of our
/// individual routers.
pub type XcmRouter = (
pub type XcmRouter = WithUniqueTopic<(
// Only one router so far - use DMP to communicate with child parachains.
ChildParachainRouter<
Runtime,
XcmPallet,
ExponentialPrice<FeeAssetId, BaseDeliveryFee, TransactionByteFee, Dmp>,
>,
);
)>;

parameter_types! {
pub const Ksm: MultiAssetFilter = Wild(AllOf { fun: WildFungible, id: Concrete(TokenLocation::get()) });
Expand All @@ -142,7 +142,7 @@ match_types! {
}

/// The barriers one of which must be passed for an XCM message to be executed.
pub type Barrier = (
pub type Barrier = AllowSetTopic<(
// Weight that is paid for may be consumed.
TakeWeightCredit,
// Expected responses are OK.
Expand All @@ -159,7 +159,7 @@ pub type Barrier = (
UniversalLocation,
ConstU32<8>,
>,
);
)>;

/// A call filter for the XCM Transact instruction. This is a temporary measure until we properly
/// account for proof size weights.
Expand Down
21 changes: 12 additions & 9 deletions runtime/parachains/src/ump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,6 @@ pub type OverweightIndex = u64;
/// and will be forwarded to the XCM Executor.
pub struct XcmSink<XcmExecutor, Config>(PhantomData<(XcmExecutor, Config)>);

/// Returns a [`MessageId`] for the given upward message payload.
fn upward_message_id(data: &[u8]) -> MessageId {
sp_io::hashing::blake2_256(data)
}

impl<XcmExecutor: xcm::latest::ExecuteXcm<C::RuntimeCall>, C: Config> UmpSink
for XcmSink<XcmExecutor, C>
{
Expand All @@ -111,7 +106,8 @@ impl<XcmExecutor: xcm::latest::ExecuteXcm<C::RuntimeCall>, C: Config> UmpSink
VersionedXcm,
};

let id = upward_message_id(data);
// The fallback message id.
let hash = sp_io::hashing::blake2_256(data);
let maybe_msg_and_weight = VersionedXcm::<C::RuntimeCall>::decode_all_with_depth_limit(
xcm::MAX_XCM_DECODE_DEPTH,
&mut data,
Expand All @@ -128,16 +124,23 @@ impl<XcmExecutor: xcm::latest::ExecuteXcm<C::RuntimeCall>, C: Config> UmpSink
});
match maybe_msg_and_weight {
Err(_) => {
Pallet::<C>::deposit_event(Event::InvalidFormat(id));
Pallet::<C>::deposit_event(Event::InvalidFormat(hash));
Ok(Weight::zero())
},
Ok((Err(()), weight_used)) => {
Pallet::<C>::deposit_event(Event::UnsupportedVersion(id));
Pallet::<C>::deposit_event(Event::UnsupportedVersion(hash));
Ok(weight_used)
},
Ok((Ok(xcm_message), weight_used)) => {
let xcm_junction = Junction::Parachain(origin.into());
let outcome = XcmExecutor::execute_xcm(xcm_junction, xcm_message, id, max_weight);
let mut id = hash;
let outcome = XcmExecutor::prepare_and_execute(
xcm_junction,
xcm_message,
&mut id,
max_weight,
Weight::zero(),
);
match outcome {
Outcome::Error(XcmError::WeightLimitReached(required)) => Err((id, required)),
outcome => {
Expand Down
5 changes: 3 additions & 2 deletions runtime/parachains/src/ump/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ frame_benchmarking::benchmarks! {
// and take the decoding weight into account by adding it to the extrinsic execution weight
// in the process_upward_message function.
let msg = create_message_overweight::<T>();
let hash = msg.using_encoded(sp_io::hashing::blake2_256);

// This just makes sure that 0 is not a valid index and we can use it later on.
let _ = Ump::<T>::service_overweight(RawOrigin::Root.into(), 0, Weight::from_parts(1000, 1000));
Expand All @@ -122,8 +123,8 @@ frame_benchmarking::benchmarks! {
queue_upward_msg::<T>(&host_conf, para, msg.clone());
Ump::<T>::process_pending_upward_messages();
assert_last_event_type::<T>(
Event::OverweightEnqueued(para, upward_message_id(&msg), 0, Weight::zero()).into()
);
Event::OverweightEnqueued(para, hash, 0, Weight::zero()).into()
);
}: _(RawOrigin::Root, 0, Weight::MAX)
verify {
assert_last_event_type::<T>(Event::OverweightServiced(0, Weight::zero()).into());
Expand Down
2 changes: 1 addition & 1 deletion runtime/parachains/src/ump/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ fn overweight_queue_works() {
assert_last_event(
Event::OverweightEnqueued(
para_a,
upward_message_id(&a_msg_3[..]),
sp_io::hashing::blake2_256(&a_msg_3[..]),
0,
Weight::from_parts(500, 500),
)
Expand Down
12 changes: 6 additions & 6 deletions runtime/rococo/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ use runtime_common::{
use sp_core::ConstU32;
use xcm::latest::prelude::*;
use xcm_builder::{
AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses,
AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses, AllowSetTopic,
AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom, BackingToPlurality,
ChildParachainAsNative, ChildParachainConvertsVia, ChildSystemParachainAsSuperuser,
CurrencyAdapter as XcmCurrencyAdapter, FixedWeightBounds, IsChildSystemParachain, IsConcrete,
MintLocation, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation,
TakeWeightCredit, UsingComponents, WeightInfoBounds, WithComputedOrigin,
TakeWeightCredit, UsingComponents, WeightInfoBounds, WithComputedOrigin, WithUniqueTopic,
};
use xcm_executor::{traits::WithOriginFilter, XcmExecutor};

Expand Down Expand Up @@ -95,14 +95,14 @@ parameter_types! {

/// The XCM router. When we want to send an XCM message, we use this type. It amalgamates all of our
/// individual routers.
pub type XcmRouter = (
pub type XcmRouter = WithUniqueTopic<(
// Only one router so far - use DMP to communicate with child parachains.
ChildParachainRouter<
Runtime,
XcmPallet,
ExponentialPrice<FeeAssetId, BaseDeliveryFee, TransactionByteFee, Dmp>,
>,
);
)>;

parameter_types! {
pub const Roc: MultiAssetFilter = Wild(AllOf { fun: WildFungible, id: Concrete(TokenLocation::get()) });
Expand Down Expand Up @@ -137,7 +137,7 @@ match_types! {
}

/// The barriers one of which must be passed for an XCM message to be executed.
pub type Barrier = (
pub type Barrier = AllowSetTopic<(
// Weight that is paid for may be consumed.
TakeWeightCredit,
// Expected responses are OK.
Expand All @@ -154,7 +154,7 @@ pub type Barrier = (
UniversalLocation,
ConstU32<8>,
>,
);
)>;

/// A call filter for the XCM Transact instruction. This is a temporary measure until we
/// properly account for proof size weights.
Expand Down
12 changes: 6 additions & 6 deletions runtime/westend/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ use sp_core::ConstU32;
use westend_runtime_constants::currency::CENTS;
use xcm::latest::prelude::*;
use xcm_builder::{
AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses,
AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses, AllowSetTopic,
AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom, ChildParachainAsNative,
ChildParachainConvertsVia, ChildSystemParachainAsSuperuser,
CurrencyAdapter as XcmCurrencyAdapter, IsChildSystemParachain, IsConcrete, MintLocation,
SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit,
UsingComponents, WeightInfoBounds, WithComputedOrigin,
UsingComponents, WeightInfoBounds, WithComputedOrigin, WithUniqueTopic,
};
use xcm_executor::{traits::WithOriginFilter, XcmExecutor};

Expand Down Expand Up @@ -80,14 +80,14 @@ type LocalOriginConverter = (

/// The XCM router. When we want to send an XCM message, we use this type. It amalgamates all of our
/// individual routers.
pub type XcmRouter = (
pub type XcmRouter = WithUniqueTopic<(
// Only one router so far - use DMP to communicate with child parachains.
ChildParachainRouter<
Runtime,
XcmPallet,
ExponentialPrice<FeeAssetId, BaseDeliveryFee, TransactionByteFee, Dmp>,
>,
);
)>;

parameter_types! {
pub const Westmint: MultiLocation = Parachain(1000).into_location();
Expand All @@ -108,7 +108,7 @@ pub type TrustedTeleporters =
(xcm_builder::Case<WndForWestmint>, xcm_builder::Case<WndForCollectives>);

/// The barriers one of which must be passed for an XCM message to be executed.
pub type Barrier = (
pub type Barrier = AllowSetTopic<(
// Weight that is paid for may be consumed.
TakeWeightCredit,
// Expected responses are OK.
Expand All @@ -125,7 +125,7 @@ pub type Barrier = (
UniversalLocation,
ConstU32<8>,
>,
);
)>;

/// A call filter for the XCM Transact instruction. This is a temporary measure until we
/// properly account for proof size weights.
Expand Down
Loading