diff --git a/bridges/modules/messages/src/lanes_manager.rs b/bridges/modules/messages/src/lanes_manager.rs index 27cab48535d7b..c785ed4e01efa 100644 --- a/bridges/modules/messages/src/lanes_manager.rs +++ b/bridges/modules/messages/src/lanes_manager.rs @@ -25,13 +25,15 @@ use bp_messages::{ MessageNonce, OutboundLaneData, }; use bp_runtime::AccountIdOf; -use codec::{Decode, Encode, MaxEncodedLen}; +use codec::{Decode, DecodeWithMemTracking, Encode, MaxEncodedLen}; use frame_support::{ensure, sp_runtime::RuntimeDebug, PalletError}; use scale_info::TypeInfo; use sp_std::marker::PhantomData; /// Lanes manager errors. -#[derive(Encode, Decode, RuntimeDebug, PartialEq, Eq, PalletError, TypeInfo)] +#[derive( + Encode, Decode, DecodeWithMemTracking, RuntimeDebug, PartialEq, Eq, PalletError, TypeInfo, +)] pub enum LanesManagerError { /// Inbound lane already exists. InboundLaneAlreadyExists, diff --git a/bridges/modules/messages/src/outbound_lane.rs b/bridges/modules/messages/src/outbound_lane.rs index c72713e7455a6..1e4411f7b4e29 100644 --- a/bridges/modules/messages/src/outbound_lane.rs +++ b/bridges/modules/messages/src/outbound_lane.rs @@ -22,7 +22,7 @@ use bp_messages::{ ChainWithMessages, DeliveredMessages, LaneState, MessageNonce, OutboundLaneData, UnrewardedRelayer, }; -use codec::{Decode, Encode}; +use codec::{Decode, DecodeWithMemTracking, Encode}; use frame_support::{traits::Get, BoundedVec, PalletError}; use scale_info::TypeInfo; use sp_runtime::RuntimeDebug; @@ -65,7 +65,9 @@ impl, I: 'static> Get for StoredMessagePayloadLimit { pub type StoredMessagePayload = BoundedVec>; /// Result of messages receival confirmation. -#[derive(Encode, Decode, RuntimeDebug, PartialEq, Eq, PalletError, TypeInfo)] +#[derive( + Encode, Decode, DecodeWithMemTracking, RuntimeDebug, PartialEq, Eq, PalletError, TypeInfo, +)] pub enum ReceptionConfirmationError { /// Bridged chain is trying to confirm more messages than we have generated. May be a result /// of invalid bridged chain storage. diff --git a/bridges/modules/xcm-bridge-hub/src/dispatcher.rs b/bridges/modules/xcm-bridge-hub/src/dispatcher.rs index dd855c7069aad..1a6be1f18e6b3 100644 --- a/bridges/modules/xcm-bridge-hub/src/dispatcher.rs +++ b/bridges/modules/xcm-bridge-hub/src/dispatcher.rs @@ -26,7 +26,7 @@ use crate::{Config, Pallet, LOG_TARGET}; use bp_messages::target_chain::{DispatchMessage, MessageDispatch}; use bp_runtime::messages::MessageDispatchResult; use bp_xcm_bridge_hub::{LocalXcmChannelManager, XcmAsPlainPayload}; -use codec::{Decode, Encode}; +use codec::{Decode, DecodeWithMemTracking, Encode}; use frame_support::{weights::Weight, CloneNoBound, EqNoBound, PartialEqNoBound}; use pallet_bridge_messages::{Config as BridgeMessagesConfig, WeightInfoExt}; use scale_info::TypeInfo; @@ -35,7 +35,16 @@ use xcm::prelude::*; use xcm_builder::{DispatchBlob, DispatchBlobError}; /// Message dispatch result type for single message. -#[derive(CloneNoBound, EqNoBound, PartialEqNoBound, Encode, Decode, Debug, TypeInfo)] +#[derive( + CloneNoBound, + EqNoBound, + PartialEqNoBound, + Encode, + Decode, + DecodeWithMemTracking, + Debug, + TypeInfo, +)] pub enum XcmBlobMessageDispatchResult { /// We've been unable to decode message payload. InvalidPayload, diff --git a/bridges/primitives/header-chain/src/justification/mod.rs b/bridges/primitives/header-chain/src/justification/mod.rs index 87f53dac64638..46c4656e33ac8 100644 --- a/bridges/primitives/header-chain/src/justification/mod.rs +++ b/bridges/primitives/header-chain/src/justification/mod.rs @@ -31,7 +31,7 @@ pub use verification::{ }; use bp_runtime::{BlockNumberOf, Chain, HashOf, HeaderId}; -use codec::{Decode, Encode, MaxEncodedLen}; +use codec::{Decode, DecodeWithMemTracking, Encode, MaxEncodedLen}; use scale_info::TypeInfo; use sp_consensus_grandpa::{AuthorityId, AuthoritySignature}; use sp_runtime::{traits::Header as HeaderT, RuntimeDebug, SaturatedConversion}; @@ -42,7 +42,7 @@ use sp_std::prelude::*; /// /// This particular proof is used to prove that headers on a bridged chain /// (so not our chain) have been finalized correctly. -#[derive(Encode, Decode, Clone, PartialEq, Eq, TypeInfo)] +#[derive(Encode, Decode, DecodeWithMemTracking, Clone, PartialEq, Eq, TypeInfo)] #[cfg_attr(feature = "std", derive(Debug))] pub struct GrandpaJustification { /// The round (voting period) this justification is valid for. diff --git a/bridges/primitives/header-chain/src/lib.rs b/bridges/primitives/header-chain/src/lib.rs index 48326bf5c19d5..cf7fde2dd739d 100644 --- a/bridges/primitives/header-chain/src/lib.rs +++ b/bridges/primitives/header-chain/src/lib.rs @@ -27,7 +27,7 @@ use bp_runtime::{ BasicOperatingMode, BlockNumberOf, Chain, HashOf, HasherOf, HeaderOf, RawStorageProof, StorageProofChecker, StorageProofError, UnderlyingChainProvider, }; -use codec::{Codec, Decode, Encode, EncodeLike, MaxEncodedLen}; +use codec::{Codec, Decode, DecodeWithMemTracking, Encode, EncodeLike, MaxEncodedLen}; use core::{clone::Clone, cmp::Eq, default::Default, fmt::Debug}; use frame_support::PalletError; use scale_info::TypeInfo; @@ -46,7 +46,9 @@ pub mod justification; pub mod storage_keys; /// Header chain error. -#[derive(Clone, Decode, Encode, Eq, PartialEq, PalletError, Debug, TypeInfo)] +#[derive( + Clone, Decode, DecodeWithMemTracking, Encode, Eq, PartialEq, PalletError, Debug, TypeInfo, +)] pub enum HeaderChainError { /// Header with given hash is missing from the chain. UnknownHeader, @@ -101,7 +103,9 @@ pub trait Parameter: Codec + EncodeLike + Clone + Eq + Debug + TypeInfo {} impl Parameter for T where T: Codec + EncodeLike + Clone + Eq + Debug + TypeInfo {} /// A GRANDPA Authority List and ID. -#[derive(Default, Encode, Eq, Decode, RuntimeDebug, PartialEq, Clone, TypeInfo)] +#[derive( + Default, Encode, Eq, Decode, DecodeWithMemTracking, RuntimeDebug, PartialEq, Clone, TypeInfo, +)] #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] pub struct AuthoritySet { /// List of GRANDPA authorities for the current round. @@ -121,7 +125,17 @@ impl AuthoritySet { /// /// The bridge needs to know where to start its sync from, and this provides that initial context. #[derive( - Default, Encode, Decode, RuntimeDebug, PartialEq, Eq, Clone, TypeInfo, Serialize, Deserialize, + Default, + Encode, + Decode, + DecodeWithMemTracking, + RuntimeDebug, + PartialEq, + Eq, + Clone, + TypeInfo, + Serialize, + Deserialize, )] pub struct InitializationData { /// The header from which we should start syncing. @@ -189,7 +203,7 @@ impl ConsensusLogReader for GrandpaConsensusLogReader { } /// The finality-related info associated to a header. -#[derive(Encode, Decode, Debug, PartialEq, Clone, TypeInfo)] +#[derive(Encode, Decode, DecodeWithMemTracking, Debug, PartialEq, Clone, TypeInfo)] pub struct HeaderFinalityInfo { /// The header finality proof. pub finality_proof: FinalityProof, diff --git a/bridges/primitives/messages/src/lane.rs b/bridges/primitives/messages/src/lane.rs index 75237a44d5385..adf06b64d31d9 100644 --- a/bridges/primitives/messages/src/lane.rs +++ b/bridges/primitives/messages/src/lane.rs @@ -16,7 +16,7 @@ //! Primitives of messages module, that represents lane id. -use codec::{Codec, Decode, Encode, EncodeLike, MaxEncodedLen}; +use codec::{Codec, Decode, DecodeWithMemTracking, Encode, EncodeLike, MaxEncodedLen}; use scale_info::TypeInfo; use serde::{de::DeserializeOwned, Deserialize, Serialize}; use sp_core::{RuntimeDebug, TypeId, H256}; @@ -50,6 +50,7 @@ pub trait LaneIdType: Clone, Copy, Decode, + DecodeWithMemTracking, Default, Encode, Eq, @@ -121,6 +122,7 @@ impl TypeId for LegacyLaneId { Clone, Copy, Decode, + DecodeWithMemTracking, Default, Encode, Eq, diff --git a/bridges/primitives/messages/src/lib.rs b/bridges/primitives/messages/src/lib.rs index 2776b806cc16b..16f5cfa1bea66 100644 --- a/bridges/primitives/messages/src/lib.rs +++ b/bridges/primitives/messages/src/lib.rs @@ -24,7 +24,7 @@ use bp_runtime::{ messages::MessageDispatchResult, BasicOperatingMode, Chain, OperatingMode, RangeInclusiveExt, StorageProofError, UnderlyingChainOf, UnderlyingChainProvider, }; -use codec::{Decode, Encode, MaxEncodedLen}; +use codec::{Decode, DecodeWithMemTracking, Encode, MaxEncodedLen}; use frame_support::PalletError; // Weight is reexported to avoid additional frame-support dependencies in related crates. pub use frame_support::weights::Weight; @@ -135,6 +135,7 @@ where #[derive( Encode, Decode, + DecodeWithMemTracking, Clone, Copy, PartialEq, @@ -336,7 +337,7 @@ pub struct UnrewardedRelayer { } /// Received messages with their dispatch result. -#[derive(Clone, Encode, Decode, RuntimeDebug, PartialEq, Eq, TypeInfo)] +#[derive(Clone, Encode, Decode, DecodeWithMemTracking, RuntimeDebug, PartialEq, Eq, TypeInfo)] pub struct ReceivedMessages { /// Id of the lane which is receiving messages. pub lane: LaneId, @@ -360,7 +361,7 @@ impl ReceivedMessages } /// Result of single message receival. -#[derive(RuntimeDebug, Encode, Decode, PartialEq, Eq, Clone, TypeInfo)] +#[derive(RuntimeDebug, Encode, Decode, DecodeWithMemTracking, PartialEq, Eq, Clone, TypeInfo)] pub enum ReceptionResult { /// Message has been received and dispatched. Note that we don't care whether dispatch has /// been successful or not - in both case message falls into this category. @@ -376,7 +377,18 @@ pub enum ReceptionResult { } /// Delivered messages with their dispatch result. -#[derive(Clone, Default, Encode, Decode, RuntimeDebug, PartialEq, Eq, TypeInfo, MaxEncodedLen)] +#[derive( + Clone, + Default, + Encode, + Decode, + DecodeWithMemTracking, + RuntimeDebug, + PartialEq, + Eq, + TypeInfo, + MaxEncodedLen, +)] pub struct DeliveredMessages { /// Nonce of the first message that has been delivered (inclusive). pub begin: MessageNonce, @@ -408,7 +420,9 @@ impl DeliveredMessages { } /// Gist of `InboundLaneData::relayers` field used by runtime APIs. -#[derive(Clone, Default, Encode, Decode, RuntimeDebug, PartialEq, Eq, TypeInfo)] +#[derive( + Clone, Default, Encode, Decode, DecodeWithMemTracking, RuntimeDebug, PartialEq, Eq, TypeInfo, +)] pub struct UnrewardedRelayersState { /// Number of entries in the `InboundLaneData::relayers` set. pub unrewarded_relayer_entries: MessageNonce, @@ -512,7 +526,9 @@ where } /// Error that happens during message verification. -#[derive(Encode, Decode, RuntimeDebug, PartialEq, Eq, PalletError, TypeInfo)] +#[derive( + Encode, Decode, DecodeWithMemTracking, RuntimeDebug, PartialEq, Eq, PalletError, TypeInfo, +)] pub enum VerificationError { /// The message proof is empty. EmptyMessageProof, diff --git a/bridges/primitives/messages/src/source_chain.rs b/bridges/primitives/messages/src/source_chain.rs index 1d4a513035c74..afb70b3d01598 100644 --- a/bridges/primitives/messages/src/source_chain.rs +++ b/bridges/primitives/messages/src/source_chain.rs @@ -19,7 +19,7 @@ use crate::{MessageNonce, UnrewardedRelayer}; use bp_runtime::{raw_storage_proof_size, RawStorageProof, Size}; -use codec::{Decode, Encode}; +use codec::{Decode, DecodeWithMemTracking, Encode}; use scale_info::TypeInfo; use sp_core::RuntimeDebug; use sp_std::{ @@ -38,7 +38,7 @@ use sp_std::{ /// - storage proof of the inbound lane state; /// /// - lane id. -#[derive(Clone, Decode, Encode, Eq, PartialEq, RuntimeDebug, TypeInfo)] +#[derive(Clone, Decode, DecodeWithMemTracking, Encode, Eq, PartialEq, RuntimeDebug, TypeInfo)] pub struct FromBridgedChainMessagesDeliveryProof { /// Hash of the bridge header the proof is for. pub bridged_header_hash: BridgedHeaderHash, diff --git a/bridges/primitives/messages/src/target_chain.rs b/bridges/primitives/messages/src/target_chain.rs index cf07a400933a9..e5b860ce305ee 100644 --- a/bridges/primitives/messages/src/target_chain.rs +++ b/bridges/primitives/messages/src/target_chain.rs @@ -19,7 +19,7 @@ use crate::{Message, MessageKey, MessageNonce, MessagePayload, OutboundLaneData}; use bp_runtime::{messages::MessageDispatchResult, raw_storage_proof_size, RawStorageProof, Size}; -use codec::{Decode, Encode, Error as CodecError}; +use codec::{Decode, DecodeWithMemTracking, Encode, Error as CodecError}; use frame_support::weights::Weight; use scale_info::TypeInfo; use sp_core::RuntimeDebug; @@ -37,7 +37,7 @@ use sp_std::{fmt::Debug, marker::PhantomData, prelude::*}; /// - lane id; /// /// - nonces (inclusive range) of messages which are included in this proof. -#[derive(Clone, Decode, Encode, Eq, PartialEq, RuntimeDebug, TypeInfo)] +#[derive(Clone, Decode, DecodeWithMemTracking, Encode, Eq, PartialEq, RuntimeDebug, TypeInfo)] pub struct FromBridgedChainMessagesProof { /// Hash of the finalized bridged header the proof is for. pub bridged_header_hash: BridgedHeaderHash, diff --git a/bridges/primitives/polkadot-core/src/parachains.rs b/bridges/primitives/polkadot-core/src/parachains.rs index a8b1cf6eebf49..be13cba3dbeb2 100644 --- a/bridges/primitives/polkadot-core/src/parachains.rs +++ b/bridges/primitives/polkadot-core/src/parachains.rs @@ -23,7 +23,7 @@ //! be two versions of polkadot crates included in the runtime. Which is bad. use bp_runtime::{raw_storage_proof_size, RawStorageProof, Size}; -use codec::{CompactAs, Decode, Encode, MaxEncodedLen}; +use codec::{CompactAs, Decode, DecodeWithMemTracking, Encode, MaxEncodedLen}; use scale_info::TypeInfo; use sp_core::Hasher; use sp_runtime::RuntimeDebug; @@ -41,6 +41,7 @@ use serde::{Deserialize, Serialize}; CompactAs, Copy, Decode, + DecodeWithMemTracking, Default, Encode, Eq, @@ -85,7 +86,7 @@ pub type ParaHash = crate::Hash; pub type ParaHasher = crate::Hasher; /// Raw storage proof of parachain heads, stored in polkadot-like chain runtime. -#[derive(Clone, Decode, Encode, Eq, PartialEq, RuntimeDebug, TypeInfo)] +#[derive(Clone, Decode, DecodeWithMemTracking, Encode, Eq, PartialEq, RuntimeDebug, TypeInfo)] pub struct ParaHeadsProof { /// Unverified storage proof of finalized parachain heads. pub storage_proof: RawStorageProof, diff --git a/bridges/primitives/relayers/src/lib.rs b/bridges/primitives/relayers/src/lib.rs index faa4cb1776294..3255e2ec3fcaa 100644 --- a/bridges/primitives/relayers/src/lib.rs +++ b/bridges/primitives/relayers/src/lib.rs @@ -29,7 +29,7 @@ use bp_runtime::{ChainId, StorageDoubleMapKeyProvider}; use frame_support::{traits::tokens::Preservation, Blake2_128Concat, Identity}; use scale_info::TypeInfo; use sp_runtime::{ - codec::{Codec, Decode, Encode, EncodeLike, MaxEncodedLen}, + codec::{Codec, Decode, DecodeWithMemTracking, Encode, EncodeLike, MaxEncodedLen}, traits::AccountIdConversion, TypeId, }; @@ -42,7 +42,18 @@ mod registration; /// /// Each of the 2 final points connected by a bridge owns a sovereign account at each end of the /// bridge. So here, at this end of the bridge there can be 2 sovereign accounts that pay rewards. -#[derive(Copy, Clone, Debug, Decode, Encode, Eq, PartialEq, TypeInfo, MaxEncodedLen)] +#[derive( + Copy, + Clone, + Debug, + Decode, + DecodeWithMemTracking, + Encode, + Eq, + PartialEq, + TypeInfo, + MaxEncodedLen, +)] pub enum RewardsAccountOwner { /// The sovereign account of the final chain on this end of the bridge. ThisChain, @@ -59,7 +70,18 @@ pub enum RewardsAccountOwner { /// destinations of a bridge lane must have a sovereign account at each end of the bridge and each /// of the sovereign accounts will pay rewards for different operations. So we need multiple /// parameters to identify the account that pays a reward to the relayer. -#[derive(Copy, Clone, Debug, Decode, Encode, Eq, PartialEq, TypeInfo, MaxEncodedLen)] +#[derive( + Copy, + Clone, + Debug, + Decode, + DecodeWithMemTracking, + Encode, + Eq, + PartialEq, + TypeInfo, + MaxEncodedLen, +)] pub struct RewardsAccountParams { // **IMPORTANT NOTE**: the order of fields here matters - we are using // `into_account_truncating` and lane id is already `32` byte, so if other fields are encoded diff --git a/bridges/primitives/relayers/src/registration.rs b/bridges/primitives/relayers/src/registration.rs index d74ef18cf706b..ac0f5063f349a 100644 --- a/bridges/primitives/relayers/src/registration.rs +++ b/bridges/primitives/relayers/src/registration.rs @@ -39,7 +39,7 @@ use crate::RewardsAccountParams; -use codec::{Decode, Encode, MaxEncodedLen}; +use codec::{Decode, DecodeWithMemTracking, Encode, MaxEncodedLen}; use scale_info::TypeInfo; use sp_runtime::{ traits::{Get, Zero}, @@ -64,7 +64,18 @@ impl From> } /// Relayer registration. -#[derive(Copy, Clone, Debug, Decode, Encode, Eq, PartialEq, TypeInfo, MaxEncodedLen)] +#[derive( + Copy, + Clone, + Debug, + Decode, + DecodeWithMemTracking, + Encode, + Eq, + PartialEq, + TypeInfo, + MaxEncodedLen, +)] pub struct Registration { /// The last block number, where this registration is considered active. /// diff --git a/bridges/primitives/runtime/src/lib.rs b/bridges/primitives/runtime/src/lib.rs index 90eb72922beaa..85525f0eb1bd9 100644 --- a/bridges/primitives/runtime/src/lib.rs +++ b/bridges/primitives/runtime/src/lib.rs @@ -19,7 +19,7 @@ #![warn(missing_docs)] #![cfg_attr(not(feature = "std"), no_std)] -use codec::{Decode, Encode, FullCodec, MaxEncodedLen}; +use codec::{Decode, DecodeWithMemTracking, Encode, FullCodec, MaxEncodedLen}; use frame_support::{ pallet_prelude::DispatchResult, weights::Weight, PalletError, StorageHasher, StorageValue, }; @@ -316,7 +316,7 @@ pub trait StorageDoubleMapKeyProvider { } /// Error generated by the `OwnedBridgeModule` trait. -#[derive(Encode, Decode, PartialEq, Eq, TypeInfo, PalletError)] +#[derive(Encode, Decode, DecodeWithMemTracking, PartialEq, Eq, TypeInfo, PalletError)] pub enum OwnedBridgeModuleError { /// All pallet operations are halted. Halted, @@ -332,6 +332,7 @@ pub trait OperatingMode: Send + Copy + Debug + FullCodec { #[derive( Encode, Decode, + DecodeWithMemTracking, Clone, Copy, PartialEq, diff --git a/bridges/primitives/runtime/src/messages.rs b/bridges/primitives/runtime/src/messages.rs index 0f219e984f728..4163fdc6fc151 100644 --- a/bridges/primitives/runtime/src/messages.rs +++ b/bridges/primitives/runtime/src/messages.rs @@ -16,13 +16,13 @@ //! Primitives that may be used by different message delivery and dispatch mechanisms. -use codec::{Decode, Encode}; +use codec::{Decode, DecodeWithMemTracking, Encode}; use frame_support::weights::Weight; use scale_info::TypeInfo; use sp_runtime::RuntimeDebug; /// Message dispatch result. -#[derive(Encode, Decode, RuntimeDebug, Clone, PartialEq, Eq, TypeInfo)] +#[derive(Encode, Decode, DecodeWithMemTracking, RuntimeDebug, Clone, PartialEq, Eq, TypeInfo)] pub struct MessageDispatchResult { /// Unspent dispatch weight. This weight that will be deducted from total delivery transaction /// weight, thus reducing the transaction cost. This shall not be zero in (at least) two cases: diff --git a/bridges/primitives/runtime/src/storage_proof.rs b/bridges/primitives/runtime/src/storage_proof.rs index 8bd9001f2b6c1..113e101e3703a 100644 --- a/bridges/primitives/runtime/src/storage_proof.rs +++ b/bridges/primitives/runtime/src/storage_proof.rs @@ -23,7 +23,7 @@ use sp_trie::{ accessed_nodes_tracker::AccessedNodesTracker, read_trie_value, LayoutV1, MemoryDB, StorageProof, }; -use codec::{Decode, Encode}; +use codec::{Decode, DecodeWithMemTracking, Encode}; use hash_db::{HashDB, Hasher, EMPTY_PREFIX}; use scale_info::TypeInfo; #[cfg(feature = "test-helpers")] @@ -32,7 +32,9 @@ use sp_trie::{recorder_ext::RecorderExt, Recorder, TrieDBBuilder, TrieError, Tri use trie_db::{Trie, TrieConfiguration, TrieDBMut}; /// Errors that can occur when interacting with `UnverifiedStorageProof` and `VerifiedStorageProof`. -#[derive(Clone, Encode, Decode, RuntimeDebug, PartialEq, Eq, PalletError, TypeInfo)] +#[derive( + Clone, Encode, Decode, DecodeWithMemTracking, RuntimeDebug, PartialEq, Eq, PalletError, TypeInfo, +)] pub enum StorageProofError { /// Call to `generate_trie_proof()` failed. UnableToGenerateTrieProof, diff --git a/bridges/primitives/xcm-bridge-hub/src/lib.rs b/bridges/primitives/xcm-bridge-hub/src/lib.rs index 471cf402c34fb..89bb888ab3faa 100644 --- a/bridges/primitives/xcm-bridge-hub/src/lib.rs +++ b/bridges/primitives/xcm-bridge-hub/src/lib.rs @@ -22,7 +22,7 @@ use bp_messages::LaneIdType; use bp_runtime::{AccountIdOf, BalanceOf, Chain}; pub use call_info::XcmBridgeHubCall; -use codec::{Decode, Encode, MaxEncodedLen}; +use codec::{Decode, DecodeWithMemTracking, Encode, MaxEncodedLen}; use frame_support::{ ensure, sp_runtime::RuntimeDebug, CloneNoBound, PalletError, PartialEqNoBound, RuntimeDebugNoBound, @@ -59,6 +59,7 @@ pub type XcmAsPlainPayload = sp_std::vec::Vec; Copy, Decode, Encode, + DecodeWithMemTracking, Eq, Ord, PartialOrd, @@ -197,7 +198,9 @@ pub struct BridgeLocations { } /// Errors that may happen when we check bridge locations. -#[derive(Encode, Decode, RuntimeDebug, PartialEq, Eq, PalletError, TypeInfo)] +#[derive( + Encode, Decode, DecodeWithMemTracking, RuntimeDebug, PartialEq, Eq, PalletError, TypeInfo, +)] pub enum BridgeLocationsError { /// Origin or destination locations are not universal. NonUniversalLocation, diff --git a/bridges/snowbridge/pallets/inbound-queue/src/lib.rs b/bridges/snowbridge/pallets/inbound-queue/src/lib.rs index 423b92b9fae04..85b98c643b6c8 100644 --- a/bridges/snowbridge/pallets/inbound-queue/src/lib.rs +++ b/bridges/snowbridge/pallets/inbound-queue/src/lib.rs @@ -188,7 +188,9 @@ pub mod pallet { ConvertMessage(ConvertMessageError), } - #[derive(Clone, Encode, Decode, Eq, PartialEq, Debug, TypeInfo, PalletError)] + #[derive( + Clone, Encode, Decode, DecodeWithMemTracking, Eq, PartialEq, Debug, TypeInfo, PalletError, + )] pub enum SendError { NotApplicable, NotRoutable, diff --git a/bridges/snowbridge/primitives/beacon/src/bls.rs b/bridges/snowbridge/primitives/beacon/src/bls.rs index 589b72e67348f..5834b9986564c 100644 --- a/bridges/snowbridge/primitives/beacon/src/bls.rs +++ b/bridges/snowbridge/primitives/beacon/src/bls.rs @@ -1,7 +1,7 @@ // SPDX-License-Identifier: Apache-2.0 // SPDX-FileCopyrightText: 2023 Snowfork use crate::{PublicKey, Signature}; -use codec::{Decode, Encode}; +use codec::{Decode, DecodeWithMemTracking, Encode}; use frame_support::{ensure, PalletError}; pub use milagro_bls::{ AggregatePublicKey, AggregateSignature, PublicKey as PublicKeyPrepared, @@ -12,7 +12,18 @@ use sp_core::H256; use sp_runtime::RuntimeDebug; use sp_std::prelude::*; -#[derive(Copy, Clone, Encode, Decode, Eq, PartialEq, TypeInfo, RuntimeDebug, PalletError)] +#[derive( + Copy, + Clone, + Encode, + Decode, + DecodeWithMemTracking, + Eq, + PartialEq, + TypeInfo, + RuntimeDebug, + PalletError, +)] pub enum BlsError { InvalidSignature, InvalidPublicKey, diff --git a/bridges/snowbridge/primitives/beacon/src/types.rs b/bridges/snowbridge/primitives/beacon/src/types.rs index e12350510c9b8..44fa7c4450ae9 100644 --- a/bridges/snowbridge/primitives/beacon/src/types.rs +++ b/bridges/snowbridge/primitives/beacon/src/types.rs @@ -1,6 +1,6 @@ // SPDX-License-Identifier: Apache-2.0 // SPDX-FileCopyrightText: 2023 Snowfork -use codec::{Decode, Encode, MaxEncodedLen}; +use codec::{Decode, DecodeWithMemTracking, Encode, MaxEncodedLen}; use frame_support::{CloneNoBound, PartialEqNoBound, RuntimeDebugNoBound}; use scale_info::TypeInfo; use sp_core::{H160, H256, U256}; @@ -44,7 +44,7 @@ pub struct Fork { pub epoch: u64, } -#[derive(Copy, Clone, Encode, Decode, PartialEq, RuntimeDebug, TypeInfo)] +#[derive(Copy, Clone, Encode, Decode, DecodeWithMemTracking, PartialEq, RuntimeDebug, TypeInfo)] pub struct PublicKey(pub [u8; PUBKEY_SIZE]); impl Default for PublicKey { @@ -85,7 +85,7 @@ impl Serialize for PublicKey { } } -#[derive(Copy, Clone, Encode, Decode, PartialEq, RuntimeDebug, TypeInfo)] +#[derive(Copy, Clone, Encode, Decode, DecodeWithMemTracking, PartialEq, RuntimeDebug, TypeInfo)] pub struct Signature(pub [u8; SIGNATURE_SIZE]); impl Default for Signature { @@ -143,7 +143,14 @@ impl SigningData { /// Sync committee as it is stored in the runtime storage. #[derive( - Encode, Decode, PartialEqNoBound, CloneNoBound, RuntimeDebugNoBound, TypeInfo, MaxEncodedLen, + Encode, + Decode, + DecodeWithMemTracking, + PartialEqNoBound, + CloneNoBound, + RuntimeDebugNoBound, + TypeInfo, + MaxEncodedLen, )] #[cfg_attr( feature = "std", @@ -215,7 +222,16 @@ impl TryFrom<&SyncCommittee> /// Beacon block header as it is stored in the runtime storage. The block root is the /// Merkleization of a BeaconHeader. #[derive( - Copy, Clone, Default, Encode, Decode, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen, + Copy, + Clone, + Default, + Encode, + Decode, + DecodeWithMemTracking, + PartialEq, + RuntimeDebug, + TypeInfo, + MaxEncodedLen, )] #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] pub struct BeaconHeader { @@ -238,7 +254,15 @@ impl BeaconHeader { } } -#[derive(Encode, Decode, CloneNoBound, PartialEqNoBound, RuntimeDebugNoBound, TypeInfo)] +#[derive( + Encode, + Decode, + DecodeWithMemTracking, + CloneNoBound, + PartialEqNoBound, + RuntimeDebugNoBound, + TypeInfo, +)] #[cfg_attr( feature = "std", derive(Deserialize), @@ -303,7 +327,14 @@ impl /// ExecutionPayloadHeader /// #[derive( - Default, Encode, Decode, CloneNoBound, PartialEqNoBound, RuntimeDebugNoBound, TypeInfo, + Default, + Encode, + Decode, + DecodeWithMemTracking, + CloneNoBound, + PartialEqNoBound, + RuntimeDebugNoBound, + TypeInfo, )] #[cfg_attr( feature = "std", @@ -356,7 +387,15 @@ pub struct CompactBeaconState { } /// VersionedExecutionPayloadHeader -#[derive(Encode, Decode, CloneNoBound, PartialEqNoBound, RuntimeDebugNoBound, TypeInfo)] +#[derive( + Encode, + Decode, + DecodeWithMemTracking, + CloneNoBound, + PartialEqNoBound, + RuntimeDebugNoBound, + TypeInfo, +)] #[cfg_attr( feature = "std", derive(Serialize, Deserialize), @@ -410,7 +449,15 @@ impl VersionedExecutionPayloadHeader { } } -#[derive(Encode, Decode, CloneNoBound, PartialEqNoBound, RuntimeDebugNoBound, TypeInfo)] +#[derive( + Encode, + Decode, + DecodeWithMemTracking, + CloneNoBound, + PartialEqNoBound, + RuntimeDebugNoBound, + TypeInfo, +)] #[cfg_attr( feature = "std", derive(serde::Deserialize), @@ -427,7 +474,15 @@ pub struct ExecutionProof { pub execution_branch: Vec, } -#[derive(Encode, Decode, CloneNoBound, PartialEqNoBound, RuntimeDebugNoBound, TypeInfo)] +#[derive( + Encode, + Decode, + DecodeWithMemTracking, + CloneNoBound, + PartialEqNoBound, + RuntimeDebugNoBound, + TypeInfo, +)] #[cfg_attr( feature = "std", derive(serde::Deserialize), @@ -566,7 +621,7 @@ pub enum Mode { } pub mod deneb { - use codec::{Decode, Encode}; + use codec::{Decode, DecodeWithMemTracking, Encode}; use frame_support::{CloneNoBound, PartialEqNoBound, RuntimeDebugNoBound}; use scale_info::TypeInfo; #[cfg(feature = "std")] @@ -577,7 +632,14 @@ pub mod deneb { /// ExecutionPayloadHeader /// #[derive( - Default, Encode, Decode, CloneNoBound, PartialEqNoBound, RuntimeDebugNoBound, TypeInfo, + Default, + Encode, + Decode, + DecodeWithMemTracking, + CloneNoBound, + PartialEqNoBound, + RuntimeDebugNoBound, + TypeInfo, )] #[cfg_attr( feature = "std", diff --git a/bridges/snowbridge/primitives/beacon/src/updates.rs b/bridges/snowbridge/primitives/beacon/src/updates.rs index ca651b5806f27..bcd371b6c77a0 100644 --- a/bridges/snowbridge/primitives/beacon/src/updates.rs +++ b/bridges/snowbridge/primitives/beacon/src/updates.rs @@ -1,6 +1,6 @@ // SPDX-License-Identifier: Apache-2.0 // SPDX-FileCopyrightText: 2023 Snowfork -use codec::{Decode, Encode}; +use codec::{Decode, DecodeWithMemTracking, Encode}; use frame_support::{CloneNoBound, PartialEqNoBound, RuntimeDebugNoBound}; use scale_info::TypeInfo; use sp_core::H256; @@ -8,7 +8,15 @@ use sp_std::prelude::*; use crate::types::{BeaconHeader, SyncAggregate, SyncCommittee}; -#[derive(Encode, Decode, CloneNoBound, PartialEqNoBound, RuntimeDebugNoBound, TypeInfo)] +#[derive( + Encode, + Decode, + DecodeWithMemTracking, + CloneNoBound, + PartialEqNoBound, + RuntimeDebugNoBound, + TypeInfo, +)] #[cfg_attr( feature = "std", derive(serde::Serialize, serde::Deserialize), @@ -24,7 +32,14 @@ pub struct CheckpointUpdate { } #[derive( - Default, Encode, Decode, CloneNoBound, PartialEqNoBound, RuntimeDebugNoBound, TypeInfo, + Default, + Encode, + Decode, + DecodeWithMemTracking, + CloneNoBound, + PartialEqNoBound, + RuntimeDebugNoBound, + TypeInfo, )] #[cfg_attr( feature = "std", @@ -54,7 +69,14 @@ pub struct Update } #[derive( - Default, Encode, Decode, CloneNoBound, PartialEqNoBound, RuntimeDebugNoBound, TypeInfo, + Default, + Encode, + Decode, + DecodeWithMemTracking, + CloneNoBound, + PartialEqNoBound, + RuntimeDebugNoBound, + TypeInfo, )] #[cfg_attr( feature = "std", diff --git a/bridges/snowbridge/primitives/core/src/inbound.rs b/bridges/snowbridge/primitives/core/src/inbound.rs index 9e8ed789ab500..5e5ae673359b5 100644 --- a/bridges/snowbridge/primitives/core/src/inbound.rs +++ b/bridges/snowbridge/primitives/core/src/inbound.rs @@ -2,7 +2,7 @@ // SPDX-FileCopyrightText: 2023 Snowfork //! Types for representing inbound messages -use codec::{Decode, Encode}; +use codec::{Decode, DecodeWithMemTracking, Encode}; use frame_support::PalletError; use scale_info::TypeInfo; use snowbridge_beacon_primitives::{BeaconHeader, ExecutionProof}; @@ -15,7 +15,7 @@ pub trait Verifier { fn verify(event: &Log, proof: &Proof) -> Result<(), VerificationError>; } -#[derive(Clone, Encode, Decode, RuntimeDebug, PalletError, TypeInfo)] +#[derive(Clone, Encode, Decode, DecodeWithMemTracking, RuntimeDebug, PalletError, TypeInfo)] #[cfg_attr(feature = "std", derive(PartialEq))] pub enum VerificationError { /// Execution header is missing @@ -33,7 +33,7 @@ pub enum VerificationError { pub type MessageNonce = u64; /// A bridge message from the Gateway contract on Ethereum -#[derive(Clone, Encode, Decode, PartialEq, RuntimeDebug, TypeInfo)] +#[derive(Clone, Encode, Decode, DecodeWithMemTracking, PartialEq, RuntimeDebug, TypeInfo)] pub struct Message { /// Event log emitted by Gateway contract pub event_log: Log, @@ -49,7 +49,7 @@ pub enum LogValidationError { } /// Event log -#[derive(Clone, Encode, Decode, PartialEq, RuntimeDebug, TypeInfo)] +#[derive(Clone, Encode, Decode, DecodeWithMemTracking, PartialEq, RuntimeDebug, TypeInfo)] pub struct Log { pub address: H160, pub topics: Vec, @@ -66,7 +66,7 @@ impl Log { } /// Inclusion proof for a transaction receipt -#[derive(Clone, Encode, Decode, PartialEq, RuntimeDebug, TypeInfo)] +#[derive(Clone, Encode, Decode, DecodeWithMemTracking, PartialEq, RuntimeDebug, TypeInfo)] pub struct Proof { // Proof keys and values (receipts tree) pub receipt_proof: (Vec>, Vec>), diff --git a/bridges/snowbridge/primitives/core/src/lib.rs b/bridges/snowbridge/primitives/core/src/lib.rs index 7ad129a52542e..9d18932c8faab 100644 --- a/bridges/snowbridge/primitives/core/src/lib.rs +++ b/bridges/snowbridge/primitives/core/src/lib.rs @@ -22,7 +22,7 @@ pub use polkadot_parachain_primitives::primitives::{ pub use ringbuffer::{RingBufferMap, RingBufferMapImpl}; pub use sp_core::U256; -use codec::{Decode, Encode, MaxEncodedLen}; +use codec::{Decode, DecodeWithMemTracking, Encode, MaxEncodedLen}; use frame_support::{traits::Contains, BoundedVec}; use hex_literal::hex; use scale_info::TypeInfo; @@ -67,7 +67,17 @@ pub const ROC: u128 = 1_000_000_000_000; /// Identifier for a message channel #[derive( - Clone, Copy, Encode, Decode, PartialEq, Eq, Default, RuntimeDebug, MaxEncodedLen, TypeInfo, + Clone, + Copy, + Encode, + Decode, + DecodeWithMemTracking, + PartialEq, + Eq, + Default, + RuntimeDebug, + MaxEncodedLen, + TypeInfo, )] pub struct ChannelId([u8; 32]); @@ -152,7 +162,7 @@ pub const SECONDARY_GOVERNANCE_CHANNEL: ChannelId = ChannelId::new(hex!("0000000000000000000000000000000000000000000000000000000000000002")); /// Metadata to include in the instantiated ERC20 token contract -#[derive(Clone, Encode, Decode, PartialEq, RuntimeDebug, TypeInfo)] +#[derive(Clone, Encode, Decode, DecodeWithMemTracking, PartialEq, RuntimeDebug, TypeInfo)] pub struct AssetMetadata { pub name: BoundedVec>, pub symbol: BoundedVec>, diff --git a/bridges/snowbridge/primitives/core/src/operating_mode.rs b/bridges/snowbridge/primitives/core/src/operating_mode.rs index 9894e587ef5e7..e450a78d9fd07 100644 --- a/bridges/snowbridge/primitives/core/src/operating_mode.rs +++ b/bridges/snowbridge/primitives/core/src/operating_mode.rs @@ -1,9 +1,20 @@ -use codec::{Decode, Encode, MaxEncodedLen}; +use codec::{Decode, DecodeWithMemTracking, Encode, MaxEncodedLen}; use scale_info::TypeInfo; use sp_runtime::RuntimeDebug; /// Basic operating modes for a bridges module (Normal/Halted). -#[derive(Encode, Decode, Clone, Copy, PartialEq, Eq, RuntimeDebug, TypeInfo, MaxEncodedLen)] +#[derive( + Encode, + Decode, + DecodeWithMemTracking, + Clone, + Copy, + PartialEq, + Eq, + RuntimeDebug, + TypeInfo, + MaxEncodedLen, +)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum BasicOperatingMode { /// Normal mode, when all operations are allowed. diff --git a/bridges/snowbridge/primitives/core/src/outbound.rs b/bridges/snowbridge/primitives/core/src/outbound.rs index 77770761822a8..4119dbd7f9251 100644 --- a/bridges/snowbridge/primitives/core/src/outbound.rs +++ b/bridges/snowbridge/primitives/core/src/outbound.rs @@ -1,4 +1,4 @@ -use codec::{Decode, Encode}; +use codec::{Decode, DecodeWithMemTracking, Encode}; use frame_support::PalletError; use scale_info::TypeInfo; use sp_arithmetic::traits::{BaseArithmetic, Unsigned}; @@ -31,7 +31,7 @@ impl> From for VersionedQueuedMessage { mod v1 { use crate::{pricing::UD60x18, ChannelId}; - use codec::{Decode, Encode}; + use codec::{Decode, DecodeWithMemTracking, Encode}; use ethabi::Token; use scale_info::TypeInfo; use sp_core::{RuntimeDebug, H160, H256, U256}; @@ -55,7 +55,9 @@ mod v1 { } /// The operating mode of Channels and Gateway contract on Ethereum. - #[derive(Copy, Clone, Encode, Decode, PartialEq, Eq, RuntimeDebug, TypeInfo)] + #[derive( + Copy, Clone, Encode, Decode, DecodeWithMemTracking, PartialEq, Eq, RuntimeDebug, TypeInfo, + )] pub enum OperatingMode { /// Normal operations. Allow sending and receiving messages. Normal, @@ -271,7 +273,7 @@ mod v1 { /// Representation of a call to the initializer of an implementation contract. /// The initializer has the following ABI signature: `initialize(bytes)`. - #[derive(Clone, Encode, Decode, PartialEq, RuntimeDebug, TypeInfo)] + #[derive(Clone, Encode, Decode, DecodeWithMemTracking, PartialEq, RuntimeDebug, TypeInfo)] pub struct Initializer { /// ABI-encoded params of type `bytes` to pass to the initializer pub params: Vec, @@ -389,7 +391,18 @@ pub trait SendMessageFeeProvider { } /// Reasons why sending to Ethereum could not be initiated -#[derive(Copy, Clone, Encode, Decode, PartialEq, Eq, RuntimeDebug, PalletError, TypeInfo)] +#[derive( + Copy, + Clone, + Encode, + Decode, + DecodeWithMemTracking, + PartialEq, + Eq, + RuntimeDebug, + PalletError, + TypeInfo, +)] pub enum SendError { /// Message is too large to be safely executed on Ethereum MessageTooLarge, diff --git a/bridges/snowbridge/primitives/core/src/pricing.rs b/bridges/snowbridge/primitives/core/src/pricing.rs index 0f392c7ad4bdd..460c59e1f2cdf 100644 --- a/bridges/snowbridge/primitives/core/src/pricing.rs +++ b/bridges/snowbridge/primitives/core/src/pricing.rs @@ -1,11 +1,13 @@ -use codec::{Decode, Encode, MaxEncodedLen}; +use codec::{Decode, DecodeWithMemTracking, Encode, MaxEncodedLen}; use scale_info::TypeInfo; use sp_arithmetic::traits::{BaseArithmetic, Unsigned, Zero}; use sp_core::U256; use sp_runtime::{FixedU128, RuntimeDebug}; use sp_std::prelude::*; -#[derive(Clone, Encode, Decode, PartialEq, RuntimeDebug, MaxEncodedLen, TypeInfo)] +#[derive( + Clone, Encode, Decode, DecodeWithMemTracking, PartialEq, RuntimeDebug, MaxEncodedLen, TypeInfo, +)] pub struct PricingParameters { /// ETH/DOT exchange rate pub exchange_rate: FixedU128, @@ -17,7 +19,9 @@ pub struct PricingParameters { pub multiplier: FixedU128, } -#[derive(Clone, Encode, Decode, PartialEq, RuntimeDebug, MaxEncodedLen, TypeInfo)] +#[derive( + Clone, Encode, Decode, DecodeWithMemTracking, PartialEq, RuntimeDebug, MaxEncodedLen, TypeInfo, +)] pub struct Rewards { /// Local reward in DOT pub local: Balance, diff --git a/bridges/snowbridge/primitives/router/src/inbound/mod.rs b/bridges/snowbridge/primitives/router/src/inbound/mod.rs index 1c210afb1f740..f2d5b02e8bbdf 100644 --- a/bridges/snowbridge/primitives/router/src/inbound/mod.rs +++ b/bridges/snowbridge/primitives/router/src/inbound/mod.rs @@ -7,7 +7,7 @@ mod mock; #[cfg(test)] mod tests; -use codec::{Decode, Encode}; +use codec::{Decode, DecodeWithMemTracking, Encode}; use core::marker::PhantomData; use frame_support::{traits::tokens::Balance as BalanceT, PalletError}; use scale_info::TypeInfo; @@ -127,7 +127,9 @@ pub struct MessageToXcm< } /// Reason why a message conversion failed. -#[derive(Copy, Clone, TypeInfo, PalletError, Encode, Decode, RuntimeDebug)] +#[derive( + Copy, Clone, TypeInfo, PalletError, Encode, Decode, DecodeWithMemTracking, RuntimeDebug, +)] pub enum ConvertMessageError { /// The message version is not supported for conversion. UnsupportedVersion, diff --git a/polkadot/xcm/pallet-xcm/src/lib.rs b/polkadot/xcm/pallet-xcm/src/lib.rs index 6360298b21c36..a422756ed570a 100644 --- a/polkadot/xcm/pallet-xcm/src/lib.rs +++ b/polkadot/xcm/pallet-xcm/src/lib.rs @@ -508,7 +508,17 @@ pub mod pallet { } #[pallet::origin] - #[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo, MaxEncodedLen)] + #[derive( + PartialEq, + Eq, + Clone, + Encode, + Decode, + DecodeWithMemTracking, + RuntimeDebug, + TypeInfo, + MaxEncodedLen, + )] pub enum Origin { /// It comes from somewhere in the XCM space wanting to transact. Xcm(Location), diff --git a/polkadot/xcm/src/double_encoded.rs b/polkadot/xcm/src/double_encoded.rs index a5eecdee97963..5efb637b9075b 100644 --- a/polkadot/xcm/src/double_encoded.rs +++ b/polkadot/xcm/src/double_encoded.rs @@ -16,11 +16,11 @@ use crate::MAX_XCM_DECODE_DEPTH; use alloc::vec::Vec; -use codec::{Decode, DecodeLimit, Encode}; +use codec::{Decode, DecodeLimit, DecodeWithMemTracking, Encode}; /// Wrapper around the encoded and decoded versions of a value. /// Caches the decoded value once computed. -#[derive(Encode, Decode, scale_info::TypeInfo)] +#[derive(Encode, Decode, DecodeWithMemTracking, scale_info::TypeInfo)] #[codec(encode_bound())] #[codec(decode_bound())] #[scale_info(bounds(), skip_type_params(T))] diff --git a/polkadot/xcm/src/lib.rs b/polkadot/xcm/src/lib.rs index 2271835a9a5e8..9d3dc56c7d3cf 100644 --- a/polkadot/xcm/src/lib.rs +++ b/polkadot/xcm/src/lib.rs @@ -24,7 +24,9 @@ extern crate alloc; -use codec::{Decode, DecodeLimit, Encode, Error as CodecError, Input, MaxEncodedLen}; +use codec::{ + Decode, DecodeLimit, DecodeWithMemTracking, Encode, Error as CodecError, Input, MaxEncodedLen, +}; use derive_where::derive_where; use frame_support::dispatch::GetDispatchInfo; use scale_info::TypeInfo; @@ -88,7 +90,7 @@ macro_rules! versioned_type { $(#[$index5:meta])+ V5($v5:ty), }) => { - #[derive(Clone, Eq, PartialEq, Debug, Encode, Decode, TypeInfo)] + #[derive(Clone, Eq, PartialEq, Debug, Encode, Decode, DecodeWithMemTracking, TypeInfo)] #[codec(encode_bound())] #[codec(decode_bound())] #[scale_info(replace_segment("staging_xcm", "xcm"))] @@ -305,7 +307,7 @@ versioned_type! { } /// A single XCM message, together with its version code. -#[derive(Encode, Decode, TypeInfo)] +#[derive(Encode, Decode, DecodeWithMemTracking, TypeInfo)] #[derive_where(Clone, Eq, PartialEq, Debug)] #[codec(encode_bound())] #[codec(decode_bound())] diff --git a/polkadot/xcm/src/v3/junction.rs b/polkadot/xcm/src/v3/junction.rs index 24e9c16bf699a..c3b0378c871e9 100644 --- a/polkadot/xcm/src/v3/junction.rs +++ b/polkadot/xcm/src/v3/junction.rs @@ -22,7 +22,7 @@ use crate::{ VersionedLocation, }; use bounded_collections::{BoundedSlice, BoundedVec, ConstU32}; -use codec::{self, Decode, Encode, MaxEncodedLen}; +use codec::{self, Decode, DecodeWithMemTracking, Encode, MaxEncodedLen}; use scale_info::TypeInfo; use serde::{Deserialize, Serialize}; @@ -39,6 +39,7 @@ use serde::{Deserialize, Serialize}; PartialOrd, Encode, Decode, + DecodeWithMemTracking, Debug, TypeInfo, MaxEncodedLen, @@ -111,6 +112,7 @@ impl From for NetworkId { PartialOrd, Encode, Decode, + DecodeWithMemTracking, Debug, TypeInfo, MaxEncodedLen, @@ -157,6 +159,7 @@ pub enum BodyId { PartialOrd, Encode, Decode, + DecodeWithMemTracking, Debug, TypeInfo, MaxEncodedLen, @@ -220,6 +223,7 @@ impl BodyPart { PartialOrd, Encode, Decode, + DecodeWithMemTracking, Debug, TypeInfo, MaxEncodedLen, diff --git a/polkadot/xcm/src/v3/junctions.rs b/polkadot/xcm/src/v3/junctions.rs index 56f5326fe97c6..3cc1b78553a61 100644 --- a/polkadot/xcm/src/v3/junctions.rs +++ b/polkadot/xcm/src/v3/junctions.rs @@ -17,7 +17,7 @@ //! XCM `Junctions`/`InteriorMultiLocation` datatype. use super::{Junction, MultiLocation, NetworkId}; -use codec::{Decode, Encode, MaxEncodedLen}; +use codec::{Decode, DecodeWithMemTracking, Encode, MaxEncodedLen}; use core::{mem, result}; use scale_info::TypeInfo; @@ -38,6 +38,7 @@ pub(crate) const MAX_JUNCTIONS: usize = 8; PartialOrd, Encode, Decode, + DecodeWithMemTracking, Debug, TypeInfo, MaxEncodedLen, diff --git a/polkadot/xcm/src/v3/mod.rs b/polkadot/xcm/src/v3/mod.rs index 6ae987a9830f1..7d48ae26f60ea 100644 --- a/polkadot/xcm/src/v3/mod.rs +++ b/polkadot/xcm/src/v3/mod.rs @@ -24,8 +24,8 @@ use crate::DoubleEncoded; use alloc::{vec, vec::Vec}; use bounded_collections::{parameter_types, BoundedVec}; use codec::{ - self, decode_vec_with_len, Compact, Decode, Encode, Error as CodecError, Input as CodecInput, - MaxEncodedLen, + self, decode_vec_with_len, Compact, Decode, DecodeWithMemTracking, Encode, Error as CodecError, + Input as CodecInput, MaxEncodedLen, }; use core::{fmt::Debug, result}; use derive_where::derive_where; @@ -57,7 +57,7 @@ pub const VERSION: super::Version = 3; /// An identifier for a query. pub type QueryId = u64; -#[derive(Default, Encode, TypeInfo)] +#[derive(Default, DecodeWithMemTracking, Encode, TypeInfo)] #[derive_where(Clone, Eq, PartialEq, Debug)] #[codec(encode_bound())] #[scale_info(bounds(), skip_type_params(Call))] @@ -236,7 +236,9 @@ parameter_types! { pub MaxPalletsInfo: u32 = 64; } -#[derive(Clone, Eq, PartialEq, Encode, Decode, Debug, TypeInfo, MaxEncodedLen)] +#[derive( + Clone, Eq, PartialEq, Encode, Decode, DecodeWithMemTracking, Debug, TypeInfo, MaxEncodedLen, +)] #[scale_info(replace_segment("staging_xcm", "xcm"))] #[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))] pub struct PalletInfo { @@ -284,7 +286,9 @@ impl TryInto for PalletInfo { } } -#[derive(Clone, Eq, PartialEq, Encode, Decode, Debug, TypeInfo, MaxEncodedLen)] +#[derive( + Clone, Eq, PartialEq, Encode, Decode, DecodeWithMemTracking, Debug, TypeInfo, MaxEncodedLen, +)] #[scale_info(replace_segment("staging_xcm", "xcm"))] #[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))] pub enum MaybeErrorCode { @@ -309,7 +313,9 @@ impl Default for MaybeErrorCode { } /// Response data to a query. -#[derive(Clone, Eq, PartialEq, Encode, Decode, Debug, TypeInfo, MaxEncodedLen)] +#[derive( + Clone, Eq, PartialEq, Encode, Decode, DecodeWithMemTracking, Debug, TypeInfo, MaxEncodedLen, +)] #[scale_info(replace_segment("staging_xcm", "xcm"))] #[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))] pub enum Response { @@ -360,7 +366,7 @@ impl TryFrom for Response { } /// Information regarding the composition of a query response. -#[derive(Clone, Eq, PartialEq, Encode, Decode, Debug, TypeInfo)] +#[derive(Clone, Eq, PartialEq, Encode, Decode, DecodeWithMemTracking, Debug, TypeInfo)] #[scale_info(replace_segment("staging_xcm", "xcm"))] #[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))] pub struct QueryResponseInfo { @@ -386,7 +392,7 @@ impl TryFrom for QueryResponseInfo { } /// An optional weight limit. -#[derive(Clone, Eq, PartialEq, Encode, Decode, Debug, TypeInfo)] +#[derive(Clone, Eq, PartialEq, Encode, Decode, DecodeWithMemTracking, Debug, TypeInfo)] #[scale_info(replace_segment("staging_xcm", "xcm"))] #[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))] pub enum WeightLimit { @@ -415,7 +421,7 @@ impl From for Option { } /// Basically just the XCM (more general) version of `ParachainDispatchOrigin`. -#[derive(Copy, Clone, Eq, PartialEq, Encode, Decode, Debug, TypeInfo)] +#[derive(Copy, Clone, Eq, PartialEq, Encode, Decode, DecodeWithMemTracking, Debug, TypeInfo)] #[scale_info(replace_segment("staging_xcm", "xcm"))] #[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))] pub enum OriginKind { @@ -474,10 +480,18 @@ impl XcmContext { /// /// This is the inner XCM format and is version-sensitive. Messages are typically passed using the /// outer XCM format, known as `VersionedXcm`. -#[derive(Encode, Decode, TypeInfo, xcm_procedural::XcmWeightInfoTrait, xcm_procedural::Builder)] +#[derive( + Encode, + Decode, + DecodeWithMemTracking, + TypeInfo, + xcm_procedural::XcmWeightInfoTrait, + xcm_procedural::Builder, +)] #[derive_where(Clone, Eq, PartialEq, Debug)] #[codec(encode_bound())] #[codec(decode_bound())] +#[codec(decode_with_mem_tracking_bound())] #[scale_info(bounds(), skip_type_params(Call))] #[scale_info(replace_segment("staging_xcm", "xcm"))] #[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))] diff --git a/polkadot/xcm/src/v3/multiasset.rs b/polkadot/xcm/src/v3/multiasset.rs index e8bd3e167f61d..b078c9f456777 100644 --- a/polkadot/xcm/src/v3/multiasset.rs +++ b/polkadot/xcm/src/v3/multiasset.rs @@ -34,7 +34,7 @@ use crate::v4::{ }; use alloc::{vec, vec::Vec}; use bounded_collections::{BoundedVec, ConstU32}; -use codec::{self as codec, Decode, Encode, MaxEncodedLen}; +use codec::{self as codec, Decode, DecodeWithMemTracking, Encode, MaxEncodedLen}; use core::cmp::Ordering; use scale_info::TypeInfo; @@ -48,6 +48,7 @@ use scale_info::TypeInfo; PartialOrd, Encode, Decode, + DecodeWithMemTracking, Debug, TypeInfo, MaxEncodedLen, @@ -256,6 +257,7 @@ impl TryFrom for u128 { PartialOrd, Debug, Encode, + DecodeWithMemTracking, TypeInfo, MaxEncodedLen, serde::Serialize, @@ -338,6 +340,7 @@ impl TryFrom for Fungibility { Debug, Encode, Decode, + DecodeWithMemTracking, TypeInfo, MaxEncodedLen, serde::Serialize, @@ -374,6 +377,7 @@ impl TryFrom for WildFungibility { Debug, Encode, Decode, + DecodeWithMemTracking, TypeInfo, MaxEncodedLen, serde::Serialize, @@ -451,6 +455,7 @@ impl AssetId { Debug, Encode, Decode, + DecodeWithMemTracking, TypeInfo, MaxEncodedLen, serde::Serialize, @@ -561,6 +566,7 @@ impl TryFrom for MultiAsset { PartialOrd, Debug, Encode, + DecodeWithMemTracking, TypeInfo, Default, serde::Serialize, @@ -776,6 +782,7 @@ impl MultiAssets { Debug, Encode, Decode, + DecodeWithMemTracking, TypeInfo, MaxEncodedLen, serde::Serialize, @@ -892,6 +899,7 @@ impl, B: Into> From<(A, B)> for WildMultiAsset Debug, Encode, Decode, + DecodeWithMemTracking, TypeInfo, MaxEncodedLen, serde::Serialize, diff --git a/polkadot/xcm/src/v3/multilocation.rs b/polkadot/xcm/src/v3/multilocation.rs index 8f18312046f88..c2da432797b19 100644 --- a/polkadot/xcm/src/v3/multilocation.rs +++ b/polkadot/xcm/src/v3/multilocation.rs @@ -18,7 +18,7 @@ use super::{Junction, Junctions}; use crate::{v4::Location as NewMultiLocation, VersionedLocation}; -use codec::{Decode, Encode, MaxEncodedLen}; +use codec::{Decode, DecodeWithMemTracking, Encode, MaxEncodedLen}; use core::result; use scale_info::TypeInfo; @@ -53,6 +53,7 @@ use scale_info::TypeInfo; Clone, Decode, Encode, + DecodeWithMemTracking, Eq, PartialEq, Ord, diff --git a/polkadot/xcm/src/v3/traits.rs b/polkadot/xcm/src/v3/traits.rs index cbf85b454cc6c..387530d5fe463 100644 --- a/polkadot/xcm/src/v3/traits.rs +++ b/polkadot/xcm/src/v3/traits.rs @@ -32,7 +32,7 @@ use super::*; /// Error codes used in XCM. The first errors codes have explicit indices and are part of the XCM /// format. Those trailing are merely part of the XCM implementation; there is no expectation that /// they will retain the same index over time. -#[derive(Copy, Clone, Encode, Decode, Eq, PartialEq, Debug, TypeInfo)] +#[derive(Copy, Clone, Encode, Decode, DecodeWithMemTracking, Eq, PartialEq, Debug, TypeInfo)] #[scale_info(replace_segment("staging_xcm", "xcm"))] #[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))] pub enum Error { @@ -379,7 +379,9 @@ impl ExecuteXcm for () { } /// Error result value when attempting to send an XCM message. -#[derive(Clone, Encode, Decode, Eq, PartialEq, Debug, scale_info::TypeInfo)] +#[derive( + Clone, Encode, Decode, DecodeWithMemTracking, Eq, PartialEq, Debug, scale_info::TypeInfo, +)] #[scale_info(replace_segment("staging_xcm", "xcm"))] pub enum SendError { /// The message and destination combination was not recognized as being reachable. diff --git a/polkadot/xcm/src/v4/asset.rs b/polkadot/xcm/src/v4/asset.rs index d7a9297d69322..414fa29267ccf 100644 --- a/polkadot/xcm/src/v4/asset.rs +++ b/polkadot/xcm/src/v4/asset.rs @@ -41,7 +41,7 @@ use crate::{ }; use alloc::{vec, vec::Vec}; use bounded_collections::{BoundedVec, ConstU32}; -use codec::{self as codec, Decode, Encode, MaxEncodedLen}; +use codec::{self as codec, Decode, DecodeWithMemTracking, Encode, MaxEncodedLen}; use core::cmp::Ordering; use scale_info::TypeInfo; @@ -55,6 +55,7 @@ use scale_info::TypeInfo; PartialOrd, Encode, Decode, + DecodeWithMemTracking, Debug, TypeInfo, MaxEncodedLen, @@ -287,6 +288,7 @@ impl TryFrom for Fungibility { PartialOrd, Debug, Encode, + DecodeWithMemTracking, TypeInfo, MaxEncodedLen, serde::Serialize, @@ -367,6 +369,7 @@ impl TryFrom for Fungibility { Debug, Encode, Decode, + DecodeWithMemTracking, TypeInfo, MaxEncodedLen, serde::Serialize, @@ -411,6 +414,7 @@ impl TryFrom for WildFungibility { Debug, Encode, Decode, + DecodeWithMemTracking, TypeInfo, MaxEncodedLen, serde::Serialize, @@ -488,6 +492,7 @@ impl Reanchorable for AssetId { Debug, Encode, Decode, + DecodeWithMemTracking, TypeInfo, MaxEncodedLen, serde::Serialize, @@ -599,6 +604,7 @@ impl TryFrom for Asset { PartialOrd, Debug, Encode, + DecodeWithMemTracking, TypeInfo, Default, serde::Serialize, @@ -828,6 +834,7 @@ impl Reanchorable for Assets { Debug, Encode, Decode, + DecodeWithMemTracking, TypeInfo, MaxEncodedLen, serde::Serialize, @@ -952,6 +959,7 @@ impl, B: Into> From<(A, B)> for WildAsset { Debug, Encode, Decode, + DecodeWithMemTracking, TypeInfo, MaxEncodedLen, serde::Serialize, diff --git a/polkadot/xcm/src/v4/junction.rs b/polkadot/xcm/src/v4/junction.rs index c6e83214328e9..4d85ac79bc7fd 100644 --- a/polkadot/xcm/src/v4/junction.rs +++ b/polkadot/xcm/src/v4/junction.rs @@ -24,7 +24,7 @@ use crate::{ VersionedLocation, }; use bounded_collections::{BoundedSlice, BoundedVec, ConstU32}; -use codec::{self, Decode, Encode, MaxEncodedLen}; +use codec::{self, Decode, DecodeWithMemTracking, Encode, MaxEncodedLen}; use scale_info::TypeInfo; use serde::{Deserialize, Serialize}; @@ -40,6 +40,7 @@ use serde::{Deserialize, Serialize}; PartialOrd, Encode, Decode, + DecodeWithMemTracking, Debug, TypeInfo, MaxEncodedLen, @@ -138,6 +139,7 @@ impl From for NetworkId { PartialOrd, Encode, Decode, + DecodeWithMemTracking, Debug, TypeInfo, MaxEncodedLen, diff --git a/polkadot/xcm/src/v4/junctions.rs b/polkadot/xcm/src/v4/junctions.rs index e5c54ecb21a5f..374d1636009a6 100644 --- a/polkadot/xcm/src/v4/junctions.rs +++ b/polkadot/xcm/src/v4/junctions.rs @@ -18,7 +18,7 @@ use super::{Junction, Location, NetworkId}; use alloc::sync::Arc; -use codec::{Decode, Encode, MaxEncodedLen}; +use codec::{Decode, DecodeWithMemTracking, Encode, MaxEncodedLen}; use core::{mem, ops::Range, result}; use scale_info::TypeInfo; @@ -38,6 +38,7 @@ pub(crate) const MAX_JUNCTIONS: usize = 8; PartialOrd, Encode, Decode, + DecodeWithMemTracking, Debug, TypeInfo, MaxEncodedLen, diff --git a/polkadot/xcm/src/v4/location.rs b/polkadot/xcm/src/v4/location.rs index 3a44b0696be41..1e31bd3b815f0 100644 --- a/polkadot/xcm/src/v4/location.rs +++ b/polkadot/xcm/src/v4/location.rs @@ -18,7 +18,7 @@ use super::{traits::Reanchorable, Junction, Junctions}; use crate::{v3::MultiLocation as OldLocation, v5::Location as NewLocation, VersionedLocation}; -use codec::{Decode, Encode, MaxEncodedLen}; +use codec::{Decode, DecodeWithMemTracking, Encode, MaxEncodedLen}; use core::result; use scale_info::TypeInfo; @@ -51,6 +51,7 @@ use scale_info::TypeInfo; #[derive( Clone, Decode, + DecodeWithMemTracking, Encode, Eq, PartialEq, diff --git a/polkadot/xcm/src/v4/mod.rs b/polkadot/xcm/src/v4/mod.rs index 66816e2fb6e7e..b40a161be60b4 100644 --- a/polkadot/xcm/src/v4/mod.rs +++ b/polkadot/xcm/src/v4/mod.rs @@ -31,8 +31,8 @@ use crate::DoubleEncoded; use alloc::{vec, vec::Vec}; use bounded_collections::{parameter_types, BoundedVec}; use codec::{ - self, decode_vec_with_len, Compact, Decode, Encode, Error as CodecError, Input as CodecInput, - MaxEncodedLen, + self, decode_vec_with_len, Compact, Decode, DecodeWithMemTracking, Encode, Error as CodecError, + Input as CodecInput, MaxEncodedLen, }; use core::{fmt::Debug, result}; use derive_where::derive_where; @@ -65,7 +65,7 @@ pub const VERSION: super::Version = 4; /// An identifier for a query. pub type QueryId = u64; -#[derive(Default, Encode, TypeInfo)] +#[derive(Default, Encode, DecodeWithMemTracking, TypeInfo)] #[derive_where(Clone, Eq, PartialEq, Debug)] #[codec(encode_bound())] #[codec(decode_bound())] @@ -232,7 +232,9 @@ parameter_types! { pub MaxPalletsInfo: u32 = 64; } -#[derive(Clone, Eq, PartialEq, Encode, Decode, Debug, TypeInfo, MaxEncodedLen)] +#[derive( + Clone, Eq, PartialEq, Encode, Decode, DecodeWithMemTracking, Debug, TypeInfo, MaxEncodedLen, +)] pub struct PalletInfo { #[codec(compact)] pub index: u32, @@ -295,7 +297,9 @@ impl PalletInfo { } /// Response data to a query. -#[derive(Clone, Eq, PartialEq, Encode, Decode, Debug, TypeInfo, MaxEncodedLen)] +#[derive( + Clone, Eq, PartialEq, Encode, Decode, DecodeWithMemTracking, Debug, TypeInfo, MaxEncodedLen, +)] pub enum Response { /// No response. Serves as a neutral default. Null, @@ -373,7 +377,7 @@ impl TryFrom for Response { } /// Information regarding the composition of a query response. -#[derive(Clone, Eq, PartialEq, Encode, Decode, Debug, TypeInfo)] +#[derive(Clone, Eq, PartialEq, Encode, Decode, DecodeWithMemTracking, Debug, TypeInfo)] pub struct QueryResponseInfo { /// The destination to which the query response message should be send. pub destination: Location, @@ -436,10 +440,18 @@ impl XcmContext { /// /// This is the inner XCM format and is version-sensitive. Messages are typically passed using the /// outer XCM format, known as `VersionedXcm`. -#[derive(Encode, Decode, TypeInfo, xcm_procedural::XcmWeightInfoTrait, xcm_procedural::Builder)] +#[derive( + Encode, + Decode, + DecodeWithMemTracking, + TypeInfo, + xcm_procedural::XcmWeightInfoTrait, + xcm_procedural::Builder, +)] #[derive_where(Clone, Eq, PartialEq, Debug)] #[codec(encode_bound())] #[codec(decode_bound())] +#[codec(decode_with_mem_tracking_bound())] #[scale_info(bounds(), skip_type_params(Call))] pub enum Instruction { /// Withdraw asset(s) (`assets`) from the ownership of `origin` and place them into the Holding diff --git a/polkadot/xcm/src/v5/asset.rs b/polkadot/xcm/src/v5/asset.rs index d0d9a7cedff05..b781ef057504e 100644 --- a/polkadot/xcm/src/v5/asset.rs +++ b/polkadot/xcm/src/v5/asset.rs @@ -34,7 +34,7 @@ use crate::v4::{ }; use alloc::{vec, vec::Vec}; use bounded_collections::{BoundedVec, ConstU32}; -use codec::{self as codec, Decode, Encode, MaxEncodedLen}; +use codec::{self as codec, Decode, DecodeWithMemTracking, Encode, MaxEncodedLen}; use core::cmp::Ordering; use scale_info::TypeInfo; @@ -48,6 +48,7 @@ use scale_info::TypeInfo; PartialOrd, Encode, Decode, + DecodeWithMemTracking, Debug, TypeInfo, MaxEncodedLen, @@ -254,6 +255,7 @@ impl TryFrom for u128 { PartialOrd, Debug, Encode, + DecodeWithMemTracking, TypeInfo, MaxEncodedLen, serde::Serialize, @@ -334,6 +336,7 @@ impl TryFrom for Fungibility { Debug, Encode, Decode, + DecodeWithMemTracking, TypeInfo, MaxEncodedLen, serde::Serialize, @@ -367,6 +370,7 @@ impl TryFrom for WildFungibility { Debug, Encode, Decode, + DecodeWithMemTracking, TypeInfo, MaxEncodedLen, serde::Serialize, @@ -433,6 +437,7 @@ impl Reanchorable for AssetId { Debug, Encode, Decode, + DecodeWithMemTracking, TypeInfo, MaxEncodedLen, serde::Serialize, @@ -537,6 +542,7 @@ impl TryFrom for Asset { PartialOrd, Debug, Encode, + DecodeWithMemTracking, TypeInfo, Default, serde::Serialize, @@ -754,6 +760,7 @@ impl Reanchorable for Assets { Debug, Encode, Decode, + DecodeWithMemTracking, TypeInfo, MaxEncodedLen, serde::Serialize, @@ -864,6 +871,7 @@ impl, B: Into> From<(A, B)> for WildAsset { Debug, Encode, Decode, + DecodeWithMemTracking, TypeInfo, MaxEncodedLen, serde::Serialize, @@ -962,6 +970,7 @@ impl TryFrom for AssetFilter { Debug, Encode, Decode, + DecodeWithMemTracking, TypeInfo, MaxEncodedLen, serde::Serialize, diff --git a/polkadot/xcm/src/v5/junction.rs b/polkadot/xcm/src/v5/junction.rs index d86a762fcf445..bd5753d69d2ab 100644 --- a/polkadot/xcm/src/v5/junction.rs +++ b/polkadot/xcm/src/v5/junction.rs @@ -23,7 +23,7 @@ use crate::{ VersionedLocation, }; use bounded_collections::{BoundedSlice, BoundedVec, ConstU32}; -use codec::{self, Decode, Encode, MaxEncodedLen}; +use codec::{self, Decode, DecodeWithMemTracking, Encode, MaxEncodedLen}; use hex_literal::hex; use scale_info::TypeInfo; use serde::{Deserialize, Serialize}; @@ -40,6 +40,7 @@ use serde::{Deserialize, Serialize}; PartialOrd, Encode, Decode, + DecodeWithMemTracking, Debug, TypeInfo, MaxEncodedLen, @@ -127,6 +128,7 @@ pub const DUMMY_GENESIS_HASH: [u8; 32] = [0; 32]; PartialOrd, Encode, Decode, + DecodeWithMemTracking, Debug, TypeInfo, MaxEncodedLen, diff --git a/polkadot/xcm/src/v5/junctions.rs b/polkadot/xcm/src/v5/junctions.rs index dc93c541d19d5..ec5381a2472c5 100644 --- a/polkadot/xcm/src/v5/junctions.rs +++ b/polkadot/xcm/src/v5/junctions.rs @@ -18,7 +18,7 @@ use super::{Junction, Location, NetworkId}; use alloc::sync::Arc; -use codec::{Decode, Encode, MaxEncodedLen}; +use codec::{Decode, DecodeWithMemTracking, Encode, MaxEncodedLen}; use core::{mem, ops::Range, result}; use scale_info::TypeInfo; @@ -38,6 +38,7 @@ pub(crate) const MAX_JUNCTIONS: usize = 8; PartialOrd, Encode, Decode, + DecodeWithMemTracking, Debug, TypeInfo, MaxEncodedLen, diff --git a/polkadot/xcm/src/v5/location.rs b/polkadot/xcm/src/v5/location.rs index 38e8ecdd15ca8..c80cd11b0aac9 100644 --- a/polkadot/xcm/src/v5/location.rs +++ b/polkadot/xcm/src/v5/location.rs @@ -18,7 +18,7 @@ use super::{traits::Reanchorable, Junction, Junctions}; use crate::{v4::Location as OldLocation, VersionedLocation}; -use codec::{Decode, Encode, MaxEncodedLen}; +use codec::{Decode, DecodeWithMemTracking, Encode, MaxEncodedLen}; use core::result; use scale_info::TypeInfo; @@ -52,6 +52,7 @@ use scale_info::TypeInfo; Clone, Decode, Encode, + DecodeWithMemTracking, Eq, PartialEq, Ord, diff --git a/polkadot/xcm/src/v5/mod.rs b/polkadot/xcm/src/v5/mod.rs index 51f6d839e972a..924e514618dd9 100644 --- a/polkadot/xcm/src/v5/mod.rs +++ b/polkadot/xcm/src/v5/mod.rs @@ -25,8 +25,8 @@ use crate::DoubleEncoded; use alloc::{vec, vec::Vec}; use bounded_collections::{parameter_types, BoundedVec}; use codec::{ - self, decode_vec_with_len, Compact, Decode, Encode, Error as CodecError, Input as CodecInput, - MaxEncodedLen, + self, decode_vec_with_len, Compact, Decode, DecodeWithMemTracking, Encode, Error as CodecError, + Input as CodecInput, MaxEncodedLen, }; use core::{fmt::Debug, result}; use derive_where::derive_where; @@ -59,7 +59,7 @@ pub const VERSION: super::Version = 5; /// An identifier for a query. pub type QueryId = u64; -#[derive(Default, Encode, TypeInfo)] +#[derive(Default, DecodeWithMemTracking, Encode, TypeInfo)] #[derive_where(Clone, Eq, PartialEq, Debug)] #[codec(encode_bound())] #[codec(decode_bound())] @@ -228,7 +228,9 @@ parameter_types! { pub MaxPalletsInfo: u32 = 64; } -#[derive(Clone, Eq, PartialEq, Encode, Decode, Debug, TypeInfo, MaxEncodedLen)] +#[derive( + Clone, Eq, PartialEq, Encode, Decode, DecodeWithMemTracking, Debug, TypeInfo, MaxEncodedLen, +)] pub struct PalletInfo { #[codec(compact)] pub index: u32, @@ -275,7 +277,9 @@ impl PalletInfo { } /// Response data to a query. -#[derive(Clone, Eq, PartialEq, Encode, Decode, Debug, TypeInfo, MaxEncodedLen)] +#[derive( + Clone, Eq, PartialEq, Encode, Decode, DecodeWithMemTracking, Debug, TypeInfo, MaxEncodedLen, +)] pub enum Response { /// No response. Serves as a neutral default. Null, @@ -327,7 +331,7 @@ impl TryFrom for Response { } /// Information regarding the composition of a query response. -#[derive(Clone, Eq, PartialEq, Encode, Decode, Debug, TypeInfo)] +#[derive(Clone, Eq, PartialEq, Encode, Decode, DecodeWithMemTracking, Debug, TypeInfo)] pub struct QueryResponseInfo { /// The destination to which the query response message should be send. pub destination: Location, @@ -378,10 +382,18 @@ impl XcmContext { /// /// This is the inner XCM format and is version-sensitive. Messages are typically passed using the /// outer XCM format, known as `VersionedXcm`. -#[derive(Encode, Decode, TypeInfo, xcm_procedural::XcmWeightInfoTrait, xcm_procedural::Builder)] +#[derive( + Encode, + Decode, + DecodeWithMemTracking, + TypeInfo, + xcm_procedural::XcmWeightInfoTrait, + xcm_procedural::Builder, +)] #[derive_where(Clone, Eq, PartialEq, Debug)] #[codec(encode_bound())] #[codec(decode_bound())] +#[codec(decode_with_mem_tracking_bound())] #[scale_info(bounds(), skip_type_params(Call))] pub enum Instruction { /// Withdraw asset(s) (`assets`) from the ownership of `origin` and place them into the Holding @@ -1134,7 +1146,17 @@ pub enum Instruction { SetHints { hints: BoundedVec }, } -#[derive(Encode, Decode, TypeInfo, Debug, PartialEq, Eq, Clone, xcm_procedural::NumVariants)] +#[derive( + Encode, + Decode, + DecodeWithMemTracking, + TypeInfo, + Debug, + PartialEq, + Eq, + Clone, + xcm_procedural::NumVariants, +)] pub enum Hint { /// Set asset claimer for all the trapped assets during the execution. /// diff --git a/polkadot/xcm/src/v5/traits.rs b/polkadot/xcm/src/v5/traits.rs index 79d3285614287..4ee921589164b 100644 --- a/polkadot/xcm/src/v5/traits.rs +++ b/polkadot/xcm/src/v5/traits.rs @@ -17,7 +17,7 @@ //! Cross-Consensus Message format data structures. pub use crate::v3::{Error as OldError, SendError, XcmHash}; -use codec::{Decode, Encode}; +use codec::{Decode, DecodeWithMemTracking, Encode}; use core::result; use scale_info::TypeInfo; @@ -28,7 +28,7 @@ use super::*; /// Error codes used in XCM. The first errors codes have explicit indices and are part of the XCM /// format. Those trailing are merely part of the XCM implementation; there is no expectation that /// they will retain the same index over time. -#[derive(Copy, Clone, Encode, Decode, Eq, PartialEq, Debug, TypeInfo)] +#[derive(Copy, Clone, Encode, Decode, DecodeWithMemTracking, Eq, PartialEq, Debug, TypeInfo)] #[scale_info(replace_segment("staging_xcm", "xcm"))] #[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))] pub enum Error { @@ -240,7 +240,7 @@ impl From for Error { pub type Result = result::Result<(), Error>; /// Outcome of an XCM execution. -#[derive(Clone, Encode, Decode, Eq, PartialEq, Debug, TypeInfo)] +#[derive(Clone, Encode, Decode, DecodeWithMemTracking, Eq, PartialEq, Debug, TypeInfo)] pub enum Outcome { /// Execution completed successfully; given weight was used. Complete { used: Weight }, diff --git a/polkadot/xcm/xcm-executor/src/traits/asset_transfer.rs b/polkadot/xcm/xcm-executor/src/traits/asset_transfer.rs index 22e4a3bd61a83..b48f089f59866 100644 --- a/polkadot/xcm/xcm-executor/src/traits/asset_transfer.rs +++ b/polkadot/xcm/xcm-executor/src/traits/asset_transfer.rs @@ -17,7 +17,7 @@ use crate::traits::TransactAsset; use frame_support::traits::ContainsPair; use scale_info::TypeInfo; -use sp_runtime::codec::{Decode, Encode}; +use sp_runtime::codec::{Decode, DecodeWithMemTracking, Encode}; use xcm::prelude::*; /// Errors related to determining asset transfer support. @@ -28,7 +28,7 @@ pub enum Error { } /// Specify which type of asset transfer is required for a particular `(asset, dest)` combination. -#[derive(Clone, Encode, Decode, PartialEq, Debug, TypeInfo)] +#[derive(Clone, Encode, Decode, DecodeWithMemTracking, PartialEq, Debug, TypeInfo)] pub enum TransferType { /// should teleport `asset` to `dest` Teleport,