Skip to content

Eth and Snap message improvements#10130

Draft
pinges wants to merge 13 commits intobesu-eth:mainfrom
pinges:snapImprovement
Draft

Eth and Snap message improvements#10130
pinges wants to merge 13 commits intobesu-eth:mainfrom
pinges:snapImprovement

Conversation

@pinges
Copy link
Copy Markdown
Contributor

@pinges pinges commented Mar 30, 2026

PR description

Snap/eth message zero-copy encoding and memory-safe decoding improvements

Description

Summary

  • Zero-copy RLP message wrapping/unwrapping for both eth and snap protocol messages
  • Public RLP.listHeader() and RLP.listHeaderSize() utility methods to eliminate duplicated RLP
    logic
  • Removed redundant requestId encoding from BlockAccessList messages

Zero-copy message wrapping

Replaced data-copying implementations of wrapMessageData / unwrapMessageData with zero-copy
splicing using Bytes.wrap() and Bytes.slice():

  • MessageData (eth protocol default): The previous implementation used
    BytesValueRLPOutput.writeRaw() to wrap and Bytes.concatenate() to unwrap, copying the entire
    message payload each time. The new implementation uses Bytes.wrap(header, reqIdBytes, data)
    for wrapping and Bytes.slice() for unwrapping — no copies.
  • AbstractSnapMessageData (snap protocol): Already had a zero-copy wrap(), but it contained a
    hand-rolled rlpListHeader() and inline header-size calculation. Both now delegate to the new
    RLP utility methods.

RLP public API additions

Added two utility methods to org.hyperledger.besu.ethereum.rlp.RLP:

  • listHeader(int payloadSize) — returns the RLP list header bytes for a given content length.
    Delegates to the existing internal RLPEncodingHelpers.writeListHeader().
  • listHeaderSize(Bytes encoded) — returns the header size of an already-encoded RLP list by
    inspecting the prefix byte.

These replace duplicated RLP header logic that was previously inlined in
AbstractSnapMessageData.

BlockAccessList message cleanup

Removed the Optional requestId parameter from BlockAccessListsMessageData.encode()
and GetBlockAccessListsMessageData.encode(). These messages now encode without a requestId,
consistent with all other snap messages, and rely on AbstractSnapMessageData.wrapMessageData()
to splice it in when needed.

GetTrieNodes improvements

Added per-path size validation (MAX_PATH_SIZE = 33) and a total path cap (MAX_TOTAL_PATHS =
1024) to GetTrieNodesMessage.paths() decoding.

@pinges pinges changed the title Snap improvement Eth and Snap message improvements Mar 30, 2026
pinges added 11 commits March 31, 2026 16:18
Signed-off-by: stefan.pingel@consensys.net <stefan.pingel@consensys.net>
Signed-off-by: stefan.pingel@consensys.net <stefan.pingel@consensys.net>
Signed-off-by: stefan.pingel@consensys.net <stefan.pingel@consensys.net>
Signed-off-by: stefan.pingel@consensys.net <stefan.pingel@consensys.net>
Signed-off-by: stefan.pingel@consensys.net <stefan.pingel@consensys.net>
Signed-off-by: stefan.pingel@consensys.net <stefan.pingel@consensys.net>
Signed-off-by: stefan.pingel@consensys.net <stefan.pingel@consensys.net>
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.

1 participant