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
55dd8fd6
Commit
55dd8fd6
authored
Jun 17, 2015
by
Péter Szilágyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
eth/downloader: always reenter processing if not exiting
parent
2f4cbe22
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
39 deletions
+37
-39
downloader.go
eth/downloader/downloader.go
+22
-23
downloader_test.go
eth/downloader/downloader_test.go
+15
-16
No files found.
eth/downloader/downloader.go
View file @
55dd8fd6
...
@@ -48,7 +48,6 @@ var (
...
@@ -48,7 +48,6 @@ var (
errCrossCheckFailed
=
errors
.
New
(
"block cross-check failed"
)
errCrossCheckFailed
=
errors
.
New
(
"block cross-check failed"
)
errCancelHashFetch
=
errors
.
New
(
"hash fetching canceled (requested)"
)
errCancelHashFetch
=
errors
.
New
(
"hash fetching canceled (requested)"
)
errCancelBlockFetch
=
errors
.
New
(
"block downloading canceled (requested)"
)
errCancelBlockFetch
=
errors
.
New
(
"block downloading canceled (requested)"
)
errCancelChainImport
=
errors
.
New
(
"chain importing canceled (requested)"
)
errNoSyncActive
=
errors
.
New
(
"no sync active"
)
errNoSyncActive
=
errors
.
New
(
"no sync active"
)
)
)
...
@@ -719,7 +718,7 @@ func (d *Downloader) banBlocks(peerId string, head common.Hash) error {
...
@@ -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
// 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
// attempt denied, so we need to re-enter to ensure the block isn't left
// to idle in the cache.
// 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
// Make sure only one goroutine is ever allowed to process blocks at once
if
!
atomic
.
CompareAndSwapInt32
(
&
d
.
processing
,
0
,
1
)
{
if
!
atomic
.
CompareAndSwapInt32
(
&
d
.
processing
,
0
,
1
)
{
return
return
...
@@ -729,8 +728,8 @@ func (d *Downloader) process() (err error) {
...
@@ -729,8 +728,8 @@ func (d *Downloader) process() (err error) {
// the fresh blocks might have been rejected entry to to this present thread
// the fresh blocks might have been rejected entry to to this present thread
// not yet releasing the `processing` state.
// not yet releasing the `processing` state.
defer
func
()
{
defer
func
()
{
if
err
==
nil
&&
d
.
queue
.
GetHeadBlock
()
!=
nil
{
if
atomic
.
LoadInt32
(
&
d
.
interrupt
)
==
0
&&
d
.
queue
.
GetHeadBlock
()
!=
nil
{
err
=
d
.
process
()
d
.
process
()
}
}
}()
}()
// Release the lock upon exit (note, before checking for reentry!), and set
// Release the lock upon exit (note, before checking for reentry!), and set
...
@@ -748,7 +747,7 @@ func (d *Downloader) process() (err error) {
...
@@ -748,7 +747,7 @@ func (d *Downloader) process() (err error) {
// Fetch the next batch of blocks
// Fetch the next batch of blocks
blocks
:=
d
.
queue
.
TakeBlocks
()
blocks
:=
d
.
queue
.
TakeBlocks
()
if
len
(
blocks
)
==
0
{
if
len
(
blocks
)
==
0
{
return
nil
return
}
}
// Reset the import statistics
// Reset the import statistics
d
.
importLock
.
Lock
()
d
.
importLock
.
Lock
()
...
@@ -762,7 +761,7 @@ func (d *Downloader) process() (err error) {
...
@@ -762,7 +761,7 @@ func (d *Downloader) process() (err error) {
for
len
(
blocks
)
!=
0
{
for
len
(
blocks
)
!=
0
{
// Check for any termination requests
// Check for any termination requests
if
atomic
.
LoadInt32
(
&
d
.
interrupt
)
==
1
{
if
atomic
.
LoadInt32
(
&
d
.
interrupt
)
==
1
{
return
errCancelChainImport
return
}
}
// Retrieve the first batch of blocks to insert
// Retrieve the first batch of blocks to insert
max
:=
int
(
math
.
Min
(
float64
(
len
(
blocks
)),
float64
(
maxBlockProcess
)))
max
:=
int
(
math
.
Min
(
float64
(
len
(
blocks
)),
float64
(
maxBlockProcess
)))
...
@@ -776,7 +775,7 @@ func (d *Downloader) process() (err error) {
...
@@ -776,7 +775,7 @@ func (d *Downloader) process() (err error) {
glog
.
V
(
logger
.
Debug
)
.
Infof
(
"Block #%d import failed: %v"
,
raw
[
index
]
.
NumberU64
(),
err
)
glog
.
V
(
logger
.
Debug
)
.
Infof
(
"Block #%d import failed: %v"
,
raw
[
index
]
.
NumberU64
(),
err
)
d
.
dropPeer
(
blocks
[
index
]
.
OriginPeer
)
d
.
dropPeer
(
blocks
[
index
]
.
OriginPeer
)
d
.
cancel
()
d
.
cancel
()
return
errCancelChainImport
return
}
}
blocks
=
blocks
[
max
:
]
blocks
=
blocks
[
max
:
]
}
}
...
...
eth/downloader/downloader_test.go
View file @
55dd8fd6
...
@@ -764,7 +764,6 @@ func TestHashAttackerDropping(t *testing.T) {
...
@@ -764,7 +764,6 @@ func TestHashAttackerDropping(t *testing.T) {
{
errCrossCheckFailed
,
true
},
// Hash-origin failed to pass a block cross check, 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
{
errCancelHashFetch
,
false
},
// Synchronisation was canceled, origin may be innocent, don't drop
{
errCancelBlockFetch
,
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
}
}
// Run the tests and check disconnection status
// Run the tests and check disconnection status
tester
:=
newTester
()
tester
:=
newTester
()
...
...
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