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
0b2edf05
Unverified
Commit
0b2edf05
authored
May 11, 2020
by
Péter Szilágyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core/state: make GetCodeSize mirror GetCode implementation wise
parent
e29e4c23
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
14 deletions
+20
-14
state_object.go
core/state/state_object.go
+17
-0
statedb.go
core/state/statedb.go
+3
-14
No files found.
core/state/state_object.go
View file @
0b2edf05
...
...
@@ -454,6 +454,23 @@ func (s *stateObject) Code(db Database) []byte {
return
code
}
// 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
// inside the database to avoid loading codes seen recently.
func
(
s
*
stateObject
)
CodeSize
(
db
Database
)
int
{
if
s
.
code
!=
nil
{
return
len
(
s
.
code
)
}
if
bytes
.
Equal
(
s
.
CodeHash
(),
emptyCodeHash
)
{
return
0
}
size
,
err
:=
db
.
ContractCodeSize
(
s
.
addrHash
,
common
.
BytesToHash
(
s
.
CodeHash
()))
if
err
!=
nil
{
s
.
setError
(
fmt
.
Errorf
(
"can't load code size %x: %v"
,
s
.
CodeHash
(),
err
))
}
return
size
}
func
(
s
*
stateObject
)
SetCode
(
codeHash
common
.
Hash
,
code
[]
byte
)
{
prevcode
:=
s
.
Code
(
s
.
db
.
db
)
s
.
db
.
journal
.
append
(
codeChange
{
...
...
core/state/statedb.go
View file @
0b2edf05
...
...
@@ -18,7 +18,6 @@
package
state
import
(
"bytes"
"errors"
"fmt"
"math/big"
...
...
@@ -289,20 +288,10 @@ func (s *StateDB) GetCode(addr common.Address) []byte {
func
(
s
*
StateDB
)
GetCodeSize
(
addr
common
.
Address
)
int
{
stateObject
:=
s
.
getStateObject
(
addr
)
if
stateObject
==
nil
{
return
0
}
if
stateObject
.
code
!=
nil
{
return
len
(
stateObject
.
code
)
}
if
bytes
.
Equal
(
stateObject
.
CodeHash
(),
emptyCode
[
:
])
{
return
0
}
size
,
err
:=
s
.
db
.
ContractCodeSize
(
stateObject
.
addrHash
,
common
.
BytesToHash
(
stateObject
.
CodeHash
()))
if
err
!=
nil
{
s
.
setError
(
fmt
.
Errorf
(
"GetCodeSize (%x) error: %v"
,
addr
[
:
],
err
))
if
stateObject
!=
nil
{
return
stateObject
.
CodeSize
(
s
.
db
)
}
return
size
return
0
}
func
(
s
*
StateDB
)
GetCodeHash
(
addr
common
.
Address
)
common
.
Hash
{
...
...
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