Skip to content

Commit 49eebe8

Browse files
alarso16JonathanOppenheimer
authored andcommitted
chore: update firewood and fix test flakes (#1151)
1 parent 4aa72e6 commit 49eebe8

File tree

5 files changed

+35
-43
lines changed

5 files changed

+35
-43
lines changed

core/extstate/database_test.go

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func newFuzzState(t *testing.T) *fuzzState {
8282
})
8383

8484
firewoodMemdb := rawdb.NewMemoryDatabase()
85-
fwCfg := firewood.Defaults
85+
fwCfg := firewood.Defaults // copy the defaults
8686
fwCfg.FilePath = filepath.Join(t.TempDir(), "firewood") // Use a temporary directory for the Firewood
8787
firewoodState := NewDatabaseWithConfig(
8888
firewoodMemdb,
@@ -309,15 +309,6 @@ func (fs *fuzzState) deleteStorage(accountIndex int, storageIndexInput uint64) {
309309
}
310310

311311
func FuzzTree(f *testing.F) {
312-
for randSeed := range int64(1000) {
313-
rand := rand.New(rand.NewSource(randSeed))
314-
steps := make([]byte, 32)
315-
_, err := rand.Read(steps)
316-
if err != nil {
317-
f.Fatal(err)
318-
}
319-
f.Add(randSeed, steps)
320-
}
321312
f.Fuzz(func(t *testing.T, randSeed int64, byteSteps []byte) {
322313
fuzzState := newFuzzState(t)
323314
rand := rand.New(rand.NewSource(randSeed))

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ go 1.23.9
55
require (
66
github.com/VictoriaMetrics/fastcache v1.12.1
77
github.com/antithesishq/antithesis-sdk-go v0.3.8
8-
github.com/ava-labs/avalanchego v1.13.5-rc.0
9-
github.com/ava-labs/firewood-go-ethhash/ffi v0.0.11
8+
github.com/ava-labs/avalanchego v1.13.5-rc.4
9+
github.com/ava-labs/firewood-go-ethhash/ffi v0.0.12
1010
github.com/ava-labs/libevm v1.13.14-0.3.0.rc.6
1111
github.com/davecgh/go-spew v1.1.1
1212
github.com/deckarep/golang-set/v2 v2.1.0

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ github.com/antithesishq/antithesis-sdk-go v0.3.8/go.mod h1:IUpT2DPAKh6i/YhSbt6Gl
2424
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
2525
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
2626
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
27-
github.com/ava-labs/avalanchego v1.13.5-rc.0 h1:73nIYhUoiwtjzlxWugvPlNkfCtsozRTwnhIxz3kO5og=
28-
github.com/ava-labs/avalanchego v1.13.5-rc.0/go.mod h1:I4AHk5hn0sbzF0rEbi/C9ql+u9sttiVIHSgDcVvMtPg=
27+
github.com/ava-labs/avalanchego v1.13.5-rc.4 h1:5aPlOFQFbKBLvUzsxLgybGhOCqEyi74x1qcgntVtzww=
28+
github.com/ava-labs/avalanchego v1.13.5-rc.4/go.mod h1:6bXxADKsAkU/f9Xme0gFJGRALp3IVzwq8NMDyx6ucRs=
2929
github.com/ava-labs/coreth v0.15.3-rc.5 h1:zGk1LaFeZOEkA6uPF1g9BNCjbZOrONx9fm5WtiH5NWg=
3030
github.com/ava-labs/coreth v0.15.3-rc.5/go.mod h1:sEqzSu2f4FJEGFL7CP3zNOQtQ0MupWJdzTp7W65EDf8=
31-
github.com/ava-labs/firewood-go-ethhash/ffi v0.0.11 h1:V9XDirIJ0oveor+sAPuOB0WMQ+b7FoDStScMdyGlBQ4=
32-
github.com/ava-labs/firewood-go-ethhash/ffi v0.0.11/go.mod h1:cq89ua3iiZ5wPBALTEQS5eG8DIZcs7ov6OiL4YR1BVY=
31+
github.com/ava-labs/firewood-go-ethhash/ffi v0.0.12 h1:aMcrLbpJ/dyu2kZDf/Di/4JIWsUcYPyTDKymiHpejt0=
32+
github.com/ava-labs/firewood-go-ethhash/ffi v0.0.12/go.mod h1:cq89ua3iiZ5wPBALTEQS5eG8DIZcs7ov6OiL4YR1BVY=
3333
github.com/ava-labs/libevm v1.13.14-0.3.0.rc.6 h1:tyM659nDOknwTeU4A0fUVsGNIU7k0v738wYN92nqs/Y=
3434
github.com/ava-labs/libevm v1.13.14-0.3.0.rc.6/go.mod h1:zP/DOcABRWargBmUWv1jXplyWNcfmBy9cxr0lw3LW3g=
3535
github.com/aymerick/raymond v2.0.3-0.20180322193309-b565731e1464+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g=

plugin/evm/vm_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,11 @@ func testBuildEthTxBlock(t *testing.T, scheme string) {
453453
if ethBlk2Root := ethBlk2.Root(); !restartedVM.blockChain.HasState(ethBlk2Root) {
454454
t.Fatalf("Expected blk2 state root to not be pruned after shutdown (last accepted tip should be committed)")
455455
}
456+
457+
// Shutdown the newest VM
458+
if err := restartedVM.Shutdown(context.Background()); err != nil {
459+
t.Fatal(err)
460+
}
456461
}
457462

458463
// Regression test to ensure that after accepting block A

triedb/firewood/database.go

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ type Config struct {
6969
ReadCacheStrategy ffi.CacheStrategy
7070
}
7171

72-
// Note that `FilePath` is not specificied, and must always be set by the user.
73-
var Defaults = &Config{
72+
// Note that `FilePath` is not specified, and must always be set by the user.
73+
var Defaults = Config{
7474
CleanCacheSize: 1024 * 1024, // 1MB
7575
FreeListCacheEntries: 40_000,
7676
Revisions: 100,
@@ -97,15 +97,20 @@ type Database struct {
9797
// Any error during creation will cause the program to exit.
9898
func New(config *Config) *Database {
9999
if config == nil {
100-
config = Defaults
100+
log.Crit("firewood: config must be provided")
101101
}
102102

103-
fwConfig, err := validatePath(config)
103+
err := validatePath(config.FilePath)
104104
if err != nil {
105105
log.Crit("firewood: error validating config", "error", err)
106106
}
107107

108-
fw, err := ffi.New(config.FilePath, fwConfig)
108+
fw, err := ffi.New(config.FilePath, &ffi.Config{
109+
NodeCacheEntries: uint(config.CleanCacheSize) / 256, // TODO: estimate 256 bytes per node
110+
FreeListCacheEntries: config.FreeListCacheEntries,
111+
Revisions: config.Revisions,
112+
ReadCacheStrategy: config.ReadCacheStrategy,
113+
})
109114
if err != nil {
110115
log.Crit("firewood: error creating firewood database", "error", err)
111116
}
@@ -124,34 +129,25 @@ func New(config *Config) *Database {
124129
}
125130
}
126131

127-
func validatePath(trieConfig *Config) (*ffi.Config, error) {
128-
if trieConfig.FilePath == "" {
129-
return nil, errors.New("firewood database file path must be set")
132+
func validatePath(path string) error {
133+
if path == "" {
134+
return errors.New("firewood database file path must be set")
130135
}
131136

132137
// Check that the directory exists
133-
dir := filepath.Dir(trieConfig.FilePath)
138+
dir := filepath.Dir(path)
134139
_, err := os.Stat(dir)
135-
if err != nil {
136-
if os.IsNotExist(err) {
137-
log.Info("Database directory not found, creating", "path", dir)
138-
if err := os.MkdirAll(dir, 0o755); err != nil {
139-
return nil, fmt.Errorf("error creating database directory: %w", err)
140-
}
141-
} else {
142-
return nil, fmt.Errorf("error checking database directory: %w", err)
143-
}
140+
if err == nil {
141+
return nil // Directory exists
144142
}
145-
146-
// Create the Firewood config from the provided config.
147-
config := &ffi.Config{
148-
NodeCacheEntries: uint(trieConfig.CleanCacheSize) / 256, // TODO: estimate 256 bytes per node
149-
FreeListCacheEntries: trieConfig.FreeListCacheEntries,
150-
Revisions: trieConfig.Revisions,
151-
ReadCacheStrategy: trieConfig.ReadCacheStrategy,
143+
if !os.IsNotExist(err) {
144+
return fmt.Errorf("error checking database directory: %w", err)
152145
}
153-
154-
return config, nil
146+
log.Info("Database directory not found, creating", "path", dir)
147+
if err := os.MkdirAll(dir, 0o755); err != nil {
148+
return fmt.Errorf("error creating database directory: %w", err)
149+
}
150+
return nil
155151
}
156152

157153
// Scheme returns the scheme of the database.

0 commit comments

Comments
 (0)