regtests last sync fixes

This commit is contained in:
Svyatoslav Nikolsky 2016-11-30 20:58:33 +03:00
parent 3711187000
commit 464a3b74a5
2 changed files with 18 additions and 19 deletions

View File

@ -11,8 +11,8 @@ use script::Script;
/// Constant optimized to create large differences in the seed for different values of `hash_functions_num`. /// Constant optimized to create large differences in the seed for different values of `hash_functions_num`.
const SEED_OFFSET: u32 = 0xFBA4C795; const SEED_OFFSET: u32 = 0xFBA4C795;
/// Max last blocks to store for given peer /// Max last blocks to store for given peer. TODO: how bitcoind deals with this?
pub const MAX_LAST_BLOCKS_TO_STORE: usize = 64; pub const MAX_LAST_BLOCKS_TO_STORE: usize = 2048;
/// Max last transactions to store for given peer /// Max last transactions to store for given peer
pub const MAX_LAST_TRANSACTIONS_TO_STORE: usize = 64; pub const MAX_LAST_TRANSACTIONS_TO_STORE: usize = 64;

View File

@ -245,25 +245,24 @@ impl SynchronizationServer {
// `getheaders` => `headers` // `getheaders` => `headers`
ServerTask::ServeGetHeaders(block_locator_hashes, hash_stop) => { ServerTask::ServeGetHeaders(block_locator_hashes, hash_stop) => {
let chain = chain.read(); let chain = chain.read();
if let Some(best_common_block) = SynchronizationServer::locate_known_block_header(&chain, &block_locator_hashes) {
trace!(target: "sync", "Best common block header with peer#{} is block#{}: {:?}", peer_index, best_common_block.number, best_common_block.hash.to_reversed_str());
// What if we have no common blocks with peer at all? Maybe drop connection or penalize peer? // TODO: if block_locator_hashes is empty => return hash_stop
// https://github.com/ethcore/parity-bitcoin/pull/91#discussion_r86734568 let blocks_headers = match SynchronizationServer::locate_known_block_header(&chain, &block_locator_hashes) {
let blocks_headers = SynchronizationServer::blocks_headers_after(&chain, &best_common_block, &hash_stop, 2000); Some(best_common_block) => {
if !blocks_headers.is_empty() { trace!(target: "sync", "Best common block header with peer#{} is block#{}: {:?}", peer_index, best_common_block.number, best_common_block.hash.to_reversed_str());
trace!(target: "sync", "Going to respond with blocks headers with {} items to peer#{}", blocks_headers.len(), peer_index);
executor.lock().execute(Task::SendHeaders(peer_index, blocks_headers, indexed_task.id)); // TODO: add test for this case
} else if let Some(response_id) = indexed_task.id.raw() { // we must respond with empty headers message even if we have no common blocks with this peer
executor.lock().execute(Task::Ignore(peer_index, response_id)); SynchronizationServer::blocks_headers_after(&chain, &best_common_block, &hash_stop, 2000)
},
None => {
trace!(target: "sync", "No common blocks headers with peer#{}", peer_index);
Vec::new()
} }
} };
else {
trace!(target: "sync", "No common blocks headers with peer#{}", peer_index); trace!(target: "sync", "Going to respond with blocks headers with {} items to peer#{}", blocks_headers.len(), peer_index);
if let Some(response_id) = indexed_task.id.raw() { executor.lock().execute(Task::SendHeaders(peer_index, blocks_headers, indexed_task.id));
executor.lock().execute(Task::Ignore(peer_index, response_id));
}
}
// inform that we have processed task for peer // inform that we have processed task for peer
queue.lock().task_processed(peer_index); queue.lock().task_processed(peer_index);
}, },