eth, triedb/pathdb: permit write buffer allowance in PBSS archive mode (#32091)

This pull request fixes a flaw in PBSS archive mode that significantly
degrades performance when the mode is enabled.

Originally, in hash mode, the dirty trie cache is completely disabled
when archive mode is active, in order to disable the in-memory garbage 
collection mechanism. However, the internal logic in path mode differs 
significantly, and the dirty trie node cache is essential for maintaining
chain insertion performance. Therefore, the cache is now retained in
path mode.
This commit is contained in:
rjl493456442 2025-06-25 16:49:09 +08:00 committed by GitHub
parent 429e821fa2
commit ce63bba361
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 16 additions and 10 deletions

View file

@ -140,7 +140,7 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
log.Warn("Sanitizing invalid miner gas price", "provided", config.Miner.GasPrice, "updated", ethconfig.Defaults.Miner.GasPrice)
config.Miner.GasPrice = new(big.Int).Set(ethconfig.Defaults.Miner.GasPrice)
}
if config.NoPruning && config.TrieDirtyCache > 0 {
if config.NoPruning && config.TrieDirtyCache > 0 && config.StateScheme == rawdb.HashScheme {
if config.SnapshotCache > 0 {
config.TrieCleanCache += config.TrieDirtyCache * 3 / 5
config.SnapshotCache += config.TrieDirtyCache * 2 / 5

View file

@ -128,9 +128,11 @@ func (b *batchIndexer) finish(force bool) error {
return nil
}
var (
batch = b.db.NewBatch()
batchMu sync.RWMutex
eg errgroup.Group
batch = b.db.NewBatch()
batchMu sync.RWMutex
storages int
start = time.Now()
eg errgroup.Group
)
eg.SetLimit(runtime.NumCPU())
@ -167,6 +169,7 @@ func (b *batchIndexer) finish(force bool) error {
})
}
for addrHash, slots := range b.storages {
storages += len(slots)
for storageHash, idList := range slots {
eg.Go(func() error {
if !b.delete {
@ -216,6 +219,7 @@ func (b *batchIndexer) finish(force bool) error {
if err := batch.Write(); err != nil {
return err
}
log.Debug("Committed batch indexer", "accounts", len(b.accounts), "storages", storages, "records", b.counter, "elapsed", common.PrettyDuration(time.Since(start)))
b.counter = 0
b.accounts = make(map[common.Hash][]uint64)
b.storages = make(map[common.Hash]map[common.Hash][]uint64)
@ -224,9 +228,10 @@ func (b *batchIndexer) finish(force bool) error {
// indexSingle processes the state history with the specified ID for indexing.
func indexSingle(historyID uint64, db ethdb.KeyValueStore, freezer ethdb.AncientReader) error {
defer func(start time.Time) {
start := time.Now()
defer func() {
indexHistoryTimer.UpdateSince(start)
}(time.Now())
}()
metadata := loadIndexMetadata(db)
if metadata == nil || metadata.Last+1 != historyID {
@ -247,15 +252,16 @@ func indexSingle(historyID uint64, db ethdb.KeyValueStore, freezer ethdb.Ancient
if err := b.finish(true); err != nil {
return err
}
log.Debug("Indexed state history", "id", historyID)
log.Debug("Indexed state history", "id", historyID, "elapsed", common.PrettyDuration(time.Since(start)))
return nil
}
// unindexSingle processes the state history with the specified ID for unindexing.
func unindexSingle(historyID uint64, db ethdb.KeyValueStore, freezer ethdb.AncientReader) error {
defer func(start time.Time) {
start := time.Now()
defer func() {
unindexHistoryTimer.UpdateSince(start)
}(time.Now())
}()
metadata := loadIndexMetadata(db)
if metadata == nil || metadata.Last != historyID {
@ -276,7 +282,7 @@ func unindexSingle(historyID uint64, db ethdb.KeyValueStore, freezer ethdb.Ancie
if err := b.finish(true); err != nil {
return err
}
log.Debug("Unindexed state history", "id", historyID)
log.Debug("Unindexed state history", "id", historyID, "elapsed", common.PrettyDuration(time.Since(start)))
return nil
}