Skip to content

Commit 4250c2c

Browse files
authored
Revert "trie: use explicit errors in stacktrie (instead of panic) (ethereum#28361)"
This reverts commit 5cbd950.
1 parent ec5e951 commit 4250c2c

File tree

3 files changed

+4
-31
lines changed

3 files changed

+4
-31
lines changed

core/state/snapshot/generate.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,7 @@ func (dl *diskLayer) proveRange(ctx *generatorContext, trieId *trie.ID, prefix [
230230
if origin == nil && !diskMore {
231231
stackTr := trie.NewStackTrie(nil)
232232
for i, key := range keys {
233-
if err := stackTr.Update(key, vals[i]); err != nil {
234-
return nil, err
235-
}
233+
stackTr.Update(key, vals[i])
236234
}
237235
if gotRoot := stackTr.Hash(); gotRoot != root {
238236
return &proofResult{

trie/stacktrie.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package trie
1818

1919
import (
2020
"bytes"
21-
"errors"
2221
"sync"
2322

2423
"github.com/ethereum/go-ethereum/common"
@@ -93,14 +92,12 @@ func NewStackTrie(options *StackTrieOptions) *StackTrie {
9392

9493
// Update inserts a (key, value) pair into the stack trie.
9594
func (t *StackTrie) Update(key, value []byte) error {
95+
k := keybytesToHex(key)
9696
if len(value) == 0 {
97-
return errors.New("trying to insert empty (deletion)")
97+
panic("deletion not supported")
9898
}
99-
k := keybytesToHex(key)
10099
k = k[:len(k)-1] // chop the termination flag
101-
if bytes.Compare(t.last, k) >= 0 {
102-
return errors.New("non-ascending key order")
103-
}
100+
104101
// track the first and last inserted entries.
105102
if t.first == nil {
106103
t.first = append([]byte{}, k...)

trie/stacktrie_test.go

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import (
2626
"github.com/ethereum/go-ethereum/core/rawdb"
2727
"github.com/ethereum/go-ethereum/crypto"
2828
"github.com/ethereum/go-ethereum/trie/testutil"
29-
"github.com/stretchr/testify/assert"
3029
"golang.org/x/exp/slices"
3130
)
3231

@@ -464,24 +463,3 @@ func TestPartialStackTrie(t *testing.T) {
464463
}
465464
}
466465
}
467-
468-
func TestStackTrieErrors(t *testing.T) {
469-
s := NewStackTrie(nil)
470-
// Deletion
471-
if err := s.Update(nil, nil); err == nil {
472-
t.Fatal("expected error")
473-
}
474-
if err := s.Update(nil, []byte{}); err == nil {
475-
t.Fatal("expected error")
476-
}
477-
if err := s.Update([]byte{0xa}, []byte{}); err == nil {
478-
t.Fatal("expected error")
479-
}
480-
// Non-ascending keys (going backwards or repeating)
481-
assert.Nil(t, s.Update([]byte{0xaa}, []byte{0xa}))
482-
assert.NotNil(t, s.Update([]byte{0xaa}, []byte{0xa}), "repeat insert same key")
483-
assert.NotNil(t, s.Update([]byte{0xaa}, []byte{0xb}), "repeat insert same key")
484-
assert.Nil(t, s.Update([]byte{0xab}, []byte{0xa}))
485-
assert.NotNil(t, s.Update([]byte{0x10}, []byte{0xb}), "out of order insert")
486-
assert.NotNil(t, s.Update([]byte{0xaa}, []byte{0xb}), "repeat insert same key")
487-
}

0 commit comments

Comments
 (0)