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

Derive DecodeWithMemTracking for cumulus pallets and for polkadot-sdk runtimes #7627

Merged
Merged
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
12 changes: 11 additions & 1 deletion bridges/snowbridge/pallets/system/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,17 @@ mod pallet_xcm_origin {

// Insert this custom Origin into the aggregate RuntimeOrigin
#[pallet::origin]
#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo, MaxEncodedLen)]
#[derive(
PartialEq,
Eq,
Clone,
Encode,
Decode,
DecodeWithMemTracking,
RuntimeDebug,
TypeInfo,
MaxEncodedLen,
)]
pub struct Origin(pub Location);

impl From<Location> for Origin {
Expand Down
12 changes: 11 additions & 1 deletion cumulus/pallets/xcm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,17 @@ pub mod pallet {
}

/// Origin for the parachains module.
#[derive(PartialEq, Eq, Clone, Encode, Decode, TypeInfo, RuntimeDebug, MaxEncodedLen)]
#[derive(
PartialEq,
Eq,
Clone,
Encode,
Decode,
DecodeWithMemTracking,
TypeInfo,
RuntimeDebug,
MaxEncodedLen,
)]
#[pallet::origin]
pub enum Origin {
/// It comes from the (parent) relay chain.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ use testnet_parachains_constants::rococo::snowbridge::EthereumNetwork;
use sp_version::NativeVersion;
use sp_version::RuntimeVersion;

use codec::{Decode, Encode, MaxEncodedLen};
use codec::{Decode, DecodeWithMemTracking, Encode, MaxEncodedLen};
use cumulus_primitives_core::ParaId;
use frame_support::{
construct_runtime, derive_impl,
Expand Down Expand Up @@ -562,6 +562,7 @@ parameter_types! {
PartialOrd,
Encode,
Decode,
DecodeWithMemTracking,
RuntimeDebug,
MaxEncodedLen,
scale_info::TypeInfo,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use assets_common::{
local_and_foreign_assets::{LocalFromLeft, TargetFromLeft},
AssetIdForPoolAssets, AssetIdForPoolAssetsConvert, AssetIdForTrustBackedAssetsConvert,
};
use codec::{Decode, Encode, MaxEncodedLen};
use codec::{Decode, DecodeWithMemTracking, Encode, MaxEncodedLen};
use cumulus_pallet_parachain_system::RelayNumberMonotonicallyIncreases;
use cumulus_primitives_core::{AggregateMessageOrigin, ClaimQueueOffset, CoreSelector, ParaId};
use frame_support::{
Expand Down Expand Up @@ -614,6 +614,7 @@ parameter_types! {
PartialOrd,
Encode,
Decode,
DecodeWithMemTracking,
RuntimeDebug,
MaxEncodedLen,
scale_info::TypeInfo,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//! Runtime configuration for MessageQueue pallet
use codec::{Decode, Encode, MaxEncodedLen};
use codec::{Decode, DecodeWithMemTracking, Encode, MaxEncodedLen};
use core::marker::PhantomData;
use cumulus_primitives_core::{AggregateMessageOrigin as CumulusAggregateMessageOrigin, ParaId};
use frame_support::{
Expand All @@ -28,7 +28,18 @@ use xcm::latest::prelude::{Junction, Location};
/// The aggregate origin of an inbound message.
/// This is specialized for BridgeHub, as the snowbridge-outbound-queue-pallet is also using
/// the shared MessageQueue pallet.
#[derive(Encode, Decode, Copy, MaxEncodedLen, Clone, Eq, PartialEq, TypeInfo, Debug)]
#[derive(
Encode,
Decode,
DecodeWithMemTracking,
Copy,
MaxEncodedLen,
Clone,
Eq,
PartialEq,
TypeInfo,
Debug,
)]
pub enum AggregateMessageOrigin {
/// The message came from the para-chain itself.
Here,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,17 @@ pub mod pallet_origins {
#[pallet::config]
pub trait Config: frame_system::Config {}

#[derive(PartialEq, Eq, Clone, MaxEncodedLen, Encode, Decode, TypeInfo, RuntimeDebug)]
#[derive(
PartialEq,
Eq,
Clone,
MaxEncodedLen,
Encode,
Decode,
DecodeWithMemTracking,
TypeInfo,
RuntimeDebug,
)]
#[pallet::origin]
pub enum Origin {
/// Plurality voice of the [ranks::AMBASSADOR_TIER_1] members or above given via
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,17 @@ pub mod pallet_origins {
#[pallet::pallet]
pub struct Pallet<T>(_);

#[derive(PartialEq, Eq, Clone, MaxEncodedLen, Encode, Decode, TypeInfo, RuntimeDebug)]
#[derive(
PartialEq,
Eq,
Clone,
MaxEncodedLen,
Encode,
Decode,
DecodeWithMemTracking,
TypeInfo,
RuntimeDebug,
)]
#[pallet::origin]
pub enum Origin {
/// Origin aggregated through weighted votes of those with rank 1 or above; `Success` is 1.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ use sp_runtime::{
use sp_version::NativeVersion;
use sp_version::RuntimeVersion;

use codec::{Decode, Encode, MaxEncodedLen};
use codec::{Decode, DecodeWithMemTracking, Encode, MaxEncodedLen};
use cumulus_primitives_core::{AggregateMessageOrigin, ClaimQueueOffset, CoreSelector, ParaId};
use frame_support::{
construct_runtime, derive_impl,
Expand Down Expand Up @@ -292,6 +292,7 @@ parameter_types! {
PartialOrd,
Encode,
Decode,
DecodeWithMemTracking,
RuntimeDebug,
MaxEncodedLen,
scale_info::TypeInfo,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub mod xcm_config;
extern crate alloc;

use alloc::{vec, vec::Vec};
use codec::{Decode, Encode, MaxEncodedLen};
use codec::{Decode, DecodeWithMemTracking, Encode, MaxEncodedLen};
use cumulus_pallet_parachain_system::RelayNumberMonotonicallyIncreases;
use cumulus_primitives_core::{AggregateMessageOrigin, ClaimQueueOffset, CoreSelector, ParaId};
use frame_support::{
Expand Down Expand Up @@ -470,6 +470,7 @@ impl pallet_multisig::Config for Runtime {
PartialOrd,
Encode,
Decode,
DecodeWithMemTracking,
RuntimeDebug,
MaxEncodedLen,
scale_info::TypeInfo,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub mod xcm_config;
extern crate alloc;

use alloc::{vec, vec::Vec};
use codec::{Decode, Encode, MaxEncodedLen};
use codec::{Decode, DecodeWithMemTracking, Encode, MaxEncodedLen};
use cumulus_pallet_parachain_system::RelayNumberMonotonicallyIncreases;
use cumulus_primitives_core::{AggregateMessageOrigin, ClaimQueueOffset, CoreSelector, ParaId};
use frame_support::{
Expand Down Expand Up @@ -471,6 +471,7 @@ impl pallet_multisig::Config for Runtime {
PartialOrd,
Encode,
Decode,
DecodeWithMemTracking,
RuntimeDebug,
MaxEncodedLen,
scale_info::TypeInfo,
Expand Down
3 changes: 2 additions & 1 deletion cumulus/parachains/runtimes/people/people-rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub mod xcm_config;
extern crate alloc;

use alloc::{vec, vec::Vec};
use codec::{Decode, Encode, MaxEncodedLen};
use codec::{Decode, DecodeWithMemTracking, Encode, MaxEncodedLen};
use cumulus_pallet_parachain_system::RelayNumberMonotonicallyIncreases;
use cumulus_primitives_core::{AggregateMessageOrigin, ClaimQueueOffset, CoreSelector, ParaId};
use frame_support::{
Expand Down Expand Up @@ -432,6 +432,7 @@ impl pallet_multisig::Config for Runtime {
PartialOrd,
Encode,
Decode,
DecodeWithMemTracking,
RuntimeDebug,
MaxEncodedLen,
scale_info::TypeInfo,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ pub enum IdentityField {
CloneNoBound,
Encode,
Decode,
DecodeWithMemTracking,
EqNoBound,
MaxEncodedLen,
PartialEqNoBound,
Expand Down
3 changes: 2 additions & 1 deletion cumulus/parachains/runtimes/people/people-westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub mod xcm_config;
extern crate alloc;

use alloc::{vec, vec::Vec};
use codec::{Decode, Encode, MaxEncodedLen};
use codec::{Decode, DecodeWithMemTracking, Encode, MaxEncodedLen};
use cumulus_pallet_parachain_system::RelayNumberMonotonicallyIncreases;
use cumulus_primitives_core::{AggregateMessageOrigin, ClaimQueueOffset, CoreSelector, ParaId};
use frame_support::{
Expand Down Expand Up @@ -431,6 +431,7 @@ impl pallet_multisig::Config for Runtime {
PartialOrd,
Encode,
Decode,
DecodeWithMemTracking,
RuntimeDebug,
MaxEncodedLen,
scale_info::TypeInfo,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ pub enum IdentityField {
CloneNoBound,
Encode,
Decode,
DecodeWithMemTracking,
EqNoBound,
MaxEncodedLen,
PartialEqNoBound,
Expand Down
6 changes: 4 additions & 2 deletions cumulus/primitives/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
extern crate alloc;

use alloc::vec::Vec;
use codec::{Decode, Encode, MaxEncodedLen};
use codec::{Decode, DecodeWithMemTracking, Encode, MaxEncodedLen};
use polkadot_parachain_primitives::primitives::HeadData;
use scale_info::TypeInfo;
use sp_runtime::RuntimeDebug;
Expand Down Expand Up @@ -85,7 +85,9 @@ impl From<MessageSendError> for &'static str {
}

/// The origin of an inbound message.
#[derive(Encode, Decode, MaxEncodedLen, Clone, Eq, PartialEq, TypeInfo, Debug)]
#[derive(
Encode, Decode, DecodeWithMemTracking, MaxEncodedLen, Clone, Eq, PartialEq, TypeInfo, Debug,
)]
pub enum AggregateMessageOrigin {
/// The message came from the para-chain itself.
Here,
Expand Down
10 changes: 9 additions & 1 deletion cumulus/primitives/parachain-inherent/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,15 @@ use sp_inherents::InherentIdentifier;
pub const INHERENT_IDENTIFIER: InherentIdentifier = *b"sysi1337";

/// The inherent data that is passed by the collator to the parachain runtime.
#[derive(codec::Encode, codec::Decode, sp_core::RuntimeDebug, Clone, PartialEq, TypeInfo)]
#[derive(
codec::Encode,
codec::Decode,
codec::DecodeWithMemTracking,
sp_core::RuntimeDebug,
Clone,
PartialEq,
TypeInfo,
)]
pub struct ParachainInherentData {
pub validation_data: PersistedValidationData,
/// A storage proof of a predefined set of keys from the relay-chain.
Expand Down
12 changes: 11 additions & 1 deletion docs/sdk/src/reference_docs/frame_origin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,17 @@ pub mod pallet_with_custom_origin {
#[docify::export(custom_origin)]
/// A dummy custom origin.
#[pallet::origin]
#[derive(PartialEq, Eq, Clone, RuntimeDebug, Encode, Decode, TypeInfo, MaxEncodedLen)]
#[derive(
PartialEq,
Eq,
Clone,
RuntimeDebug,
Encode,
Decode,
DecodeWithMemTracking,
TypeInfo,
MaxEncodedLen,
)]
pub enum Origin {
/// If all holders of a particular NFT have agreed upon this.
AllNftHolders,
Expand Down
12 changes: 11 additions & 1 deletion docs/sdk/src/reference_docs/frame_runtime_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,17 @@ pub mod pallet_foo {
pub trait Config: frame_system::Config {}

#[pallet::origin]
#[derive(PartialEq, Eq, Clone, RuntimeDebug, Encode, Decode, TypeInfo, MaxEncodedLen)]
#[derive(
PartialEq,
Eq,
Clone,
RuntimeDebug,
Encode,
Decode,
DecodeWithMemTracking,
TypeInfo,
MaxEncodedLen,
)]
pub enum Origin {
A,
B,
Expand Down
37 changes: 32 additions & 5 deletions polkadot/core-primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

extern crate alloc;

use codec::{Decode, Encode};
use codec::{Decode, DecodeWithMemTracking, Encode};
use scale_info::TypeInfo;
use sp_runtime::{
generic,
Expand Down Expand Up @@ -65,7 +65,20 @@ pub type Hash = sp_core::H256;
/// This type is produced by `CandidateReceipt::hash`.
///
/// This type makes it easy to enforce that a hash is a candidate hash on the type level.
#[derive(Clone, Copy, Encode, Decode, Hash, Eq, PartialEq, Default, PartialOrd, Ord, TypeInfo)]
#[derive(
Clone,
Copy,
Encode,
Decode,
DecodeWithMemTracking,
Hash,
Eq,
PartialEq,
Default,
PartialOrd,
Ord,
TypeInfo,
)]
pub struct CandidateHash(pub Hash);

#[cfg(feature = "std")]
Expand Down Expand Up @@ -125,7 +138,9 @@ pub type DownwardMessage = alloc::vec::Vec<u8>;

/// A wrapped version of `DownwardMessage`. The difference is that it has attached the block number
/// when the message was sent.
#[derive(Encode, Decode, Clone, sp_runtime::RuntimeDebug, PartialEq, TypeInfo)]
#[derive(
Encode, Decode, DecodeWithMemTracking, Clone, sp_runtime::RuntimeDebug, PartialEq, TypeInfo,
)]
pub struct InboundDownwardMessage<BlockNumber = crate::BlockNumber> {
/// The block number at which these messages were put into the downward message queue.
pub sent_at: BlockNumber,
Expand All @@ -134,7 +149,9 @@ pub struct InboundDownwardMessage<BlockNumber = crate::BlockNumber> {
}

/// An HRMP message seen from the perspective of a recipient.
#[derive(Encode, Decode, Clone, sp_runtime::RuntimeDebug, PartialEq, TypeInfo)]
#[derive(
Encode, Decode, DecodeWithMemTracking, Clone, sp_runtime::RuntimeDebug, PartialEq, TypeInfo,
)]
pub struct InboundHrmpMessage<BlockNumber = crate::BlockNumber> {
/// The block number at which this message was sent.
/// Specifically, it is the block number at which the candidate that sends this message was
Expand All @@ -145,7 +162,17 @@ pub struct InboundHrmpMessage<BlockNumber = crate::BlockNumber> {
}

/// An HRMP message seen from the perspective of a sender.
#[derive(Encode, Decode, Clone, sp_runtime::RuntimeDebug, PartialEq, Eq, Hash, TypeInfo)]
#[derive(
Encode,
Decode,
DecodeWithMemTracking,
Clone,
sp_runtime::RuntimeDebug,
PartialEq,
Eq,
Hash,
TypeInfo,
)]
pub struct OutboundHrmpMessage<Id> {
/// The para that will get this message in its downward message queue.
pub recipient: Id,
Expand Down
Loading
Loading