Merge pull request #3573 from ethcore/no-bg-download

CLI option to disable ancient block downloading
This commit is contained in:
Gav Wood 2016-11-23 16:06:45 +01:00 committed by GitHub
commit 820e291ac8
7 changed files with 25 additions and 10 deletions

View File

@ -140,7 +140,7 @@ pub trait BlockProvider {
fn blocks_with_bloom(&self, bloom: &H2048, from_block: BlockNumber, to_block: BlockNumber) -> Vec<BlockNumber>; fn blocks_with_bloom(&self, bloom: &H2048, from_block: BlockNumber, to_block: BlockNumber) -> Vec<BlockNumber>;
/// Returns logs matching given filter. /// Returns logs matching given filter.
fn logs<F>(&self, mut blocks: Vec<BlockNumber>, matches: F, limit: Option<usize>) -> Vec<LocalizedLogEntry> fn logs<F>(&self, blocks: Vec<BlockNumber>, matches: F, limit: Option<usize>) -> Vec<LocalizedLogEntry>
where F: Fn(&LogEntry) -> bool, Self: Sized; where F: Fn(&LogEntry) -> bool, Self: Sized;
} }

View File

@ -132,6 +132,7 @@ usage! {
or |c: &Config| otry!(c.network).reserved_peers.clone().map(Some), or |c: &Config| otry!(c.network).reserved_peers.clone().map(Some),
flag_reserved_only: bool = false, flag_reserved_only: bool = false,
or |c: &Config| otry!(c.network).reserved_only.clone(), or |c: &Config| otry!(c.network).reserved_only.clone(),
flag_no_ancient_blocks: bool = false, or |_| None,
// -- API and Console Options // -- API and Console Options
// RPC // RPC
@ -533,6 +534,7 @@ mod tests {
flag_node_key: None, flag_node_key: None,
flag_reserved_peers: Some("./path_to_file".into()), flag_reserved_peers: Some("./path_to_file".into()),
flag_reserved_only: false, flag_reserved_only: false,
flag_no_ancient_blocks: false,
// -- API and Console Options // -- API and Console Options
// RPC // RPC

View File

@ -95,6 +95,8 @@ Networking Options:
all - connect to any IP address. all - connect to any IP address.
(default: {flag_allow_ips}) (default: {flag_allow_ips})
--max-pending-peers NUM Allow up to NUM pending connections. (default: {flag_max_pending_peers}) --max-pending-peers NUM Allow up to NUM pending connections. (default: {flag_max_pending_peers})
--no-ancient-blocks Disable downloading old blocks after snapshot restoration
or warp sync. (default: {flag_no_ancient_blocks})
API and Console Options: API and Console Options:
--no-jsonrpc Disable the JSON-RPC API server. (default: {flag_no_jsonrpc}) --no-jsonrpc Disable the JSON-RPC API server. (default: {flag_no_jsonrpc})

View File

@ -250,6 +250,7 @@ impl Configuration {
custom_bootnodes: self.args.flag_bootnodes.is_some(), custom_bootnodes: self.args.flag_bootnodes.is_some(),
no_periodic_snapshot: self.args.flag_no_periodic_snapshot, no_periodic_snapshot: self.args.flag_no_periodic_snapshot,
check_seal: !self.args.flag_no_seal_check, check_seal: !self.args.flag_no_seal_check,
download_old_blocks: !self.args.flag_no_ancient_blocks,
}; };
Cmd::Run(run_cmd) Cmd::Run(run_cmd)
}; };
@ -871,6 +872,7 @@ mod tests {
fat_db: Default::default(), fat_db: Default::default(),
no_periodic_snapshot: false, no_periodic_snapshot: false,
check_seal: true, check_seal: true,
download_old_blocks: true,
})); }));
} }

View File

@ -91,6 +91,7 @@ pub struct RunCmd {
pub custom_bootnodes: bool, pub custom_bootnodes: bool,
pub no_periodic_snapshot: bool, pub no_periodic_snapshot: bool,
pub check_seal: bool, pub check_seal: bool,
pub download_old_blocks: bool,
} }
pub fn open_ui(dapps_conf: &dapps::Configuration, signer_conf: &signer::Configuration) -> Result<(), String> { pub fn open_ui(dapps_conf: &dapps::Configuration, signer_conf: &signer::Configuration) -> Result<(), String> {
@ -202,6 +203,7 @@ pub fn execute(cmd: RunCmd, logger: Arc<RotatingLogger>) -> Result<(), String> {
} }
sync_config.fork_block = spec.fork_block(); sync_config.fork_block = spec.fork_block();
sync_config.warp_sync = cmd.warp_sync; sync_config.warp_sync = cmd.warp_sync;
sync_config.download_old_blocks = cmd.download_old_blocks;
// prepare account provider // prepare account provider
let account_provider = Arc::new(try!(prepare_account_provider(&cmd.dirs, cmd.acc_conf))); let account_provider = Arc::new(try!(prepare_account_provider(&cmd.dirs, cmd.acc_conf)));

View File

@ -41,6 +41,8 @@ pub const WARP_SYNC_PROTOCOL_ID: ProtocolId = *b"par";
pub struct SyncConfig { pub struct SyncConfig {
/// Max blocks to download ahead /// Max blocks to download ahead
pub max_download_ahead_blocks: usize, pub max_download_ahead_blocks: usize,
/// Enable ancient block download.
pub download_old_blocks: bool,
/// Network ID /// Network ID
pub network_id: usize, pub network_id: usize,
/// Main "eth" subprotocol name. /// Main "eth" subprotocol name.
@ -55,6 +57,7 @@ impl Default for SyncConfig {
fn default() -> SyncConfig { fn default() -> SyncConfig {
SyncConfig { SyncConfig {
max_download_ahead_blocks: 20000, max_download_ahead_blocks: 20000,
download_old_blocks: true,
network_id: 1, network_id: 1,
subprotocol_name: *b"eth", subprotocol_name: *b"eth",
fork_block: None, fork_block: None,

View File

@ -352,6 +352,8 @@ pub struct ChainSync {
sync_start_time: Option<u64>, sync_start_time: Option<u64>,
/// Transactions propagation statistics /// Transactions propagation statistics
transactions_stats: TransactionsStats, transactions_stats: TransactionsStats,
/// Enable ancient block downloading
download_old_blocks: bool,
} }
type RlpResponseResult = Result<Option<(PacketId, RlpStream)>, PacketDecodeError>; type RlpResponseResult = Result<Option<(PacketId, RlpStream)>, PacketDecodeError>;
@ -372,6 +374,7 @@ impl ChainSync {
last_sent_block_number: 0, last_sent_block_number: 0,
network_id: config.network_id, network_id: config.network_id,
fork_block: config.fork_block, fork_block: config.fork_block,
download_old_blocks: config.download_old_blocks,
snapshot: Snapshot::new(), snapshot: Snapshot::new(),
sync_start_time: None, sync_start_time: None,
transactions_stats: TransactionsStats::default(), transactions_stats: TransactionsStats::default(),
@ -539,17 +542,18 @@ impl ChainSync {
// Do not assume that the block queue/chain still has our last_imported_block // Do not assume that the block queue/chain still has our last_imported_block
let chain = chain.chain_info(); let chain = chain.chain_info();
self.new_blocks = BlockDownloader::new(false, &chain.best_block_hash, chain.best_block_number); self.new_blocks = BlockDownloader::new(false, &chain.best_block_hash, chain.best_block_number);
if let (Some(ancient_block_hash), Some(ancient_block_number)) = (chain.ancient_block_hash, chain.ancient_block_number) { self.old_blocks = None;
if self.download_old_blocks {
if let (Some(ancient_block_hash), Some(ancient_block_number)) = (chain.ancient_block_hash, chain.ancient_block_number) {
trace!(target: "sync", "Downloading old blocks from {:?} (#{}) till {:?} (#{:?})", ancient_block_hash, ancient_block_number, chain.first_block_hash, chain.first_block_number); trace!(target: "sync", "Downloading old blocks from {:?} (#{}) till {:?} (#{:?})", ancient_block_hash, ancient_block_number, chain.first_block_hash, chain.first_block_number);
let mut downloader = BlockDownloader::new(true, &ancient_block_hash, ancient_block_number); let mut downloader = BlockDownloader::new(true, &ancient_block_hash, ancient_block_number);
if let Some(hash) = chain.first_block_hash { if let Some(hash) = chain.first_block_hash {
trace!(target: "sync", "Downloader target set to {:?}", hash); trace!(target: "sync", "Downloader target set to {:?}", hash);
downloader.set_target(&hash); downloader.set_target(&hash);
}
self.old_blocks = Some(downloader);
} }
self.old_blocks = Some(downloader);
} else {
self.old_blocks = None;
} }
} }