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
366e9627
Commit
366e9627
authored
May 14, 2015
by
Péter Szilágyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
eth/downloader: add a test for detecting missing blocks
parent
cd2fb090
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
8 deletions
+24
-8
downloader.go
eth/downloader/downloader.go
+1
-3
downloader_test.go
eth/downloader/downloader_test.go
+23
-5
No files found.
eth/downloader/downloader.go
View file @
366e9627
...
@@ -2,7 +2,6 @@ package downloader
...
@@ -2,7 +2,6 @@ package downloader
import
(
import
(
"errors"
"errors"
"fmt"
"sync"
"sync"
"sync/atomic"
"sync/atomic"
"time"
"time"
...
@@ -398,8 +397,7 @@ out:
...
@@ -398,8 +397,7 @@ out:
// and all failed throw an error
// and all failed throw an error
if
d
.
queue
.
InFlight
()
==
0
{
if
d
.
queue
.
InFlight
()
==
0
{
d
.
queue
.
Reset
()
d
.
queue
.
Reset
()
return
errPeersUnavailable
return
fmt
.
Errorf
(
"%v peers available = %d. total peers = %d. hashes needed = %d"
,
errPeersUnavailable
,
len
(
idlePeers
),
d
.
peers
.
Len
(),
d
.
queue
.
Pending
())
}
}
}
else
if
d
.
queue
.
InFlight
()
==
0
{
}
else
if
d
.
queue
.
InFlight
()
==
0
{
...
...
eth/downloader/downloader_test.go
View file @
366e9627
...
@@ -106,11 +106,12 @@ func (dl *downloadTester) getHashes(hash common.Hash) error {
...
@@ -106,11 +106,12 @@ func (dl *downloadTester) getHashes(hash common.Hash) error {
func
(
dl
*
downloadTester
)
getBlocks
(
id
string
)
func
([]
common
.
Hash
)
error
{
func
(
dl
*
downloadTester
)
getBlocks
(
id
string
)
func
([]
common
.
Hash
)
error
{
return
func
(
hashes
[]
common
.
Hash
)
error
{
return
func
(
hashes
[]
common
.
Hash
)
error
{
blocks
:=
make
([]
*
types
.
Block
,
len
(
hashes
))
blocks
:=
make
([]
*
types
.
Block
,
0
,
len
(
hashes
))
for
i
,
hash
:=
range
hashes
{
for
_
,
hash
:=
range
hashes
{
blocks
[
i
]
=
dl
.
blocks
[
hash
]
if
block
,
ok
:=
dl
.
blocks
[
hash
];
ok
{
blocks
=
append
(
blocks
,
block
)
}
}
}
go
dl
.
downloader
.
DeliverBlocks
(
id
,
blocks
)
go
dl
.
downloader
.
DeliverBlocks
(
id
,
blocks
)
return
nil
return
nil
...
@@ -341,7 +342,7 @@ func TestNonExistingParentAttack(t *testing.T) {
...
@@ -341,7 +342,7 @@ func TestNonExistingParentAttack(t *testing.T) {
// loop indefinitely.
// loop indefinitely.
func
TestRepeatingHashAttack
(
t
*
testing
.
T
)
{
func
TestRepeatingHashAttack
(
t
*
testing
.
T
)
{
// Create a valid chain, but drop the last link
// Create a valid chain, but drop the last link
hashes
:=
createHashes
(
1000
,
1
)
hashes
:=
createHashes
(
0
,
1000
)
blocks
:=
createBlocksFromHashes
(
hashes
)
blocks
:=
createBlocksFromHashes
(
hashes
)
hashes
=
hashes
[
:
len
(
hashes
)
-
1
]
hashes
=
hashes
[
:
len
(
hashes
)
-
1
]
...
@@ -365,3 +366,20 @@ func TestRepeatingHashAttack(t *testing.T) {
...
@@ -365,3 +366,20 @@ func TestRepeatingHashAttack(t *testing.T) {
}
}
}
}
}
}
// Tests that if a malicious peers returns a non-existent block hash, it should
// eventually time out and the sync reattempted.
func
TestNonExistingBlockAttack
(
t
*
testing
.
T
)
{
// Create a valid chain, but forge the last link
hashes
:=
createHashes
(
0
,
10
)
blocks
:=
createBlocksFromHashes
(
hashes
)
hashes
[
len
(
hashes
)
/
2
]
=
unknownHash
// Try and sync with the malicious node and check that it fails
tester
:=
newTester
(
t
,
hashes
,
blocks
)
tester
.
newPeer
(
"attack"
,
big
.
NewInt
(
10000
),
hashes
[
0
])
if
err
:=
tester
.
sync
(
"attack"
,
hashes
[
0
]);
err
!=
errPeersUnavailable
{
t
.
Fatalf
(
"synchronisation error mismatch: have %v, want %v"
,
err
,
errPeersUnavailable
)
}
}
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