Skip to content

Commit fb44328

Browse files
committed
triedb/pathdb: change to the default datadir
1 parent 516c1b3 commit fb44328

File tree

10 files changed

+106
-110
lines changed

10 files changed

+106
-110
lines changed

cmd/utils/flags.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -446,15 +446,6 @@ var (
446446
Value: ethconfig.Defaults.BlobPool.PriceBump,
447447
Category: flags.BlobPoolCategory,
448448
}
449-
450-
// Trie database settings
451-
TrieDBJournalFlag = &cli.BoolFlag{
452-
Name: "triedb.journal",
453-
Usage: "Enable persisting the trie database journal to disk (only used with pbss state scheme, default path: <datadir>/triedb.journal.rlp)",
454-
Value: true,
455-
Category: flags.TrieDatabaseCategory,
456-
}
457-
458449
// Performance tuning settings
459450
CacheFlag = &cli.IntFlag{
460451
Name: "cache",
@@ -992,7 +983,6 @@ var (
992983
DataDirFlag,
993984
AncientFlag,
994985
EraFlag,
995-
TrieDBJournalFlag,
996986
RemoteDBFlag,
997987
DBEngineFlag,
998988
StateSchemeFlag,
@@ -1654,9 +1644,6 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
16541644
if ctx.IsSet(StateSchemeFlag.Name) {
16551645
cfg.StateScheme = ctx.String(StateSchemeFlag.Name)
16561646
}
1657-
if !ctx.Bool(TrieDBJournalFlag.Name) {
1658-
cfg.TrieDBJournal = false
1659-
}
16601647
// Parse transaction history flag, if user is still using legacy config
16611648
// file with 'TxLookupLimit' configured, copy the value to 'TransactionHistory'.
16621649
if cfg.TransactionHistory == ethconfig.Defaults.TransactionHistory && cfg.TxLookupLimit != ethconfig.Defaults.TxLookupLimit {
@@ -2216,9 +2203,6 @@ func MakeChain(ctx *cli.Context, stack *node.Node, readonly bool) (*core.BlockCh
22162203
options.Preimages = true
22172204
log.Info("Enabling recording of key preimages since archive mode is used")
22182205
}
2219-
if !ctx.Bool(TrieDBJournalFlag.Name) {
2220-
options.TrieDBJournal = stack.ResolvePath("triedb.journal.rlp")
2221-
}
22222206
if !ctx.Bool(SnapshotFlag.Name) {
22232207
options.SnapshotLimit = 0 // Disabled
22242208
} else if ctx.IsSet(CacheFlag.Name) || ctx.IsSet(CacheSnapshotFlag.Name) {

core/blockchain.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,11 @@ const (
162162
// BlockChainConfig contains the configuration of the BlockChain object.
163163
type BlockChainConfig struct {
164164
// Trie database related options
165-
TrieCleanLimit int // Memory allowance (MB) to use for caching trie nodes in memory
166-
TrieDirtyLimit int // Memory limit (MB) at which to start flushing dirty trie nodes to disk
167-
TrieTimeLimit time.Duration // Time limit after which to flush the current in-memory trie to disk
168-
TrieNoAsyncFlush bool // Whether the asynchronous buffer flushing is disallowed
169-
TrieDBJournal string // Path to the journal used for persisting trie data across node restarts
165+
TrieCleanLimit int // Memory allowance (MB) to use for caching trie nodes in memory
166+
TrieDirtyLimit int // Memory limit (MB) at which to start flushing dirty trie nodes to disk
167+
TrieTimeLimit time.Duration // Time limit after which to flush the current in-memory trie to disk
168+
TrieNoAsyncFlush bool // Whether the asynchronous buffer flushing is disallowed
169+
TrieJournalDirectory string // Directory path to the journal used for persisting trie data across node restarts
170170

171171
Preimages bool // Whether to store preimage of trie key to the disk
172172
StateHistory uint64 // Number of blocks from head whose state histories are reserved.
@@ -247,7 +247,7 @@ func (cfg *BlockChainConfig) triedbConfig(isVerkle bool) *triedb.Config {
247247
EnableStateIndexing: cfg.ArchiveMode,
248248
TrieCleanSize: cfg.TrieCleanLimit * 1024 * 1024,
249249
StateCleanSize: cfg.SnapshotLimit * 1024 * 1024,
250-
JournalPath: cfg.TrieDBJournal,
250+
JournalDirectory: cfg.TrieJournalDirectory,
251251

252252
// TODO(rjl493456442): The write buffer represents the memory limit used
253253
// for flushing both trie data and state data to disk. The config name

eth/backend.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -237,14 +237,14 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
237237
ChainHistoryMode: config.HistoryMode,
238238
TxLookupLimit: int64(min(config.TransactionHistory, math.MaxInt64)),
239239
VmConfig: vmConfig,
240+
241+
// Enables file journaling for the trie database. The journal files will be stored
242+
// within the data directory. The corresponding paths will be either:
243+
// - DATADIR/merkle.journal
244+
// - DATADIR/verkle.journal
245+
TrieJournalDirectory: stack.ResolvePath(""),
240246
}
241247
)
242-
if config.TrieDBJournal {
243-
options.TrieDBJournal = stack.ResolvePath("triedb.journal.rlp")
244-
} else {
245-
log.Warn("Trie database journal is persisted within the database")
246-
}
247-
248248
if config.VMTrace != "" {
249249
traceConfig := json.RawMessage("{}")
250250
if config.VMTraceJsonConfig != "" {

eth/ethconfig/config.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@ type Config struct {
103103
LogHistory uint64 `toml:",omitempty"` // The maximum number of blocks from head where a log search index is maintained.
104104
LogNoHistory bool `toml:",omitempty"` // No log search index is maintained.
105105
LogExportCheckpoints string // export log index checkpoints to file
106+
StateHistory uint64 `toml:",omitempty"` // The maximum number of blocks from head whose state histories are reserved.
107+
108+
// State scheme represents the scheme used to store ethereum states and trie
109+
// nodes on top. It can be 'hash', 'path', or none which means use the scheme
110+
// consistent with persistent state.
111+
StateScheme string `toml:",omitempty"`
106112

107113
// RequiredBlocks is a set of block number -> hash mappings which must be in the
108114
// canonical chain of all remote peers. Setting the option makes geth verify the
@@ -116,20 +122,11 @@ type Config struct {
116122
DatabaseFreezer string
117123
DatabaseEra string
118124

119-
// Trie database options. TODO(rjl493456442) move all trie database options
120-
// into a separate config structure.
121125
TrieCleanCache int
122126
TrieDirtyCache int
123127
TrieTimeout time.Duration
124128
SnapshotCache int
125129
Preimages bool
126-
StateHistory uint64 `toml:",omitempty"` // The maximum number of blocks from head whose state histories are reserved.
127-
TrieDBJournal bool // Enable persisting the trie database journal to disk.
128-
129-
// State scheme represents the scheme used to store ethereum states and trie
130-
// nodes on top. It can be 'hash', 'path', or none which means use the scheme
131-
// consistent with persistent state.
132-
StateScheme string `toml:",omitempty"`
133130

134131
// This is the number of blocks for which logs will be cached in the filter system.
135132
FilterLogCacheSize int

eth/ethconfig/gen_config.go

Lines changed: 12 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/flags/categories.go

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,24 @@ package flags
1919
import "github.com/urfave/cli/v2"
2020

2121
const (
22-
EthCategory = "ETHEREUM"
23-
BeaconCategory = "BEACON CHAIN"
24-
DevCategory = "DEVELOPER CHAIN"
25-
StateCategory = "STATE HISTORY MANAGEMENT"
26-
TxPoolCategory = "TRANSACTION POOL (EVM)"
27-
BlobPoolCategory = "TRANSACTION POOL (BLOB)"
28-
PerfCategory = "PERFORMANCE TUNING"
29-
AccountCategory = "ACCOUNT"
30-
APICategory = "API AND CONSOLE"
31-
NetworkingCategory = "NETWORKING"
32-
MinerCategory = "MINER"
33-
TrieDatabaseCategory = "TRIE DATABASE"
34-
GasPriceCategory = "GAS PRICE ORACLE"
35-
VMCategory = "VIRTUAL MACHINE"
36-
LoggingCategory = "LOGGING AND DEBUGGING"
37-
MetricsCategory = "METRICS AND STATS"
38-
MiscCategory = "MISC"
39-
TestingCategory = "TESTING"
40-
DeprecatedCategory = "ALIASED (deprecated)"
22+
EthCategory = "ETHEREUM"
23+
BeaconCategory = "BEACON CHAIN"
24+
DevCategory = "DEVELOPER CHAIN"
25+
StateCategory = "STATE HISTORY MANAGEMENT"
26+
TxPoolCategory = "TRANSACTION POOL (EVM)"
27+
BlobPoolCategory = "TRANSACTION POOL (BLOB)"
28+
PerfCategory = "PERFORMANCE TUNING"
29+
AccountCategory = "ACCOUNT"
30+
APICategory = "API AND CONSOLE"
31+
NetworkingCategory = "NETWORKING"
32+
MinerCategory = "MINER"
33+
GasPriceCategory = "GAS PRICE ORACLE"
34+
VMCategory = "VIRTUAL MACHINE"
35+
LoggingCategory = "LOGGING AND DEBUGGING"
36+
MetricsCategory = "METRICS AND STATS"
37+
MiscCategory = "MISC"
38+
TestingCategory = "TESTING"
39+
DeprecatedCategory = "ALIASED (deprecated)"
4140
)
4241

4342
func init() {

triedb/pathdb/database.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"errors"
2222
"fmt"
2323
"io"
24+
"path/filepath"
2425
"sync"
2526
"time"
2627

@@ -120,7 +121,7 @@ type Config struct {
120121
StateCleanSize int // Maximum memory allowance (in bytes) for caching clean state data
121122
WriteBufferSize int // Maximum memory allowance (in bytes) for write buffer
122123
ReadOnly bool // Flag whether the database is opened in read only mode
123-
JournalPath string // Absolute path of journal file (null means the journal data is persisted in key-value store)
124+
JournalDirectory string // Absolute path of journal directory (null means the journal data is persisted in key-value store)
124125

125126
// Testing configurations
126127
SnapshotNoBuild bool // Flag Whether the state generation is allowed
@@ -157,8 +158,8 @@ func (c *Config) fields() []interface{} {
157158
} else {
158159
list = append(list, "history", fmt.Sprintf("last %d blocks", c.StateHistory))
159160
}
160-
if c.JournalPath != "" {
161-
list = append(list, "journal", c.JournalPath)
161+
if c.JournalDirectory != "" {
162+
list = append(list, "journal-dir", c.JournalDirectory)
162163
}
163164
return list
164165
}
@@ -674,6 +675,20 @@ func (db *Database) modifyAllowed() error {
674675
return nil
675676
}
676677

678+
// journalPath returns the absolute path of journal for persisting state data.
679+
func (db *Database) journalPath() string {
680+
if db.config.JournalDirectory == "" {
681+
return ""
682+
}
683+
var fname string
684+
if db.isVerkle {
685+
fname = fmt.Sprintf("verkle.journal")
686+
} else {
687+
fname = fmt.Sprintf("merkle.journal")
688+
}
689+
return filepath.Join(db.config.JournalDirectory, fname)
690+
}
691+
677692
// AccountHistory inspects the account history within the specified range.
678693
//
679694
// Start: State ID of the first history object for the query. 0 implies the first

triedb/pathdb/database_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ type tester struct {
125125
snapStorages map[common.Hash]map[common.Hash]map[common.Hash][]byte // Keyed by the hash of account address and the hash of storage key
126126
}
127127

128-
func newTester(t *testing.T, historyLimit uint64, isVerkle bool, layers int, enableIndex bool, journal string) *tester {
128+
func newTester(t *testing.T, historyLimit uint64, isVerkle bool, layers int, enableIndex bool, journalDir string) *tester {
129129
var (
130130
disk, _ = rawdb.Open(rawdb.NewMemoryDatabase(), rawdb.OpenOptions{Ancient: t.TempDir()})
131131
db = New(disk, &Config{
@@ -135,7 +135,7 @@ func newTester(t *testing.T, historyLimit uint64, isVerkle bool, layers int, ena
135135
StateCleanSize: 256 * 1024,
136136
WriteBufferSize: 256 * 1024,
137137
NoAsyncFlush: true,
138-
JournalPath: journal,
138+
JournalDirectory: journalDir,
139139
}, isVerkle)
140140

141141
obj = &tester{
@@ -619,14 +619,14 @@ func TestJournal(t *testing.T) {
619619
testJournal(t, filepath.Join(t.TempDir(), strconv.Itoa(rand.Intn(10000))))
620620
}
621621

622-
func testJournal(t *testing.T, journal string) {
622+
func testJournal(t *testing.T, journalDir string) {
623623
// Redefine the diff layer depth allowance for faster testing.
624624
maxDiffLayers = 4
625625
defer func() {
626626
maxDiffLayers = 128
627627
}()
628628

629-
tester := newTester(t, 0, false, 12, false, journal)
629+
tester := newTester(t, 0, false, 12, false, journalDir)
630630
defer tester.release()
631631

632632
if err := tester.db.Journal(tester.lastHash()); err != nil {
@@ -657,23 +657,23 @@ func TestCorruptedJournal(t *testing.T) {
657657
rawdb.WriteTrieJournal(db, blob)
658658
})
659659

660-
path := filepath.Join(t.TempDir(), strconv.Itoa(rand.Intn(10000)))
661-
testCorruptedJournal(t, path, func(_ ethdb.Database) {
662-
f, _ := os.OpenFile(path, os.O_WRONLY, 0644)
660+
directory := filepath.Join(t.TempDir(), strconv.Itoa(rand.Intn(10000)))
661+
testCorruptedJournal(t, directory, func(_ ethdb.Database) {
662+
f, _ := os.OpenFile(filepath.Join(directory, "merkle.journal"), os.O_WRONLY, 0644)
663663
f.WriteAt([]byte{0xa}, 0)
664664
f.Sync()
665665
f.Close()
666666
})
667667
}
668668

669-
func testCorruptedJournal(t *testing.T, journal string, modifyFn func(database ethdb.Database)) {
669+
func testCorruptedJournal(t *testing.T, journalDir string, modifyFn func(database ethdb.Database)) {
670670
// Redefine the diff layer depth allowance for faster testing.
671671
maxDiffLayers = 4
672672
defer func() {
673673
maxDiffLayers = 128
674674
}()
675675

676-
tester := newTester(t, 0, false, 12, false, journal)
676+
tester := newTester(t, 0, false, 12, false, journalDir)
677677
defer tester.release()
678678

679679
if err := tester.db.Journal(tester.lastHash()); err != nil {

triedb/pathdb/history_reader_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ func testHistoryReader(t *testing.T, historyLimit uint64) {
126126
}()
127127
//log.SetDefault(log.NewLogger(log.NewTerminalHandlerWithLevel(os.Stderr, log.LevelDebug, true)))
128128

129-
env := newTester(t, historyLimit, false, 64, true)
129+
env := newTester(t, historyLimit, false, 64, true, "")
130130
defer env.release()
131131
waitIndexing(env.db)
132132

0 commit comments

Comments
 (0)