Skip to content

Commit

Permalink
Implement DecodeWithMemTracking for some structs (#897)
Browse files Browse the repository at this point in the history
* Implement DecodeWithMemTracking for uint and fixed hashes

* Implement DecodeWithMemTracking for BoundedVec and WeakBoundedVec

* Update rust version

* Bump version
  • Loading branch information
serban300 authored Feb 10, 2025
1 parent d54ac84 commit 84ca434
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions bounded-collections/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
6 changes: 3 additions & 3 deletions bounded-collections/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
[package]
name = "bounded-collections"
version = "0.2.2"
version = "0.2.3"
authors = ["Parity Technologies <admin@parity.io>"]
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 }
Expand Down
4 changes: 3 additions & 1 deletion bounded-collections/src/bounded_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -285,6 +285,8 @@ impl<T: Decode, S: Get<u32>> Decode for BoundedVec<T, S> {
}
}

impl<T: DecodeWithMemTracking, S: Get<u32>> DecodeWithMemTracking for BoundedVec<T, S> {}

// `BoundedVec`s encode to something which will always decode as a `Vec`.
impl<T: Encode + Decode, S: Get<u32>> EncodeLike<Vec<T>> for BoundedVec<T, S> {}

Expand Down
4 changes: 3 additions & 1 deletion bounded-collections/src/weak_bounded_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -118,6 +118,8 @@ impl<T: Decode, S: Get<u32>> Decode for WeakBoundedVec<T, S> {
}
}

impl<T: DecodeWithMemTracking, S: Get<u32>> DecodeWithMemTracking for WeakBoundedVec<T, S> {}

impl<T, S> WeakBoundedVec<T, S> {
/// Create `Self` from `t` without any checks.
fn unchecked_from(t: Vec<T>) -> Self {
Expand Down
3 changes: 3 additions & 0 deletions primitive-types/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions primitive-types/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[package]
name = "primitive-types"
version = "0.13.1"
version = "0.13.2"
authors = ["Parity Technologies <admin@parity.io>"]
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 }
Expand Down
2 changes: 1 addition & 1 deletion primitive-types/impls/codec/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
4 changes: 4 additions & 0 deletions primitive-types/impls/codec/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>()
Expand All @@ -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>()
Expand Down

0 comments on commit 84ca434

Please # to comment.