Repository navigation
Conversation
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 59 minutes. View limit details
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
4310548 to
9d9524b
Compare
…um#22841 Every GetBlockHeaders request copied its origin into a temporary RLP value and decoded that copy a second time. Decoding straight from the stream drops one copy and one decoder pass per request, and propagates the error from Kind instead of discarding it. The old decoder also wrote only the field it selected. Reusing a HashOrNumber across decodes left the other field set, so EncodeRLP could reject the packet with "both origin hash and number provided" and the header handler could mix a stale number into a hash lookup. Clearing the unused field restores the union's exclusivity. The existing round-trip test passes with the old decoder, so it cannot cover either clearing case. The new table test turns red when the implementation is reverted, covering both origins, an invalid size and an empty input. Ref: ethereum#22841
9d9524b to
7f44e03
Compare
Summary
HashOrNumber.DecodeRLPdecodes the origin of everyGetBlockHeadersrequest. This ports theeth/protocols/ethhalf of geth ethereum#22841 (c0e201b69), which is still the decoder on geth master78af8c312— unchanged through eth/67–71, delayed p2p decoding (ethereum#33835) and the removal ofles(ethereum#28586).The upstream
les/protocol.gohalf does not apply: this tree has nolespackage, and upstream removed light client code in ethereum#28586. The port is 12 lines in one file; theHashOrNumbertype,EncodeRLP, imports and the xdc/166 request-id wrapper are untouched, so the wire format, peer negotiation, consensus state and RPC surface do not change.Evidence
s.Raw()and decodes it a second time withrlp.DecodeBytes; a temporary benchmark over hash and number origins measured144.6–146.1 ns/op,100 B/op,4 allocs/op. The existingTestGetBlockHeadersDataEncodeDecoderound-trip test passes with the old decoder.After:
95.6–96.5 ns/op,72 B/op,2 allocs/opon the same probe (removed afterwards; not part of this PR).DecodeRLPto the old implementation leaves the existing round-trip test green but turns the two new clearing cases red:TestHashOrNumberDecodeRLPadds four cases: number/hash decode into a reused value, an invalid 9-byte origin and empty input. The clearing is defensive in production —handler.gocreates a zero-value query per request — but it restores the union's exclusivity for reused values, soEncodeRLPcannot reject a packet as "both origin hash and number provided" and a hash lookup cannot carry a stale number.git show c0e201b69 -- eth/protocols/eth/protocol.gomatches this diff line for line (only the hunk line number and the surrounding baseline comment differ).git log -S 'hn.Number = 0' -- eth/protocols/eth/protocol.goon local geth master returns only eth/protocols/eth, les: avoid Raw() when decoding HashOrNumber ethereum/go-ethereum#22841, so this is the stable upstream end state and will not be undone by later protocol ports.make all,make generate,make tidy, clean tree,make lint(0 issues),go vet ./...,make testall pass in a detached/tmpworktree at this commit (log/tmp/verify-logs/port-hashornumber-decode-c569e7736c-VwTxpb.log).Merge Danger
Door: two-way — 12 lines in one function, no wire, state or API change; reverting restores the old decoder exactly.
Blast Radius: narrow. Only
eth/protocols/ethheader-request decoding is affected.handler.gobuilds a fresh zero-value query per request, and clearing the unused field can only remove stale data that the old decoder would have retained; successful decodes produce the same hash or number as before.Proposed changes
Port geth ethereum#22841's
HashOrNumber.DecodeRLPto decode the origin directly from the RLP stream instead of copying the raw value. One production function changes (+12/-12), plus a focused table test (+43). Theleshalf of the upstream change is not applicable to this tree.Types of changes
What types of changes does your code introduce to XDC network?
Put an
✅in the boxes that applyImpacted Components
Which parts of the codebase does this PR touch?
Put an
✅in the boxes that applyeth/protocols/ethonly (the eth protocol RLP decoder), with no consensus, account, contract or RPC surface.Checklist
Put an
✅in the boxes once you have confirmed below actions (or provide reasons on not doing so) thatTestGetBlockHeadersDataEncodeDecoderound-trips both hash and number origins through the new decoder, and the xdc/164–166 packet shapes are untouched.Unchecked items: this is an internal RLP decoding path with no wire format, negotiation, consensus, state or RPC change, so a genesis/epoch private-network run and a mixed-version coexistence run cannot exercise anything beyond the round-trip and table tests above; no documentation describes this decoder.
End-to-end test plan: bring up two nodes on a private network (
Local_DPoS_Setup), one with this build and one with the previous build, and confirm header sync converges while requesting headers by both number and hash (aGetBlockHeadersorigin of314and of a known block hash). Confirm both peers stay connected and return identical header sets; no new RPC or observable behavior is introduced.Ref: ethereum#22841
Summary by CodeRabbit