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:
@ -23,7 +23,7 @@ import (
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/core"
|
||||
"github.com/ethereum/go-ethereum/core/state"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/light"
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
"github.com/ethereum/go-ethereum/metrics"
|
||||
@ -319,7 +319,7 @@ func handleMessage(backend Backend, peer *Peer) error {
|
||||
if err != nil {
|
||||
return p2p.Send(peer.rw, StorageRangesMsg, &StorageRangesPacket{ID: req.ID})
|
||||
}
|
||||
var acc state.Account
|
||||
var acc types.StateAccount
|
||||
if err := rlp.DecodeBytes(accTrie.Get(account[:]), &acc); err != nil {
|
||||
return p2p.Send(peer.rw, StorageRangesMsg, &StorageRangesPacket{ID: req.ID})
|
||||
}
|
||||
|
@ -32,6 +32,7 @@ import (
|
||||
"github.com/ethereum/go-ethereum/core/rawdb"
|
||||
"github.com/ethereum/go-ethereum/core/state"
|
||||
"github.com/ethereum/go-ethereum/core/state/snapshot"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
"github.com/ethereum/go-ethereum/ethdb"
|
||||
"github.com/ethereum/go-ethereum/event"
|
||||
@ -125,8 +126,8 @@ type accountRequest struct {
|
||||
type accountResponse struct {
|
||||
task *accountTask // Task which this request is filling
|
||||
|
||||
hashes []common.Hash // Account hashes in the returned range
|
||||
accounts []*state.Account // Expanded accounts in the returned range
|
||||
hashes []common.Hash // Account hashes in the returned range
|
||||
accounts []*types.StateAccount // Expanded accounts in the returned range
|
||||
|
||||
cont bool // Whether the account range has a continuation
|
||||
}
|
||||
@ -2274,9 +2275,9 @@ func (s *Syncer) OnAccounts(peer SyncPeer, id uint64, hashes []common.Hash, acco
|
||||
s.scheduleRevertAccountRequest(req)
|
||||
return err
|
||||
}
|
||||
accs := make([]*state.Account, len(accounts))
|
||||
accs := make([]*types.StateAccount, len(accounts))
|
||||
for i, account := range accounts {
|
||||
acc := new(state.Account)
|
||||
acc := new(types.StateAccount)
|
||||
if err := rlp.DecodeBytes(account, acc); err != nil {
|
||||
panic(err) // We created these blobs, we must be able to decode them
|
||||
}
|
||||
@ -2740,7 +2741,7 @@ func (s *Syncer) onHealByteCodes(peer SyncPeer, id uint64, bytecodes [][]byte) e
|
||||
// Note it's not concurrent safe, please handle the concurrent issue outside.
|
||||
func (s *Syncer) onHealState(paths [][]byte, value []byte) error {
|
||||
if len(paths) == 1 {
|
||||
var account state.Account
|
||||
var account types.StateAccount
|
||||
if err := rlp.DecodeBytes(value, &account); err != nil {
|
||||
return nil
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ import (
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"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/crypto"
|
||||
"github.com/ethereum/go-ethereum/ethdb"
|
||||
"github.com/ethereum/go-ethereum/light"
|
||||
@ -1349,7 +1349,7 @@ func makeAccountTrieNoStorage(n int) (*trie.Trie, entrySlice) {
|
||||
accTrie, _ := trie.New(common.Hash{}, db)
|
||||
var entries entrySlice
|
||||
for i := uint64(1); i <= uint64(n); i++ {
|
||||
value, _ := rlp.EncodeToBytes(state.Account{
|
||||
value, _ := rlp.EncodeToBytes(types.StateAccount{
|
||||
Nonce: i,
|
||||
Balance: big.NewInt(int64(i)),
|
||||
Root: emptyRoot,
|
||||
@ -1394,7 +1394,7 @@ func makeBoundaryAccountTrie(n int) (*trie.Trie, entrySlice) {
|
||||
}
|
||||
// Fill boundary accounts
|
||||
for i := 0; i < len(boundaries); i++ {
|
||||
value, _ := rlp.EncodeToBytes(state.Account{
|
||||
value, _ := rlp.EncodeToBytes(types.StateAccount{
|
||||
Nonce: uint64(0),
|
||||
Balance: big.NewInt(int64(i)),
|
||||
Root: emptyRoot,
|
||||
@ -1406,7 +1406,7 @@ func makeBoundaryAccountTrie(n int) (*trie.Trie, entrySlice) {
|
||||
}
|
||||
// Fill other accounts if required
|
||||
for i := uint64(1); i <= uint64(n); i++ {
|
||||
value, _ := rlp.EncodeToBytes(state.Account{
|
||||
value, _ := rlp.EncodeToBytes(types.StateAccount{
|
||||
Nonce: i,
|
||||
Balance: big.NewInt(int64(i)),
|
||||
Root: emptyRoot,
|
||||
@ -1442,7 +1442,7 @@ func makeAccountTrieWithStorageWithUniqueStorage(accounts, slots int, code bool)
|
||||
stTrie, stEntries := makeStorageTrieWithSeed(uint64(slots), i, db)
|
||||
stRoot := stTrie.Hash()
|
||||
stTrie.Commit(nil)
|
||||
value, _ := rlp.EncodeToBytes(state.Account{
|
||||
value, _ := rlp.EncodeToBytes(types.StateAccount{
|
||||
Nonce: i,
|
||||
Balance: big.NewInt(int64(i)),
|
||||
Root: stRoot,
|
||||
@ -1489,7 +1489,7 @@ func makeAccountTrieWithStorage(accounts, slots int, code, boundary bool) (*trie
|
||||
if code {
|
||||
codehash = getCodeHash(i)
|
||||
}
|
||||
value, _ := rlp.EncodeToBytes(state.Account{
|
||||
value, _ := rlp.EncodeToBytes(types.StateAccount{
|
||||
Nonce: i,
|
||||
Balance: big.NewInt(int64(i)),
|
||||
Root: stRoot,
|
||||
|
Reference in New Issue
Block a user