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"),
|
||||
|
||||
// Enable state size tracking if enabled
|
||||
EnableStateSizeTracking: ctx.Bool(StateSizeTrackingFlag.Name),
|
||||
StateSizeTracking: ctx.Bool(StateSizeTrackingFlag.Name),
|
||||
}
|
||||
if options.ArchiveMode && !options.Preimages {
|
||||
options.Preimages = true
|
||||
|
|
|
|||
|
|
@ -197,8 +197,8 @@ type BlockChainConfig struct {
|
|||
// If the value is -1, indexing is disabled.
|
||||
TxLookupLimit int64
|
||||
|
||||
// EnableStateSizeTracking indicates whether the state size tracking is enabled.
|
||||
EnableStateSizeTracking bool
|
||||
// StateSizeTracking indicates whether the state size tracking is enabled.
|
||||
StateSizeTracking bool
|
||||
}
|
||||
|
||||
// DefaultConfig returns the default config.
|
||||
|
|
@ -532,7 +532,7 @@ func NewBlockChain(db ethdb.Database, genesis *Genesis, engine consensus.Engine,
|
|||
}
|
||||
|
||||
// Start state size tracker
|
||||
if bc.cfg.EnableStateSizeTracking {
|
||||
if bc.cfg.StateSizeTracking {
|
||||
stateSizer, err := state.NewSizeTracker(bc.db, bc.triedb)
|
||||
if err == nil {
|
||||
bc.stateSizer = stateSizer
|
||||
|
|
|
|||
|
|
@ -292,6 +292,7 @@ func (t *SizeTracker) run() {
|
|||
case u := <-t.updateCh:
|
||||
base, found := stats[u.originRoot]
|
||||
if !found {
|
||||
log.Debug("Ignored the state size without parent", "parent", u.originRoot, "root", u.root, "number", u.blockNumber)
|
||||
continue
|
||||
}
|
||||
diff, err := calSizeStats(u)
|
||||
|
|
@ -352,8 +353,6 @@ wait:
|
|||
done chan buildResult
|
||||
)
|
||||
|
||||
t.triedb.SetForceFlush(true)
|
||||
|
||||
for {
|
||||
select {
|
||||
case u := <-t.updateCh:
|
||||
|
|
@ -378,8 +377,6 @@ wait:
|
|||
log.Info("Measuring persistent state size", "root", root.Hex(), "number", entry.blockNumber)
|
||||
|
||||
case result := <-done:
|
||||
t.triedb.SetForceFlush(false)
|
||||
|
||||
if result.err != nil {
|
||||
return nil, result.err
|
||||
}
|
||||
|
|
@ -410,6 +407,7 @@ wait:
|
|||
|
||||
// Set initial latest stats
|
||||
stats[result.root] = result.stat
|
||||
|
||||
t.mu.Lock()
|
||||
t.latestStats = &result.stat
|
||||
t.mu.Unlock()
|
||||
|
|
@ -561,16 +559,18 @@ func (t *SizeTracker) iterateTable(closed chan struct{}, prefix []byte, name str
|
|||
return count, bytes, nil
|
||||
}
|
||||
|
||||
// iterateTableParallel performs parallel iteration over a table by splitting into hex ranges
|
||||
// For storage tables, it splits on the first byte of the account hash (after the prefix)
|
||||
// iterateTableParallel performs parallel iteration over a table by splitting into
|
||||
// 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) {
|
||||
var (
|
||||
start = time.Now()
|
||||
workers = runtime.NumCPU()
|
||||
totalCount int64
|
||||
totalBytes int64
|
||||
group errgroup.Group
|
||||
mu sync.Mutex
|
||||
|
||||
start = time.Now()
|
||||
workers = runtime.NumCPU()
|
||||
group errgroup.Group
|
||||
mu sync.Mutex
|
||||
)
|
||||
group.SetLimit(workers)
|
||||
|
||||
|
|
@ -598,11 +598,9 @@ func (t *SizeTracker) iterateTableParallel(closed chan struct{}, prefix []byte,
|
|||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
if err := group.Wait(); err != nil {
|
||||
return 0, 0, err
|
||||
}
|
||||
|
||||
log.Info("Finished parallel state iteration", "category", name, "count", totalCount, "size", common.StorageSize(totalBytes), "elapsed", common.PrettyDuration(time.Since(start)))
|
||||
return totalCount, totalBytes, nil
|
||||
}
|
||||
|
|
@ -611,5 +609,6 @@ func (t *SizeTracker) iterateTableParallel(closed chan struct{}, prefix []byte,
|
|||
func (t *SizeTracker) GetLatestStats() *SizeStats {
|
||||
t.mu.RLock()
|
||||
defer t.mu.RUnlock()
|
||||
|
||||
return t.latestStats
|
||||
}
|
||||
|
|
|
|||
|
|
@ -451,12 +451,10 @@ func (api *DebugAPI) StateSize() (interface{}, error) {
|
|||
if sizer == nil {
|
||||
return nil, errors.New("state size tracker is not enabled")
|
||||
}
|
||||
|
||||
stats := sizer.GetLatestStats()
|
||||
if stats == nil {
|
||||
return nil, errors.New("state size statistics are not ready yet")
|
||||
}
|
||||
|
||||
return map[string]interface{}{
|
||||
"stateRoot": stats.StateRoot,
|
||||
"blockNumber": hexutil.Uint64(stats.BlockNumber),
|
||||
|
|
|
|||
|
|
@ -240,8 +240,8 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
|
|||
// within the data directory. The corresponding paths will be either:
|
||||
// - DATADIR/triedb/merkle.journal
|
||||
// - DATADIR/triedb/verkle.journal
|
||||
TrieJournalDirectory: stack.ResolvePath("triedb"),
|
||||
EnableStateSizeTracking: config.EnableStateSizeTracking,
|
||||
TrieJournalDirectory: stack.ResolvePath("triedb"),
|
||||
StateSizeTracking: config.EnableStateSizeTracking,
|
||||
}
|
||||
)
|
||||
if config.VMTrace != "" {
|
||||
|
|
|
|||
|
|
@ -49,6 +49,7 @@ func (c Config) MarshalTOML() (interface{}, error) {
|
|||
BlobPool blobpool.Config
|
||||
GPO gasprice.Config
|
||||
EnablePreimageRecording bool
|
||||
EnableStateSizeTracking bool
|
||||
VMTrace string
|
||||
VMTraceJsonConfig string
|
||||
RPCGasCap uint64
|
||||
|
|
@ -90,6 +91,7 @@ func (c Config) MarshalTOML() (interface{}, error) {
|
|||
enc.BlobPool = c.BlobPool
|
||||
enc.GPO = c.GPO
|
||||
enc.EnablePreimageRecording = c.EnablePreimageRecording
|
||||
enc.EnableStateSizeTracking = c.EnableStateSizeTracking
|
||||
enc.VMTrace = c.VMTrace
|
||||
enc.VMTraceJsonConfig = c.VMTraceJsonConfig
|
||||
enc.RPCGasCap = c.RPCGasCap
|
||||
|
|
@ -135,6 +137,7 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error {
|
|||
BlobPool *blobpool.Config
|
||||
GPO *gasprice.Config
|
||||
EnablePreimageRecording *bool
|
||||
EnableStateSizeTracking *bool
|
||||
VMTrace *string
|
||||
VMTraceJsonConfig *string
|
||||
RPCGasCap *uint64
|
||||
|
|
@ -243,6 +246,9 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error {
|
|||
if dec.EnablePreimageRecording != nil {
|
||||
c.EnablePreimageRecording = *dec.EnablePreimageRecording
|
||||
}
|
||||
if dec.EnableStateSizeTracking != nil {
|
||||
c.EnableStateSizeTracking = *dec.EnableStateSizeTracking
|
||||
}
|
||||
if dec.VMTrace != nil {
|
||||
c.VMTrace = *dec.VMTrace
|
||||
}
|
||||
|
|
|
|||
|
|
@ -384,12 +384,3 @@ func (db *Database) SnapshotCompleted() bool {
|
|||
}
|
||||
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
|
||||
stateIndexer *historyIndexer // History indexer historical state data, nil possible
|
||||
|
||||
lock sync.RWMutex // Lock to prevent mutations from happening at the same time
|
||||
forceFlush bool // Flag to force buffer flush regardless of size
|
||||
lock sync.RWMutex // Lock to prevent mutations from happening at the same time
|
||||
}
|
||||
|
||||
// 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)
|
||||
}
|
||||
|
||||
// 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
|
||||
// as stale to prevent access to the persistent state, which is in the syncing
|
||||
// stage.
|
||||
|
|
|
|||
|
|
@ -417,7 +417,7 @@ func (dl *diskLayer) commit(bottom *diffLayer, force bool) (*diskLayer, error) {
|
|||
|
||||
// Terminate the background state snapshot generation before mutating the
|
||||
// persistent state.
|
||||
if combined.full() || force || flush || dl.db.forceFlush {
|
||||
if combined.full() || force || flush {
|
||||
// Wait until the previous frozen buffer is fully flushed
|
||||
if dl.frozen != nil {
|
||||
if err := dl.frozen.waitFlush(); err != nil {
|
||||
|
|
|
|||
Loading…
Reference in a new issue