Skip to content

Commit 1aa875c

Browse files
authored
add DecodeWithMemTracking features (#1028)
* add DecodeWithMemTracking features * fix clippy * downgrade [email protected] * fix ci
1 parent 2fd6442 commit 1aa875c

File tree

11 files changed

+53
-24
lines changed

11 files changed

+53
-24
lines changed

.github/workflows/coverage.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ jobs:
3838
make Cargo.toml
3939
cargo update
4040
cargo update base64ct --precise 1.6.0 # 1.8.0 requires the Cargo feature called `edition2024`
41+
cargo update pallet-revive-proc-macro --precise 0.3.0 # TODO: https://github.com/paritytech/polkadot-sdk/issues/9425
4142
cargo tarpaulin --verbose --no-fail-fast --workspace --timeout 300 --out Xml
4243
- name: Upload to codecov.io
4344
uses: codecov/codecov-action@v5

.github/workflows/test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ jobs:
3737
run: |
3838
cargo update
3939
cargo update base64ct --precise 1.6.0 # 1.8.0 requires the Cargo feature called `edition2024`
40+
cargo update pallet-revive-proc-macro --precise 0.3.0 # TODO: https://github.com/paritytech/polkadot-sdk/issues/9425
4041
- name: Run clippy
4142
run: cargo clippy -- -D warnings
4243
- name: Check for Wasm

nft/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
use frame_support::{ensure, pallet_prelude::*, traits::Get, BoundedVec, Parameter};
2525
use frame_system::pallet_prelude::*;
26-
use parity_scale_codec::{Decode, Encode, MaxEncodedLen};
26+
use parity_scale_codec::{Decode, DecodeWithMemTracking, Encode, MaxEncodedLen};
2727
use scale_info::TypeInfo;
2828
use sp_runtime::{
2929
traits::{AtLeast32BitUnsigned, CheckedAdd, CheckedSub, MaybeSerializeDeserialize, Member, One, Zero},
@@ -35,7 +35,7 @@ mod mock;
3535
mod tests;
3636

3737
/// Class info
38-
#[derive(Encode, Decode, Clone, Eq, PartialEq, MaxEncodedLen, RuntimeDebug, TypeInfo)]
38+
#[derive(Encode, Decode, DecodeWithMemTracking, Clone, Eq, PartialEq, MaxEncodedLen, RuntimeDebug, TypeInfo)]
3939
pub struct ClassInfo<TokenId, AccountId, Data, ClassMetadataOf> {
4040
/// Class metadata
4141
pub metadata: ClassMetadataOf,
@@ -48,7 +48,7 @@ pub struct ClassInfo<TokenId, AccountId, Data, ClassMetadataOf> {
4848
}
4949

5050
/// Token info
51-
#[derive(Encode, Decode, Clone, Eq, PartialEq, MaxEncodedLen, RuntimeDebug, TypeInfo)]
51+
#[derive(Encode, Decode, DecodeWithMemTracking, Clone, Eq, PartialEq, MaxEncodedLen, RuntimeDebug, TypeInfo)]
5252
pub struct TokenInfo<AccountId, Data, TokenMetadataOf> {
5353
/// Token metadata
5454
pub metadata: TokenMetadataOf,

oracle/src/lib.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#![allow(clippy::string_lit_as_bytes)]
2020
#![allow(clippy::unused_unit)]
2121

22-
use parity_scale_codec::{Decode, Encode, MaxEncodedLen};
22+
use parity_scale_codec::{Decode, DecodeWithMemTracking, Encode, MaxEncodedLen};
2323

2424
#[cfg(feature = "std")]
2525
use serde::{Deserialize, Serialize};
@@ -77,7 +77,20 @@ pub mod module {
7777
pub(crate) type MomentOf<T, I = ()> = <<T as Config<I>>::Time as Time>::Moment;
7878
pub(crate) type TimestampedValueOf<T, I = ()> = TimestampedValue<<T as Config<I>>::OracleValue, MomentOf<T, I>>;
7979

80-
#[derive(Encode, Decode, RuntimeDebug, Eq, PartialEq, Clone, Copy, Ord, PartialOrd, TypeInfo, MaxEncodedLen)]
80+
#[derive(
81+
Encode,
82+
Decode,
83+
DecodeWithMemTracking,
84+
RuntimeDebug,
85+
Eq,
86+
PartialEq,
87+
Clone,
88+
Copy,
89+
Ord,
90+
PartialOrd,
91+
TypeInfo,
92+
MaxEncodedLen,
93+
)]
8194
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
8295
pub struct TimestampedValue<Value, Moment> {
8396
pub value: Value,

payments/src/types.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#![allow(unused_qualifications)]
22
use crate::{pallet, AssetIdOf, BalanceOf};
33
use frame_system::pallet_prelude::*;
4-
use parity_scale_codec::{Decode, Encode, HasCompact, MaxEncodedLen};
4+
use parity_scale_codec::{Decode, DecodeWithMemTracking, Encode, HasCompact, MaxEncodedLen};
55
use scale_info::TypeInfo;
66
use sp_runtime::{DispatchResult, Percent};
77

@@ -13,7 +13,7 @@ use serde::{Deserialize, Serialize};
1313
/// guarantee proof of funds and can be released once an agreed upon condition
1414
/// has reached between the payment creator and recipient. The payment lifecycle
1515
/// is tracked using the state field.
16-
#[derive(Encode, Decode, Debug, Clone, PartialEq, Eq, MaxEncodedLen, TypeInfo)]
16+
#[derive(Encode, Decode, DecodeWithMemTracking, Debug, Clone, PartialEq, Eq, MaxEncodedLen, TypeInfo)]
1717
#[scale_info(skip_type_params(T))]
1818
#[codec(mel_bound(T: pallet::Config))]
1919
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
@@ -38,7 +38,7 @@ pub struct PaymentDetail<T: pallet::Config> {
3838
/// The `PaymentState` enum tracks the possible states that a payment can be in.
3939
/// When a payment is 'completed' or 'cancelled' it is removed from storage and
4040
/// hence not tracked by a state.
41-
#[derive(Encode, Decode, Debug, Clone, PartialEq, Eq, MaxEncodedLen, TypeInfo)]
41+
#[derive(Encode, Decode, DecodeWithMemTracking, Debug, Clone, PartialEq, Eq, MaxEncodedLen, TypeInfo)]
4242
#[scale_info(skip_type_params(T))]
4343
#[codec(mel_bound(T: pallet::Config))]
4444
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
@@ -109,15 +109,18 @@ pub trait FeeHandler<T: pallet::Config> {
109109
}
110110

111111
/// Types of Tasks that can be scheduled in the pallet
112-
#[derive(PartialEq, Eq, Clone, Encode, Decode, Debug, TypeInfo, MaxEncodedLen)]
112+
#[derive(PartialEq, Eq, Clone, Encode, Decode, DecodeWithMemTracking, Debug, TypeInfo, MaxEncodedLen)]
113113
pub enum Task {
114114
// payment `from` to `to` has to be cancelled
115115
Cancel,
116116
}
117117

118118
/// The details of a scheduled task
119-
#[derive(PartialEq, Eq, Clone, Encode, Decode, Debug, TypeInfo, MaxEncodedLen)]
120-
pub struct ScheduledTask<Time: HasCompact> {
119+
#[derive(PartialEq, Eq, Clone, Encode, Decode, DecodeWithMemTracking, Debug, TypeInfo, MaxEncodedLen)]
120+
pub struct ScheduledTask<Time>
121+
where
122+
Time: HasCompact,
123+
{
121124
/// the type of scheduled task
122125
pub task: Task,
123126
/// the 'time' at which the task should be executed

rewards/src/lib.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,13 @@ use sp_runtime::{
1717
use sp_std::{borrow::ToOwned, collections::btree_map::BTreeMap, fmt::Debug, prelude::*};
1818

1919
/// The Reward Pool Info.
20-
#[derive(Clone, Encode, Decode, PartialEq, Eq, RuntimeDebug, TypeInfo)]
21-
pub struct PoolInfo<Share: HasCompact, Balance: HasCompact, CurrencyId: Ord> {
20+
#[derive(Clone, Encode, Decode, DecodeWithMemTracking, PartialEq, Eq, RuntimeDebug, TypeInfo)]
21+
pub struct PoolInfo<Share, Balance, CurrencyId>
22+
where
23+
Share: HasCompact,
24+
Balance: HasCompact,
25+
CurrencyId: Ord,
26+
{
2227
/// Total shares amount
2328
pub total_shares: Share,
2429
/// Reward infos <reward_currency, (total_reward, total_withdrawn_reward)>

rust-toolchain.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[toolchain]
22
channel = "1.84.1"
3-
components = ["rustfmt", "clippy"]
3+
components = ["rust-src", "rustfmt", "clippy"]
44
targets = ["wasm32-unknown-unknown"]

tokens/src/lib.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ impl<T: Config> OnDust<T::AccountId, T::CurrencyId, T::Balance> for BurnDust<T>
114114

115115
/// A single lock on a balance. There can be many of these on an account and
116116
/// they "overlap", so the same balance is frozen by multiple locks.
117-
#[derive(Encode, Decode, Clone, PartialEq, Eq, MaxEncodedLen, RuntimeDebug, TypeInfo)]
117+
#[derive(Encode, Decode, DecodeWithMemTracking, Clone, PartialEq, Eq, MaxEncodedLen, RuntimeDebug, TypeInfo)]
118118
pub struct BalanceLock<Balance> {
119119
/// An identifier for this lock. Only one lock may be in existence for
120120
/// each identifier.
@@ -125,7 +125,7 @@ pub struct BalanceLock<Balance> {
125125
}
126126

127127
/// Store named reserved balance.
128-
#[derive(Encode, Decode, Clone, PartialEq, Eq, RuntimeDebug, MaxEncodedLen, TypeInfo)]
128+
#[derive(Encode, Decode, DecodeWithMemTracking, Clone, PartialEq, Eq, RuntimeDebug, MaxEncodedLen, TypeInfo)]
129129
pub struct ReserveData<ReserveIdentifier, Balance> {
130130
/// The identifier for the named reserve.
131131
pub id: ReserveIdentifier,
@@ -134,7 +134,9 @@ pub struct ReserveData<ReserveIdentifier, Balance> {
134134
}
135135

136136
/// balance information for an account.
137-
#[derive(Encode, Decode, Clone, PartialEq, Eq, Default, MaxEncodedLen, RuntimeDebug, TypeInfo)]
137+
#[derive(
138+
Encode, Decode, DecodeWithMemTracking, Clone, PartialEq, Eq, Default, MaxEncodedLen, RuntimeDebug, TypeInfo,
139+
)]
138140
pub struct AccountData<Balance> {
139141
/// Non-reserved part of the balance. There may still be restrictions on
140142
/// this, but it is the total pool what may in principle be transferred,

traits/src/auction.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::Change;
2-
use parity_scale_codec::{Decode, Encode, FullCodec, MaxEncodedLen};
2+
use parity_scale_codec::{Decode, DecodeWithMemTracking, Encode, FullCodec, MaxEncodedLen};
33
use scale_info::TypeInfo;
44
use sp_runtime::{
55
traits::{AtLeast32Bit, Bounded, MaybeSerializeDeserialize},
@@ -13,7 +13,7 @@ use sp_std::{
1313

1414
/// Auction info.
1515
#[cfg_attr(feature = "std", derive(PartialEq, Eq))]
16-
#[derive(Encode, Decode, RuntimeDebug, TypeInfo, MaxEncodedLen)]
16+
#[derive(Encode, Decode, DecodeWithMemTracking, RuntimeDebug, TypeInfo, MaxEncodedLen)]
1717
pub struct AuctionInfo<AccountId, Balance, BlockNumber> {
1818
/// Current bidder and bid price.
1919
pub bid: Option<(AccountId, Balance)>,

traits/src/lib.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#![cfg_attr(not(feature = "std"), no_std)]
22

33
use impl_trait_for_tuples::impl_for_tuples;
4-
use parity_scale_codec::{Decode, Encode, MaxEncodedLen};
4+
use parity_scale_codec::{Decode, DecodeWithMemTracking, Encode, MaxEncodedLen};
55
use sp_runtime::{DispatchResult, RuntimeDebug};
66
use sp_std::{
77
cmp::{Eq, PartialEq},
@@ -60,17 +60,20 @@ pub trait CombineData<Key, TimestampedValue> {
6060
}
6161

6262
/// Indicate if should change a value
63-
#[derive(Encode, Decode, Clone, Eq, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)]
63+
#[derive(Encode, Decode, DecodeWithMemTracking, Clone, Eq, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)]
6464
pub enum Change<Value> {
6565
/// No change.
6666
NoChange,
6767
/// Changed to new value.
6868
NewValue(Value),
6969
}
7070

71-
#[derive(Encode, Decode, RuntimeDebug, Eq, PartialEq, Ord, PartialOrd, Clone, Copy)]
71+
#[derive(Encode, Decode, DecodeWithMemTracking, RuntimeDebug, Eq, PartialEq, Ord, PartialOrd, Clone, Copy)]
7272
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
73-
pub struct TimestampedValue<Value: Ord + PartialOrd, Moment> {
73+
pub struct TimestampedValue<Value, Moment>
74+
where
75+
Value: Ord + PartialOrd,
76+
{
7477
pub value: Value,
7578
pub timestamp: Moment,
7679
}

0 commit comments

Comments
 (0)