Skip to content
This repository was archived by the owner on Nov 6, 2020. It is now read-only.

Commit 5f38aa8

Browse files
committed
Log block set in block_sync for easier debugging
1 parent 6888a96 commit 5f38aa8

File tree

2 files changed

+26
-26
lines changed

2 files changed

+26
-26
lines changed

ethcore/sync/src/block_sync.rs

+23-23
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ use ethcore::client::{BlockStatus, BlockId, BlockImportError, BlockImportErrorKi
2828
use ethcore::error::{ImportErrorKind, QueueErrorKind, BlockError};
2929
use sync_io::SyncIo;
3030
use blocks::{BlockCollection, SyncBody, SyncHeader};
31+
use chain::BlockSet;
3132

3233
const MAX_HEADERS_TO_REQUEST: usize = 128;
3334
const MAX_BODIES_TO_REQUEST: usize = 32;
@@ -36,6 +37,17 @@ const SUBCHAIN_SIZE: u64 = 256;
3637
const MAX_ROUND_PARENTS: usize = 16;
3738
const MAX_PARALLEL_SUBCHAIN_DOWNLOAD: usize = 5;
3839

40+
macro_rules! trace_sync {
41+
($self:ident, target: $target:expr, $($arg:tt)*) => {
42+
trace!(target: $target, $($arg)+, $self.block_set);
43+
}
44+
}
45+
macro_rules! debug_sync {
46+
($self:ident, target: $target:expr, $($arg:tt)*) => {
47+
debug!(target: $target, $($arg)+, $self.block_set);
48+
}
49+
}
50+
3951
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
4052
/// Downloader state
4153
pub enum State {
@@ -89,6 +101,8 @@ impl From<rlp::DecoderError> for BlockDownloaderImportError {
89101
/// Block downloader strategy.
90102
/// Manages state and block data for a block download process.
91103
pub struct BlockDownloader {
104+
/// Which set of blocks to download
105+
block_set: BlockSet,
92106
/// Downloader state
93107
state: State,
94108
/// Highest block number seen
@@ -117,29 +131,15 @@ pub struct BlockDownloader {
117131
}
118132

119133
impl BlockDownloader {
120-
/// Create a new instance of syncing strategy. This won't reorganize to before the
121-
/// last kept state.
122-
pub fn new(sync_receipts: bool, start_hash: &H256, start_number: BlockNumber) -> Self {
123-
BlockDownloader {
124-
state: State::Idle,
125-
highest_block: None,
126-
last_imported_block: start_number,
127-
last_imported_hash: start_hash.clone(),
128-
last_round_start: start_number,
129-
last_round_start_hash: start_hash.clone(),
130-
blocks: BlockCollection::new(sync_receipts),
131-
imported_this_round: None,
132-
round_parents: VecDeque::new(),
133-
download_receipts: sync_receipts,
134-
target_hash: None,
135-
retract_step: 1,
136-
limit_reorg: true,
137-
}
138-
}
139-
140-
/// Create a new instance of sync with unlimited reorg allowed.
141-
pub fn with_unlimited_reorg(sync_receipts: bool, start_hash: &H256, start_number: BlockNumber) -> Self {
134+
/// Create a new instance of syncing strategy.
135+
/// For BlockSet::NewBlocks this won't reorganize to before the last kept state.
136+
pub fn new(block_set: BlockSet, start_hash: &H256, start_number: BlockNumber) -> Self {
137+
let (limit_reorg, sync_receipts) = match block_set {
138+
BlockSet::NewBlocks => (true, false),
139+
BlockSet::OldBlocks => (false, true)
140+
};
142141
BlockDownloader {
142+
block_set: block_set,
143143
state: State::Idle,
144144
highest_block: None,
145145
last_imported_block: start_number,
@@ -152,7 +152,7 @@ impl BlockDownloader {
152152
download_receipts: sync_receipts,
153153
target_hash: None,
154154
retract_step: 1,
155-
limit_reorg: false,
155+
limit_reorg: limit_reorg,
156156
}
157157
}
158158

ethcore/sync/src/chain/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ impl ChainSync {
429429
peers: HashMap::new(),
430430
handshaking_peers: HashMap::new(),
431431
active_peers: HashSet::new(),
432-
new_blocks: BlockDownloader::new(false, &chain_info.best_block_hash, chain_info.best_block_number),
432+
new_blocks: BlockDownloader::new(BlockSet::NewBlocks, &chain_info.best_block_hash, chain_info.best_block_number),
433433
old_blocks: None,
434434
last_sent_block_number: 0,
435435
network_id: config.network_id,
@@ -637,13 +637,13 @@ impl ChainSync {
637637
pub fn update_targets(&mut self, chain: &BlockChainClient) {
638638
// Do not assume that the block queue/chain still has our last_imported_block
639639
let chain = chain.chain_info();
640-
self.new_blocks = BlockDownloader::new(false, &chain.best_block_hash, chain.best_block_number);
640+
self.new_blocks = BlockDownloader::new(BlockSet::NewBlocks, &chain.best_block_hash, chain.best_block_number);
641641
self.old_blocks = None;
642642
if self.download_old_blocks {
643643
if let (Some(ancient_block_hash), Some(ancient_block_number)) = (chain.ancient_block_hash, chain.ancient_block_number) {
644644

645645
trace!(target: "sync", "Downloading old blocks from {:?} (#{}) till {:?} (#{:?})", ancient_block_hash, ancient_block_number, chain.first_block_hash, chain.first_block_number);
646-
let mut downloader = BlockDownloader::with_unlimited_reorg(true, &ancient_block_hash, ancient_block_number);
646+
let mut downloader = BlockDownloader::new(BlockSet::OldBlocks, &ancient_block_hash, ancient_block_number);
647647
if let Some(hash) = chain.first_block_hash {
648648
trace!(target: "sync", "Downloader target set to {:?}", hash);
649649
downloader.set_target(&hash);

0 commit comments

Comments
 (0)