Skip to content

[NIT-3021] paralellise pruning inside accounts #390

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Feb 13, 2025
Merged
Changes from 4 commits
Commits
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
61 changes: 44 additions & 17 deletions core/state/pruner/pruner.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"errors"
"fmt"
"math"
"math/big"
"os"
"path/filepath"
"sync"
Expand Down Expand Up @@ -422,31 +423,57 @@ func dumpRawTrieDescendants(db ethdb.Database, root common.Hash, output *stateBl
threadStartedAt := time.Now()
threadLastLog := time.Now()

storageIt, err := storageTr.NodeIterator(nil)
var processedNodes uint64
var startStorageIt trie.NodeIterator
startStorageIt, err = storageTr.NodeIterator(nil)
if err != nil {
return
}
var processedNodes uint64
for storageIt.Next(true) {
storageTrieHash := storageIt.Hash()
if storageTrieHash != (common.Hash{}) {
// The inner bloomfilter library has a mutex so concurrency is fine here
err = output.Put(storageTrieHash.Bytes(), nil)
for i := int64(1); i <= 32; i++ {
// Split the storage trie into 32 parts to parallelize the traversal
var nextStorageIt trie.NodeIterator
// For the last iteration, we don't need to create a new iterator, as it will be till the end, so just let it be nil
if i != 32 {
nextStorageIt, err = storageTr.NodeIterator(big.NewInt((i) << 3).Bytes())
if err != nil {
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 = <-results
if err != nil {
return
}
}
err = storageIt.Error()
if err != nil {
return
go func(startIt, endIt trie.NodeIterator) {
threadsRunning.Add(1)
defer threadsRunning.Add(-1)
var err error
defer func() {
results <- err
}()
// Traverse the storage trie, and stop if we reach the end of the trie or the end of the current part
for startIt.Next(true) && (endIt == nil || startIt.Hash() == endIt.Hash()) {
storageTrieHash := startIt.Hash()
if storageTrieHash != (common.Hash{}) {
// The inner bloomfilter library has a mutex so concurrency is fine here
err = output.Put(storageTrieHash.Bytes(), nil)
if err != nil {
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 = startIt.Error()
if err != nil {
return
}
}(startStorageIt, nextStorageIt)
startStorageIt = nextStorageIt
}
}()
}
Expand Down
Loading