Merge pull request #149 from ethcore/fix_121

Check that all blocks hashes are unknown before adding to `SCHEDULED_QUEUE`
This commit is contained in:
Svyatoslav Nikolsky 2016-11-21 09:22:51 +03:00 committed by GitHub
commit b3f2088198
1 changed files with 8 additions and 2 deletions

View File

@ -803,6 +803,13 @@ impl<T> SynchronizationClientCore<T> where T: TaskExecutor {
| HeadersIntersection::InMemoryForkNewBlocks(new_block_index)
| HeadersIntersection::DbForkNewBlocks(new_block_index)
| HeadersIntersection::NoKnownBlocks(new_block_index) => {
// check that we do not know all blocks in range [new_block_index..]
// if we know some block => there has been verification error => all headers should be ignored
// see when_previous_block_verification_failed_fork_is_not_requested for details
if hashes.iter().skip(new_block_index).any(|h| chain.block_state(h) != BlockState::Unknown) {
return;
}
// schedule new blocks
let new_blocks_hashes = hashes.split_off(new_block_index);
let new_blocks_headers = headers.split_off(new_block_index);
@ -1736,7 +1743,6 @@ pub mod tests {
}
#[test]
#[ignore] // TODO: causes panic currently
// https://github.com/ethcore/parity-bitcoin/issues/121
fn when_previous_block_verification_failed_fork_is_not_requested() {
// got headers [b10, b11, b12] - some fork
@ -1751,7 +1757,7 @@ pub mod tests {
//
// block queue is empty => new tasks => requesting [b21, b22] => panic in hash_queue
//
// TODO: do not trust first intersection point - check each hash when scheduling hashes.
// => do not trust first intersection point - check each hash when scheduling hashes.
// If at least one hash is known => previous verification failed => drop all headers.
let genesis = test_data::genesis();