diff --git a/RELEASES.md b/RELEASES.md index 45bc5a4ba1..a870afaa31 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -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) diff --git a/core/blockchain.go b/core/blockchain.go index ba97bd8df7..5d86e779bd 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -34,7 +34,6 @@ import ( "fmt" "io" "math/big" - "path/filepath" "runtime" "strings" "sync" @@ -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 @@ -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 diff --git a/core/extstate/database_test.go b/core/extstate/database_test.go index a753530d6e..80c6b4700c 100644 --- a/core/extstate/database_test.go +++ b/core/extstate/database_test.go @@ -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{ diff --git a/core/genesis_test.go b/core/genesis_test.go index 431b9c3f23..c0482bfb29 100644 --- a/core/genesis_test.go +++ b/core/genesis_test.go @@ -32,7 +32,6 @@ import ( _ "embed" "fmt" "math/big" - "path/filepath" "reflect" "testing" @@ -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) diff --git a/tests/state_test_util.go b/tests/state_test_util.go index badd8cd65c..83b3e777f0 100644 --- a/tests/state_test_util.go +++ b/tests/state_test_util.go @@ -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) diff --git a/triedb/firewood/database.go b/triedb/firewood/database.go index 3ffa60e5ea..f12c83c68a 100644 --- a/triedb/firewood/database.go +++ b/triedb/firewood/database.go @@ -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) @@ -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 @@ -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, @@ -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)