Skip to content

Commit 69351e8

Browse files
jwasingerkaralabe
andauthored
core/state, eth/protocols, trie, triedb/pathdb: remove unused error from trie Commit (#29869)
* core/state, eth/protocols, trie, triedb/pathdb: remove unused error return from trie Commit * move set back to account-trie-update block scoping for easier readability * address review * undo tests submodule change * trie: panic if BatchSerialize returns an error in Verkle trie Commit * trie: verkle comment nitpicks --------- Co-authored-by: Péter Szilágyi <[email protected]>
1 parent 3687c34 commit 69351e8

File tree

18 files changed

+72
-98
lines changed

18 files changed

+72
-98
lines changed

core/state/database.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ type Trie interface {
123123
// The returned nodeset can be nil if the trie is clean(nothing to commit).
124124
// Once the trie is committed, it's not usable anymore. A new trie must
125125
// be created with new root and updated trie database for following usage
126-
Commit(collectLeaf bool) (common.Hash, *trienode.NodeSet, error)
126+
Commit(collectLeaf bool) (common.Hash, *trienode.NodeSet)
127127

128128
// NodeIterator returns an iterator that returns nodes of the trie. Iteration
129129
// starts at the key after the given start key. And error will be returned

core/state/snapshot/generate.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -360,10 +360,7 @@ func (dl *diskLayer) generateRange(ctx *generatorContext, trieId *trie.ID, prefi
360360
for i, key := range result.keys {
361361
snapTrie.Update(key, result.vals[i])
362362
}
363-
root, nodes, err := snapTrie.Commit(false)
364-
if err != nil {
365-
return false, nil, err
366-
}
363+
root, nodes := snapTrie.Commit(false)
367364
if nodes != nil {
368365
tdb.Update(root, types.EmptyRootHash, 0, trienode.NewWithNodeSet(nodes), nil)
369366
tdb.Commit(root, false)

core/state/snapshot/generate_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,15 +210,15 @@ func (t *testHelper) makeStorageTrie(owner common.Hash, keys []string, vals []st
210210
if !commit {
211211
return stTrie.Hash()
212212
}
213-
root, nodes, _ := stTrie.Commit(false)
213+
root, nodes := stTrie.Commit(false)
214214
if nodes != nil {
215215
t.nodes.Merge(nodes)
216216
}
217217
return root
218218
}
219219

220220
func (t *testHelper) Commit() common.Hash {
221-
root, nodes, _ := t.accTrie.Commit(true)
221+
root, nodes := t.accTrie.Commit(true)
222222
if nodes != nil {
223223
t.nodes.Merge(nodes)
224224
}

core/state/state_object.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -470,10 +470,7 @@ func (s *stateObject) commit() (*accountUpdate, *trienode.NodeSet, error) {
470470
s.origin = s.data.Copy()
471471
return op, nil, nil
472472
}
473-
root, nodes, err := s.trie.Commit(false)
474-
if err != nil {
475-
return nil, nil, err
476-
}
473+
root, nodes := s.trie.Commit(false)
477474
s.data.Root = root
478475
s.origin = s.data.Copy()
479476
return op, nodes, nil

core/state/statedb.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,10 +1179,7 @@ func (s *StateDB) commit(deleteEmptyObjects bool) (*stateUpdate, error) {
11791179
// code didn't anticipate for.
11801180
workers.Go(func() error {
11811181
// Write the account trie changes, measuring the amount of wasted time
1182-
newroot, set, err := s.trie.Commit(true)
1183-
if err != nil {
1184-
return err
1185-
}
1182+
newroot, set := s.trie.Commit(true)
11861183
root = newroot
11871184

11881185
if err := merge(set); err != nil {

eth/protocols/snap/sync_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1525,7 +1525,7 @@ func makeAccountTrieNoStorage(n int, scheme string) (string, *trie.Trie, []*kv)
15251525

15261526
// Commit the state changes into db and re-create the trie
15271527
// for accessing later.
1528-
root, nodes, _ := accTrie.Commit(false)
1528+
root, nodes := accTrie.Commit(false)
15291529
db.Update(root, types.EmptyRootHash, 0, trienode.NewWithNodeSet(nodes), nil)
15301530

15311531
accTrie, _ = trie.New(trie.StateTrieID(root), db)
@@ -1587,7 +1587,7 @@ func makeBoundaryAccountTrie(scheme string, n int) (string, *trie.Trie, []*kv) {
15871587

15881588
// Commit the state changes into db and re-create the trie
15891589
// for accessing later.
1590-
root, nodes, _ := accTrie.Commit(false)
1590+
root, nodes := accTrie.Commit(false)
15911591
db.Update(root, types.EmptyRootHash, 0, trienode.NewWithNodeSet(nodes), nil)
15921592

15931593
accTrie, _ = trie.New(trie.StateTrieID(root), db)
@@ -1633,7 +1633,7 @@ func makeAccountTrieWithStorageWithUniqueStorage(scheme string, accounts, slots
16331633
slices.SortFunc(entries, (*kv).cmp)
16341634

16351635
// Commit account trie
1636-
root, set, _ := accTrie.Commit(true)
1636+
root, set := accTrie.Commit(true)
16371637
nodes.Merge(set)
16381638

16391639
// Commit gathered dirty nodes into database
@@ -1700,7 +1700,7 @@ func makeAccountTrieWithStorage(scheme string, accounts, slots int, code, bounda
17001700
slices.SortFunc(entries, (*kv).cmp)
17011701

17021702
// Commit account trie
1703-
root, set, _ := accTrie.Commit(true)
1703+
root, set := accTrie.Commit(true)
17041704
nodes.Merge(set)
17051705

17061706
// Commit gathered dirty nodes into database
@@ -1742,7 +1742,7 @@ func makeStorageTrieWithSeed(owner common.Hash, n, seed uint64, db *triedb.Datab
17421742
entries = append(entries, elem)
17431743
}
17441744
slices.SortFunc(entries, (*kv).cmp)
1745-
root, nodes, _ := trie.Commit(false)
1745+
root, nodes := trie.Commit(false)
17461746
return root, nodes, entries
17471747
}
17481748

@@ -1793,7 +1793,7 @@ func makeBoundaryStorageTrie(owner common.Hash, n int, db *triedb.Database) (com
17931793
entries = append(entries, elem)
17941794
}
17951795
slices.SortFunc(entries, (*kv).cmp)
1796-
root, nodes, _ := trie.Commit(false)
1796+
root, nodes := trie.Commit(false)
17971797
return root, nodes, entries
17981798
}
17991799

@@ -1825,7 +1825,7 @@ func makeUnevenStorageTrie(owner common.Hash, slots int, db *triedb.Database) (c
18251825
}
18261826
}
18271827
slices.SortFunc(entries, (*kv).cmp)
1828-
root, nodes, _ := tr.Commit(false)
1828+
root, nodes := tr.Commit(false)
18291829
return root, nodes, entries
18301830
}
18311831

trie/iterator_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func TestIterator(t *testing.T) {
5959
all[val.k] = val.v
6060
trie.MustUpdate([]byte(val.k), []byte(val.v))
6161
}
62-
root, nodes, _ := trie.Commit(false)
62+
root, nodes := trie.Commit(false)
6363
db.Update(root, types.EmptyRootHash, trienode.NewWithNodeSet(nodes))
6464

6565
trie, _ = New(TrieID(root), db)
@@ -257,7 +257,7 @@ func TestDifferenceIterator(t *testing.T) {
257257
for _, val := range testdata1 {
258258
triea.MustUpdate([]byte(val.k), []byte(val.v))
259259
}
260-
rootA, nodesA, _ := triea.Commit(false)
260+
rootA, nodesA := triea.Commit(false)
261261
dba.Update(rootA, types.EmptyRootHash, trienode.NewWithNodeSet(nodesA))
262262
triea, _ = New(TrieID(rootA), dba)
263263

@@ -266,7 +266,7 @@ func TestDifferenceIterator(t *testing.T) {
266266
for _, val := range testdata2 {
267267
trieb.MustUpdate([]byte(val.k), []byte(val.v))
268268
}
269-
rootB, nodesB, _ := trieb.Commit(false)
269+
rootB, nodesB := trieb.Commit(false)
270270
dbb.Update(rootB, types.EmptyRootHash, trienode.NewWithNodeSet(nodesB))
271271
trieb, _ = New(TrieID(rootB), dbb)
272272

@@ -299,7 +299,7 @@ func TestUnionIterator(t *testing.T) {
299299
for _, val := range testdata1 {
300300
triea.MustUpdate([]byte(val.k), []byte(val.v))
301301
}
302-
rootA, nodesA, _ := triea.Commit(false)
302+
rootA, nodesA := triea.Commit(false)
303303
dba.Update(rootA, types.EmptyRootHash, trienode.NewWithNodeSet(nodesA))
304304
triea, _ = New(TrieID(rootA), dba)
305305

@@ -308,7 +308,7 @@ func TestUnionIterator(t *testing.T) {
308308
for _, val := range testdata2 {
309309
trieb.MustUpdate([]byte(val.k), []byte(val.v))
310310
}
311-
rootB, nodesB, _ := trieb.Commit(false)
311+
rootB, nodesB := trieb.Commit(false)
312312
dbb.Update(rootB, types.EmptyRootHash, trienode.NewWithNodeSet(nodesB))
313313
trieb, _ = New(TrieID(rootB), dbb)
314314

@@ -371,7 +371,7 @@ func testIteratorContinueAfterError(t *testing.T, memonly bool, scheme string) {
371371
for _, val := range testdata1 {
372372
tr.MustUpdate([]byte(val.k), []byte(val.v))
373373
}
374-
root, nodes, _ := tr.Commit(false)
374+
root, nodes := tr.Commit(false)
375375
tdb.Update(root, types.EmptyRootHash, trienode.NewWithNodeSet(nodes))
376376
if !memonly {
377377
tdb.Commit(root)
@@ -481,7 +481,7 @@ func testIteratorContinueAfterSeekError(t *testing.T, memonly bool, scheme strin
481481
for _, val := range testdata1 {
482482
ctr.MustUpdate([]byte(val.k), []byte(val.v))
483483
}
484-
root, nodes, _ := ctr.Commit(false)
484+
root, nodes := ctr.Commit(false)
485485
for path, n := range nodes.Nodes {
486486
if n.Hash == barNodeHash {
487487
barNodePath = []byte(path)
@@ -561,7 +561,7 @@ func testIteratorNodeBlob(t *testing.T, scheme string) {
561561
all[val.k] = val.v
562562
trie.MustUpdate([]byte(val.k), []byte(val.v))
563563
}
564-
root, nodes, _ := trie.Commit(false)
564+
root, nodes := trie.Commit(false)
565565
triedb.Update(root, types.EmptyRootHash, trienode.NewWithNodeSet(nodes))
566566
triedb.Commit(root)
567567

trie/secure_trie.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ func (t *StateTrie) GetKey(shaKey []byte) []byte {
221221
// All cached preimages will be also flushed if preimages recording is enabled.
222222
// Once the trie is committed, it's not usable anymore. A new trie must
223223
// be created with new root and updated trie database for following usage
224-
func (t *StateTrie) Commit(collectLeaf bool) (common.Hash, *trienode.NodeSet, error) {
224+
func (t *StateTrie) Commit(collectLeaf bool) (common.Hash, *trienode.NodeSet) {
225225
// Write all the pre-images to the actual disk database
226226
if len(t.getSecKeyCache()) > 0 {
227227
preimages := make(map[common.Hash][]byte)

trie/secure_trie_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func makeTestStateTrie() (*testDb, *StateTrie, map[string][]byte) {
6060
trie.MustUpdate(key, val)
6161
}
6262
}
63-
root, nodes, _ := trie.Commit(false)
63+
root, nodes := trie.Commit(false)
6464
if err := triedb.Update(root, types.EmptyRootHash, trienode.NewWithNodeSet(nodes)); err != nil {
6565
panic(fmt.Errorf("failed to commit db %v", err))
6666
}

trie/stacktrie_fuzzer_test.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,7 @@ func fuzz(data []byte, debugging bool) {
7979
return
8080
}
8181
// Flush trie -> database
82-
rootA, nodes, err := trieA.Commit(false)
83-
if err != nil {
84-
panic(err)
85-
}
82+
rootA, nodes := trieA.Commit(false)
8683
if nodes != nil {
8784
dbA.Update(rootA, types.EmptyRootHash, trienode.NewWithNodeSet(nodes))
8885
}

0 commit comments

Comments
 (0)