core/state: move state account to core/types + abstracted "write account to trie" (#23567)

* core/state: abstracted "write account to trie" method

* fix appveyor build

* Apply suggestions from code review

Co-authored-by: Martin Holst Swende <martin@swende.se>

* review feedback

* core/state/accounts: move Account to core/types

* core/types: rename Account -> StateAccount

* core/state: restore EncodeRLP for stateObject

* core/types: add the missing file

* more review feedback

* more review feedback

Co-authored-by: Martin Holst Swende <martin@swende.se>
Co-authored-by: Felix Lange <fjl@twurst.com>
This commit is contained in:
Guillaume Ballet
2021-09-28 10:48:07 +02:00
committed by GitHub
parent ac7baeab57
commit 443afc975c
18 changed files with 122 additions and 61 deletions

View File

@ -27,7 +27,7 @@ import (
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/forkid"
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/les/flowcontrol"
"github.com/ethereum/go-ethereum/light"
@ -358,20 +358,20 @@ func (h *serverHandler) AddTxsSync() bool {
}
// getAccount retrieves an account from the state based on root.
func getAccount(triedb *trie.Database, root, hash common.Hash) (state.Account, error) {
func getAccount(triedb *trie.Database, root, hash common.Hash) (types.StateAccount, error) {
trie, err := trie.New(root, triedb)
if err != nil {
return state.Account{}, err
return types.StateAccount{}, err
}
blob, err := trie.TryGet(hash[:])
if err != nil {
return state.Account{}, err
return types.StateAccount{}, err
}
var account state.Account
if err = rlp.DecodeBytes(blob, &account); err != nil {
return state.Account{}, err
var acc types.StateAccount
if err = rlp.DecodeBytes(blob, &acc); err != nil {
return types.StateAccount{}, err
}
return account, nil
return acc, nil
}
// getHelperTrie returns the post-processed trie root for the given trie ID and section index