@@ -2,6 +2,7 @@ package arbtest
22
33import (
44 "context"
5+ "fmt"
56 "math/big"
67 "testing"
78
@@ -10,14 +11,10 @@ import (
1011 "github.com/ethereum/go-ethereum/core/rawdb"
1112)
1213
13- func TestAccessingPathSchemeArchivalState (t * testing.T ) {
14+ func TestAccessingPathSchemeState (t * testing.T ) {
1415 ctx , cancel := context .WithCancel (context .Background ())
1516 defer cancel ()
1617 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
2118
2219 // This test is PathScheme specific, it shouldn't be run with HashScheme
2320 builder .RequireScheme (t , rawdb .PathScheme )
@@ -34,10 +31,10 @@ func TestAccessingPathSchemeArchivalState(t *testing.T) {
3431 }
3532
3633 head := header .Number .Uint64 ()
37- start := head - 128
38- if start < 1 {
34+ if head < 129 {
3935 t .Fatalf ("chain height (%d) too low — need at least 129 blocks to check last 128" , head )
4036 }
37+ start := head - 128
4138
4239 for height := head ; height > start ; height -- {
4340 _ , err := l2client .BalanceAt (ctx , GetTestAddressForAccountName (t , "User2" ), new (big.Int ).SetUint64 (height ))
@@ -54,5 +51,45 @@ func TestAccessingPathSchemeArchivalState(t *testing.T) {
5451 require .Error (t , err , "expected BalanceAt to fail for missing historical state" )
5552 require .Contains (t , err .Error (), "historical state" , "unexpected error message: %v" , err )
5653 require .Contains (t , err .Error (), "is not available" , "unexpected error message: %v" , err )
54+ }
55+
56+ func TestAccessingPathSchemeArchivalState (t * testing.T ) {
57+ ctx , cancel := context .WithCancel (context .Background ())
58+ defer cancel ()
59+ builder := NewNodeBuilder (ctx ).DefaultConfig (t , true )
60+ builder .execConfig .Caching .Archive = true
61+ builder .execConfig .Caching .StateHistory = 2
62+
63+ // This test is PathScheme specific, it shouldn't be run with HashScheme
64+ builder .RequireScheme (t , rawdb .PathScheme )
65+
66+ // Build a node with history past the 128 block diff threshold
67+ cancelNode := buildWithHistory (t , ctx , builder , 150 )
68+ fmt .Println ("bluebird 5-3" , builder .execConfig .Caching .StateScheme )
69+ execNode , l2client := builder .L2 .ExecNode , builder .L2 .Client
70+ defer cancelNode ()
71+ bc := execNode .Backend .ArbInterface ().BlockChain ()
5772
73+ header := bc .CurrentBlock ()
74+ if header == nil {
75+ Fatal (t , "failed to get current block header" )
76+ }
77+
78+ head := header .Number .Uint64 ()
79+ if head < 132 {
80+ t .Fatalf ("chain height (%d) too low — need at least 129 blocks to check last 128" , head )
81+ }
82+ start := head - 131
83+
84+ for height := head ; height > start ; height -- {
85+ _ , err := l2client .BalanceAt (ctx , GetTestAddressForAccountName (t , "User2" ), new (big.Int ).SetUint64 (height ))
86+ Require (t , err , "Failed to get balance at height" , height )
87+ }
88+
89+ // Now try to access state older than 131 blocks ago, which should be missing
90+ heightWhereStateShouldBeMissing := head - 132
91+ _ , err := l2client .BalanceAt (ctx , GetTestAddressForAccountName (t , "User2" ), new (big.Int ).SetUint64 (heightWhereStateShouldBeMissing ))
92+ require .Error (t , err , "expected BalanceAt to fail for missing historical state" )
93+ // `metadata is not found` is the error returned when archival data is pruned for some reason
94+ require .Contains (t , err .Error (), "metadata is not found" , "unexpected error message: %v" , err )
5895}
0 commit comments