Skip to content

Commit

Permalink
core/state/prunner: add extra progress log when traversing a storage …
Browse files Browse the repository at this point in the history
…trie takes long
  • Loading branch information
magicxyyz committed Jun 13, 2024
1 parent b113d15 commit fd4ac69
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions core/state/pruner/pruner.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"os"
"path/filepath"
"sync"
"sync/atomic"
"time"

"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -357,6 +358,7 @@ func dumpRawTrieDescendants(db ethdb.Database, root common.Hash, output *stateBl
for i := 0; i < threads; i++ {
results <- nil
}
var threadsRunning atomic.Int32

for accountIt.Next(true) {
accountTrieHash := accountIt.Hash()
Expand Down Expand Up @@ -399,14 +401,20 @@ func dumpRawTrieDescendants(db ethdb.Database, root common.Hash, output *stateBl
return err
}
go func() {
threadsRunning.Add(1)
defer threadsRunning.Add(-1)
var err error
defer func() {
results <- err
}()
threadStartedAt := time.Now()
threadLastLog := time.Now()

storageIt, err := storageTr.NodeIterator(nil)
if err != nil {
return
}
var processedNodes uint64
for storageIt.Next(true) {
storageTrieHash := storageIt.Hash()
if storageTrieHash != (common.Hash{}) {
Expand All @@ -416,6 +424,13 @@ func dumpRawTrieDescendants(db ethdb.Database, root common.Hash, output *stateBl
return
}
}
processedNodes++
if time.Since(threadLastLog) > 5*time.Minute {
elapsedTotal := time.Since(startedAt)
elapsedThread := time.Since(threadStartedAt)
log.Info("traversing trie database - traversing storage trie taking long", "key", key, "elapsedTotal", elapsedTotal, "elapsedThread", elapsedThread, "processedNodes", processedNodes, "threadsRunning", threadsRunning.Load())
threadLastLog = time.Now()
}
}
err = storageIt.Error()
if err != nil {
Expand Down

0 comments on commit fd4ac69

Please sign in to comment.