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
13bd452f
Commit
13bd452f
authored
Jun 11, 2015
by
Jeffrey Wilcke
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1227 from karalabe/block-fetcher-optimisations
eth: optimize the notification/explicit fetch mechanism
parents
979ebfc1
e61db714
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
18 deletions
+37
-18
sync.go
eth/sync.go
+37
-18
No files found.
eth/sync.go
View file @
13bd452f
...
@@ -127,10 +127,11 @@ func (pm *ProtocolManager) txsyncLoop() {
...
@@ -127,10 +127,11 @@ func (pm *ProtocolManager) txsyncLoop() {
// fetcher is responsible for collecting hash notifications, and periodically
// fetcher is responsible for collecting hash notifications, and periodically
// checking all unknown ones and individually fetching them.
// checking all unknown ones and individually fetching them.
func
(
pm
*
ProtocolManager
)
fetcher
()
{
func
(
pm
*
ProtocolManager
)
fetcher
()
{
announces
:=
make
(
map
[
common
.
Hash
]
*
blockAnnounce
)
announces
:=
make
(
map
[
common
.
Hash
]
[]
*
blockAnnounce
)
request
:=
make
(
map
[
*
peer
][]
common
.
Hash
)
request
:=
make
(
map
[
*
peer
][]
common
.
Hash
)
pending
:=
make
(
map
[
common
.
Hash
]
*
blockAnnounce
)
pending
:=
make
(
map
[
common
.
Hash
]
*
blockAnnounce
)
cycle
:=
time
.
Tick
(
notifyCheckCycle
)
cycle
:=
time
.
Tick
(
notifyCheckCycle
)
done
:=
make
(
chan
common
.
Hash
)
// Iterate the block fetching until a quit is requested
// Iterate the block fetching until a quit is requested
for
{
for
{
...
@@ -139,9 +140,18 @@ func (pm *ProtocolManager) fetcher() {
...
@@ -139,9 +140,18 @@ func (pm *ProtocolManager) fetcher() {
// A batch of hashes the notified, schedule them for retrieval
// A batch of hashes the notified, schedule them for retrieval
glog
.
V
(
logger
.
Debug
)
.
Infof
(
"Scheduling %d hash announcements from %s"
,
len
(
notifications
),
notifications
[
0
]
.
peer
.
id
)
glog
.
V
(
logger
.
Debug
)
.
Infof
(
"Scheduling %d hash announcements from %s"
,
len
(
notifications
),
notifications
[
0
]
.
peer
.
id
)
for
_
,
announce
:=
range
notifications
{
for
_
,
announce
:=
range
notifications
{
announces
[
announce
.
hash
]
=
announce
// Skip if it's already pending fetch
if
_
,
ok
:=
pending
[
announce
.
hash
];
ok
{
continue
}
// Otherwise queue up the peer as a potential source
announces
[
announce
.
hash
]
=
append
(
announces
[
announce
.
hash
],
announce
)
}
}
case
hash
:=
<-
done
:
// A pending import finished, remove all traces
delete
(
pending
,
hash
)
case
<-
cycle
:
case
<-
cycle
:
// Clean up any expired block fetches
// Clean up any expired block fetches
for
hash
,
announce
:=
range
pending
{
for
hash
,
announce
:=
range
pending
{
...
@@ -150,8 +160,9 @@ func (pm *ProtocolManager) fetcher() {
...
@@ -150,8 +160,9 @@ func (pm *ProtocolManager) fetcher() {
}
}
}
}
// Check if any notified blocks failed to arrive
// Check if any notified blocks failed to arrive
for
hash
,
announce
:=
range
announces
{
for
hash
,
all
:=
range
announces
{
if
time
.
Since
(
announce
.
time
)
>
notifyArriveTimeout
{
if
time
.
Since
(
all
[
0
]
.
time
)
>
notifyArriveTimeout
{
announce
:=
all
[
rand
.
Intn
(
len
(
all
))]
if
!
pm
.
chainman
.
HasBlock
(
hash
)
{
if
!
pm
.
chainman
.
HasBlock
(
hash
)
{
request
[
announce
.
peer
]
=
append
(
request
[
announce
.
peer
],
hash
)
request
[
announce
.
peer
]
=
append
(
request
[
announce
.
peer
],
hash
)
pending
[
hash
]
=
announce
pending
[
hash
]
=
announce
...
@@ -200,24 +211,32 @@ func (pm *ProtocolManager) fetcher() {
...
@@ -200,24 +211,32 @@ func (pm *ProtocolManager) fetcher() {
case
<-
pm
.
quitSync
:
case
<-
pm
.
quitSync
:
return
return
}
}
// If any explicit fetches were replied to, import them
// Create a closure with the retrieved blocks and origin peers
if
count
:=
len
(
explicit
);
count
>
0
{
peers
:=
make
([]
*
peer
,
0
,
len
(
explicit
))
glog
.
V
(
logger
.
Debug
)
.
Infof
(
"Importing %d explicitly fetched blocks"
,
count
)
blocks
=
make
([]
*
types
.
Block
,
0
,
len
(
explicit
))
for
_
,
block
:=
range
explicit
{
// Create a closure with the retrieved blocks and origin peers
hash
:=
block
.
Hash
()
peers
:=
make
([]
*
peer
,
0
,
count
)
if
announce
:=
pending
[
hash
];
announce
!=
nil
{
blocks
:=
make
([]
*
types
.
Block
,
0
,
count
)
// Drop the block if it surely cannot fit
for
_
,
block
:=
range
explicit
{
if
pm
.
chainman
.
HasBlock
(
hash
)
||
!
pm
.
chainman
.
HasBlock
(
block
.
ParentHash
())
{
hash
:=
block
.
Hash
()
if
announce
:=
pending
[
hash
];
announce
!=
nil
{
peers
=
append
(
peers
,
announce
.
peer
)
blocks
=
append
(
blocks
,
block
)
delete
(
pending
,
hash
)
delete
(
pending
,
hash
)
continue
}
}
// Otherwise accumulate for import
peers
=
append
(
peers
,
announce
.
peer
)
blocks
=
append
(
blocks
,
block
)
}
}
// Run the importer on a new thread
}
// If any explicit fetches were replied to, import them
if
count
:=
len
(
blocks
);
count
>
0
{
glog
.
V
(
logger
.
Debug
)
.
Infof
(
"Importing %d explicitly fetched blocks"
,
len
(
blocks
))
go
func
()
{
go
func
()
{
// Make sure all hashes are cleaned up
for
_
,
block
:=
range
blocks
{
hash
:=
block
.
Hash
()
defer
func
()
{
done
<-
hash
}()
}
// Try and actually import the blocks
for
i
:=
0
;
i
<
len
(
blocks
);
i
++
{
for
i
:=
0
;
i
<
len
(
blocks
);
i
++
{
if
err
:=
pm
.
importBlock
(
peers
[
i
],
blocks
[
i
],
nil
);
err
!=
nil
{
if
err
:=
pm
.
importBlock
(
peers
[
i
],
blocks
[
i
],
nil
);
err
!=
nil
{
glog
.
V
(
logger
.
Detail
)
.
Infof
(
"Failed to import explicitly fetched block: %v"
,
err
)
glog
.
V
(
logger
.
Detail
)
.
Infof
(
"Failed to import explicitly fetched block: %v"
,
err
)
...
...
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