mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
eth, trie: remove onBoundary callback
This commit is contained in:
parent
c884b4dfcc
commit
a43ea13491
4 changed files with 25 additions and 47 deletions
|
|
@ -35,6 +35,11 @@ var (
|
||||||
// performed to determine if node needs to be deleted.
|
// performed to determine if node needs to be deleted.
|
||||||
lookupGauge = metrics.NewRegisteredGauge("eth/protocols/snap/sync/lookup", nil)
|
lookupGauge = metrics.NewRegisteredGauge("eth/protocols/snap/sync/lookup", nil)
|
||||||
|
|
||||||
// boundaryNodesGauge is the metric to track how many boundary trie node are met.
|
// boundaryAccountNodesGauge is the metric to track how many boundary trie
|
||||||
boundaryNodesGauge = metrics.NewRegisteredGauge("eth/protocols/snap/sync/boundary", nil)
|
// nodes in account trie are met.
|
||||||
|
boundaryAccountNodesGauge = metrics.NewRegisteredGauge("eth/protocols/snap/sync/boundary/account", nil)
|
||||||
|
|
||||||
|
// boundaryAccountNodesGauge is the metric to track how many boundary trie
|
||||||
|
// nodes in storage tries are met.
|
||||||
|
boundaryStorageNodesGauge = metrics.NewRegisteredGauge("eth/protocols/snap/sync/boundary/storage", nil)
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -762,9 +762,7 @@ func (s *Syncer) loadSyncStatus() {
|
||||||
options = options.WithCleaner(func(path []byte) {
|
options = options.WithCleaner(func(path []byte) {
|
||||||
s.cleanPath(task.genBatch, common.Hash{}, path)
|
s.cleanPath(task.genBatch, common.Hash{}, path)
|
||||||
})
|
})
|
||||||
options = options.SkipBoundary(true, true, func(path []byte, hash common.Hash, blob []byte) {
|
options = options.SkipBoundary(true, true, boundaryAccountNodesGauge)
|
||||||
boundaryNodesGauge.Inc(1)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
task.genTrie = trie.NewStackTrie(options)
|
task.genTrie = trie.NewStackTrie(options)
|
||||||
for accountHash, subtasks := range task.SubTasks {
|
for accountHash, subtasks := range task.SubTasks {
|
||||||
|
|
@ -789,9 +787,7 @@ func (s *Syncer) loadSyncStatus() {
|
||||||
options = options.WithCleaner(func(path []byte) {
|
options = options.WithCleaner(func(path []byte) {
|
||||||
s.cleanPath(subtask.genBatch, owner, path)
|
s.cleanPath(subtask.genBatch, owner, path)
|
||||||
})
|
})
|
||||||
options = options.SkipBoundary(true, true, func(path []byte, hash common.Hash, blob []byte) {
|
options = options.SkipBoundary(true, true, boundaryStorageNodesGauge)
|
||||||
boundaryNodesGauge.Inc(1)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
subtask.genTrie = trie.NewStackTrie(options)
|
subtask.genTrie = trie.NewStackTrie(options)
|
||||||
}
|
}
|
||||||
|
|
@ -856,9 +852,7 @@ func (s *Syncer) loadSyncStatus() {
|
||||||
options = options.WithCleaner(func(path []byte) {
|
options = options.WithCleaner(func(path []byte) {
|
||||||
s.cleanPath(batch, common.Hash{}, path)
|
s.cleanPath(batch, common.Hash{}, path)
|
||||||
})
|
})
|
||||||
options = options.SkipBoundary(true, true, func(path []byte, hash common.Hash, blob []byte) {
|
options = options.SkipBoundary(true, true, boundaryAccountNodesGauge)
|
||||||
boundaryNodesGauge.Inc(1)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
s.tasks = append(s.tasks, &accountTask{
|
s.tasks = append(s.tasks, &accountTask{
|
||||||
Next: next,
|
Next: next,
|
||||||
|
|
@ -2066,9 +2060,7 @@ func (s *Syncer) processStorageResponse(res *storageResponse) {
|
||||||
options = options.WithCleaner(func(path []byte) {
|
options = options.WithCleaner(func(path []byte) {
|
||||||
s.cleanPath(batch, owner, path)
|
s.cleanPath(batch, owner, path)
|
||||||
})
|
})
|
||||||
options.SkipBoundary(true, true, func(path []byte, hash common.Hash, blob []byte) {
|
options.SkipBoundary(true, true, boundaryStorageNodesGauge)
|
||||||
boundaryNodesGauge.Inc(1)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
tasks = append(tasks, &storageTask{
|
tasks = append(tasks, &storageTask{
|
||||||
Next: common.Hash{},
|
Next: common.Hash{},
|
||||||
|
|
@ -2095,9 +2087,7 @@ func (s *Syncer) processStorageResponse(res *storageResponse) {
|
||||||
options = options.WithCleaner(func(path []byte) {
|
options = options.WithCleaner(func(path []byte) {
|
||||||
s.cleanPath(batch, owner, path)
|
s.cleanPath(batch, owner, path)
|
||||||
})
|
})
|
||||||
options.SkipBoundary(true, true, func(path []byte, hash common.Hash, blob []byte) {
|
options.SkipBoundary(true, true, boundaryStorageNodesGauge)
|
||||||
boundaryNodesGauge.Inc(1)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
tasks = append(tasks, &storageTask{
|
tasks = append(tasks, &storageTask{
|
||||||
Next: r.Start(),
|
Next: r.Start(),
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/log"
|
"github.com/ethereum/go-ethereum/log"
|
||||||
|
"github.com/ethereum/go-ethereum/metrics"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
@ -37,7 +38,7 @@ type StackTrieOptions struct {
|
||||||
|
|
||||||
SkipLeftBoundary bool // Flag whether the nodes on the left boundary are skipped for committing
|
SkipLeftBoundary bool // Flag whether the nodes on the left boundary are skipped for committing
|
||||||
SkipRightBoundary bool // Flag whether the nodes on the right boundary are skipped for committing
|
SkipRightBoundary bool // Flag whether the nodes on the right boundary are skipped for committing
|
||||||
OnBoundary func(path []byte, hash common.Hash, blob []byte) // Callback invoked when the node is skipped committing
|
boundaryGauge metrics.Gauge // Gauge to track how many boundary nodes are met
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewStackTrieOptions initializes an empty options for stackTrie.
|
// NewStackTrieOptions initializes an empty options for stackTrie.
|
||||||
|
|
@ -58,10 +59,10 @@ func (o *StackTrieOptions) WithCleaner(cleaner func(path []byte)) *StackTrieOpti
|
||||||
// SkipBoundary configures whether the left and right boundary nodes are filtered
|
// SkipBoundary configures whether the left and right boundary nodes are filtered
|
||||||
// for committing, along with a onBoundary callback invoked whenever the boundary
|
// for committing, along with a onBoundary callback invoked whenever the boundary
|
||||||
// nodes are met.
|
// nodes are met.
|
||||||
func (o *StackTrieOptions) SkipBoundary(skipLeft, skipRight bool, onBoundary func(path []byte, hash common.Hash, blob []byte)) *StackTrieOptions {
|
func (o *StackTrieOptions) SkipBoundary(skipLeft, skipRight bool, gauge metrics.Gauge) *StackTrieOptions {
|
||||||
o.SkipLeftBoundary = skipLeft
|
o.SkipLeftBoundary = skipLeft
|
||||||
o.SkipRightBoundary = skipRight
|
o.SkipRightBoundary = skipRight
|
||||||
o.OnBoundary = onBoundary
|
o.boundaryGauge = gauge
|
||||||
return o
|
return o
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -429,21 +430,19 @@ func (t *StackTrie) hash(st *stNode, path []byte) {
|
||||||
if t.options.Writer == nil {
|
if t.options.Writer == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
hash := common.BytesToHash(st.val)
|
|
||||||
|
|
||||||
// Skip committing if the node is on the left boundary and stackTrie is
|
// Skip committing if the node is on the left boundary and stackTrie is
|
||||||
// configured to filter the boundary.
|
// configured to filter the boundary.
|
||||||
if t.options.SkipLeftBoundary && bytes.HasPrefix(t.first, path) {
|
if t.options.SkipLeftBoundary && bytes.HasPrefix(t.first, path) {
|
||||||
if t.options.OnBoundary != nil {
|
if t.options.boundaryGauge != nil {
|
||||||
t.options.OnBoundary(path, hash, blob)
|
t.options.boundaryGauge.Inc(1)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// Skip committing if the node is on the right boundary and stackTrie is
|
// Skip committing if the node is on the right boundary and stackTrie is
|
||||||
// configured to filter the boundary.
|
// configured to filter the boundary.
|
||||||
if t.options.SkipRightBoundary && bytes.HasPrefix(t.last, path) {
|
if t.options.SkipRightBoundary && bytes.HasPrefix(t.last, path) {
|
||||||
if t.options.OnBoundary != nil {
|
if t.options.boundaryGauge != nil {
|
||||||
t.options.OnBoundary(path, hash, blob)
|
t.options.boundaryGauge.Inc(1)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -384,7 +384,6 @@ func buildPartialTree(entries []*kv, t *testing.T) map[string]common.Hash {
|
||||||
var (
|
var (
|
||||||
options = NewStackTrieOptions()
|
options = NewStackTrieOptions()
|
||||||
nodes = make(map[string]common.Hash)
|
nodes = make(map[string]common.Hash)
|
||||||
boundary = make(map[string]common.Hash)
|
|
||||||
)
|
)
|
||||||
var (
|
var (
|
||||||
first int
|
first int
|
||||||
|
|
@ -409,9 +408,7 @@ func buildPartialTree(entries []*kv, t *testing.T) map[string]common.Hash {
|
||||||
noRight = true
|
noRight = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
options = options.SkipBoundary(noLeft, noRight, func(path []byte, hash common.Hash, blob []byte) {
|
options = options.SkipBoundary(noLeft, noRight, nil)
|
||||||
boundary[string(path)] = hash
|
|
||||||
})
|
|
||||||
options = options.WithWriter(func(path []byte, hash common.Hash, blob []byte) {
|
options = options.WithWriter(func(path []byte, hash common.Hash, blob []byte) {
|
||||||
nodes[string(path)] = hash
|
nodes[string(path)] = hash
|
||||||
})
|
})
|
||||||
|
|
@ -421,19 +418,6 @@ func buildPartialTree(entries []*kv, t *testing.T) map[string]common.Hash {
|
||||||
tr.MustUpdate(entries[i].k, entries[i].v)
|
tr.MustUpdate(entries[i].k, entries[i].v)
|
||||||
}
|
}
|
||||||
tr.Commit()
|
tr.Commit()
|
||||||
|
|
||||||
for path := range boundary {
|
|
||||||
var expect bool
|
|
||||||
if noLeft && bytes.HasPrefix(keybytesToHex(entries[first].k), []byte(path)) {
|
|
||||||
expect = true
|
|
||||||
}
|
|
||||||
if noRight && bytes.HasPrefix(keybytesToHex(entries[last].k), []byte(path)) {
|
|
||||||
expect = true
|
|
||||||
}
|
|
||||||
if !expect {
|
|
||||||
t.Fatalf("Unexpected boundary node, %v", []byte(path))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nodes
|
return nodes
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue