Skip to content

Commit bcee229

Browse files
authored
refactor: derive DecodeWithMemTracking (#536)
* refactor: derive DecodeWithMemTracking for ProxyType * refactor: derive DecodeWithMemTracking in pallets structs * refactor: impl DecodeWithMemTracking for ItemSettings & CollectionSettings
1 parent c13b5dc commit bcee229

File tree

13 files changed

+1509
-1117
lines changed

13 files changed

+1509
-1117
lines changed

Cargo.lock

Lines changed: 1181 additions & 1071 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ resolver = "2"
3636
[workspace.dependencies]
3737
anyhow = { version = "1.0", default-features = false }
3838
clap = { version = "4.5.10", features = [ "derive" ] }
39-
codec = { package = "parity-scale-codec", version = "3.6.12", default-features = false, features = [
39+
codec = { package = "parity-scale-codec", version = "3.7.4", default-features = false, features = [
4040
"derive",
4141
] }
4242
color-print = "0.3.4"

pallets/api/src/fungibles/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ pub mod pallet {
409409
}
410410

411411
/// State reads for the fungibles API with required input.
412-
#[derive(Encode, Decode, Debug, MaxEncodedLen)]
412+
#[derive(Encode, Decode, DecodeWithMemTracking, Debug, MaxEncodedLen)]
413413
#[cfg_attr(feature = "std", derive(PartialEq, Clone))]
414414
#[repr(u8)]
415415
#[allow(clippy::unnecessary_cast)]

pallets/api/src/messaging/mod.rs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use alloc::vec::Vec;
44

5-
use codec::{Decode, Encode};
5+
use codec::{Decode, DecodeWithMemTracking, Encode};
66
use frame_support::{
77
dispatch::{DispatchResult, DispatchResultWithPostInfo},
88
pallet_prelude::MaxEncodedLen,
@@ -531,14 +531,16 @@ impl<T: Config> Pallet<T> {
531531
}
532532
}
533533

534-
#[derive(Clone, Decode, Debug, Encode, MaxEncodedLen, PartialEq, TypeInfo)]
534+
#[derive(
535+
Clone, Decode, DecodeWithMemTracking, Debug, Encode, MaxEncodedLen, PartialEq, TypeInfo,
536+
)]
535537
pub enum Status {
536538
Pending,
537539
TimedOut,
538540
Complete,
539541
}
540542

541-
#[derive(Encode, Decode, Debug, MaxEncodedLen)]
543+
#[derive(Encode, Decode, DecodeWithMemTracking, Debug, MaxEncodedLen)]
542544
#[cfg_attr(feature = "std", derive(PartialEq, Clone))]
543545
#[repr(u8)]
544546
#[allow(clippy::unnecessary_cast)]
@@ -608,7 +610,9 @@ trait CalculateDeposit<Deposit> {
608610
fn calculate_deposit(&self) -> Deposit;
609611
}
610612

611-
#[derive(Clone, Debug, Encode, Eq, Decode, MaxEncodedLen, PartialEq, TypeInfo)]
613+
#[derive(
614+
Clone, Debug, Encode, Eq, Decode, DecodeWithMemTracking, MaxEncodedLen, PartialEq, TypeInfo,
615+
)]
612616
#[scale_info(skip_type_params(T))]
613617
enum Message<T: Config> {
614618
Ismp {
@@ -638,7 +642,18 @@ enum Message<T: Config> {
638642
}
639643

640644
// Message selector and pre-paid weight used as gas limit
641-
#[derive(Copy, Clone, Debug, Encode, Eq, Decode, MaxEncodedLen, PartialEq, TypeInfo)]
645+
#[derive(
646+
Copy,
647+
Clone,
648+
Debug,
649+
Encode,
650+
Eq,
651+
Decode,
652+
DecodeWithMemTracking,
653+
MaxEncodedLen,
654+
PartialEq,
655+
TypeInfo,
656+
)]
642657
pub struct Callback {
643658
pub selector: [u8; 4],
644659
pub weight: Weight,

pallets/api/src/messaging/transports/ismp.rs

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use ::ismp::{
88
},
99
host::StateMachine,
1010
};
11-
use codec::{Decode, Encode, MaxEncodedLen};
11+
use codec::{Decode, DecodeWithMemTracking, Encode, MaxEncodedLen};
1212
use frame_support::{
1313
pallet_prelude::Weight, traits::Get as _, CloneNoBound, DebugNoBound, EqNoBound,
1414
PartialEqNoBound,
@@ -33,7 +33,16 @@ pub const ID: [u8; 3] = *b"pop";
3333

3434
type DbWeightOf<T> = <T as frame_system::Config>::DbWeight;
3535

36-
#[derive(Encode, EqNoBound, CloneNoBound, DebugNoBound, Decode, PartialEqNoBound, TypeInfo)]
36+
#[derive(
37+
Encode,
38+
EqNoBound,
39+
CloneNoBound,
40+
DebugNoBound,
41+
Decode,
42+
DecodeWithMemTracking,
43+
PartialEqNoBound,
44+
TypeInfo,
45+
)]
3746
#[scale_info(skip_type_params(T))]
3847
pub enum Message<T: Config> {
3948
Get(Get<T>),
@@ -49,7 +58,16 @@ impl<T: Config> From<Message<T>> for DispatchRequest {
4958
}
5059
}
5160

52-
#[derive(Encode, EqNoBound, CloneNoBound, DebugNoBound, Decode, PartialEqNoBound, TypeInfo)]
61+
#[derive(
62+
Encode,
63+
EqNoBound,
64+
CloneNoBound,
65+
DebugNoBound,
66+
Decode,
67+
DecodeWithMemTracking,
68+
PartialEqNoBound,
69+
TypeInfo,
70+
)]
5371
#[scale_info(skip_type_params(T))]
5472
pub struct Get<T: Config> {
5573
// TODO: Option<u32> to support relay?
@@ -90,7 +108,16 @@ impl<T: Config> CalculateDeposit<BalanceOf<T>> for Get<T> {
90108
}
91109
}
92110

93-
#[derive(Encode, EqNoBound, CloneNoBound, DebugNoBound, Decode, PartialEqNoBound, TypeInfo)]
111+
#[derive(
112+
Encode,
113+
EqNoBound,
114+
CloneNoBound,
115+
DebugNoBound,
116+
Decode,
117+
DecodeWithMemTracking,
118+
PartialEqNoBound,
119+
TypeInfo,
120+
)]
94121
#[scale_info(skip_type_params(T))]
95122
pub struct Post<T: Config> {
96123
// TODO: Option<u32> to support relay?

pallets/api/src/mock.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use codec::{Decode, Encode};
1+
use codec::{Decode, DecodeWithMemTracking, Encode};
22
use frame_support::{
33
derive_impl, parameter_types,
44
traits::{AsEnsureOriginWithArg, ConstU128, ConstU32, ConstU64, Everything},
@@ -102,6 +102,7 @@ impl pallet_assets::Config<AssetsInstance> for Test {
102102
type Extra = ();
103103
type ForceOrigin = EnsureRoot<u64>;
104104
type Freezer = ();
105+
type Holder = ();
105106
type MetadataDepositBase = ConstU128<1>;
106107
type MetadataDepositPerByte = ConstU128<1>;
107108
type RemoveItemsLimit = ConstU32<5>;
@@ -120,7 +121,7 @@ parameter_types! {
120121
pub storage Features: PalletFeatures = PalletFeatures::all_enabled();
121122
}
122123

123-
#[derive(Debug, Clone, PartialEq, Eq, Encode, Decode, TypeInfo)]
124+
#[derive(Debug, Clone, PartialEq, Eq, Encode, Decode, DecodeWithMemTracking, TypeInfo)]
124125
pub struct Noop;
125126

126127
impl IdentifyAccount for Noop {
@@ -207,6 +208,7 @@ pub(crate) fn new_test_ext() -> sp_io::TestExternalities {
207208

208209
pallet_balances::GenesisConfig::<Test> {
209210
balances: vec![(ALICE, INIT_AMOUNT), (BOB, INIT_AMOUNT), (CHARLIE, INIT_AMOUNT)],
211+
..Default::default()
210212
}
211213
.assimilate_storage(&mut t)
212214
.expect("Pallet balances storage can be assimilated");

pallets/api/src/nonfungibles/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ pub mod pallet {
531531
}
532532

533533
/// State reads for the non-fungibles API with required input.
534-
#[derive(Encode, Decode, Debug, MaxEncodedLen)]
534+
#[derive(Encode, Decode, DecodeWithMemTracking, Debug, MaxEncodedLen)]
535535
#[cfg_attr(feature = "std", derive(PartialEq, Clone))]
536536
#[repr(u8)]
537537
#[allow(clippy::unnecessary_cast)]

pallets/motion/src/mock.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ pub fn new_test_ext() -> sp_io::TestExternalities {
8888
let mut ext: sp_io::TestExternalities = RuntimeGenesisConfig {
8989
balances: pallet_balances::GenesisConfig::<Test> {
9090
balances: vec![(1, 10), (2, 20), (3, 30), (4, 40), (5, 50)],
91+
..Default::default()
9192
},
9293
council: pallet_collective::GenesisConfig {
9394
members: vec![1, 2, 3, 4],

pallets/motion/src/tests.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use codec::Encode;
1+
use codec::{DecodeWithMemTracking, Encode};
22
use frame_support::{assert_ok, dispatch::GetDispatchInfo, weights::Weight};
33
use frame_system::{EventRecord, Phase};
44
use mock::{RuntimeCall, RuntimeEvent};
@@ -13,13 +13,14 @@ use crate::{mock::*, Event as MotionEvent};
1313
fn record(event: RuntimeEvent) -> EventRecord<RuntimeEvent, H256> {
1414
EventRecord { phase: Phase::Initialization, event, topics: vec![] }
1515
}
16-
16+
#[derive(DecodeWithMemTracking)]
1717
struct Proposal {
1818
len: u32,
1919
weight: Weight,
2020
hash: H256,
2121
}
2222

23+
#[derive(DecodeWithMemTracking)]
2324
enum MotionType {
2425
SimpleMajority,
2526
SuperMajority,

pallets/nfts/src/migration.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub mod v1 {
2828

2929
use super::*;
3030

31-
#[derive(Decode)]
31+
#[derive(Decode, DecodeWithMemTracking)]
3232
#[allow(missing_docs)]
3333
pub struct OldCollectionDetails<AccountId, DepositBalance> {
3434
pub owner: AccountId,

0 commit comments

Comments
 (0)