mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-24 05:36:46 +00:00
all: polish
This commit is contained in:
parent
1abfb07782
commit
f7332e9d6e
9 changed files with 25 additions and 42 deletions
|
|
@ -2221,7 +2221,7 @@ func MakeChain(ctx *cli.Context, stack *node.Node, readonly bool) (*core.BlockCh
|
||||||
TrieJournalDirectory: stack.ResolvePath("triedb"),
|
TrieJournalDirectory: stack.ResolvePath("triedb"),
|
||||||
|
|
||||||
// Enable state size tracking if enabled
|
// Enable state size tracking if enabled
|
||||||
EnableStateSizeTracking: ctx.Bool(StateSizeTrackingFlag.Name),
|
StateSizeTracking: ctx.Bool(StateSizeTrackingFlag.Name),
|
||||||
}
|
}
|
||||||
if options.ArchiveMode && !options.Preimages {
|
if options.ArchiveMode && !options.Preimages {
|
||||||
options.Preimages = true
|
options.Preimages = true
|
||||||
|
|
|
||||||
|
|
@ -197,8 +197,8 @@ type BlockChainConfig struct {
|
||||||
// If the value is -1, indexing is disabled.
|
// If the value is -1, indexing is disabled.
|
||||||
TxLookupLimit int64
|
TxLookupLimit int64
|
||||||
|
|
||||||
// EnableStateSizeTracking indicates whether the state size tracking is enabled.
|
// StateSizeTracking indicates whether the state size tracking is enabled.
|
||||||
EnableStateSizeTracking bool
|
StateSizeTracking bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// DefaultConfig returns the default config.
|
// DefaultConfig returns the default config.
|
||||||
|
|
@ -532,7 +532,7 @@ func NewBlockChain(db ethdb.Database, genesis *Genesis, engine consensus.Engine,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start state size tracker
|
// Start state size tracker
|
||||||
if bc.cfg.EnableStateSizeTracking {
|
if bc.cfg.StateSizeTracking {
|
||||||
stateSizer, err := state.NewSizeTracker(bc.db, bc.triedb)
|
stateSizer, err := state.NewSizeTracker(bc.db, bc.triedb)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
bc.stateSizer = stateSizer
|
bc.stateSizer = stateSizer
|
||||||
|
|
|
||||||
|
|
@ -292,6 +292,7 @@ func (t *SizeTracker) run() {
|
||||||
case u := <-t.updateCh:
|
case u := <-t.updateCh:
|
||||||
base, found := stats[u.originRoot]
|
base, found := stats[u.originRoot]
|
||||||
if !found {
|
if !found {
|
||||||
|
log.Debug("Ignored the state size without parent", "parent", u.originRoot, "root", u.root, "number", u.blockNumber)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
diff, err := calSizeStats(u)
|
diff, err := calSizeStats(u)
|
||||||
|
|
@ -352,8 +353,6 @@ wait:
|
||||||
done chan buildResult
|
done chan buildResult
|
||||||
)
|
)
|
||||||
|
|
||||||
t.triedb.SetForceFlush(true)
|
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case u := <-t.updateCh:
|
case u := <-t.updateCh:
|
||||||
|
|
@ -378,8 +377,6 @@ wait:
|
||||||
log.Info("Measuring persistent state size", "root", root.Hex(), "number", entry.blockNumber)
|
log.Info("Measuring persistent state size", "root", root.Hex(), "number", entry.blockNumber)
|
||||||
|
|
||||||
case result := <-done:
|
case result := <-done:
|
||||||
t.triedb.SetForceFlush(false)
|
|
||||||
|
|
||||||
if result.err != nil {
|
if result.err != nil {
|
||||||
return nil, result.err
|
return nil, result.err
|
||||||
}
|
}
|
||||||
|
|
@ -410,6 +407,7 @@ wait:
|
||||||
|
|
||||||
// Set initial latest stats
|
// Set initial latest stats
|
||||||
stats[result.root] = result.stat
|
stats[result.root] = result.stat
|
||||||
|
|
||||||
t.mu.Lock()
|
t.mu.Lock()
|
||||||
t.latestStats = &result.stat
|
t.latestStats = &result.stat
|
||||||
t.mu.Unlock()
|
t.mu.Unlock()
|
||||||
|
|
@ -561,14 +559,16 @@ func (t *SizeTracker) iterateTable(closed chan struct{}, prefix []byte, name str
|
||||||
return count, bytes, nil
|
return count, bytes, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// iterateTableParallel performs parallel iteration over a table by splitting into hex ranges
|
// iterateTableParallel performs parallel iteration over a table by splitting into
|
||||||
// For storage tables, it splits on the first byte of the account hash (after the prefix)
|
// hex ranges. For storage tables, it splits on the first byte of the account hash
|
||||||
|
// (after the prefix).
|
||||||
func (t *SizeTracker) iterateTableParallel(closed chan struct{}, prefix []byte, name string) (int64, int64, error) {
|
func (t *SizeTracker) iterateTableParallel(closed chan struct{}, prefix []byte, name string) (int64, int64, error) {
|
||||||
var (
|
var (
|
||||||
start = time.Now()
|
|
||||||
workers = runtime.NumCPU()
|
|
||||||
totalCount int64
|
totalCount int64
|
||||||
totalBytes int64
|
totalBytes int64
|
||||||
|
|
||||||
|
start = time.Now()
|
||||||
|
workers = runtime.NumCPU()
|
||||||
group errgroup.Group
|
group errgroup.Group
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
)
|
)
|
||||||
|
|
@ -598,11 +598,9 @@ func (t *SizeTracker) iterateTableParallel(closed chan struct{}, prefix []byte,
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := group.Wait(); err != nil {
|
if err := group.Wait(); err != nil {
|
||||||
return 0, 0, err
|
return 0, 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Info("Finished parallel state iteration", "category", name, "count", totalCount, "size", common.StorageSize(totalBytes), "elapsed", common.PrettyDuration(time.Since(start)))
|
log.Info("Finished parallel state iteration", "category", name, "count", totalCount, "size", common.StorageSize(totalBytes), "elapsed", common.PrettyDuration(time.Since(start)))
|
||||||
return totalCount, totalBytes, nil
|
return totalCount, totalBytes, nil
|
||||||
}
|
}
|
||||||
|
|
@ -611,5 +609,6 @@ func (t *SizeTracker) iterateTableParallel(closed chan struct{}, prefix []byte,
|
||||||
func (t *SizeTracker) GetLatestStats() *SizeStats {
|
func (t *SizeTracker) GetLatestStats() *SizeStats {
|
||||||
t.mu.RLock()
|
t.mu.RLock()
|
||||||
defer t.mu.RUnlock()
|
defer t.mu.RUnlock()
|
||||||
|
|
||||||
return t.latestStats
|
return t.latestStats
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -451,12 +451,10 @@ func (api *DebugAPI) StateSize() (interface{}, error) {
|
||||||
if sizer == nil {
|
if sizer == nil {
|
||||||
return nil, errors.New("state size tracker is not enabled")
|
return nil, errors.New("state size tracker is not enabled")
|
||||||
}
|
}
|
||||||
|
|
||||||
stats := sizer.GetLatestStats()
|
stats := sizer.GetLatestStats()
|
||||||
if stats == nil {
|
if stats == nil {
|
||||||
return nil, errors.New("state size statistics are not ready yet")
|
return nil, errors.New("state size statistics are not ready yet")
|
||||||
}
|
}
|
||||||
|
|
||||||
return map[string]interface{}{
|
return map[string]interface{}{
|
||||||
"stateRoot": stats.StateRoot,
|
"stateRoot": stats.StateRoot,
|
||||||
"blockNumber": hexutil.Uint64(stats.BlockNumber),
|
"blockNumber": hexutil.Uint64(stats.BlockNumber),
|
||||||
|
|
|
||||||
|
|
@ -241,7 +241,7 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
|
||||||
// - DATADIR/triedb/merkle.journal
|
// - DATADIR/triedb/merkle.journal
|
||||||
// - DATADIR/triedb/verkle.journal
|
// - DATADIR/triedb/verkle.journal
|
||||||
TrieJournalDirectory: stack.ResolvePath("triedb"),
|
TrieJournalDirectory: stack.ResolvePath("triedb"),
|
||||||
EnableStateSizeTracking: config.EnableStateSizeTracking,
|
StateSizeTracking: config.EnableStateSizeTracking,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
if config.VMTrace != "" {
|
if config.VMTrace != "" {
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,7 @@ func (c Config) MarshalTOML() (interface{}, error) {
|
||||||
BlobPool blobpool.Config
|
BlobPool blobpool.Config
|
||||||
GPO gasprice.Config
|
GPO gasprice.Config
|
||||||
EnablePreimageRecording bool
|
EnablePreimageRecording bool
|
||||||
|
EnableStateSizeTracking bool
|
||||||
VMTrace string
|
VMTrace string
|
||||||
VMTraceJsonConfig string
|
VMTraceJsonConfig string
|
||||||
RPCGasCap uint64
|
RPCGasCap uint64
|
||||||
|
|
@ -90,6 +91,7 @@ func (c Config) MarshalTOML() (interface{}, error) {
|
||||||
enc.BlobPool = c.BlobPool
|
enc.BlobPool = c.BlobPool
|
||||||
enc.GPO = c.GPO
|
enc.GPO = c.GPO
|
||||||
enc.EnablePreimageRecording = c.EnablePreimageRecording
|
enc.EnablePreimageRecording = c.EnablePreimageRecording
|
||||||
|
enc.EnableStateSizeTracking = c.EnableStateSizeTracking
|
||||||
enc.VMTrace = c.VMTrace
|
enc.VMTrace = c.VMTrace
|
||||||
enc.VMTraceJsonConfig = c.VMTraceJsonConfig
|
enc.VMTraceJsonConfig = c.VMTraceJsonConfig
|
||||||
enc.RPCGasCap = c.RPCGasCap
|
enc.RPCGasCap = c.RPCGasCap
|
||||||
|
|
@ -135,6 +137,7 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error {
|
||||||
BlobPool *blobpool.Config
|
BlobPool *blobpool.Config
|
||||||
GPO *gasprice.Config
|
GPO *gasprice.Config
|
||||||
EnablePreimageRecording *bool
|
EnablePreimageRecording *bool
|
||||||
|
EnableStateSizeTracking *bool
|
||||||
VMTrace *string
|
VMTrace *string
|
||||||
VMTraceJsonConfig *string
|
VMTraceJsonConfig *string
|
||||||
RPCGasCap *uint64
|
RPCGasCap *uint64
|
||||||
|
|
@ -243,6 +246,9 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error {
|
||||||
if dec.EnablePreimageRecording != nil {
|
if dec.EnablePreimageRecording != nil {
|
||||||
c.EnablePreimageRecording = *dec.EnablePreimageRecording
|
c.EnablePreimageRecording = *dec.EnablePreimageRecording
|
||||||
}
|
}
|
||||||
|
if dec.EnableStateSizeTracking != nil {
|
||||||
|
c.EnableStateSizeTracking = *dec.EnableStateSizeTracking
|
||||||
|
}
|
||||||
if dec.VMTrace != nil {
|
if dec.VMTrace != nil {
|
||||||
c.VMTrace = *dec.VMTrace
|
c.VMTrace = *dec.VMTrace
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -384,12 +384,3 @@ func (db *Database) SnapshotCompleted() bool {
|
||||||
}
|
}
|
||||||
return pdb.SnapshotCompleted()
|
return pdb.SnapshotCompleted()
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetForceFlush enables or disables the pathdb to flush any pending changes to disk
|
|
||||||
// immediately, regardless of the buffer size threshold. This can be used to accelerate
|
|
||||||
// state sizer initialization by making buffered state changes visible on disk.
|
|
||||||
func (db *Database) SetForceFlush(enabled bool) {
|
|
||||||
if pdb, ok := db.backend.(*pathdb.Database); ok {
|
|
||||||
pdb.SetForceFlush(enabled)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -136,9 +136,7 @@ type Database struct {
|
||||||
|
|
||||||
stateFreezer ethdb.ResettableAncientStore // Freezer for storing state histories, nil possible in tests
|
stateFreezer ethdb.ResettableAncientStore // Freezer for storing state histories, nil possible in tests
|
||||||
stateIndexer *historyIndexer // History indexer historical state data, nil possible
|
stateIndexer *historyIndexer // History indexer historical state data, nil possible
|
||||||
|
|
||||||
lock sync.RWMutex // Lock to prevent mutations from happening at the same time
|
lock sync.RWMutex // Lock to prevent mutations from happening at the same time
|
||||||
forceFlush bool // Flag to force buffer flush regardless of size
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// New attempts to load an already existing layer from a persistent key-value
|
// New attempts to load an already existing layer from a persistent key-value
|
||||||
|
|
@ -361,15 +359,6 @@ func (db *Database) Commit(root common.Hash, report bool) error {
|
||||||
return db.tree.cap(root, 0)
|
return db.tree.cap(root, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetForceFlush enables or disables force flushing for the next state update.
|
|
||||||
func (db *Database) SetForceFlush(enabled bool) {
|
|
||||||
db.lock.Lock()
|
|
||||||
defer db.lock.Unlock()
|
|
||||||
|
|
||||||
db.forceFlush = enabled
|
|
||||||
log.Info("Set triedb force flush for next pathdb update", "enabled", enabled)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Disable deactivates the database and invalidates all available state layers
|
// Disable deactivates the database and invalidates all available state layers
|
||||||
// as stale to prevent access to the persistent state, which is in the syncing
|
// as stale to prevent access to the persistent state, which is in the syncing
|
||||||
// stage.
|
// stage.
|
||||||
|
|
|
||||||
|
|
@ -417,7 +417,7 @@ func (dl *diskLayer) commit(bottom *diffLayer, force bool) (*diskLayer, error) {
|
||||||
|
|
||||||
// Terminate the background state snapshot generation before mutating the
|
// Terminate the background state snapshot generation before mutating the
|
||||||
// persistent state.
|
// persistent state.
|
||||||
if combined.full() || force || flush || dl.db.forceFlush {
|
if combined.full() || force || flush {
|
||||||
// Wait until the previous frozen buffer is fully flushed
|
// Wait until the previous frozen buffer is fully flushed
|
||||||
if dl.frozen != nil {
|
if dl.frozen != nil {
|
||||||
if err := dl.frozen.waitFlush(); err != nil {
|
if err := dl.frozen.waitFlush(); err != nil {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue