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
aa699a12
Commit
aa699a12
authored
Jun 17, 2015
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core/state: removed state from state object
parent
aaddc99c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
31 deletions
+20
-31
dump.go
core/state/dump.go
+3
-3
state_object.go
core/state/state_object.go
+15
-18
statedb.go
core/state/statedb.go
+2
-10
No files found.
core/state/dump.go
View file @
aa699a12
...
@@ -34,7 +34,7 @@ func (self *StateDB) RawDump() World {
...
@@ -34,7 +34,7 @@ func (self *StateDB) RawDump() World {
account
:=
Account
{
Balance
:
stateObject
.
balance
.
String
(),
Nonce
:
stateObject
.
nonce
,
Root
:
common
.
Bytes2Hex
(
stateObject
.
Root
()),
CodeHash
:
common
.
Bytes2Hex
(
stateObject
.
codeHash
)}
account
:=
Account
{
Balance
:
stateObject
.
balance
.
String
(),
Nonce
:
stateObject
.
nonce
,
Root
:
common
.
Bytes2Hex
(
stateObject
.
Root
()),
CodeHash
:
common
.
Bytes2Hex
(
stateObject
.
codeHash
)}
account
.
Storage
=
make
(
map
[
string
]
string
)
account
.
Storage
=
make
(
map
[
string
]
string
)
storageIt
:=
stateObject
.
State
.
trie
.
Iterator
()
storageIt
:=
stateObject
.
trie
.
Iterator
()
for
storageIt
.
Next
()
{
for
storageIt
.
Next
()
{
account
.
Storage
[
common
.
Bytes2Hex
(
self
.
trie
.
GetKey
(
storageIt
.
Key
))]
=
common
.
Bytes2Hex
(
storageIt
.
Value
)
account
.
Storage
[
common
.
Bytes2Hex
(
self
.
trie
.
GetKey
(
storageIt
.
Key
))]
=
common
.
Bytes2Hex
(
storageIt
.
Value
)
}
}
...
@@ -54,8 +54,8 @@ func (self *StateDB) Dump() []byte {
...
@@ -54,8 +54,8 @@ func (self *StateDB) Dump() []byte {
// Debug stuff
// Debug stuff
func
(
self
*
StateObject
)
CreateOutputForDiff
()
{
func
(
self
*
StateObject
)
CreateOutputForDiff
()
{
fmt
.
Printf
(
"%x %x %x %x
\n
"
,
self
.
Address
(),
self
.
State
.
Root
(),
self
.
balance
.
Bytes
(),
self
.
nonce
)
fmt
.
Printf
(
"%x %x %x %x
\n
"
,
self
.
Address
(),
self
.
Root
(),
self
.
balance
.
Bytes
(),
self
.
nonce
)
it
:=
self
.
State
.
trie
.
Iterator
()
it
:=
self
.
trie
.
Iterator
()
for
it
.
Next
()
{
for
it
.
Next
()
{
fmt
.
Printf
(
"%x %x
\n
"
,
it
.
Key
,
it
.
Value
)
fmt
.
Printf
(
"%x %x
\n
"
,
it
.
Key
,
it
.
Value
)
}
}
...
...
core/state/state_object.go
View file @
aa699a12
...
@@ -40,9 +40,8 @@ func (self Storage) Copy() Storage {
...
@@ -40,9 +40,8 @@ func (self Storage) Copy() Storage {
type
StateObject
struct
{
type
StateObject
struct
{
// State database for storing state changes
// State database for storing state changes
db
common
.
Database
db
common
.
Database
// The state object
trie
*
trie
.
SecureTrie
State
*
StateDB
// Address belonging to this account
// Address belonging to this account
address
common
.
Address
address
common
.
Address
...
@@ -75,7 +74,6 @@ type StateObject struct {
...
@@ -75,7 +74,6 @@ type StateObject struct {
func
(
self
*
StateObject
)
Reset
()
{
func
(
self
*
StateObject
)
Reset
()
{
self
.
storage
=
make
(
Storage
)
self
.
storage
=
make
(
Storage
)
self
.
State
.
Reset
()
}
}
func
NewStateObject
(
address
common
.
Address
,
db
common
.
Database
)
*
StateObject
{
func
NewStateObject
(
address
common
.
Address
,
db
common
.
Database
)
*
StateObject
{
...
@@ -83,7 +81,7 @@ func NewStateObject(address common.Address, db common.Database) *StateObject {
...
@@ -83,7 +81,7 @@ func NewStateObject(address common.Address, db common.Database) *StateObject {
//address := common.ToAddress(addr)
//address := common.ToAddress(addr)
object
:=
&
StateObject
{
db
:
db
,
address
:
address
,
balance
:
new
(
big
.
Int
),
gasPool
:
new
(
big
.
Int
),
dirty
:
true
}
object
:=
&
StateObject
{
db
:
db
,
address
:
address
,
balance
:
new
(
big
.
Int
),
gasPool
:
new
(
big
.
Int
),
dirty
:
true
}
object
.
State
=
New
(
common
.
Hash
{},
db
)
//New(trie.New(common.Config.Db, "")
)
object
.
trie
=
trie
.
NewSecure
((
common
.
Hash
{})
.
Bytes
(),
db
)
object
.
storage
=
make
(
Storage
)
object
.
storage
=
make
(
Storage
)
object
.
gasPool
=
new
(
big
.
Int
)
object
.
gasPool
=
new
(
big
.
Int
)
object
.
prepaid
=
new
(
big
.
Int
)
object
.
prepaid
=
new
(
big
.
Int
)
...
@@ -110,7 +108,7 @@ func NewStateObjectFromBytes(address common.Address, data []byte, db common.Data
...
@@ -110,7 +108,7 @@ func NewStateObjectFromBytes(address common.Address, data []byte, db common.Data
object
.
nonce
=
extobject
.
Nonce
object
.
nonce
=
extobject
.
Nonce
object
.
balance
=
extobject
.
Balance
object
.
balance
=
extobject
.
Balance
object
.
codeHash
=
extobject
.
CodeHash
object
.
codeHash
=
extobject
.
CodeHash
object
.
State
=
New
(
extobject
.
Root
,
db
)
object
.
trie
=
trie
.
NewSecure
(
extobject
.
Root
[
:
]
,
db
)
object
.
storage
=
make
(
map
[
string
]
common
.
Hash
)
object
.
storage
=
make
(
map
[
string
]
common
.
Hash
)
object
.
gasPool
=
new
(
big
.
Int
)
object
.
gasPool
=
new
(
big
.
Int
)
object
.
prepaid
=
new
(
big
.
Int
)
object
.
prepaid
=
new
(
big
.
Int
)
...
@@ -130,7 +128,7 @@ func (self *StateObject) MarkForDeletion() {
...
@@ -130,7 +128,7 @@ func (self *StateObject) MarkForDeletion() {
func
(
c
*
StateObject
)
getAddr
(
addr
common
.
Hash
)
common
.
Hash
{
func
(
c
*
StateObject
)
getAddr
(
addr
common
.
Hash
)
common
.
Hash
{
var
ret
[]
byte
var
ret
[]
byte
rlp
.
DecodeBytes
(
c
.
State
.
trie
.
Get
(
addr
[
:
]),
&
ret
)
rlp
.
DecodeBytes
(
c
.
trie
.
Get
(
addr
[
:
]),
&
ret
)
return
common
.
BytesToHash
(
ret
)
return
common
.
BytesToHash
(
ret
)
}
}
...
@@ -140,7 +138,7 @@ func (c *StateObject) setAddr(addr []byte, value common.Hash) {
...
@@ -140,7 +138,7 @@ func (c *StateObject) setAddr(addr []byte, value common.Hash) {
// if RLPing failed we better panic and not fail silently. This would be considered a consensus issue
// if RLPing failed we better panic and not fail silently. This would be considered a consensus issue
panic
(
err
)
panic
(
err
)
}
}
c
.
State
.
trie
.
Update
(
addr
,
v
)
c
.
trie
.
Update
(
addr
,
v
)
}
}
func
(
self
*
StateObject
)
Storage
()
Storage
{
func
(
self
*
StateObject
)
Storage
()
Storage
{
...
@@ -165,10 +163,11 @@ func (self *StateObject) SetState(k, value common.Hash) {
...
@@ -165,10 +163,11 @@ func (self *StateObject) SetState(k, value common.Hash) {
self
.
dirty
=
true
self
.
dirty
=
true
}
}
func
(
self
*
StateObject
)
Sync
()
{
// Update updates the current cached storage to the trie
func
(
self
*
StateObject
)
Update
()
{
for
key
,
value
:=
range
self
.
storage
{
for
key
,
value
:=
range
self
.
storage
{
if
(
value
==
common
.
Hash
{})
{
if
(
value
==
common
.
Hash
{})
{
self
.
State
.
trie
.
Delete
([]
byte
(
key
))
self
.
trie
.
Delete
([]
byte
(
key
))
continue
continue
}
}
...
@@ -261,9 +260,7 @@ func (self *StateObject) Copy() *StateObject {
...
@@ -261,9 +260,7 @@ func (self *StateObject) Copy() *StateObject {
stateObject
.
balance
.
Set
(
self
.
balance
)
stateObject
.
balance
.
Set
(
self
.
balance
)
stateObject
.
codeHash
=
common
.
CopyBytes
(
self
.
codeHash
)
stateObject
.
codeHash
=
common
.
CopyBytes
(
self
.
codeHash
)
stateObject
.
nonce
=
self
.
nonce
stateObject
.
nonce
=
self
.
nonce
if
self
.
State
!=
nil
{
stateObject
.
trie
=
self
.
trie
stateObject
.
State
=
self
.
State
.
Copy
()
}
stateObject
.
code
=
common
.
CopyBytes
(
self
.
code
)
stateObject
.
code
=
common
.
CopyBytes
(
self
.
code
)
stateObject
.
initCode
=
common
.
CopyBytes
(
self
.
initCode
)
stateObject
.
initCode
=
common
.
CopyBytes
(
self
.
initCode
)
stateObject
.
storage
=
self
.
storage
.
Copy
()
stateObject
.
storage
=
self
.
storage
.
Copy
()
...
@@ -301,11 +298,11 @@ func (c *StateObject) Init() Code {
...
@@ -301,11 +298,11 @@ func (c *StateObject) Init() Code {
}
}
func
(
self
*
StateObject
)
Trie
()
*
trie
.
SecureTrie
{
func
(
self
*
StateObject
)
Trie
()
*
trie
.
SecureTrie
{
return
self
.
State
.
trie
return
self
.
trie
}
}
func
(
self
*
StateObject
)
Root
()
[]
byte
{
func
(
self
*
StateObject
)
Root
()
[]
byte
{
return
self
.
Trie
()
.
Root
()
return
self
.
trie
.
Root
()
}
}
func
(
self
*
StateObject
)
Code
()
[]
byte
{
func
(
self
*
StateObject
)
Code
()
[]
byte
{
...
@@ -337,10 +334,10 @@ func (self *StateObject) EachStorage(cb func(key, value []byte)) {
...
@@ -337,10 +334,10 @@ func (self *StateObject) EachStorage(cb func(key, value []byte)) {
cb
([]
byte
(
h
),
v
.
Bytes
())
cb
([]
byte
(
h
),
v
.
Bytes
())
}
}
it
:=
self
.
State
.
trie
.
Iterator
()
it
:=
self
.
trie
.
Iterator
()
for
it
.
Next
()
{
for
it
.
Next
()
{
// ignore cached values
// ignore cached values
key
:=
self
.
State
.
trie
.
GetKey
(
it
.
Key
)
key
:=
self
.
trie
.
GetKey
(
it
.
Key
)
if
_
,
ok
:=
self
.
storage
[
string
(
key
)];
!
ok
{
if
_
,
ok
:=
self
.
storage
[
string
(
key
)];
!
ok
{
cb
(
key
,
it
.
Value
)
cb
(
key
,
it
.
Value
)
}
}
...
@@ -364,7 +361,7 @@ func (c *StateObject) RlpDecode(data []byte) {
...
@@ -364,7 +361,7 @@ func (c *StateObject) RlpDecode(data []byte) {
decoder
:=
common
.
NewValueFromBytes
(
data
)
decoder
:=
common
.
NewValueFromBytes
(
data
)
c
.
nonce
=
decoder
.
Get
(
0
)
.
Uint
()
c
.
nonce
=
decoder
.
Get
(
0
)
.
Uint
()
c
.
balance
=
decoder
.
Get
(
1
)
.
BigInt
()
c
.
balance
=
decoder
.
Get
(
1
)
.
BigInt
()
c
.
State
=
New
(
common
.
BytesToHash
(
decoder
.
Get
(
2
)
.
Bytes
()),
c
.
db
)
//New(trie.New(common.Config.Db, decoder.Get(2).Interface())
)
c
.
trie
=
trie
.
NewSecure
(
decoder
.
Get
(
2
)
.
Bytes
(),
c
.
db
)
c
.
storage
=
make
(
map
[
string
]
common
.
Hash
)
c
.
storage
=
make
(
map
[
string
]
common
.
Hash
)
c
.
gasPool
=
new
(
big
.
Int
)
c
.
gasPool
=
new
(
big
.
Int
)
...
...
core/state/statedb.go
View file @
aa699a12
...
@@ -296,10 +296,6 @@ func (s *StateDB) Reset() {
...
@@ -296,10 +296,6 @@ func (s *StateDB) Reset() {
// Reset all nested states
// Reset all nested states
for
_
,
stateObject
:=
range
s
.
stateObjects
{
for
_
,
stateObject
:=
range
s
.
stateObjects
{
if
stateObject
.
State
==
nil
{
continue
}
stateObject
.
Reset
()
stateObject
.
Reset
()
}
}
...
@@ -310,11 +306,7 @@ func (s *StateDB) Reset() {
...
@@ -310,11 +306,7 @@ func (s *StateDB) Reset() {
func
(
s
*
StateDB
)
Sync
()
{
func
(
s
*
StateDB
)
Sync
()
{
// Sync all nested states
// Sync all nested states
for
_
,
stateObject
:=
range
s
.
stateObjects
{
for
_
,
stateObject
:=
range
s
.
stateObjects
{
if
stateObject
.
State
==
nil
{
stateObject
.
trie
.
Commit
()
continue
}
stateObject
.
State
.
Sync
()
}
}
s
.
trie
.
Commit
()
s
.
trie
.
Commit
()
...
@@ -339,7 +331,7 @@ func (self *StateDB) Update() {
...
@@ -339,7 +331,7 @@ func (self *StateDB) Update() {
if
stateObject
.
remove
{
if
stateObject
.
remove
{
self
.
DeleteStateObject
(
stateObject
)
self
.
DeleteStateObject
(
stateObject
)
}
else
{
}
else
{
stateObject
.
Sync
()
stateObject
.
Update
()
self
.
UpdateStateObject
(
stateObject
)
self
.
UpdateStateObject
(
stateObject
)
}
}
...
...
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