Skip to content

Commit ccf50d6

Browse files
committed
Add configuration option for the snapshot sync target
1 parent 96641fb commit ccf50d6

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

codechain/codechain.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,16 @@ args:
259259
takes_value: true
260260
conflicts_with:
261261
- no-discovery
262+
- snapshot-hash:
263+
long: snapshot-hash
264+
value_name: HASH
265+
requires: snapshot-number
266+
takes_value: true
267+
- snapshot-number:
268+
long: snapshot-number
269+
value_name: NUM
270+
requires: snapshot-hash
271+
takes_value: true
262272
- no-snapshot:
263273
long: no-snapshot
264274
help: Disable snapshots

codechain/config/mod.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use cidr::IpCidr;
2525
use ckey::PlatformAddress;
2626
use clap;
2727
use cnetwork::{FilterEntry, NetworkConfig, SocketAddr};
28+
use primitives::H256;
2829
use toml;
2930

3031
pub use self::chain_type::ChainType;
@@ -242,6 +243,8 @@ pub struct Network {
242243
pub min_peers: Option<usize>,
243244
pub max_peers: Option<usize>,
244245
pub sync: Option<bool>,
246+
pub snapshot_hash: Option<H256>,
247+
pub snapshot_number: Option<u64>,
245248
pub transaction_relay: Option<bool>,
246249
pub discovery: Option<bool>,
247250
pub discovery_type: Option<String>,
@@ -500,6 +503,12 @@ impl Network {
500503
if other.sync.is_some() {
501504
self.sync = other.sync;
502505
}
506+
if other.snapshot_hash.is_some() {
507+
self.snapshot_hash = other.snapshot_hash;
508+
}
509+
if other.snapshot_number.is_some() {
510+
self.snapshot_number = other.snapshot_number;
511+
}
503512
if other.transaction_relay.is_some() {
504513
self.transaction_relay = other.transaction_relay;
505514
}
@@ -552,6 +561,12 @@ impl Network {
552561
if matches.is_present("no-sync") {
553562
self.sync = Some(false);
554563
}
564+
if let Some(snapshot_hash) = matches.value_of("snapshot-hash") {
565+
self.snapshot_hash = Some(snapshot_hash.parse().map_err(|_| "Invalid snapshot-hash")?);
566+
}
567+
if let Some(snapshot_number) = matches.value_of("snapshot-number") {
568+
self.snapshot_number = Some(snapshot_number.parse().map_err(|_| "Invalid snapshot-number")?);
569+
}
555570
if matches.is_present("no-tx-relay") {
556571
self.transaction_relay = Some(false);
557572
}

codechain/run_node.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,11 @@ pub fn run_node(matches: &ArgMatches) -> Result<(), String> {
300300
if config.network.sync.unwrap() {
301301
let sync_sender = {
302302
let client = client.client();
303-
service.register_extension(move |api| BlockSyncExtension::new(client, api))
303+
let snapshot_target = match (config.network.snapshot_hash, config.network.snapshot_number) {
304+
(Some(hash), Some(num)) => Some((hash, num)),
305+
_ => None,
306+
};
307+
service.register_extension(move |api| BlockSyncExtension::new(client, api, snapshot_target))
304308
};
305309
let sync = Arc::new(BlockSyncSender::from(sync_sender.clone()));
306310
client.client().add_notify(Arc::downgrade(&sync) as Weak<dyn ChainNotify>);

sync/src/block/extension.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ pub struct Extension {
6969
}
7070

7171
impl Extension {
72-
pub fn new(client: Arc<Client>, api: Box<dyn Api>) -> Extension {
72+
pub fn new(client: Arc<Client>, api: Box<dyn Api>, _snapshot_target: Option<(H256, u64)>) -> Extension {
7373
api.set_timer(SYNC_TIMER_TOKEN, Duration::from_millis(SYNC_TIMER_INTERVAL)).expect("Timer set succeeds");
7474

7575
let mut header = client.best_header();

0 commit comments

Comments
 (0)