good morning!!!!
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
bor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open
bor
Commits
55dd8fd6
Commit
55dd8fd6
authored
9 years ago
by
Péter Szilágyi
Browse files
Options
Downloads
Patches
Plain Diff
eth/downloader: always reenter processing if not exiting
parent
2f4cbe22
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
eth/downloader/downloader.go
+22
-23
22 additions, 23 deletions
eth/downloader/downloader.go
eth/downloader/downloader_test.go
+15
-16
15 additions, 16 deletions
eth/downloader/downloader_test.go
with
37 additions
and
39 deletions
eth/downloader/downloader.go
+
22
−
23
View file @
55dd8fd6
...
...
@@ -33,23 +33,22 @@ var (
)
var
(
errBusy
=
errors
.
New
(
"busy"
)
errUnknownPeer
=
errors
.
New
(
"peer is unknown or unhealthy"
)
errBadPeer
=
errors
.
New
(
"action from bad peer ignored"
)
errStallingPeer
=
errors
.
New
(
"peer is stalling"
)
errBannedHead
=
errors
.
New
(
"peer head hash already banned"
)
errNoPeers
=
errors
.
New
(
"no peers to keep download active"
)
errPendingQueue
=
errors
.
New
(
"pending items in queue"
)
errTimeout
=
errors
.
New
(
"timeout"
)
errEmptyHashSet
=
errors
.
New
(
"empty hash set by peer"
)
errPeersUnavailable
=
errors
.
New
(
"no peers available or all peers tried for block download process"
)
errAlreadyInPool
=
errors
.
New
(
"hash already in pool"
)
errInvalidChain
=
errors
.
New
(
"retrieved hash chain is invalid"
)
errCrossCheckFailed
=
errors
.
New
(
"block cross-check failed"
)
errCancelHashFetch
=
errors
.
New
(
"hash fetching canceled (requested)"
)
errCancelBlockFetch
=
errors
.
New
(
"block downloading canceled (requested)"
)
errCancelChainImport
=
errors
.
New
(
"chain importing canceled (requested)"
)
errNoSyncActive
=
errors
.
New
(
"no sync active"
)
errBusy
=
errors
.
New
(
"busy"
)
errUnknownPeer
=
errors
.
New
(
"peer is unknown or unhealthy"
)
errBadPeer
=
errors
.
New
(
"action from bad peer ignored"
)
errStallingPeer
=
errors
.
New
(
"peer is stalling"
)
errBannedHead
=
errors
.
New
(
"peer head hash already banned"
)
errNoPeers
=
errors
.
New
(
"no peers to keep download active"
)
errPendingQueue
=
errors
.
New
(
"pending items in queue"
)
errTimeout
=
errors
.
New
(
"timeout"
)
errEmptyHashSet
=
errors
.
New
(
"empty hash set by peer"
)
errPeersUnavailable
=
errors
.
New
(
"no peers available or all peers tried for block download process"
)
errAlreadyInPool
=
errors
.
New
(
"hash already in pool"
)
errInvalidChain
=
errors
.
New
(
"retrieved hash chain is invalid"
)
errCrossCheckFailed
=
errors
.
New
(
"block cross-check failed"
)
errCancelHashFetch
=
errors
.
New
(
"hash fetching canceled (requested)"
)
errCancelBlockFetch
=
errors
.
New
(
"block downloading canceled (requested)"
)
errNoSyncActive
=
errors
.
New
(
"no sync active"
)
)
// hashCheckFn is a callback type for verifying a hash's presence in the local chain.
...
...
@@ -719,7 +718,7 @@ func (d *Downloader) banBlocks(peerId string, head common.Hash) error {
// between these state changes, a block may have arrived, but a processing
// attempt denied, so we need to re-enter to ensure the block isn't left
// to idle in the cache.
func
(
d
*
Downloader
)
process
()
(
err
error
)
{
func
(
d
*
Downloader
)
process
()
{
// Make sure only one goroutine is ever allowed to process blocks at once
if
!
atomic
.
CompareAndSwapInt32
(
&
d
.
processing
,
0
,
1
)
{
return
...
...
@@ -729,8 +728,8 @@ func (d *Downloader) process() (err error) {
// the fresh blocks might have been rejected entry to to this present thread
// not yet releasing the `processing` state.
defer
func
()
{
if
err
==
nil
&&
d
.
queue
.
GetHeadBlock
()
!=
nil
{
err
=
d
.
process
()
if
atomic
.
LoadInt32
(
&
d
.
interrupt
)
==
0
&&
d
.
queue
.
GetHeadBlock
()
!=
nil
{
d
.
process
()
}
}()
// Release the lock upon exit (note, before checking for reentry!), and set
...
...
@@ -748,7 +747,7 @@ func (d *Downloader) process() (err error) {
// Fetch the next batch of blocks
blocks
:=
d
.
queue
.
TakeBlocks
()
if
len
(
blocks
)
==
0
{
return
nil
return
}
// Reset the import statistics
d
.
importLock
.
Lock
()
...
...
@@ -762,7 +761,7 @@ func (d *Downloader) process() (err error) {
for
len
(
blocks
)
!=
0
{
// Check for any termination requests
if
atomic
.
LoadInt32
(
&
d
.
interrupt
)
==
1
{
return
errCancelChainImport
return
}
// Retrieve the first batch of blocks to insert
max
:=
int
(
math
.
Min
(
float64
(
len
(
blocks
)),
float64
(
maxBlockProcess
)))
...
...
@@ -776,7 +775,7 @@ func (d *Downloader) process() (err error) {
glog
.
V
(
logger
.
Debug
)
.
Infof
(
"Block #%d import failed: %v"
,
raw
[
index
]
.
NumberU64
(),
err
)
d
.
dropPeer
(
blocks
[
index
]
.
OriginPeer
)
d
.
cancel
()
return
errCancelChainImport
return
}
blocks
=
blocks
[
max
:
]
}
...
...
This diff is collapsed.
Click to expand it.
eth/downloader/downloader_test.go
+
15
−
16
View file @
55dd8fd6
...
...
@@ -749,22 +749,21 @@ func TestHashAttackerDropping(t *testing.T) {
result
error
drop
bool
}{
{
nil
,
false
},
// Sync succeeded, all is well
{
errBusy
,
false
},
// Sync is already in progress, no problem
{
errUnknownPeer
,
false
},
// Peer is unknown, was already dropped, don't double drop
{
errBadPeer
,
true
},
// Peer was deemed bad for some reason, drop it
{
errStallingPeer
,
true
},
// Peer was detected to be stalling, drop it
{
errBannedHead
,
true
},
// Peer's head hash is a known bad hash, drop it
{
errNoPeers
,
false
},
// No peers to download from, soft race, no issue
{
errPendingQueue
,
false
},
// There are blocks still cached, wait to exhaust, no issue
{
errTimeout
,
true
},
// No hashes received in due time, drop the peer
{
errEmptyHashSet
,
true
},
// No hashes were returned as a response, drop as it's a dead end
{
errPeersUnavailable
,
true
},
// Nobody had the advertised blocks, drop the advertiser
{
errInvalidChain
,
true
},
// Hash chain was detected as invalid, definitely drop
{
errCrossCheckFailed
,
true
},
// Hash-origin failed to pass a block cross check, drop
{
errCancelHashFetch
,
false
},
// Synchronisation was canceled, origin may be innocent, don't drop
{
errCancelBlockFetch
,
false
},
// Synchronisation was canceled, origin may be innocent, don't drop
{
errCancelChainImport
,
false
},
// Synchronisation was canceled, origin may be innocent, don't drop
{
nil
,
false
},
// Sync succeeded, all is well
{
errBusy
,
false
},
// Sync is already in progress, no problem
{
errUnknownPeer
,
false
},
// Peer is unknown, was already dropped, don't double drop
{
errBadPeer
,
true
},
// Peer was deemed bad for some reason, drop it
{
errStallingPeer
,
true
},
// Peer was detected to be stalling, drop it
{
errBannedHead
,
true
},
// Peer's head hash is a known bad hash, drop it
{
errNoPeers
,
false
},
// No peers to download from, soft race, no issue
{
errPendingQueue
,
false
},
// There are blocks still cached, wait to exhaust, no issue
{
errTimeout
,
true
},
// No hashes received in due time, drop the peer
{
errEmptyHashSet
,
true
},
// No hashes were returned as a response, drop as it's a dead end
{
errPeersUnavailable
,
true
},
// Nobody had the advertised blocks, drop the advertiser
{
errInvalidChain
,
true
},
// Hash chain was detected as invalid, definitely drop
{
errCrossCheckFailed
,
true
},
// Hash-origin failed to pass a block cross check, drop
{
errCancelHashFetch
,
false
},
// Synchronisation was canceled, origin may be innocent, don't drop
{
errCancelBlockFetch
,
false
},
// Synchronisation was canceled, origin may be innocent, don't drop
}
// Run the tests and check disconnection status
tester
:=
newTester
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment