Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

refactor(core): replace ResourceBounds map with a fixed-field struct#3819

Open
Ehsan-saradar wants to merge 2 commits into
NethermindEth:mainNethermindEth/juno:mainfrom
Ehsan-saradar:refactor/3742-resource-bounds-structEhsan-saradar/juno:refactor/3742-resource-bounds-structCopy head branch name to clipboard
Open

refactor(core): replace ResourceBounds map with a fixed-field struct#3819
Ehsan-saradar wants to merge 2 commits into
NethermindEth:mainNethermindEth/juno:mainfrom
Ehsan-saradar:refactor/3742-resource-bounds-structEhsan-saradar/juno:refactor/3742-resource-bounds-structCopy head branch name to clipboard

Conversation

@Ehsan-saradar

Copy link
Copy Markdown
Contributor

Closes #3742

Both core and starknet resource bounds were modeled as map[Resource]ResourceBounds. Since the keys are effectively fixed, this replaces them with a struct with explicit L1Gas / L2Gas / L1DataGas fields — clearer, and it drops a map allocation per transaction.

Approach

  • New core.ResourceBoundsMap struct (L1Gas / L2Gas / L1DataGas) replacing the map[Resource]ResourceBounds field on the v3 transaction types, and the same for the feeder starknet type.
  • No DB migration. The struct implements MarshalCBOR / UnmarshalCBOR that keep the exact legacy map[Resource]ResourceBounds wire format. A golden test pins byte-for-byte equality across the three historical shapes — all three resources, the pre-0.13.4 two-resource form (no l1_data_gas), and the nil map on v0–v2 — so already-stored bytes still decode into the struct.
  • Hashes unchanged. l1_data_gas only enters the tip/resources hash when it's actually set (non-nil MaxPricePerUnit), which reproduces the old map-key check, so pre-0.13.4 tx hashes stay identical.
  • Feeder JSON unchanged. The starknet struct keeps the uppercase L1_GAS / L2_GAS / L1_DATA_GAS keys and uses omitzero, so an absent l1_data_gas round-trips both ways.
  • Left the vm resource-bounds map as-is — it's the marshal-only Blockifier payload (with the short L1_DATA key), out of scope for this one.

Testing

  • make lint — pass
  • Tests for all affected packages (core, starknet, adapters/..., rpc/..., vm, genesis, consensus, clients/feeder) — pass, including the new backward-compat golden tests in core/resource_bounds_test.go and starknet/resource_bounds_test.go.

@Ehsan-saradar
Ehsan-saradar force-pushed the refactor/3742-resource-bounds-struct branch from 3073074 to ce1cc64 Compare July 16, 2026 07:00
Swap map[Resource]ResourceBounds on the v3 transaction types for a
ResourceBoundsMap struct with explicit L1Gas/L2Gas/L1DataGas fields, which is
clearer and avoids a map allocation per transaction.

To keep already-stored transactions readable without a DB migration, the type
implements MarshalCBOR/UnmarshalCBOR that reproduce the exact legacy
map[Resource]ResourceBounds wire format. l1_data_gas still only enters the
transaction hash when present (non-nil MaxPricePerUnit), matching the old
map-key check, so historical tx hashes are unchanged.
Replace *map[Resource]ResourceBounds on the feeder starknet.Transaction with a
ResourceBoundsMap struct. JSON tags keep the uppercase L1_GAS/L2_GAS/L1_DATA_GAS
feeder keys, and omitzero preserves the pre-0.13.4 shape where l1_data_gas is
absent, so both add_transaction requests and decoded feeder responses
round-trip unchanged. sn2core and the rpc feeder adapters consume the struct
directly instead of iterating a map.
@Ehsan-saradar
Ehsan-saradar force-pushed the refactor/3742-resource-bounds-struct branch from ce1cc64 to 16f2075 Compare July 25, 2026 05:39
Copilot AI review requested due to automatic review settings July 25, 2026 05:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 refactors v3 transaction resource-bounds representation in both core and starknet from map[Resource]ResourceBounds to fixed-field structs (L1Gas / L2Gas / L1DataGas) to improve clarity and remove per-transaction map allocations, while preserving legacy encodings and hash behavior for backward compatibility.

Changes:

  • Introduces core.ResourceBoundsMap with CBOR marshal/unmarshal that preserves the legacy on-disk map[Resource]ResourceBounds encoding, plus tests that pin byte-for-byte compatibility and hashing presence rules.
  • Introduces starknet.ResourceBoundsMap for feeder JSON with uppercase keys and omission behavior for absent l1_data_gas, plus JSON round-trip tests.
  • Updates adapters/RPC/VM/genesis/test utilities to use the new struct-based bounds representation end-to-end.

Reviewed changes

Copilot reviewed 27 out of 27 changed files in this pull request and generated no comments.

Show a summary per file
File Description
vm/transaction.go Adapts core.ResourceBoundsMap into the VM payload map, conditionally including l1_data_gas.
starknet/transaction.go Adds feeder-facing ResourceBoundsMap struct and updates Transaction.ResourceBounds type accordingly.
starknet/resource_bounds_test.go Adds JSON round-trip tests to preserve feeder wire format, including pre-0.13.4 omission behavior.
rpc/v9/transaction.go Migrates v9 RPC adaptation and feeder conversion paths to the new bounds struct types.
rpc/v9/transaction_test.go Updates v9 transaction tests to construct core.ResourceBoundsMap literals.
rpc/v9/block_test.go Updates v9 block tests to reference fixed fields instead of map indexing.
rpc/v8/transaction.go Migrates v8 RPC adaptation and feeder conversion paths to the new bounds struct types.
rpc/v8/transaction_test.go Updates v8 transaction tests to construct core.ResourceBoundsMap literals.
rpc/v8/subscriptions_test.go Updates v8 subscription tests to use core.ResourceBoundsMap.
rpc/v8/block_test.go Updates v8 block tests to reference fixed fields instead of map indexing.
rpc/v10/transaction_test.go Updates v10 tests to construct core.ResourceBoundsMap literals.
rpc/v10/subscriptions_test.go Updates v10 subscription tests to use core.ResourceBoundsMap.
rpc/v10/block_test.go Updates v10 block tests to reference fixed fields instead of map indexing.
rpc/v10/adapt_transaction.go Updates v10 core↔RPC↔feeder adaptation to use struct resource bounds.
genesis/genesis.go Updates genesis transaction adaptation to produce core.ResourceBoundsMap.
core/transaction.go Introduces core.ResourceBoundsMap, preserves CBOR wire format, and updates hashing to use fixed fields with presence semantics.
core/resource_bounds_test.go Adds CBOR golden compatibility tests and hash presence-guard tests for l1_data_gas.
consensus/proposer/proposer_test.go Updates proposer test transaction construction to use core.ResourceBoundsMap.
consensus/p2p/validator/transition_test.go Updates validator transition tests to use core.ResourceBoundsMap.
clients/feeder/feeder_test.go Updates feeder client tests to expect *starknet.ResourceBoundsMap instead of a map pointer.
adapters/testutils/transaction_test_utils.go Updates test utilities to return core.ResourceBoundsMap instead of a map.
adapters/testutils/synctransaction_test_utils.go Updates sync transaction builders to use zero-valued core.ResourceBoundsMap{} for pre-v3 transactions.
adapters/sn2core/sn2core.go Updates feeder→core adaptation to build core.ResourceBoundsMap and preserve absence semantics.
adapters/sn2core/sn2core_test.go Updates adapter tests to use core.ResourceBoundsMap.
adapters/p2p2core/transaction.go Updates p2p→core transaction adaptation to populate core.ResourceBoundsMap.
adapters/core2p2p/transaction.go Updates core→p2p transaction adaptation to read from core.ResourceBoundsMap fields.
.golangci.yaml Excludes core.ResourceBounds / core.ResourceBoundsMap from exhaustruct checks due to meaningful zero values.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

core: replace ResourceBounds map[Resource]ResourceBounds with a fixed-field struct

2 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.