-
Notifications
You must be signed in to change notification settings - Fork 21.5k
cmd, core, eth, triedb/pathdb: track node origins in the path database #32418
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| // Copyright 2025 The go-ethereum Authors | ||
| // This file is part of the go-ethereum library. | ||
| // | ||
| // The go-ethereum library is free software: you can redistribute it and/or modify | ||
| // it under the terms of the GNU Lesser General Public License as published by | ||
| // the Free Software Foundation, either version 3 of the License, or | ||
| // (at your option) any later version. | ||
| // | ||
| // The go-ethereum library is distributed in the hope that it will be useful, | ||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| // GNU Lesser General Public License for more details. | ||
| // | ||
| // You should have received a copy of the GNU Lesser General Public License | ||
| // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. | ||
|
|
||
| package pathdb | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/ethereum/go-ethereum/common" | ||
| "github.com/ethereum/go-ethereum/log" | ||
| "github.com/ethereum/go-ethereum/params" | ||
| ) | ||
|
|
||
| const ( | ||
| // defaultTrieCleanSize is the default memory allowance of clean trie cache. | ||
| defaultTrieCleanSize = 16 * 1024 * 1024 | ||
|
|
||
| // defaultStateCleanSize is the default memory allowance of clean state cache. | ||
| defaultStateCleanSize = 16 * 1024 * 1024 | ||
|
|
||
| // maxBufferSize is the maximum memory allowance of node buffer. | ||
| // Too large buffer will cause the system to pause for a long | ||
| // time when write happens. Also, the largest batch that pebble can | ||
| // support is 4GB, node will panic if batch size exceeds this limit. | ||
| maxBufferSize = 256 * 1024 * 1024 | ||
|
|
||
| // defaultBufferSize is the default memory allowance of node buffer | ||
| // that aggregates the writes from above until it's flushed into the | ||
| // disk. It's meant to be used once the initial sync is finished. | ||
| // Do not increase the buffer size arbitrarily, otherwise the system | ||
| // pause time will increase when the database writes happen. | ||
| defaultBufferSize = 64 * 1024 * 1024 | ||
| ) | ||
|
|
||
| var ( | ||
| // maxDiffLayers is the maximum diff layers allowed in the layer tree. | ||
| maxDiffLayers = 128 | ||
| ) | ||
|
|
||
| // Defaults contains default settings for Ethereum mainnet. | ||
| var Defaults = &Config{ | ||
| StateHistory: params.FullImmutabilityThreshold, | ||
| EnableStateIndexing: false, | ||
| TrieCleanSize: defaultTrieCleanSize, | ||
| StateCleanSize: defaultStateCleanSize, | ||
| WriteBufferSize: defaultBufferSize, | ||
| } | ||
|
|
||
| // ReadOnly is the config in order to open database in read only mode. | ||
| var ReadOnly = &Config{ | ||
| ReadOnly: true, | ||
| TrieCleanSize: defaultTrieCleanSize, | ||
| StateCleanSize: defaultStateCleanSize, | ||
| } | ||
|
|
||
| // Config contains the settings for database. | ||
| type Config struct { | ||
| StateHistory uint64 // Number of recent blocks to maintain state history for, 0: full chain | ||
| EnableStateIndexing bool // Whether to enable state history indexing for external state access | ||
| TrieCleanSize int // Maximum memory allowance (in bytes) for caching clean trie data | ||
| StateCleanSize int // Maximum memory allowance (in bytes) for caching clean state data | ||
| WriteBufferSize int // Maximum memory allowance (in bytes) for write buffer | ||
| ReadOnly bool // Flag whether the database is opened in read only mode | ||
| JournalDirectory string // Absolute path of journal directory (null means the journal data is persisted in key-value store) | ||
|
|
||
| // Testing configurations | ||
| SnapshotNoBuild bool // Flag Whether the state generation is disabled | ||
| NoAsyncFlush bool // Flag whether the background buffer flushing is disabled | ||
| NoAsyncGeneration bool // Flag whether the background generation is disabled | ||
| } | ||
|
|
||
| // sanitize checks the provided user configurations and changes anything that's | ||
| // unreasonable or unworkable. | ||
| func (c *Config) sanitize() *Config { | ||
| conf := *c | ||
| if conf.WriteBufferSize > maxBufferSize { | ||
| log.Warn("Sanitizing invalid node buffer size", "provided", common.StorageSize(conf.WriteBufferSize), "updated", common.StorageSize(maxBufferSize)) | ||
| conf.WriteBufferSize = maxBufferSize | ||
| } | ||
| return &conf | ||
| } | ||
|
|
||
| // fields returns a list of attributes of config for printing. | ||
| func (c *Config) fields() []interface{} { | ||
| var list []interface{} | ||
| if c.ReadOnly { | ||
| list = append(list, "readonly", true) | ||
| } | ||
| list = append(list, "triecache", common.StorageSize(c.TrieCleanSize)) | ||
| list = append(list, "statecache", common.StorageSize(c.StateCleanSize)) | ||
| list = append(list, "buffer", common.StorageSize(c.WriteBufferSize)) | ||
|
|
||
| if c.StateHistory == 0 { | ||
| list = append(list, "state-history", "entire chain") | ||
| } else { | ||
| list = append(list, "state-history", fmt.Sprintf("last %d blocks", c.StateHistory)) | ||
| } | ||
| if c.EnableStateIndexing { | ||
| list = append(list, "index-history", true) | ||
| } | ||
| if c.JournalDirectory != "" { | ||
| list = append(list, "journal-dir", c.JournalDirectory) | ||
| } | ||
| return list | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think we should sanitize the state history flag as well? Limit it to 90k or something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No no, state history is not only for deep reorg resilience, but also the data for historical state.
Normally people will choose to keep the full history since the genesis with
statehistory=0.