Skip to content

Support JAM codec for bounded collections#914

Merged
davxy merged 8 commits intomasterfrom
support-jam-codec-for-bounded-collections
May 26, 2025
Merged

Support JAM codec for bounded collections#914
davxy merged 8 commits intomasterfrom
support-jam-codec-for-bounded-collections

Conversation

@davxy
Copy link
Copy Markdown
Member

@davxy davxy commented May 21, 2025

Previously, bounded-collections was tightly coupled to scale-codec, which posed limitations as our usage evolved.

For now, in PolkaJam, we're relying on a temporary fork: bounded-collections-next with these changes applied. However, our long-term goal is to have jam-codec supported upstream.


This PR introduces the following changes:

  • Makes the choice of codec optional (though we might retain scale-codec as the default for backward compatibility).
  • Uses feature flags and macros to conditionally enable codec-specific code, as jam-codec and scale-codec share an identical API (different in their implementations of integers compact encoding).

@davxy davxy changed the title Support JAM codec cor bounded collections Support JAM codec for bounded collections May 21, 2025
@davxy davxy requested a review from Copilot May 21, 2025 15:48
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR decouples the bounded collections’ codec implementation from a hard dependency on scale-codec by making the codec used optional with feature flags and adding support for jam-codec. Key changes include re-exporting scale-codec as codec in primitive-types, updating dependencies and Cargo.toml files, and refactoring codec implementations across bounded collections using conditional compilation macros.

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
primitive-types/impls/codec/src/lib.rs Re-exports scale-codec as codec to enable optional codec selection.
primitive-types/impls/codec/Cargo.toml Updates dependency references from codec to scale-codec.
bounded-collections/src/weak_bounded_vec.rs Removes unconditional codec impls and adds a macro-based conditional implementation for scale-codec and jam-codec.
bounded-collections/src/bounded_vec.rs Updates attribute derivations and refactors codec decoding via macros.
bounded-collections/src/bounded_btree_set.rs Refactors codec implementations using macros for both codec libraries.
bounded-collections/src/bounded_btree_map.rs Refactors codec implementations and removes deprecated helper structs for decoding.
bounded-collections/Cargo.toml Updates dependency definitions and versions to support jam-codec.
bounded-collections/CHANGELOG.md Adds a new changelog entry documenting the JAM codec support.
Cargo.toml Updates root dependency from codec to scale-codec.
Comments suppressed due to low confidence (1)

bounded-collections/src/bounded_btree_map.rs:429

  • [nitpick] Consider renaming the macro to a more specific name (e.g., 'bounded_btree_map_codec_impl') to enhance clarity and prevent potential name conflicts in larger modules.
macro_rules! codec_impl {

@davxy davxy requested review from arkpar, bkchr and zdave-parity May 22, 2025 06:44
Copy link
Copy Markdown
Member

@bkchr bkchr left a comment

Choose a reason for hiding this comment

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

Besides the dependency that should be moved, it looks good.

@davxy davxy requested a review from a team as a code owner May 26, 2025 10:29
@davxy davxy requested a review from alvicsam May 26, 2025 10:30
@davxy davxy merged commit f0dade1 into master May 26, 2025
6 checks passed
@davxy davxy deleted the support-jam-codec-for-bounded-collections branch May 26, 2025 10:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants