diff --git a/core/state/state_object.go b/core/state/state_object.go index 015a6737818a..26ab67e1adb7 100644 --- a/core/state/state_object.go +++ b/core/state/state_object.go @@ -375,22 +375,21 @@ func (s *stateObject) CommitTrie(db Database) error { return 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 { @@ -455,7 +454,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 17dd474314aa..0134a9d443c7 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -58,7 +58,7 @@ func (n *proofList) Delete(key []byte) error { panic("not supported") } -// 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 @@ -115,7 +115,7 @@ type StateDB struct { SnapshotCommits time.Duration } -// Create a new state from a given trie. +// New creates a new state from a given trie. func New(root common.Hash, db Database, snaps *snapshot.Tree) (*StateDB, error) { tr, err := db.OpenTrie(root) if err != nil { @@ -250,7 +250,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 { @@ -318,7 +318,7 @@ func (s *StateDB) GetProof(a common.Address) ([][]byte, error) { return [][]byte(proof), err } -// GetProof returns the StorageProof for given key +// GetStorageProof returns the StorageProof for given key func (s *StateDB) GetStorageProof(a common.Address, key common.Hash) ([][]byte, error) { var proof proofList trie := s.StorageTrie(a) @@ -560,7 +560,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 824a59749883..36ff27133188 100644 --- a/core/state/statedb_test.go +++ b/core/state/statedb_test.go @@ -144,7 +144,7 @@ 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/ethereum/go-ethereum/pull/15549. func TestCopy(t *testing.T) { @@ -647,11 +647,11 @@ func TestCopyCopyCommitCopy(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) { @@ -681,7 +681,7 @@ func TestDeleteCreateRevert(t *testing.T) { } } -// TestMissingTrieNodes tests that if the statedb fails to load parts of the trie, +// TestMissingTrieNodes tests that if the StateDB fails to load parts of the trie, // the Commit operation fails with an error // If we are missing trie nodes, we should not continue writing to the trie func TestMissingTrieNodes(t *testing.T) {