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
0c7b99b8
Unverified
Commit
0c7b99b8
authored
Apr 10, 2018
by
Martin Holst Swende
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core/state: fix bug in copy of copy State
parent
2e247705
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
0 deletions
+26
-0
statedb.go
core/state/statedb.go
+10
-0
statedb_test.go
core/state/statedb_test.go
+16
-0
No files found.
core/state/statedb.go
View file @
0c7b99b8
...
...
@@ -474,6 +474,16 @@ func (self *StateDB) Copy() *StateDB {
state
.
stateObjects
[
addr
]
=
self
.
stateObjects
[
addr
]
.
deepCopy
(
state
)
state
.
stateObjectsDirty
[
addr
]
=
struct
{}{}
}
// Above, we don't copy the actual journal. This means that if the copy is copied, the
// loop above will be a no-op, since the copy's journal is empty.
// Thus, here we iterate over stateObjects, to enable copies of copies
for
addr
:=
range
self
.
stateObjectsDirty
{
if
_
,
exist
:=
state
.
stateObjects
[
addr
];
!
exist
{
state
.
stateObjects
[
addr
]
=
self
.
stateObjects
[
addr
]
.
deepCopy
(
state
)
state
.
stateObjectsDirty
[
addr
]
=
struct
{}{}
}
}
for
hash
,
logs
:=
range
self
.
logs
{
state
.
logs
[
hash
]
=
make
([]
*
types
.
Log
,
len
(
logs
))
copy
(
state
.
logs
[
hash
],
logs
)
...
...
core/state/statedb_test.go
View file @
0c7b99b8
...
...
@@ -422,3 +422,19 @@ func (s *StateSuite) TestTouchDelete(c *check.C) {
c
.
Fatal
(
"expected no dirty state object"
)
}
}
// TestCopyOfCopy tests that modified objects are carried over to the copy, and the copy of the copy.
// See https://github.com/ethereum/go-ethereum/pull/15225#issuecomment-380191512
func
TestCopyOfCopy
(
t
*
testing
.
T
)
{
db
,
_
:=
ethdb
.
NewMemDatabase
()
sdb
,
_
:=
New
(
common
.
Hash
{},
NewDatabase
(
db
))
addr
:=
common
.
HexToAddress
(
"aaaa"
)
sdb
.
SetBalance
(
addr
,
big
.
NewInt
(
42
))
if
got
:=
sdb
.
Copy
()
.
GetBalance
(
addr
)
.
Uint64
();
got
!=
42
{
t
.
Fatalf
(
"1st copy fail, expected 42, got %v"
,
got
)
}
if
got
:=
sdb
.
Copy
()
.
Copy
()
.
GetBalance
(
addr
)
.
Uint64
();
got
!=
42
{
t
.
Fatalf
(
"2nd copy fail, expected 42, got %v"
,
got
)
}
}
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