regtests last sync fixes
This commit is contained in:
parent
3711187000
commit
464a3b74a5
|
@ -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;
|
||||||
|
|
||||||
|
|
|
@ -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) {
|
|
||||||
|
// TODO: if block_locator_hashes is empty => return hash_stop
|
||||||
|
let blocks_headers = match SynchronizationServer::locate_known_block_header(&chain, &block_locator_hashes) {
|
||||||
|
Some(best_common_block) => {
|
||||||
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", "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: add test for this case
|
||||||
// https://github.com/ethcore/parity-bitcoin/pull/91#discussion_r86734568
|
// we must respond with empty headers message even if we have no common blocks with this peer
|
||||||
let blocks_headers = SynchronizationServer::blocks_headers_after(&chain, &best_common_block, &hash_stop, 2000);
|
SynchronizationServer::blocks_headers_after(&chain, &best_common_block, &hash_stop, 2000)
|
||||||
if !blocks_headers.is_empty() {
|
},
|
||||||
|
None => {
|
||||||
|
trace!(target: "sync", "No common blocks headers with peer#{}", peer_index);
|
||||||
|
Vec::new()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
trace!(target: "sync", "Going to respond with blocks headers with {} items to peer#{}", blocks_headers.len(), peer_index);
|
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));
|
executor.lock().execute(Task::SendHeaders(peer_index, blocks_headers, indexed_task.id));
|
||||||
} else if let Some(response_id) = indexed_task.id.raw() {
|
|
||||||
executor.lock().execute(Task::Ignore(peer_index, response_id));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
trace!(target: "sync", "No common blocks headers with peer#{}", peer_index);
|
|
||||||
if let Some(response_id) = indexed_task.id.raw() {
|
|
||||||
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);
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue