@@ -28,6 +28,7 @@ use ethcore::client::{BlockStatus, BlockId, BlockImportError, BlockImportErrorKi
28
28
use ethcore:: error:: { ImportErrorKind , QueueErrorKind , BlockError } ;
29
29
use sync_io:: SyncIo ;
30
30
use blocks:: { BlockCollection , SyncBody , SyncHeader } ;
31
+ use chain:: BlockSet ;
31
32
32
33
const MAX_HEADERS_TO_REQUEST : usize = 128 ;
33
34
const MAX_BODIES_TO_REQUEST : usize = 32 ;
@@ -36,6 +37,17 @@ const SUBCHAIN_SIZE: u64 = 256;
36
37
const MAX_ROUND_PARENTS : usize = 16 ;
37
38
const MAX_PARALLEL_SUBCHAIN_DOWNLOAD : usize = 5 ;
38
39
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
+
39
51
#[ derive( Copy , Clone , Eq , PartialEq , Debug ) ]
40
52
/// Downloader state
41
53
pub enum State {
@@ -89,6 +101,8 @@ impl From<rlp::DecoderError> for BlockDownloaderImportError {
89
101
/// Block downloader strategy.
90
102
/// Manages state and block data for a block download process.
91
103
pub struct BlockDownloader {
104
+ /// Which set of blocks to download
105
+ block_set : BlockSet ,
92
106
/// Downloader state
93
107
state : State ,
94
108
/// Highest block number seen
@@ -117,29 +131,15 @@ pub struct BlockDownloader {
117
131
}
118
132
119
133
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
+ } ;
142
141
BlockDownloader {
142
+ block_set : block_set,
143
143
state : State :: Idle ,
144
144
highest_block : None ,
145
145
last_imported_block : start_number,
@@ -152,7 +152,7 @@ impl BlockDownloader {
152
152
download_receipts : sync_receipts,
153
153
target_hash : None ,
154
154
retract_step : 1 ,
155
- limit_reorg : false ,
155
+ limit_reorg : limit_reorg ,
156
156
}
157
157
}
158
158
0 commit comments