eth/downloader: test registration rejection on head ban

This commit is contained in:
Péter Szilágyi 2015-06-08 15:02:52 +03:00
parent c4f224932f
commit 4ed3509a02
1 changed files with 10 additions and 2 deletions

View File

@ -169,8 +169,9 @@ func (dl *downloadTester) getBlocks(id string) func([]common.Hash) error {
}
}
func (dl *downloadTester) newPeer(id string, td *big.Int, hash common.Hash) {
dl.downloader.RegisterPeer(id, hash, dl.getHashes, dl.getBlocks(id))
// newPeer registers a new block download source into the syncer.
func (dl *downloadTester) newPeer(id string, td *big.Int, hash common.Hash) error {
return dl.downloader.RegisterPeer(id, hash, dl.getHashes, dl.getBlocks(id))
}
// Tests that simple synchronization, without throttling from a good peer works.
@ -559,6 +560,13 @@ func TestBannedChainStarvationAttack(t *testing.T) {
}
banned = bans
}
// Check that after banning an entire chain, bad peers get dropped
if err := tester.newPeer("new attacker", big.NewInt(10000), hashes[0]); err != errBannedHead {
t.Fatalf("peer registration mismatch: have %v, want %v", err, errBannedHead)
}
if peer := tester.downloader.peers.Peer("net attacker"); peer != nil {
t.Fatalf("banned attacker registered: %v", peer)
}
}
// Tests that if a peer sends excessively many/large invalid chains that are