mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-25 06:06:44 +00:00
use flatReader
This commit is contained in:
parent
9e0ea3fccc
commit
6f4f78b568
3 changed files with 28 additions and 30 deletions
|
|
@ -73,7 +73,7 @@ type StateReader interface {
|
||||||
Storage(addr common.Address, slot common.Hash) (common.Hash, error)
|
Storage(addr common.Address, slot common.Hash) (common.Hash, error)
|
||||||
|
|
||||||
AccountBAL(addr common.Address) (*types.StateAccount, error)
|
AccountBAL(addr common.Address) (*types.StateAccount, error)
|
||||||
StorageBAL(addr common.Address, slot common.Hash, tr *trie.StateTrie) (common.Hash, error)
|
StorageBAL(addr common.Address, slot common.Hash) (common.Hash, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reader defines the interface for accessing accounts, storage slots and contract
|
// Reader defines the interface for accessing accounts, storage slots and contract
|
||||||
|
|
@ -207,7 +207,7 @@ func (r *flatReader) Storage(addr common.Address, key common.Hash) (common.Hash,
|
||||||
return value, nil
|
return value, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *flatReader) StorageBAL(addr common.Address, key common.Hash, tr *trie.StateTrie) (common.Hash, error) {
|
func (r *flatReader) StorageBAL(addr common.Address, key common.Hash) (common.Hash, error) {
|
||||||
return r.Storage(addr, key)
|
return r.Storage(addr, key)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -333,15 +333,8 @@ func (r *trieReader) Storage(addr common.Address, key common.Hash) (common.Hash,
|
||||||
return value, nil
|
return value, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *trieReader) StorageBAL(addr common.Address, key common.Hash, tr *trie.StateTrie) (common.Hash, error) {
|
func (r *trieReader) StorageBAL(addr common.Address, key common.Hash) (common.Hash, error) {
|
||||||
ret, err := tr.GetStorage(addr, key.Bytes())
|
return r.Storage(addr, key)
|
||||||
if err != nil {
|
|
||||||
return common.Hash{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
var value common.Hash
|
|
||||||
value.SetBytes(ret)
|
|
||||||
return value, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// multiStateReader is the aggregation of a list of StateReader interface,
|
// multiStateReader is the aggregation of a list of StateReader interface,
|
||||||
|
|
@ -387,12 +380,18 @@ func (r *multiStateReader) Account(addr common.Address) (*types.StateAccount, er
|
||||||
func (r *multiStateReader) AccountBAL(addr common.Address) (*types.StateAccount, error) {
|
func (r *multiStateReader) AccountBAL(addr common.Address) (*types.StateAccount, error) {
|
||||||
var errs []error
|
var errs []error
|
||||||
for _, reader := range r.readers {
|
for _, reader := range r.readers {
|
||||||
|
switch reader.(type) {
|
||||||
|
case *flatReader:
|
||||||
|
{
|
||||||
acct, err := reader.AccountBAL(addr)
|
acct, err := reader.AccountBAL(addr)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return acct, nil
|
return acct, nil
|
||||||
}
|
}
|
||||||
errs = append(errs, err)
|
errs = append(errs, err)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
errs = append(errs, errors.New("no flatReader"))
|
||||||
return nil, errors.Join(errs...)
|
return nil, errors.Join(errs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -414,15 +413,21 @@ func (r *multiStateReader) Storage(addr common.Address, slot common.Hash) (commo
|
||||||
return common.Hash{}, errors.Join(errs...)
|
return common.Hash{}, errors.Join(errs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *multiStateReader) StorageBAL(addr common.Address, slot common.Hash, tr *trie.StateTrie) (common.Hash, error) {
|
func (r *multiStateReader) StorageBAL(addr common.Address, slot common.Hash) (common.Hash, error) {
|
||||||
var errs []error
|
var errs []error
|
||||||
for _, reader := range r.readers {
|
for _, reader := range r.readers {
|
||||||
slot, err := reader.StorageBAL(addr, slot, tr)
|
switch reader.(type) {
|
||||||
|
case *flatReader:
|
||||||
|
{
|
||||||
|
slot, err := reader.Storage(addr, slot)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return slot, nil
|
return slot, nil
|
||||||
}
|
}
|
||||||
errs = append(errs, err)
|
errs = append(errs, err)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
errs = append(errs, errors.New("no flatReader"))
|
||||||
return common.Hash{}, errors.Join(errs...)
|
return common.Hash{}, errors.Join(errs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -337,6 +337,7 @@ func (s *StateDB) SetPostBAL(postBal map[int]types.TxPostValues, bn uint64) erro
|
||||||
}
|
}
|
||||||
s.blockNumber = bn
|
s.blockNumber = bn
|
||||||
s.postBAL = postBal
|
s.postBAL = postBal
|
||||||
|
s.prefetcher = nil
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -416,16 +417,9 @@ func (s *StateDB) prefetchBalPreblockKeys() {
|
||||||
|
|
||||||
lenSlots += len(acl.StorageKeys)
|
lenSlots += len(acl.StorageKeys)
|
||||||
|
|
||||||
tr, err := trie.NewStateTrie(trie.StorageTrieID(s.originalRoot, obj.addrHash, obj.origin.Root), s.db.TrieDB())
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println(s.originalRoot, obj.addrHash, obj.origin.Root)
|
|
||||||
log.Error("fail to create trie for", "addr:", addr, "error:", err)
|
|
||||||
panic("fail to create trie")
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, key := range keys {
|
for _, key := range keys {
|
||||||
workers.Go(func() error {
|
workers.Go(func() error {
|
||||||
val, err := s.reader.StorageBAL(addr, key, tr)
|
val, err := s.reader.StorageBAL(addr, key)
|
||||||
kv := &StorageKV{&addr, &key, &val}
|
kv := &StorageKV{&addr, &key, &val}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("fail to fetch storage from BALs:", addr, key)
|
log.Error("fail to fetch storage from BALs:", addr, key)
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@ import (
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/trie"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// All states must has been cachae to statedb.
|
// All states must has been cachae to statedb.
|
||||||
|
|
@ -40,6 +39,6 @@ func (s *StateDB) AccountBAL(addr common.Address) (*types.StateAccount, error) {
|
||||||
panic("AccountBAL not implemented for statedb")
|
panic("AccountBAL not implemented for statedb")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StateDB) StorageBAL(addr common.Address, slot common.Hash, tr *trie.StateTrie) (common.Hash, error) {
|
func (s *StateDB) StorageBAL(addr common.Address, slot common.Hash) (common.Hash, error) {
|
||||||
panic("StorageBAL not implemented for statedb")
|
panic("StorageBAL not implemented for statedb")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue