Skip to content

Commit e2036eb

Browse files
committed
all: polish
1 parent 1bc3da5 commit e2036eb

File tree

9 files changed

+25
-42
lines changed

9 files changed

+25
-42
lines changed

cmd/utils/flags.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2221,7 +2221,7 @@ func MakeChain(ctx *cli.Context, stack *node.Node, readonly bool) (*core.BlockCh
22212221
TrieJournalDirectory: stack.ResolvePath("triedb"),
22222222

22232223
// Enable state size tracking if enabled
2224-
EnableStateSizeTracking: ctx.Bool(StateSizeTrackingFlag.Name),
2224+
StateSizeTracking: ctx.Bool(StateSizeTrackingFlag.Name),
22252225
}
22262226
if options.ArchiveMode && !options.Preimages {
22272227
options.Preimages = true

core/blockchain.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,8 @@ type BlockChainConfig struct {
194194
// If the value is -1, indexing is disabled.
195195
TxLookupLimit int64
196196

197-
// EnableStateSizeTracking indicates whether the state size tracking is enabled.
198-
EnableStateSizeTracking bool
197+
// StateSizeTracking indicates whether the state size tracking is enabled.
198+
StateSizeTracking bool
199199
}
200200

201201
// DefaultConfig returns the default config.
@@ -529,7 +529,7 @@ func NewBlockChain(db ethdb.Database, genesis *Genesis, engine consensus.Engine,
529529
}
530530

531531
// Start state size tracker
532-
if bc.cfg.EnableStateSizeTracking {
532+
if bc.cfg.StateSizeTracking {
533533
stateSizer, err := state.NewSizeTracker(bc.db, bc.triedb)
534534
if err == nil {
535535
bc.stateSizer = stateSizer

core/state/state_sizer.go

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ func (t *SizeTracker) run() {
292292
case u := <-t.updateCh:
293293
base, found := stats[u.originRoot]
294294
if !found {
295+
log.Debug("Ignored the state size without parent", "parent", u.originRoot, "root", u.root, "number", u.blockNumber)
295296
continue
296297
}
297298
diff, err := calSizeStats(u)
@@ -352,8 +353,6 @@ wait:
352353
done chan buildResult
353354
)
354355

355-
t.triedb.SetForceFlush(true)
356-
357356
for {
358357
select {
359358
case u := <-t.updateCh:
@@ -378,8 +377,6 @@ wait:
378377
log.Info("Measuring persistent state size", "root", root.Hex(), "number", entry.blockNumber)
379378

380379
case result := <-done:
381-
t.triedb.SetForceFlush(false)
382-
383380
if result.err != nil {
384381
return nil, result.err
385382
}
@@ -410,6 +407,7 @@ wait:
410407

411408
// Set initial latest stats
412409
stats[result.root] = result.stat
410+
413411
t.mu.Lock()
414412
t.latestStats = &result.stat
415413
t.mu.Unlock()
@@ -561,16 +559,18 @@ func (t *SizeTracker) iterateTable(closed chan struct{}, prefix []byte, name str
561559
return count, bytes, nil
562560
}
563561

564-
// iterateTableParallel performs parallel iteration over a table by splitting into hex ranges
565-
// For storage tables, it splits on the first byte of the account hash (after the prefix)
562+
// iterateTableParallel performs parallel iteration over a table by splitting into
563+
// hex ranges. For storage tables, it splits on the first byte of the account hash
564+
// (after the prefix).
566565
func (t *SizeTracker) iterateTableParallel(closed chan struct{}, prefix []byte, name string) (int64, int64, error) {
567566
var (
568-
start = time.Now()
569-
workers = runtime.NumCPU()
570567
totalCount int64
571568
totalBytes int64
572-
group errgroup.Group
573-
mu sync.Mutex
569+
570+
start = time.Now()
571+
workers = runtime.NumCPU()
572+
group errgroup.Group
573+
mu sync.Mutex
574574
)
575575
group.SetLimit(workers)
576576

@@ -598,11 +598,9 @@ func (t *SizeTracker) iterateTableParallel(closed chan struct{}, prefix []byte,
598598
return nil
599599
})
600600
}
601-
602601
if err := group.Wait(); err != nil {
603602
return 0, 0, err
604603
}
605-
606604
log.Info("Finished parallel state iteration", "category", name, "count", totalCount, "size", common.StorageSize(totalBytes), "elapsed", common.PrettyDuration(time.Since(start)))
607605
return totalCount, totalBytes, nil
608606
}
@@ -611,5 +609,6 @@ func (t *SizeTracker) iterateTableParallel(closed chan struct{}, prefix []byte,
611609
func (t *SizeTracker) GetLatestStats() *SizeStats {
612610
t.mu.RLock()
613611
defer t.mu.RUnlock()
612+
614613
return t.latestStats
615614
}

eth/api_debug.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -451,12 +451,10 @@ func (api *DebugAPI) StateSize() (interface{}, error) {
451451
if sizer == nil {
452452
return nil, errors.New("state size tracker is not enabled")
453453
}
454-
455454
stats := sizer.GetLatestStats()
456455
if stats == nil {
457456
return nil, errors.New("state size statistics are not ready yet")
458457
}
459-
460458
return map[string]interface{}{
461459
"stateRoot": stats.StateRoot,
462460
"blockNumber": hexutil.Uint64(stats.BlockNumber),

eth/backend.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,8 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
240240
// within the data directory. The corresponding paths will be either:
241241
// - DATADIR/triedb/merkle.journal
242242
// - DATADIR/triedb/verkle.journal
243-
TrieJournalDirectory: stack.ResolvePath("triedb"),
244-
EnableStateSizeTracking: config.EnableStateSizeTracking,
243+
TrieJournalDirectory: stack.ResolvePath("triedb"),
244+
StateSizeTracking: config.EnableStateSizeTracking,
245245
}
246246
)
247247
if config.VMTrace != "" {

eth/ethconfig/gen_config.go

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

triedb/database.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -384,12 +384,3 @@ func (db *Database) SnapshotCompleted() bool {
384384
}
385385
return pdb.SnapshotCompleted()
386386
}
387-
388-
// SetForceFlush enables or disables the pathdb to flush any pending changes to disk
389-
// immediately, regardless of the buffer size threshold. This can be used to accelerate
390-
// state sizer initialization by making buffered state changes visible on disk.
391-
func (db *Database) SetForceFlush(enabled bool) {
392-
if pdb, ok := db.backend.(*pathdb.Database); ok {
393-
pdb.SetForceFlush(enabled)
394-
}
395-
}

triedb/pathdb/database.go

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,7 @@ type Database struct {
225225

226226
stateFreezer ethdb.ResettableAncientStore // Freezer for storing state histories, nil possible in tests
227227
stateIndexer *historyIndexer // History indexer historical state data, nil possible
228-
229-
lock sync.RWMutex // Lock to prevent mutations from happening at the same time
230-
forceFlush bool // Flag to force buffer flush regardless of size
228+
lock sync.RWMutex // Lock to prevent mutations from happening at the same time
231229
}
232230

233231
// New attempts to load an already existing layer from a persistent key-value
@@ -449,15 +447,6 @@ func (db *Database) Commit(root common.Hash, report bool) error {
449447
return db.tree.cap(root, 0)
450448
}
451449

452-
// SetForceFlush enables or disables force flushing for the next state update.
453-
func (db *Database) SetForceFlush(enabled bool) {
454-
db.lock.Lock()
455-
defer db.lock.Unlock()
456-
457-
db.forceFlush = enabled
458-
log.Info("Set triedb force flush for next pathdb update", "enabled", enabled)
459-
}
460-
461450
// Disable deactivates the database and invalidates all available state layers
462451
// as stale to prevent access to the persistent state, which is in the syncing
463452
// stage.

triedb/pathdb/disklayer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ func (dl *diskLayer) commit(bottom *diffLayer, force bool) (*diskLayer, error) {
417417

418418
// Terminate the background state snapshot generation before mutating the
419419
// persistent state.
420-
if combined.full() || force || flush || dl.db.forceFlush {
420+
if combined.full() || force || flush {
421421
// Wait until the previous frozen buffer is fully flushed
422422
if dl.frozen != nil {
423423
if err := dl.frozen.waitFlush(); err != nil {

0 commit comments

Comments
 (0)