good morning!!!!
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
bor
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
github
maticnetwork
bor
Commits
4b622b27
Commit
4b622b27
authored
5 years ago
by
Mohanson
Committed by
Péter Szilágyi
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
core/state: unified function receiver names (#19615)
parent
2cd6059e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
core/state/state_object.go
+118
-118
118 additions, 118 deletions
core/state/state_object.go
with
118 additions
and
118 deletions
core/state/state_object.go
+
118
−
118
View file @
4b622b27
...
...
@@ -33,23 +33,23 @@ var emptyCodeHash = crypto.Keccak256(nil)
type
Code
[]
byte
func
(
self
Code
)
String
()
string
{
return
string
(
self
)
//strings.Join(Disassemble(
self
), " ")
func
(
c
Code
)
String
()
string
{
return
string
(
c
)
//strings.Join(Disassemble(
c
), " ")
}
type
Storage
map
[
common
.
Hash
]
common
.
Hash
func
(
s
elf
Storage
)
String
()
(
str
string
)
{
for
key
,
value
:=
range
s
elf
{
func
(
s
Storage
)
String
()
(
str
string
)
{
for
key
,
value
:=
range
s
{
str
+=
fmt
.
Sprintf
(
"%X : %X
\n
"
,
key
,
value
)
}
return
}
func
(
s
elf
Storage
)
Copy
()
Storage
{
func
(
s
Storage
)
Copy
()
Storage
{
cpy
:=
make
(
Storage
)
for
key
,
value
:=
range
s
elf
{
for
key
,
value
:=
range
s
{
cpy
[
key
]
=
value
}
...
...
@@ -123,210 +123,210 @@ func newObject(db *StateDB, address common.Address, data Account) *stateObject {
}
// EncodeRLP implements rlp.Encoder.
func
(
c
*
stateObject
)
EncodeRLP
(
w
io
.
Writer
)
error
{
return
rlp
.
Encode
(
w
,
c
.
data
)
func
(
s
*
stateObject
)
EncodeRLP
(
w
io
.
Writer
)
error
{
return
rlp
.
Encode
(
w
,
s
.
data
)
}
// setError remembers the first non-nil error it is called with.
func
(
s
elf
*
stateObject
)
setError
(
err
error
)
{
if
s
elf
.
dbErr
==
nil
{
s
elf
.
dbErr
=
err
func
(
s
*
stateObject
)
setError
(
err
error
)
{
if
s
.
dbErr
==
nil
{
s
.
dbErr
=
err
}
}
func
(
s
elf
*
stateObject
)
markSuicided
()
{
s
elf
.
suicided
=
true
func
(
s
*
stateObject
)
markSuicided
()
{
s
.
suicided
=
true
}
func
(
c
*
stateObject
)
touch
()
{
c
.
db
.
journal
.
append
(
touchChange
{
account
:
&
c
.
address
,
func
(
s
*
stateObject
)
touch
()
{
s
.
db
.
journal
.
append
(
touchChange
{
account
:
&
s
.
address
,
})
if
c
.
address
==
ripemd
{
if
s
.
address
==
ripemd
{
// Explicitly put it in the dirty-cache, which is otherwise generated from
// flattened journals.
c
.
db
.
journal
.
dirty
(
c
.
address
)
s
.
db
.
journal
.
dirty
(
s
.
address
)
}
}
func
(
c
*
stateObject
)
getTrie
(
db
Database
)
Trie
{
if
c
.
trie
==
nil
{
func
(
s
*
stateObject
)
getTrie
(
db
Database
)
Trie
{
if
s
.
trie
==
nil
{
var
err
error
c
.
trie
,
err
=
db
.
OpenStorageTrie
(
c
.
addrHash
,
c
.
data
.
Root
)
s
.
trie
,
err
=
db
.
OpenStorageTrie
(
s
.
addrHash
,
s
.
data
.
Root
)
if
err
!=
nil
{
c
.
trie
,
_
=
db
.
OpenStorageTrie
(
c
.
addrHash
,
common
.
Hash
{})
c
.
setError
(
fmt
.
Errorf
(
"can't create storage trie: %v"
,
err
))
s
.
trie
,
_
=
db
.
OpenStorageTrie
(
s
.
addrHash
,
common
.
Hash
{})
s
.
setError
(
fmt
.
Errorf
(
"can't create storage trie: %v"
,
err
))
}
}
return
c
.
trie
return
s
.
trie
}
// GetState retrieves a value from the account storage trie.
func
(
s
elf
*
stateObject
)
GetState
(
db
Database
,
key
common
.
Hash
)
common
.
Hash
{
func
(
s
*
stateObject
)
GetState
(
db
Database
,
key
common
.
Hash
)
common
.
Hash
{
// If we have a dirty value for this state entry, return it
value
,
dirty
:=
s
elf
.
dirtyStorage
[
key
]
value
,
dirty
:=
s
.
dirtyStorage
[
key
]
if
dirty
{
return
value
}
// Otherwise return the entry's original value
return
s
elf
.
GetCommittedState
(
db
,
key
)
return
s
.
GetCommittedState
(
db
,
key
)
}
// GetCommittedState retrieves a value from the committed account storage trie.
func
(
s
elf
*
stateObject
)
GetCommittedState
(
db
Database
,
key
common
.
Hash
)
common
.
Hash
{
func
(
s
*
stateObject
)
GetCommittedState
(
db
Database
,
key
common
.
Hash
)
common
.
Hash
{
// If we have the original value cached, return that
value
,
cached
:=
s
elf
.
originStorage
[
key
]
value
,
cached
:=
s
.
originStorage
[
key
]
if
cached
{
return
value
}
// Track the amount of time wasted on reading the storge trie
if
metrics
.
EnabledExpensive
{
defer
func
(
start
time
.
Time
)
{
s
elf
.
db
.
StorageReads
+=
time
.
Since
(
start
)
}(
time
.
Now
())
defer
func
(
start
time
.
Time
)
{
s
.
db
.
StorageReads
+=
time
.
Since
(
start
)
}(
time
.
Now
())
}
// Otherwise load the value from the database
enc
,
err
:=
s
elf
.
getTrie
(
db
)
.
TryGet
(
key
[
:
])
enc
,
err
:=
s
.
getTrie
(
db
)
.
TryGet
(
key
[
:
])
if
err
!=
nil
{
s
elf
.
setError
(
err
)
s
.
setError
(
err
)
return
common
.
Hash
{}
}
if
len
(
enc
)
>
0
{
_
,
content
,
_
,
err
:=
rlp
.
Split
(
enc
)
if
err
!=
nil
{
s
elf
.
setError
(
err
)
s
.
setError
(
err
)
}
value
.
SetBytes
(
content
)
}
s
elf
.
originStorage
[
key
]
=
value
s
.
originStorage
[
key
]
=
value
return
value
}
// SetState updates a value in account storage.
func
(
s
elf
*
stateObject
)
SetState
(
db
Database
,
key
,
value
common
.
Hash
)
{
func
(
s
*
stateObject
)
SetState
(
db
Database
,
key
,
value
common
.
Hash
)
{
// If the new value is the same as old, don't set
prev
:=
s
elf
.
GetState
(
db
,
key
)
prev
:=
s
.
GetState
(
db
,
key
)
if
prev
==
value
{
return
}
// New value is different, update and journal the change
s
elf
.
db
.
journal
.
append
(
storageChange
{
account
:
&
s
elf
.
address
,
s
.
db
.
journal
.
append
(
storageChange
{
account
:
&
s
.
address
,
key
:
key
,
prevalue
:
prev
,
})
s
elf
.
setState
(
key
,
value
)
s
.
setState
(
key
,
value
)
}
func
(
s
elf
*
stateObject
)
setState
(
key
,
value
common
.
Hash
)
{
s
elf
.
dirtyStorage
[
key
]
=
value
func
(
s
*
stateObject
)
setState
(
key
,
value
common
.
Hash
)
{
s
.
dirtyStorage
[
key
]
=
value
}
// updateTrie writes cached storage modifications into the object's storage trie.
func
(
s
elf
*
stateObject
)
updateTrie
(
db
Database
)
Trie
{
func
(
s
*
stateObject
)
updateTrie
(
db
Database
)
Trie
{
// Track the amount of time wasted on updating the storge trie
if
metrics
.
EnabledExpensive
{
defer
func
(
start
time
.
Time
)
{
s
elf
.
db
.
StorageUpdates
+=
time
.
Since
(
start
)
}(
time
.
Now
())
defer
func
(
start
time
.
Time
)
{
s
.
db
.
StorageUpdates
+=
time
.
Since
(
start
)
}(
time
.
Now
())
}
// Update all the dirty slots in the trie
tr
:=
s
elf
.
getTrie
(
db
)
for
key
,
value
:=
range
s
elf
.
dirtyStorage
{
delete
(
s
elf
.
dirtyStorage
,
key
)
tr
:=
s
.
getTrie
(
db
)
for
key
,
value
:=
range
s
.
dirtyStorage
{
delete
(
s
.
dirtyStorage
,
key
)
// Skip noop changes, persist actual changes
if
value
==
s
elf
.
originStorage
[
key
]
{
if
value
==
s
.
originStorage
[
key
]
{
continue
}
s
elf
.
originStorage
[
key
]
=
value
s
.
originStorage
[
key
]
=
value
if
(
value
==
common
.
Hash
{})
{
s
elf
.
setError
(
tr
.
TryDelete
(
key
[
:
]))
s
.
setError
(
tr
.
TryDelete
(
key
[
:
]))
continue
}
// Encoding []byte cannot fail, ok to ignore the error.
v
,
_
:=
rlp
.
EncodeToBytes
(
bytes
.
TrimLeft
(
value
[
:
],
"
\x00
"
))
s
elf
.
setError
(
tr
.
TryUpdate
(
key
[
:
],
v
))
s
.
setError
(
tr
.
TryUpdate
(
key
[
:
],
v
))
}
return
tr
}
// UpdateRoot sets the trie root to the current root hash of
func
(
s
elf
*
stateObject
)
updateRoot
(
db
Database
)
{
s
elf
.
updateTrie
(
db
)
func
(
s
*
stateObject
)
updateRoot
(
db
Database
)
{
s
.
updateTrie
(
db
)
// Track the amount of time wasted on hashing the storge trie
if
metrics
.
EnabledExpensive
{
defer
func
(
start
time
.
Time
)
{
s
elf
.
db
.
StorageHashes
+=
time
.
Since
(
start
)
}(
time
.
Now
())
defer
func
(
start
time
.
Time
)
{
s
.
db
.
StorageHashes
+=
time
.
Since
(
start
)
}(
time
.
Now
())
}
s
elf
.
data
.
Root
=
s
elf
.
trie
.
Hash
()
s
.
data
.
Root
=
s
.
trie
.
Hash
()
}
// CommitTrie the storage trie of the object to db.
// This updates the trie root.
func
(
s
elf
*
stateObject
)
CommitTrie
(
db
Database
)
error
{
s
elf
.
updateTrie
(
db
)
if
s
elf
.
dbErr
!=
nil
{
return
s
elf
.
dbErr
func
(
s
*
stateObject
)
CommitTrie
(
db
Database
)
error
{
s
.
updateTrie
(
db
)
if
s
.
dbErr
!=
nil
{
return
s
.
dbErr
}
// Track the amount of time wasted on committing the storge trie
if
metrics
.
EnabledExpensive
{
defer
func
(
start
time
.
Time
)
{
s
elf
.
db
.
StorageCommits
+=
time
.
Since
(
start
)
}(
time
.
Now
())
defer
func
(
start
time
.
Time
)
{
s
.
db
.
StorageCommits
+=
time
.
Since
(
start
)
}(
time
.
Now
())
}
root
,
err
:=
s
elf
.
trie
.
Commit
(
nil
)
root
,
err
:=
s
.
trie
.
Commit
(
nil
)
if
err
==
nil
{
s
elf
.
data
.
Root
=
root
s
.
data
.
Root
=
root
}
return
err
}
// AddBalance removes amount from c's balance.
// It is used to add funds to the destination account of a transfer.
func
(
c
*
stateObject
)
AddBalance
(
amount
*
big
.
Int
)
{
func
(
s
*
stateObject
)
AddBalance
(
amount
*
big
.
Int
)
{
// EIP158: We must check emptiness for the objects such that the account
// clearing (0,0,0 objects) can take effect.
if
amount
.
Sign
()
==
0
{
if
c
.
empty
()
{
c
.
touch
()
if
s
.
empty
()
{
s
.
touch
()
}
return
}
c
.
SetBalance
(
new
(
big
.
Int
)
.
Add
(
c
.
Balance
(),
amount
))
s
.
SetBalance
(
new
(
big
.
Int
)
.
Add
(
s
.
Balance
(),
amount
))
}
// SubBalance removes amount from c's balance.
// It is used to remove funds from the origin account of a transfer.
func
(
c
*
stateObject
)
SubBalance
(
amount
*
big
.
Int
)
{
func
(
s
*
stateObject
)
SubBalance
(
amount
*
big
.
Int
)
{
if
amount
.
Sign
()
==
0
{
return
}
c
.
SetBalance
(
new
(
big
.
Int
)
.
Sub
(
c
.
Balance
(),
amount
))
s
.
SetBalance
(
new
(
big
.
Int
)
.
Sub
(
s
.
Balance
(),
amount
))
}
func
(
s
elf
*
stateObject
)
SetBalance
(
amount
*
big
.
Int
)
{
s
elf
.
db
.
journal
.
append
(
balanceChange
{
account
:
&
s
elf
.
address
,
prev
:
new
(
big
.
Int
)
.
Set
(
s
elf
.
data
.
Balance
),
func
(
s
*
stateObject
)
SetBalance
(
amount
*
big
.
Int
)
{
s
.
db
.
journal
.
append
(
balanceChange
{
account
:
&
s
.
address
,
prev
:
new
(
big
.
Int
)
.
Set
(
s
.
data
.
Balance
),
})
s
elf
.
setBalance
(
amount
)
s
.
setBalance
(
amount
)
}
func
(
s
elf
*
stateObject
)
setBalance
(
amount
*
big
.
Int
)
{
s
elf
.
data
.
Balance
=
amount
func
(
s
*
stateObject
)
setBalance
(
amount
*
big
.
Int
)
{
s
.
data
.
Balance
=
amount
}
// Return the gas back to the origin. Used by the Virtual machine or Closures
func
(
c
*
stateObject
)
ReturnGas
(
gas
*
big
.
Int
)
{}
func
(
s
*
stateObject
)
ReturnGas
(
gas
*
big
.
Int
)
{}
func
(
s
elf
*
stateObject
)
deepCopy
(
db
*
StateDB
)
*
stateObject
{
stateObject
:=
newObject
(
db
,
s
elf
.
address
,
s
elf
.
data
)
if
s
elf
.
trie
!=
nil
{
stateObject
.
trie
=
db
.
db
.
CopyTrie
(
s
elf
.
trie
)
func
(
s
*
stateObject
)
deepCopy
(
db
*
StateDB
)
*
stateObject
{
stateObject
:=
newObject
(
db
,
s
.
address
,
s
.
data
)
if
s
.
trie
!=
nil
{
stateObject
.
trie
=
db
.
db
.
CopyTrie
(
s
.
trie
)
}
stateObject
.
code
=
s
elf
.
code
stateObject
.
dirtyStorage
=
s
elf
.
dirtyStorage
.
Copy
()
stateObject
.
originStorage
=
s
elf
.
originStorage
.
Copy
()
stateObject
.
suicided
=
s
elf
.
suicided
stateObject
.
dirtyCode
=
s
elf
.
dirtyCode
stateObject
.
deleted
=
s
elf
.
deleted
stateObject
.
code
=
s
.
code
stateObject
.
dirtyStorage
=
s
.
dirtyStorage
.
Copy
()
stateObject
.
originStorage
=
s
.
originStorage
.
Copy
()
stateObject
.
suicided
=
s
.
suicided
stateObject
.
dirtyCode
=
s
.
dirtyCode
stateObject
.
deleted
=
s
.
deleted
return
stateObject
}
...
...
@@ -335,69 +335,69 @@ func (self *stateObject) deepCopy(db *StateDB) *stateObject {
//
// Returns the address of the contract/account
func
(
c
*
stateObject
)
Address
()
common
.
Address
{
return
c
.
address
func
(
s
*
stateObject
)
Address
()
common
.
Address
{
return
s
.
address
}
// Code returns the contract code associated with this object, if any.
func
(
s
elf
*
stateObject
)
Code
(
db
Database
)
[]
byte
{
if
s
elf
.
code
!=
nil
{
return
s
elf
.
code
func
(
s
*
stateObject
)
Code
(
db
Database
)
[]
byte
{
if
s
.
code
!=
nil
{
return
s
.
code
}
if
bytes
.
Equal
(
s
elf
.
CodeHash
(),
emptyCodeHash
)
{
if
bytes
.
Equal
(
s
.
CodeHash
(),
emptyCodeHash
)
{
return
nil
}
code
,
err
:=
db
.
ContractCode
(
s
elf
.
addrHash
,
common
.
BytesToHash
(
s
elf
.
CodeHash
()))
code
,
err
:=
db
.
ContractCode
(
s
.
addrHash
,
common
.
BytesToHash
(
s
.
CodeHash
()))
if
err
!=
nil
{
s
elf
.
setError
(
fmt
.
Errorf
(
"can't load code hash %x: %v"
,
s
elf
.
CodeHash
(),
err
))
s
.
setError
(
fmt
.
Errorf
(
"can't load code hash %x: %v"
,
s
.
CodeHash
(),
err
))
}
s
elf
.
code
=
code
s
.
code
=
code
return
code
}
func
(
s
elf
*
stateObject
)
SetCode
(
codeHash
common
.
Hash
,
code
[]
byte
)
{
prevcode
:=
s
elf
.
Code
(
s
elf
.
db
.
db
)
s
elf
.
db
.
journal
.
append
(
codeChange
{
account
:
&
s
elf
.
address
,
prevhash
:
s
elf
.
CodeHash
(),
func
(
s
*
stateObject
)
SetCode
(
codeHash
common
.
Hash
,
code
[]
byte
)
{
prevcode
:=
s
.
Code
(
s
.
db
.
db
)
s
.
db
.
journal
.
append
(
codeChange
{
account
:
&
s
.
address
,
prevhash
:
s
.
CodeHash
(),
prevcode
:
prevcode
,
})
s
elf
.
setCode
(
codeHash
,
code
)
s
.
setCode
(
codeHash
,
code
)
}
func
(
s
elf
*
stateObject
)
setCode
(
codeHash
common
.
Hash
,
code
[]
byte
)
{
s
elf
.
code
=
code
s
elf
.
data
.
CodeHash
=
codeHash
[
:
]
s
elf
.
dirtyCode
=
true
func
(
s
*
stateObject
)
setCode
(
codeHash
common
.
Hash
,
code
[]
byte
)
{
s
.
code
=
code
s
.
data
.
CodeHash
=
codeHash
[
:
]
s
.
dirtyCode
=
true
}
func
(
s
elf
*
stateObject
)
SetNonce
(
nonce
uint64
)
{
s
elf
.
db
.
journal
.
append
(
nonceChange
{
account
:
&
s
elf
.
address
,
prev
:
s
elf
.
data
.
Nonce
,
func
(
s
*
stateObject
)
SetNonce
(
nonce
uint64
)
{
s
.
db
.
journal
.
append
(
nonceChange
{
account
:
&
s
.
address
,
prev
:
s
.
data
.
Nonce
,
})
s
elf
.
setNonce
(
nonce
)
s
.
setNonce
(
nonce
)
}
func
(
s
elf
*
stateObject
)
setNonce
(
nonce
uint64
)
{
s
elf
.
data
.
Nonce
=
nonce
func
(
s
*
stateObject
)
setNonce
(
nonce
uint64
)
{
s
.
data
.
Nonce
=
nonce
}
func
(
s
elf
*
stateObject
)
CodeHash
()
[]
byte
{
return
s
elf
.
data
.
CodeHash
func
(
s
*
stateObject
)
CodeHash
()
[]
byte
{
return
s
.
data
.
CodeHash
}
func
(
s
elf
*
stateObject
)
Balance
()
*
big
.
Int
{
return
s
elf
.
data
.
Balance
func
(
s
*
stateObject
)
Balance
()
*
big
.
Int
{
return
s
.
data
.
Balance
}
func
(
s
elf
*
stateObject
)
Nonce
()
uint64
{
return
s
elf
.
data
.
Nonce
func
(
s
*
stateObject
)
Nonce
()
uint64
{
return
s
.
data
.
Nonce
}
// Never called, but must be present to allow stateObject to be used
// as a vm.Account interface that also satisfies the vm.ContractRef
// interface. Interfaces are awesome.
func
(
s
elf
*
stateObject
)
Value
()
*
big
.
Int
{
func
(
s
*
stateObject
)
Value
()
*
big
.
Int
{
panic
(
"Value on stateObject should never be called"
)
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment