@@ -31,37 +31,10 @@ import (
3131 "github.com/ethereum/go-ethereum/crypto"
3232 "github.com/ethereum/go-ethereum/ethdb"
3333 "github.com/ethereum/go-ethereum/log"
34- "github.com/ethereum/go-ethereum/params"
3534 "github.com/ethereum/go-ethereum/trie/trienode"
3635 "github.com/ethereum/go-verkle"
3736)
3837
39- const (
40- // defaultTrieCleanSize is the default memory allowance of clean trie cache.
41- defaultTrieCleanSize = 16 * 1024 * 1024
42-
43- // defaultStateCleanSize is the default memory allowance of clean state cache.
44- defaultStateCleanSize = 16 * 1024 * 1024
45-
46- // maxBufferSize is the maximum memory allowance of node buffer.
47- // Too large buffer will cause the system to pause for a long
48- // time when write happens. Also, the largest batch that pebble can
49- // support is 4GB, node will panic if batch size exceeds this limit.
50- maxBufferSize = 256 * 1024 * 1024
51-
52- // defaultBufferSize is the default memory allowance of node buffer
53- // that aggregates the writes from above until it's flushed into the
54- // disk. It's meant to be used once the initial sync is finished.
55- // Do not increase the buffer size arbitrarily, otherwise the system
56- // pause time will increase when the database writes happen.
57- defaultBufferSize = 64 * 1024 * 1024
58- )
59-
60- var (
61- // maxDiffLayers is the maximum diff layers allowed in the layer tree.
62- maxDiffLayers = 128
63- )
64-
6538// layer is the interface implemented by all state layers which includes some
6639// public methods and some additional methods for internal usage.
6740type layer interface {
@@ -105,76 +78,14 @@ type layer interface {
10578 // the provided dirty trie nodes along with the state change set.
10679 //
10780 // Note, the maps are retained by the method to avoid copying everything.
108- update (root common.Hash , id uint64 , block uint64 , nodes * nodeSet , states * StateSetWithOrigin ) * diffLayer
81+ update (root common.Hash , id uint64 , block uint64 , nodes * nodeSetWithOrigin , states * StateSetWithOrigin ) * diffLayer
10982
11083 // journal commits an entire diff hierarchy to disk into a single journal entry.
11184 // This is meant to be used during shutdown to persist the layer without
11285 // flattening everything down (bad for reorgs).
11386 journal (w io.Writer ) error
11487}
11588
116- // Config contains the settings for database.
117- type Config struct {
118- StateHistory uint64 // Number of recent blocks to maintain state history for
119- EnableStateIndexing bool // Whether to enable state history indexing for external state access
120- TrieCleanSize int // Maximum memory allowance (in bytes) for caching clean trie nodes
121- StateCleanSize int // Maximum memory allowance (in bytes) for caching clean state data
122- WriteBufferSize int // Maximum memory allowance (in bytes) for write buffer
123- ReadOnly bool // Flag whether the database is opened in read only mode
124- JournalDirectory string // Absolute path of journal directory (null means the journal data is persisted in key-value store)
125-
126- // Testing configurations
127- SnapshotNoBuild bool // Flag Whether the state generation is allowed
128- NoAsyncFlush bool // Flag whether the background buffer flushing is allowed
129- NoAsyncGeneration bool // Flag whether the background generation is allowed
130- }
131-
132- // sanitize checks the provided user configurations and changes anything that's
133- // unreasonable or unworkable.
134- func (c * Config ) sanitize () * Config {
135- conf := * c
136- if conf .WriteBufferSize > maxBufferSize {
137- log .Warn ("Sanitizing invalid node buffer size" , "provided" , common .StorageSize (conf .WriteBufferSize ), "updated" , common .StorageSize (maxBufferSize ))
138- conf .WriteBufferSize = maxBufferSize
139- }
140- return & conf
141- }
142-
143- // fields returns a list of attributes of config for printing.
144- func (c * Config ) fields () []interface {} {
145- var list []interface {}
146- if c .ReadOnly {
147- list = append (list , "readonly" , true )
148- }
149- if c .SnapshotNoBuild {
150- list = append (list , "snapshot" , false )
151- }
152- list = append (list , "triecache" , common .StorageSize (c .TrieCleanSize ))
153- list = append (list , "statecache" , common .StorageSize (c .StateCleanSize ))
154- list = append (list , "buffer" , common .StorageSize (c .WriteBufferSize ))
155-
156- if c .StateHistory == 0 {
157- list = append (list , "history" , "entire chain" )
158- } else {
159- list = append (list , "history" , fmt .Sprintf ("last %d blocks" , c .StateHistory ))
160- }
161- if c .JournalDirectory != "" {
162- list = append (list , "journal-dir" , c .JournalDirectory )
163- }
164- return list
165- }
166-
167- // Defaults contains default settings for Ethereum mainnet.
168- var Defaults = & Config {
169- StateHistory : params .FullImmutabilityThreshold ,
170- TrieCleanSize : defaultTrieCleanSize ,
171- StateCleanSize : defaultStateCleanSize ,
172- WriteBufferSize : defaultBufferSize ,
173- }
174-
175- // ReadOnly is the config in order to open database in read only mode.
176- var ReadOnly = & Config {ReadOnly : true }
177-
17889// nodeHasher is the function to compute the hash of supplied node blob.
17990type nodeHasher func ([]byte ) (common.Hash , error )
18091
@@ -422,7 +333,8 @@ func (db *Database) Update(root common.Hash, parentRoot common.Hash, block uint6
422333 if err := db .modifyAllowed (); err != nil {
423334 return err
424335 }
425- if err := db .tree .add (root , parentRoot , block , nodes , states ); err != nil {
336+ // TODO(rjl493456442) tracking the origins in the following PRs.
337+ if err := db .tree .add (root , parentRoot , block , NewNodeSetWithOrigin (nodes .Nodes (), nil ), states ); err != nil {
426338 return err
427339 }
428340 // Keep 128 diff layers in the memory, persistent layer is 129th.
0 commit comments