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
b517967f
Commit
b517967f
authored
May 15, 2015
by
Péter Szilágyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
eth/downloader: don't penalize for stale cross checks
parent
83226762
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
7 deletions
+17
-7
downloader.go
eth/downloader/downloader.go
+17
-7
No files found.
eth/downloader/downloader.go
View file @
b517967f
...
@@ -63,9 +63,10 @@ type hashPack struct {
...
@@ -63,9 +63,10 @@ type hashPack struct {
type
Downloader
struct
{
type
Downloader
struct
{
mux
*
event
.
TypeMux
mux
*
event
.
TypeMux
mu
sync
.
RWMutex
mu
sync
.
RWMutex
queue
*
queue
queue
*
queue
// Scheduler for selecting the hashes to download
peers
*
peerSet
peers
*
peerSet
// Set of active peers from which download can proceed
checks
map
[
common
.
Hash
]
time
.
Time
// Pending cross checks to verify a hash chain
// Callbacks
// Callbacks
hasBlock
hashCheckFn
hasBlock
hashCheckFn
...
@@ -89,6 +90,7 @@ func New(mux *event.TypeMux, hasBlock hashCheckFn, getBlock getBlockFn) *Downloa
...
@@ -89,6 +90,7 @@ func New(mux *event.TypeMux, hasBlock hashCheckFn, getBlock getBlockFn) *Downloa
mux
:
mux
,
mux
:
mux
,
queue
:
newQueue
(),
queue
:
newQueue
(),
peers
:
newPeerSet
(),
peers
:
newPeerSet
(),
checks
:
make
(
map
[
common
.
Hash
]
time
.
Time
),
hasBlock
:
hasBlock
,
hasBlock
:
hasBlock
,
getBlock
:
getBlock
,
getBlock
:
getBlock
,
newPeerCh
:
make
(
chan
*
peer
,
1
),
newPeerCh
:
make
(
chan
*
peer
,
1
),
...
@@ -236,7 +238,6 @@ func (d *Downloader) fetchHashes(p *peer, h common.Hash) error {
...
@@ -236,7 +238,6 @@ func (d *Downloader) fetchHashes(p *peer, h common.Hash) error {
timeout
=
time
.
NewTimer
(
hashTTL
)
// timer to dump a non-responsive active peer
timeout
=
time
.
NewTimer
(
hashTTL
)
// timer to dump a non-responsive active peer
attempted
=
make
(
map
[
string
]
bool
)
// attempted peers will help with retries
attempted
=
make
(
map
[
string
]
bool
)
// attempted peers will help with retries
crossChecks
=
make
(
map
[
common
.
Hash
]
time
.
Time
)
// running cross checks and their deadline
crossTicker
=
time
.
NewTicker
(
crossCheckCycle
)
// ticker to periodically check expired cross checks
crossTicker
=
time
.
NewTicker
(
crossCheckCycle
)
// ticker to periodically check expired cross checks
)
)
defer
crossTicker
.
Stop
()
defer
crossTicker
.
Stop
()
...
@@ -285,7 +286,7 @@ func (d *Downloader) fetchHashes(p *peer, h common.Hash) error {
...
@@ -285,7 +286,7 @@ func (d *Downloader) fetchHashes(p *peer, h common.Hash) error {
cross
:=
inserts
[
rand
.
Intn
(
len
(
inserts
))]
cross
:=
inserts
[
rand
.
Intn
(
len
(
inserts
))]
glog
.
V
(
logger
.
Detail
)
.
Infof
(
"Cross checking (%s) with %x"
,
active
.
id
,
cross
)
glog
.
V
(
logger
.
Detail
)
.
Infof
(
"Cross checking (%s) with %x"
,
active
.
id
,
cross
)
crossC
hecks
[
cross
]
=
time
.
Now
()
.
Add
(
blockTTL
)
d
.
c
hecks
[
cross
]
=
time
.
Now
()
.
Add
(
blockTTL
)
active
.
getBlocks
([]
common
.
Hash
{
cross
})
active
.
getBlocks
([]
common
.
Hash
{
cross
})
// Also fetch a fresh
// Also fetch a fresh
...
@@ -306,11 +307,11 @@ func (d *Downloader) fetchHashes(p *peer, h common.Hash) error {
...
@@ -306,11 +307,11 @@ func (d *Downloader) fetchHashes(p *peer, h common.Hash) error {
continue
continue
}
}
hash
:=
blockPack
.
blocks
[
0
]
.
Hash
()
hash
:=
blockPack
.
blocks
[
0
]
.
Hash
()
delete
(
crossC
hecks
,
hash
)
delete
(
d
.
c
hecks
,
hash
)
case
<-
crossTicker
.
C
:
case
<-
crossTicker
.
C
:
// Iterate over all the cross checks and fail the hash chain if they're not verified
// Iterate over all the cross checks and fail the hash chain if they're not verified
for
hash
,
deadline
:=
range
crossC
hecks
{
for
hash
,
deadline
:=
range
d
.
c
hecks
{
if
time
.
Now
()
.
After
(
deadline
)
{
if
time
.
Now
()
.
After
(
deadline
)
{
glog
.
V
(
logger
.
Debug
)
.
Infof
(
"Cross check timeout for %x"
,
hash
)
glog
.
V
(
logger
.
Debug
)
.
Infof
(
"Cross check timeout for %x"
,
hash
)
return
ErrCrossCheckFailed
return
ErrCrossCheckFailed
...
@@ -362,7 +363,16 @@ out:
...
@@ -362,7 +363,16 @@ out:
select
{
select
{
case
<-
d
.
cancelCh
:
case
<-
d
.
cancelCh
:
return
errCancelBlockFetch
return
errCancelBlockFetch
case
blockPack
:=
<-
d
.
blockCh
:
case
blockPack
:=
<-
d
.
blockCh
:
// Short circuit if it's a stale cross check
if
len
(
blockPack
.
blocks
)
==
1
{
block
:=
blockPack
.
blocks
[
0
]
if
_
,
ok
:=
d
.
checks
[
block
.
Hash
()];
ok
{
delete
(
d
.
checks
,
block
.
Hash
())
continue
}
}
// If the peer was previously banned and failed to deliver it's pack
// If the peer was previously banned and failed to deliver it's pack
// in a reasonable time frame, ignore it's message.
// in a reasonable time frame, ignore it's message.
if
peer
:=
d
.
peers
.
Peer
(
blockPack
.
peerId
);
peer
!=
nil
{
if
peer
:=
d
.
peers
.
Peer
(
blockPack
.
peerId
);
peer
!=
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