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
f459a3f0
Commit
f459a3f0
authored
Sep 23, 2015
by
Péter Szilágyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
eth/downloader: always send termination wakes, clean leftover
parent
e456f277
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
20 deletions
+36
-20
downloader.go
eth/downloader/downloader.go
+36
-20
No files found.
eth/downloader/downloader.go
View file @
f459a3f0
...
@@ -154,7 +154,7 @@ type Downloader struct {
...
@@ -154,7 +154,7 @@ type Downloader struct {
blockCh
chan
blockPack
// [eth/61] Channel receiving inbound blocks
blockCh
chan
blockPack
// [eth/61] Channel receiving inbound blocks
headerCh
chan
headerPack
// [eth/62] Channel receiving inbound block headers
headerCh
chan
headerPack
// [eth/62] Channel receiving inbound block headers
bodyCh
chan
bodyPack
// [eth/62] Channel receiving inbound block bodies
bodyCh
chan
bodyPack
// [eth/62] Channel receiving inbound block bodies
processCh
chan
bool
// Channel to signal the block fetcher of new or finished work
wakeCh
chan
bool
// Channel to signal the block/body fetcher of new tasks
cancelCh
chan
struct
{}
// Channel to cancel mid-flight syncs
cancelCh
chan
struct
{}
// Channel to cancel mid-flight syncs
cancelLock
sync
.
RWMutex
// Lock to protect the cancel channel in delivers
cancelLock
sync
.
RWMutex
// Lock to protect the cancel channel in delivers
...
@@ -188,7 +188,7 @@ func New(mux *event.TypeMux, hasBlock hashCheckFn, getBlock blockRetrievalFn, he
...
@@ -188,7 +188,7 @@ func New(mux *event.TypeMux, hasBlock hashCheckFn, getBlock blockRetrievalFn, he
blockCh
:
make
(
chan
blockPack
,
1
),
blockCh
:
make
(
chan
blockPack
,
1
),
headerCh
:
make
(
chan
headerPack
,
1
),
headerCh
:
make
(
chan
headerPack
,
1
),
bodyCh
:
make
(
chan
bodyPack
,
1
),
bodyCh
:
make
(
chan
bodyPack
,
1
),
processCh
:
make
(
chan
bool
,
1
),
wakeCh
:
make
(
chan
bool
,
1
),
}
}
}
}
...
@@ -282,6 +282,10 @@ func (d *Downloader) synchronise(id string, hash common.Hash, td *big.Int) error
...
@@ -282,6 +282,10 @@ func (d *Downloader) synchronise(id string, hash common.Hash, td *big.Int) error
d
.
queue
.
Reset
()
d
.
queue
.
Reset
()
d
.
peers
.
Reset
()
d
.
peers
.
Reset
()
select
{
case
<-
d
.
wakeCh
:
default
:
}
// Create cancel channel for aborting mid-flight
// Create cancel channel for aborting mid-flight
d
.
cancelLock
.
Lock
()
d
.
cancelLock
.
Lock
()
d
.
cancelCh
=
make
(
chan
struct
{})
d
.
cancelCh
=
make
(
chan
struct
{})
...
@@ -633,7 +637,7 @@ func (d *Downloader) fetchHashes61(p *peer, td *big.Int, from uint64) error {
...
@@ -633,7 +637,7 @@ func (d *Downloader) fetchHashes61(p *peer, td *big.Int, from uint64) error {
glog
.
V
(
logger
.
Debug
)
.
Infof
(
"%v: no available hashes"
,
p
)
glog
.
V
(
logger
.
Debug
)
.
Infof
(
"%v: no available hashes"
,
p
)
select
{
select
{
case
d
.
process
Ch
<-
false
:
case
d
.
wake
Ch
<-
false
:
case
<-
d
.
cancelCh
:
case
<-
d
.
cancelCh
:
}
}
// If no hashes were retrieved at all, the peer violated it's TD promise that it had a
// If no hashes were retrieved at all, the peer violated it's TD promise that it had a
...
@@ -664,12 +668,18 @@ func (d *Downloader) fetchHashes61(p *peer, td *big.Int, from uint64) error {
...
@@ -664,12 +668,18 @@ func (d *Downloader) fetchHashes61(p *peer, td *big.Int, from uint64) error {
return
errBadPeer
return
errBadPeer
}
}
// Notify the block fetcher of new hashes, but stop if queue is full
// Notify the block fetcher of new hashes, but stop if queue is full
cont
:=
d
.
queue
.
Pending
()
<
maxQueuedHashes
if
d
.
queue
.
Pending
()
<
maxQueuedHashes
{
// We still have hashes to fetch, send continuation wake signal (potential)
select
{
select
{
case
d
.
processCh
<-
cont
:
case
d
.
wakeCh
<-
true
:
default
:
default
:
}
}
if
!
cont
{
}
else
{
// Hash limit reached, send a termination wake signal (enforced)
select
{
case
d
.
wakeCh
<-
false
:
case
<-
d
.
cancelCh
:
}
return
nil
return
nil
}
}
// Queue not yet full, fetch the next batch
// Queue not yet full, fetch the next batch
...
@@ -766,7 +776,7 @@ func (d *Downloader) fetchBlocks61(from uint64) error {
...
@@ -766,7 +776,7 @@ func (d *Downloader) fetchBlocks61(from uint64) error {
default
:
default
:
}
}
case
cont
:=
<-
d
.
process
Ch
:
case
cont
:=
<-
d
.
wake
Ch
:
// The hash fetcher sent a continuation flag, check if it's done
// The hash fetcher sent a continuation flag, check if it's done
if
!
cont
{
if
!
cont
{
finished
=
true
finished
=
true
...
@@ -1053,7 +1063,7 @@ func (d *Downloader) fetchHeaders(p *peer, td *big.Int, from uint64) error {
...
@@ -1053,7 +1063,7 @@ func (d *Downloader) fetchHeaders(p *peer, td *big.Int, from uint64) error {
glog
.
V
(
logger
.
Debug
)
.
Infof
(
"%v: no available headers"
,
p
)
glog
.
V
(
logger
.
Debug
)
.
Infof
(
"%v: no available headers"
,
p
)
select
{
select
{
case
d
.
process
Ch
<-
false
:
case
d
.
wake
Ch
<-
false
:
case
<-
d
.
cancelCh
:
case
<-
d
.
cancelCh
:
}
}
// If no headers were retrieved at all, the peer violated it's TD promise that it had a
// If no headers were retrieved at all, the peer violated it's TD promise that it had a
...
@@ -1084,12 +1094,18 @@ func (d *Downloader) fetchHeaders(p *peer, td *big.Int, from uint64) error {
...
@@ -1084,12 +1094,18 @@ func (d *Downloader) fetchHeaders(p *peer, td *big.Int, from uint64) error {
return
errBadPeer
return
errBadPeer
}
}
// Notify the block fetcher of new headers, but stop if queue is full
// Notify the block fetcher of new headers, but stop if queue is full
cont
:=
d
.
queue
.
Pending
()
<
maxQueuedHeaders
if
d
.
queue
.
Pending
()
<
maxQueuedHeaders
{
// We still have headers to fetch, send continuation wake signal (potential)
select
{
select
{
case
d
.
processCh
<-
cont
:
case
d
.
wakeCh
<-
true
:
default
:
default
:
}
}
if
!
cont
{
}
else
{
// Header limit reached, send a termination wake signal (enforced)
select
{
case
d
.
wakeCh
<-
false
:
case
<-
d
.
cancelCh
:
}
return
nil
return
nil
}
}
// Queue not yet full, fetch the next batch
// Queue not yet full, fetch the next batch
...
@@ -1104,8 +1120,8 @@ func (d *Downloader) fetchHeaders(p *peer, td *big.Int, from uint64) error {
...
@@ -1104,8 +1120,8 @@ func (d *Downloader) fetchHeaders(p *peer, td *big.Int, from uint64) error {
// Finish the sync gracefully instead of dumping the gathered data though
// Finish the sync gracefully instead of dumping the gathered data though
select
{
select
{
case
d
.
process
Ch
<-
false
:
case
d
.
wake
Ch
<-
false
:
default
:
case
<-
d
.
cancelCh
:
}
}
return
nil
return
nil
}
}
...
@@ -1199,7 +1215,7 @@ func (d *Downloader) fetchBodies(from uint64) error {
...
@@ -1199,7 +1215,7 @@ func (d *Downloader) fetchBodies(from uint64) error {
default
:
default
:
}
}
case
cont
:=
<-
d
.
process
Ch
:
case
cont
:=
<-
d
.
wake
Ch
:
// The header fetcher sent a continuation flag, check if it's done
// The header fetcher sent a continuation flag, check if it's done
if
!
cont
{
if
!
cont
{
finished
=
true
finished
=
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