From 757641d9b817ae8b63fec684759b0815af9c4d0e Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Tue, 18 Sep 2018 17:58:39 +0100 Subject: [PATCH] Some logging and clear stalled blocks head --- ethcore/sync/src/block_sync.rs | 4 ++++ ethcore/sync/src/blocks.rs | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/ethcore/sync/src/block_sync.rs b/ethcore/sync/src/block_sync.rs index a51b192dbde..ad4b9dc7001 100644 --- a/ethcore/sync/src/block_sync.rs +++ b/ethcore/sync/src/block_sync.rs @@ -292,6 +292,10 @@ impl BlockDownloader { if !headers.is_empty() { // TODO: validate heads better. E.g. check that there is enough distance between blocks. trace_sync!(self, target: "sync", "Received {} subchain heads, proceeding to download", headers.len()); + match self.block_set { + BlockSet::NewBlocks => (), + BlockSet::OldBlocks => trace_sync!(self, target: "sync", "ChainHead: reset_to {:?}", hashes), + } self.blocks.reset_to(hashes); self.state = State::Blocks; return Ok(DownloadAction::Reset); diff --git a/ethcore/sync/src/blocks.rs b/ethcore/sync/src/blocks.rs index 3815084f8f1..0361098a181 100644 --- a/ethcore/sync/src/blocks.rs +++ b/ethcore/sync/src/blocks.rs @@ -387,6 +387,15 @@ impl BlockCollection { } trace!(target: "sync", "Drained {} blocks, new head :{:?}", drained.len(), self.head); + + // reset if head stuck, not downloading any block bodies or receipts + // for now a crude heuristic that may not cover all cases + // assumes that at least some bodies will be downloaded before all headers + // 256 = subchain heads length and 128 = subchain length. This limit could be an argument. + if drained.len() == 0 && self.blocks.len() > 128 * 256 { + info!(target: "sync", "Resetting blocks. Current head {:?}, blocks length {:?}, heads {:?}", self.head, self.blocks.len(), self.heads); + } + drained } @@ -569,6 +578,9 @@ impl BlockCollection { } } } + if self.need_receipts { + trace!(target: "sync", "update_heads: {:?}", new_heads); + } self.heads = new_heads; } }