Expose config max-round-blocks-to-import (#9439)
* Expose config max-round-blocks-to-import * Fix test
This commit is contained in:
		
							parent
							
								
									e7f1204fa4
								
							
						
					
					
						commit
						1ff827b2ea
					
				@ -262,13 +262,12 @@ impl Importer {
 | 
			
		||||
 | 
			
		||||
	/// This is triggered by a message coming from a block queue when the block is ready for insertion
 | 
			
		||||
	pub fn import_verified_blocks(&self, client: &Client) -> usize {
 | 
			
		||||
 | 
			
		||||
		// Shortcut out if we know we're incapable of syncing the chain.
 | 
			
		||||
		if !client.enabled.load(AtomicOrdering::Relaxed) {
 | 
			
		||||
			return 0;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		let max_blocks_to_import = 4;
 | 
			
		||||
		let max_blocks_to_import = client.config.max_round_blocks_to_import;
 | 
			
		||||
		let (imported_blocks, import_results, invalid_blocks, imported, proposed_blocks, duration, is_empty) = {
 | 
			
		||||
			let mut imported_blocks = Vec::with_capacity(max_blocks_to_import);
 | 
			
		||||
			let mut invalid_blocks = HashSet::new();
 | 
			
		||||
 | 
			
		||||
@ -121,6 +121,8 @@ pub struct ClientConfig {
 | 
			
		||||
	pub check_seal: bool,
 | 
			
		||||
	/// Maximal number of transactions queued for verification in a separate thread.
 | 
			
		||||
	pub transaction_verification_queue_size: usize,
 | 
			
		||||
	/// Maximal number of blocks to import at each round.
 | 
			
		||||
	pub max_round_blocks_to_import: usize,
 | 
			
		||||
	/// Snapshot configuration
 | 
			
		||||
	pub snapshot: SnapshotConfiguration,
 | 
			
		||||
}
 | 
			
		||||
@ -147,6 +149,7 @@ impl Default for ClientConfig {
 | 
			
		||||
			history_mem: 32 * mb,
 | 
			
		||||
			check_seal: true,
 | 
			
		||||
			transaction_verification_queue_size: 8192,
 | 
			
		||||
			max_round_blocks_to_import: 12,
 | 
			
		||||
			snapshot: Default::default(),
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@ -98,6 +98,7 @@ pub struct ImportBlockchain {
 | 
			
		||||
	pub with_color: bool,
 | 
			
		||||
	pub verifier_settings: VerifierSettings,
 | 
			
		||||
	pub light: bool,
 | 
			
		||||
	pub max_round_blocks_to_import: usize,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[derive(Debug, PartialEq)]
 | 
			
		||||
@ -116,6 +117,7 @@ pub struct ExportBlockchain {
 | 
			
		||||
	pub from_block: BlockId,
 | 
			
		||||
	pub to_block: BlockId,
 | 
			
		||||
	pub check_seal: bool,
 | 
			
		||||
	pub max_round_blocks_to_import: usize,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[derive(Debug, PartialEq)]
 | 
			
		||||
@ -136,6 +138,7 @@ pub struct ExportState {
 | 
			
		||||
	pub code: bool,
 | 
			
		||||
	pub min_balance: Option<U256>,
 | 
			
		||||
	pub max_balance: Option<U256>,
 | 
			
		||||
	pub max_round_blocks_to_import: usize,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
pub fn execute(cmd: BlockchainCmd) -> Result<(), String> {
 | 
			
		||||
@ -354,6 +357,7 @@ fn execute_import(cmd: ImportBlockchain) -> Result<(), String> {
 | 
			
		||||
		cmd.pruning_history,
 | 
			
		||||
		cmd.pruning_memory,
 | 
			
		||||
		cmd.check_seal,
 | 
			
		||||
		12,
 | 
			
		||||
	);
 | 
			
		||||
 | 
			
		||||
	client_config.queue.verifier_settings = cmd.verifier_settings;
 | 
			
		||||
@ -493,6 +497,7 @@ fn start_client(
 | 
			
		||||
	compaction: DatabaseCompactionProfile,
 | 
			
		||||
	cache_config: CacheConfig,
 | 
			
		||||
	require_fat_db: bool,
 | 
			
		||||
	max_round_blocks_to_import: usize,
 | 
			
		||||
) -> Result<ClientService, String> {
 | 
			
		||||
 | 
			
		||||
	// load spec file
 | 
			
		||||
@ -546,6 +551,7 @@ fn start_client(
 | 
			
		||||
		pruning_history,
 | 
			
		||||
		pruning_memory,
 | 
			
		||||
		true,
 | 
			
		||||
		max_round_blocks_to_import,
 | 
			
		||||
	);
 | 
			
		||||
 | 
			
		||||
	let restoration_db_handler = db::restoration_db_handler(&client_path, &client_config);
 | 
			
		||||
@ -583,6 +589,7 @@ fn execute_export(cmd: ExportBlockchain) -> Result<(), String> {
 | 
			
		||||
		cmd.compaction,
 | 
			
		||||
		cmd.cache_config,
 | 
			
		||||
		false,
 | 
			
		||||
		cmd.max_round_blocks_to_import,
 | 
			
		||||
	)?;
 | 
			
		||||
	let format = cmd.format.unwrap_or_default();
 | 
			
		||||
 | 
			
		||||
@ -626,7 +633,8 @@ fn execute_export_state(cmd: ExportState) -> Result<(), String> {
 | 
			
		||||
		cmd.fat_db,
 | 
			
		||||
		cmd.compaction,
 | 
			
		||||
		cmd.cache_config,
 | 
			
		||||
		true
 | 
			
		||||
		true,
 | 
			
		||||
		cmd.max_round_blocks_to_import,
 | 
			
		||||
	)?;
 | 
			
		||||
 | 
			
		||||
	let client = service.client();
 | 
			
		||||
 | 
			
		||||
@ -785,6 +785,10 @@ usage! {
 | 
			
		||||
			"--stratum-secret=[STRING]",
 | 
			
		||||
			"Secret for authorizing Stratum server for peers.",
 | 
			
		||||
 | 
			
		||||
			ARG arg_max_round_blocks_to_import: (usize) = 12usize, or |c: &Config| c.mining.as_ref()?.max_round_blocks_to_import.clone(),
 | 
			
		||||
			"--max-round-blocks-to-import=[S]",
 | 
			
		||||
			"Maximal number of blocks to import for each import round.",
 | 
			
		||||
 | 
			
		||||
		["Internal Options"]
 | 
			
		||||
			FLAG flag_can_restart: (bool) = false, or |_| None,
 | 
			
		||||
			"--can-restart",
 | 
			
		||||
@ -1326,6 +1330,7 @@ struct Mining {
 | 
			
		||||
	notify_work: Option<Vec<String>>,
 | 
			
		||||
	refuse_service_transactions: Option<bool>,
 | 
			
		||||
	infinite_pending_block: Option<bool>,
 | 
			
		||||
	max_round_blocks_to_import: Option<usize>,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[derive(Default, Debug, PartialEq, Deserialize)]
 | 
			
		||||
@ -1758,6 +1763,7 @@ mod tests {
 | 
			
		||||
			arg_notify_work: Some("http://localhost:3001".into()),
 | 
			
		||||
			flag_refuse_service_transactions: false,
 | 
			
		||||
			flag_infinite_pending_block: false,
 | 
			
		||||
			arg_max_round_blocks_to_import: 12usize,
 | 
			
		||||
 | 
			
		||||
			flag_stratum: false,
 | 
			
		||||
			arg_stratum_interface: "local".to_owned(),
 | 
			
		||||
@ -2029,6 +2035,7 @@ mod tests {
 | 
			
		||||
				notify_work: None,
 | 
			
		||||
				refuse_service_transactions: None,
 | 
			
		||||
				infinite_pending_block: None,
 | 
			
		||||
				max_round_blocks_to_import: None,
 | 
			
		||||
			}),
 | 
			
		||||
			footprint: Some(Footprint {
 | 
			
		||||
				tracing: Some("on".into()),
 | 
			
		||||
 | 
			
		||||
@ -243,6 +243,7 @@ impl Configuration {
 | 
			
		||||
				with_color: logger_config.color,
 | 
			
		||||
				verifier_settings: self.verifier_settings(),
 | 
			
		||||
				light: self.args.flag_light,
 | 
			
		||||
				max_round_blocks_to_import: self.args.arg_max_round_blocks_to_import,
 | 
			
		||||
			};
 | 
			
		||||
			Cmd::Blockchain(BlockchainCmd::Import(import_cmd))
 | 
			
		||||
		} else if self.args.cmd_export {
 | 
			
		||||
@ -262,6 +263,7 @@ impl Configuration {
 | 
			
		||||
					from_block: to_block_id(&self.args.arg_export_blocks_from)?,
 | 
			
		||||
					to_block: to_block_id(&self.args.arg_export_blocks_to)?,
 | 
			
		||||
					check_seal: !self.args.flag_no_seal_check,
 | 
			
		||||
					max_round_blocks_to_import: self.args.arg_max_round_blocks_to_import,
 | 
			
		||||
				};
 | 
			
		||||
				Cmd::Blockchain(BlockchainCmd::Export(export_cmd))
 | 
			
		||||
			} else if self.args.cmd_export_state {
 | 
			
		||||
@ -282,6 +284,7 @@ impl Configuration {
 | 
			
		||||
					code: !self.args.flag_export_state_no_code,
 | 
			
		||||
					min_balance: self.args.arg_export_state_min_balance.and_then(|s| to_u256(&s).ok()),
 | 
			
		||||
					max_balance: self.args.arg_export_state_max_balance.and_then(|s| to_u256(&s).ok()),
 | 
			
		||||
					max_round_blocks_to_import: self.args.arg_max_round_blocks_to_import,
 | 
			
		||||
				};
 | 
			
		||||
				Cmd::Blockchain(BlockchainCmd::ExportState(export_cmd))
 | 
			
		||||
			} else {
 | 
			
		||||
@ -301,6 +304,7 @@ impl Configuration {
 | 
			
		||||
				file_path: self.args.arg_snapshot_file.clone(),
 | 
			
		||||
				kind: snapshot::Kind::Take,
 | 
			
		||||
				block_at: to_block_id(&self.args.arg_snapshot_at)?,
 | 
			
		||||
				max_round_blocks_to_import: self.args.arg_max_round_blocks_to_import,
 | 
			
		||||
				snapshot_conf: snapshot_conf,
 | 
			
		||||
			};
 | 
			
		||||
			Cmd::Snapshot(snapshot_cmd)
 | 
			
		||||
@ -318,6 +322,7 @@ impl Configuration {
 | 
			
		||||
				file_path: self.args.arg_restore_file.clone(),
 | 
			
		||||
				kind: snapshot::Kind::Restore,
 | 
			
		||||
				block_at: to_block_id("latest")?, // unimportant.
 | 
			
		||||
				max_round_blocks_to_import: self.args.arg_max_round_blocks_to_import,
 | 
			
		||||
				snapshot_conf: snapshot_conf,
 | 
			
		||||
			};
 | 
			
		||||
			Cmd::Snapshot(restore_cmd)
 | 
			
		||||
@ -388,6 +393,7 @@ impl Configuration {
 | 
			
		||||
				no_persistent_txqueue: self.args.flag_no_persistent_txqueue,
 | 
			
		||||
				whisper: whisper_config,
 | 
			
		||||
				no_hardcoded_sync: self.args.flag_no_hardcoded_sync,
 | 
			
		||||
				max_round_blocks_to_import: self.args.arg_max_round_blocks_to_import,
 | 
			
		||||
				on_demand_retry_count: self.args.arg_on_demand_retry_count,
 | 
			
		||||
				on_demand_inactive_time_limit: self.args.arg_on_demand_inactive_time_limit,
 | 
			
		||||
			};
 | 
			
		||||
@ -1263,6 +1269,7 @@ mod tests {
 | 
			
		||||
			with_color: !cfg!(windows),
 | 
			
		||||
			verifier_settings: Default::default(),
 | 
			
		||||
			light: false,
 | 
			
		||||
			max_round_blocks_to_import: 12,
 | 
			
		||||
		})));
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@ -1285,6 +1292,7 @@ mod tests {
 | 
			
		||||
			from_block: BlockId::Number(1),
 | 
			
		||||
			to_block: BlockId::Latest,
 | 
			
		||||
			check_seal: true,
 | 
			
		||||
			max_round_blocks_to_import: 12,
 | 
			
		||||
		})));
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@ -1309,6 +1317,7 @@ mod tests {
 | 
			
		||||
			code: true,
 | 
			
		||||
			min_balance: None,
 | 
			
		||||
			max_balance: None,
 | 
			
		||||
			max_round_blocks_to_import: 12,
 | 
			
		||||
		})));
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@ -1331,6 +1340,7 @@ mod tests {
 | 
			
		||||
			from_block: BlockId::Number(1),
 | 
			
		||||
			to_block: BlockId::Latest,
 | 
			
		||||
			check_seal: true,
 | 
			
		||||
			max_round_blocks_to_import: 12,
 | 
			
		||||
		})));
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@ -1427,6 +1437,7 @@ mod tests {
 | 
			
		||||
			no_hardcoded_sync: false,
 | 
			
		||||
			no_persistent_txqueue: false,
 | 
			
		||||
			whisper: Default::default(),
 | 
			
		||||
			max_round_blocks_to_import: 12,
 | 
			
		||||
			on_demand_retry_count: None,
 | 
			
		||||
			on_demand_inactive_time_limit: None,
 | 
			
		||||
		};
 | 
			
		||||
 | 
			
		||||
@ -204,19 +204,20 @@ pub fn default_network_config() -> ::sync::NetworkConfiguration {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
pub fn to_client_config(
 | 
			
		||||
		cache_config: &CacheConfig,
 | 
			
		||||
		spec_name: String,
 | 
			
		||||
		mode: Mode,
 | 
			
		||||
		tracing: bool,
 | 
			
		||||
		fat_db: bool,
 | 
			
		||||
		compaction: DatabaseCompactionProfile,
 | 
			
		||||
		vm_type: VMType,
 | 
			
		||||
		name: String,
 | 
			
		||||
		pruning: Algorithm,
 | 
			
		||||
		pruning_history: u64,
 | 
			
		||||
		pruning_memory: usize,
 | 
			
		||||
		check_seal: bool,
 | 
			
		||||
	) -> ClientConfig {
 | 
			
		||||
	cache_config: &CacheConfig,
 | 
			
		||||
	spec_name: String,
 | 
			
		||||
	mode: Mode,
 | 
			
		||||
	tracing: bool,
 | 
			
		||||
	fat_db: bool,
 | 
			
		||||
	compaction: DatabaseCompactionProfile,
 | 
			
		||||
	vm_type: VMType,
 | 
			
		||||
	name: String,
 | 
			
		||||
	pruning: Algorithm,
 | 
			
		||||
	pruning_history: u64,
 | 
			
		||||
	pruning_memory: usize,
 | 
			
		||||
	check_seal: bool,
 | 
			
		||||
	max_round_blocks_to_import: usize,
 | 
			
		||||
) -> ClientConfig {
 | 
			
		||||
	let mut client_config = ClientConfig::default();
 | 
			
		||||
 | 
			
		||||
	let mb = 1024 * 1024;
 | 
			
		||||
@ -249,6 +250,7 @@ pub fn to_client_config(
 | 
			
		||||
	client_config.name = name;
 | 
			
		||||
	client_config.verifier_type = if check_seal { VerifierType::Canon } else { VerifierType::CanonNoSeal };
 | 
			
		||||
	client_config.spec_name = spec_name;
 | 
			
		||||
	client_config.max_round_blocks_to_import = max_round_blocks_to_import;
 | 
			
		||||
	client_config
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -133,6 +133,7 @@ pub struct RunCmd {
 | 
			
		||||
	pub no_persistent_txqueue: bool,
 | 
			
		||||
	pub whisper: ::whisper::Config,
 | 
			
		||||
	pub no_hardcoded_sync: bool,
 | 
			
		||||
	pub max_round_blocks_to_import: usize,
 | 
			
		||||
	pub on_demand_retry_count: Option<usize>,
 | 
			
		||||
	pub on_demand_inactive_time_limit: Option<u64>,
 | 
			
		||||
}
 | 
			
		||||
@ -530,6 +531,7 @@ fn execute_impl<Cr, Rr>(cmd: RunCmd, logger: Arc<RotatingLogger>, on_client_rq:
 | 
			
		||||
		cmd.pruning_history,
 | 
			
		||||
		cmd.pruning_memory,
 | 
			
		||||
		cmd.check_seal,
 | 
			
		||||
		cmd.max_round_blocks_to_import,
 | 
			
		||||
	);
 | 
			
		||||
 | 
			
		||||
	client_config.queue.verifier_settings = cmd.verifier_settings;
 | 
			
		||||
 | 
			
		||||
@ -62,6 +62,7 @@ pub struct SnapshotCommand {
 | 
			
		||||
	pub file_path: Option<String>,
 | 
			
		||||
	pub kind: Kind,
 | 
			
		||||
	pub block_at: BlockId,
 | 
			
		||||
	pub max_round_blocks_to_import: usize,
 | 
			
		||||
	pub snapshot_conf: SnapshotConfiguration,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -179,6 +180,7 @@ impl SnapshotCommand {
 | 
			
		||||
			self.pruning_history,
 | 
			
		||||
			self.pruning_memory,
 | 
			
		||||
			true,
 | 
			
		||||
			self.max_round_blocks_to_import,
 | 
			
		||||
		);
 | 
			
		||||
 | 
			
		||||
		client_config.snapshot = self.snapshot_conf;
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user