Conversation
There was a problem hiding this comment.
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
RlpTypeand a shareddetail::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_metadatain terms of the shared metadata parser.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| constexpr Result<std::pair<RlpType, byte_string_view>> | ||
| parse_metadata(byte_string_view &enc) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
…s decoded view and its type
bce1875 to
8fc860d
Compare
add unified RLP parse metadata function which returns decoded view and its type