Skip to content

Commit c7e89d2

Browse files
committed
Add a system_test for fix for "missing trie node error on pathdb nodes"
1 parent 0b3b2ee commit c7e89d2

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package arbtest
2+
3+
import (
4+
"context"
5+
"math/big"
6+
"testing"
7+
8+
"github.com/stretchr/testify/require"
9+
10+
"github.com/ethereum/go-ethereum/core/rawdb"
11+
)
12+
13+
func TestAccessingPathSchemeArchivalState(t *testing.T) {
14+
ctx, cancel := context.WithCancel(context.Background())
15+
defer cancel()
16+
builder := NewNodeBuilder(ctx).DefaultConfig(t, true)
17+
scheme := rawdb.PathScheme
18+
builder.defaultDbScheme = scheme
19+
builder.execConfig.Caching.StateScheme = scheme
20+
builder.execConfig.RPC.StateScheme = scheme
21+
22+
// This test is PathScheme specific, it shouldn't be run with HashScheme
23+
builder.RequireScheme(t, rawdb.PathScheme)
24+
25+
// Build a node with history past the 128 block diff threshold
26+
cancelNode := buildWithHistory(t, ctx, builder, 150)
27+
execNode, l2client := builder.L2.ExecNode, builder.L2.Client
28+
defer cancelNode()
29+
bc := execNode.Backend.ArbInterface().BlockChain()
30+
31+
header := bc.CurrentBlock()
32+
if header == nil {
33+
Fatal(t, "failed to get current block header")
34+
}
35+
36+
head := header.Number.Uint64()
37+
start := head - 128
38+
if start < 1 {
39+
t.Fatalf("chain height (%d) too low — need at least 129 blocks to check last 128", head)
40+
}
41+
42+
for height := head; height > start; height-- {
43+
_, err := l2client.BalanceAt(ctx, GetTestAddressForAccountName(t, "User2"), new(big.Int).SetUint64(height))
44+
Require(t, err, "Failed to get balance at height", height)
45+
}
46+
47+
// Now try to access state older than 128 blocks ago, which should be missing
48+
//
49+
// We don't want to see the error
50+
// `missing trie node X (path ) state Y is not available, not found`
51+
// because that indicates a failure to find data that should exist. Implying our state backend has a bug.
52+
heightWhereStateShouldBeMissing := head - 129
53+
_, err := l2client.BalanceAt(ctx, GetTestAddressForAccountName(t, "User2"), new(big.Int).SetUint64(heightWhereStateShouldBeMissing))
54+
require.Error(t, err, "expected BalanceAt to fail for missing historical state")
55+
require.Contains(t, err.Error(), "historical state", "unexpected error message: %v", err)
56+
require.Contains(t, err.Error(), "is not available", "unexpected error message: %v", err)
57+
58+
}

0 commit comments

Comments
 (0)