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

Open
#2,568 1 comment 0 reactions 0 assignees View on GitHub

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

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.240 UTC the node imported block 97,873,428. With maxDiffLayers = 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=dirty errors 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, as eth_getTransactionCount on 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)
  1. eth/state_accessor.go pathState() opens the parent state with blockchain.StateAt(root) from the live layer tree, because the root is still within the 128 diff layers.
  2. While the earlier transactions are replayed, a block import runs cap(), and the layer the reader holds goes stale. triedb/pathdb/reader.go nodeWalk() gets errSnapshotStale and falls back to nodeFallback(), which reads tree.bottom(). That disk layer now represents a newer state. The node hash check fails, it logs Unexpected trie node, and it returns unexpected node (reader.go:111-164, 196-198).
  3. core/state/statedb.go getStateObject() stores the error with setError and returns nil (statedb.go:1448-1451), so GetNonce returns 0.
  4. core/state_transition.go preCheck returns ErrNonceTooHigh (state_transition.go:360-364). eth/state_accessor.go:286 wraps it as transaction %#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 from HistoricState(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 HistoricState from 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:

  1. Run a path-scheme archive node at the chain head.
  2. Repeatedly call debug_traceBlockByNumber (or debug_traceTransaction for 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.
  3. A fraction of the calls fail with nonce too high ... state: 0, each one alongside an Unexpected trie node location=dirty burst 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

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from 0xPolygon/bor

All issues in 0xPolygon/bor

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.