Skip to content

fix: use hexutil.Uint64 for MorphTx version JSON encoding#292

Closed
panos-xyz wants to merge 30 commits intomainfrom
test_3_13
Closed

fix: use hexutil.Uint64 for MorphTx version JSON encoding#292
panos-xyz wants to merge 30 commits intomainfrom
test_3_13

Conversation

@panos-xyz
Copy link
Copy Markdown
Contributor

@panos-xyz panos-xyz commented Mar 2, 2026

Summary

  • Fix json: cannot unmarshal string into Go struct field rpcBlock.transactions.version of type uint8 error on non-sequencer (syncing) nodes
  • txJSON.Version was *uint8 (plain number in JSON) while RPCTransaction.Version in api.go uses *hexutil.Uint64 (hex string like "0x1")
  • Align txJSON.Version with the Ethereum JSON-RPC hex encoding convention, consistent with all other numeric fields (FeeTokenID, QueueIndex, etc.)

Root Cause

Non-sequencer nodes call eth_getBlockByNumber via ethclient.BlockByNumber to sync blocks. The RPC server serializes version as "0x1" (hexutil.Uint64), but types.Transaction.UnmarshalJSON used *uint8 which the standard JSON decoder cannot unmarshal from a hex string.

Sequencers were unaffected because they never go through the JSON RPC path for block production — they operate directly on in-memory Go structs via the Engine API.

Changes

  • core/types/transaction_marshalling.go: change txJSON.Version from *uint8 to *hexutil.Uint64, update marshal/unmarshal accordingly

Test plan

  • Run go test ./core/types/... -run "TestTransaction|TestMorph|TestMarshal|TestJSON"
  • Verify syncing node can call BlockByNumber on blocks containing MorphTx V1 transactions without error

Summary by CodeRabbit

Release Notes

  • New Features

    • MorphTx versioning system (V0/V1) supporting transaction metadata (Reference and Memo fields)
    • Reference-based transaction indexing for efficient lookups
    • GetTransactionHashesByReference RPC method for querying transactions by reference
    • AssembleL2BlockV2 method for flexible L2 block construction
  • Updates

    • Replaced AltFeeTx with MorphTx transaction type throughout
    • Jade Fork terminology replaces MPT Fork references
    • Extended transaction support with version, reference, and memo fields

segue and others added 30 commits January 4, 2026 15:05
…284)

Co-authored-by: fletcher.fan <fletcher.fan@bitget.com>
MorphTx enhance & implement reference key
concensus: pbft to single sequencer, include P2P & block produce

Co-authored-by: allen.wu <allen.wu@bitget.com>
txJSON.Version was *uint8 (plain number) while RPCTransaction.Version
uses *hexutil.Uint64 (hex string). This caused ethclient.BlockByNumber
to fail with "cannot unmarshal string into Go struct field
rpcBlock.transactions.version of type uint8" on non-sequencer nodes.

Align txJSON.Version with the Ethereum JSON-RPC convention by using
*hexutil.Uint64, consistent with all other numeric fields (FeeTokenID,
QueueIndex, etc.).
@panos-xyz panos-xyz requested a review from a team as a code owner March 2, 2026 10:55
@panos-xyz panos-xyz requested review from r3aker86 and removed request for a team March 2, 2026 10:55
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 2, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3b802aa and 9e26fa1.

📒 Files selected for processing (55)
  • accounts/abi/bind/backends/simulated.go
  • accounts/abi/bind/base.go
  • accounts/external/backend.go
  • cmd/evm/internal/t8ntool/execution.go
  • cmd/geth/chaincmd.go
  • cmd/geth/config.go
  • cmd/geth/main.go
  • cmd/utils/flags.go
  • common/types.go
  • core/block_validator.go
  • core/block_validator_test.go
  • core/blockchain.go
  • core/blockchain_test.go
  • core/genesis.go
  • core/mpt_fork_test.go
  • core/rawdb/accessors_chain.go
  • core/rawdb/accessors_reference_index.go
  • core/rawdb/reference_index_iterator.go
  • core/rawdb/schema.go
  • core/state_processor.go
  • core/state_transition.go
  • core/tx_list.go
  • core/tx_pool.go
  • core/tx_pool_test.go
  • core/types/alt_fee_tx.go
  • core/types/gen_receipt_json.go
  • core/types/l2trace.go
  • core/types/morph_tx.go
  • core/types/morph_tx_compat_test.go
  • core/types/receipt.go
  • core/types/receipt_test.go
  • core/types/transaction.go
  • core/types/transaction_marshalling.go
  • core/types/transaction_signing.go
  • core/types/transaction_test.go
  • eth/backend.go
  • eth/catalyst/l2_api.go
  • eth/ethconfig/config.go
  • ethclient/authclient/engine.go
  • ethclient/ethclient.go
  • graphql/graphql.go
  • interfaces.go
  • internal/ethapi/api.go
  • internal/ethapi/backend.go
  • internal/ethapi/transaction_args.go
  • les/client.go
  • les/odr_test.go
  • light/odr_test.go
  • light/txpool.go
  • params/config.go
  • rollup/fees/rollup_fee.go
  • rollup/tracing/tracing.go
  • rpc/types.go
  • signer/core/apitypes/types.go
  • tests/state_test_util.go

📝 Walkthrough

Walkthrough

This PR introduces MorphTx as a new versioned transaction type replacing AltFeeTx, adds a Reference metadata type for transaction indexing, renames MPTFork to JadeFork throughout, implements a reference index subsystem for transaction lookups, and extends receipts and RPC APIs to support versioned transaction metadata.

Changes

Cohort / File(s) Summary
Reference Type System
common/types.go
Introduces new 32-byte Reference type with comprehensive serialization support including Hex(), String(), JSON/Text marshaling, GraphQL interop, and database integration; mirrors existing Hash type pattern.
Fork Renaming (MPT → Jade)
cmd/geth/chaincmd.go, cmd/geth/config.go, cmd/geth/main.go, cmd/utils/flags.go, eth/backend.go, eth/ethconfig/config.go, core/genesis.go, params/config.go, core/block_validator.go, core/mpt_fork_test.go, les/client.go
Systematic replacement of OverrideMPTForkTimeFlag with OverrideJadeForkTimeFlag, MPTForkTime config fields with JadeForkTime, and IsMPTFork() method calls with IsJadeFork() across chain configuration, CLI flags, and validation logic.
MorphTx Type Definition
core/types/morph_tx.go, core/types/transaction.go
Introduces MorphTx transaction type with two-version format support (V0 legacy, V1 with metadata), replacing AltFeeTx; includes version-aware encoding/decoding, validation logic, and signature handling; adds accessor methods Version(), Reference(), Memo() on Transaction and Message types.
MorphTx Type Removal
core/types/alt_fee_tx.go
Removes entire AltFeeTx type definition and associated methods (copy, encoding/decoding, signature handling).
Transaction Binding & Construction
accounts/abi/bind/base.go, accounts/abi/bind/backends/simulated.go, accounts/external/backend.go, internal/ethapi/transaction_args.go
Adds Version, Reference, Memo fields to TransactOpts and CallMsg; introduces morphTxVersion validation method; renames createAltFeeTx to createMorphTx; implements isMorphTxArgs and validateMorphTxVersion helpers for transaction type selection and validation.
Receipt Storage & Encoding
core/types/receipt.go, core/types/gen_receipt_json.go, core/rawdb/accessors_chain.go
Extends Receipt struct with FeeTokenID, FeeRate, TokenScale, FeeLimit, Version, Reference, Memo fields; updates RLP encoding to v8StoredReceiptRLP format; modifies JSON marshaling to include new fields; handles backward compatibility with older storage formats.
Receipt Testing & Compatibility
core/types/receipt_test.go, core/types/morph_tx_compat_test.go
Adds comprehensive MorphTx receipt tests including storage encoding, backward compatibility, JSON marshaling; introduces V0/V1 round-trip tests with reference and memo validation; validates storage format migration paths.
Reference Index Subsystem
core/rawdb/accessors_reference_index.go, core/rawdb/reference_index_iterator.go, core/rawdb/schema.go
Implements reference-based index for MorphTx transactions; provides CRUD operations (WriteReferenceIndexEntry, DeleteReferenceIndexEntry), block-level batch operations, range queries with sorting; includes concurrent iteration and batched indexing/unindexing with progress tracking.
Blockchain Integration
core/blockchain.go, core/blockchain_test.go, core/block_validator.go
Adds maintainReferenceIndex background goroutine for reference index maintenance; integrates reference index writes into block insertion paths (writeHeadBlock, writeAncient, writeLive); adds reference index deletion during reorg cleanup; includes validation checks for MorphTxVersion1 activation (ErrMorphTxV1NotYetActive).
Transaction Pool & State Processing
core/tx_pool.go, core/tx_pool_test.go, core/state_processor.go, core/tx_list.go, core/state_transition.go
Updates TxPool with Jade fork state gating for MorphTx V1 validation; adds removeMorphTxV1 for pre-fork cleanup; replaces IsAltFeeTx() with IsMorphTxWithAltFee() checks; extends Message interface with Version/Reference/Memo accessors; adds version-gated receipt field population.
RPC & API Extensions
ethclient/ethclient.go, ethclient/authclient/engine.go, eth/catalyst/l2_api.go, internal/ethapi/api.go, internal/ethapi/backend.go, rpc/types.go
Introduces GetTransactionHashesByReference RPC method for reference-based lookups; adds AssembleL2BlockV2 for building blocks on arbitrary parents; introduces PublicMorphAPI with reference querying; extends RPCTransaction and Receipt serialization with new fields.
Transaction Marshaling & Signing
core/types/transaction_marshalling.go, core/types/transaction_signing.go, core/types/transaction_test.go
Updates JSON marshaling to handle MorphTxType; adds conditional V1+ field emission (Version, Reference, Memo); updates modern signer to recognize MorphTxType; includes extensive round-trip tests and backward compatibility validation.
Execution Tracing & Schema
cmd/evm/internal/t8ntool/execution.go, core/types/l2trace.go, rollup/tracing/tracing.go, rollup/fees/rollup_fee.go
Extends ExecutionResult and TransactionData with Version, Reference, Memo fields; updates receipt population to conditionally include MorphTx metadata based on version; adjusts token-bytecode collection logic for MorphTxType.
State Test Utilities & Signing
tests/state_test_util.go, signer/core/apitypes/types.go, les/odr_test.go, light/odr_test.go, light/txpool.go, graphql/graphql.go, interfaces.go
Extends stTransaction, SendTxArgs, and CallMsg with Version/Reference/Memo fields; updates message construction to propagate new fields; replaces AltFeeTxType with MorphTxType in GraphQL handlers; updates ODR test message construction.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant TransactionArgs
    participant BlockChain
    participant TxPool
    participant StateProcessor
    participant ReferenceIndex

    Note over Client,ReferenceIndex: MorphTx V1 with Reference Creation & Indexing

    Client->>TransactionArgs: Submit TX with Version=V1, Reference=ref
    TransactionArgs->>TransactionArgs: isMorphTxArgs() check
    TransactionArgs->>TransactionArgs: validateMorphTxVersion()
    TransactionArgs->>TransactionArgs: toTransaction() → MorphTx creation
    TransactionArgs->>TxPool: Add MorphTx V1

    TxPool->>TxPool: Check Jade fork active
    TxPool->>TxPool: ValidateMorphTxVersion()
    TxPool->>TxPool: Accept into pool

    BlockChain->>BlockChain: InsertChain()
    BlockChain->>StateProcessor: Process TX
    StateProcessor->>StateProcessor: Populate receipt fields (Version, Reference, Memo)
    StateProcessor->>BlockChain: Return receipt

    BlockChain->>ReferenceIndex: WriteReferenceIndexEntriesForBlock()
    ReferenceIndex->>ReferenceIndex: Extract MorphTx references
    ReferenceIndex->>ReferenceIndex: Construct index keys (ref + timestamp + txIndex)
    ReferenceIndex->>ReferenceIndex: Persist to database

    BlockChain->>BlockChain: maintainReferenceIndex() background
    BlockChain->>ReferenceIndex: Manage tail, prune old entries
Loading
sequenceDiagram
    participant RPC Client
    participant ethclient
    participant PublicMorphAPI
    participant rawdb
    participant Database

    Note over RPC Client,Database: Reference-Based Transaction Query Flow

    RPC Client->>ethclient: GetTransactionHashesByReference(ref, offset, limit)
    ethclient->>ethclient: Construct ReferenceQueryArgs
    ethclient->>PublicMorphAPI: Call morph_getTransactionHashesByReference
    PublicMorphAPI->>rawdb: ReadReferenceIndexEntries(reference)
    rawdb->>Database: Iterate reference index by prefix
    Database-->>rawdb: Return sorted entries (blockTimestamp, txIndex, txHash)
    rawdb->>PublicMorphAPI: []ReferenceIndexEntry
    PublicMorphAPI->>PublicMorphAPI: Apply offset/limit pagination
    PublicMorphAPI-->>RPC Client: []ReferenceTransactionResult
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • Fix receipt rlp #247 — Modifies storedReceiptRLP encoding in core/rawdb/accessors_chain.go with receipt field extensions, directly overlapping with this PR's receipt storage format changes.
  • feat: change zktrie to mpt #257 — Updates fork-time configuration machinery (MPTForkTime/JadeForkTime, flag naming, and validation logic), with systematic overlap across chain config and CLI flag handling.
  • Add hexutil Uint16 #253 — Introduces hexutil.Uint16 type for FeeTokenID serialization and modifies transaction type encoding in multiple files, sharing code-level changes with this PR's transaction type system updates.

Suggested reviewers

  • r3aker86
  • FletcherMan

Poem

🐰 A morph-y transaction hops into view,
With reference and version, so shiny and new,
The jade fork arrives with metadata in tow,
Jade indexing leads where transactions flow,
From alt-fees to morph, the rabbit's work's through! 🎉

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch test_3_13

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.5.0)

Error: can't load config: unsupported version of the configuration: "" See https://golangci-lint.run/docs/product/migration-guide for migration instructions
The command is terminated due to an error: can't load config: unsupported version of the configuration: "" See https://golangci-lint.run/docs/product/migration-guide for migration instructions


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@panos-xyz panos-xyz closed this Mar 2, 2026
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