@@ -31,37 +31,10 @@ import (
31
31
"github.com/ethereum/go-ethereum/crypto"
32
32
"github.com/ethereum/go-ethereum/ethdb"
33
33
"github.com/ethereum/go-ethereum/log"
34
- "github.com/ethereum/go-ethereum/params"
35
34
"github.com/ethereum/go-ethereum/trie/trienode"
36
35
"github.com/ethereum/go-verkle"
37
36
)
38
37
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
-
65
38
// layer is the interface implemented by all state layers which includes some
66
39
// public methods and some additional methods for internal usage.
67
40
type layer interface {
@@ -105,76 +78,14 @@ type layer interface {
105
78
// the provided dirty trie nodes along with the state change set.
106
79
//
107
80
// 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
109
82
110
83
// journal commits an entire diff hierarchy to disk into a single journal entry.
111
84
// This is meant to be used during shutdown to persist the layer without
112
85
// flattening everything down (bad for reorgs).
113
86
journal (w io.Writer ) error
114
87
}
115
88
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
-
178
89
// nodeHasher is the function to compute the hash of supplied node blob.
179
90
type nodeHasher func ([]byte ) (common.Hash , error )
180
91
@@ -419,7 +330,8 @@ func (db *Database) Update(root common.Hash, parentRoot common.Hash, block uint6
419
330
if err := db .modifyAllowed (); err != nil {
420
331
return err
421
332
}
422
- if err := db .tree .add (root , parentRoot , block , nodes , states ); err != nil {
333
+ // TODO(rjl493456442) tracking the origins in the following PRs.
334
+ if err := db .tree .add (root , parentRoot , block , NewNodeSetWithOrigin (nodes .Nodes (), nil ), states ); err != nil {
423
335
return err
424
336
}
425
337
// Keep 128 diff layers in the memory, persistent layer is 129th.
0 commit comments