Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added fallback_max_weight to Transact for sending messages to V4 chains #6643

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
4479a29
feat: add fallback_max_weight for sending messages to V4 chains
franciscoaguirre Nov 26, 2024
5b9bf84
Merge branch 'master' into xcm-transact-compatibility
franciscoaguirre Nov 26, 2024
b5b21ee
Update from franciscoaguirre running command 'fmt'
actions-user Nov 26, 2024
b96e76e
Merge branch 'master' into xcm-transact-compatibility
franciscoaguirre Nov 26, 2024
56eb9f1
Update from franciscoaguirre running command 'prdoc --audience runtim…
actions-user Nov 26, 2024
d9e409e
Merge branch 'master' into xcm-transact-compatibility
franciscoaguirre Nov 26, 2024
19c923c
chore(xcm): remove unused frame-support dependency
franciscoaguirre Nov 26, 2024
8917c80
Merge branch 'master' into xcm-transact-compatibility
franciscoaguirre Nov 29, 2024
b3967c7
test(xcm): add test for conversions between v4 and v5
franciscoaguirre Nov 29, 2024
9527b5b
Update from franciscoaguirre running command 'fmt'
actions-user Nov 29, 2024
9ced35f
Update polkadot/xcm/src/v5/mod.rs
franciscoaguirre Nov 29, 2024
7d777cf
Update prdoc/pr_6643.prdoc
franciscoaguirre Nov 29, 2024
899b995
Update prdoc/pr_6643.prdoc
franciscoaguirre Nov 29, 2024
e63ea59
doc: update prdoc
franciscoaguirre Nov 29, 2024
b755fa2
fix: add missing weight to coretime calls
franciscoaguirre Nov 29, 2024
f589f37
Merge branch 'master' into xcm-transact-compatibility
franciscoaguirre Nov 29, 2024
d6e803e
Update from franciscoaguirre running command 'fmt'
actions-user Nov 29, 2024
ec2e097
doc: update prdoc
franciscoaguirre Nov 29, 2024
fef70c0
fix(pallet-xcm-benchmarks): typo
franciscoaguirre Nov 29, 2024
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
1 change: 1 addition & 0 deletions bridges/snowbridge/primitives/router/src/inbound/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ where
// Call create_asset on foreign assets pallet.
Transact {
origin_kind: OriginKind::Xcm,
fallback_max_weight: None,
call: (
create_call_index,
asset_id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub fn xcm_transact_paid_execution(
VersionedXcm::from(Xcm(vec![
WithdrawAsset(fees.clone().into()),
BuyExecution { fees, weight_limit },
Transact { origin_kind, call },
Transact { origin_kind, call, fallback_max_weight: None },
RefundSurplus,
DepositAsset {
assets: All.into(),
Expand All @@ -53,7 +53,7 @@ pub fn xcm_transact_unpaid_execution(

VersionedXcm::from(Xcm(vec![
UnpaidExecution { weight_limit, check_origin },
Transact { origin_kind, call },
Transact { origin_kind, call, fallback_max_weight: None },
]))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ fn transfer_and_transact_in_same_xcm(

// xcm to be executed at dest
let xcm_on_dest = Xcm(vec![
Transact { origin_kind: OriginKind::Xcm, call },
Transact { origin_kind: OriginKind::Xcm, call, fallback_max_weight: None },
ExpectTransactStatus(MaybeErrorCode::Success),
// since this is the last hop, we don't need to further use any assets previously
// reserved for fees (there are no further hops to cover transport fees for); we
Expand Down
2 changes: 2 additions & 0 deletions cumulus/parachains/pallets/ping/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ pub mod pallet {
})
.encode()
.into(),
fallback_max_weight: None,
}]),
) {
Ok((hash, cost)) => {
Expand Down Expand Up @@ -214,6 +215,7 @@ pub mod pallet {
})
.encode()
.into(),
fallback_max_weight: None,
}]),
) {
Ok((hash, cost)) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,11 @@ impl<Call> XcmWeightInfo<Call> for AssetHubRococoXcmWeight<Call> {
fn transfer_reserve_asset(assets: &Assets, _dest: &Location, _xcm: &Xcm<()>) -> Weight {
assets.weigh_assets(XcmFungibleWeight::<Runtime>::transfer_reserve_asset())
}
fn transact(_origin_type: &OriginKind, _call: &DoubleEncoded<Call>) -> Weight {
fn transact(
_origin_type: &OriginKind,
_fallback_max_weight: &Option<Weight>,
_call: &DoubleEncoded<Call>,
) -> Weight {
XcmGeneric::<Runtime>::transact()
}
fn hrmp_new_channel_open_request(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@ impl<Call> XcmWeightInfo<Call> for AssetHubWestendXcmWeight<Call> {
fn transfer_reserve_asset(assets: &Assets, _dest: &Location, _xcm: &Xcm<()>) -> Weight {
assets.weigh_assets(XcmFungibleWeight::<Runtime>::transfer_reserve_asset())
}
fn transact(_origin_type: &OriginKind, _call: &DoubleEncoded<Call>) -> Weight {
fn transact(
_origin_type: &OriginKind,
_fallback_max_weight: &Option<Weight>,
_call: &DoubleEncoded<Call>,
) -> Weight {
XcmGeneric::<Runtime>::transact()
}
fn hrmp_new_channel_open_request(
Expand Down
14 changes: 12 additions & 2 deletions cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1205,14 +1205,20 @@ pub fn create_and_manage_foreign_assets_for_local_consensus_parachain_assets_wor
let xcm = Xcm(vec![
WithdrawAsset(buy_execution_fee.clone().into()),
BuyExecution { fees: buy_execution_fee.clone(), weight_limit: Unlimited },
Transact { origin_kind: OriginKind::Xcm, call: foreign_asset_create.into() },
Transact {
origin_kind: OriginKind::Xcm,
call: foreign_asset_create.into(),
fallback_max_weight: None,
},
Transact {
origin_kind: OriginKind::SovereignAccount,
call: foreign_asset_set_metadata.into(),
fallback_max_weight: None,
},
Transact {
origin_kind: OriginKind::SovereignAccount,
call: foreign_asset_set_team.into(),
fallback_max_weight: None,
},
ExpectTransactStatus(MaybeErrorCode::Success),
]);
Expand Down Expand Up @@ -1318,7 +1324,11 @@ pub fn create_and_manage_foreign_assets_for_local_consensus_parachain_assets_wor
let xcm = Xcm(vec![
WithdrawAsset(buy_execution_fee.clone().into()),
BuyExecution { fees: buy_execution_fee.clone(), weight_limit: Unlimited },
Transact { origin_kind: OriginKind::Xcm, call: foreign_asset_create.into() },
Transact {
origin_kind: OriginKind::Xcm,
call: foreign_asset_create.into(),
fallback_max_weight: None,
},
ExpectTransactStatus(MaybeErrorCode::from(DispatchError::BadOrigin.encode())),
]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,11 @@ impl<Call> XcmWeightInfo<Call> for BridgeHubRococoXcmWeight<Call> {
fn transfer_reserve_asset(assets: &Assets, _dest: &Location, _xcm: &Xcm<()>) -> Weight {
assets.weigh_assets(XcmFungibleWeight::<Runtime>::transfer_reserve_asset())
}
fn transact(_origin_type: &OriginKind, _call: &DoubleEncoded<Call>) -> Weight {
fn transact(
_origin_type: &OriginKind,
_fallback_max_weight: &Option<Weight>,
_call: &DoubleEncoded<Call>,
) -> Weight {
XcmGeneric::<Runtime>::transact()
}
fn hrmp_new_channel_open_request(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@ impl<Call> XcmWeightInfo<Call> for BridgeHubWestendXcmWeight<Call> {
fn transfer_reserve_asset(assets: &Assets, _dest: &Location, _xcm: &Xcm<()>) -> Weight {
assets.weigh_assets(XcmFungibleWeight::<Runtime>::transfer_reserve_asset())
}
fn transact(_origin_type: &OriginKind, _call: &DoubleEncoded<Call>) -> Weight {
fn transact(
_origin_type: &OriginKind,
_fallback_max_weight: &Option<Weight>,
_call: &DoubleEncoded<Call>,
) -> Weight {
XcmGeneric::<Runtime>::transact()
}
fn hrmp_new_channel_open_request(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ impl CoretimeInterface for CoretimeAllocator {
Instruction::Transact {
origin_kind: OriginKind::Native,
call: request_core_count_call.encode().into(),
fallback_max_weight: Some(Weight::from_parts(1_000_000_000, 200_000)),
franciscoaguirre marked this conversation as resolved.
Show resolved Hide resolved
},
]);

Expand Down Expand Up @@ -164,6 +165,7 @@ impl CoretimeInterface for CoretimeAllocator {
Instruction::Transact {
origin_kind: OriginKind::Native,
call: request_revenue_info_at_call.encode().into(),
fallback_max_weight: Some(Weight::from_parts(1_000_000_000, 200_000)),
},
]);

Expand Down Expand Up @@ -192,6 +194,7 @@ impl CoretimeInterface for CoretimeAllocator {
Instruction::Transact {
origin_kind: OriginKind::Native,
call: credit_account_call.encode().into(),
fallback_max_weight: Some(Weight::from_parts(1_000_000_000, 200_000)),
},
]);

Expand Down Expand Up @@ -256,6 +259,7 @@ impl CoretimeInterface for CoretimeAllocator {
Instruction::Transact {
origin_kind: OriginKind::Native,
call: assign_core_call.encode().into(),
fallback_max_weight: Some(Weight::from_parts(1_000_000_000, 200_000)),
},
]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,11 @@ impl<Call> XcmWeightInfo<Call> for CoretimeRococoXcmWeight<Call> {
fn transfer_reserve_asset(assets: &Assets, _dest: &Location, _xcm: &Xcm<()>) -> Weight {
assets.weigh_assets(XcmFungibleWeight::<Runtime>::transfer_reserve_asset())
}
fn transact(_origin_type: &OriginKind, _call: &DoubleEncoded<Call>) -> Weight {
fn transact(
_origin_type: &OriginKind,
_fallback_max_weight: &Option<Weight>,
_call: &DoubleEncoded<Call>,
) -> Weight {
XcmGeneric::<Runtime>::transact()
}
fn hrmp_new_channel_open_request(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ impl CoretimeInterface for CoretimeAllocator {
use crate::coretime::CoretimeProviderCalls::RequestCoreCount;
let request_core_count_call = RelayRuntimePallets::Coretime(RequestCoreCount(count));

// Weight for `request_core_count` from westend benchmarks:
// `ref_time` = 7889000 + (3 * 25000000) + (1 * 100000000) = 182889000
// `proof_size` = 1636
// Add 5% to each component and round to 2 significant figures.
let call_weight = Weight::from_parts(190_000_000, 1700);

let message = Xcm(vec![
Instruction::UnpaidExecution {
weight_limit: WeightLimit::Unlimited,
Expand All @@ -135,6 +141,7 @@ impl CoretimeInterface for CoretimeAllocator {
Instruction::Transact {
origin_kind: OriginKind::Native,
call: request_core_count_call.encode().into(),
fallback_max_weight: Some(call_weight),
},
]);

Expand Down Expand Up @@ -164,6 +171,7 @@ impl CoretimeInterface for CoretimeAllocator {
Instruction::Transact {
origin_kind: OriginKind::Native,
call: request_revenue_info_at_call.encode().into(),
fallback_max_weight: Some(Weight::from_parts(1_000_000_000, 200_000)),
},
]);

Expand Down Expand Up @@ -192,6 +200,7 @@ impl CoretimeInterface for CoretimeAllocator {
Instruction::Transact {
origin_kind: OriginKind::Native,
call: credit_account_call.encode().into(),
fallback_max_weight: Some(Weight::from_parts(1_000_000_000, 200_000)),
},
]);

Expand All @@ -216,6 +225,12 @@ impl CoretimeInterface for CoretimeAllocator {
) {
use crate::coretime::CoretimeProviderCalls::AssignCore;

// Weight for `assign_core` from westend benchmarks:
// `ref_time` = 10177115 + (1 * 25000000) + (2 * 100000000) + (57600 * 13932) = 937660315
// `proof_size` = 3612
// Add 5% to each component and round to 2 significant figures.
let call_weight = Weight::from_parts(980_000_000, 3800);

// The relay chain currently only allows `assign_core` to be called with a complete mask
// and only ever with increasing `begin`. The assignments must be truncated to avoid
// dropping that core's assignment completely.
Expand Down Expand Up @@ -256,6 +271,7 @@ impl CoretimeInterface for CoretimeAllocator {
Instruction::Transact {
origin_kind: OriginKind::Native,
call: assign_core_call.encode().into(),
fallback_max_weight: Some(call_weight),
},
]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@ impl<Call> XcmWeightInfo<Call> for CoretimeWestendXcmWeight<Call> {
fn transfer_reserve_asset(assets: &Assets, _dest: &Location, _xcm: &Xcm<()>) -> Weight {
assets.weigh_assets(XcmFungibleWeight::<Runtime>::transfer_reserve_asset())
}
fn transact(_origin_type: &OriginKind, _call: &DoubleEncoded<Call>) -> Weight {
fn transact(
_origin_type: &OriginKind,
_fallback_max_weight: &Option<Weight>,
_call: &DoubleEncoded<Call>,
) -> Weight {
XcmGeneric::<Runtime>::transact()
}
fn hrmp_new_channel_open_request(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@ impl<Call> XcmWeightInfo<Call> for PeopleRococoXcmWeight<Call> {
fn transfer_reserve_asset(assets: &Assets, _dest: &Location, _xcm: &Xcm<()>) -> Weight {
assets.weigh_assets(XcmFungibleWeight::<Runtime>::transfer_reserve_asset())
}
fn transact(_origin_type: &OriginKind, _call: &DoubleEncoded<Call>) -> Weight {
fn transact(
_origin_type: &OriginKind,
_fallback_max_weight: &Option<Weight>,
_call: &DoubleEncoded<Call>,
) -> Weight {
XcmGeneric::<Runtime>::transact()
}
fn hrmp_new_channel_open_request(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@ impl<Call> XcmWeightInfo<Call> for PeopleWestendXcmWeight<Call> {
fn transfer_reserve_asset(assets: &Assets, _dest: &Location, _xcm: &Xcm<()>) -> Weight {
assets.weigh_assets(XcmFungibleWeight::<Runtime>::transfer_reserve_asset())
}
fn transact(_origin_type: &OriginKind, _call: &DoubleEncoded<Call>) -> Weight {
fn transact(
_origin_type: &OriginKind,
_fallback_max_weight: &Option<Weight>,
_call: &DoubleEncoded<Call>,
) -> Weight {
XcmGeneric::<Runtime>::transact()
}
fn hrmp_new_channel_open_request(
Expand Down
8 changes: 6 additions & 2 deletions cumulus/parachains/runtimes/test-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,11 @@ impl<
// prepare xcm as governance will do
let xcm = Xcm(vec![
UnpaidExecution { weight_limit: Unlimited, check_origin: None },
Transact { origin_kind: OriginKind::Superuser, call: call.into() },
Transact {
origin_kind: OriginKind::Superuser,
call: call.into(),
fallback_max_weight: None,
},
ExpectTransactStatus(MaybeErrorCode::Success),
]);

Expand Down Expand Up @@ -476,7 +480,7 @@ impl<

// prepare `Transact` xcm
instructions.extend(vec![
Transact { origin_kind, call: call.encode().into() },
Transact { origin_kind, call: call.encode().into(), fallback_max_weight: None },
ExpectTransactStatus(MaybeErrorCode::Success),
]);
let xcm = Xcm(instructions);
Expand Down
6 changes: 6 additions & 0 deletions polkadot/runtime/parachains/src/coretime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ pub mod pallet {
type AssetTransactor: TransactAsset;
/// AccountId to Location converter
type AccountToLocation: for<'a> TryConvert<&'a Self::AccountId, Location>;

/// Maximum weight for any XCM transact call that should be executed on the coretime chain.
///
/// Basically should be `max_weight(set_leases, reserve, notify_core_count)`.
type MaxXcmTransactWeight: Get<Weight>;
}

#[pallet::event]
Expand Down Expand Up @@ -333,6 +338,7 @@ impl<T: Config> OnNewSession<BlockNumberFor<T>> for Pallet<T> {
fn mk_coretime_call<T: Config>(call: crate::coretime::CoretimeCalls) -> Instruction<()> {
Instruction::Transact {
origin_kind: OriginKind::Superuser,
fallback_max_weight: Some(T::MaxXcmTransactWeight::get()),
call: BrokerRuntimePallets::Broker(call).encode().into(),
}
}
Expand Down
2 changes: 2 additions & 0 deletions polkadot/runtime/parachains/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@ impl assigner_coretime::Config for Test {}

parameter_types! {
pub const BrokerId: u32 = 10u32;
pub MaxXcmTransactWeight: Weight = Weight::from_parts(10_000_000, 10_000);
}

pub struct BrokerPot;
Expand All @@ -437,6 +438,7 @@ impl coretime::Config for Test {
type BrokerId = BrokerId;
type WeightInfo = crate::coretime::TestWeightInfo;
type SendXcm = DummyXcmSender;
type MaxXcmTransactWeight = MaxXcmTransactWeight;
type BrokerPotLocation = BrokerPot;
type AssetTransactor = ();
type AccountToLocation = ();
Expand Down
14 changes: 11 additions & 3 deletions polkadot/runtime/rococo/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use core::marker::PhantomData;
use frame_support::pallet_prelude::DispatchResult;
use frame_system::RawOrigin;
use polkadot_primitives::Balance;
use polkadot_runtime_common::identity_migrator::OnReapIdentity;
use polkadot_runtime_common::identity_migrator::{OnReapIdentity, WeightInfo};
use rococo_runtime_constants::currency::*;
use xcm::{latest::prelude::*, VersionedLocation, VersionedXcm};
use xcm_executor::traits::TransactAsset;
Expand Down Expand Up @@ -88,7 +88,10 @@ where
AccountId: Into<[u8; 32]> + Clone + Encode,
{
fn on_reap_identity(who: &AccountId, fields: u32, subs: u32) -> DispatchResult {
use crate::impls::IdentityMigratorCalls::PokeDeposit;
use crate::{
impls::IdentityMigratorCalls::PokeDeposit,
weights::polkadot_runtime_common_identity_migrator::WeightInfo as MigratorWeights,
};

let total_to_send = Self::calculate_remote_deposit(fields, subs);

Expand Down Expand Up @@ -141,6 +144,7 @@ where
.into();

let poke = PeopleRuntimePallets::<AccountId>::IdentityMigrator(PokeDeposit(who.clone()));
let remote_weight_limit = MigratorWeights::<Runtime>::poke_deposit().saturating_mul(2);

// Actual program to execute on People Chain.
let program: Xcm<()> = Xcm(vec![
Expand All @@ -157,7 +161,11 @@ where
.into(),
},
// Poke the deposit to reserve the appropriate amount on the parachain.
Transact { origin_kind: OriginKind::Superuser, call: poke.encode().into() },
Transact {
origin_kind: OriginKind::Superuser,
fallback_max_weight: Some(remote_weight_limit),
call: poke.encode().into(),
},
]);

// send
Expand Down
2 changes: 2 additions & 0 deletions polkadot/runtime/rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1100,6 +1100,7 @@ impl parachains_scheduler::Config for Runtime {
parameter_types! {
pub const BrokerId: u32 = BROKER_ID;
pub const BrokerPalletId: PalletId = PalletId(*b"py/broke");
pub MaxXcmTransactWeight: Weight = Weight::from_parts(200_000_000, 20_000);
}

pub struct BrokerPot;
Expand All @@ -1123,6 +1124,7 @@ impl coretime::Config for Runtime {
xcm_config::ThisNetwork,
<Runtime as frame_system::Config>::AccountId,
>;
type MaxXcmTransactWeight = MaxXcmTransactWeight;
}

parameter_types! {
Expand Down
Loading
Loading