debug_trace on path-scheme archive node fails with misleading "nonce too high ... state: 0" when the parent state's diff layer is flattened mid-trace
Maintainers usually reply within 2 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 22/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- go
- Domain
- blockchain, databases
Research direction
Start at eth/state_accessor.go, where pathState and the transaction replay wrap failures as 'transaction %#x failed' (around line 286), then follow the read path through core/state/statedb.go getStateObject and triedb/pathdb/reader.go nodeWalk/nodeFallback. Done means that when statedb.Error() is set the trace returns that real read error, or retries from a historic state, instead of the derived ErrNonceTooHigh. The reproduction is not yet written and the fix direction is still open for discussion, so confirm the approach with maintainers first.
Written by the indexing model from the issue text.
Description
System information
Bor client version: v2.11.1 (Polygon private build v2.11.1-private, commit e01580f0; its eth, core, triedb and trie trees are identical to public v2.11.1)
Heimdall client version: v0.14.0
OS & Version: Linux
Environment: Polygon Mainnet
Type of node: Archive (state.scheme = "path", gcmode = "archive", snapshot = true, history.state = 0, db.engine = "pebble", syncmode = "full")
Additional Information: no client modifications
Overview of the problem
Now and then, debug_traceTransaction and debug_traceBlockByNumber return:
-32000 transaction <hash of an EARLIER tx in the same block> failed: nonce too high: address <that tx's sender>, tx: <N> state: 0
The traced transactions are canonical, their receipts are successful, and the same call works when retried. We see about 13 of these a week, out of about 1.8M trace calls, on two of our three mainnet archive nodes (all on the same build and config). They go back at least a month, so they predate v2.11.1.
Expected: the trace succeeds (the parent state is available in state history), or the RPC returns the real read error.
Actual: the state read fails. The account is treated as non-existent, and the RPC reports a misleading nonce error for a different transaction.
What we observed in one case
debug_traceTransaction(callTracer) for a tx in the second half of block 97,873,300. Its parent state is block 97,873,299. The call failed after 50 ms.- At
10:20:10.240UTC the node imported block 97,873,428. WithmaxDiffLayers = 128, that makes the layer for 97,873,299 the 129th, so it is flattened into the disk layer. - In the same millisecond the node logged 9
Unexpected trie node location=dirtyerrors on the account trie (owner=0x00..00). - The RPC returned
nonce too high ... state: 0, naming an earlier tx in the same block. That tx's sender has a nonce above 100,000 at block 97,873,299, aseth_getTransactionCounton the node returns now. - The same trace succeeds now on all three nodes.
In the other cases we checked (on the second node), the Unexpected trie node burst also lands in the same millisecond as a block import. We have not checked the traced block depth for those.
Code path as we read it (v2.11.1)
eth/state_accessor.gopathState()opens the parent state withblockchain.StateAt(root)from the live layer tree, because the root is still within the 128 diff layers.- While the earlier transactions are replayed, a block import runs
cap(), and the layer the reader holds goes stale.triedb/pathdb/reader.gonodeWalk()getserrSnapshotStaleand falls back tonodeFallback(), which readstree.bottom(). That disk layer now represents a newer state. The node hash check fails, it logsUnexpected trie node, and it returnsunexpected node(reader.go:111-164,196-198). core/state/statedb.gogetStateObject()stores the error withsetErrorand returnsnil(statedb.go:1448-1451), soGetNoncereturns 0.core/state_transition.gopreCheckreturnsErrNonceTooHigh(state_transition.go:360-364).eth/state_accessor.go:286wraps it astransaction %#x failed, with the earlier tx's hash.statedb.Error()is never checked, so the real cause is lost.
#2466 (v2.10.2) made a lookup rejection authoritative for account and storage reads. The trie-node path still falls back to tree.bottom(). The hash check makes that fail safe (no wrong data is served), but the trace cannot recover from it.
Possible directions (for discussion)
- In
pathState/stateAtTransaction: if the StateDB recorded a read error while replaying on a live-tree state, retry once fromHistoricState(root), which does not depend on the live layers. - Or open a state that is close to the flatten edge (for example, older than head minus 120) through
HistoricStatefrom the start. - In any case, return
statedb.Error()when it is set, rather than the derived nonce error, so the failure is visible to callers.
Reproduction Steps
We have not run a dedicated repro. From the code path above, we expect this to reproduce it:
- Run a path-scheme archive node at the chain head.
- Repeatedly call
debug_traceBlockByNumber(ordebug_traceTransactionfor a late tx in the block) on blocks about 128 below head, so that the parent's diff layer is flattened while the replay runs. - A fraction of the calls fail with
nonce too high ... state: 0, each one alongside anUnexpected trie node location=dirtyburst at a block import.
Logs / Traces / Output / Error Messages
INFO [11-24|10:20:08.788] Imported new chain segment number=97,873,427 hash=9fde65..7e9e0b blocks=1 txs=81 mgas=22.719 elapsed=72.041ms triediffs=163.73MiB triedirty=0.00B
ERROR[11-24|10:20:10.240] Unexpected trie node location=dirty owner=0x0000000000000000000000000000000000000000000000000000000000000000 path=[14] expect=0xca27e136e118c4b998deb780f0d21e9bd023374452b0fdde36cc254fcda84061 got=0x6170ae9a0f2b5b0e8ce50fcf43657b0fb217270868cc0f2797...
ERROR[11-24|10:20:10.240] Unexpected trie node location=dirty owner=0x0000000000000000000000000000000000000000000000000000000000000000 path=[12] expect=0xd55c2e620174bfc5905df8121b37a19489873e832c3c202c913201e06ed6d4c3 got=0x76d217ba42f6dd4a7d33ebf075e62f69f1d8e6bc8534b8e4f5...
INFO [11-24|10:20:10.240] Imported new chain segment number=97,873,428 hash=ff3abf..6cc725 blocks=1 txs=77 mgas=17.507 elapsed=52.546ms triediffs=163.91MiB triedirty=0.00B
ERROR[11-24|10:20:10.241] Unexpected trie node location=dirty owner=0x0000000000000000000000000000000000000000000000000000000000000000 path=[14] expect=0xca27e136...
ERROR[11-24|10:20:10.242] Unexpected trie node location=dirty owner=0x0000000000000000000000000000000000000000000000000000000000000000 path=[1] expect=0x4e7de4aa6d94d12be912553af84d4a43f536f2873e02b4edeb1071ad4bb84839 got=0x83b095194283341dac30bf1f1f49198415f4ae987ae7075ed1...
INFO [11-24|10:20:11.772] Imported new chain segment number=97,873,429 hash=ad13ae..00199a blocks=1 txs=79 mgas=28.044 elapsed=70.504ms triediffs=164.27MiB triedirty=0.00B
(9 Unexpected trie node lines in total between .240 and .242; some fields trimmed and got values truncated here.)
RPC error returned for that request (hashes and nonce redacted):
{"code":-32000,"message":"transaction 0x<earlier tx> failed: nonce too high: address 0x<its sender>, tx: <nonce> state: 0"}
- Dominant language
- Go
- Stars
- 1.1k
- Forks
- 623
- Avg merge
- 4d 14h
- Merged PRs (30d)
- 34
Getting set up
- Ships a Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from 0xPolygon/bor
-
Difficulty 4/5 3-5 days Newbie friendliness 30/100
Maintainers usually reply within 2 days
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
0xPolygon/bor#2539 · 1 comment ·
Maintainers usually reply within 2 days
-
Stale
Difficulty 4/5 3-5 days Newbie friendliness 35/100
0xPolygon/bor#2528 · 2 comments ·
Maintainers usually reply within 2 days
-
Backport go-ethereum#34898 so bor no longer deadlocks in p2p/discover waitForNodes and hangs on shutdownMay be free again A pull request for this issue was closed without being merged. Open
Difficulty 3/5 1-2 days Newbie friendliness 35/100
0xPolygon/bor#2506 · 4 comments · 1 reaction ·
Maintainers usually reply within 2 days
-
Snap sync on Amoy cannot progress past block 34,546,977: receipts exceed the 10 MiB eth maxMessageSize, every peer is disconnectedMay be free again @Samyra312007 claimed this 49 days ago, and no pull request is open. OpenStale
Difficulty 4/5 3-5 days Newbie friendliness 30/100
0xPolygon/bor#2441 · 5 comments ·
Maintainers usually reply within 2 days
Similar issues
-
needs-triage
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
gke-labs/kube-agents#7441 ·
Maintainers usually reply within 1 day
-
triage/pending-triage
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
external-secrets/external-secrets#7361 ·
Maintainers usually reply within 2 days
-
Type/Bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
thunder-id/thunderid#7092 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
jdx/jactionlint#360 ·
Maintainers usually reply within 1 day
-
enhancement good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
Maintainers usually reply within 1 day