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
3eda70c6
Commit
3eda70c6
authored
May 14, 2015
by
Péter Szilágyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
eth, eth/downloader: remove parent verification from the downlaoder
parent
a4246c2d
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
17 additions
and
46 deletions
+17
-46
downloader.go
eth/downloader/downloader.go
+2
-12
downloader_test.go
eth/downloader/downloader_test.go
+9
-17
queue.go
eth/downloader/queue.go
+2
-8
sync.go
eth/sync.go
+4
-9
No files found.
eth/downloader/downloader.go
View file @
3eda70c6
...
@@ -144,18 +144,8 @@ func (d *Downloader) Synchronise(id string, hash common.Hash) error {
...
@@ -144,18 +144,8 @@ func (d *Downloader) Synchronise(id string, hash common.Hash) error {
}
}
// TakeBlocks takes blocks from the queue and yields them to the caller.
// TakeBlocks takes blocks from the queue and yields them to the caller.
func
(
d
*
Downloader
)
TakeBlocks
()
(
types
.
Blocks
,
error
)
{
func
(
d
*
Downloader
)
TakeBlocks
()
types
.
Blocks
{
// If the head block is missing, no blocks are ready
return
d
.
queue
.
TakeBlocks
()
head
:=
d
.
queue
.
GetHeadBlock
()
if
head
==
nil
{
return
nil
,
nil
}
// If the parent hash of the head is unknown, notify the caller
if
!
d
.
hasBlock
(
head
.
ParentHash
())
{
return
nil
,
ErrUnknownParent
}
// Otherwise retrieve a full batch of blocks
return
d
.
queue
.
TakeBlocks
(
head
),
nil
}
}
func
(
d
*
Downloader
)
Has
(
hash
common
.
Hash
)
bool
{
func
(
d
*
Downloader
)
Has
(
hash
common
.
Hash
)
bool
{
...
...
eth/downloader/downloader_test.go
View file @
3eda70c6
...
@@ -197,10 +197,7 @@ func TestTaking(t *testing.T) {
...
@@ -197,10 +197,7 @@ func TestTaking(t *testing.T) {
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Error
(
"download error"
,
err
)
t
.
Error
(
"download error"
,
err
)
}
}
bs
,
err
:=
tester
.
downloader
.
TakeBlocks
()
bs
:=
tester
.
downloader
.
TakeBlocks
()
if
err
!=
nil
{
t
.
Fatalf
(
"failed to take blocks: %v"
,
err
)
}
if
len
(
bs
)
!=
targetBlocks
{
if
len
(
bs
)
!=
targetBlocks
{
t
.
Error
(
"retrieved block mismatch: have %v, want %v"
,
len
(
bs
),
targetBlocks
)
t
.
Error
(
"retrieved block mismatch: have %v, want %v"
,
len
(
bs
),
targetBlocks
)
}
}
...
@@ -280,8 +277,7 @@ func TestThrottling(t *testing.T) {
...
@@ -280,8 +277,7 @@ func TestThrottling(t *testing.T) {
time
.
Sleep
(
time
.
Millisecond
)
time
.
Sleep
(
time
.
Millisecond
)
}
}
// Take a batch of blocks and accumulate
// Take a batch of blocks and accumulate
blocks
,
_
:=
tester
.
downloader
.
TakeBlocks
()
took
=
append
(
took
,
tester
.
downloader
.
TakeBlocks
()
...
)
took
=
append
(
took
,
blocks
...
)
}
}
done
<-
struct
{}{}
done
<-
struct
{}{}
}()
}()
...
@@ -315,14 +311,13 @@ func TestNonExistingParentAttack(t *testing.T) {
...
@@ -315,14 +311,13 @@ func TestNonExistingParentAttack(t *testing.T) {
if
err
:=
tester
.
sync
(
"attack"
,
hashes
[
0
]);
err
!=
nil
{
if
err
:=
tester
.
sync
(
"attack"
,
hashes
[
0
]);
err
!=
nil
{
t
.
Fatalf
(
"failed to synchronise blocks: %v"
,
err
)
t
.
Fatalf
(
"failed to synchronise blocks: %v"
,
err
)
}
}
bs
,
err
:=
tester
.
downloader
.
TakeBlocks
()
bs
:=
tester
.
downloader
.
TakeBlocks
()
if
err
!=
ErrUnknownParent
{
if
len
(
bs
)
!=
1
{
t
.
Fatalf
(
"
take error mismatch: have %v, want %v"
,
err
,
ErrUnknownParent
)
t
.
Fatalf
(
"
retrieved block mismatch: have %v, want %v"
,
len
(
bs
),
1
)
}
}
if
len
(
bs
)
!=
0
{
if
tester
.
hasBlock
(
bs
[
0
]
.
ParentHash
())
{
t
.
Error
(
"retrieved block mismatch: have %v, want %v"
,
len
(
bs
),
0
)
t
.
Fatalf
(
"tester knows about the unknown hash"
)
}
}
// Cancel the download due to the parent attack
tester
.
downloader
.
Cancel
()
tester
.
downloader
.
Cancel
()
// Reconstruct a valid chain, and try to synchronize with it
// Reconstruct a valid chain, and try to synchronize with it
...
@@ -331,11 +326,8 @@ func TestNonExistingParentAttack(t *testing.T) {
...
@@ -331,11 +326,8 @@ func TestNonExistingParentAttack(t *testing.T) {
if
err
:=
tester
.
sync
(
"valid"
,
hashes
[
0
]);
err
!=
nil
{
if
err
:=
tester
.
sync
(
"valid"
,
hashes
[
0
]);
err
!=
nil
{
t
.
Fatalf
(
"failed to synchronise blocks: %v"
,
err
)
t
.
Fatalf
(
"failed to synchronise blocks: %v"
,
err
)
}
}
bs
,
err
=
tester
.
downloader
.
TakeBlocks
()
bs
=
tester
.
downloader
.
TakeBlocks
()
if
err
!=
nil
{
t
.
Fatalf
(
"failed to retrieve blocks: %v"
,
err
)
}
if
len
(
bs
)
!=
1
{
if
len
(
bs
)
!=
1
{
t
.
Error
(
"retrieved block mismatch: have %v, want %v"
,
len
(
bs
),
1
)
t
.
Fatalf
(
"retrieved block mismatch: have %v, want %v"
,
len
(
bs
),
1
)
}
}
}
}
eth/downloader/queue.go
View file @
3eda70c6
...
@@ -172,17 +172,11 @@ func (q *queue) GetBlock(hash common.Hash) *types.Block {
...
@@ -172,17 +172,11 @@ func (q *queue) GetBlock(hash common.Hash) *types.Block {
}
}
// TakeBlocks retrieves and permanently removes a batch of blocks from the cache.
// TakeBlocks retrieves and permanently removes a batch of blocks from the cache.
// The head parameter is required to prevent a race condition where concurrent
func
(
q
*
queue
)
TakeBlocks
()
types
.
Blocks
{
// takes may fail parent verifications.
func
(
q
*
queue
)
TakeBlocks
(
head
*
types
.
Block
)
types
.
Blocks
{
q
.
lock
.
Lock
()
q
.
lock
.
Lock
()
defer
q
.
lock
.
Unlock
()
defer
q
.
lock
.
Unlock
()
// Short circuit if the head block's different
// Accumulate all available blocks
if
len
(
q
.
blockCache
)
==
0
||
q
.
blockCache
[
0
]
!=
head
{
return
nil
}
// Otherwise accumulate all available blocks
var
blocks
types
.
Blocks
var
blocks
types
.
Blocks
for
_
,
block
:=
range
q
.
blockCache
{
for
_
,
block
:=
range
q
.
blockCache
{
if
block
==
nil
{
if
block
==
nil
{
...
...
eth/sync.go
View file @
3eda70c6
...
@@ -40,9 +40,7 @@ func (pm *ProtocolManager) update() {
...
@@ -40,9 +40,7 @@ func (pm *ProtocolManager) update() {
// Try to pull some blocks from the downloaded
// Try to pull some blocks from the downloaded
if
atomic
.
CompareAndSwapInt32
(
&
blockProcPend
,
0
,
1
)
{
if
atomic
.
CompareAndSwapInt32
(
&
blockProcPend
,
0
,
1
)
{
go
func
()
{
go
func
()
{
if
err
:=
pm
.
processBlocks
();
err
!=
nil
{
pm
.
processBlocks
()
pm
.
downloader
.
Cancel
()
}
atomic
.
StoreInt32
(
&
blockProcPend
,
0
)
atomic
.
StoreInt32
(
&
blockProcPend
,
0
)
}()
}()
}
}
...
@@ -61,12 +59,8 @@ func (pm *ProtocolManager) processBlocks() error {
...
@@ -61,12 +59,8 @@ func (pm *ProtocolManager) processBlocks() error {
pm
.
wg
.
Add
(
1
)
pm
.
wg
.
Add
(
1
)
defer
pm
.
wg
.
Done
()
defer
pm
.
wg
.
Done
()
// Take a batch of blocks, but abort if there's an invalid head or if the chain's empty
// Short circuit if no blocks are available for insertion
blocks
,
err
:=
pm
.
downloader
.
TakeBlocks
()
blocks
:=
pm
.
downloader
.
TakeBlocks
()
if
err
!=
nil
{
glog
.
V
(
logger
.
Warn
)
.
Infof
(
"Block processing failed: %v"
,
err
)
return
err
}
if
len
(
blocks
)
==
0
{
if
len
(
blocks
)
==
0
{
return
nil
return
nil
}
}
...
@@ -77,6 +71,7 @@ func (pm *ProtocolManager) processBlocks() error {
...
@@ -77,6 +71,7 @@ func (pm *ProtocolManager) processBlocks() error {
_
,
err
:=
pm
.
chainman
.
InsertChain
(
blocks
[
:
max
])
_
,
err
:=
pm
.
chainman
.
InsertChain
(
blocks
[
:
max
])
if
err
!=
nil
{
if
err
!=
nil
{
glog
.
V
(
logger
.
Warn
)
.
Infof
(
"Block insertion failed: %v"
,
err
)
glog
.
V
(
logger
.
Warn
)
.
Infof
(
"Block insertion failed: %v"
,
err
)
pm
.
downloader
.
Cancel
()
return
err
return
err
}
}
blocks
=
blocks
[
max
:
]
blocks
=
blocks
[
max
:
]
...
...
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