mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-21 22:24:32 +00:00
Continuing with a series of PRs to make the Trie interface more generic, this PR moves the RLP encoding of storage slots inside the StateTrie and light.Trie implementations, as other types of tries don't use RLP. Co-authored-by: Guillaume Ballet <3272758+gballet@users.noreply.github.com>
This commit is contained in:
parent
e40208f3db
commit
3518be8c8b
2 changed files with 12 additions and 12 deletions
|
|
@ -185,20 +185,14 @@ func (s *stateObject) GetCommittedState(key common.Hash) common.Hash {
|
|||
s.db.setError(err)
|
||||
return common.Hash{}
|
||||
}
|
||||
enc, err := tr.GetStorage(s.address, key.Bytes())
|
||||
val, err := tr.GetStorage(s.address, key.Bytes())
|
||||
s.db.StorageReads += time.Since(start)
|
||||
if err != nil {
|
||||
s.db.setError(err)
|
||||
return common.Hash{}
|
||||
}
|
||||
var value common.Hash
|
||||
if len(enc) > 0 {
|
||||
_, content, _, err := rlp.Split(enc)
|
||||
if err != nil {
|
||||
s.db.setError(err)
|
||||
}
|
||||
value.SetBytes(content)
|
||||
}
|
||||
value.SetBytes(val)
|
||||
s.originStorage[key] = value
|
||||
return value
|
||||
}
|
||||
|
|
@ -267,9 +261,9 @@ func (s *stateObject) updateTrie() (Trie, error) {
|
|||
}
|
||||
s.db.StorageDeleted += 1
|
||||
} else {
|
||||
trimmedVal := common.TrimLeftZeroes(value[:])
|
||||
// Encoding []byte cannot fail, ok to ignore the error.
|
||||
v, _ := rlp.EncodeToBytes(common.TrimLeftZeroes(value[:]))
|
||||
if err := tr.UpdateStorage(s.address, key[:], v); err != nil {
|
||||
if err := tr.UpdateStorage(s.address, key[:], trimmedVal); err != nil {
|
||||
s.db.setError(err)
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -86,7 +86,12 @@ func (t *StateTrie) MustGet(key []byte) []byte {
|
|||
// 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.
|
||||
func (t *StateTrie) GetStorage(_ common.Address, key []byte) ([]byte, error) {
|
||||
return t.trie.Get(t.hashKey(key))
|
||||
enc, err := 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.
|
||||
|
|
@ -148,7 +153,8 @@ func (t *StateTrie) MustUpdate(key, value []byte) {
|
|||
// If a node is not found in the database, a MissingNodeError is returned.
|
||||
func (t *StateTrie) UpdateStorage(_ common.Address, key, value []byte) error {
|
||||
hk := t.hashKey(key)
|
||||
err := t.trie.Update(hk, value)
|
||||
v, _ := rlp.EncodeToBytes(value)
|
||||
err := t.trie.Update(hk, v)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue