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

Commit 6179a9d

Browse files
authored
Add --sync-until=[NUM] (#11635)
Add an option to halt syncing at a given block number. This is useful when benchmarking or debugging and you want to sync the chain to a predetermined block. The alternative today is to have scripts and poll the node using RPCs and use `db reset` to get to the desired state.
1 parent 327c704 commit 6179a9d

File tree

9 files changed

+28
-0
lines changed

9 files changed

+28
-0
lines changed

ethcore/src/client/client.rs

+8
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,14 @@ impl Importer {
313313

314314
match self.check_and_lock_block(block, client) {
315315
Ok((locked_block, pending)) => {
316+
if let Some(sync_until_block_nr) = client.config.sync_until {
317+
if locked_block.header.number() > sync_until_block_nr {
318+
info!("Sync target reached at block: #{}. Going offline.", sync_until_block_nr);
319+
client.disable();
320+
break;
321+
}
322+
}
323+
316324
imported_blocks.push(hash);
317325
let transactions_len = locked_block.transactions.len();
318326
let gas_used = *locked_block.header.gas_used();

ethcore/src/client/config.rs

+3
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ pub struct ClientConfig {
9494
pub max_round_blocks_to_import: usize,
9595
/// Snapshot configuration
9696
pub snapshot: SnapshotConfiguration,
97+
/// Stop importing at this block and enter sleep mode.
98+
pub sync_until: Option<u64>,
9799
}
98100

99101
impl Default for ClientConfig {
@@ -122,6 +124,7 @@ impl Default for ClientConfig {
122124
transaction_verification_queue_size: 8192,
123125
max_round_blocks_to_import: 12,
124126
snapshot: Default::default(),
127+
sync_until: None,
125128
}
126129
}
127130
}

parity/blockchain.rs

+2
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@ fn execute_import(cmd: ImportBlockchain) -> Result<(), String> {
358358
cmd.pruning_memory,
359359
cmd.check_seal,
360360
12,
361+
None,
361362
);
362363

363364
client_config.queue.verifier_settings = cmd.verifier_settings;
@@ -494,6 +495,7 @@ fn start_client(
494495
pruning_memory,
495496
true,
496497
max_round_blocks_to_import,
498+
None
497499
);
498500

499501
let restoration_db_handler = db::restoration_db_handler(&client_path, &client_config);

parity/cli/mod.rs

+7
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,10 @@ usage! {
318318
"--db-path=[PATH]",
319319
"Specify the database directory path",
320320

321+
ARG arg_sync_until: (Option<u64>) = None, or |c: &Config| c.parity.as_ref()?.sync_until.clone(),
322+
"--sync-until=[NUM]",
323+
"Sync until the given block has been imported, then enter offline mode. Intended for debug/benchmarking only.",
324+
321325
["Convenience Options"]
322326
FLAG flag_unsafe_expose: (bool) = false, or |c: &Config| c.misc.as_ref()?.unsafe_expose,
323327
"--unsafe-expose",
@@ -1171,6 +1175,7 @@ struct Operating {
11711175
light: Option<bool>,
11721176
no_persistent_txqueue: Option<bool>,
11731177
no_hardcoded_sync: Option<bool>,
1178+
sync_until: Option<u64>,
11741179

11751180
#[serde(rename = "public_node")]
11761181
_legacy_public_node: Option<bool>,
@@ -1734,6 +1739,7 @@ mod tests {
17341739
flag_no_hardcoded_sync: false,
17351740
flag_no_persistent_txqueue: false,
17361741
flag_force_direct: false,
1742+
arg_sync_until: None,
17371743

17381744
// -- Convenience Options
17391745
arg_config: "$BASE/config.toml".into(),
@@ -2014,6 +2020,7 @@ mod tests {
20142020
light: None,
20152021
no_hardcoded_sync: None,
20162022
no_persistent_txqueue: None,
2023+
sync_until: Some(123),
20172024
_legacy_public_node: None,
20182025
}),
20192026
account: Some(Account {

parity/cli/tests/config.toml

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ mode = "dark"
33
mode_timeout = 15
44
mode_alarm = 10
55
chain = "./chain.json"
6+
sync_until = 123
67

78
[account]
89
unlock = ["0x1", "0x2", "0x3"]

parity/configuration.rs

+2
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,7 @@ impl Configuration {
413413
on_demand_request_backoff_max: self.args.arg_on_demand_request_backoff_max,
414414
on_demand_request_backoff_rounds_max: self.args.arg_on_demand_request_backoff_rounds_max,
415415
on_demand_request_consecutive_failures: self.args.arg_on_demand_request_consecutive_failures,
416+
sync_until: self.args.arg_sync_until,
416417
};
417418
Cmd::Run(run_cmd)
418419
};
@@ -1453,6 +1454,7 @@ mod tests {
14531454
on_demand_request_backoff_max: None,
14541455
on_demand_request_backoff_rounds_max: None,
14551456
on_demand_request_consecutive_failures: None,
1457+
sync_until: None,
14561458
};
14571459
expected.secretstore_conf.enabled = cfg!(feature = "secretstore");
14581460
expected.secretstore_conf.http_enabled = cfg!(feature = "secretstore");

parity/helpers.rs

+2
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ pub fn to_client_config(
240240
pruning_memory: usize,
241241
check_seal: bool,
242242
max_round_blocks_to_import: usize,
243+
sync_until: Option<u64>,
243244
) -> ClientConfig {
244245
let mut client_config = ClientConfig::default();
245246

@@ -273,6 +274,7 @@ pub fn to_client_config(
273274
client_config.verifier_type = if check_seal { VerifierType::Canon } else { VerifierType::CanonNoSeal };
274275
client_config.spec_name = spec_name;
275276
client_config.max_round_blocks_to_import = max_round_blocks_to_import;
277+
client_config.sync_until = sync_until;
276278
client_config
277279
}
278280

parity/run.rs

+2
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ pub struct RunCmd {
137137
pub on_demand_request_backoff_max: Option<u64>,
138138
pub on_demand_request_backoff_rounds_max: Option<usize>,
139139
pub on_demand_request_consecutive_failures: Option<usize>,
140+
pub sync_until: Option<u64>,
140141
}
141142

142143
// node info fetcher for the local store.
@@ -538,6 +539,7 @@ fn execute_impl<Cr, Rr>(
538539
cmd.pruning_memory,
539540
cmd.check_seal,
540541
cmd.max_round_blocks_to_import,
542+
cmd.sync_until,
541543
);
542544

543545
client_config.queue.verifier_settings = cmd.verifier_settings;

parity/snapshot_cmd.rs

+1
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ impl SnapshotCommand {
186186
self.pruning_memory,
187187
true,
188188
self.max_round_blocks_to_import,
189+
None,
189190
);
190191

191192
client_config.snapshot = self.snapshot_conf;

0 commit comments

Comments
 (0)