@@ -241,7 +241,7 @@ impl BlockDownloader {
|
||||
self.last_round_start_hash = start_hash.clone();
|
||||
self.imported_this_round = None;
|
||||
self.round_parents = VecDeque::new();
|
||||
self.target_hash = None;
|
||||
//self.target_hash = None; // target_hash is only used for old (ancient) block download. And once set should not be reseted in any way.
|
||||
self.retract_step = 1;
|
||||
}
|
||||
|
||||
@@ -516,8 +516,24 @@ impl BlockDownloader {
|
||||
self.last_imported_hash
|
||||
);
|
||||
} else {
|
||||
let best = io.chain().chain_info().best_block_number;
|
||||
let best_hash = io.chain().chain_info().best_block_hash;
|
||||
let (best, best_hash) = match self.block_set {
|
||||
BlockSet::NewBlocks => (
|
||||
io.chain().chain_info().best_block_number,
|
||||
io.chain().chain_info().best_block_hash,
|
||||
),
|
||||
BlockSet::OldBlocks => {
|
||||
if let (Some(best), Some(best_hash)) = (
|
||||
io.chain().chain_info().ancient_block_number,
|
||||
io.chain().chain_info().ancient_block_hash,
|
||||
) {
|
||||
(best, best_hash) // best ancient block number and hash.
|
||||
} else {
|
||||
// None on ancient block/hash means that all ancient are already downloaded and stored in DB.
|
||||
self.state = State::Complete;
|
||||
return;
|
||||
}
|
||||
}
|
||||
};
|
||||
let oldest_reorg = io.chain().pruning_info().earliest_state;
|
||||
if self.block_set == BlockSet::NewBlocks && best > start && start < oldest_reorg
|
||||
{
|
||||
@@ -531,7 +547,7 @@ impl BlockDownloader {
|
||||
} else {
|
||||
let n = start - cmp::min(self.retract_step, start);
|
||||
if n == 0 {
|
||||
debug_sync!(self, "Header not found, bottom line reached, resetting, last imported: {}", self.last_imported_hash);
|
||||
info!("Header not found, bottom line reached, resetting, last imported: {}", self.last_imported_hash);
|
||||
self.reset_to_block(&best_hash, best);
|
||||
} else {
|
||||
self.retract_step *= 2;
|
||||
@@ -547,11 +563,9 @@ impl BlockDownloader {
|
||||
);
|
||||
}
|
||||
None => {
|
||||
debug_sync!(
|
||||
self,
|
||||
info!(
|
||||
"Could not revert to previous block, last: {} ({})",
|
||||
start,
|
||||
self.last_imported_hash
|
||||
start, self.last_imported_hash
|
||||
);
|
||||
self.reset_to_block(&best_hash, best);
|
||||
}
|
||||
@@ -661,7 +675,10 @@ impl BlockDownloader {
|
||||
|
||||
if self.target_hash.as_ref().map_or(false, |t| t == &h) {
|
||||
self.state = State::Complete;
|
||||
trace_sync!(self, "Sync target reached");
|
||||
info!(
|
||||
"Sync target {:?} for old blocks reached. Syncing ancient blocks finished.",
|
||||
self.target_hash
|
||||
);
|
||||
return download_action;
|
||||
}
|
||||
|
||||
|
||||
@@ -969,15 +969,17 @@ impl ChainSync {
|
||||
if let (Some(ancient_block_hash), Some(ancient_block_number)) =
|
||||
(chain.ancient_block_hash, chain.ancient_block_number)
|
||||
{
|
||||
trace!(target: "sync", "Downloading old blocks from {:?} (#{}) till {:?} (#{:?})", ancient_block_hash, ancient_block_number, chain.first_block_hash, chain.first_block_number);
|
||||
info!(target: "sync", "Downloading old blocks from {:?} (#{}) till {:?} (#{:?})", ancient_block_hash, ancient_block_number, chain.first_block_hash, chain.first_block_number);
|
||||
let mut downloader = BlockDownloader::new(
|
||||
BlockSet::OldBlocks,
|
||||
&ancient_block_hash,
|
||||
ancient_block_number,
|
||||
);
|
||||
if let Some(hash) = chain.first_block_hash {
|
||||
trace!(target: "sync", "Downloader target set to {:?}", hash);
|
||||
trace!(target: "sync", "Downloader target for old blocks is set to {:?}", hash);
|
||||
downloader.set_target(&hash);
|
||||
} else {
|
||||
trace!(target: "sync", "Downloader target could not be found");
|
||||
}
|
||||
self.old_blocks = Some(downloader);
|
||||
}
|
||||
@@ -1114,10 +1116,18 @@ impl ChainSync {
|
||||
let equal_or_higher_difficulty = peer_difficulty.map_or(true, |pd| pd >= syncing_difficulty);
|
||||
|
||||
if force || equal_or_higher_difficulty {
|
||||
if let Some(request) = self.old_blocks.as_mut().and_then(|d| d.request_blocks(peer_id, io, num_active_peers)) {
|
||||
SyncRequester::request_blocks(self, io, peer_id, request, BlockSet::OldBlocks);
|
||||
return;
|
||||
}
|
||||
let mut is_complete = false;
|
||||
if let Some(old_blocks) = self.old_blocks.as_mut() {
|
||||
if let Some(request) = old_blocks.request_blocks(peer_id, io, num_active_peers) {
|
||||
SyncRequester::request_blocks(self, io, peer_id, request, BlockSet::OldBlocks);
|
||||
return;
|
||||
}
|
||||
is_complete = old_blocks.is_complete();
|
||||
|
||||
}
|
||||
if is_complete { // if old_blocks is in complete state, set it to None.
|
||||
self.old_blocks = None;
|
||||
}
|
||||
} else {
|
||||
trace!(
|
||||
target: "sync",
|
||||
@@ -1344,7 +1354,7 @@ impl ChainSync {
|
||||
},
|
||||
SyncState::SnapshotWaiting => match io.snapshot_service().restoration_status() {
|
||||
RestorationStatus::Inactive => {
|
||||
trace!(target:"sync", "Snapshot restoration is complete");
|
||||
info!(target:"sync", "Snapshot restoration is complete");
|
||||
self.restart(io);
|
||||
}
|
||||
RestorationStatus::Initializing { .. } => {
|
||||
@@ -1443,7 +1453,7 @@ impl ChainSync {
|
||||
SyncPropagator::propagate_proposed_blocks(self, io, proposed);
|
||||
}
|
||||
if !invalid.is_empty() {
|
||||
trace!(target: "sync", "Bad blocks in the queue, restarting");
|
||||
info!(target: "sync", "Bad blocks in the queue, restarting sync");
|
||||
self.restart(io);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user