Skip to content
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
2 changes: 1 addition & 1 deletion bridges/bin/runtime-common/src/extensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ where
#[macro_export]
macro_rules! generate_bridge_reject_obsolete_headers_and_messages {
($call:ty, $account_id:ty, $($filter_call:ty),*) => {
#[derive(Clone, codec::Decode, Default, codec::Encode, Eq, PartialEq, sp_runtime::RuntimeDebug, scale_info::TypeInfo)]
#[derive(Clone, codec::Decode, codec::DecodeWithMemTracking, Default, codec::Encode, Eq, PartialEq, sp_runtime::RuntimeDebug, scale_info::TypeInfo)]
pub struct BridgeRejectObsoleteHeadersAndMessages;
impl sp_runtime::traits::TransactionExtension<$call> for BridgeRejectObsoleteHeadersAndMessages {
const IDENTIFIER: &'static str = "BridgeRejectObsoleteHeadersAndMessages";
Expand Down
4 changes: 2 additions & 2 deletions bridges/chains/chain-polkadot-bulletin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use bp_runtime::{
},
Chain, ChainId, TransactionEra,
};
use codec::{Decode, Encode};
use codec::{Decode, DecodeWithMemTracking, Encode};
use frame_support::{
dispatch::DispatchClass,
parameter_types,
Expand Down Expand Up @@ -91,7 +91,7 @@ pub type TransactionExtensionSchema = GenericTransactionExtension<(
)>;

/// Transaction extension, used by Polkadot Bulletin.
#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)]
#[derive(Encode, Decode, DecodeWithMemTracking, Debug, PartialEq, Eq, Clone, TypeInfo)]
pub struct TransactionExtension(TransactionExtensionSchema);

impl<C> sp_runtime::traits::TransactionExtension<C> for TransactionExtension
Expand Down
4 changes: 2 additions & 2 deletions bridges/modules/messages/src/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ use bp_messages::{
use bp_runtime::{
messages::MessageDispatchResult, Chain, ChainId, Size, UnverifiedStorageProofParams,
};
use codec::{Decode, Encode};
use codec::{Decode, DecodeWithMemTracking, Encode};
use frame_support::{
derive_impl,
weights::{constants::RocksDbWeight, Weight},
Expand All @@ -58,7 +58,7 @@ use std::{collections::VecDeque, ops::RangeInclusive};

pub type AccountId = u64;
pub type Balance = u64;
#[derive(Decode, Encode, Clone, Debug, PartialEq, Eq, TypeInfo)]
#[derive(Decode, DecodeWithMemTracking, Encode, Clone, Debug, PartialEq, Eq, TypeInfo)]
pub struct TestPayload {
/// Field that may be used to identify messages.
pub id: u64,
Expand Down
3 changes: 2 additions & 1 deletion bridges/modules/relayers/src/extension/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use bp_relayers::{
RewardsAccountOwner, RewardsAccountParams,
};
use bp_runtime::{Chain, RangeInclusiveExt, StaticStrProvider};
use codec::{Decode, Encode};
use codec::{Decode, DecodeWithMemTracking, Encode};
use core::{fmt::Debug, marker::PhantomData};
use frame_support::{
dispatch::{DispatchInfo, PostDispatchInfo},
Expand Down Expand Up @@ -117,6 +117,7 @@ pub enum RelayerAccountAction<AccountId, RewardBalance, LaneId> {
DefaultNoBound,
CloneNoBound,
Decode,
DecodeWithMemTracking,
Encode,
EqNoBound,
PartialEqNoBound,
Expand Down
10 changes: 5 additions & 5 deletions bridges/primitives/runtime/src/extensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

//! Primitives that may be used for creating signed extensions for indirect runtimes.

use codec::{Compact, Decode, Encode};
use codec::{Compact, Decode, DecodeWithMemTracking, Encode};
use impl_trait_for_tuples::impl_for_tuples;
use scale_info::{StaticTypeInfo, TypeInfo};
use sp_runtime::{
Expand All @@ -29,7 +29,7 @@ use sp_std::{fmt::Debug, marker::PhantomData};
/// Trait that describes some properties of a `TransactionExtension` that are needed in order to
/// send a transaction to the chain.
pub trait TransactionExtensionSchema:
Encode + Decode + Debug + Eq + Clone + StaticTypeInfo
Encode + Decode + DecodeWithMemTracking + Debug + Eq + Clone + StaticTypeInfo
{
/// A type of the data encoded as part of the transaction.
type Payload: Encode + Decode + Debug + Eq + Clone + StaticTypeInfo;
Expand All @@ -44,7 +44,7 @@ impl TransactionExtensionSchema for () {
}

/// An implementation of `TransactionExtensionSchema` using generic params.
#[derive(Encode, Decode, Clone, Debug, PartialEq, Eq, TypeInfo)]
#[derive(Encode, Decode, DecodeWithMemTracking, Clone, Debug, PartialEq, Eq, TypeInfo)]
pub struct GenericTransactionExtensionSchema<P, S>(PhantomData<(P, S)>);

impl<P, S> TransactionExtensionSchema for GenericTransactionExtensionSchema<P, S>
Expand Down Expand Up @@ -104,7 +104,7 @@ impl TransactionExtensionSchema for Tuple {

/// A simplified version of signed extensions meant for producing signed transactions
/// and signed payloads in the client code.
#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)]
#[derive(Encode, Decode, DecodeWithMemTracking, Debug, PartialEq, Eq, Clone, TypeInfo)]
pub struct GenericTransactionExtension<S: TransactionExtensionSchema> {
/// A payload that is included in the transaction.
pub payload: S::Payload,
Expand All @@ -127,7 +127,7 @@ impl<S, C> TransactionExtension<C> for GenericTransactionExtension<S>
where
C: Dispatchable,
S: TransactionExtensionSchema,
S::Payload: Send + Sync,
S::Payload: DecodeWithMemTracking + Send + Sync,
S::Implicit: Send + Sync,
{
const IDENTIFIER: &'static str = "Not needed.";
Expand Down
4 changes: 2 additions & 2 deletions cumulus/pallets/weight-reclaim/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
extern crate alloc;
#[cfg(not(feature = "std"))]
use alloc::vec::Vec;
use codec::{Decode, Encode};
use codec::{Decode, DecodeWithMemTracking, Encode};
use cumulus_primitives_storage_weight_reclaim::get_proof_size;
use derive_where::derive_where;
use frame_support::{
Expand Down Expand Up @@ -83,7 +83,7 @@ pub mod pallet {
/// calculates the unused weight using the post information and reclaim the unused weight.
/// So this extension can be used as a drop-in replacement for `WeightReclaim` extension for
/// parachains.
#[derive(Encode, Decode, TypeInfo)]
#[derive(Encode, Decode, DecodeWithMemTracking, TypeInfo)]
#[derive_where(Clone, Eq, PartialEq, Default; S)]
#[scale_info(skip_type_params(T))]
pub struct StorageWeightReclaim<T, S>(pub S, core::marker::PhantomData<T>);
Expand Down
4 changes: 3 additions & 1 deletion cumulus/pallets/weight-reclaim/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ thread_local! {
}

/// An extension which has some proof_size weight and some proof_size refund.
#[derive(Encode, Decode, Debug, Clone, PartialEq, Eq, scale_info::TypeInfo)]
#[derive(
Encode, Decode, DecodeWithMemTracking, Debug, Clone, PartialEq, Eq, scale_info::TypeInfo,
)]
pub struct MockExtensionWithRefund;

impl TransactionExtension<RuntimeCall> for MockExtensionWithRefund {
Expand Down
4 changes: 2 additions & 2 deletions cumulus/primitives/storage-weight-reclaim/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

#![cfg_attr(not(feature = "std"), no_std)]

use codec::{Decode, Encode};
use codec::{Decode, DecodeWithMemTracking, Encode};
use core::marker::PhantomData;
use cumulus_primitives_core::Weight;
use cumulus_primitives_proof_size_hostfunction::{
Expand Down Expand Up @@ -116,7 +116,7 @@ mod allow_deprecated {
to itself and ignores the post dispatch logic for extensions subsequent to itself, it also
doesn't provide weight information. \
Use `StorageWeightReclaim` in the `cumulus-pallet-weight-reclaim` crate")]
#[derive(Encode, Decode, Clone, Eq, PartialEq, Default, TypeInfo)]
#[derive(Encode, Decode, DecodeWithMemTracking, Clone, Eq, PartialEq, Default, TypeInfo)]
#[scale_info(skip_type_params(T))]
pub struct StorageWeightReclaim<T: Config + Send + Sync>(pub(super) PhantomData<T>);
}
Expand Down
6 changes: 3 additions & 3 deletions docs/sdk/src/reference_docs/transaction_extensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@

#[docify::export]
pub mod transaction_extensions_example {
use codec::{Decode, Encode};
use codec::{Decode, DecodeWithMemTracking, Encode};
use scale_info::TypeInfo;
use sp_runtime::{
impl_tx_ext_default,
Expand All @@ -72,7 +72,7 @@ pub mod transaction_extensions_example {

// This doesn't actually check anything, but simply allows
// some arbitrary `u32` to be added to the extrinsic payload
#[derive(Debug, Encode, Decode, Clone, Eq, PartialEq, TypeInfo)]
#[derive(Debug, Encode, Decode, DecodeWithMemTracking, Clone, Eq, PartialEq, TypeInfo)]
pub struct AddToPayload(pub u32);

impl<Call: Dispatchable> TransactionExtension<Call> for AddToPayload {
Expand All @@ -87,7 +87,7 @@ pub mod transaction_extensions_example {
// This is the opposite; nothing will be added to the extrinsic payload,
// but the Implicit type (`1234u32`) will be added to the
// payload to be signed.
#[derive(Debug, Encode, Decode, Clone, Eq, PartialEq, TypeInfo)]
#[derive(Debug, Encode, Decode, DecodeWithMemTracking, Clone, Eq, PartialEq, TypeInfo)]
pub struct AddToSignaturePayload;

impl<Call: Dispatchable> TransactionExtension<Call> for AddToSignaturePayload {
Expand Down
2 changes: 1 addition & 1 deletion polkadot/runtime/common/src/claims/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ impl<T: Config> Pallet<T> {

/// Validate `attest` calls prior to execution. Needed to avoid a DoS attack since they are
/// otherwise free to place on chain.
#[derive(Encode, Decode, Clone, Eq, PartialEq, TypeInfo)]
#[derive(Encode, Decode, DecodeWithMemTracking, Clone, Eq, PartialEq, TypeInfo)]
#[scale_info(skip_type_params(T))]
pub struct PrevalidateAttests<T>(core::marker::PhantomData<fn(T)>);

Expand Down
6 changes: 4 additions & 2 deletions polkadot/xcm/xcm-builder/src/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub use crate::{
FixedRateOfFungible, FixedWeightBounds, TakeWeightCredit,
};
pub use alloc::collections::{btree_map::BTreeMap, btree_set::BTreeSet};
pub use codec::{Decode, Encode};
pub use codec::{Decode, DecodeWithMemTracking, Encode};
pub use core::{
cell::{Cell, RefCell},
fmt::Debug,
Expand Down Expand Up @@ -62,7 +62,9 @@ pub enum TestOrigin {
///
/// Each item contains the amount of weight that it *wants* to consume as the first item, and the
/// actual amount (if different from the former) in the second option.
#[derive(Debug, Encode, Decode, Eq, PartialEq, Clone, Copy, scale_info::TypeInfo)]
#[derive(
Debug, Encode, Decode, DecodeWithMemTracking, Eq, PartialEq, Clone, Copy, scale_info::TypeInfo,
)]
pub enum TestCall {
OnlyRoot(Weight, Option<Weight>),
OnlyParachain(Weight, Option<Weight>, Option<u32>),
Expand Down
6 changes: 4 additions & 2 deletions polkadot/xcm/xcm-executor/src/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
//! Mock types and XcmConfig for all executor unit tests.

use alloc::collections::btree_map::BTreeMap;
use codec::{Decode, Encode};
use codec::{Decode, DecodeWithMemTracking, Encode};
use core::cell::RefCell;
use frame_support::{
dispatch::{DispatchInfo, DispatchResultWithPostInfo, GetDispatchInfo, PostDispatchInfo},
Expand Down Expand Up @@ -64,7 +64,9 @@ pub struct TestOrigin;
///
/// Doesn't dispatch anything, has an empty implementation of [`Dispatchable`] that
/// just returns `Ok` with an empty [`PostDispatchInfo`].
#[derive(Debug, Encode, Decode, Eq, PartialEq, Clone, Copy, scale_info::TypeInfo)]
#[derive(
Debug, Encode, Decode, DecodeWithMemTracking, Eq, PartialEq, Clone, Copy, scale_info::TypeInfo,
)]
pub struct TestCall;
impl Dispatchable for TestCall {
type RuntimeOrigin = TestOrigin;
Expand Down
2 changes: 1 addition & 1 deletion prdoc/pr_7634.prdoc
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ crates:
- name: frame-support-procedural
bump: major
- name: bridge-hub-westend-runtime
bump: none
bump: patch
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why this change?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

When working on the prdoc for this PR I realized that I also derived DecodeWithMemTracking in some structures from bridge-hub-westend-runtime in pr #7634. So I guess it should also be patch.

73 changes: 73 additions & 0 deletions prdoc/pr_7655.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0
# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json

title: derive `DecodeWithMemTracking` for `Block`

doc:
- audience: Runtime Dev
description: |
This PR adds `DecodeWithMemTracking` as a trait bound for `Header`, `Block` and `TransactionExtension` and
derives it for all the types that implement these traits in `polkadot-sdk`.
All the external types that implement these traits will need to implement `DecodeWithMemTracking` as well.

crates:
- name: sp-runtime
bump: major
- name: sp-staking
bump: minor
- name: bp-runtime
bump: major
- name: bridge-runtime-common
bump: patch
- name: frame-executive
bump: patch
- name: frame-support
bump: major
- name: frame-system
bump: minor
- name: pallet-balances
bump: minor
- name: pallet-verify-signature
bump: minor
- name: pallet-transaction-payment
bump: minor
- name: pallet-sudo
bump: minor
- name: polkadot-runtime-common
bump: minor
- name: cumulus-pallet-weight-reclaim
bump: minor
- name: cumulus-primitives-storage-weight-reclaim
bump: minor
- name: frame-benchmarking-cli
bump: patch
- name: frame-metadata-hash-extension
bump: minor
- name: pallet-assets
bump: minor
- name: pallet-assets-freezer
bump: minor
- name: pallet-asset-tx-payment
bump: minor
- name: pallet-bridge-relayers
bump: minor
- name: pallet-bridge-messages
bump: minor
- name: pallet-asset-conversion-tx-payment
bump: minor
- name: pallet-referenda
bump: minor
- name: pallet-revive
bump: minor
- name: pallet-skip-feeless-payment
bump: minor
- name: pallet-staking
bump: minor
- name: staging-xcm-builder
bump: patch
- name: staging-xcm-executor
bump: patch
- name: bp-polkadot-bulletin
bump: minor
- name: frame-system-benchmarking
bump: patch
13 changes: 12 additions & 1 deletion substrate/frame/assets-freezer/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,18 @@ impl pallet_assets::Config for Test {
}

#[derive(
Decode, Encode, MaxEncodedLen, PartialEq, Eq, Ord, PartialOrd, TypeInfo, Debug, Clone, Copy,
Decode,
DecodeWithMemTracking,
Encode,
MaxEncodedLen,
PartialEq,
Eq,
Ord,
PartialOrd,
TypeInfo,
Debug,
Clone,
Copy,
)]
pub enum DummyFreezeReason {
Governance,
Expand Down
2 changes: 2 additions & 0 deletions substrate/frame/assets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ where
#[frame_support::pallet]
pub mod pallet {
use super::*;
use codec::HasCompact;
use frame_support::{
pallet_prelude::*,
traits::{AccountTouch, ContainsPair},
Expand Down Expand Up @@ -316,6 +317,7 @@ pub mod pallet {
/// The units in which we record balances.
type Balance: Member
+ Parameter
+ HasCompact<Type: DecodeWithMemTracking>
+ AtLeast32BitUnsigned
+ Default
+ Copy
Expand Down
2 changes: 2 additions & 0 deletions substrate/frame/balances/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ type AccountIdLookupOf<T> = <<T as frame_system::Config>::Lookup as StaticLookup
#[frame_support::pallet]
pub mod pallet {
use super::*;
use codec::HasCompact;
use frame_support::{
pallet_prelude::*,
traits::{fungible::Credit, tokens::Precision, VariantCount, VariantCountOf},
Expand Down Expand Up @@ -270,6 +271,7 @@ pub mod pallet {
+ Member
+ AtLeast32BitUnsigned
+ Codec
+ HasCompact<Type: DecodeWithMemTracking>
+ Default
+ Copy
+ MaybeSerializeDeserialize
Expand Down
3 changes: 2 additions & 1 deletion substrate/frame/balances/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crate::{
self as pallet_balances, AccountData, Config, CreditOf, Error, Pallet, TotalIssuance,
DEFAULT_ADDRESS_URI,
};
use codec::{Decode, Encode, MaxEncodedLen};
use codec::{Decode, DecodeWithMemTracking, Encode, MaxEncodedLen};
use frame_support::{
assert_err, assert_noop, assert_ok, assert_storage_noop, derive_impl,
dispatch::{DispatchInfo, GetDispatchInfo},
Expand Down Expand Up @@ -58,6 +58,7 @@ type Block = frame_system::mocking::MockBlock<Test>;
#[derive(
Encode,
Decode,
DecodeWithMemTracking,
Copy,
Clone,
Eq,
Expand Down
Loading
Loading