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
ee0c8923
Commit
ee0c8923
authored
May 13, 2015
by
Péter Szilágyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
eth/downloader: fix deliveries to check for sync cancels
parent
7cb0e242
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
10 deletions
+31
-10
downloader.go
eth/downloader/downloader.go
+31
-10
No files found.
eth/downloader/downloader.go
View file @
ee0c8923
...
@@ -70,7 +70,9 @@ type Downloader struct {
...
@@ -70,7 +70,9 @@ type Downloader struct {
newPeerCh
chan
*
peer
newPeerCh
chan
*
peer
hashCh
chan
hashPack
hashCh
chan
hashPack
blockCh
chan
blockPack
blockCh
chan
blockPack
cancelCh
chan
struct
{}
cancelCh
chan
struct
{}
// Channel to cancel mid-flight syncs
cancelLock
sync
.
RWMutex
// Lock to protect the cancel channel in delivers
}
}
func
New
(
hasBlock
hashCheckFn
,
getBlock
getBlockFn
)
*
Downloader
{
func
New
(
hasBlock
hashCheckFn
,
getBlock
getBlockFn
)
*
Downloader
{
...
@@ -83,6 +85,9 @@ func New(hasBlock hashCheckFn, getBlock getBlockFn) *Downloader {
...
@@ -83,6 +85,9 @@ func New(hasBlock hashCheckFn, getBlock getBlockFn) *Downloader {
hashCh
:
make
(
chan
hashPack
,
1
),
hashCh
:
make
(
chan
hashPack
,
1
),
blockCh
:
make
(
chan
blockPack
,
1
),
blockCh
:
make
(
chan
blockPack
,
1
),
}
}
// Set the initial downloader state as canceled (sanity check)
downloader
.
cancelCh
=
make
(
chan
struct
{})
close
(
downloader
.
cancelCh
)
return
downloader
return
downloader
}
}
...
@@ -123,8 +128,10 @@ func (d *Downloader) Synchronise(id string, hash common.Hash) error {
...
@@ -123,8 +128,10 @@ func (d *Downloader) Synchronise(id string, hash common.Hash) error {
}
}
defer
atomic
.
StoreInt32
(
&
d
.
synchronising
,
0
)
defer
atomic
.
StoreInt32
(
&
d
.
synchronising
,
0
)
// Create cancel channel for aborting midflight
// Create cancel channel for aborting mid-flight
d
.
cancelLock
.
Lock
()
d
.
cancelCh
=
make
(
chan
struct
{})
d
.
cancelCh
=
make
(
chan
struct
{})
d
.
cancelLock
.
Unlock
()
// Abort if the queue still contains some leftover data
// Abort if the queue still contains some leftover data
if
_
,
cached
:=
d
.
queue
.
Size
();
cached
>
0
&&
d
.
queue
.
GetHeadBlock
()
!=
nil
{
if
_
,
cached
:=
d
.
queue
.
Size
();
cached
>
0
&&
d
.
queue
.
GetHeadBlock
()
!=
nil
{
...
@@ -421,9 +428,18 @@ func (d *Downloader) DeliverBlocks(id string, blocks []*types.Block) error {
...
@@ -421,9 +428,18 @@ func (d *Downloader) DeliverBlocks(id string, blocks []*types.Block) error {
if
atomic
.
LoadInt32
(
&
d
.
synchronising
)
==
0
{
if
atomic
.
LoadInt32
(
&
d
.
synchronising
)
==
0
{
return
errNoSyncActive
return
errNoSyncActive
}
}
d
.
blockCh
<-
blockPack
{
id
,
blocks
}
// Deliver or abort if the sync is canceled while queuing
d
.
cancelLock
.
RLock
()
cancel
:=
d
.
cancelCh
d
.
cancelLock
.
RUnlock
()
select
{
case
d
.
blockCh
<-
blockPack
{
id
,
blocks
}
:
return
nil
return
nil
case
<-
cancel
:
return
errNoSyncActive
}
}
}
// DeliverHashes injects a new batch of hashes received from a remote node into
// DeliverHashes injects a new batch of hashes received from a remote node into
...
@@ -434,11 +450,16 @@ func (d *Downloader) DeliverHashes(id string, hashes []common.Hash) error {
...
@@ -434,11 +450,16 @@ func (d *Downloader) DeliverHashes(id string, hashes []common.Hash) error {
if
atomic
.
LoadInt32
(
&
d
.
synchronising
)
==
0
{
if
atomic
.
LoadInt32
(
&
d
.
synchronising
)
==
0
{
return
errNoSyncActive
return
errNoSyncActive
}
}
if
glog
.
V
(
logger
.
Debug
)
&&
len
(
hashes
)
!=
0
{
// Deliver or abort if the sync is canceled while queuing
from
,
to
:=
hashes
[
0
],
hashes
[
len
(
hashes
)
-
1
]
d
.
cancelLock
.
RLock
()
glog
.
V
(
logger
.
Debug
)
.
Infof
(
"adding %d (T=%d) hashes [ %x / %x ] from: %s
\n
"
,
len
(
hashes
),
d
.
queue
.
Pending
(),
from
[
:
4
],
to
[
:
4
],
id
)
cancel
:=
d
.
cancelCh
}
d
.
cancelLock
.
RUnlock
()
d
.
hashCh
<-
hashPack
{
id
,
hashes
}
select
{
case
d
.
hashCh
<-
hashPack
{
id
,
hashes
}
:
return
nil
return
nil
case
<-
cancel
:
return
errNoSyncActive
}
}
}
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