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
8d56bf5c
Commit
8d56bf5c
authored
Oct 17, 2016
by
Felix Lange
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
trie: ensure dirty flag is unset for embedded child nodes
This was caught by the new invariant check.
parent
44f419ec
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
32 deletions
+42
-32
hasher.go
trie/hasher.go
+14
-17
trie_test.go
trie/trie_test.go
+28
-15
No files found.
trie/hasher.go
View file @
8d56bf5c
...
...
@@ -75,23 +75,20 @@ func (h *hasher) hash(n node, db DatabaseWriter, force bool) (node, node, error)
if
err
!=
nil
{
return
hashNode
{},
n
,
err
}
// Cache the hash of the ndoe for later reuse.
if
hash
,
ok
:=
hashed
.
(
hashNode
);
ok
&&
!
force
{
switch
cached
:=
cached
.
(
type
)
{
case
*
shortNode
:
cached
=
cached
.
copy
()
cached
.
flags
.
hash
=
hash
if
db
!=
nil
{
cached
.
flags
.
dirty
=
false
}
return
hashed
,
cached
,
nil
case
*
fullNode
:
cached
=
cached
.
copy
()
cached
.
flags
.
hash
=
hash
if
db
!=
nil
{
cached
.
flags
.
dirty
=
false
}
return
hashed
,
cached
,
nil
// Cache the hash of the ndoe for later reuse and remove
// the dirty flag in commit mode. It's fine to assign these values directly
// without copying the node first because hashChildren copies it.
cachedHash
,
_
:=
hashed
.
(
hashNode
)
switch
cn
:=
cached
.
(
type
)
{
case
*
shortNode
:
cn
.
flags
.
hash
=
cachedHash
if
db
!=
nil
{
cn
.
flags
.
dirty
=
false
}
case
*
fullNode
:
cn
.
flags
.
hash
=
cachedHash
if
db
!=
nil
{
cn
.
flags
.
dirty
=
false
}
}
return
hashed
,
cached
,
nil
...
...
trie/trie_test.go
View file @
8d56bf5c
...
...
@@ -462,31 +462,44 @@ func runRandTest(rt randTest) bool {
return
false
}
case
opCheckCacheInvariant
:
return
checkCacheInvariant
(
tr
.
root
,
tr
.
cachegen
,
0
)
return
checkCacheInvariant
(
tr
.
root
,
nil
,
tr
.
cachegen
,
false
,
0
)
}
}
return
true
}
func
checkCacheInvariant
(
n
node
,
parentCachegen
uint16
,
depth
int
)
bool
{
func
checkCacheInvariant
(
n
,
parent
node
,
parentCachegen
uint16
,
parentDirty
bool
,
depth
int
)
bool
{
var
children
[]
node
var
flag
nodeFlag
switch
n
:=
n
.
(
type
)
{
case
*
shortNode
:
if
n
.
flags
.
gen
>
parentCachegen
{
fmt
.
Printf
(
"cache invariant violation: %d > %d
\n
at depth %d node %s"
,
n
.
flags
.
gen
,
parentCachegen
,
depth
,
spew
.
Sdump
(
n
))
return
false
}
return
checkCacheInvariant
(
n
.
Val
,
n
.
flags
.
gen
,
depth
+
1
)
flag
=
n
.
flags
children
=
[]
node
{
n
.
Val
}
case
*
fullNode
:
if
n
.
flags
.
gen
>
parentCachegen
{
fmt
.
Printf
(
"cache invariant violation: %d > %d
\n
at depth %d node %s"
,
n
.
flags
.
gen
,
parentCachegen
,
depth
,
spew
.
Sdump
(
n
))
flag
=
n
.
flags
children
=
n
.
Children
[
:
]
default
:
return
true
}
showerror
:=
func
()
{
fmt
.
Printf
(
"at depth %d node %s"
,
depth
,
spew
.
Sdump
(
n
))
fmt
.
Printf
(
"parent: %s"
,
spew
.
Sdump
(
parent
))
}
if
flag
.
gen
>
parentCachegen
{
fmt
.
Printf
(
"cache invariant violation: %d > %d
\n
"
,
flag
.
gen
,
parentCachegen
)
showerror
()
return
false
}
if
depth
>
0
&&
!
parentDirty
&&
flag
.
dirty
{
fmt
.
Printf
(
"cache invariant violation: child is dirty but parent isn't
\n
"
)
showerror
()
return
false
}
for
_
,
child
:=
range
children
{
if
!
checkCacheInvariant
(
child
,
n
,
flag
.
gen
,
flag
.
dirty
,
depth
+
1
)
{
return
false
}
for
_
,
child
:=
range
n
.
Children
{
if
!
checkCacheInvariant
(
child
,
n
.
flags
.
gen
,
depth
+
1
)
{
return
false
}
}
return
true
}
return
true
}
...
...
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