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
bcc29801
Commit
bcc29801
authored
May 14, 2015
by
Péter Szilágyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
eth/downloader: check sync after failed attacks
parent
366e9627
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
7 deletions
+23
-7
downloader.go
eth/downloader/downloader.go
+5
-1
downloader_test.go
eth/downloader/downloader_test.go
+18
-6
No files found.
eth/downloader/downloader.go
View file @
bcc29801
...
@@ -268,8 +268,12 @@ out:
...
@@ -268,8 +268,12 @@ out:
// Insert all the new hashes, but only continue if got something useful
// Insert all the new hashes, but only continue if got something useful
inserts
:=
d
.
queue
.
Insert
(
hashPack
.
hashes
)
inserts
:=
d
.
queue
.
Insert
(
hashPack
.
hashes
)
if
inserts
==
0
&&
!
done
{
if
inserts
==
0
&&
!
done
{
glog
.
V
(
logger
.
Debug
)
.
Infof
(
"Peer (%s) responded with stale hashes
\n
"
,
activePeer
.
id
)
d
.
queue
.
Reset
()
return
ErrBadPeer
return
ErrBadPeer
}
else
if
!
done
{
}
if
!
done
{
activePeer
.
getHashes
(
hash
)
activePeer
.
getHashes
(
hash
)
continue
continue
}
}
...
...
eth/downloader/downloader_test.go
View file @
bcc29801
...
@@ -342,14 +342,13 @@ func TestNonExistingParentAttack(t *testing.T) {
...
@@ -342,14 +342,13 @@ 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
(
0
,
1000
)
hashes
:=
createHashes
(
0
,
blockCacheLimit
)
blocks
:=
createBlocksFromHashes
(
hashes
)
blocks
:=
createBlocksFromHashes
(
hashes
)
forged
:=
hashes
[
:
len
(
hashes
)
-
1
]
hashes
=
hashes
[
:
len
(
hashes
)
-
1
]
// Try and sync with the malicious node
// Try and sync with the malicious node
tester
:=
newTester
(
t
,
hashes
,
blocks
)
tester
:=
newTester
(
t
,
forged
,
blocks
)
tester
.
newPeer
(
"attack"
,
big
.
NewInt
(
10000
),
hashes
[
0
])
tester
.
newPeer
(
"attack"
,
big
.
NewInt
(
10000
),
forged
[
0
])
errc
:=
make
(
chan
error
)
errc
:=
make
(
chan
error
)
go
func
()
{
go
func
()
{
...
@@ -365,14 +364,21 @@ func TestRepeatingHashAttack(t *testing.T) {
...
@@ -365,14 +364,21 @@ func TestRepeatingHashAttack(t *testing.T) {
t
.
Fatalf
(
"synchronisation succeeded"
)
t
.
Fatalf
(
"synchronisation succeeded"
)
}
}
}
}
// Ensure that a valid chain can still pass sync
tester
.
hashes
=
hashes
tester
.
newPeer
(
"valid"
,
big
.
NewInt
(
20000
),
hashes
[
0
])
if
err
:=
tester
.
sync
(
"valid"
,
hashes
[
0
]);
err
!=
nil
{
t
.
Fatalf
(
"failed to synchronise blocks: %v"
,
err
)
}
}
}
// Tests that if a malicious peers returns a non-existent block hash, it should
// Tests that if a malicious peers returns a non-existent block hash, it should
// eventually time out and the sync reattempted.
// eventually time out and the sync reattempted.
func
TestNonExistingBlockAttack
(
t
*
testing
.
T
)
{
func
TestNonExistingBlockAttack
(
t
*
testing
.
T
)
{
// Create a valid chain, but forge the last link
// Create a valid chain, but forge the last link
hashes
:=
createHashes
(
0
,
10
)
hashes
:=
createHashes
(
0
,
blockCacheLimit
)
blocks
:=
createBlocksFromHashes
(
hashes
)
blocks
:=
createBlocksFromHashes
(
hashes
)
origin
:=
hashes
[
len
(
hashes
)
/
2
]
hashes
[
len
(
hashes
)
/
2
]
=
unknownHash
hashes
[
len
(
hashes
)
/
2
]
=
unknownHash
...
@@ -382,4 +388,10 @@ func TestNonExistingBlockAttack(t *testing.T) {
...
@@ -382,4 +388,10 @@ func TestNonExistingBlockAttack(t *testing.T) {
if
err
:=
tester
.
sync
(
"attack"
,
hashes
[
0
]);
err
!=
errPeersUnavailable
{
if
err
:=
tester
.
sync
(
"attack"
,
hashes
[
0
]);
err
!=
errPeersUnavailable
{
t
.
Fatalf
(
"synchronisation error mismatch: have %v, want %v"
,
err
,
errPeersUnavailable
)
t
.
Fatalf
(
"synchronisation error mismatch: have %v, want %v"
,
err
,
errPeersUnavailable
)
}
}
// Ensure that a valid chain can still pass sync
hashes
[
len
(
hashes
)
/
2
]
=
origin
tester
.
newPeer
(
"valid"
,
big
.
NewInt
(
20000
),
hashes
[
0
])
if
err
:=
tester
.
sync
(
"valid"
,
hashes
[
0
]);
err
!=
nil
{
t
.
Fatalf
(
"failed to synchronise blocks: %v"
,
err
)
}
}
}
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