mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 18:32:23 +00:00
trie: fix closure error, work around upstream Go issue
This commit is contained in:
parent
9a4e5db197
commit
eae228f0d8
3 changed files with 25 additions and 7 deletions
|
|
@ -98,7 +98,7 @@ type Trie interface {
|
||||||
GetStorage(addr common.Address, key []byte) ([]byte, error)
|
GetStorage(addr common.Address, key []byte) ([]byte, error)
|
||||||
|
|
||||||
// GetStorageBatch is a batched version of GetStorage that simultaneously looks
|
// GetStorageBatch is a batched version of GetStorage that simultaneously looks
|
||||||
// up multiple slots. The advantage vs. teh singleton version is the potential
|
// up multiple slots. The advantage vs. the singleton version is the potential
|
||||||
// for concurrent disk lookups.
|
// for concurrent disk lookups.
|
||||||
GetStorageBatch(addrs []common.Address, keys [][]byte) ([][]byte, error)
|
GetStorageBatch(addrs []common.Address, keys [][]byte) ([][]byte, error)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -101,7 +101,7 @@ func (t *StateTrie) GetStorage(_ common.Address, key []byte) ([]byte, error) {
|
||||||
func (t *StateTrie) GetStorageBatch(_ []common.Address, keys [][]byte) ([][]byte, error) {
|
func (t *StateTrie) GetStorageBatch(_ []common.Address, keys [][]byte) ([][]byte, error) {
|
||||||
hashes := make([][]byte, len(keys))
|
hashes := make([][]byte, len(keys))
|
||||||
for i, key := range keys {
|
for i, key := range keys {
|
||||||
hashes[i] = t.hashKey(key)
|
hashes[i] = common.CopyBytes(t.hashKey(key))
|
||||||
}
|
}
|
||||||
encs, err := t.trie.GetBatch(hashes)
|
encs, err := t.trie.GetBatch(hashes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -138,7 +138,7 @@ func (t *StateTrie) GetAccount(address common.Address) (*types.StateAccount, err
|
||||||
func (t *StateTrie) GetAccountBatch(addrs []common.Address) ([]*types.StateAccount, error) {
|
func (t *StateTrie) GetAccountBatch(addrs []common.Address) ([]*types.StateAccount, error) {
|
||||||
hashes := make([][]byte, len(addrs))
|
hashes := make([][]byte, len(addrs))
|
||||||
for i, addr := range addrs {
|
for i, addr := range addrs {
|
||||||
hashes[i] = t.hashKey(addr.Bytes())
|
hashes[i] = common.CopyBytes(t.hashKey(addr.Bytes()))
|
||||||
}
|
}
|
||||||
encs, err := t.trie.GetBatch(hashes)
|
encs, err := t.trie.GetBatch(hashes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
26
trie/trie.go
26
trie/trie.go
|
|
@ -279,10 +279,28 @@ func (t *Trie) getBatch(origNode node, keys [][]byte, pos int) ([][]byte, node,
|
||||||
n = n.copy()
|
n = n.copy()
|
||||||
n.Val = newnode
|
n.Val = newnode
|
||||||
}
|
}
|
||||||
values = append(make([][]byte, first), values...)
|
if first == 0 && last == len(keys) {
|
||||||
values = append(values, make([][]byte, len(keys)-last)...)
|
// If all the keys are the same (or there's only 1 key), return the
|
||||||
|
// result values without padding them on the two sides with nils.
|
||||||
return values, n, didResolve, err
|
//
|
||||||
|
// A bit of a weird clause, but this is the default, it is possibly
|
||||||
|
// insiginificantly faster, and it avoids a rare Go crash prior to
|
||||||
|
// v1.22.4 per https://github.com/golang/go/issues/67255.
|
||||||
|
//
|
||||||
|
// TODO(karalabe): Simplify when Go v1.24.0 is out.
|
||||||
|
return values, n, didResolve, err
|
||||||
|
} else {
|
||||||
|
// Only a subset of the keys are existent in the trie, pad the value
|
||||||
|
// return slice with nils for the rest.
|
||||||
|
//
|
||||||
|
// We could also use append here, but that can potentially hit the
|
||||||
|
// above Go issue: https://github.com/golang/go/issues/67255.
|
||||||
|
//
|
||||||
|
// TODO(karalabe): Simplify when Go v1.24.0 is out.
|
||||||
|
result := make([][]byte, len(keys))
|
||||||
|
copy(result[first:], values)
|
||||||
|
return result, n, didResolve, err
|
||||||
|
}
|
||||||
|
|
||||||
case *fullNode:
|
case *fullNode:
|
||||||
var (
|
var (
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue