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
08caeedd
Commit
08caeedd
authored
Jun 30, 2015
by
Jeffrey Wilcke
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core, core/state: only write necessary state. Skip intermediate
parent
6f69b4d6
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
11 deletions
+21
-11
block_processor.go
core/block_processor.go
+1
-1
state_object.go
core/state/state_object.go
+0
-8
statedb.go
core/state/statedb.go
+20
-2
No files found.
core/block_processor.go
View file @
08caeedd
...
@@ -243,7 +243,7 @@ func (sm *BlockProcessor) processWithParent(block, parent *types.Block) (logs st
...
@@ -243,7 +243,7 @@ func (sm *BlockProcessor) processWithParent(block, parent *types.Block) (logs st
// Commit state objects/accounts to a temporary trie (does not save)
// Commit state objects/accounts to a temporary trie (does not save)
// used to calculate the state root.
// used to calculate the state root.
state
.
Update
()
state
.
Clean
Update
()
if
header
.
Root
!=
state
.
Root
()
{
if
header
.
Root
!=
state
.
Root
()
{
err
=
fmt
.
Errorf
(
"invalid merkle root. received=%x got=%x"
,
header
.
Root
,
state
.
Root
())
err
=
fmt
.
Errorf
(
"invalid merkle root. received=%x got=%x"
,
header
.
Root
,
state
.
Root
())
return
return
...
...
core/state/state_object.go
View file @
08caeedd
...
@@ -57,8 +57,6 @@ type StateObject struct {
...
@@ -57,8 +57,6 @@ type StateObject struct {
initCode
Code
initCode
Code
// Cached storage (flushed when updated)
// Cached storage (flushed when updated)
storage
Storage
storage
Storage
// Temporary prepaid gas, reward after transition
prepaid
*
big
.
Int
// Total gas pool is the total amount of gas currently
// Total gas pool is the total amount of gas currently
// left if this object is the coinbase. Gas is directly
// left if this object is the coinbase. Gas is directly
...
@@ -77,14 +75,10 @@ func (self *StateObject) Reset() {
...
@@ -77,14 +75,10 @@ func (self *StateObject) Reset() {
}
}
func
NewStateObject
(
address
common
.
Address
,
db
common
.
Database
)
*
StateObject
{
func
NewStateObject
(
address
common
.
Address
,
db
common
.
Database
)
*
StateObject
{
// This to ensure that it has 20 bytes (and not 0 bytes), thus left or right pad doesn't matter.
//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
.
trie
=
trie
.
NewSecure
((
common
.
Hash
{})
.
Bytes
(),
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
)
return
object
return
object
}
}
...
@@ -110,7 +104,6 @@ func NewStateObjectFromBytes(address common.Address, data []byte, db common.Data
...
@@ -110,7 +104,6 @@ func NewStateObjectFromBytes(address common.Address, data []byte, db common.Data
object
.
trie
=
trie
.
NewSecure
(
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
.
code
,
_
=
db
.
Get
(
extobject
.
CodeHash
)
object
.
code
,
_
=
db
.
Get
(
extobject
.
CodeHash
)
return
object
return
object
...
@@ -172,7 +165,6 @@ func (self *StateObject) Update() {
...
@@ -172,7 +165,6 @@ func (self *StateObject) Update() {
self
.
setAddr
([]
byte
(
key
),
value
)
self
.
setAddr
([]
byte
(
key
),
value
)
}
}
self
.
storage
=
make
(
Storage
)
}
}
func
(
c
*
StateObject
)
GetInstr
(
pc
*
big
.
Int
)
*
common
.
Value
{
func
(
c
*
StateObject
)
GetInstr
(
pc
*
big
.
Int
)
*
common
.
Value
{
...
...
core/state/statedb.go
View file @
08caeedd
...
@@ -18,6 +18,7 @@ import (
...
@@ -18,6 +18,7 @@ import (
type
StateDB
struct
{
type
StateDB
struct
{
db
common
.
Database
db
common
.
Database
trie
*
trie
.
SecureTrie
trie
*
trie
.
SecureTrie
root
common
.
Hash
stateObjects
map
[
string
]
*
StateObject
stateObjects
map
[
string
]
*
StateObject
...
@@ -31,7 +32,7 @@ type StateDB struct {
...
@@ -31,7 +32,7 @@ type StateDB struct {
// Create a new state from a given trie
// Create a new state from a given trie
func
New
(
root
common
.
Hash
,
db
common
.
Database
)
*
StateDB
{
func
New
(
root
common
.
Hash
,
db
common
.
Database
)
*
StateDB
{
trie
:=
trie
.
NewSecure
(
root
[
:
],
db
)
trie
:=
trie
.
NewSecure
(
root
[
:
],
db
)
return
&
StateDB
{
db
:
db
,
trie
:
trie
,
stateObjects
:
make
(
map
[
string
]
*
StateObject
),
refund
:
new
(
big
.
Int
),
logs
:
make
(
map
[
common
.
Hash
]
Logs
)}
return
&
StateDB
{
root
:
root
,
db
:
db
,
trie
:
trie
,
stateObjects
:
make
(
map
[
string
]
*
StateObject
),
refund
:
new
(
big
.
Int
),
logs
:
make
(
map
[
common
.
Hash
]
Logs
)}
}
}
func
(
self
*
StateDB
)
PrintRoot
()
{
func
(
self
*
StateDB
)
PrintRoot
()
{
...
@@ -185,7 +186,7 @@ func (self *StateDB) DeleteStateObject(stateObject *StateObject) {
...
@@ -185,7 +186,7 @@ func (self *StateDB) DeleteStateObject(stateObject *StateObject) {
addr
:=
stateObject
.
Address
()
addr
:=
stateObject
.
Address
()
self
.
trie
.
Delete
(
addr
[
:
])
self
.
trie
.
Delete
(
addr
[
:
])
delete
(
self
.
stateObjects
,
addr
.
Str
())
//
delete(self.stateObjects, addr.Str())
}
}
// Retrieve a state object given my the address. Nil if not found
// Retrieve a state object given my the address. Nil if not found
...
@@ -340,6 +341,23 @@ func (self *StateDB) Update() {
...
@@ -340,6 +341,23 @@ func (self *StateDB) Update() {
}
}
}
}
func
(
self
*
StateDB
)
CleanUpdate
()
{
self
.
trie
=
trie
.
NewSecure
(
self
.
root
[
:
],
self
.
db
)
self
.
refund
=
new
(
big
.
Int
)
for
_
,
stateObject
:=
range
self
.
stateObjects
{
if
stateObject
.
remove
{
self
.
DeleteStateObject
(
stateObject
)
}
else
{
stateObject
.
Update
()
self
.
UpdateStateObject
(
stateObject
)
}
stateObject
.
dirty
=
false
}
}
// Debug stuff
// Debug stuff
func
(
self
*
StateDB
)
CreateOutputForDiff
()
{
func
(
self
*
StateDB
)
CreateOutputForDiff
()
{
for
_
,
stateObject
:=
range
self
.
stateObjects
{
for
_
,
stateObject
:=
range
self
.
stateObjects
{
...
...
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