Skip to content

Commit 434db9c

Browse files
Improve tracing of merkledb trie updates (#2897)
1 parent f7def4d commit 434db9c

File tree

4 files changed

+100
-78
lines changed

4 files changed

+100
-78
lines changed

x/merkledb/db.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,9 @@ type merkleDB struct {
216216
// Valid children of this trie.
217217
childViews []*view
218218

219-
// calculateNodeIDsSema controls the number of goroutines inside
220-
// [calculateNodeIDsHelper] at any given time.
221-
calculateNodeIDsSema *semaphore.Weighted
219+
// hashNodesSema controls the number of goroutines that are created inside
220+
// [hashChangedNode] at any given time.
221+
hashNodesSema *semaphore.Weighted
222222

223223
tokenSize int
224224
}
@@ -270,12 +270,12 @@ func newDatabase(
270270
bufferPool,
271271
metrics,
272272
int(config.ValueNodeCacheSize)),
273-
history: newTrieHistory(int(config.HistoryLength)),
274-
debugTracer: getTracerIfEnabled(config.TraceLevel, DebugTrace, config.Tracer),
275-
infoTracer: getTracerIfEnabled(config.TraceLevel, InfoTrace, config.Tracer),
276-
childViews: make([]*view, 0, defaultPreallocationSize),
277-
calculateNodeIDsSema: semaphore.NewWeighted(int64(rootGenConcurrency)),
278-
tokenSize: BranchFactorToTokenSize[config.BranchFactor],
273+
history: newTrieHistory(int(config.HistoryLength)),
274+
debugTracer: getTracerIfEnabled(config.TraceLevel, DebugTrace, config.Tracer),
275+
infoTracer: getTracerIfEnabled(config.TraceLevel, InfoTrace, config.Tracer),
276+
childViews: make([]*view, 0, defaultPreallocationSize),
277+
hashNodesSema: semaphore.NewWeighted(int64(rootGenConcurrency)),
278+
tokenSize: BranchFactorToTokenSize[config.BranchFactor],
279279
}
280280

281281
if err := trieDB.initializeRoot(); err != nil {

x/merkledb/history.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ type changeSummary struct {
5757
// The ID of the trie after these changes.
5858
rootID ids.ID
5959
// The root before/after this change.
60-
// Set in [calculateNodeIDs].
60+
// Set in [applyValueChanges].
6161
rootChange change[maybe.Maybe[*node]]
6262
nodes map[Key]*change[*node]
6363
values map[Key]*change[maybe.Maybe[[]byte]]

x/merkledb/trie_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
func getNodeValue(t Trie, key string) ([]byte, error) {
2222
path := ToKey([]byte(key))
2323
if asView, ok := t.(*view); ok {
24-
if err := asView.calculateNodeIDs(context.Background()); err != nil {
24+
if err := asView.applyValueChanges(context.Background()); err != nil {
2525
return nil, err
2626
}
2727
}
@@ -131,7 +131,7 @@ func TestVisitPathToKey(t *testing.T) {
131131
require.NoError(err)
132132
require.IsType(&view{}, trieIntf)
133133
trie = trieIntf.(*view)
134-
require.NoError(trie.calculateNodeIDs(context.Background()))
134+
require.NoError(trie.applyValueChanges(context.Background()))
135135

136136
nodePath = make([]*node, 0, 1)
137137
require.NoError(visitPathToKey(trie, ToKey(key1), func(n *node) error {
@@ -156,7 +156,7 @@ func TestVisitPathToKey(t *testing.T) {
156156
require.NoError(err)
157157
require.IsType(&view{}, trieIntf)
158158
trie = trieIntf.(*view)
159-
require.NoError(trie.calculateNodeIDs(context.Background()))
159+
require.NoError(trie.applyValueChanges(context.Background()))
160160

161161
nodePath = make([]*node, 0, 2)
162162
require.NoError(visitPathToKey(trie, ToKey(key2), func(n *node) error {
@@ -185,7 +185,7 @@ func TestVisitPathToKey(t *testing.T) {
185185
require.NoError(err)
186186
require.IsType(&view{}, trieIntf)
187187
trie = trieIntf.(*view)
188-
require.NoError(trie.calculateNodeIDs(context.Background()))
188+
require.NoError(trie.applyValueChanges(context.Background()))
189189

190190
// Trie is:
191191
// []
@@ -775,7 +775,7 @@ func Test_Trie_ChainDeletion(t *testing.T) {
775775
)
776776
require.NoError(err)
777777

778-
require.NoError(newTrie.(*view).calculateNodeIDs(context.Background()))
778+
require.NoError(newTrie.(*view).applyValueChanges(context.Background()))
779779
maybeRoot := newTrie.getRoot()
780780
require.NoError(err)
781781
require.True(maybeRoot.HasValue())
@@ -794,7 +794,7 @@ func Test_Trie_ChainDeletion(t *testing.T) {
794794
},
795795
)
796796
require.NoError(err)
797-
require.NoError(newTrie.(*view).calculateNodeIDs(context.Background()))
797+
require.NoError(newTrie.(*view).applyValueChanges(context.Background()))
798798

799799
// trie should be empty
800800
root := newTrie.getRoot()
@@ -861,7 +861,7 @@ func Test_Trie_NodeCollapse(t *testing.T) {
861861
)
862862
require.NoError(err)
863863

864-
require.NoError(trie.(*view).calculateNodeIDs(context.Background()))
864+
require.NoError(trie.(*view).applyValueChanges(context.Background()))
865865

866866
for _, kv := range kvs {
867867
node, err := trie.getEditableNode(ToKey(kv.Key), true)
@@ -888,7 +888,7 @@ func Test_Trie_NodeCollapse(t *testing.T) {
888888
)
889889
require.NoError(err)
890890

891-
require.NoError(trie.(*view).calculateNodeIDs(context.Background()))
891+
require.NoError(trie.(*view).applyValueChanges(context.Background()))
892892

893893
for _, kv := range deletedKVs {
894894
_, err := trie.getEditableNode(ToKey(kv.Key), true)

0 commit comments

Comments
 (0)