Skip to content

Commit

Permalink
Fixed some comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Neurone committed Aug 15, 2020
1 parent 54add42 commit a60ed5e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
9 changes: 4 additions & 5 deletions core/state/state_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
10 changes: 5 additions & 5 deletions core/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
10 changes: 5 additions & 5 deletions core/state/statedb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit a60ed5e

Please sign in to comment.