Repository navigation
fix(chainlib): a batch mixing a latest read with block 0 asks about latest, not block 0 (MAG-4346) - #593
Merged
Conversation
…atest, not block 0 (MAG-4346) CompareRequestedBlockInBatch's two mixed-sign branches tested currentLatest > 0 and parsedBlock > 0, so block 0 fell through to Max. Every "latest"-style tag is a negative sentinel, and Max(LATEST, 0) is 0: a batch of eth_getBalance(a, "latest") with eth_getBalance(a, "0x0") reported requested block 0, in either order. With 0x64 in place of 0x0 the same batch reports LATEST. The cache then filed the batch as finalized block 0, which lives for the finalized lifetime rather than the temporary one, so the batch's "latest" balance was served long after it changed. The same latest read sent alone is filed under the tip and expires with the temporary TTL. Block 0 is a numeric block like any other on this side, so both branches now test >= 0. The patch is Anna Rayer's, attached to the ticket. The earliest side is deliberately unchanged. This function's earliest return is discarded by its only production caller — requestedBlockFold.add folds earliest itself — and the JSON-RPC batch path maps an element at block 0 to EARLIEST_BLOCK before that fold, so block 0 never reaches it as 0 from a batch. Tests: Anna's TestJsonRpcBatchMixingLatestWithBlockZeroIsNotCachedAsFinalized, which writes the batch through tryCacheWrite against a real cache server and checks it expires with the temporary TTL and is not filed under finalized block 0. Her four TestCompareRequestedBlockInBatch rows, plus the pending, safe and finalized tags in both orders and block 0 beside an element that failed to parse. Ten rows and the cache test fail on main. Same family as MAG-4650 and MAG-4381, which change the same fold for a block-less element: a batch cached under a block that does not cover all its calls. Those two are Anna's and are not in this change; this one touches only the mixed-sign comparison, not whether an element takes part in the fold. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
AnnaR-prog
reviewed
Nov 3, 2026
AnnaR-prog
left a comment
Contributor
There was a problem hiding this comment.
Reviewed at 269059e. I tested it merged with current main 7c1102e.
The change is correct.
- I diffed main's
CompareRequestedBlockInBatchagainst this one over every pair of NA, LATEST, EARLIEST, PENDING, SAFE, FINALIZED, 0, 1 and 100. Exactly ten pairs change: block 0 with NA, LATEST, PENDING, SAFE or FINALIZED, in both orders. Every pair with EARLIEST is unchanged, and[NA, 0]now gives NA, as[NA, 100]already did. - The only production caller is
requestedBlockFold.add. It drops this function's earliest return, andCombineEarliestRequestedBlockis not touched, so the earliest block and the archive decision do not change. On the ETH1 fixture,[latest, 0x0],[0x0, latest]and[0x0, pending|safe|finalized]still go to archive. - The change also reaches Tendermint batches:
[block "0", abci_info]was (0, LATEST) and is now (LATEST, LATEST), so that batch is no longer filed as finalized block 0 either. Batches of0x0with pending, safe or finalized are now not cached at all (the unresolved-tag guard skips them), where main cached them as finalized block 0. - With main's
common.gooverlaid, ten table rows andTestJsonRpcBatchMixingLatestWithBlockZeroIsNotCachedAsFinalizedfail. They pass on this head, also with-race.go test ./protocol/chainlib/...and the batch/cache tests inprotocol/rpcsmartrouterpass on the merged tree, and lint reports nothing new.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
AnnaR-prog
approved these changes
Nov 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
A JSON-RPC batch that mixes a
latestread with a block0x0read reported requested block 0, so the cache filed it as finalized block 0 and served its latest answer for the finalized lifetime.Jira ticket: MAG-4346
Independent of the other open tickets in this batch; it can merge in any order.
Summary
CompareRequestedBlockInBatch's two mixed-sign branches testedcurrentLatest > 0andparsedBlock > 0, so block 0 fell through toMax. Every latest-style tag is a negative sentinel, andMax(LATEST, 0)is 0 — in either element order. With0x64in place of0x0the same batch reports LATEST.The cache then filed the batch as finalized block 0, which lives for the finalized lifetime rather than the temporary one, so the batch's
latestbalance was served long after it had changed. The samelatestread sent alone is filed under the tip and expires with the temporary TTL.Block 0 is a numeric block like any other on this side, so both branches now test
>= 0. The one-line patch is Anna Rayer's, attached to the ticket.The earliest side is deliberately unchanged, and it is worth knowing why rather than reading it as an oversight: this function's earliest return is discarded by its only production caller (
requestedBlockFold.addfolds earliest itself), and the JSON-RPC batch path maps an element at block 0 toEARLIEST_BLOCKbefore that fold. So block 0 never reaches the earliest fold as 0 from a batch. The new table rows assert the function's own earliest values, with a comment saying they are not what a batch comes out as.Relationship to MAG-4650 and MAG-4381
Same family, same file: a batch cached under a block that does not cover all its calls. Those two change whether a block-less element takes part in the fold — MAG-4381 made "latest + none" cacheable, MAG-4650 is the regression that produced for an element whose answer changes. Both are Anna's and neither is in this change, which touches only the mixed-sign comparison. The two sets do not overlap in code, but they do overlap in intent, so whoever lands those should read this one first.
Test plan
TestJsonRpcBatchMixingLatestWithBlockZeroIsNotCachedAsFinalized— Anna's attached test, which writes the batch throughtryCacheWriteagainst a real cache server, then checks it expires with the temporary TTL and that nothing is filed under finalized block 0. Renamed from the attached file's hyphenated name to the package convention.TestCompareRequestedBlockInBatch— Anna's four rows, plus the pending, safe and finalized tags in both element orders, and block 0 beside an element that failed to parse (which must still leave the whole request unjudgeable).main, verified withgo test -overlayagainstorigin/main's copy ofcommon.go.go test -count=1onprotocol/chainlib(6s),protocol/rpcsmartrouter(253s),protocol/relaycoreandprotocol/relaypolicyon the committed tree: all ok.protocol/chainlibalso passes under-raceon the committed tree.go build -buildvcs=false ./...andgo veton the committed tree.CI runs no unit tests on this repo, so the local runs above are the only test evidence.
🤖 Generated with Claude Code