core: reject stateless blocks on incomplete state or code - #2401
Draft
lucca30 wants to merge 1 commit into
Draft
Conversation
…king it A WIT2 stateless node reads contract code from local disk (witnesses carry no code). When a called contract's bytecode is absent — a bytecode-heal / fast-forward completeness gap — StateDB records a sticky error and nil-serves the read, so execution continues against phantom-zero state. ExecuteStateless never consulted db.Error(), so the miss surfaced only as a misleading ErrGasUsedMismatch (or, when the divergent execution then hit "gas limit reached", as that Process error), masquerading as consensus divergence. Check db.Error() in ExecuteStateless immediately after Process and prefer it over any Process error, returning ErrStatelessIncompleteState wrapping the missing hash. A state-read failure invalidates the computed result, so this is the true cause regardless of which downstream symptom fires first. Add a chain/stateless/incomplete_state meter so a real occurrence is visible fleet-wide. The test-only serial replay (executeStatelessSerial) already gated on db.Error(); this makes the production path do the same. Test drives the real ExecuteStateless over a mainnet witness fixture, removes each contract code the block reads, and asserts ErrStatelessIncompleteState naming the hash — never a gas mismatch, a Process symptom, or a silent pass.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #2401 +/- ##
========================================
Coverage 55.59% 55.60%
========================================
Files 918 918
Lines 167145 167167 +22
========================================
+ Hits 92926 92950 +24
- Misses 68740 68747 +7
+ Partials 5479 5470 -9
... and 24 files with indirect coverage changes
🚀 New features to boost your workflow:
|
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.
Problem
A WIT2 stateless node reads contract code from its local disk — witnesses
carry no code. When a called contract's bytecode is absent (a bytecode-heal /
fast-forward completeness gap),
StateDBrecords a sticky error and serves theread as phantom-zero, so execution silently continues against wrong state.
ExecuteStatelessnever consulteddb.Error(), so the miss surfaced only as amisleading
ErrGasUsedMismatch— or, when the divergent execution then hit"gas limit reached", as that
Processerror — masquerading as consensusdivergence.
Observed on mainnet-soak: block
93472327diverged (gasUsed46,716,714vs47,007,392) because code0xf98d41f7…e56e64was missing from local disk. Thetrue cause was invisible in the logs.
Fix
Check
db.Error()inExecuteStatelessimmediately afterProcess, beforethe
Process-error branch — a failed state read invalidates the computedresult, so it is the true cause regardless of which downstream symptom fires
first. On a hit, return a new
ErrStatelessIncompleteStatesentinel wrapping theunderlying error, and bump a
chain/stateless/incomplete_statemeter so a realoccurrence is visible fleet-wide.
The test-only serial replay (
executeStatelessSerial) already gated ondb.Error(); this brings the production path in line.Test
TestExecuteStatelessRejectsMissingCodedrives the realExecuteStatelessovera mainnet witness fixture, removes each contract code the block reads, and
asserts
ErrStatelessIncompleteStatenaming the hash — never a gas mismatch, aProcesssymptom, or a silent pass. Writing it caught a real ordering bug inthe fix: a missing code first surfaced as "gas limit reached" from
Process,which is exactly why the
db.Error()check must precede theProcess-errorbranch.
Scope / risk
Stateless-verification path only. A valid block whose code is fully present is
unaffected:
db.Error()is nil and the existingValidateStatepath runsunchanged. This turns a silently mis-attributed failure into an explicit,
metered rejection — it does not change which valid blocks are accepted.
This is the mechanism-agnostic detection half of the fix; the companion PR adds
peer self-heal so a detected miss recovers instead of stalling.