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 7 commits into
base: master
Choose a base branch
from
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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
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 @@ -1202,14 +1202,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 @@ -1315,7 +1321,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)),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@seadanda We had to keep the weight in the form of a fallback when dealing with chains that haven't yet upgraded to V5. This means if you're only sending this messages when you know the other chain has already upgraded then you can put None and have the benefits of never having too little weight.

Please check if any of these calls could have None or should have a fallback.

},
]);

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
1 change: 1 addition & 0 deletions polkadot/runtime/parachains/src/coretime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,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: None,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@seadanda Another place to check

call: BrokerRuntimePallets::Broker(call).encode().into(),
}
}
Expand Down
6 changes: 5 additions & 1 deletion polkadot/runtime/rococo/src/weights/xcm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,11 @@ impl<RuntimeCall> XcmWeightInfo<RuntimeCall> for RococoXcmWeight<RuntimeCall> {
fn transfer_reserve_asset(assets: &Assets, _dest: &Location, _xcm: &Xcm<()>) -> Weight {
assets.weigh_assets(XcmBalancesWeight::<Runtime>::transfer_reserve_asset())
}
fn transact(_origin_kind: &OriginKind, _call: &DoubleEncoded<RuntimeCall>) -> Weight {
fn transact(
_origin_kind: &OriginKind,
_fallback_max_weight: &Option<Weight>,
_call: &DoubleEncoded<RuntimeCall>,
) -> Weight {
XcmGeneric::<Runtime>::transact()
}
fn hrmp_new_channel_open_request(
Expand Down
6 changes: 5 additions & 1 deletion polkadot/runtime/westend/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,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,
call: poke.encode().into(),
fallback_max_weight: None,
},
]);

// send
Expand Down
6 changes: 5 additions & 1 deletion polkadot/runtime/westend/src/weights/xcm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,11 @@ impl<RuntimeCall> XcmWeightInfo<RuntimeCall> for WestendXcmWeight<RuntimeCall> {
fn transfer_reserve_asset(assets: &Assets, _dest: &Location, _xcm: &Xcm<()>) -> Weight {
assets.weigh_assets(XcmBalancesWeight::<Runtime>::transfer_reserve_asset())
}
fn transact(_origin_kind: &OriginKind, _call: &DoubleEncoded<RuntimeCall>) -> Weight {
fn transact(
_origin_kind: &OriginKind,
_fallback_max_weight: &Option<Weight>,
_call: &DoubleEncoded<RuntimeCall>,
) -> Weight {
XcmGeneric::<Runtime>::transact()
}
fn hrmp_new_channel_open_request(
Expand Down
2 changes: 0 additions & 2 deletions polkadot/xcm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ schemars = { default-features = true, optional = true, workspace = true }
xcm-procedural = { workspace = true, default-features = true }
environmental = { workspace = true }
hex-literal = { workspace = true, default-features = true }
frame-support = { workspace = true }

[dev-dependencies]
sp-io = { workspace = true, default-features = true }
Expand All @@ -37,7 +36,6 @@ std = [
"bounded-collections/std",
"codec/std",
"environmental/std",
"frame-support/std",
"log/std",
"scale-info/std",
"serde/std",
Expand Down
Loading
Loading