Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- Implement ACP-226: Add `timeMilliseconds` (Unix uint64) timestamp to block header for Granite upgrade.
- Implement ACP-226: Add `minDelayExcess` (uint64) to block header for Granite upgrade.
- Update go version to 1.24.7
- Enabled logs for Firewood.

## [v0.15.3](https://github.com/ava-labs/coreth/releases/tag/v0.15.3)

Expand Down
5 changes: 1 addition & 4 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import (
"fmt"
"io"
"math/big"
"path/filepath"
"runtime"
"strings"
"sync"
Expand Down Expand Up @@ -175,8 +174,6 @@ const (
// trieCleanCacheStatsNamespace is the namespace to surface stats from the trie
// clean cache's underlying fastcache.
trieCleanCacheStatsNamespace = "hashdb/memcache/clean/fastcache"

firewoodFileName = "firewood.db"
)

// CacheConfig contains the configuration values for the trie database
Expand Down Expand Up @@ -230,7 +227,7 @@ func (c *CacheConfig) triedbConfig() *triedb.Config {
log.Crit("Chain data directory must be specified for Firewood")
}
config.DBOverride = firewood.Config{
FilePath: filepath.Join(c.ChainDataDir, firewoodFileName),
ChainDir: c.ChainDataDir,
CleanCacheSize: c.TrieCleanLimit * 1024 * 1024,
FreeListCacheEntries: firewood.Defaults.FreeListCacheEntries,
Revisions: uint(c.StateHistory), // must be at least 2
Expand Down
2 changes: 1 addition & 1 deletion core/extstate/database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func newFuzzState(t *testing.T) *fuzzState {

firewoodMemdb := rawdb.NewMemoryDatabase()
fwCfg := firewood.Defaults // copy the defaults
fwCfg.FilePath = filepath.Join(t.TempDir(), "firewood") // Use a temporary directory for the Firewood
fwCfg.ChainDir = filepath.Join(t.TempDir(), "firewood") // Use a temporary directory for the Firewood
firewoodState := NewDatabaseWithConfig(
firewoodMemdb,
&triedb.Config{
Expand Down
3 changes: 1 addition & 2 deletions core/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import (
_ "embed"
"fmt"
"math/big"
"path/filepath"
"reflect"
"testing"

Expand Down Expand Up @@ -307,7 +306,7 @@ func newDbConfig(t *testing.T, scheme string) *triedb.Config {
case customrawdb.FirewoodScheme:
fwCfg := firewood.Defaults
// Create a unique temporary directory for each test
fwCfg.FilePath = filepath.Join(t.TempDir(), "firewood_state") // matches blockchain.go
fwCfg.ChainDir = t.TempDir()
return &triedb.Config{DBOverride: fwCfg.BackendConstructor}
default:
t.Fatalf("unknown scheme %s", scheme)
Expand Down
2 changes: 1 addition & 1 deletion tests/state_test_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func MakePreState(db ethdb.Database, accounts types.GenesisAlloc, snapshotter bo
tconf.DBOverride = pathdb.Defaults.BackendConstructor
case customrawdb.FirewoodScheme:
cfg := firewood.Defaults
cfg.FilePath = filepath.Join(tempdir, "firewood")
cfg.ChainDir = filepath.Join(tempdir, "firewood")
tconf.DBOverride = cfg.BackendConstructor
default:
panic("unknown trie database scheme" + scheme)
Expand Down
27 changes: 20 additions & 7 deletions triedb/firewood/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ import (
"github.com/ava-labs/libevm/triedb/database"
)

const (
dbFileName = "firewood.db"
logFileName = "firewood.log"
)

var (
_ proposable = (*ffi.Database)(nil)
_ proposable = (*ffi.Proposal)(nil)
Expand Down Expand Up @@ -61,7 +66,7 @@ type ProposalContext struct {
}

type Config struct {
FilePath string
ChainDir string
CleanCacheSize int // Size of the clean cache in bytes
FreeListCacheEntries uint // Number of free list entries to cache
Revisions uint
Expand Down Expand Up @@ -99,11 +104,20 @@ type Database struct {
// New creates a new Firewood database with the given disk database and configuration.
// Any error during creation will cause the program to exit.
func New(config Config) (*Database, error) {
if err := validatePath(config.FilePath); err != nil {
if err := validatePath(config.ChainDir); err != nil {
return nil, err
}

fw, err := ffi.New(config.FilePath, &ffi.Config{
// Start the logs prior to opening the database
logPath := filepath.Join(config.ChainDir, logFileName)
if err := ffi.StartLogs(&ffi.LogConfig{Path: logPath}); err != nil {
// This shouldn't be a fatal error, as this can only be called once per thread.
// Specifically, this will return an error in unit tests.
log.Error("firewood: error starting logs", "error", err)
}

dbPath := filepath.Join(config.ChainDir, dbFileName)
fw, err := ffi.New(dbPath, &ffi.Config{
NodeCacheEntries: uint(config.CleanCacheSize) / 256, // TODO: estimate 256 bytes per node
FreeListCacheEntries: config.FreeListCacheEntries,
Revisions: config.Revisions,
Expand All @@ -127,13 +141,12 @@ func New(config Config) (*Database, error) {
}, nil
}

func validatePath(path string) error {
if path == "" {
return errors.New("firewood database file path must be set")
func validatePath(dir string) error {
if dir == "" {
return errors.New("chain data directory must be set")
}

// Check that the directory exists
dir := filepath.Dir(path)
switch info, err := os.Stat(dir); {
case os.IsNotExist(err):
log.Info("Database directory not found, creating", "path", dir)
Expand Down
Loading