diff --git a/core/state/state_object.go b/core/state/state_object.go index 6f00a80a0f..2c27caf3e8 100644 --- a/core/state/state_object.go +++ b/core/state/state_object.go @@ -332,22 +332,21 @@ func (s *stateObject) commitTrie(db Database) (int, error) { return committed, err } -// AddBalance removes amount from c's balance. +// AddBalance adds amount to s's balance. // It is used to add funds to the destination account of a transfer. func (s *stateObject) AddBalance(amount *big.Int) { - // EIP158: We must check emptiness for the objects such that the account + // EIP161: We must check emptiness for the objects such that the account // clearing (0,0,0 objects) can take effect. if amount.Sign() == 0 { if s.empty() { s.touch() } - return } s.SetBalance(new(big.Int).Add(s.Balance(), amount)) } -// SubBalance removes amount from c's balance. +// SubBalance removes amount from s's balance. // It is used to remove funds from the origin account of a transfer. func (s *stateObject) SubBalance(amount *big.Int) { if amount.Sign() == 0 { @@ -409,7 +408,7 @@ func (s *stateObject) Code(db Database) []byte { } // CodeSize returns the size of the contract code associated with this object, -// or zero if none. This methos is an almost mirror of Code, but uses a cache +// or zero if none. This method is an almost mirror of Code, but uses a cache // inside the database to avoid loading codes seen recently. func (s *stateObject) CodeSize(db Database) int { if s.code != nil { diff --git a/core/state/statedb.go b/core/state/statedb.go index 2d0846dcb6..f0e309f49d 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -39,7 +39,7 @@ type revision struct { journalIndex int } -// StateDBs within the ethereum protocol are used to store anything +// StateDB structs within the ethereum protocol are used to store anything // within the merkle trie. StateDBs take care of caching and storing // nested states. It's the general query interface to retrieve: // * Contracts @@ -108,7 +108,7 @@ type AccountInfo struct { StorageHash common.Hash } -// Create a new state from a given trie. +// New creates a new state from a given trie. func New(root common.Hash, db Database) (*StateDB, error) { tr, err := db.OpenTrie(root) if err != nil { @@ -234,7 +234,7 @@ func (s *StateDB) Empty(addr common.Address) bool { return so == nil || so.empty() } -// Retrieve the balance from the given address or 0 if object not found +// GetBalance retrieves the balance from the given address or 0 if object not found func (s *StateDB) GetBalance(addr common.Address) *big.Int { stateObject := s.getStateObject(addr) if stateObject != nil { @@ -553,7 +553,7 @@ func (s *StateDB) setStateObject(object *stateObject) { s.stateObjects[object.Address()] = object } -// Retrieve a state object or create a new state object if nil. +// GetOrNewStateObject retrieves a state object or create a new state object if nil. func (s *StateDB) GetOrNewStateObject(addr common.Address) *stateObject { stateObject := s.getStateObject(addr) if stateObject == nil { diff --git a/core/state/statedb_test.go b/core/state/statedb_test.go index dd47c76180..ac818a23b4 100644 --- a/core/state/statedb_test.go +++ b/core/state/statedb_test.go @@ -144,9 +144,9 @@ func TestIntermediateLeaks(t *testing.T) { } } -// TestCopy tests that copying a statedb object indeed makes the original and +// TestCopy tests that copying a StateDB object indeed makes the original and // the copy independent of each other. This test is a regression test against -// https://github.com/XinFinOrg/XDPoSChain/pull/15549. +// https://github.com/ethereum/go-ethereum/pull/15549. func TestCopy(t *testing.T) { // Create a random state test to copy and modify "independently" db := rawdb.NewMemoryDatabase() @@ -707,11 +707,11 @@ func TestStateDBTransientStorage(t *testing.T) { } // TestDeleteCreateRevert tests a weird state transition corner case that we hit -// while changing the internals of statedb. The workflow is that a contract is -// self destructed, then in a followup transaction (but same block) it's created +// while changing the internals of StateDB. The workflow is that a contract is +// self-destructed, then in a follow-up transaction (but same block) it's created // again and the transaction reverted. // -// The original statedb implementation flushed dirty objects to the tries after +// The original StateDB implementation flushed dirty objects to the tries after // each transaction, so this works ok. The rework accumulated writes in memory // first, but the journal wiped the entire state object on create-revert. func TestDeleteCreateRevert(t *testing.T) {