Skip to content

Commit

Permalink
review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
gballet committed Sep 17, 2021
1 parent 14ad53a commit 260fb94
Show file tree
Hide file tree
Showing 18 changed files with 56 additions and 50 deletions.
6 changes: 3 additions & 3 deletions cmd/geth/snapshot.go
Expand Up @@ -27,7 +27,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/state/account"
accs "github.com/ethereum/go-ethereum/core/state/accounts"
"github.com/ethereum/go-ethereum/core/state/pruner"
"github.com/ethereum/go-ethereum/core/state/snapshot"
"github.com/ethereum/go-ethereum/crypto"
Expand Down Expand Up @@ -288,7 +288,7 @@ func traverseState(ctx *cli.Context) error {
accIter := trie.NewIterator(t.NodeIterator(nil))
for accIter.Next() {
accounts += 1
var acc account.Account
var acc accs.Account
if err := rlp.DecodeBytes(accIter.Value, &acc); err != nil {
log.Error("Invalid account encountered during traversal", "err", err)
return err
Expand Down Expand Up @@ -394,7 +394,7 @@ func traverseRawState(ctx *cli.Context) error {
// dig into the storage trie further.
if accIter.Leaf() {
accounts += 1
var acc account.Account
var acc accs.Account
if err := rlp.DecodeBytes(accIter.LeafBlob(), &acc); err != nil {
log.Error("Invalid account encountered during traversal", "err", err)
return errors.New("invalid account")
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions core/state/database.go
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/VictoriaMetrics/fastcache"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/state/account"
accounts "github.com/ethereum/go-ethereum/core/state/accounts"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/trie"
lru "github.com/hashicorp/golang-lru"
Expand Down Expand Up @@ -72,7 +72,7 @@ type Trie interface {
TryGet(key []byte) ([]byte, error)

// TryUpdateAccount abstract an account write in the trie.
TryUpdateAccount(key []byte, acc account.Account) error
TryUpdateAccount(key []byte, acc *accounts.Account) error

// TryUpdate associates key with value in the trie. If value has length zero, any
// existing value is deleted from the trie. The value bytes must not be modified
Expand Down
2 changes: 1 addition & 1 deletion core/state/dump.go
Expand Up @@ -23,7 +23,7 @@ import (

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core/state/account"
"github.com/ethereum/go-ethereum/core/state/accounts"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/trie"
Expand Down
2 changes: 1 addition & 1 deletion core/state/iterator.go
Expand Up @@ -21,7 +21,7 @@ import (
"fmt"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/state/account"
"github.com/ethereum/go-ethereum/core/state/accounts"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/trie"
)
Expand Down
4 changes: 2 additions & 2 deletions core/state/pruner/pruner.go
Expand Up @@ -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/account"
accounts "github.com/ethereum/go-ethereum/core/state/accounts"
"github.com/ethereum/go-ethereum/core/state/snapshot"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
Expand Down Expand Up @@ -426,7 +426,7 @@ func extractGenesis(db ethdb.Database, stateBloom *stateBloom) error {
// If it's a leaf node, yes we are touching an account,
// dig into the storage trie further.
if accIter.Leaf() {
var acc account.Account
var acc accounts.Account
if err := rlp.DecodeBytes(accIter.LeafBlob(), &acc); err != nil {
return err
}
Expand Down
8 changes: 7 additions & 1 deletion core/state/state_object.go
Expand Up @@ -19,11 +19,12 @@ package state
import (
"bytes"
"fmt"
"io"
"math/big"
"time"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/state/account"
"github.com/ethereum/go-ethereum/core/state/accounts"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/metrics"
"github.com/ethereum/go-ethereum/rlp"
Expand Down Expand Up @@ -119,6 +120,11 @@ func newObject(db *StateDB, address common.Address, data account.Account) *state
}
}

// EncodeRLP implements rlp.Encoder.
func (s *stateObject) EncodeRLP(io.Writer) error {
panic("deprecated code, should not be called")
}

// setError remembers the first non-nil error it is called with.
func (s *stateObject) setError(err error) {
if s.dbErr == nil {
Expand Down
14 changes: 7 additions & 7 deletions core/state/statedb.go
Expand Up @@ -26,7 +26,7 @@ import (

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/state/account"
accounts "github.com/ethereum/go-ethereum/core/state/accounts"
"github.com/ethereum/go-ethereum/core/state/snapshot"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
Expand Down Expand Up @@ -461,7 +461,7 @@ func (s *StateDB) updateStateObject(obj *stateObject) {
}
// Encode the account and update the account trie
addr := obj.Address()
if err := s.trie.TryUpdateAccount(addr[:], obj.data); err != nil {
if err := s.trie.TryUpdateAccount(addr[:], &obj.data); err != nil {
//if err := s.trie.TryUpdateAccount(addr[:], obj.data); err != nil {
s.setError(fmt.Errorf("updateStateObject (%x) error: %v", addr[:], err))
}
Expand Down Expand Up @@ -509,7 +509,7 @@ func (s *StateDB) getDeletedStateObject(addr common.Address) *stateObject {
}
// If no live objects are available, attempt to use snapshots
var (
data *account.Account
data *accounts.Account
err error
)
if s.snap != nil {
Expand All @@ -521,7 +521,7 @@ func (s *StateDB) getDeletedStateObject(addr common.Address) *stateObject {
if acc == nil {
return nil
}
data = &account.Account{
data = &accounts.Account{
Nonce: acc.Nonce,
Balance: acc.Balance,
CodeHash: acc.CodeHash,
Expand All @@ -548,7 +548,7 @@ func (s *StateDB) getDeletedStateObject(addr common.Address) *stateObject {
if len(enc) == 0 {
return nil
}
data = new(account.Account)
data = new(accounts.Account)
if err := rlp.DecodeBytes(enc, data); err != nil {
log.Error("Failed to decode state object", "addr", addr, "err", err)
return nil
Expand Down Expand Up @@ -585,7 +585,7 @@ func (s *StateDB) createObject(addr common.Address) (newobj, prev *stateObject)
s.snapDestructs[prev.addrHash] = struct{}{}
}
}
newobj = newObject(s, addr, account.Account{})
newobj = newObject(s, addr, accounts.Account{})
if prev == nil {
s.journal.append(createObjectChange{account: &addr})
} else {
Expand Down Expand Up @@ -939,7 +939,7 @@ func (s *StateDB) Commit(deleteEmptyObjects bool) (common.Hash, error) {
}
// The onleaf func is called _serially_, so we can reuse the same account
// for unmarshalling every time.
var account account.Account
var account accounts.Account
root, accountCommitted, err := s.trie.Commit(func(_ [][]byte, _ []byte, leaf []byte, parent common.Hash) error {
if err := rlp.DecodeBytes(leaf, &account); err != nil {
return nil
Expand Down
4 changes: 2 additions & 2 deletions core/state/sync.go
Expand Up @@ -20,7 +20,7 @@ import (
"bytes"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/state/account"
accounts "github.com/ethereum/go-ethereum/core/state/accounts"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/trie"
Expand All @@ -44,7 +44,7 @@ func NewStateSync(root common.Hash, database ethdb.KeyValueReader, bloom *trie.S
return err
}
}
var obj account.Account
var obj accounts.Account
if err := rlp.Decode(bytes.NewReader(leaf), &obj); err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions core/state/sync_test.go
Expand Up @@ -23,7 +23,7 @@ import (

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/state/account"
accs "github.com/ethereum/go-ethereum/core/state/accounts"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/ethdb/memorydb"
Expand Down Expand Up @@ -204,7 +204,7 @@ func testIterativeStateSync(t *testing.T, count int, commit bool, bypath bool) {
}
results[len(hashQueue)+i] = trie.SyncResult{Hash: crypto.Keccak256Hash(data), Data: data}
} else {
var acc account.Account
var acc accs.Account
if err := rlp.DecodeBytes(srcTrie.Get(path[0]), &acc); err != nil {
t.Fatalf("failed to decode account on path %x: %v", path, err)
}
Expand Down
4 changes: 2 additions & 2 deletions eth/protocols/snap/handler.go
Expand Up @@ -23,7 +23,7 @@ import (

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
accounT "github.com/ethereum/go-ethereum/core/state/account"
accounts "github.com/ethereum/go-ethereum/core/state/accounts"
"github.com/ethereum/go-ethereum/light"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/metrics"
Expand Down Expand Up @@ -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 accounT.Account
var acc accounts.Account
if err := rlp.DecodeBytes(accTrie.Get(account[:]), &acc); err != nil {
return p2p.Send(peer.rw, StorageRangesMsg, &StorageRangesPacket{ID: req.ID})
}
Expand Down
12 changes: 6 additions & 6 deletions eth/protocols/snap/sync.go
Expand Up @@ -31,7 +31,7 @@ import (
"github.com/ethereum/go-ethereum/common/math"
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/state"
accounT "github.com/ethereum/go-ethereum/core/state/account"
acts "github.com/ethereum/go-ethereum/core/state/accounts"
"github.com/ethereum/go-ethereum/core/state/snapshot"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethdb"
Expand Down Expand Up @@ -126,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 []*accounT.Account // Expanded accounts in the returned range
hashes []common.Hash // Account hashes in the returned range
accounts []*acts.Account // Expanded accounts in the returned range

cont bool // Whether the account range has a continuation
}
Expand Down Expand Up @@ -2275,9 +2275,9 @@ func (s *Syncer) OnAccounts(peer SyncPeer, id uint64, hashes []common.Hash, acco
s.scheduleRevertAccountRequest(req)
return err
}
accs := make([]*accounT.Account, len(accounts))
accs := make([]*acts.Account, len(accounts))
for i, account := range accounts {
acc := new(accounT.Account)
acc := new(acts.Account)
if err := rlp.DecodeBytes(account, acc); err != nil {
panic(err) // We created these blobs, we must be able to decode them
}
Expand Down Expand Up @@ -2741,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 accounT.Account
var account acts.Account
if err := rlp.DecodeBytes(value, &account); err != nil {
return nil
}
Expand Down
12 changes: 6 additions & 6 deletions eth/protocols/snap/sync_test.go
Expand Up @@ -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/account"
acts "github.com/ethereum/go-ethereum/core/state/accounts"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/light"
Expand Down Expand Up @@ -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(account.Account{
value, _ := rlp.EncodeToBytes(acts.Account{
Nonce: i,
Balance: big.NewInt(int64(i)),
Root: emptyRoot,
Expand Down Expand Up @@ -1394,7 +1394,7 @@ func makeBoundaryAccountTrie(n int) (*trie.Trie, entrySlice) {
}
// Fill boundary accounts
for i := 0; i < len(boundaries); i++ {
value, _ := rlp.EncodeToBytes(account.Account{
value, _ := rlp.EncodeToBytes(acts.Account{
Nonce: uint64(0),
Balance: big.NewInt(int64(i)),
Root: emptyRoot,
Expand All @@ -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(account.Account{
value, _ := rlp.EncodeToBytes(acts.Account{
Nonce: i,
Balance: big.NewInt(int64(i)),
Root: emptyRoot,
Expand Down Expand Up @@ -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(account.Account{
value, _ := rlp.EncodeToBytes(acts.Account{
Nonce: i,
Balance: big.NewInt(int64(i)),
Root: stRoot,
Expand Down Expand Up @@ -1489,7 +1489,7 @@ func makeAccountTrieWithStorage(accounts, slots int, code, boundary bool) (*trie
if code {
codehash = getCodeHash(i)
}
value, _ := rlp.EncodeToBytes(account.Account{
value, _ := rlp.EncodeToBytes(acts.Account{
Nonce: i,
Balance: big.NewInt(int64(i)),
Root: stRoot,
Expand Down
12 changes: 6 additions & 6 deletions les/server_handler.go
Expand Up @@ -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/account"
accounts "github.com/ethereum/go-ethereum/core/state/accounts"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/les/flowcontrol"
"github.com/ethereum/go-ethereum/light"
Expand Down Expand Up @@ -358,18 +358,18 @@ func (h *serverHandler) AddTxsSync() bool {
}

// getAccount retrieves an account from the state based on root.
func getAccount(triedb *trie.Database, root, hash common.Hash) (account.Account, error) {
func getAccount(triedb *trie.Database, root, hash common.Hash) (accounts.Account, error) {
trie, err := trie.New(root, triedb)
if err != nil {
return account.Account{}, err
return accounts.Account{}, err
}
blob, err := trie.TryGet(hash[:])
if err != nil {
return account.Account{}, err
return accounts.Account{}, err
}
var acc account.Account
var acc accounts.Account
if err = rlp.DecodeBytes(blob, &acc); err != nil {
return account.Account{}, err
return accounts.Account{}, err
}
return acc, nil
}
Expand Down
4 changes: 2 additions & 2 deletions light/trie.go
Expand Up @@ -24,7 +24,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/state/account"
accounts "github.com/ethereum/go-ethereum/core/state/accounts"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethdb"
Expand Down Expand Up @@ -113,7 +113,7 @@ func (t *odrTrie) TryGet(key []byte) ([]byte, error) {
return res, err
}

func (t *odrTrie) TryUpdateAccount(key []byte, acc account.Account) error {
func (t *odrTrie) TryUpdateAccount(key []byte, acc *accounts.Account) error {
key = crypto.Keccak256(key)
value, err := rlp.EncodeToBytes(acc)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions trie/secure_trie.go
Expand Up @@ -20,7 +20,7 @@ import (
"fmt"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/state/account"
accounts "github.com/ethereum/go-ethereum/core/state/accounts"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/rlp"
)
Expand Down Expand Up @@ -89,7 +89,7 @@ func (t *SecureTrie) TryGetNode(path []byte) ([]byte, int, error) {

// TryUpdate account will abstract the write of an account to the
// secure trie.
func (t *SecureTrie) TryUpdateAccount(key []byte, acc account.Account) error {
func (t *SecureTrie) TryUpdateAccount(key []byte, acc *accounts.Account) error {
hk := t.hashKey(key)
data, err := rlp.EncodeToBytes(acc)
if err != nil {
Expand Down

0 comments on commit 260fb94

Please sign in to comment.