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
c683e4aa
Commit
c683e4aa
authored
8 years ago
by
Péter Szilágyi
Committed by
GitHub
8 years ago
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3072 from karalabe/state-storage-dirty
core/state: track dirty state entries for each object
parents
d4b55fc5
b7159818
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
18 deletions
+24
-18
state_object.go
core/state/state_object.go
+17
-11
state_test.go
core/state/state_test.go
+7
-7
No files found.
core/state/state_object.go
View file @
c683e4aa
...
...
@@ -75,9 +75,11 @@ type StateObject struct {
dbErr
error
// Write caches.
trie
*
trie
.
SecureTrie
// storage trie, which becomes non-nil on first access
code
Code
// contract bytecode, which gets set when code is loaded
storage
Storage
// Cached storage (flushed when updated)
trie
*
trie
.
SecureTrie
// storage trie, which becomes non-nil on first access
code
Code
// contract bytecode, which gets set when code is loaded
cachedStorage
Storage
// Storage entry cache to avoid duplicate reads
dirtyStorage
Storage
// Storage entries that need to be flushed to disk
// Cache flags.
// When an object is marked for deletion it will be delete from the trie
...
...
@@ -105,7 +107,7 @@ func NewObject(address common.Address, data Account, onDirty func(addr common.Ad
if
data
.
CodeHash
==
nil
{
data
.
CodeHash
=
emptyCodeHash
}
return
&
StateObject
{
address
:
address
,
data
:
data
,
s
torage
:
make
(
Storage
),
onDirty
:
onDirty
}
return
&
StateObject
{
address
:
address
,
data
:
data
,
cachedStorage
:
make
(
Storage
),
dirtyS
torage
:
make
(
Storage
),
onDirty
:
onDirty
}
}
// EncodeRLP implements rlp.Encoder.
...
...
@@ -145,7 +147,7 @@ func (c *StateObject) getTrie(db trie.Database) *trie.SecureTrie {
// GetState returns a value in account storage.
func
(
self
*
StateObject
)
GetState
(
db
trie
.
Database
,
key
common
.
Hash
)
common
.
Hash
{
value
,
exists
:=
self
.
s
torage
[
key
]
value
,
exists
:=
self
.
cachedS
torage
[
key
]
if
exists
{
return
value
}
...
...
@@ -155,14 +157,16 @@ func (self *StateObject) GetState(db trie.Database, key common.Hash) common.Hash
rlp
.
DecodeBytes
(
tr
.
Get
(
key
[
:
]),
&
ret
)
value
=
common
.
BytesToHash
(
ret
)
if
(
value
!=
common
.
Hash
{})
{
self
.
s
torage
[
key
]
=
value
self
.
cachedS
torage
[
key
]
=
value
}
return
value
}
// SetState updates a value in account storage.
func
(
self
*
StateObject
)
SetState
(
key
,
value
common
.
Hash
)
{
self
.
storage
[
key
]
=
value
self
.
cachedStorage
[
key
]
=
value
self
.
dirtyStorage
[
key
]
=
value
if
self
.
onDirty
!=
nil
{
self
.
onDirty
(
self
.
Address
())
self
.
onDirty
=
nil
...
...
@@ -172,7 +176,8 @@ func (self *StateObject) SetState(key, value common.Hash) {
// updateTrie writes cached storage modifications into the object's storage trie.
func
(
self
*
StateObject
)
updateTrie
(
db
trie
.
Database
)
{
tr
:=
self
.
getTrie
(
db
)
for
key
,
value
:=
range
self
.
storage
{
for
key
,
value
:=
range
self
.
dirtyStorage
{
delete
(
self
.
dirtyStorage
,
key
)
if
(
value
==
common
.
Hash
{})
{
tr
.
Delete
(
key
[
:
])
continue
...
...
@@ -241,7 +246,8 @@ func (self *StateObject) Copy(db trie.Database, onDirty func(addr common.Address
stateObject
:=
NewObject
(
self
.
address
,
self
.
data
,
onDirty
)
stateObject
.
trie
=
self
.
trie
stateObject
.
code
=
self
.
code
stateObject
.
storage
=
self
.
storage
.
Copy
()
stateObject
.
dirtyStorage
=
self
.
dirtyStorage
.
Copy
()
stateObject
.
cachedStorage
=
self
.
dirtyStorage
.
Copy
()
stateObject
.
remove
=
self
.
remove
stateObject
.
dirtyCode
=
self
.
dirtyCode
stateObject
.
deleted
=
self
.
deleted
...
...
@@ -312,7 +318,7 @@ func (self *StateObject) Value() *big.Int {
func
(
self
*
StateObject
)
ForEachStorage
(
cb
func
(
key
,
value
common
.
Hash
)
bool
)
{
// When iterating over the storage check the cache first
for
h
,
value
:=
range
self
.
s
torage
{
for
h
,
value
:=
range
self
.
cachedS
torage
{
cb
(
h
,
value
)
}
...
...
@@ -320,7 +326,7 @@ func (self *StateObject) ForEachStorage(cb func(key, value common.Hash) bool) {
for
it
.
Next
()
{
// ignore cached values
key
:=
common
.
BytesToHash
(
self
.
trie
.
GetKey
(
it
.
Key
))
if
_
,
ok
:=
self
.
s
torage
[
key
];
!
ok
{
if
_
,
ok
:=
self
.
cachedS
torage
[
key
];
!
ok
{
cb
(
key
,
common
.
BytesToHash
(
it
.
Value
))
}
}
...
...
This diff is collapsed.
Click to expand it.
core/state/state_test.go
View file @
c683e4aa
...
...
@@ -208,16 +208,16 @@ func compareStateObjects(so0, so1 *StateObject, t *testing.T) {
t
.
Fatalf
(
"Code mismatch: have %v, want %v"
,
so0
.
code
,
so1
.
code
)
}
if
len
(
so1
.
storage
)
!=
len
(
so0
.
s
torage
)
{
t
.
Errorf
(
"Storage size mismatch: have %d, want %d"
,
len
(
so1
.
storage
),
len
(
so0
.
s
torage
))
if
len
(
so1
.
cachedStorage
)
!=
len
(
so0
.
cachedS
torage
)
{
t
.
Errorf
(
"Storage size mismatch: have %d, want %d"
,
len
(
so1
.
cachedStorage
),
len
(
so0
.
cachedS
torage
))
}
for
k
,
v
:=
range
so1
.
s
torage
{
if
so0
.
s
torage
[
k
]
!=
v
{
t
.
Errorf
(
"Storage key %x mismatch: have %v, want %v"
,
k
,
so0
.
s
torage
[
k
],
v
)
for
k
,
v
:=
range
so1
.
cachedS
torage
{
if
so0
.
cachedS
torage
[
k
]
!=
v
{
t
.
Errorf
(
"Storage key %x mismatch: have %v, want %v"
,
k
,
so0
.
cachedS
torage
[
k
],
v
)
}
}
for
k
,
v
:=
range
so0
.
s
torage
{
if
so1
.
s
torage
[
k
]
!=
v
{
for
k
,
v
:=
range
so0
.
cachedS
torage
{
if
so1
.
cachedS
torage
[
k
]
!=
v
{
t
.
Errorf
(
"Storage key %x mismatch: have %v, want none."
,
k
,
v
)
}
}
...
...
This diff is collapsed.
Click to expand it.
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