Skip to content

Commit 68245d1

Browse files
author
Dan Laine
authored
merkledb -- remove unneeded return values (#1959)
1 parent 2eabd22 commit 68245d1

File tree

4 files changed

+20
-31
lines changed

4 files changed

+20
-31
lines changed

x/merkledb/db.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,9 +1085,7 @@ func (db *merkleDB) initializeRootIfNeeded() (ids.ID, error) {
10851085
}
10861086
if err == nil {
10871087
// Root already exists, so calculate its id
1088-
if err := db.root.calculateID(db.metrics); err != nil {
1089-
return ids.Empty, err
1090-
}
1088+
db.root.calculateID(db.metrics)
10911089
return db.root.id, nil
10921090
}
10931091
if err != database.ErrNotFound {
@@ -1098,9 +1096,7 @@ func (db *merkleDB) initializeRootIfNeeded() (ids.ID, error) {
10981096
db.root = newNode(nil, RootPath)
10991097

11001098
// update its ID
1101-
if err := db.root.calculateID(db.metrics); err != nil {
1102-
return ids.Empty, err
1103-
}
1099+
db.root.calculateID(db.metrics)
11041100

11051101
if err := db.intermediateNodeDB.Put(RootPath, db.root); err != nil {
11061102
return ids.Empty, err

x/merkledb/node.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,21 +98,18 @@ func (n *node) onNodeChanged() {
9898
}
9999

100100
// Returns and caches the ID of this node.
101-
func (n *node) calculateID(metrics merkleMetrics) error {
101+
func (n *node) calculateID(metrics merkleMetrics) {
102102
if n.id != ids.Empty {
103-
return nil
103+
return
104104
}
105105

106-
hv := &hashValues{
106+
metrics.HashCalculated()
107+
bytes := codec.encodeHashValues(&hashValues{
107108
Children: n.children,
108109
Value: n.valueDigest,
109110
Key: n.key.Serialize(),
110-
}
111-
112-
bytes := codec.encodeHashValues(hv)
113-
metrics.HashCalculated()
111+
})
114112
n.id = hashing.ComputeHash256Array(bytes)
115-
return nil
116113
}
117114

118115
// Set [n]'s value to [val].

x/merkledb/node_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func Test_Node_Marshal(t *testing.T) {
2121
childNode.setValue(maybe.Some([]byte("value")))
2222
require.NotNil(t, childNode)
2323

24-
require.NoError(t, childNode.calculateID(&mockMetrics{}))
24+
childNode.calculateID(&mockMetrics{})
2525
root.addChild(childNode)
2626

2727
data := root.bytes()
@@ -45,15 +45,15 @@ func Test_Node_Marshal_Errors(t *testing.T) {
4545
childNode1.setValue(maybe.Some([]byte("value1")))
4646
require.NotNil(t, childNode1)
4747

48-
require.NoError(t, childNode1.calculateID(&mockMetrics{}))
48+
childNode1.calculateID(&mockMetrics{})
4949
root.addChild(childNode1)
5050

5151
fullpath = newPath([]byte{237})
5252
childNode2 := newNode(root, fullpath)
5353
childNode2.setValue(maybe.Some([]byte("value2")))
5454
require.NotNil(t, childNode2)
5555

56-
require.NoError(t, childNode2.calculateID(&mockMetrics{}))
56+
childNode2.calculateID(&mockMetrics{})
5757
root.addChild(childNode2)
5858

5959
data := root.bytes()

x/merkledb/trieview.go

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -242,9 +242,7 @@ func (t *trieView) calculateNodeIDs(ctx context.Context) error {
242242
// [eg] limits the number of goroutines we start.
243243
var eg errgroup.Group
244244
eg.SetLimit(t.db.rootGenConcurrency)
245-
if err = t.calculateNodeIDsHelper(ctx, t.root, &eg); err != nil {
246-
return
247-
}
245+
t.calculateNodeIDsHelper(ctx, t.root, &eg)
248246
if err = eg.Wait(); err != nil {
249247
return
250248
}
@@ -261,7 +259,7 @@ func (t *trieView) calculateNodeIDs(ctx context.Context) error {
261259

262260
// Calculates the ID of all descendants of [n] which need to be recalculated,
263261
// and then calculates the ID of [n] itself.
264-
func (t *trieView) calculateNodeIDsHelper(ctx context.Context, n *node, eg *errgroup.Group) error {
262+
func (t *trieView) calculateNodeIDsHelper(ctx context.Context, n *node, eg *errgroup.Group) {
265263
var (
266264
// We use [wg] to wait until all descendants of [n] have been updated.
267265
// Note we can't wait on [eg] because [eg] may have started goroutines
@@ -281,24 +279,22 @@ func (t *trieView) calculateNodeIDsHelper(ctx context.Context, n *node, eg *errg
281279
}
282280

283281
wg.Add(1)
284-
updateChild := func() error {
282+
updateChild := func() {
285283
defer wg.Done()
286284

287-
if err := t.calculateNodeIDsHelper(ctx, childNodeChange.after, eg); err != nil {
288-
return err
289-
}
285+
t.calculateNodeIDsHelper(ctx, childNodeChange.after, eg)
290286

291287
// Note that this will never block
292288
updatedChildren <- childNodeChange.after
293-
return nil
294289
}
295290

296291
// Try updating the child and its descendants in a goroutine.
297-
if ok := eg.TryGo(updateChild); !ok {
292+
if ok := eg.TryGo(func() error {
293+
updateChild()
294+
return nil
295+
}); !ok {
298296
// We're at the goroutine limit; do the work in this goroutine.
299-
if err := updateChild(); err != nil {
300-
return err
301-
}
297+
updateChild()
302298
}
303299
}
304300

@@ -311,7 +307,7 @@ func (t *trieView) calculateNodeIDsHelper(ctx context.Context, n *node, eg *errg
311307
}
312308

313309
// The IDs [n]'s descendants are up to date so we can calculate [n]'s ID.
314-
return n.calculateID(t.db.metrics)
310+
n.calculateID(t.db.metrics)
315311
}
316312

317313
// GetProof returns a proof that [bytesPath] is in or not in trie [t].

0 commit comments

Comments
 (0)