core/stateless: cap witness depth metrics buckets

This commit is contained in:
yyhrnk 2025-12-10 14:45:54 +02:00 committed by GitHub
parent b98b255449
commit 82fa9a4268
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -62,10 +62,14 @@ func (s *WitnessStats) Add(nodes map[string][]byte, owner common.Hash) {
// If current path is a prefix of the next path, it's not a leaf.
// The last path is always a leaf.
if i == len(paths)-1 || !strings.HasPrefix(paths[i+1], paths[i]) {
depth := len(path)
if depth >= len(s.accountTrieLeaves) {
depth = len(s.accountTrieLeaves) - 1
}
if owner == (common.Hash{}) {
s.accountTrieLeaves[len(path)] += 1
s.accountTrieLeaves[depth] += 1
} else {
s.storageTrieLeaves[len(path)] += 1
s.storageTrieLeaves[depth] += 1
}
}
}