core/state: move slot RLP encoding into the MPT implementation (#27000)

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.
This commit is contained in:
Guillaume Ballet
2023-06-01 10:29:41 +02:00
committed by GitHub
parent ac86547b01
commit 45a3ab42aa
3 changed files with 35 additions and 21 deletions
+9 -4
View File
@@ -108,12 +108,16 @@ type odrTrie struct {
func (t *odrTrie) GetStorage(_ common.Address, key []byte) ([]byte, error) {
key = crypto.Keccak256(key)
var res []byte
var enc []byte
err := t.do(key, func() (err error) {
res, err = t.trie.Get(key)
enc, err = t.trie.Get(key)
return err
})
return res, err
if err != nil || len(enc) == 0 {
return nil, err
}
_, content, _, err := rlp.Split(enc)
return content, err
}
func (t *odrTrie) GetAccount(address common.Address) (*types.StateAccount, error) {
@@ -145,8 +149,9 @@ func (t *odrTrie) UpdateAccount(address common.Address, acc *types.StateAccount)
func (t *odrTrie) UpdateStorage(_ common.Address, key, value []byte) error {
key = crypto.Keccak256(key)
v, _ := rlp.EncodeToBytes(value)
return t.do(key, func() error {
return t.trie.Update(key, value)
return t.trie.Update(key, v)
})
}