mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-24 05:36:46 +00:00
reset
This commit is contained in:
parent
d4d1467d39
commit
765c380b6c
4 changed files with 8 additions and 74 deletions
|
|
@ -1464,11 +1464,3 @@ func (s *StateDB) Witness() *stateless.Witness {
|
|||
func (s *StateDB) AccessEvents() *AccessEvents {
|
||||
return s.accessEvents
|
||||
}
|
||||
|
||||
func (s *StateDB) BeginTrieDepthWindow() {
|
||||
trie.StateDepthMetricsStartBlock()
|
||||
}
|
||||
|
||||
func (s *StateDB) EndTrieDepthWindow() {
|
||||
trie.StateDepthMetricsEndBlock()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -64,9 +64,6 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
|
|||
allLogs []*types.Log
|
||||
gp = new(GasPool).AddGas(block.GasLimit())
|
||||
)
|
||||
// Start the trie depth metrics window
|
||||
statedb.BeginTrieDepthWindow()
|
||||
defer statedb.EndTrieDepthWindow()
|
||||
|
||||
// Mutate the block and state according to any hard-fork specs
|
||||
if p.config.DAOForkSupport && p.config.DAOForkBlock != nil && p.config.DAOForkBlock.Cmp(block.Number()) == 0 {
|
||||
|
|
|
|||
15
trie/trie.go
15
trie/trie.go
|
|
@ -21,7 +21,6 @@ import (
|
|||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"slices"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
|
|
@ -376,10 +375,6 @@ func (t *Trie) update(key, value []byte) error {
|
|||
|
||||
func (t *Trie) insert(n node, prefix, key []byte, value node) (bool, node, error) {
|
||||
if len(key) == 0 {
|
||||
if t.owner == (common.Hash{}) {
|
||||
stateDepthAggregator.record(int64(len(prefix)))
|
||||
}
|
||||
|
||||
if v, ok := n.(valueNode); ok {
|
||||
return !bytes.Equal(v, value.(valueNode)), value, nil
|
||||
}
|
||||
|
|
@ -522,7 +517,10 @@ func (t *Trie) delete(n node, prefix, key []byte) (bool, node, error) {
|
|||
// always creates a new slice) instead of append to
|
||||
// avoid modifying n.Key since it might be shared with
|
||||
// other nodes.
|
||||
return true, &shortNode{slices.Concat(n.Key, child.Key), child.Val, t.newFlag()}, nil
|
||||
if t.owner == (common.Hash{}) {
|
||||
stateDepthAggregator.record(int64(len(prefix) + len(key)))
|
||||
}
|
||||
return true, &shortNode{concat(n.Key, child.Key...), child.Val, t.newFlag()}, nil
|
||||
default:
|
||||
return true, &shortNode{n.Key, child, t.newFlag()}, nil
|
||||
}
|
||||
|
|
@ -579,7 +577,10 @@ func (t *Trie) delete(n node, prefix, key []byte) (bool, node, error) {
|
|||
// Replace the entire full node with the short node.
|
||||
// Mark the original short node as deleted since the
|
||||
// value is embedded into the parent now.
|
||||
t.opTracer.onDelete(append(prefix, byte(pos)))
|
||||
t.tracer.onDelete(append(prefix, byte(pos)))
|
||||
if t.owner == (common.Hash{}) {
|
||||
stateDepthAggregator.record(int64(len(prefix) + 1))
|
||||
}
|
||||
|
||||
k := append([]byte{byte(pos)}, cnode.Key...)
|
||||
return true, &shortNode{k, cnode.Val, t.newFlag()}, nil
|
||||
|
|
|
|||
|
|
@ -1,56 +0,0 @@
|
|||
package trie
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"github.com/ethereum/go-ethereum/metrics"
|
||||
)
|
||||
|
||||
var (
|
||||
avgAccessDepthInBlock = metrics.NewRegisteredGauge("trie/access/depth/avg", nil)
|
||||
minAccessDepthInBlock = metrics.NewRegisteredGauge("trie/access/depth/min", nil)
|
||||
stateDepthAggregator = &depthAggregator{}
|
||||
)
|
||||
|
||||
// depthAggregator aggregates trie access depth metrics for a block.
|
||||
type depthAggregator struct {
|
||||
mu sync.Mutex
|
||||
sum, cnt int64
|
||||
min int64
|
||||
}
|
||||
|
||||
// start initializes the aggregator for a new block.
|
||||
func (d *depthAggregator) start() {
|
||||
d.mu.Lock()
|
||||
d.sum, d.cnt, d.min = 0, 0, -1
|
||||
d.mu.Unlock()
|
||||
}
|
||||
|
||||
// record records the access depth for a trie operation.
|
||||
func (d *depthAggregator) record(depth int64) {
|
||||
d.mu.Lock()
|
||||
v := depth
|
||||
d.sum += v
|
||||
d.cnt++
|
||||
if d.min < 0 || v < d.min {
|
||||
d.min = v
|
||||
}
|
||||
d.mu.Unlock()
|
||||
}
|
||||
|
||||
// end finalizes the metrics for the current block and updates the registered metrics.
|
||||
func (d *depthAggregator) end() {
|
||||
d.mu.Lock()
|
||||
sum, cnt, min := d.sum, d.cnt, d.min
|
||||
d.mu.Unlock()
|
||||
if cnt > 0 {
|
||||
avgAccessDepthInBlock.Update(sum / cnt)
|
||||
minAccessDepthInBlock.Update(min)
|
||||
}
|
||||
}
|
||||
|
||||
// StateDepthMetricsStartBlock initializes the depth aggregator for a new block.
|
||||
func StateDepthMetricsStartBlock() { stateDepthAggregator.start() }
|
||||
|
||||
// StateDepthMetricsEndBlock finalizes the depth metrics for the current block.
|
||||
func StateDepthMetricsEndBlock() { stateDepthAggregator.end() }
|
||||
Loading…
Reference in a new issue