Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
65e4393
core/rawdb: read write state size metrics
jsvisa Aug 6, 2025
c80f118
core/state: state size metrics
jsvisa Aug 6, 2025
2c20733
triedb: Snapshot completed
jsvisa Aug 6, 2025
00adb27
concurrent iterate snapshot
jsvisa Aug 6, 2025
9c61ce8
stop and close iterator
jsvisa Aug 6, 2025
772031b
state update
jsvisa Aug 6, 2025
ca7f046
core: track state size in blockchain.go
jsvisa Aug 6, 2025
8d53996
set state root
jsvisa Aug 6, 2025
5e2b547
no need chan if init done
jsvisa Aug 6, 2025
7c8bb5f
use gauge to replace meter
jsvisa Aug 7, 2025
99bc834
fix: int64 instead of uint64
jsvisa Aug 7, 2025
5ac2fa6
fix: trienode calculate
jsvisa Aug 7, 2025
5f4937d
use time.After instead of sleep, incase of goroutine leak
jsvisa Aug 11, 2025
644801c
check iterator error
jsvisa Aug 12, 2025
b22bcdc
stop state size inside stop without saving
jsvisa Aug 12, 2025
5687ab6
Revert "check iterator error"
jsvisa Aug 12, 2025
826d397
fix data race
jsvisa Aug 12, 2025
04db370
core/state: rewrite the state size tracker
rjl493456442 Aug 15, 2025
0556f9f
core: update
rjl493456442 Aug 20, 2025
077df09
triedb/pathdb: for test
rjl493456442 Aug 20, 2025
c6ce9b6
fix: add snapshot root
jsvisa Aug 20, 2025
4b8a2a6
cmd: --metrics.statesize
jsvisa Aug 20, 2025
dd53866
fix: enable state size tracker if metrics and flag are enabled
jsvisa Aug 20, 2025
d4a5216
core: add state tracker test
jsvisa Aug 25, 2025
a59721a
fix: use 0 as snapshot block
jsvisa Aug 25, 2025
f4ebab3
fix: add with base
jsvisa Aug 25, 2025
9a237c4
test
jsvisa Aug 25, 2025
6f90804
expose stats
jsvisa Aug 25, 2025
f734928
Revert "expose stats"
jsvisa Aug 25, 2025
1099c56
debug log
jsvisa Aug 25, 2025
816ea2a
triedb: force flush
jsvisa Aug 25, 2025
67aec14
fix: wait for snapshot root is ready
jsvisa Aug 25, 2025
67cc5b8
force flush controlled in state_sizer
jsvisa Aug 25, 2025
7de66b4
log
jsvisa Aug 26, 2025
cb6bab0
Revert "triedb/pathdb: for test"
jsvisa Aug 26, 2025
dd3e8ca
use parallel iterate of the storage tables
jsvisa Aug 28, 2025
c8287fe
parallel run for all states
jsvisa Aug 28, 2025
40f10d4
cmd/geth: enable metrics state size in db import
jsvisa Sep 1, 2025
6ecc311
state: debug_stateSize to retrieve the latest state size
jsvisa Sep 2, 2025
b582c39
return hexutil
jsvisa Sep 2, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/geth/chaincmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ if one is set. Otherwise it prints the genesis from the datadir.`,
utils.MetricsInfluxDBTokenFlag,
utils.MetricsInfluxDBBucketFlag,
utils.MetricsInfluxDBOrganizationFlag,
utils.StateSizeTrackingFlag,
utils.TxLookupLimitFlag,
utils.VMTraceFlag,
utils.VMTraceJsonConfigFlag,
Expand Down
2 changes: 1 addition & 1 deletion cmd/geth/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ func constructDevModeBanner(ctx *cli.Context, cfg gethConfig) string {
0x%x (10^49 ETH)
`, cfg.Eth.Miner.PendingFeeRecipient)
if cfg.Eth.Miner.PendingFeeRecipient == utils.DeveloperAddr {
devModeBanner += fmt.Sprintf(`
devModeBanner += fmt.Sprintf(`
Private Key
------------------
0x%x
Expand Down
1 change: 1 addition & 0 deletions cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ var (
utils.MetricsInfluxDBTokenFlag,
utils.MetricsInfluxDBBucketFlag,
utils.MetricsInfluxDBOrganizationFlag,
utils.StateSizeTrackingFlag,
}
)

Expand Down
14 changes: 14 additions & 0 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,12 @@ var (
TakesFile: true,
Category: flags.MiscCategory,
}
StateSizeTrackingFlag = &cli.BoolFlag{
Name: "state-size-tracking",
Usage: "Enable state size tracking",
Value: ethconfig.Defaults.EnableStateSizeTracking,
Category: flags.MiscCategory,
}

// RPC settings
IPCDisabledFlag = &cli.BoolFlag{
Expand Down Expand Up @@ -1726,6 +1732,11 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
cfg.EthDiscoveryURLs = SplitAndTrim(urls)
}
}

if ctx.Bool(StateSizeTrackingFlag.Name) {
log.Info("Enabling state size metrics")
cfg.EnableStateSizeTracking = true
}
// Override any default configs for hard coded networks.
switch {
case ctx.Bool(MainnetFlag.Name):
Expand Down Expand Up @@ -2208,6 +2219,9 @@ func MakeChain(ctx *cli.Context, stack *node.Node, readonly bool) (*core.BlockCh
// - DATADIR/triedb/merkle.journal
// - DATADIR/triedb/verkle.journal
TrieJournalDirectory: stack.ResolvePath("triedb"),

// Enable state size tracking if enabled
EnableStateSizeTracking: ctx.Bool(StateSizeTrackingFlag.Name),
}
if options.ArchiveMode && !options.Preimages {
options.Preimages = true
Expand Down
30 changes: 29 additions & 1 deletion core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@ type BlockChainConfig struct {
// If the value is zero, all transactions of the entire chain will be indexed.
// If the value is -1, indexing is disabled.
TxLookupLimit int64

// EnableStateSizeTracking indicates whether the state size tracking is enabled.
EnableStateSizeTracking bool
}

// DefaultConfig returns the default config.
Expand Down Expand Up @@ -330,6 +333,7 @@ type BlockChain struct {
prefetcher Prefetcher
processor Processor // Block transaction processor interface
logger *tracing.Hooks
stateSizer *state.SizeTracker // State size tracking

lastForkReadyAlert time.Time // Last time there was a fork readiness print out
}
Expand Down Expand Up @@ -523,6 +527,16 @@ func NewBlockChain(db ethdb.Database, genesis *Genesis, engine consensus.Engine,
if bc.cfg.TxLookupLimit >= 0 {
bc.txIndexer = newTxIndexer(uint64(bc.cfg.TxLookupLimit), bc)
}

// Start state size tracker
if bc.cfg.EnableStateSizeTracking {
stateSizer, err := state.NewSizeTracker(bc.db, bc.triedb)
if err == nil {
bc.stateSizer = stateSizer
} else {
log.Info("Failed to setup size tracker", "err", err)
}
}
return bc, nil
}

Expand Down Expand Up @@ -1249,6 +1263,10 @@ func (bc *BlockChain) stopWithoutSaving() {
// Signal shutdown to all goroutines.
bc.InterruptInsert(true)

// Stop state size tracker
if bc.stateSizer != nil {
bc.stateSizer.Stop()
}
// Now wait for all chain modifications to end and persistent goroutines to exit.
//
// Note: Close waits for the mutex to become available, i.e. any running chain
Expand Down Expand Up @@ -1310,6 +1328,7 @@ func (bc *BlockChain) Stop() {
}
}
}

// Allow tracers to clean-up and release resources.
if bc.logger != nil && bc.logger.OnClose != nil {
bc.logger.OnClose()
Expand Down Expand Up @@ -1583,10 +1602,14 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.
log.Crit("Failed to write block into disk", "err", err)
}
// Commit all cached state changes into underlying memory database.
root, err := statedb.Commit(block.NumberU64(), bc.chainConfig.IsEIP158(block.Number()), bc.chainConfig.IsCancun(block.Number(), block.Time()))
root, stateUpdate, err := statedb.CommitWithUpdate(block.NumberU64(), bc.chainConfig.IsEIP158(block.Number()), bc.chainConfig.IsCancun(block.Number(), block.Time()))
if err != nil {
return err
}
// Emit the state update to the state sizestats if it's active
if bc.stateSizer != nil {
bc.stateSizer.Notify(stateUpdate)
}
// If node is running in path mode, skip explicit gc operation
// which is unnecessary in this mode.
if bc.triedb.Scheme() == rawdb.PathScheme {
Expand Down Expand Up @@ -2788,3 +2811,8 @@ func (bc *BlockChain) SetTrieFlushInterval(interval time.Duration) {
func (bc *BlockChain) GetTrieFlushInterval() time.Duration {
return time.Duration(bc.flushInterval.Load())
}

// StateSizer returns the state size tracker, or nil if it's not initialized
func (bc *BlockChain) StateSizer() *state.SizeTracker {
return bc.stateSizer
}
13 changes: 0 additions & 13 deletions core/rawdb/accessors_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,16 +174,3 @@ func UpdateUncleanShutdownMarker(db ethdb.KeyValueStore) {
log.Warn("Failed to write unclean-shutdown marker", "err", err)
}
}

// ReadTransitionStatus retrieves the eth2 transition status from the database
func ReadTransitionStatus(db ethdb.KeyValueReader) []byte {
data, _ := db.Get(transitionStatusKey)
return data
}

// WriteTransitionStatus stores the eth2 transition status to the database
func WriteTransitionStatus(db ethdb.KeyValueWriter, data []byte) {
if err := db.Put(transitionStatusKey, data); err != nil {
log.Crit("Failed to store the eth2 transition status", "err", err)
}
}
5 changes: 5 additions & 0 deletions core/state/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,11 @@ func (db *CachingDB) TrieDB() *triedb.Database {
return db.triedb
}

// DiskDB returns the underlying disk database for direct access.
func (db *CachingDB) DiskDB() ethdb.KeyValueStore {
return db.disk
}

// PointCache returns the cache of evaluated curve points.
func (db *CachingDB) PointCache() *utils.PointCache {
return db.pointCache
Expand Down
Loading
Loading