Skip to content

refactor: encode MorphTx version as prefix byte instead of RLP field#284

Merged
FletcherMan merged 1 commit intoref_keyfrom
morph-tx-encoding-optimize
Jan 30, 2026
Merged

refactor: encode MorphTx version as prefix byte instead of RLP field#284
FletcherMan merged 1 commit intoref_keyfrom
morph-tx-encoding-optimize

Conversation

@FletcherMan
Copy link
Copy Markdown
Collaborator

1. Purpose or design rationale of this PR

Optimizes MorphTx encoding by moving the Version field outside of the RLP structure and encoding it as a prefix byte, similar to how Transaction.Type is handled.

Changes

Encoding Format

  • V0 (legacy): 0x7F + RLP([chainID, nonce, ..., feeLimit, v, r, s])
    • Maintains full backward compatibility with existing AltFeeTx data
    • First inner byte is RLP list prefix (>= 0xC0)
  • V1 (new): 0x7F + 0x01 + RLP([chainID, nonce, ..., feeLimit, reference, memo, v, r, s])
    • Version byte (0x01) precedes the RLP data
    • Enables future version upgrades without RLP structure changes

Version Detection Logic

firstByte == 0x00 || firstByte >= 0xC0 → V0 format (legacy)
firstByte == 0x01                      → V1 format
other                                  → unsupported version error 

Files Changed

  • core/types/morph_tx.go - Updated encode()/decode() logic
  • core/types/morph_tx_compat_test.go - New compatibility test file

2. PR title

Your PR title must follow conventional commits (as we are doing squash merge for each PR), so it must start with one of the following types:

  • build: Changes that affect the build system or external dependencies (example scopes: yarn, eslint, typescript)
  • ci: Changes to our CI configuration files and scripts (example scopes: vercel, github, cypress)
  • docs: Documentation-only changes
  • feat: A new feature
  • fix: A bug fix
  • perf: A code change that improves performance
  • refactor: A code change that doesn't fix a bug, or add a feature, or improves performance
  • style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
  • test: Adding missing tests or correcting existing tests

3. Deployment tag versioning

Has the version in params/version.go been updated?

  • This PR doesn't involve a new deployment, git tag, docker image tag, and it doesn't affect traces
  • Yes

4. Breaking change label

Does this PR have the breaking-change label?

  • This PR is not a breaking change
  • Yes

@FletcherMan FletcherMan requested a review from a team as a code owner January 30, 2026 09:06
@FletcherMan FletcherMan requested review from tomatoishealthy and removed request for a team January 30, 2026 09:06
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jan 30, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

  • 🔍 Trigger a full review
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch morph-tx-encoding-optimize

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.

@FletcherMan FletcherMan merged commit 846ff39 into ref_key Jan 30, 2026
1 check passed
@FletcherMan FletcherMan deleted the morph-tx-encoding-optimize branch January 30, 2026 09:40
FletcherMan added a commit that referenced this pull request Mar 6, 2026
* update morph tx

* add reference

* update

* update

* add test

* fix sth

* add check and test

* add  test

* refactor: encode MorphTx version as prefix byte instead of RLP field (#284)

Co-authored-by: fletcher.fan <fletcher.fan@bitget.com>

* fix  decode morphtx & receipt

* fix get transaction hashes by reference

* update args

* fix args checks

* fix version check

* some improve

* add args check

* update

* update

* update to jade

* active after jade fork time

* check geth version

* fix sth

* fix reference validate

* fix memo validate

* fix tx filter

* fix rpc and ref index

* fix

* fix version

* add validate

* update returns receipt & result

* fix: use hexutil.Uint64 for MorphTx version JSON encoding (#293)

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.).

* fix hash

* add version check and test

---------

Co-authored-by: segue <“huoda.china@gmail.com”>
Co-authored-by: FletcherMan <fletcherman0709@gmail.com>
Co-authored-by: fletcher.fan <fletcher.fan@bitget.com>
Co-authored-by: panos <pan107104@outlook.com>
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.

2 participants