Skip to content

Commit 2ff464b

Browse files
authored
core/state: fixed some comments (#21450)
1 parent f3bafec commit 2ff464b

File tree

3 files changed

+14
-15
lines changed

3 files changed

+14
-15
lines changed

core/state/state_object.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -375,22 +375,21 @@ func (s *stateObject) CommitTrie(db Database) error {
375375
return err
376376
}
377377

378-
// AddBalance removes amount from c's balance.
378+
// AddBalance adds amount to s's balance.
379379
// It is used to add funds to the destination account of a transfer.
380380
func (s *stateObject) AddBalance(amount *big.Int) {
381-
// EIP158: We must check emptiness for the objects such that the account
381+
// EIP161: We must check emptiness for the objects such that the account
382382
// clearing (0,0,0 objects) can take effect.
383383
if amount.Sign() == 0 {
384384
if s.empty() {
385385
s.touch()
386386
}
387-
388387
return
389388
}
390389
s.SetBalance(new(big.Int).Add(s.Balance(), amount))
391390
}
392391

393-
// SubBalance removes amount from c's balance.
392+
// SubBalance removes amount from s's balance.
394393
// It is used to remove funds from the origin account of a transfer.
395394
func (s *stateObject) SubBalance(amount *big.Int) {
396395
if amount.Sign() == 0 {
@@ -455,7 +454,7 @@ func (s *stateObject) Code(db Database) []byte {
455454
}
456455

457456
// CodeSize returns the size of the contract code associated with this object,
458-
// or zero if none. This methos is an almost mirror of Code, but uses a cache
457+
// or zero if none. This method is an almost mirror of Code, but uses a cache
459458
// inside the database to avoid loading codes seen recently.
460459
func (s *stateObject) CodeSize(db Database) int {
461460
if s.code != nil {

core/state/statedb.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func (n *proofList) Delete(key []byte) error {
5858
panic("not supported")
5959
}
6060

61-
// StateDBs within the ethereum protocol are used to store anything
61+
// StateDB structs within the ethereum protocol are used to store anything
6262
// within the merkle trie. StateDBs take care of caching and storing
6363
// nested states. It's the general query interface to retrieve:
6464
// * Contracts
@@ -115,7 +115,7 @@ type StateDB struct {
115115
SnapshotCommits time.Duration
116116
}
117117

118-
// Create a new state from a given trie.
118+
// New creates a new state from a given trie.
119119
func New(root common.Hash, db Database, snaps *snapshot.Tree) (*StateDB, error) {
120120
tr, err := db.OpenTrie(root)
121121
if err != nil {
@@ -250,7 +250,7 @@ func (s *StateDB) Empty(addr common.Address) bool {
250250
return so == nil || so.empty()
251251
}
252252

253-
// Retrieve the balance from the given address or 0 if object not found
253+
// GetBalance retrieves the balance from the given address or 0 if object not found
254254
func (s *StateDB) GetBalance(addr common.Address) *big.Int {
255255
stateObject := s.getStateObject(addr)
256256
if stateObject != nil {
@@ -318,7 +318,7 @@ func (s *StateDB) GetProof(a common.Address) ([][]byte, error) {
318318
return [][]byte(proof), err
319319
}
320320

321-
// GetProof returns the StorageProof for given key
321+
// GetStorageProof returns the StorageProof for given key
322322
func (s *StateDB) GetStorageProof(a common.Address, key common.Hash) ([][]byte, error) {
323323
var proof proofList
324324
trie := s.StorageTrie(a)
@@ -560,7 +560,7 @@ func (s *StateDB) setStateObject(object *stateObject) {
560560
s.stateObjects[object.Address()] = object
561561
}
562562

563-
// Retrieve a state object or create a new state object if nil.
563+
// GetOrNewStateObject retrieves a state object or create a new state object if nil.
564564
func (s *StateDB) GetOrNewStateObject(addr common.Address) *stateObject {
565565
stateObject := s.getStateObject(addr)
566566
if stateObject == nil {

core/state/statedb_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ func TestIntermediateLeaks(t *testing.T) {
144144
}
145145
}
146146

147-
// TestCopy tests that copying a statedb object indeed makes the original and
147+
// TestCopy tests that copying a StateDB object indeed makes the original and
148148
// the copy independent of each other. This test is a regression test against
149149
// https://github.com/ethereum/go-ethereum/pull/15549.
150150
func TestCopy(t *testing.T) {
@@ -647,11 +647,11 @@ func TestCopyCopyCommitCopy(t *testing.T) {
647647
}
648648

649649
// TestDeleteCreateRevert tests a weird state transition corner case that we hit
650-
// while changing the internals of statedb. The workflow is that a contract is
651-
// self destructed, then in a followup transaction (but same block) it's created
650+
// while changing the internals of StateDB. The workflow is that a contract is
651+
// self-destructed, then in a follow-up transaction (but same block) it's created
652652
// again and the transaction reverted.
653653
//
654-
// The original statedb implementation flushed dirty objects to the tries after
654+
// The original StateDB implementation flushed dirty objects to the tries after
655655
// each transaction, so this works ok. The rework accumulated writes in memory
656656
// first, but the journal wiped the entire state object on create-revert.
657657
func TestDeleteCreateRevert(t *testing.T) {
@@ -681,7 +681,7 @@ func TestDeleteCreateRevert(t *testing.T) {
681681
}
682682
}
683683

684-
// TestMissingTrieNodes tests that if the statedb fails to load parts of the trie,
684+
// TestMissingTrieNodes tests that if the StateDB fails to load parts of the trie,
685685
// the Commit operation fails with an error
686686
// If we are missing trie nodes, we should not continue writing to the trie
687687
func TestMissingTrieNodes(t *testing.T) {

0 commit comments

Comments
 (0)