Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
2ff464b2
Unverified
Commit
2ff464b2
authored
Aug 19, 2020
by
Giuseppe Bertone
Committed by
GitHub
Aug 19, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core/state: fixed some comments (#21450)
parent
f3bafece
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
14 additions
and
15 deletions
+14
-15
state_object.go
core/state/state_object.go
+4
-5
statedb.go
core/state/statedb.go
+5
-5
statedb_test.go
core/state/statedb_test.go
+5
-5
No files found.
core/state/state_object.go
View file @
2ff464b2
...
...
@@ -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
)
{
// EIP1
58
: We must check emptiness for the objects such that the account
// EIP1
61
: 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 metho
s
is an almost mirror of Code, but uses a cache
// or zero if none. This metho
d
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
{
...
...
core/state/statedb.go
View file @
2ff464b2
...
...
@@ -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
struct
s 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
// Get
Storage
Proof 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
{
...
...
core/state/statedb_test.go
View file @
2ff464b2
...
...
@@ -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 follow
up 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
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment