mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
Revert "core/state: move slot RLP encoding into the MPT implementation (#27000)"
This reverts commit 797c10068e.
This commit is contained in:
parent
955ff6ee56
commit
74d25c4c98
3 changed files with 21 additions and 35 deletions
|
|
@ -185,7 +185,6 @@ func (s *stateObject) GetCommittedState(db Database, key common.Hash) common.Has
|
||||||
var (
|
var (
|
||||||
enc []byte
|
enc []byte
|
||||||
err error
|
err error
|
||||||
value common.Hash
|
|
||||||
)
|
)
|
||||||
if s.db.snap != nil {
|
if s.db.snap != nil {
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
|
|
@ -193,13 +192,6 @@ func (s *stateObject) GetCommittedState(db Database, key common.Hash) common.Has
|
||||||
if metrics.EnabledExpensive {
|
if metrics.EnabledExpensive {
|
||||||
s.db.SnapshotStorageReads += time.Since(start)
|
s.db.SnapshotStorageReads += time.Since(start)
|
||||||
}
|
}
|
||||||
if len(enc) > 0 {
|
|
||||||
_, content, _, err := rlp.Split(enc)
|
|
||||||
if err != nil {
|
|
||||||
s.db.setError(err)
|
|
||||||
}
|
|
||||||
value.SetBytes(content)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// If the snapshot is unavailable or reading from it fails, load from the database.
|
// If the snapshot is unavailable or reading from it fails, load from the database.
|
||||||
if s.db.snap == nil || err != nil {
|
if s.db.snap == nil || err != nil {
|
||||||
|
|
@ -209,7 +201,7 @@ func (s *stateObject) GetCommittedState(db Database, key common.Hash) common.Has
|
||||||
s.db.setError(err)
|
s.db.setError(err)
|
||||||
return common.Hash{}
|
return common.Hash{}
|
||||||
}
|
}
|
||||||
val, err := tr.GetStorage(s.address, key.Bytes())
|
enc, err = tr.GetStorage(s.address, key.Bytes())
|
||||||
if metrics.EnabledExpensive {
|
if metrics.EnabledExpensive {
|
||||||
s.db.StorageReads += time.Since(start)
|
s.db.StorageReads += time.Since(start)
|
||||||
}
|
}
|
||||||
|
|
@ -217,7 +209,14 @@ func (s *stateObject) GetCommittedState(db Database, key common.Hash) common.Has
|
||||||
s.db.setError(err)
|
s.db.setError(err)
|
||||||
return common.Hash{}
|
return common.Hash{}
|
||||||
}
|
}
|
||||||
value.SetBytes(val)
|
}
|
||||||
|
var value common.Hash
|
||||||
|
if len(enc) > 0 {
|
||||||
|
_, content, _, err := rlp.Split(enc)
|
||||||
|
if err != nil {
|
||||||
|
s.db.setError(err)
|
||||||
|
}
|
||||||
|
value.SetBytes(content)
|
||||||
}
|
}
|
||||||
s.originStorage[key] = value
|
s.originStorage[key] = value
|
||||||
return value
|
return value
|
||||||
|
|
@ -293,8 +292,7 @@ func (s *stateObject) updateTrie(db Database) (Trie, error) {
|
||||||
}
|
}
|
||||||
s.originStorage[key] = value
|
s.originStorage[key] = value
|
||||||
|
|
||||||
// rlp-encoded value to be used by the snapshot
|
var v []byte
|
||||||
var snapshotVal []byte
|
|
||||||
if (value == common.Hash{}) {
|
if (value == common.Hash{}) {
|
||||||
if err := tr.DeleteStorage(s.address, key[:]); err != nil {
|
if err := tr.DeleteStorage(s.address, key[:]); err != nil {
|
||||||
s.db.setError(err)
|
s.db.setError(err)
|
||||||
|
|
@ -302,10 +300,9 @@ func (s *stateObject) updateTrie(db Database) (Trie, error) {
|
||||||
}
|
}
|
||||||
s.db.StorageDeleted += 1
|
s.db.StorageDeleted += 1
|
||||||
} else {
|
} else {
|
||||||
trimmedVal := common.TrimLeftZeroes(value[:])
|
|
||||||
// Encoding []byte cannot fail, ok to ignore the error.
|
// Encoding []byte cannot fail, ok to ignore the error.
|
||||||
snapshotVal, _ = rlp.EncodeToBytes(trimmedVal)
|
v, _ = rlp.EncodeToBytes(common.TrimLeftZeroes(value[:]))
|
||||||
if err := tr.UpdateStorage(s.address, key[:], trimmedVal); err != nil {
|
if err := tr.UpdateStorage(s.address, key[:], v); err != nil {
|
||||||
s.db.setError(err)
|
s.db.setError(err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -320,7 +317,7 @@ func (s *stateObject) updateTrie(db Database) (Trie, error) {
|
||||||
s.db.snapStorage[s.addrHash] = storage
|
s.db.snapStorage[s.addrHash] = storage
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
storage[crypto.HashData(hasher, key[:])] = snapshotVal // will be nil if it's deleted
|
storage[crypto.HashData(hasher, key[:])] = v // v will be nil if it's deleted
|
||||||
}
|
}
|
||||||
usedStorage = append(usedStorage, common.CopyBytes(key[:])) // Copy needed for closure
|
usedStorage = append(usedStorage, common.CopyBytes(key[:])) // Copy needed for closure
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -108,16 +108,12 @@ type odrTrie struct {
|
||||||
|
|
||||||
func (t *odrTrie) GetStorage(_ common.Address, key []byte) ([]byte, error) {
|
func (t *odrTrie) GetStorage(_ common.Address, key []byte) ([]byte, error) {
|
||||||
key = crypto.Keccak256(key)
|
key = crypto.Keccak256(key)
|
||||||
var enc []byte
|
var res []byte
|
||||||
err := t.do(key, func() (err error) {
|
err := t.do(key, func() (err error) {
|
||||||
enc, err = t.trie.Get(key)
|
res, err = t.trie.Get(key)
|
||||||
return err
|
return err
|
||||||
})
|
})
|
||||||
if err != nil || len(enc) == 0 {
|
return res, err
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
_, content, _, err := rlp.Split(enc)
|
|
||||||
return content, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *odrTrie) GetAccount(address common.Address) (*types.StateAccount, error) {
|
func (t *odrTrie) GetAccount(address common.Address) (*types.StateAccount, error) {
|
||||||
|
|
@ -149,9 +145,8 @@ func (t *odrTrie) UpdateAccount(address common.Address, acc *types.StateAccount)
|
||||||
|
|
||||||
func (t *odrTrie) UpdateStorage(_ common.Address, key, value []byte) error {
|
func (t *odrTrie) UpdateStorage(_ common.Address, key, value []byte) error {
|
||||||
key = crypto.Keccak256(key)
|
key = crypto.Keccak256(key)
|
||||||
v, _ := rlp.EncodeToBytes(value)
|
|
||||||
return t.do(key, func() error {
|
return t.do(key, func() error {
|
||||||
return t.trie.Update(key, v)
|
return t.trie.Update(key, value)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -86,12 +86,7 @@ func (t *StateTrie) MustGet(key []byte) []byte {
|
||||||
// If the specified storage slot is not in the trie, nil will be returned.
|
// If the specified storage slot is not in the trie, nil will be returned.
|
||||||
// If a trie node is not found in the database, a MissingNodeError is returned.
|
// If a trie node is not found in the database, a MissingNodeError is returned.
|
||||||
func (t *StateTrie) GetStorage(_ common.Address, key []byte) ([]byte, error) {
|
func (t *StateTrie) GetStorage(_ common.Address, key []byte) ([]byte, error) {
|
||||||
enc, err := t.trie.Get(t.hashKey(key))
|
return t.trie.Get(t.hashKey(key))
|
||||||
if err != nil || len(enc) == 0 {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
_, content, _, err := rlp.Split(enc)
|
|
||||||
return content, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAccount attempts to retrieve an account with provided account address.
|
// GetAccount attempts to retrieve an account with provided account address.
|
||||||
|
|
@ -153,8 +148,7 @@ func (t *StateTrie) MustUpdate(key, value []byte) {
|
||||||
// If a node is not found in the database, a MissingNodeError is returned.
|
// If a node is not found in the database, a MissingNodeError is returned.
|
||||||
func (t *StateTrie) UpdateStorage(_ common.Address, key, value []byte) error {
|
func (t *StateTrie) UpdateStorage(_ common.Address, key, value []byte) error {
|
||||||
hk := t.hashKey(key)
|
hk := t.hashKey(key)
|
||||||
v, _ := rlp.EncodeToBytes(value)
|
err := t.trie.Update(hk, value)
|
||||||
err := t.trie.Update(hk, v)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue