From d9f032edce4d7a99f52605c5a714bd9501b1fc4c Mon Sep 17 00:00:00 2001 From: Svyatoslav Nikolsky Date: Mon, 7 Nov 2016 12:31:11 +0300 Subject: [PATCH] fixed couple of issues from #91 --- sync/src/synchronization_server.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/sync/src/synchronization_server.rs b/sync/src/synchronization_server.rs index e9b5fc0c..10deee56 100644 --- a/sync/src/synchronization_server.rs +++ b/sync/src/synchronization_server.rs @@ -133,6 +133,8 @@ impl SynchronizationServer { }, // `getheaders` => `headers` (peer_index, ServerTask::ServeGetHeaders(best_block, hash_stop)) => { + // What if we have no common blocks with peer at all? Maybe drop connection or penalize peer? + // https://github.com/ethcore/parity-bitcoin/pull/91#discussion_r86734568 let blocks_hashes = SynchronizationServer::blocks_hashes_after(&chain, &best_block, &hash_stop, 2000); if !blocks_hashes.is_empty() { trace!(target: "sync", "Going to respond with blocks headers with {} items to peer#{}", blocks_hashes.len(), peer_index); @@ -167,9 +169,9 @@ impl SynchronizationServer { }, // `block` (peer_index, ServerTask::ReturnBlock(block_hash)) => { - if let Some(storage_block) = chain.read().storage().block(db::BlockRef::Hash(block_hash)) { - executor.lock().execute(Task::SendBlock(peer_index, storage_block)); - } + let block = chain.read().storage().block(db::BlockRef::Hash(block_hash)) + .expect("we have checked that block exists in ServeGetData; db is append-only; qed"); + executor.lock().execute(Task::SendBlock(peer_index, block)); }, }, // no tasks after wake-up => stopping