You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit eea0b48
Browse filesBrowse the repository at this point in the historyBrowse files
fix(query): fix off-by-one when iteration budget exhausts at offset (#4629)
Untrusted unfiltered offset queries were rejected with `InvalidArgument`
("scanned more than N entries before reaching offset") when
`max-iterations` equalled the requested offset, even though the offset
had been fully skipped at that point. The correct response is an empty
page whose `next_key` resumes at the first entry of the page. Defaults
cannot reach this (`max-iterations` 11000 > `max-offset` 10000), and
`ValidateQueryConfig` already warns about such configs, so it needs an
operator who ignores that warning. Follow-up to #3984 review; fixes
PLT-1485.
The cause is that `offsetScanCursor.phase()` meant different things at
its two call sites. The loop body calls it after `beginIteration`
increments `scanned`, where `scanned <= offset` correctly means "this
entry is skipped". The budget-exhaust check in `beginIteration` calls it
before the increment, where the same predicate is off by one. Rather
than overload `phase()` further, the exhaust check now uses a new
`offsetConsumed()` predicate, so `phase()` keeps a single meaning. The
filtered path is unaffected: `offsetConsumed()` reduces to the existing
`hits < offset` check there.
No consensus, state, or wire-format impact; this only changes the
response to a narrow class of ABCI queries from an error to a valid
page.
`TestUntrustedQueryUnfilteredBudgetExhaustAtOffsetReturnsResumeKey`
covers the boundary and its resume, and fails without the fix. The
existing
`TestUntrustedQueryRejectsBudgetExhaustBeforeOffset{Filtered,Unfiltered}`
tests pass unchanged.
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
0 commit comments