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

implement DecodeWithMemTracking for frame pallets #7598

Merged
merged 5 commits into from
Feb 18, 2025
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 substrate/frame/alliance/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,17 @@ pub enum MemberRole {
}

/// The type of item that may be deemed unscrupulous.
#[derive(Clone, PartialEq, Eq, RuntimeDebug, Encode, Decode, TypeInfo, MaxEncodedLen)]
#[derive(
Clone,
PartialEq,
Eq,
RuntimeDebug,
Encode,
Decode,
DecodeWithMemTracking,
TypeInfo,
MaxEncodedLen,
)]
pub enum UnscrupulousItem<AccountId, Url> {
AccountId(AccountId),
Website(Url),
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/alliance/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ impl pallet_identity::Config for Test {
type WeightInfo = ();
}

#[derive(Clone, Debug, Encode, Decode, PartialEq, Eq, TypeInfo)]
#[derive(Clone, Debug, Encode, Decode, DecodeWithMemTracking, PartialEq, Eq, TypeInfo)]
pub struct AccountU64(u64);
impl IdentifyAccount for AccountU64 {
type AccountId = u64;
Expand Down
39 changes: 35 additions & 4 deletions substrate/frame/alliance/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,24 @@
// limitations under the License.

use alloc::vec::Vec;
use codec::{Decode, Encode, MaxEncodedLen};
use codec::{Decode, DecodeWithMemTracking, Encode, MaxEncodedLen};
use frame_support::{traits::ConstU32, BoundedVec};
use scale_info::TypeInfo;
use sp_runtime::RuntimeDebug;

/// A Multihash instance that only supports the basic functionality and no hashing.
#[derive(
Clone, PartialEq, Eq, PartialOrd, Ord, RuntimeDebug, Encode, Decode, TypeInfo, MaxEncodedLen,
Clone,
PartialEq,
Eq,
PartialOrd,
Ord,
RuntimeDebug,
Encode,
Decode,
DecodeWithMemTracking,
TypeInfo,
MaxEncodedLen,
)]
pub struct Multihash {
/// The code of the Multihash.
Expand All @@ -50,6 +60,7 @@ impl Multihash {
RuntimeDebug,
Encode,
Decode,
DecodeWithMemTracking,
TypeInfo,
MaxEncodedLen,
)]
Expand All @@ -64,7 +75,17 @@ pub enum Version {
///
/// The generic is about the allocated size of the multihash.
#[derive(
Clone, PartialEq, Eq, PartialOrd, Ord, RuntimeDebug, Encode, Decode, TypeInfo, MaxEncodedLen,
Clone,
PartialEq,
Eq,
PartialOrd,
Ord,
RuntimeDebug,
Encode,
Decode,
DecodeWithMemTracking,
TypeInfo,
MaxEncodedLen,
)]
pub struct Cid {
/// The version of CID.
Expand Down Expand Up @@ -96,7 +117,17 @@ impl Cid {

/// Witness data for the `disband` call.
#[derive(
Copy, Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, MaxEncodedLen, TypeInfo, Default,
Copy,
Clone,
Encode,
Decode,
DecodeWithMemTracking,
Eq,
PartialEq,
RuntimeDebug,
MaxEncodedLen,
TypeInfo,
Default,
)]
pub struct DisbandWitness {
/// Total number of fellow members in the current Alliance.
Expand Down
26 changes: 23 additions & 3 deletions substrate/frame/atomic-swap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ mod tests;
extern crate alloc;

use alloc::vec::Vec;
use codec::{Decode, Encode};
use codec::{Decode, DecodeWithMemTracking, Encode};
use core::{
marker::PhantomData,
ops::{Deref, DerefMut},
Expand All @@ -57,7 +57,17 @@ use frame::{
use scale_info::TypeInfo;

/// Pending atomic swap operation.
#[derive(Clone, Eq, PartialEq, RuntimeDebugNoBound, Encode, Decode, TypeInfo, MaxEncodedLen)]
#[derive(
Clone,
Eq,
PartialEq,
RuntimeDebugNoBound,
Encode,
Decode,
DecodeWithMemTracking,
TypeInfo,
MaxEncodedLen,
)]
#[scale_info(skip_type_params(T))]
#[codec(mel_bound())]
pub struct PendingSwap<T: Config> {
Expand Down Expand Up @@ -92,7 +102,17 @@ pub trait SwapAction<AccountId, T: Config> {
}

/// A swap action that only allows transferring balances.
#[derive(Clone, RuntimeDebug, Eq, PartialEq, Encode, Decode, TypeInfo, MaxEncodedLen)]
#[derive(
Clone,
RuntimeDebug,
Eq,
PartialEq,
Encode,
Decode,
DecodeWithMemTracking,
TypeInfo,
MaxEncodedLen,
)]
#[scale_info(skip_type_params(C))]
#[codec(mel_bound())]
pub struct BalanceSwapAction<AccountId, C: ReservableCurrency<AccountId>> {
Expand Down
14 changes: 12 additions & 2 deletions substrate/frame/bags-list/src/list/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use alloc::{
boxed::Box,
collections::{btree_map::BTreeMap, btree_set::BTreeSet},
};
use codec::{Decode, Encode, MaxEncodedLen};
use codec::{Decode, DecodeWithMemTracking, Encode, MaxEncodedLen};
use core::{iter, marker::PhantomData};
use frame_election_provider_support::ScoreProvider;
use frame_support::{
Expand All @@ -51,7 +51,17 @@ use alloc::vec::Vec;
#[cfg(any(test, feature = "try-runtime", feature = "fuzz"))]
use sp_runtime::TryRuntimeError;

#[derive(Debug, PartialEq, Eq, Encode, Decode, MaxEncodedLen, TypeInfo, PalletError)]
#[derive(
Debug,
PartialEq,
Eq,
Encode,
Decode,
DecodeWithMemTracking,
MaxEncodedLen,
TypeInfo,
PalletError,
)]
pub enum ListError {
/// A duplicate id has been detected.
Duplicate,
Expand Down
14 changes: 12 additions & 2 deletions substrate/frame/balances/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
//! Types used in the pallet.

use crate::{Config, CreditOf, Event, Pallet};
use codec::{Decode, Encode, MaxEncodedLen};
use codec::{Decode, DecodeWithMemTracking, Encode, MaxEncodedLen};
use core::ops::BitOr;
use frame_support::traits::{Imbalance, LockIdentifier, OnUnbalanced, WithdrawReasons};
use scale_info::TypeInfo;
Expand Down Expand Up @@ -145,7 +145,17 @@ impl<T: Config<I>, I: 'static> Drop for DustCleaner<T, I> {
}

/// Whether something should be interpreted as an increase or a decrease.
#[derive(Encode, Decode, Clone, PartialEq, Eq, RuntimeDebug, MaxEncodedLen, TypeInfo)]
#[derive(
Encode,
Decode,
DecodeWithMemTracking,
Clone,
PartialEq,
Eq,
RuntimeDebug,
MaxEncodedLen,
TypeInfo,
)]
pub enum AdjustmentDirection {
/// Increase the amount.
Increase,
Expand Down
4 changes: 2 additions & 2 deletions substrate/frame/beefy/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use codec::{Decode, Encode};
use codec::{Decode, DecodeWithMemTracking, Encode};
use frame_election_provider_support::{
bounds::{ElectionBounds, ElectionBoundsBuilder},
onchain, SequentialPhragmen, Weight,
Expand Down Expand Up @@ -95,7 +95,7 @@ pub struct MockAncestryProofContext {
pub is_valid: bool,
}

#[derive(Clone, Debug, Decode, Encode, PartialEq, TypeInfo)]
#[derive(Clone, Debug, Decode, DecodeWithMemTracking, Encode, PartialEq, TypeInfo)]
pub struct MockAncestryProof {
pub is_optimal: bool,
pub is_non_canonical: bool,
Expand Down
14 changes: 12 additions & 2 deletions substrate/frame/broker/src/core_mask.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use codec::{Decode, Encode, MaxEncodedLen};
use codec::{Decode, DecodeWithMemTracking, Encode, MaxEncodedLen};
use core::ops::{BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign, Not};
use scale_info::TypeInfo;
use sp_core::RuntimeDebug;
Expand All @@ -25,7 +25,17 @@ pub const CORE_MASK_BITS: usize = 80;

// TODO: Use BitArr instead; for this, we'll need to ensure Codec is impl'ed for `BitArr`.
#[derive(
Encode, Decode, Default, Copy, Clone, PartialEq, Eq, RuntimeDebug, TypeInfo, MaxEncodedLen,
Encode,
Decode,
DecodeWithMemTracking,
Default,
Copy,
Clone,
PartialEq,
Eq,
RuntimeDebug,
TypeInfo,
MaxEncodedLen,
)]
pub struct CoreMask([u8; 10]);
impl CoreMask {
Expand Down
14 changes: 12 additions & 2 deletions substrate/frame/broker/src/coretime_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#![deny(missing_docs)]

use alloc::vec::Vec;
use codec::{Decode, Encode, MaxEncodedLen};
use codec::{Decode, DecodeWithMemTracking, Encode, MaxEncodedLen};
use core::fmt::Debug;
use frame_support::Parameter;
use scale_info::TypeInfo;
Expand All @@ -39,7 +39,17 @@ pub type PartsOf57600 = u16;

/// An element to which a core can be assigned.
#[derive(
Encode, Decode, Clone, Eq, PartialEq, Ord, PartialOrd, RuntimeDebug, TypeInfo, MaxEncodedLen,
Encode,
Decode,
DecodeWithMemTracking,
Clone,
Eq,
PartialEq,
Ord,
PartialOrd,
RuntimeDebug,
TypeInfo,
MaxEncodedLen,
)]
pub enum CoreAssignment {
/// Core need not be used for anything.
Expand Down
64 changes: 58 additions & 6 deletions substrate/frame/broker/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::{
Config, CoreAssignment, CoreIndex, CoreMask, CoretimeInterface, RCBlockNumberOf, TaskId,
CORE_MASK_BITS,
};
use codec::{Decode, Encode, MaxEncodedLen};
use codec::{Decode, DecodeWithMemTracking, Encode, MaxEncodedLen};
use frame_support::traits::fungible::Inspect;
use frame_system::Config as SConfig;
use scale_info::TypeInfo;
Expand All @@ -42,7 +42,18 @@ pub type CoreMaskBitCount = u32;
pub type SignedCoreMaskBitCount = i32;

/// Whether a core assignment is revokable or not.
#[derive(Encode, Decode, Copy, Clone, PartialEq, Eq, RuntimeDebug, TypeInfo, MaxEncodedLen)]
#[derive(
Encode,
Decode,
DecodeWithMemTracking,
Copy,
Clone,
PartialEq,
Eq,
RuntimeDebug,
TypeInfo,
MaxEncodedLen,
)]
pub enum Finality {
/// The region remains with the same owner allowing the assignment to be altered.
Provisional,
Expand All @@ -51,7 +62,18 @@ pub enum Finality {
}

/// Self-describing identity for a Region of Bulk Coretime.
#[derive(Encode, Decode, Copy, Clone, PartialEq, Eq, RuntimeDebug, TypeInfo, MaxEncodedLen)]
#[derive(
Encode,
Decode,
DecodeWithMemTracking,
Copy,
Clone,
PartialEq,
Eq,
RuntimeDebug,
TypeInfo,
MaxEncodedLen,
)]
pub struct RegionId {
/// The timeslice at which this Region begins.
pub begin: Timeslice,
Expand Down Expand Up @@ -91,7 +113,17 @@ pub struct RegionRecord<AccountId, Balance> {
pub type RegionRecordOf<T> = RegionRecord<<T as SConfig>::AccountId, BalanceOf<T>>;

/// An distinct item which can be scheduled on a Polkadot Core.
#[derive(Encode, Decode, Clone, PartialEq, Eq, RuntimeDebug, TypeInfo, MaxEncodedLen)]
#[derive(
Encode,
Decode,
DecodeWithMemTracking,
Clone,
PartialEq,
Eq,
RuntimeDebug,
TypeInfo,
MaxEncodedLen,
)]
pub struct ScheduleItem {
/// The regularity parts in which this Item will be scheduled on the Core.
pub mask: CoreMask,
Expand Down Expand Up @@ -259,7 +291,17 @@ pub type LeasesRecordOf<T> = LeasesRecord<<T as Config>::MaxLeasedCores>;
///
/// The blocknumber is the relay chain block height `until` which the original request
/// for revenue was made.
#[derive(Encode, Decode, Clone, PartialEq, Eq, RuntimeDebug, TypeInfo, MaxEncodedLen)]
#[derive(
Encode,
Decode,
DecodeWithMemTracking,
Clone,
PartialEq,
Eq,
RuntimeDebug,
TypeInfo,
MaxEncodedLen,
)]
pub struct OnDemandRevenueRecord<RelayBlockNumber, RelayBalance> {
/// The height of the Relay-chain at the time the revenue request was made.
pub until: RelayBlockNumber,
Expand All @@ -271,7 +313,17 @@ pub type OnDemandRevenueRecordOf<T> =
OnDemandRevenueRecord<RelayBlockNumberOf<T>, RelayBalanceOf<T>>;

/// Configuration of this pallet.
#[derive(Encode, Decode, Clone, PartialEq, Eq, RuntimeDebug, TypeInfo, MaxEncodedLen)]
#[derive(
Encode,
Decode,
DecodeWithMemTracking,
Clone,
PartialEq,
Eq,
RuntimeDebug,
TypeInfo,
MaxEncodedLen,
)]
pub struct ConfigRecord<RelayBlockNumber> {
/// The number of Relay-chain blocks in advance which scheduling should be fixed and the
/// `Coretime::assign` API used to inform the Relay-chain.
Expand Down
Loading
Loading