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

XCM V3 (Non-controversial Subset) #6564

Closed
wants to merge 12 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
397 changes: 209 additions & 188 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion node/core/pvf/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ async fn run(
futures::select_biased! {
() = cleanup_pulse.select_next_some() => {
// `select_next_some` because we don't expect this to fail, but if it does, we
// still don't fail. The tradeoff is that the compiled cache will start growing
// still don't fail. The trade-off is that the compiled cache will start growing
// in size. That is, however, rather a slow process and hopefully the operator
// will notice it.

Expand Down
2 changes: 1 addition & 1 deletion node/network/protocol/src/request_response/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ const STATEMENTS_TIMEOUT: Duration = Duration::from_secs(1);

/// We don't want a slow peer to slow down all the others, at the same time we want to get out the
/// data quickly in full to at least some peers (as this will reduce load on us as they then can
/// start serving the data). So this value is a tradeoff. 3 seems to be sensible. So we would need
/// start serving the data). So this value is a trade-off. 3 seems to be sensible. So we would need
/// to have 3 slow nodes connected, to delay transfer for others by `STATEMENTS_TIMEOUT`.
pub const MAX_PARALLEL_STATEMENT_REQUESTS: u32 = 3;

Expand Down
3 changes: 1 addition & 2 deletions node/service/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,7 @@ fn default_parachains_host_configuration(
max_upward_queue_count: 8,
max_upward_queue_size: 1024 * 1024,
max_downward_message_size: 1024 * 1024,
ump_service_total_weight: Weight::from_ref_time(100_000_000_000)
.set_proof_size(MAX_POV_SIZE as u64),
ump_service_total_weight: Weight::from_parts(100_000_000_000, MAX_POV_SIZE as u64),
max_upward_message_size: 50 * 1024,
max_upward_message_num_per_candidate: 5,
hrmp_sender_deposit: 0,
Expand Down
2 changes: 1 addition & 1 deletion runtime/common/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ mod tests {
weight.base_extrinsic = Weight::from_ref_time(100);
})
.for_class(DispatchClass::non_mandatory(), |weight| {
weight.max_total = Some(Weight::from_ref_time(1024).set_proof_size(u64::MAX));
weight.max_total = Some(Weight::from_parts(1024, u64::MAX));
})
.build_or_panic();
pub BlockLength: limits::BlockLength = limits::BlockLength::max(2 * 1024);
Expand Down
2 changes: 1 addition & 1 deletion runtime/common/src/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ parameter_types! {
pub const BlockHashCount: u32 = 250;
pub BlockWeights: frame_system::limits::BlockWeights =
frame_system::limits::BlockWeights::simple_max(
Weight::from_ref_time(4 * 1024 * 1024).set_proof_size(u64::MAX),
Weight::from_parts(4 * 1024 * 1024, u64::MAX),
);
}

Expand Down
4 changes: 1 addition & 3 deletions runtime/common/src/paras_registrar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -705,9 +705,7 @@ mod tests {
parameter_types! {
pub const BlockHashCount: u32 = 250;
pub BlockWeights: limits::BlockWeights =
frame_system::limits::BlockWeights::simple_max(
Weight::from_ref_time(1024).set_proof_size(u64::MAX),
);
frame_system::limits::BlockWeights::simple_max(Weight::from_parts(1024, u64::MAX));
pub BlockLength: limits::BlockLength =
limits::BlockLength::max_with_normal_ratio(4 * 1024 * 1024, NORMAL_RATIO);
}
Expand Down
12 changes: 6 additions & 6 deletions runtime/kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1978,7 +1978,7 @@ sp_api::impl_runtime_apis! {
use pallet_nomination_pools_benchmarking::Pallet as NominationPoolsBench;
use frame_benchmarking::baseline::Pallet as Baseline;
use xcm::latest::prelude::*;
use xcm_config::{CheckAccount, KsmLocation, SovereignAccountOf, Statemine, XcmConfig};
use xcm_config::{CheckAccount, TokenLocation, SovereignAccountOf, Statemine, XcmConfig};

impl pallet_session_benchmarking::Config for Runtime {}
impl pallet_offences_benchmarking::Config for Runtime {}
Expand All @@ -1996,7 +1996,7 @@ sp_api::impl_runtime_apis! {
fn worst_case_holding() -> MultiAssets {
// Kusama only knows about KSM.
vec![MultiAsset{
id: Concrete(KsmLocation::get()),
id: Concrete(TokenLocation::get()),
fun: Fungible(1_000_000 * UNITS),
}].into()
}
Expand All @@ -2005,11 +2005,11 @@ sp_api::impl_runtime_apis! {
parameter_types! {
pub const TrustedTeleporter: Option<(MultiLocation, MultiAsset)> = Some((
Statemine::get(),
MultiAsset { fun: Fungible(1 * UNITS), id: Concrete(KsmLocation::get()) },
MultiAsset { fun: Fungible(1 * UNITS), id: Concrete(TokenLocation::get()) },
));
pub const TrustedReserve: Option<(MultiLocation, MultiAsset)> = Some((
Statemine::get(),
MultiAsset { fun: Fungible(1 * UNITS), id: Concrete(KsmLocation::get()) },
MultiAsset { fun: Fungible(1 * UNITS), id: Concrete(TokenLocation::get()) },
));
}

Expand All @@ -2022,7 +2022,7 @@ sp_api::impl_runtime_apis! {

fn get_multi_asset() -> MultiAsset {
MultiAsset {
id: Concrete(KsmLocation::get()),
id: Concrete(TokenLocation::get()),
fun: Fungible(1 * UNITS),
}
}
Expand All @@ -2045,7 +2045,7 @@ sp_api::impl_runtime_apis! {

fn claimable_asset() -> Result<(MultiLocation, MultiLocation, MultiAssets), BenchmarkError> {
let origin = Statemine::get();
let assets: MultiAssets = (Concrete(KsmLocation::get()), 1_000 * UNITS).into();
let assets: MultiAssets = (Concrete(TokenLocation::get()), 1_000 * UNITS).into();
let ticket = MultiLocation { parents: 0, interior: Here };
Ok((origin, ticket, assets))
}
Expand Down
2 changes: 1 addition & 1 deletion runtime/kusama/src/weights/xcm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl<RuntimeCall> XcmWeightInfo<RuntimeCall> for KusamaXcmWeight<RuntimeCall> {
assets.weigh_multi_assets(XcmBalancesWeight::<Runtime>::transfer_reserve_asset())
}
fn transact(
_origin_type: &OriginKind,
_origin_kind: &OriginKind,
_require_weight_at_most: &u64,
_call: &DoubleEncoded<RuntimeCall>,
) -> XCMWeight {
Expand Down
25 changes: 13 additions & 12 deletions runtime/kusama/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ parameter_types! {
/// The location of the KSM token, from the context of this chain. Since this token is native to this
/// chain, we make it synonymous with it and thus it is the `Here` location, which means "equivalent to
/// the context".
pub const KsmLocation: MultiLocation = Here.into();
pub const TokenLocation: MultiLocation = Here.into();
/// The Kusama network ID. This is named.
pub const KusamaNetwork: NetworkId = NetworkId::Kusama;
pub const ThisNetwork: NetworkId = NetworkId::Kusama;
/// Our XCM location ancestry - i.e. what, if anything, `Parent` means evaluated in our context. Since
/// Kusama is a top-level relay-chain, there is no ancestry.
pub const Ancestry: MultiLocation = Here.into();
Expand All @@ -52,18 +52,18 @@ pub type SovereignAccountOf = (
// We can convert a child parachain using the standard `AccountId` conversion.
ChildParachainConvertsVia<ParaId, AccountId>,
// We can directly alias an `AccountId32` into a local account.
AccountId32Aliases<KusamaNetwork, AccountId>,
AccountId32Aliases<ThisNetwork, 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`.
///
/// Ours is only aware of the Balances pallet, which is mapped to `KsmLocation`.
/// Ours is only aware of the Balances pallet, which is mapped to `TokenLocation`.
pub type LocalAssetTransactor = XcmCurrencyAdapter<
// Use this currency:
Balances,
// Use this currency when it is a fungible asset matching the given location or name:
IsConcrete<KsmLocation>,
IsConcrete<TokenLocation>,
// We can convert the MultiLocations with our converter above:
SovereignAccountOf,
// Our chain's account ID type (we can't get away without mentioning it explicitly):
Expand All @@ -79,7 +79,7 @@ type LocalOriginConverter = (
// A child parachain, natively expressed, has the `Parachain` origin.
ChildParachainAsNative<parachains_origin::Origin, RuntimeOrigin>,
// The AccountId32 location type can be expressed natively as a `Signed` origin.
SignedAccountId32AsNative<KusamaNetwork, RuntimeOrigin>,
SignedAccountId32AsNative<ThisNetwork, RuntimeOrigin>,
// A system child parachain, expressed as a Superuser, converts to the `Root` origin.
ChildSystemParachainAsSuperuser<ParaId, RuntimeOrigin>,
);
Expand All @@ -100,14 +100,14 @@ pub type XcmRouter = (
);

parameter_types! {
pub const Kusama: MultiAssetFilter = Wild(AllOf { fun: WildFungible, id: Concrete(KsmLocation::get()) });
pub const Kusama: MultiAssetFilter = Wild(AllOf { fun: WildFungible, id: Concrete(TokenLocation::get()) });
pub const Statemine: MultiLocation = Parachain(1000).into();
pub const Encointer: MultiLocation = Parachain(1001).into();
pub const KusamaForStatemine: (MultiAssetFilter, MultiLocation) = (Kusama::get(), Statemine::get());
pub const KusamaForEncointer: (MultiAssetFilter, MultiLocation) = (Kusama::get(), Encointer::get());
pub const KsmForStatemine: (MultiAssetFilter, MultiLocation) = (Kusama::get(), Statemine::get());
pub const KsmForEncointer: (MultiAssetFilter, MultiLocation) = (Kusama::get(), Encointer::get());
}
pub type TrustedTeleporters =
(xcm_builder::Case<KusamaForStatemine>, xcm_builder::Case<KusamaForEncointer>);
(xcm_builder::Case<KsmForStatemine>, xcm_builder::Case<KsmForEncointer>);

match_types! {
pub type OnlyParachains: impl Contains<MultiLocation> = {
Expand Down Expand Up @@ -145,7 +145,8 @@ impl xcm_executor::Config for XcmConfig {
MaxInstructions,
>;
// The weight trader piggybacks on the existing transaction-fee conversion logic.
type Trader = UsingComponents<WeightToFee, KsmLocation, AccountId, Balances, ToAuthor<Runtime>>;
type Trader =
UsingComponents<WeightToFee, TokenLocation, AccountId, Balances, ToAuthor<Runtime>>;
type ResponseHandler = XcmPallet;
type AssetTrap = XcmPallet;
type AssetClaims = XcmPallet;
Expand Down Expand Up @@ -174,7 +175,7 @@ pub type LocalOriginToLocation = (
// `Unit` body.
CouncilToPlurality,
// And a usual Signed origin to be used in XCM as a corresponding AccountId32
SignedToAccountId32<RuntimeOrigin, AccountId, KusamaNetwork>,
SignedToAccountId32<RuntimeOrigin, AccountId, ThisNetwork>,
);

/// Type to convert the `StakingAdmin` origin to a Plurality `MultiLocation` value.
Expand Down
1 change: 0 additions & 1 deletion runtime/parachains/src/configuration/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ ump_max_individual_weight : pre.ump_max_individual_weight,
pvf_checking_enabled : pre.pvf_checking_enabled,
pvf_voting_ttl : pre.pvf_voting_ttl,
minimum_validation_upgrade_delay : pre.minimum_validation_upgrade_delay,

}
};

Expand Down
4 changes: 2 additions & 2 deletions runtime/parachains/src/configuration/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ fn setting_pending_config_members() {
max_upward_queue_count: 1337,
max_upward_queue_size: 228,
max_downward_message_size: 2048,
ump_service_total_weight: Weight::from_ref_time(20000),
ump_service_total_weight: Weight::from_parts(20000, 20000),
max_upward_message_size: 448,
max_upward_message_num_per_candidate: 5,
hrmp_sender_deposit: 22,
Expand All @@ -331,7 +331,7 @@ fn setting_pending_config_members() {
hrmp_max_parachain_outbound_channels: 10,
hrmp_max_parathread_outbound_channels: 20,
hrmp_max_message_num_per_candidate: 20,
ump_max_individual_weight: Weight::from_ref_time(909),
ump_max_individual_weight: Weight::from_parts(909, 909),
pvf_checking_enabled: true,
pvf_voting_ttl: 3,
minimum_validation_upgrade_delay: 20,
Expand Down
2 changes: 1 addition & 1 deletion runtime/parachains/src/disputes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -973,7 +973,7 @@ impl<T: Config> Pallet<T> {

/// Handle a set of dispute statements corresponding to a single candidate.
///
/// Fails if the dispute data is invalid. Returns a boolean indicating whether the
/// Fails if the dispute data is invalid. Returns a Boolean indicating whether the
/// dispute is fresh.
fn process_checked_dispute_data(
set: CheckedDisputeStatementSet,
Expand Down
30 changes: 30 additions & 0 deletions runtime/parachains/src/dmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ pub use pallet::*;
#[cfg(test)]
mod tests;

pub const MAX_MESSAGE_QUEUE_SIZE: usize = 1024;

/// An error sending a downward message.
#[cfg_attr(test, derive(Debug))]
pub enum QueueDownwardMessageError {
Expand Down Expand Up @@ -137,6 +139,28 @@ impl<T: Config> Pallet<T> {
<Self as Store>::DownwardMessageQueueHeads::remove(outgoing_para);
}

/// Determine whether enqueuing a downward message to a specific recipient para would result
/// in an error. If this returns `Ok(())` the caller can be certain that a call to
/// `queue_downward_message` with the same parameters will be successful.
pub fn can_queue_downward_message(
config: &HostConfiguration<T::BlockNumber>,
para: &ParaId,
msg: &DownwardMessage,
) -> Result<(), QueueDownwardMessageError> {
let serialized_len = msg.len() as u32;
if serialized_len > config.max_downward_message_size {
return Err(QueueDownwardMessageError::ExceedsMaxMessageSize)
}

if <Self as Store>::DownwardMessageQueues::decode_len(para).unwrap_or(0) >
MAX_MESSAGE_QUEUE_SIZE
{
return Err(QueueDownwardMessageError::ExceedsMaxMessageSize)
}

Ok(())
}

/// Enqueue a downward message to a specific recipient para.
///
/// When encoded, the message should not exceed the `config.max_downward_message_size`.
Expand All @@ -155,6 +179,12 @@ impl<T: Config> Pallet<T> {
return Err(QueueDownwardMessageError::ExceedsMaxMessageSize)
}

if <Self as Store>::DownwardMessageQueues::decode_len(para).unwrap_or(0) >
MAX_MESSAGE_QUEUE_SIZE
{
return Err(QueueDownwardMessageError::ExceedsMaxMessageSize)
}

Comment on lines +182 to +187
Copy link
Member Author

Choose a reason for hiding this comment

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

this might be the only logic change, but seems pretty uncontroversial

let inbound =
InboundDownwardMessage { msg, sent_at: <frame_system::Pallet<T>>::block_number() };

Expand Down
4 changes: 2 additions & 2 deletions runtime/parachains/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ parameter_types! {
pub const BlockHashCount: u32 = 250;
pub BlockWeights: frame_system::limits::BlockWeights =
frame_system::limits::BlockWeights::simple_max(
Weight::from_ref_time(4 * 1024 * 1024).set_proof_size(u64::MAX),
Weight::from_parts(4 * 1024 * 1024, u64::MAX),
);
}

Expand Down Expand Up @@ -394,7 +394,7 @@ impl UmpSink for TestUmpSink {
max_weight: Weight,
) -> Result<Weight, (MessageId, Weight)> {
let weight = match u32::decode(&mut &actual_msg[..]) {
Ok(w) => Weight::from_ref_time(w as u64),
Ok(w) => Weight::from_parts(w as u64, w as u64),
Err(_) => return Ok(Weight::zero()), // same as the real `UmpSink`
};
if weight.any_gt(max_weight) {
Expand Down
4 changes: 2 additions & 2 deletions runtime/parachains/src/paras/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ pub struct ReplacementTimes<N> {
#[cfg_attr(test, derive(Debug, Clone, PartialEq))]
pub struct ParaPastCodeMeta<N> {
/// Block numbers where the code was expected to be replaced and where the code
/// was actually replaced, respectively. The first is used to do accurate lookups
/// was actually replaced, respectively. The first is used to do accurate look-ups
/// of historic code in historic contexts, whereas the second is used to do
/// pruning on an accurate timeframe. These can be used as indices
/// into the `PastCodeHash` map along with the `ParaId` to fetch the code itself.
Expand Down Expand Up @@ -520,7 +520,7 @@ impl WeightInfo for TestWeightInfo {
}
fn include_pvf_check_statement() -> Weight {
// This special value is to distinguish from the finalizing variants above in tests.
Weight::MAX - Weight::from_ref_time(1)
Weight::MAX - Weight::from_parts(1, 1)
}
}

Expand Down
6 changes: 3 additions & 3 deletions runtime/parachains/src/ump/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ fn queue_upward_msg<T: Config>(
fn create_message_min_size<T: Config>(size: u32) -> Vec<u8> {
// Create a message with an empty remark call to determine the encoding overhead
let msg_size_empty_transact = VersionedXcm::<T>::from(Xcm::<T>(vec![Transact {
origin_type: OriginKind::SovereignAccount,
origin_kind: OriginKind::SovereignAccount,
require_weight_at_most: Weight::MAX.ref_time(),
call: frame_system::Call::<T>::remark_with_event { remark: vec![] }.encode().into(),
}]))
Expand All @@ -54,7 +54,7 @@ fn create_message_min_size<T: Config>(size: u32) -> Vec<u8> {
let mut remark = Vec::new();
remark.resize(size, 0u8);
let msg = VersionedXcm::<T>::from(Xcm::<T>(vec![Transact {
origin_type: OriginKind::SovereignAccount,
origin_kind: OriginKind::SovereignAccount,
require_weight_at_most: Weight::MAX.ref_time(),
call: frame_system::Call::<T>::remark_with_event { remark }.encode().into(),
}]))
Expand All @@ -69,7 +69,7 @@ fn create_message_overweight<T: Config>() -> Vec<u8> {
// We use a `set_code` Call because it
let call = frame_system::Call::<T>::set_code { code: vec![] };
VersionedXcm::<T>::from(Xcm::<T>(vec![Transact {
origin_type: OriginKind::Superuser,
origin_kind: OriginKind::Superuser,
require_weight_at_most: max_block_weight.ref_time(),
call: call.encode().into(),
}]))
Expand Down
Loading