Rename stateObject to Object (#256)

Was not renamed to StateObject because that would cause the
package-qualified name to be state.StateObject, triggering another “name
stutter” warning.

More commits to come to fix a new salvo of warnings that stems from this
private-to-public flip.
pull/263/head
Eugene Kim 6 years ago
parent 0ec8fa1548
commit b32dcd9444
  1. 2
      core/state/journal.go
  2. 4
      core/state/managed_state.go
  3. 70
      core/state/state_object.go
  4. 2
      core/state/state_test.go
  5. 20
      core/state/statedb.go

@ -90,7 +90,7 @@ type (
account *common.Address
}
resetObjectChange struct {
prev *stateObject
prev *Object
}
suicideChange struct {
account *common.Address

@ -23,7 +23,7 @@ import (
)
type account struct {
stateObject *stateObject
stateObject *Object
nstart uint64
nonces []bool
}
@ -138,6 +138,6 @@ func (ms *ManagedState) getAccount(addr common.Address) *account {
return ms.accounts[addr]
}
func newAccount(so *stateObject) *account {
func newAccount(so *Object) *account {
return &account{so, so.Nonce(), nil}
}

@ -56,13 +56,13 @@ func (storage Storage) Copy() Storage {
return cpy
}
// stateObject represents an Ethereum account which is being modified.
// Object represents an Ethereum account which is being modified.
//
// The usage pattern is as follows:
// First you need to obtain a state object.
// Account values can be accessed and modified through the object.
// Finally, call CommitTrie to write the modified storage trie into a database.
type stateObject struct {
type Object struct {
address common.Address
addrHash common.Hash // hash of ethereum address of the account
data Account
@ -91,7 +91,7 @@ type stateObject struct {
}
// empty returns whether the account is considered empty.
func (s *stateObject) empty() bool {
func (s *Object) empty() bool {
return s.data.Nonce == 0 && s.data.Balance.Sign() == 0 && bytes.Equal(s.data.CodeHash, emptyCodeHash)
}
@ -105,14 +105,14 @@ type Account struct {
}
// newObject creates a state object.
func newObject(db *DB, address common.Address, data Account) *stateObject {
func newObject(db *DB, address common.Address, data Account) *Object {
if data.Balance == nil {
data.Balance = new(big.Int)
}
if data.CodeHash == nil {
data.CodeHash = emptyCodeHash
}
return &stateObject{
return &Object{
db: db,
address: address,
addrHash: crypto.Keccak256Hash(address[:]),
@ -123,22 +123,22 @@ func newObject(db *DB, address common.Address, data Account) *stateObject {
}
// EncodeRLP implements rlp.Encoder.
func (s *stateObject) EncodeRLP(w io.Writer) error {
func (s *Object) EncodeRLP(w io.Writer) error {
return rlp.Encode(w, s.data)
}
// setError remembers the first non-nil error it is called with.
func (s *stateObject) setError(err error) {
func (s *Object) setError(err error) {
if s.dbErr == nil {
s.dbErr = err
}
}
func (s *stateObject) markSuicided() {
func (s *Object) markSuicided() {
s.suicided = true
}
func (s *stateObject) touch() {
func (s *Object) touch() {
s.db.journal.append(touchChange{
account: &s.address,
})
@ -149,7 +149,7 @@ func (s *stateObject) touch() {
}
}
func (s *stateObject) getTrie(db Database) Trie {
func (s *Object) getTrie(db Database) Trie {
if s.trie == nil {
var err error
s.trie, err = db.OpenStorageTrie(s.addrHash, s.data.Root)
@ -162,7 +162,7 @@ func (s *stateObject) getTrie(db Database) Trie {
}
// GetState retrieves a value from the account storage trie.
func (s *stateObject) GetState(db Database, key common.Hash) common.Hash {
func (s *Object) GetState(db Database, key common.Hash) common.Hash {
// If we have a dirty value for this state entry, return it
value, dirty := s.dirtyStorage[key]
if dirty {
@ -173,7 +173,7 @@ func (s *stateObject) GetState(db Database, key common.Hash) common.Hash {
}
// GetCommittedState retrieves a value from the committed account storage trie.
func (s *stateObject) GetCommittedState(db Database, key common.Hash) common.Hash {
func (s *Object) GetCommittedState(db Database, key common.Hash) common.Hash {
// If we have the original value cached, return that
value, cached := s.originStorage[key]
if cached {
@ -197,7 +197,7 @@ func (s *stateObject) GetCommittedState(db Database, key common.Hash) common.Has
}
// SetState updates a value in account storage.
func (s *stateObject) SetState(db Database, key, value common.Hash) {
func (s *Object) SetState(db Database, key, value common.Hash) {
// If the new value is the same as old, don't set
prev := s.GetState(db, key)
if prev == value {
@ -212,12 +212,12 @@ func (s *stateObject) SetState(db Database, key, value common.Hash) {
s.setState(key, value)
}
func (s *stateObject) setState(key, value common.Hash) {
func (s *Object) setState(key, value common.Hash) {
s.dirtyStorage[key] = value
}
// updateTrie writes cached storage modifications into the object's storage trie.
func (s *stateObject) updateTrie(db Database) Trie {
func (s *Object) updateTrie(db Database) Trie {
tr := s.getTrie(db)
for key, value := range s.dirtyStorage {
delete(s.dirtyStorage, key)
@ -240,14 +240,14 @@ func (s *stateObject) updateTrie(db Database) Trie {
}
// UpdateRoot sets the trie root to the current root hash of
func (s *stateObject) updateRoot(db Database) {
func (s *Object) updateRoot(db Database) {
s.updateTrie(db)
s.data.Root = s.trie.Hash()
}
// CommitTrie the storage trie of the object to db.
// This updates the trie root.
func (s *stateObject) CommitTrie(db Database) error {
func (s *Object) CommitTrie(db Database) error {
s.updateTrie(db)
if s.dbErr != nil {
return s.dbErr
@ -261,7 +261,7 @@ func (s *stateObject) CommitTrie(db Database) error {
// AddBalance removes amount from c's balance.
// It is used to add funds to the destination account of a transfer.
func (s *stateObject) AddBalance(amount *big.Int) {
func (s *Object) AddBalance(amount *big.Int) {
// EIP158: We must check emptiness for the objects such that the account
// clearing (0,0,0 objects) can take effect.
if amount.Sign() == 0 {
@ -276,14 +276,14 @@ func (s *stateObject) AddBalance(amount *big.Int) {
// SubBalance removes amount from c's balance.
// It is used to remove funds from the origin account of a transfer.
func (s *stateObject) SubBalance(amount *big.Int) {
func (s *Object) SubBalance(amount *big.Int) {
if amount.Sign() == 0 {
return
}
s.SetBalance(new(big.Int).Sub(s.Balance(), amount))
}
func (s *stateObject) SetBalance(amount *big.Int) {
func (s *Object) SetBalance(amount *big.Int) {
s.db.journal.append(balanceChange{
account: &s.address,
prev: new(big.Int).Set(s.data.Balance),
@ -291,14 +291,14 @@ func (s *stateObject) SetBalance(amount *big.Int) {
s.setBalance(amount)
}
func (s *stateObject) setBalance(amount *big.Int) {
func (s *Object) setBalance(amount *big.Int) {
s.data.Balance = amount
}
// Return the gas back to the origin. Used by the Virtual machine or Closures
func (s *stateObject) ReturnGas(gas *big.Int) {}
func (s *Object) ReturnGas(gas *big.Int) {}
func (s *stateObject) deepCopy(db *DB) *stateObject {
func (s *Object) deepCopy(db *DB) *Object {
stateObject := newObject(db, s.address, s.data)
if s.trie != nil {
stateObject.trie = db.db.CopyTrie(s.trie)
@ -317,12 +317,12 @@ func (s *stateObject) deepCopy(db *DB) *stateObject {
//
// Returns the address of the contract/account
func (s *stateObject) Address() common.Address {
func (s *Object) Address() common.Address {
return s.address
}
// Code returns the contract code associated with this object, if any.
func (s *stateObject) Code(db Database) []byte {
func (s *Object) Code(db Database) []byte {
if s.code != nil {
return s.code
}
@ -337,7 +337,7 @@ func (s *stateObject) Code(db Database) []byte {
return code
}
func (s *stateObject) SetCode(codeHash common.Hash, code []byte) {
func (s *Object) SetCode(codeHash common.Hash, code []byte) {
prevcode := s.Code(s.db.db)
s.db.journal.append(codeChange{
account: &s.address,
@ -347,13 +347,13 @@ func (s *stateObject) SetCode(codeHash common.Hash, code []byte) {
s.setCode(codeHash, code)
}
func (s *stateObject) setCode(codeHash common.Hash, code []byte) {
func (s *Object) setCode(codeHash common.Hash, code []byte) {
s.code = code
s.data.CodeHash = codeHash[:]
s.dirtyCode = true
}
func (s *stateObject) SetNonce(nonce uint64) {
func (s *Object) SetNonce(nonce uint64) {
s.db.journal.append(nonceChange{
account: &s.address,
prev: s.data.Nonce,
@ -361,25 +361,25 @@ func (s *stateObject) SetNonce(nonce uint64) {
s.setNonce(nonce)
}
func (s *stateObject) setNonce(nonce uint64) {
func (s *Object) setNonce(nonce uint64) {
s.data.Nonce = nonce
}
func (s *stateObject) CodeHash() []byte {
func (s *Object) CodeHash() []byte {
return s.data.CodeHash
}
func (s *stateObject) Balance() *big.Int {
func (s *Object) Balance() *big.Int {
return s.data.Balance
}
func (s *stateObject) Nonce() uint64 {
func (s *Object) Nonce() uint64 {
return s.data.Nonce
}
// Never called, but must be present to allow stateObject to be used
// Never called, but must be present to allow Object to be used
// as a vm.Account interface that also satisfies the vm.ContractRef
// interface. Interfaces are awesome.
func (s *stateObject) Value() *big.Int {
panic("Value on stateObject should never be called")
func (s *Object) Value() *big.Int {
panic("Value on Object should never be called")
}

@ -196,7 +196,7 @@ func TestSnapshot2(t *testing.T) {
}
}
func compareStateObjects(so0, so1 *stateObject, t *testing.T) {
func compareStateObjects(so0, so1 *Object, t *testing.T) {
if so0.Address() != so1.Address() {
t.Fatalf("Address mismatch: have %v, want %v", so0.address, so1.address)
}

@ -62,7 +62,7 @@ type DB struct {
trie Trie
// This map holds 'live' objects, which will get modified while processing a state transition.
stateObjects map[common.Address]*stateObject
stateObjects map[common.Address]*Object
stateObjectsDirty map[common.Address]struct{}
// DB error.
@ -100,7 +100,7 @@ func New(root common.Hash, db Database) (*DB, error) {
return &DB{
db: db,
trie: tr,
stateObjects: make(map[common.Address]*stateObject),
stateObjects: make(map[common.Address]*Object),
stateObjectsDirty: make(map[common.Address]struct{}),
logs: make(map[common.Hash][]*types.Log),
preimages: make(map[common.Hash][]byte),
@ -127,7 +127,7 @@ func (stateDB *DB) Reset(root common.Hash) error {
return err
}
stateDB.trie = tr
stateDB.stateObjects = make(map[common.Address]*stateObject)
stateDB.stateObjects = make(map[common.Address]*Object)
stateDB.stateObjectsDirty = make(map[common.Address]struct{})
stateDB.thash = common.Hash{}
stateDB.bhash = common.Hash{}
@ -401,7 +401,7 @@ func (stateDB *DB) Suicide(addr common.Address) bool {
//
// updateStateObject writes the given object to the trie.
func (stateDB *DB) updateStateObject(stateObject *stateObject) {
func (stateDB *DB) updateStateObject(stateObject *Object) {
addr := stateObject.Address()
data, err := rlp.EncodeToBytes(stateObject)
if err != nil {
@ -411,14 +411,14 @@ func (stateDB *DB) updateStateObject(stateObject *stateObject) {
}
// deleteStateObject removes the given object from the state trie.
func (stateDB *DB) deleteStateObject(stateObject *stateObject) {
func (stateDB *DB) deleteStateObject(stateObject *Object) {
stateObject.deleted = true
addr := stateObject.Address()
stateDB.setError(stateDB.trie.TryDelete(addr[:]))
}
// Retrieve a state object given by the address. Returns nil if not found.
func (stateDB *DB) getStateObject(addr common.Address) (stateObject *stateObject) {
func (stateDB *DB) getStateObject(addr common.Address) (stateObject *Object) {
// Prefer 'live' objects.
if obj := stateDB.stateObjects[addr]; obj != nil {
if obj.deleted {
@ -444,12 +444,12 @@ func (stateDB *DB) getStateObject(addr common.Address) (stateObject *stateObject
return obj
}
func (stateDB *DB) setStateObject(object *stateObject) {
func (stateDB *DB) setStateObject(object *Object) {
stateDB.stateObjects[object.Address()] = object
}
// GetOrNewStateObject retrieves a state object or create a new state object if nil.
func (stateDB *DB) GetOrNewStateObject(addr common.Address) *stateObject {
func (stateDB *DB) GetOrNewStateObject(addr common.Address) *Object {
stateObject := stateDB.getStateObject(addr)
if stateObject == nil || stateObject.deleted {
stateObject, _ = stateDB.createObject(addr)
@ -459,7 +459,7 @@ func (stateDB *DB) GetOrNewStateObject(addr common.Address) *stateObject {
// createObject creates a new state object. If there is an existing account with
// the given address, it is overwritten and returned as the second return value.
func (stateDB *DB) createObject(addr common.Address) (newobj, prev *stateObject) {
func (stateDB *DB) createObject(addr common.Address) (newobj, prev *Object) {
prev = stateDB.getStateObject(addr)
newobj = newObject(stateDB, addr, Account{})
newobj.setNonce(0) // sets the object to dirty
@ -516,7 +516,7 @@ func (stateDB *DB) Copy() *DB {
state := &DB{
db: stateDB.db,
trie: stateDB.db.CopyTrie(stateDB.trie),
stateObjects: make(map[common.Address]*stateObject, len(stateDB.journal.dirties)),
stateObjects: make(map[common.Address]*Object, len(stateDB.journal.dirties)),
stateObjectsDirty: make(map[common.Address]struct{}, len(stateDB.journal.dirties)),
refund: stateDB.refund,
logs: make(map[common.Hash][]*types.Log, len(stateDB.logs)),

Loading…
Cancel
Save