mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 03:01:07 +00:00
parachain dmp.rs to Frame V2 (#3426)
* migration * fix warning * change runtimes * extra line * another double space lol * add dmp in test runtime * test runtime * Adjust visibility on storage items Co-authored-by: Keith Yeung <kungfukeith11@gmail.com>
This commit is contained in:
@@ -30,7 +30,7 @@ impl<T: configuration::Config + dmp::Config> SendXcm for ChildParachainRouter<T>
|
||||
MultiLocation::X1(Junction::Parachain(id)) => {
|
||||
// Downward message passing.
|
||||
let config = <configuration::Module<T>>::config();
|
||||
<dmp::Module<T>>::queue_downward_message(
|
||||
<dmp::Pallet<T>>::queue_downward_message(
|
||||
&config,
|
||||
id.into(),
|
||||
VersionedXcm::from(msg).encode(),
|
||||
|
||||
@@ -1487,7 +1487,7 @@ construct_runtime! {
|
||||
ParasScheduler: parachains_scheduler::{Pallet, Call, Storage} = 55,
|
||||
Paras: parachains_paras::{Pallet, Call, Storage, Event, Config} = 56,
|
||||
Initializer: parachains_initializer::{Pallet, Call, Storage} = 57,
|
||||
ParasDmp: parachains_dmp::{Pallet, Call, Storage} = 58,
|
||||
Dmp: parachains_dmp::{Pallet, Call, Storage} = 58,
|
||||
ParasUmp: parachains_ump::{Pallet, Call, Storage, Event} = 59,
|
||||
ParasHrmp: parachains_hrmp::{Pallet, Call, Storage, Event} = 60,
|
||||
ParasSessionInfo: parachains_session_info::{Pallet, Call, Storage} = 61,
|
||||
|
||||
@@ -18,12 +18,14 @@ use crate::{
|
||||
configuration::{self, HostConfiguration},
|
||||
initializer,
|
||||
};
|
||||
use frame_support::{decl_module, decl_storage, StorageMap, weights::Weight, traits::Get};
|
||||
use frame_support::pallet_prelude::*;
|
||||
use sp_std::{fmt, prelude::*};
|
||||
use sp_runtime::traits::{BlakeTwo256, Hash as HashT, SaturatedConversion};
|
||||
use primitives::v1::{Id as ParaId, DownwardMessage, InboundDownwardMessage, Hash};
|
||||
use xcm::v0::Error as XcmError;
|
||||
|
||||
pub use pallet::*;
|
||||
|
||||
/// An error sending a downward message.
|
||||
#[cfg_attr(test, derive(Debug))]
|
||||
pub enum QueueDownwardMessageError {
|
||||
@@ -71,30 +73,49 @@ impl fmt::Debug for ProcessedDownwardMessagesAcceptanceErr {
|
||||
}
|
||||
}
|
||||
|
||||
pub trait Config: frame_system::Config + configuration::Config {}
|
||||
#[frame_support::pallet]
|
||||
pub mod pallet {
|
||||
use super::*;
|
||||
|
||||
decl_storage! {
|
||||
trait Store for Module<T: Config> as Dmp {
|
||||
/// The downward messages addressed for a certain para.
|
||||
DownwardMessageQueues: map hasher(twox_64_concat) ParaId => Vec<InboundDownwardMessage<T::BlockNumber>>;
|
||||
/// A mapping that stores the downward message queue MQC head for each para.
|
||||
///
|
||||
/// Each link in this chain has a form:
|
||||
/// `(prev_head, B, H(M))`, where
|
||||
/// - `prev_head`: is the previous head hash or zero if none.
|
||||
/// - `B`: is the relay-chain block number in which a message was appended.
|
||||
/// - `H(M)`: is the hash of the message being appended.
|
||||
DownwardMessageQueueHeads: map hasher(twox_64_concat) ParaId => Hash;
|
||||
}
|
||||
}
|
||||
#[pallet::pallet]
|
||||
#[pallet::generate_store(pub(super) trait Store)]
|
||||
pub struct Pallet<T>(_);
|
||||
|
||||
decl_module! {
|
||||
/// The DMP module.
|
||||
pub struct Module<T: Config> for enum Call where origin: <T as frame_system::Config>::Origin { }
|
||||
#[pallet::config]
|
||||
pub trait Config: frame_system::Config + configuration::Config {}
|
||||
|
||||
/// The downward messages addressed for a certain para.
|
||||
#[pallet::storage]
|
||||
pub(crate) type DownwardMessageQueues<T: Config> = StorageMap<
|
||||
_,
|
||||
Twox64Concat,
|
||||
ParaId,
|
||||
Vec<InboundDownwardMessage<T::BlockNumber>>,
|
||||
ValueQuery
|
||||
>;
|
||||
|
||||
/// A mapping that stores the downward message queue MQC head for each para.
|
||||
///
|
||||
/// Each link in this chain has a form:
|
||||
/// `(prev_head, B, H(M))`, where
|
||||
/// - `prev_head`: is the previous head hash or zero if none.
|
||||
/// - `B`: is the relay-chain block number in which a message was appended.
|
||||
/// - `H(M)`: is the hash of the message being appended.
|
||||
#[pallet::storage]
|
||||
pub(crate) type DownwardMessageQueueHeads<T: Config> = StorageMap<
|
||||
_,
|
||||
Twox64Concat,
|
||||
ParaId,
|
||||
Hash,
|
||||
ValueQuery,
|
||||
>;
|
||||
|
||||
#[pallet::call]
|
||||
impl<T: Config> Pallet<T> {}
|
||||
}
|
||||
|
||||
/// Routines and getters related to downward message passing.
|
||||
impl<T: Config> Module<T> {
|
||||
impl<T: Config> Pallet<T> {
|
||||
/// Block initialization logic, called by initializer.
|
||||
pub(crate) fn initializer_initialize(_now: T::BlockNumber) -> Weight {
|
||||
0
|
||||
@@ -226,7 +247,6 @@ mod tests {
|
||||
use super::*;
|
||||
use hex_literal::hex;
|
||||
use primitives::v1::BlockNumber;
|
||||
use frame_support::traits::{OnFinalize, OnInitialize};
|
||||
use parity_scale_codec::Encode;
|
||||
use crate::mock::{Configuration, new_test_ext, System, Dmp, MockGenesisConfig, Paras};
|
||||
|
||||
|
||||
@@ -1051,7 +1051,7 @@ impl<T: Config> Module<T> {
|
||||
.encode()
|
||||
};
|
||||
if let Err(dmp::QueueDownwardMessageError::ExceedsMaxMessageSize) =
|
||||
<dmp::Module<T>>::queue_downward_message(&config, recipient, notification_bytes)
|
||||
<dmp::Pallet<T>>::queue_downward_message(&config, recipient, notification_bytes)
|
||||
{
|
||||
// this should never happen unless the max downward message size is configured to an
|
||||
// jokingly small number.
|
||||
@@ -1114,7 +1114,7 @@ impl<T: Config> Module<T> {
|
||||
.encode()
|
||||
};
|
||||
if let Err(dmp::QueueDownwardMessageError::ExceedsMaxMessageSize) =
|
||||
<dmp::Module<T>>::queue_downward_message(&config, sender, notification_bytes)
|
||||
<dmp::Pallet<T>>::queue_downward_message(&config, sender, notification_bytes)
|
||||
{
|
||||
// this should never happen unless the max downward message size is configured to an
|
||||
// jokingly small number.
|
||||
@@ -1164,7 +1164,7 @@ impl<T: Config> Module<T> {
|
||||
channel_id.sender
|
||||
};
|
||||
if let Err(dmp::QueueDownwardMessageError::ExceedsMaxMessageSize) =
|
||||
<dmp::Module<T>>::queue_downward_message(&config, opposite_party, notification_bytes)
|
||||
<dmp::Pallet<T>>::queue_downward_message(&config, opposite_party, notification_bytes)
|
||||
{
|
||||
// this should never happen unless the max downward message size is configured to an
|
||||
// jokingly small number.
|
||||
|
||||
@@ -697,7 +697,7 @@ impl<T: Config> Pallet<T> {
|
||||
}
|
||||
|
||||
// enact the messaging facet of the candidate.
|
||||
weight += <dmp::Module<T>>::prune_dmq(
|
||||
weight += <dmp::Pallet<T>>::prune_dmq(
|
||||
receipt.descriptor.para_id,
|
||||
commitments.processed_downward_messages,
|
||||
);
|
||||
@@ -918,7 +918,7 @@ impl<T: Config> CandidateCheckContext<T> {
|
||||
}
|
||||
|
||||
// check if the candidate passes the messaging acceptance criteria
|
||||
<dmp::Module<T>>::check_processed_downward_messages(
|
||||
<dmp::Pallet<T>>::check_processed_downward_messages(
|
||||
para_id,
|
||||
processed_downward_messages,
|
||||
)?;
|
||||
|
||||
@@ -139,7 +139,7 @@ pub mod pallet {
|
||||
inclusion::Pallet::<T>::initializer_initialize(now) +
|
||||
session_info::Module::<T>::initializer_initialize(now) +
|
||||
T::DisputesHandler::initializer_initialize(now) +
|
||||
dmp::Module::<T>::initializer_initialize(now) +
|
||||
dmp::Pallet::<T>::initializer_initialize(now) +
|
||||
ump::Module::<T>::initializer_initialize(now) +
|
||||
hrmp::Module::<T>::initializer_initialize(now);
|
||||
|
||||
@@ -152,7 +152,7 @@ pub mod pallet {
|
||||
// reverse initialization order.
|
||||
hrmp::Module::<T>::initializer_finalize();
|
||||
ump::Module::<T>::initializer_finalize();
|
||||
dmp::Module::<T>::initializer_finalize();
|
||||
dmp::Pallet::<T>::initializer_finalize();
|
||||
T::DisputesHandler::initializer_finalize();
|
||||
session_info::Module::<T>::initializer_finalize();
|
||||
inclusion::Pallet::<T>::initializer_finalize();
|
||||
@@ -238,7 +238,7 @@ impl<T: Config> Pallet<T> {
|
||||
inclusion::Pallet::<T>::initializer_on_new_session(¬ification);
|
||||
session_info::Module::<T>::initializer_on_new_session(¬ification);
|
||||
T::DisputesHandler::initializer_on_new_session(¬ification);
|
||||
dmp::Module::<T>::initializer_on_new_session(¬ification, &outgoing_paras);
|
||||
dmp::Pallet::<T>::initializer_on_new_session(¬ification, &outgoing_paras);
|
||||
ump::Module::<T>::initializer_on_new_session(¬ification, &outgoing_paras);
|
||||
hrmp::Module::<T>::initializer_on_new_session(¬ification, &outgoing_paras);
|
||||
}
|
||||
|
||||
@@ -315,7 +315,7 @@ pub fn session_info<T: session_info::Config>(index: SessionIndex) -> Option<Sess
|
||||
pub fn dmq_contents<T: dmp::Config>(
|
||||
recipient: ParaId,
|
||||
) -> Vec<InboundDownwardMessage<T::BlockNumber>> {
|
||||
<dmp::Module<T>>::dmq_contents(recipient)
|
||||
<dmp::Pallet<T>>::dmq_contents(recipient)
|
||||
}
|
||||
|
||||
/// Implementation for the `inbound_hrmp_channels_contents` function of the runtime API.
|
||||
|
||||
@@ -545,6 +545,7 @@ construct_runtime! {
|
||||
SessionInfo: parachains_session_info::{Pallet, Call, Storage},
|
||||
Hrmp: parachains_hrmp::{Pallet, Call, Storage, Event},
|
||||
Ump: parachains_ump::{Pallet, Call, Storage, Event},
|
||||
Dmp: parachains_dmp::{Pallet, Call, Storage},
|
||||
ParasDisputes: parachains_disputes::{Pallet, Storage, Event<T>},
|
||||
|
||||
Sudo: pallet_sudo::{Pallet, Call, Storage, Config<T>, Event<T>},
|
||||
|
||||
@@ -1078,7 +1078,7 @@ construct_runtime! {
|
||||
ParasScheduler: parachains_scheduler::{Pallet, Call, Storage} = 46,
|
||||
Paras: parachains_paras::{Pallet, Call, Storage, Event, Config} = 47,
|
||||
Initializer: parachains_initializer::{Pallet, Call, Storage} = 48,
|
||||
ParasDmp: parachains_dmp::{Pallet, Call, Storage} = 49,
|
||||
Dmp: parachains_dmp::{Pallet, Call, Storage} = 49,
|
||||
ParasUmp: parachains_ump::{Pallet, Call, Storage, Event} = 50,
|
||||
ParasHrmp: parachains_hrmp::{Pallet, Call, Storage, Event} = 51,
|
||||
ParasSessionInfo: parachains_session_info::{Pallet, Call, Storage} = 52,
|
||||
|
||||
Reference in New Issue
Block a user