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

Companion for polkadot#7424 (pallet xcm remote weigher) #2811

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
28 changes: 24 additions & 4 deletions parachain-template/runtime/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ use xcm::latest::prelude::*;
use xcm_builder::{
AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowTopLevelPaidExecutionFrom,
CurrencyAdapter, DenyReserveTransferToRelayChain, DenyThenTry, EnsureXcmOrigin,
FixedWeightBounds, IsConcrete, NativeAsset, ParentIsPreset, RelayChainAsNative,
SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative,
SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId,
UsingComponents, WithComputedOrigin, WithUniqueTopic,
FixedWeightBounds, IsConcrete, NativeAsset, ParentIsPreset, ProvideWeighableInstructions,
RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia,
SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit,
TrailingSetTopicAsId, UniversalWeigherAdapter, UsingComponents, WithComputedOrigin,
WithUniqueTopic,
};
use xcm_executor::XcmExecutor;

Expand Down Expand Up @@ -155,6 +156,20 @@ parameter_types! {
pub ReachableDest: Option<MultiLocation> = Some(Parent.into());
}

/// Helper for adding more instructions to the weight estimation on destination side.
pub struct DestinationWeigherAddons;
impl ProvideWeighableInstructions<()> for DestinationWeigherAddons {
fn provide_for(
_dest: impl Into<MultiLocation>,
_message: &Xcm<()>,
) -> sp_std::vec::Vec<Instruction<()>> {
sp_std::vec![
// runtime uses `WithUniqueTopic` which (possibly) adds `SetTopic` instruction
SetTopic([3; 32])
]
}
}

impl pallet_xcm::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type SendXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
Expand All @@ -167,6 +182,11 @@ impl pallet_xcm::Config for Runtime {
type XcmTeleportFilter = Everything;
type XcmReserveTransferFilter = Nothing;
type Weigher = FixedWeightBounds<UnitWeightCost, RuntimeCall, MaxInstructions>;
type DestinationWeigher = UniversalWeigherAdapter<
// use local weight for remote message and hope for the best.
FixedWeightBounds<UnitWeightCost, (), MaxInstructions>,
DestinationWeigherAddons,
>;
type UniversalLocation = UniversalLocation;
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
Expand Down
29 changes: 24 additions & 5 deletions parachains/runtimes/assets/asset-hub-kusama/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@ use xcm_builder::{
AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom, CurrencyAdapter,
DenyReserveTransferToRelayChain, DenyThenTry, DescribeAllTerminal, DescribeFamily,
EnsureXcmOrigin, FungiblesAdapter, HashedDescription, IsConcrete, LocalMint, NativeAsset,
NoChecking, ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative,
SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32,
SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, UsingComponents,
WeightInfoBounds, WithComputedOrigin, WithUniqueTopic,
NoChecking, ParentAsSuperuser, ParentIsPreset, ProvideWeighableInstructions,
RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia,
SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit,
TrailingSetTopicAsId, UniversalWeigherAdapter, UsingComponents, WeightInfoBounds,
WithComputedOrigin, WithUniqueTopic,
};
use xcm_executor::{traits::WithOriginFilter, XcmExecutor};

Expand Down Expand Up @@ -445,6 +446,20 @@ parameter_types! {
pub ReachableDest: Option<MultiLocation> = Some(Parent.into());
}

/// Helper for adding more instructions to the weight estimation on destination side.
pub struct DestinationWeigherAddons;
impl ProvideWeighableInstructions<()> for DestinationWeigherAddons {
fn provide_for(
_dest: impl Into<MultiLocation>,
_message: &Xcm<()>,
) -> sp_std::vec::Vec<Instruction<()>> {
sp_std::vec![
// runtime uses `WithUniqueTopic` which (possibly) adds `SetTopic` instruction
SetTopic([3; 32])
bkontur marked this conversation as resolved.
Show resolved Hide resolved
]
}
}

impl pallet_xcm::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
// We want to disallow users sending (arbitrary) XCMs from this chain.
Expand All @@ -462,7 +477,11 @@ impl pallet_xcm::Config for Runtime {
RuntimeCall,
MaxInstructions,
>;

type DestinationWeigher = UniversalWeigherAdapter<
// use local weight for remote message and hope for the best.
WeightInfoBounds<crate::weights::xcm::AssetHubKusamaXcmWeight<()>, (), MaxInstructions>,
DestinationWeigherAddons,
>;
type UniversalLocation = UniversalLocation;
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ use xcm_builder::{
EnsureXcmOrigin, FungiblesAdapter, HashedDescription, IsConcrete, LocalMint, NativeAsset,
NoChecking, ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative,
SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32,
SovereignSignedViaLocation, TakeWeightCredit, UsingComponents, WeightInfoBounds,
WithComputedOrigin,
SovereignSignedViaLocation, TakeWeightCredit, UniversalWeigherAdapter, UsingComponents,
WeightInfoBounds, WithComputedOrigin,
};
use xcm_executor::{traits::WithOriginFilter, XcmExecutor};

Expand Down Expand Up @@ -472,6 +472,11 @@ impl pallet_xcm::Config for Runtime {
RuntimeCall,
MaxInstructions,
>;
type DestinationWeigher = UniversalWeigherAdapter<
// use local weight for remote message and hope for the best.
WeightInfoBounds<crate::weights::xcm::AssetHubPolkadotXcmWeight<()>, (), MaxInstructions>,
(),
>;
type UniversalLocation = UniversalLocation;
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
Expand Down
26 changes: 23 additions & 3 deletions parachains/runtimes/assets/asset-hub-westend/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ use xcm_builder::{
AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses,
AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom, CurrencyAdapter,
DenyReserveTransferToRelayChain, DenyThenTry, EnsureXcmOrigin, FungiblesAdapter, IsConcrete,
LocalMint, NativeAsset, NoChecking, ParentAsSuperuser, ParentIsPreset, RelayChainAsNative,
SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative,
SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId,
LocalMint, NativeAsset, NoChecking, ParentAsSuperuser, ParentIsPreset,
ProvideWeighableInstructions, RelayChainAsNative, SiblingParachainAsNative,
SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32,
SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, UniversalWeigherAdapter,
UsingComponents, WeightInfoBounds, WithComputedOrigin, WithUniqueTopic,
};
use xcm_executor::{traits::WithOriginFilter, XcmExecutor};
Expand Down Expand Up @@ -482,6 +483,20 @@ parameter_types! {
pub ReachableDest: Option<MultiLocation> = Some(Parent.into());
}

/// Helper for adding more instructions to the weight estimation on destination side.
pub struct DestinationWeigherAddons;
impl ProvideWeighableInstructions<()> for DestinationWeigherAddons {
fn provide_for(
_dest: impl Into<MultiLocation>,
_message: &Xcm<()>,
) -> sp_std::vec::Vec<Instruction<()>> {
sp_std::vec![
// runtime uses `WithUniqueTopic` which (possibly) adds `SetTopic` instruction
SetTopic([3; 32])
]
}
}

impl pallet_xcm::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type SendXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
Expand All @@ -496,6 +511,11 @@ impl pallet_xcm::Config for Runtime {
RuntimeCall,
MaxInstructions,
>;
type DestinationWeigher = UniversalWeigherAdapter<
// use local weight for remote message and hope for the best.
WeightInfoBounds<crate::weights::xcm::AssetHubWestendXcmWeight<()>, (), MaxInstructions>,
DestinationWeigherAddons,
>;
type UniversalLocation = UniversalLocation;
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ use xcm_builder::{
AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses,
AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom, CurrencyAdapter,
DenyReserveTransferToRelayChain, DenyThenTry, EnsureXcmOrigin, IsConcrete, ParentAsSuperuser,
ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia,
SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit,
TrailingSetTopicAsId, UsingComponents, WeightInfoBounds, WithComputedOrigin, WithUniqueTopic,
ParentIsPreset, ProvideWeighableInstructions, RelayChainAsNative, SiblingParachainAsNative,
SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32,
SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, UniversalWeigherAdapter,
UsingComponents, WeightInfoBounds, WithComputedOrigin, WithUniqueTopic,
};
use xcm_executor::{traits::WithOriginFilter, XcmExecutor};

Expand Down Expand Up @@ -231,6 +232,20 @@ parameter_types! {
pub ReachableDest: Option<MultiLocation> = Some(Parent.into());
}

/// Helper for adding more instructions to the weight estimation on destination side.
pub struct DestinationWeigherAddons;
impl ProvideWeighableInstructions<()> for DestinationWeigherAddons {
fn provide_for(
_dest: impl Into<MultiLocation>,
_message: &Xcm<()>,
) -> sp_std::vec::Vec<Instruction<()>> {
sp_std::vec![
// runtime uses `WithUniqueTopic` which (possibly) adds `SetTopic` instruction
SetTopic([3; 32])
]
}
}

impl pallet_xcm::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
// We want to disallow users sending (arbitrary) XCMs from this chain.
Expand All @@ -248,6 +263,11 @@ impl pallet_xcm::Config for Runtime {
RuntimeCall,
MaxInstructions,
>;
type DestinationWeigher = UniversalWeigherAdapter<
// use local weight for remote message and hope for the best.
WeightInfoBounds<crate::weights::xcm::BridgeHubKusamaXcmWeight<()>, (), MaxInstructions>,
DestinationWeigherAddons,
>;
type UniversalLocation = UniversalLocation;
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use xcm_builder::{
DenyReserveTransferToRelayChain, DenyThenTry, EnsureXcmOrigin, IsConcrete, ParentAsSuperuser,
ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia,
SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit,
UsingComponents, WeightInfoBounds, WithComputedOrigin,
UniversalWeigherAdapter, UsingComponents, WeightInfoBounds, WithComputedOrigin,
};
use xcm_executor::{traits::WithOriginFilter, XcmExecutor};

Expand Down Expand Up @@ -249,6 +249,11 @@ impl pallet_xcm::Config for Runtime {
RuntimeCall,
MaxInstructions,
>;
type DestinationWeigher = UniversalWeigherAdapter<
// use local weight for remote message and hope for the best.
WeightInfoBounds<crate::weights::xcm::BridgeHubPolkadotXcmWeight<()>, (), MaxInstructions>,
(),
>;
type UniversalLocation = UniversalLocation;
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ use xcm_builder::{
AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses,
AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom,
CurrencyAdapter, DenyReserveTransferToRelayChain, DenyThenTry, EnsureXcmOrigin, IsConcrete,
ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative,
SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32,
SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, UsingComponents,
WeightInfoBounds, WithComputedOrigin, WithUniqueTopic,
ParentAsSuperuser, ParentIsPreset, ProvideWeighableInstructions, RelayChainAsNative,
SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative,
SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId,
UniversalWeigherAdapter, UsingComponents, WeightInfoBounds, WithComputedOrigin,
WithUniqueTopic,
};
use xcm_executor::{
traits::{ExportXcm, WithOriginFilter},
Expand Down Expand Up @@ -278,6 +279,20 @@ parameter_types! {
pub ReachableDest: Option<MultiLocation> = Some(Parent.into());
}

/// Helper for adding more instructions to the weight estimation on destination side.
pub struct DestinationWeigherAddons;
impl ProvideWeighableInstructions<()> for DestinationWeigherAddons {
fn provide_for(
_dest: impl Into<MultiLocation>,
_message: &Xcm<()>,
) -> sp_std::vec::Vec<Instruction<()>> {
sp_std::vec![
// runtime uses `WithUniqueTopic` which (possibly) adds `SetTopic` instruction
SetTopic([3; 32])
]
}
}

impl pallet_xcm::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type XcmRouter = XcmRouter;
Expand All @@ -294,6 +309,11 @@ impl pallet_xcm::Config for Runtime {
RuntimeCall,
MaxInstructions,
>;
type DestinationWeigher = UniversalWeigherAdapter<
// use local weight for remote message and hope for the best.
WeightInfoBounds<crate::weights::xcm::BridgeHubRococoXcmWeight<()>, (), MaxInstructions>,
DestinationWeigherAddons,
>;
type UniversalLocation = UniversalLocation;
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ use xcm_builder::{
DenyReserveTransferToRelayChain, DenyThenTry, EnsureXcmOrigin, FixedWeightBounds, IsConcrete,
OriginToPluralityVoice, ParentAsSuperuser, ParentIsPreset, RelayChainAsNative,
SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative,
SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, UsingComponents,
WithComputedOrigin,
SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, UniversalWeigherAdapter,
UsingComponents, WithComputedOrigin,
};
use xcm_executor::{traits::WithOriginFilter, XcmExecutor};

Expand Down Expand Up @@ -291,6 +291,11 @@ impl pallet_xcm::Config for Runtime {
type XcmTeleportFilter = Everything;
type XcmReserveTransferFilter = Nothing; // This parachain is not meant as a reserve location.
type Weigher = FixedWeightBounds<BaseXcmWeight, RuntimeCall, MaxInstructions>;
type DestinationWeigher = UniversalWeigherAdapter<
// use local weight for remote message and hope for the best.
FixedWeightBounds<BaseXcmWeight, (), MaxInstructions>,
(),
>;
type UniversalLocation = UniversalLocation;
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
Expand Down
28 changes: 24 additions & 4 deletions parachains/runtimes/contracts/contracts-rococo/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ use xcm_builder::{
AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses,
AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom, CurrencyAdapter,
DenyReserveTransferToRelayChain, DenyThenTry, EnsureXcmOrigin, FixedWeightBounds, IsConcrete,
NativeAsset, ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative,
SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32,
SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, UsingComponents,
WithComputedOrigin, WithUniqueTopic,
NativeAsset, ParentAsSuperuser, ParentIsPreset, ProvideWeighableInstructions,
RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia,
SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit,
TrailingSetTopicAsId, UniversalWeigherAdapter, UsingComponents, WithComputedOrigin,
WithUniqueTopic,
};
use xcm_executor::XcmExecutor;

Expand Down Expand Up @@ -189,6 +190,20 @@ parameter_types! {
pub ReachableDest: Option<MultiLocation> = Some(Parent.into());
}

/// Helper for adding more instructions to the weight estimation on destination side.
pub struct DestinationWeigherAddons;
impl ProvideWeighableInstructions<()> for DestinationWeigherAddons {
fn provide_for(
_dest: impl Into<MultiLocation>,
_message: &Xcm<()>,
) -> sp_std::vec::Vec<Instruction<()>> {
sp_std::vec![
// runtime uses `WithUniqueTopic` which (possibly) adds `SetTopic` instruction
SetTopic([3; 32])
]
}
}

impl pallet_xcm::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
// We want to disallow users sending (arbitrary) XCMs from this chain.
Expand All @@ -202,6 +217,11 @@ impl pallet_xcm::Config for Runtime {
type XcmTeleportFilter = Everything;
type XcmReserveTransferFilter = Everything;
type Weigher = FixedWeightBounds<UnitWeightCost, RuntimeCall, MaxInstructions>;
type DestinationWeigher = UniversalWeigherAdapter<
// use local weight for remote message and hope for the best.
FixedWeightBounds<UnitWeightCost, (), MaxInstructions>,
DestinationWeigherAddons,
>;
type UniversalLocation = UniversalLocation;
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
Expand Down
Loading