Skip to content

Commit

Permalink
feat: add recover node buffer list for pathdb
Browse files Browse the repository at this point in the history
  • Loading branch information
VM committed Jul 26, 2024
1 parent 3adcb84 commit a83c03e
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 82 deletions.
1 change: 0 additions & 1 deletion cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ var (
utils.EnableProofKeeperFlag,
utils.KeepProofBlockSpanFlag,
utils.JournalFileFlag,
utils.EnableRecoverNodeBufferListFlag,
utils.LightServeFlag, // deprecated
utils.LightIngressFlag, // deprecated
utils.LightEgressFlag, // deprecated
Expand Down
9 changes: 0 additions & 9 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,12 +346,6 @@ var (
Value: false,
Category: flags.StateCategory,
}
EnableRecoverNodeBufferListFlag = &cli.BoolFlag{
Name: "pathdb.recovernodebufferlist",
Usage: "Enable recovering node buffer list",
Value: false,
Category: flags.StateCategory,
}
StateHistoryFlag = &cli.Uint64Flag{
Name: "history.state",
Usage: "Number of recent blocks to retain state history for (default = 90,000 blocks, 0 = entire chain)",
Expand Down Expand Up @@ -1893,9 +1887,6 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
if ctx.IsSet(JournalFileFlag.Name) {
cfg.JournalFileEnabled = true
}
if ctx.IsSet(EnableRecoverNodeBufferListFlag.Name) {
cfg.EnableRecoverNodeBufferList = true
}

if ctx.String(GCModeFlag.Name) == "archive" && cfg.TransactionHistory != 0 {
cfg.TransactionHistory = 0
Expand Down
54 changes: 26 additions & 28 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,25 +149,24 @@ const (
// CacheConfig contains the configuration values for the trie database
// and state snapshot these are resident in a blockchain.
type CacheConfig struct {
TrieCleanLimit int // Memory allowance (MB) to use for caching trie nodes in memory
TrieCleanNoPrefetch bool // Whether to disable heuristic state prefetching for followup blocks
TrieDirtyLimit int // Memory limit (MB) at which to start flushing dirty trie nodes to disk
TrieDirtyDisabled bool // Whether to disable trie write caching and GC altogether (archive node)
TrieTimeLimit time.Duration // Time limit after which to flush the current in-memory trie to disk
SnapshotLimit int // Memory allowance (MB) to use for caching snapshot entries in memory
Preimages bool // Whether to store preimage of trie key to the disk
NoTries bool // Insecure settings. Do not have any tries in databases if enabled.
StateHistory uint64 // Number of blocks from head whose state histories are reserved.
StateScheme string // Scheme used to store ethereum states and merkle tree nodes on top
PathNodeBuffer pathdb.NodeBufferType // Type of trienodebuffer to cache trie nodes in disklayer
ProposeBlockInterval uint64 // Propose block to L1 block interval.
EnableProofKeeper bool // Whether to enable proof keeper
KeepProofBlockSpan uint64 // Block span of keep proof
SnapshotNoBuild bool // Whether the background generation is allowed
SnapshotWait bool // Wait for snapshot construction on startup. TODO(karalabe): This is a dirty hack for testing, nuke it
JournalFilePath string // The file path to journal pathdb diff layers
JournalFile bool // Whether to enable journal file
EnableRecoverNodeBufferList bool // Whether enable recover node buffer list.
TrieCleanLimit int // Memory allowance (MB) to use for caching trie nodes in memory
TrieCleanNoPrefetch bool // Whether to disable heuristic state prefetching for followup blocks
TrieDirtyLimit int // Memory limit (MB) at which to start flushing dirty trie nodes to disk
TrieDirtyDisabled bool // Whether to disable trie write caching and GC altogether (archive node)
TrieTimeLimit time.Duration // Time limit after which to flush the current in-memory trie to disk
SnapshotLimit int // Memory allowance (MB) to use for caching snapshot entries in memory
Preimages bool // Whether to store preimage of trie key to the disk
NoTries bool // Insecure settings. Do not have any tries in databases if enabled.
StateHistory uint64 // Number of blocks from head whose state histories are reserved.
StateScheme string // Scheme used to store ethereum states and merkle tree nodes on top
PathNodeBuffer pathdb.NodeBufferType // Type of trienodebuffer to cache trie nodes in disklayer
ProposeBlockInterval uint64 // Propose block to L1 block interval.
EnableProofKeeper bool // Whether to enable proof keeper
KeepProofBlockSpan uint64 // Block span of keep proof
SnapshotNoBuild bool // Whether the background generation is allowed
SnapshotWait bool // Wait for snapshot construction on startup. TODO(karalabe): This is a dirty hack for testing, nuke it
JournalFilePath string // The file path to journal pathdb diff layers
JournalFile bool // Whether to enable journal file

TrieCommitInterval uint64 // Define a block height interval, commit trie every TrieCommitInterval block height.
}
Expand All @@ -185,15 +184,14 @@ func (c *CacheConfig) triedbConfig(keepFunc pathdb.NotifyKeepFunc) *trie.Config
}
if c.StateScheme == rawdb.PathScheme {
config.PathDB = &pathdb.Config{
TrieNodeBufferType: c.PathNodeBuffer,
StateHistory: c.StateHistory,
CleanCacheSize: c.TrieCleanLimit * 1024 * 1024,
DirtyCacheSize: c.TrieDirtyLimit * 1024 * 1024,
ProposeBlockInterval: c.ProposeBlockInterval,
NotifyKeep: keepFunc,
JournalFilePath: c.JournalFilePath,
JournalFile: c.JournalFile,
EnableRecoverNodeBufferList: c.EnableRecoverNodeBufferList,
TrieNodeBufferType: c.PathNodeBuffer,
StateHistory: c.StateHistory,
CleanCacheSize: c.TrieCleanLimit * 1024 * 1024,
DirtyCacheSize: c.TrieDirtyLimit * 1024 * 1024,
ProposeBlockInterval: c.ProposeBlockInterval,
NotifyKeep: keepFunc,
JournalFilePath: c.JournalFilePath,
JournalFile: c.JournalFile,
}
}
return config
Expand Down
35 changes: 17 additions & 18 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,24 +228,23 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
EnableOpcodeOptimizations: config.EnableOpcodeOptimizing,
}
cacheConfig = &core.CacheConfig{
TrieCleanLimit: config.TrieCleanCache,
TrieCleanNoPrefetch: config.NoPrefetch,
TrieDirtyLimit: config.TrieDirtyCache,
TrieDirtyDisabled: config.NoPruning,
TrieTimeLimit: config.TrieTimeout,
SnapshotLimit: config.SnapshotCache,
Preimages: config.Preimages,
NoTries: config.NoTries,
StateHistory: config.StateHistory,
StateScheme: config.StateScheme,
TrieCommitInterval: config.TrieCommitInterval,
PathNodeBuffer: config.PathNodeBuffer,
ProposeBlockInterval: config.ProposeBlockInterval,
EnableProofKeeper: config.EnableProofKeeper,
KeepProofBlockSpan: config.KeepProofBlockSpan,
JournalFilePath: journalFilePath,
JournalFile: config.JournalFileEnabled,
EnableRecoverNodeBufferList: config.EnableRecoverNodeBufferList,
TrieCleanLimit: config.TrieCleanCache,
TrieCleanNoPrefetch: config.NoPrefetch,
TrieDirtyLimit: config.TrieDirtyCache,
TrieDirtyDisabled: config.NoPruning,
TrieTimeLimit: config.TrieTimeout,
SnapshotLimit: config.SnapshotCache,
Preimages: config.Preimages,
NoTries: config.NoTries,
StateHistory: config.StateHistory,
StateScheme: config.StateScheme,
TrieCommitInterval: config.TrieCommitInterval,
PathNodeBuffer: config.PathNodeBuffer,
ProposeBlockInterval: config.ProposeBlockInterval,
EnableProofKeeper: config.EnableProofKeeper,
KeepProofBlockSpan: config.KeepProofBlockSpan,
JournalFilePath: journalFilePath,
JournalFile: config.JournalFileEnabled,
}
)
// Override the chain config with provided settings.
Expand Down
13 changes: 6 additions & 7 deletions eth/ethconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,12 @@ type Config struct {
// State scheme represents the scheme used to store ethereum states and trie
// nodes on top. It can be 'hash', 'path', or none which means use the scheme
// consistent with persistent state.
StateScheme string `toml:",omitempty"`
PathNodeBuffer pathdb.NodeBufferType `toml:",omitempty"` // Type of trienodebuffer to cache trie nodes in disklayer
ProposeBlockInterval uint64 `toml:",omitempty"` // Keep the same with op-proposer propose block interval
EnableProofKeeper bool `toml:",omitempty"` // Whether to enable proof keeper
KeepProofBlockSpan uint64 `toml:",omitempty"` // Span block of keep proof
JournalFileEnabled bool `toml:",omitempty"` // Whether the TrieJournal is stored using journal file
EnableRecoverNodeBufferList bool `toml:",omitempty"` // Whether enable recover node buffer list.
StateScheme string `toml:",omitempty"`
PathNodeBuffer pathdb.NodeBufferType `toml:",omitempty"` // Type of trienodebuffer to cache trie nodes in disklayer
ProposeBlockInterval uint64 `toml:",omitempty"` // Keep the same with op-proposer propose block interval
EnableProofKeeper bool `toml:",omitempty"` // Whether to enable proof keeper
KeepProofBlockSpan uint64 `toml:",omitempty"` // Span block of keep proof
JournalFileEnabled bool `toml:",omitempty"` // Whether the TrieJournal is stored using journal file

// RequiredBlocks is a set of block number -> hash mappings which must be in the
// canonical chain of all remote peers. Setting the option makes geth verify the
Expand Down
6 changes: 0 additions & 6 deletions eth/ethconfig/gen_config.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 9 additions & 10 deletions trie/triedb/pathdb/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,15 @@ type layer interface {

// Config contains the settings for database.
type Config struct {
TrieNodeBufferType NodeBufferType // Type of trienodebuffer to cache trie nodes in disklayer
StateHistory uint64 // Number of recent blocks to maintain state history for
CleanCacheSize int // Maximum memory allowance (in bytes) for caching clean nodes
DirtyCacheSize int // Maximum memory allowance (in bytes) for caching dirty nodes
ReadOnly bool // Flag whether the database is opened in read only mode.
ProposeBlockInterval uint64 // Propose block to L1 block interval.
NotifyKeep NotifyKeepFunc // NotifyKeep is used to keep the proof which maybe queried by op-proposer.
JournalFilePath string // The journal file path
JournalFile bool // Whether to use journal file mode
EnableRecoverNodeBufferList bool // Whether enable recover node buffer list.
TrieNodeBufferType NodeBufferType // Type of trienodebuffer to cache trie nodes in disklayer
StateHistory uint64 // Number of recent blocks to maintain state history for
CleanCacheSize int // Maximum memory allowance (in bytes) for caching clean nodes
DirtyCacheSize int // Maximum memory allowance (in bytes) for caching dirty nodes
ReadOnly bool // Flag whether the database is opened in read only mode.
ProposeBlockInterval uint64 // Propose block to L1 block interval.
NotifyKeep NotifyKeepFunc // NotifyKeep is used to keep the proof which maybe queried by op-proposer.
JournalFilePath string // The journal file path
JournalFile bool // Whether to use journal file mode
}

// sanitize checks the provided user configurations and changes anything that's
Expand Down
3 changes: 1 addition & 2 deletions trie/triedb/pathdb/journal.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,7 @@ func (db *Database) loadLayers() layer {
dl *diskLayer
stateID = rawdb.ReadPersistentStateID(db.diskdb)
)
if (errors.Is(err, errMissJournal) || errors.Is(err, errUnmatchedJournal)) && db.config.EnableRecoverNodeBufferList &&
db.config.TrieNodeBufferType == NodeBufferList {
if (errors.Is(err, errMissJournal) || errors.Is(err, errUnmatchedJournal)) && db.config.TrieNodeBufferType == NodeBufferList {
start := time.Now()
if db.freezer == nil {
log.Crit("Use unopened freezer db to recover node buffer list")
Expand Down
1 change: 0 additions & 1 deletion trie/triedb/pathdb/nodebufferlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,6 @@ func (nf *nodebufferlist) createBlockInterval(startBlock, endBlock uint64) [][]u
return intervalBoundaries
}

// startStateID: persistentStateID+1, endStateID: freezerLength
func (nf *nodebufferlist) createStateInterval(freezer *rawdb.ResettableFreezer, startStateID, endStateID uint64,
blockIntervals [][]uint64) ([][]uint64, error) {
blockMap, err := readAllBlockNumbers(freezer, startStateID, endStateID)
Expand Down

0 comments on commit a83c03e

Please sign in to comment.