From 84ca434413e7fa75c0d45ffd4d2e59ace763da20 Mon Sep 17 00:00:00 2001 From: Serban Iorga Date: Mon, 10 Feb 2025 18:51:01 +0200 Subject: [PATCH] Implement DecodeWithMemTracking for some structs (#897) * Implement DecodeWithMemTracking for uint and fixed hashes * Implement DecodeWithMemTracking for BoundedVec and WeakBoundedVec * Update rust version * Bump version --- .github/workflows/ci.yml | 2 +- bounded-collections/CHANGELOG.md | 3 +++ bounded-collections/Cargo.toml | 6 +++--- bounded-collections/src/bounded_vec.rs | 4 +++- bounded-collections/src/weak_bounded_vec.rs | 4 +++- primitive-types/CHANGELOG.md | 3 +++ primitive-types/Cargo.toml | 4 ++-- primitive-types/impls/codec/Cargo.toml | 2 +- primitive-types/impls/codec/src/lib.rs | 4 ++++ 9 files changed, 23 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d499b251..ebea0997 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -39,7 +39,7 @@ jobs: - uses: actions-rs/toolchain@v1 with: profile: minimal - toolchain: 1.75.0 + toolchain: 1.79.0 override: true - name: Rust Cache diff --git a/bounded-collections/CHANGELOG.md b/bounded-collections/CHANGELOG.md index 101024fe..7e8cfcd0 100644 --- a/bounded-collections/CHANGELOG.md +++ b/bounded-collections/CHANGELOG.md @@ -4,6 +4,9 @@ The format is based on [Keep a Changelog]. [Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ +## [0.2.3] - 2025-01-30 +- Implement DecodeWithMemTracking for some structs [#897](https://github.com/paritytech/parity-common/pull/897) + ## [0.2.2] - 2024-11-08 - Added `ConstInt` and `ConstUint` types. [#878](https://github.com/paritytech/parity-common/pull/878) diff --git a/bounded-collections/Cargo.toml b/bounded-collections/Cargo.toml index 3f72b5e9..7bdfe84f 100644 --- a/bounded-collections/Cargo.toml +++ b/bounded-collections/Cargo.toml @@ -1,16 +1,16 @@ [package] name = "bounded-collections" -version = "0.2.2" +version = "0.2.3" authors = ["Parity Technologies "] license = "MIT OR Apache-2.0" homepage = "https://github.com/paritytech/parity-common" description = "Bounded types and their supporting traits" edition = "2021" -rust-version = "1.75.0" +rust-version = "1.79.0" [dependencies] serde = { version = "1.0.101", default-features = false, optional = true, features=["alloc", "derive"] } -codec = { version = "3.3.0", default-features = false, features = ["max-encoded-len"], package = "parity-scale-codec" } +codec = { version = "3.7.4", default-features = false, features = ["max-encoded-len"], package = "parity-scale-codec" } scale-info = { version = ">=1.0, <3", features = ["derive"], default-features = false } log = { version = "0.4.17", default-features = false } schemars = { version = ">=0.8.12", default-features = true, optional = true } diff --git a/bounded-collections/src/bounded_vec.rs b/bounded-collections/src/bounded_vec.rs index 1c3a5b34..99d293bc 100644 --- a/bounded-collections/src/bounded_vec.rs +++ b/bounded-collections/src/bounded_vec.rs @@ -21,7 +21,7 @@ use super::WeakBoundedVec; use crate::{Get, TryCollect}; use alloc::vec::Vec; -use codec::{decode_vec_with_len, Compact, Decode, Encode, EncodeLike, MaxEncodedLen}; +use codec::{decode_vec_with_len, Compact, Decode, DecodeWithMemTracking, Encode, EncodeLike, MaxEncodedLen}; use core::{ marker::PhantomData, ops::{Deref, Index, IndexMut, RangeBounds}, @@ -285,6 +285,8 @@ impl> Decode for BoundedVec { } } +impl> DecodeWithMemTracking for BoundedVec {} + // `BoundedVec`s encode to something which will always decode as a `Vec`. impl> EncodeLike> for BoundedVec {} diff --git a/bounded-collections/src/weak_bounded_vec.rs b/bounded-collections/src/weak_bounded_vec.rs index b6f0846e..f5cf4e7b 100644 --- a/bounded-collections/src/weak_bounded_vec.rs +++ b/bounded-collections/src/weak_bounded_vec.rs @@ -21,7 +21,7 @@ use super::{BoundedSlice, BoundedVec}; use crate::Get; use alloc::vec::Vec; -use codec::{Decode, Encode, MaxEncodedLen}; +use codec::{Decode, DecodeWithMemTracking, Encode, MaxEncodedLen}; use core::{ marker::PhantomData, ops::{Deref, Index, IndexMut}, @@ -118,6 +118,8 @@ impl> Decode for WeakBoundedVec { } } +impl> DecodeWithMemTracking for WeakBoundedVec {} + impl WeakBoundedVec { /// Create `Self` from `t` without any checks. fn unchecked_from(t: Vec) -> Self { diff --git a/primitive-types/CHANGELOG.md b/primitive-types/CHANGELOG.md index 7bcb454a..4d97623b 100644 --- a/primitive-types/CHANGELOG.md +++ b/primitive-types/CHANGELOG.md @@ -6,6 +6,9 @@ The format is based on [Keep a Changelog]. ## [Unreleased] +## [0.13.2] - 2025-01-30 +- Implement DecodeWithMemTracking for some structs [#897](https://github.com/paritytech/parity-common/pull/897) + ## [0.13.1] - 2024-09-12 - Updated `uint` to 0.10. [#859](https://github.com/paritytech/parity-common/pull/859) diff --git a/primitive-types/Cargo.toml b/primitive-types/Cargo.toml index 20292d01..f339abf9 100644 --- a/primitive-types/Cargo.toml +++ b/primitive-types/Cargo.toml @@ -1,13 +1,13 @@ [package] name = "primitive-types" -version = "0.13.1" +version = "0.13.2" authors = ["Parity Technologies "] license = "MIT OR Apache-2.0" homepage = "https://github.com/paritytech/parity-common" repository = "https://github.com/paritytech/parity-common" description = "Primitive types shared by Ethereum and Substrate" edition = "2021" -rust-version = "1.60.0" +rust-version = "1.79.0" [dependencies] fixed-hash = { version = "0.8", path = "../fixed-hash", default-features = false } diff --git a/primitive-types/impls/codec/Cargo.toml b/primitive-types/impls/codec/Cargo.toml index d0bd6b60..f2de13bd 100644 --- a/primitive-types/impls/codec/Cargo.toml +++ b/primitive-types/impls/codec/Cargo.toml @@ -9,7 +9,7 @@ edition = "2021" rust-version = "1.56.1" [dependencies] -parity-scale-codec = { version = "3.3.0", default-features = false, features = ["max-encoded-len"] } +parity-scale-codec = { version = "3.7.4", default-features = false, features = ["max-encoded-len"] } [features] default = ["std"] diff --git a/primitive-types/impls/codec/src/lib.rs b/primitive-types/impls/codec/src/lib.rs index 905d17d1..39aeaa73 100644 --- a/primitive-types/impls/codec/src/lib.rs +++ b/primitive-types/impls/codec/src/lib.rs @@ -32,6 +32,8 @@ macro_rules! impl_uint_codec { } } + impl $crate::codec::DecodeWithMemTracking for $name {} + impl $crate::codec::MaxEncodedLen for $name { fn max_encoded_len() -> usize { ::core::mem::size_of::<$name>() @@ -58,6 +60,8 @@ macro_rules! impl_fixed_hash_codec { } } + impl $crate::codec::DecodeWithMemTracking for $name {} + impl $crate::codec::MaxEncodedLen for $name { fn max_encoded_len() -> usize { ::core::mem::size_of::<$name>()