Skip to content

Reorg rlp parse*_metadata functions#2222

Open
goodlyrottenapple wants to merge 1 commit intomainfrom
sam/rlp_nibbles_reorg
Open

Reorg rlp parse*_metadata functions#2222
goodlyrottenapple wants to merge 1 commit intomainfrom
sam/rlp_nibbles_reorg

Conversation

@goodlyrottenapple
Copy link
Copy Markdown
Contributor

add unified RLP parse metadata function which returns decoded view and its type

Copilot AI review requested due to automatic review settings April 21, 2026 17:00
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 refactors the Ethereum RLP decoder’s parse*_metadata helpers by introducing a unified parse_metadata() API that returns both the decoded payload view and whether the next RLP item is a string or a list.

Changes:

  • Added RlpType and a shared detail::parse_metadata_raw() routine to parse RLP item headers for both strings and lists.
  • Introduced parse_metadata(byte_string_view&) -> Result<std::pair<RlpType, byte_string_view>>.
  • Reimplemented parse_string_metadata / parse_list_metadata in terms of the shared metadata parser.

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

Comment on lines +131 to +132
constexpr Result<std::pair<RlpType, byte_string_view>>
parse_metadata(byte_string_view &enc)
Copy link

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

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

parse_metadata() returns a std::pair<RlpType, byte_string_view>, which forces callers to use .first/.second and makes it easy to accidentally swap or misread the fields. Consider returning a small named struct (e.g., {RlpType type; byte_string_view payload;}) or a dedicated alias/type to make the API self-documenting.

Copilot uses AI. Check for mistakes.
Comment thread category/execution/ethereum/rlp/decode.hpp
Comment thread category/execution/ethereum/rlp/decode.hpp
Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

The refactor unifies parse_string_metadata and parse_list_metadata through a shared detail::parse_metadata_raw helper and adds a new parse_metadata entrypoint. I walked through every branch against the previous implementation and the semantics are preserved exactly: i, length, end and the i + length_of_length >= enc.size() / end > enc.size() || end < i bounds checks all match the pre-refactor behavior, the empty check has simply migrated from the old body into the three public entry points (all three check enc.empty() before calling parse_metadata_raw, so the unconditional enc[0] read is safe), and the [[gnu::always_inline]] should let the compiler fold the unreachable list/string branch out at each specialized call site. The new parse_metadata is exercised by the follow-up PR #2170 (partial_trie_db.cpp, execution_witness.cpp), so it isn't dead code. Existing RLP decode tests continue to cover the two specialized callers unchanged. Single commit, rebased, format / clang-tidy / trait-instantiation checks are green.

Verdict: CORRECT

🤖 Generated with Claude Code

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