Skip to content

Commit b537f3f

Browse files
committed
triedb/pathdb: migrate BSC journal for JournalFileType
1 parent d9549dc commit b537f3f

File tree

6 files changed

+46
-14
lines changed

6 files changed

+46
-14
lines changed

core/blockchain.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@ type CacheConfig struct {
171171
TriesInMemory uint64 // Number of recent tries to keep in memory
172172
StateHistory uint64 // Number of blocks from head whose state histories are reserved.
173173
StateScheme string // Scheme used to store ethereum states and merkle tree nodes on top
174+
JournalFilePath string
175+
JournalFile bool
174176

175177
SnapshotNoBuild bool // Whether the background generation is allowed
176178
SnapshotWait bool // Wait for snapshot construction on startup. TODO(karalabe): This is a dirty hack for testing, nuke it
@@ -197,6 +199,8 @@ func (c *CacheConfig) triedbConfig(isVerkle bool) *triedb.Config {
197199
StateHistory: c.StateHistory,
198200
CleanCacheSize: c.TrieCleanLimit * 1024 * 1024,
199201
WriteBufferSize: c.TrieDirtyLimit * 1024 * 1024,
202+
JournalFilePath: c.JournalFilePath,
203+
JournalFile: c.JournalFile,
200204
}
201205
}
202206
return config

eth/backend.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ import (
7171
gethversion "github.com/ethereum/go-ethereum/version"
7272
)
7373

74+
const (
75+
JournalFileName = "trie.journal"
76+
ChainData = "chaindata"
77+
)
78+
7479
var (
7580
MilestoneWhitelistedDelayTimer = metrics.NewRegisteredTimer("chain/milestone/whitelisteddelay", nil)
7681
)
@@ -228,6 +233,12 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
228233
rawdb.WriteDatabaseVersion(chainDb, core.BlockChainVersion)
229234
}
230235
}
236+
var (
237+
journalFilePath string
238+
path string
239+
)
240+
path = ChainData
241+
journalFilePath = stack.ResolvePath(path) + "/" + JournalFileName
231242
var (
232243
vmConfig = vm.Config{
233244
EnablePreimageRecording: config.EnablePreimageRecording,
@@ -244,6 +255,8 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
244255
StateScheme: scheme,
245256
TriesInMemory: config.TriesInMemory,
246257
ChainHistoryMode: config.HistoryMode,
258+
JournalFilePath: journalFilePath,
259+
JournalFile: config.JournalFileEnabled,
247260
}
248261
)
249262

eth/ethconfig/config.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ type Config struct {
116116
// State scheme represents the scheme used to store ethereum states and trie
117117
// nodes on top. It can be 'hash', 'path', or none which means use the scheme
118118
// consistent with persistent state.
119-
StateScheme string `toml:",omitempty"`
119+
StateScheme string `toml:",omitempty"`
120+
JournalFileEnabled bool // Whether the TrieJournal is stored using journal file
120121

121122
// RequiredBlocks is a set of block number -> hash mappings which must be in the
122123
// canonical chain of all remote peers. Setting the option makes geth verify the

eth/ethconfig/gen_config.go

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

internal/cli/server/config.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@ import (
88
"os"
99
"path/filepath"
1010
"runtime"
11+
godebug "runtime/debug"
1112
"strconv"
1213
"strings"
1314
"time"
1415

15-
godebug "runtime/debug"
16-
1716
"github.com/hashicorp/hcl/v2/hclsimple"
1817
"github.com/imdario/mergo"
1918
"github.com/mitchellh/go-homedir"
@@ -88,6 +87,8 @@ type Config struct {
8887
// state.scheme selects the Scheme to use for storing ethereum state ('hash' or 'path')
8988
StateScheme string `hcl:"state.scheme,optional" toml:"state.scheme,optional"`
9089

90+
JournalFileEnabled bool // Whether the TrieJournal is stored using journal file
91+
9192
// Snapshot enables the snapshot database mode
9293
Snapshot bool `hcl:"snapshot,optional" toml:"snapshot,optional"`
9394

@@ -1257,6 +1258,8 @@ func (c *Config) buildEth(stack *node.Node, accountManager *accounts.Manager) (*
12571258

12581259
n.EnableBlockTracking = c.Logging.EnableBlockTracking
12591260

1261+
n.JournalFileEnabled = c.JournalFileEnabled
1262+
12601263
return &n, nil
12611264
}
12621265

internal/cli/server/flags.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@ func (c *Command) Flags(config *Config) *flagset.Flagset {
104104
Value: &c.cliConfig.StateScheme,
105105
Default: c.cliConfig.StateScheme,
106106
})
107+
f.BoolFlag(&flagset.BoolFlag{
108+
Name: "journalfile",
109+
Usage: "Enable using journal file to store the TrieJournal instead of KVDB in pbss (default = false)",
110+
Value: &c.cliConfig.JournalFileEnabled,
111+
Default: c.cliConfig.JournalFileEnabled,
112+
})
107113
f.MapStringFlag(&flagset.MapStringFlag{
108114
Name: "eth.requiredblocks",
109115
Usage: "Comma separated block number-to-hash mappings to require for peering (<number>=<hash>)",

0 commit comments

Comments
 (0)