fix: adapt journal for cmd (#2425)

This commit is contained in:
Chris Li 2024-04-28 11:02:14 +08:00 committed by GitHub
parent 31d92c50ad
commit 6573254a62
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 19 additions and 12 deletions

@ -282,7 +282,7 @@ func initGenesis(ctx *cli.Context) error {
log.Warn("Multi-database is an experimental feature") log.Warn("Multi-database is an experimental feature")
} }
triedb := utils.MakeTrieDatabase(ctx, chaindb, ctx.Bool(utils.CachePreimagesFlag.Name), false, genesis.IsVerkle()) triedb := utils.MakeTrieDatabase(ctx, stack, chaindb, ctx.Bool(utils.CachePreimagesFlag.Name), false, genesis.IsVerkle())
defer triedb.Close() defer triedb.Close()
_, hash, err := core.SetupGenesisBlockWithOverride(chaindb, triedb, genesis, &overrides) _, hash, err := core.SetupGenesisBlockWithOverride(chaindb, triedb, genesis, &overrides)
@ -778,7 +778,7 @@ func parseDumpConfig(ctx *cli.Context, stack *node.Node) (*state.DumpConfig, eth
} else { } else {
// Use latest // Use latest
if scheme == rawdb.PathScheme { if scheme == rawdb.PathScheme {
triedb := triedb.NewDatabase(db, &triedb.Config{PathDB: pathdb.ReadOnly}) triedb := triedb.NewDatabase(db, &triedb.Config{PathDB: utils.PathDBConfigAddJournalFilePath(stack, pathdb.ReadOnly)})
defer triedb.Close() defer triedb.Close()
if stateRoot := triedb.Head(); stateRoot != (common.Hash{}) { if stateRoot := triedb.Head(); stateRoot != (common.Hash{}) {
header.Root = stateRoot header.Root = stateRoot
@ -829,7 +829,7 @@ func dump(ctx *cli.Context) error {
return err return err
} }
defer db.Close() defer db.Close()
triedb := utils.MakeTrieDatabase(ctx, db, true, true, false) // always enable preimage lookup triedb := utils.MakeTrieDatabase(ctx, stack, db, true, true, false) // always enable preimage lookup
defer triedb.Close() defer triedb.Close()
state, err := state.New(root, state.NewDatabaseWithNodeDB(db, triedb), nil) state, err := state.New(root, state.NewDatabaseWithNodeDB(db, triedb), nil)
@ -849,7 +849,7 @@ func dumpAllRootHashInPath(ctx *cli.Context) error {
defer stack.Close() defer stack.Close()
db := utils.MakeChainDatabase(ctx, stack, true, false) db := utils.MakeChainDatabase(ctx, stack, true, false)
defer db.Close() defer db.Close()
triedb := triedb.NewDatabase(db, &triedb.Config{PathDB: pathdb.ReadOnly}) triedb := triedb.NewDatabase(db, &triedb.Config{PathDB: utils.PathDBConfigAddJournalFilePath(stack, pathdb.ReadOnly)})
defer triedb.Close() defer triedb.Close()
scheme, err := rawdb.ParseStateScheme(ctx.String(utils.StateSchemeFlag.Name), db) scheme, err := rawdb.ParseStateScheme(ctx.String(utils.StateSchemeFlag.Name), db)

@ -436,7 +436,7 @@ func inspectTrie(ctx *cli.Context) error {
var config *triedb.Config var config *triedb.Config
if dbScheme == rawdb.PathScheme { if dbScheme == rawdb.PathScheme {
config = &triedb.Config{ config = &triedb.Config{
PathDB: pathdb.ReadOnly, PathDB: utils.PathDBConfigAddJournalFilePath(stack, pathdb.ReadOnly),
} }
} else if dbScheme == rawdb.HashScheme { } else if dbScheme == rawdb.HashScheme {
config = triedb.HashDefaults config = triedb.HashDefaults
@ -975,7 +975,7 @@ func dbDumpTrie(ctx *cli.Context) error {
db := utils.MakeChainDatabase(ctx, stack, true, false) db := utils.MakeChainDatabase(ctx, stack, true, false)
defer db.Close() defer db.Close()
triedb := utils.MakeTrieDatabase(ctx, db, false, true, false) triedb := utils.MakeTrieDatabase(ctx, stack, db, false, true, false)
defer triedb.Close() defer triedb.Close()
var ( var (

@ -532,7 +532,7 @@ func verifyState(ctx *cli.Context) error {
log.Error("Failed to load head block") log.Error("Failed to load head block")
return errors.New("no head block") return errors.New("no head block")
} }
triedb := utils.MakeTrieDatabase(ctx, chaindb, false, true, false) triedb := utils.MakeTrieDatabase(ctx, stack, chaindb, false, true, false)
defer triedb.Close() defer triedb.Close()
snapConfig := snapshot.Config{ snapConfig := snapshot.Config{
@ -587,7 +587,7 @@ func traverseState(ctx *cli.Context) error {
chaindb := utils.MakeChainDatabase(ctx, stack, true, false) chaindb := utils.MakeChainDatabase(ctx, stack, true, false)
defer chaindb.Close() defer chaindb.Close()
triedb := utils.MakeTrieDatabase(ctx, chaindb, false, true, false) triedb := utils.MakeTrieDatabase(ctx, stack, chaindb, false, true, false)
defer triedb.Close() defer triedb.Close()
headBlock := rawdb.ReadHeadBlock(chaindb) headBlock := rawdb.ReadHeadBlock(chaindb)
@ -696,7 +696,7 @@ func traverseRawState(ctx *cli.Context) error {
chaindb := utils.MakeChainDatabase(ctx, stack, true, false) chaindb := utils.MakeChainDatabase(ctx, stack, true, false)
defer chaindb.Close() defer chaindb.Close()
triedb := utils.MakeTrieDatabase(ctx, chaindb, false, true, false) triedb := utils.MakeTrieDatabase(ctx, stack, chaindb, false, true, false)
defer triedb.Close() defer triedb.Close()
headBlock := rawdb.ReadHeadBlock(chaindb) headBlock := rawdb.ReadHeadBlock(chaindb)
@ -861,7 +861,7 @@ func dumpState(ctx *cli.Context) error {
return err return err
} }
defer db.Close() defer db.Close()
triedb := utils.MakeTrieDatabase(ctx, db, false, true, false) triedb := utils.MakeTrieDatabase(ctx, stack, db, false, true, false)
defer triedb.Close() defer triedb.Close()
snapConfig := snapshot.Config{ snapConfig := snapshot.Config{
@ -944,7 +944,7 @@ func snapshotExportPreimages(ctx *cli.Context) error {
chaindb := utils.MakeChainDatabase(ctx, stack, true, false) chaindb := utils.MakeChainDatabase(ctx, stack, true, false)
defer chaindb.Close() defer chaindb.Close()
triedb := utils.MakeTrieDatabase(ctx, chaindb, false, true, false) triedb := utils.MakeTrieDatabase(ctx, stack, chaindb, false, true, false)
defer triedb.Close() defer triedb.Close()
var root common.Hash var root common.Hash

@ -2430,6 +2430,12 @@ func MakeBlockDatabase(ctx *cli.Context, stack *node.Node, readonly, disableFree
return blockDb return blockDb
} }
func PathDBConfigAddJournalFilePath(stack *node.Node, config *pathdb.Config) *pathdb.Config {
path := fmt.Sprintf("%s/%s", stack.ResolvePath("chaindata"), eth.JournalFileName)
config.JournalFilePath = path
return config
}
// tryMakeReadOnlyDatabase try to open the chain database in read-only mode, // tryMakeReadOnlyDatabase try to open the chain database in read-only mode,
// or fallback to write mode if the database is not initialized. // or fallback to write mode if the database is not initialized.
// //
@ -2572,7 +2578,7 @@ func MakeConsolePreloads(ctx *cli.Context) []string {
} }
// MakeTrieDatabase constructs a trie database based on the configured scheme. // MakeTrieDatabase constructs a trie database based on the configured scheme.
func MakeTrieDatabase(ctx *cli.Context, disk ethdb.Database, preimage bool, readOnly bool, isVerkle bool) *triedb.Database { func MakeTrieDatabase(ctx *cli.Context, stack *node.Node, disk ethdb.Database, preimage bool, readOnly bool, isVerkle bool) *triedb.Database {
config := &triedb.Config{ config := &triedb.Config{
Preimages: preimage, Preimages: preimage,
IsVerkle: isVerkle, IsVerkle: isVerkle,
@ -2593,6 +2599,7 @@ func MakeTrieDatabase(ctx *cli.Context, disk ethdb.Database, preimage bool, read
} else { } else {
config.PathDB = pathdb.Defaults config.PathDB = pathdb.Defaults
} }
config.PathDB.JournalFilePath = fmt.Sprintf("%s/%s", stack.ResolvePath("chaindata"), eth.JournalFileName)
return triedb.NewDatabase(disk, config) return triedb.NewDatabase(disk, config)
} }