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
d408cb6f
Unverified
Commit
d408cb6f
authored
Sep 06, 2022
by
Péter Szilágyi
Committed by
GitHub
Sep 06, 2022
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #25694 from karalabe/concurrent-heal-check
trie: check childrens' existence concurrently for snap heal
parents
73188580
a9ec2ab2
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
18 deletions
+39
-18
sync.go
trie/sync.go
+39
-18
No files found.
trie/sync.go
View file @
d408cb6f
...
...
@@ -19,6 +19,7 @@ package trie
import
(
"errors"
"fmt"
"sync"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/prque"
...
...
@@ -381,11 +382,11 @@ func (s *Sync) scheduleCodeRequest(req *codeRequest) {
// retrieval scheduling.
func
(
s
*
Sync
)
children
(
req
*
nodeRequest
,
object
node
)
([]
*
nodeRequest
,
error
)
{
// Gather all the children of the node, irrelevant whether known or not
type
child
struct
{
type
child
Node
struct
{
path
[]
byte
node
node
}
var
children
[]
child
var
children
[]
child
Node
switch
node
:=
(
object
)
.
(
type
)
{
case
*
shortNode
:
...
...
@@ -393,14 +394,14 @@ func (s *Sync) children(req *nodeRequest, object node) ([]*nodeRequest, error) {
if
hasTerm
(
key
)
{
key
=
key
[
:
len
(
key
)
-
1
]
}
children
=
[]
child
{{
children
=
[]
child
Node
{{
node
:
node
.
Val
,
path
:
append
(
append
([]
byte
(
nil
),
req
.
path
...
),
key
...
),
}}
case
*
fullNode
:
for
i
:=
0
;
i
<
17
;
i
++
{
if
node
.
Children
[
i
]
!=
nil
{
children
=
append
(
children
,
child
{
children
=
append
(
children
,
child
Node
{
node
:
node
.
Children
[
i
],
path
:
append
(
append
([]
byte
(
nil
),
req
.
path
...
),
byte
(
i
)),
})
...
...
@@ -410,7 +411,10 @@ func (s *Sync) children(req *nodeRequest, object node) ([]*nodeRequest, error) {
panic
(
fmt
.
Sprintf
(
"unknown node: %+v"
,
node
))
}
// Iterate over the children, and request all unknown ones
requests
:=
make
([]
*
nodeRequest
,
0
,
len
(
children
))
var
(
missing
=
make
(
chan
*
nodeRequest
,
len
(
children
))
pending
sync
.
WaitGroup
)
for
_
,
child
:=
range
children
{
// Notify any external watcher of a new key/value node
if
req
.
callback
!=
nil
{
...
...
@@ -433,19 +437,36 @@ func (s *Sync) children(req *nodeRequest, object node) ([]*nodeRequest, error) {
if
s
.
membatch
.
hasNode
(
child
.
path
)
{
continue
}
// If database says duplicate, then at least the trie node is present
// and we hold the assumption that it's NOT legacy contract code.
chash
:=
common
.
BytesToHash
(
node
)
if
rawdb
.
HasTrieNode
(
s
.
database
,
chash
)
{
continue
}
// Locally unknown node, schedule for retrieval
requests
=
append
(
requests
,
&
nodeRequest
{
path
:
child
.
path
,
hash
:
chash
,
parent
:
req
,
callback
:
req
.
callback
,
})
// Check the presence of children concurrently
pending
.
Add
(
1
)
go
func
(
child
childNode
)
{
defer
pending
.
Done
()
// If database says duplicate, then at least the trie node is present
// and we hold the assumption that it's NOT legacy contract code.
chash
:=
common
.
BytesToHash
(
node
)
if
rawdb
.
HasTrieNode
(
s
.
database
,
chash
)
{
return
}
// Locally unknown node, schedule for retrieval
missing
<-
&
nodeRequest
{
path
:
child
.
path
,
hash
:
chash
,
parent
:
req
,
callback
:
req
.
callback
,
}
}(
child
)
}
}
pending
.
Wait
()
requests
:=
make
([]
*
nodeRequest
,
0
,
len
(
children
))
for
done
:=
false
;
!
done
;
{
select
{
case
miss
:=
<-
missing
:
requests
=
append
(
requests
,
miss
)
default
:
done
=
true
}
}
return
requests
,
nil
...
...
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