From 727df531a99b4a4a7a85ca9cf86f56628ec40f71 Mon Sep 17 00:00:00 2001 From: Lohachov Mykhailo Date: Sat, 30 Nov 2024 01:24:56 +0900 Subject: [PATCH] chore: clippy Signed-off-by: Lohachov Mykhailo --- crates/iroha/examples/tutorial.rs | 22 +++++++--------- crates/iroha/src/client.rs | 14 +++++----- crates/iroha_cli/src/main.rs | 4 +-- crates/iroha_core/benches/kura.rs | 15 ++++++----- crates/iroha_core/src/block_sync.rs | 4 +-- crates/iroha_core/src/gossiper.rs | 4 +-- crates/iroha_core/src/kiso.rs | 4 +-- crates/iroha_core/src/kura.rs | 4 +-- crates/iroha_core/src/peers_gossiper.rs | 2 +- crates/iroha_core/src/query/store.rs | 6 ++--- crates/iroha_core/src/queue.rs | 12 ++++----- crates/iroha_core/src/snapshot.rs | 2 +- crates/iroha_core/src/sumeragi/main_loop.rs | 2 +- crates/iroha_core/src/sumeragi/mod.rs | 4 +-- crates/iroha_p2p/src/network.rs | 2 +- crates/iroha_telemetry/src/ws.rs | 4 +-- crates/iroha_test_network/src/lib.rs | 2 +- crates/iroha_torii/src/lib.rs | 4 +-- crates/irohad/src/main.rs | 29 +++++++++------------ 19 files changed, 67 insertions(+), 73 deletions(-) diff --git a/crates/iroha/examples/tutorial.rs b/crates/iroha/examples/tutorial.rs index 8ce941f4619..4376856c366 100644 --- a/crates/iroha/examples/tutorial.rs +++ b/crates/iroha/examples/tutorial.rs @@ -12,22 +12,20 @@ fn main() { // Your code goes hereā€¦ - domain_registration_test(config.clone()) + domain_registration_test(&config) .expect("Domain registration example is expected to work correctly"); account_definition_test().expect("Account definition example is expected to work correctly"); - account_registration_test(config.clone()) + account_registration_test(&config) .expect("Account registration example is expected to work correctly"); - asset_registration_test(config.clone()) + asset_registration_test(&config) .expect("Asset registration example is expected to work correctly"); - asset_minting_test(config.clone()) - .expect("Asset minting example is expected to work correctly"); - asset_burning_test(config.clone()) - .expect("Asset burning example is expected to work correctly"); + asset_minting_test(&config).expect("Asset minting example is expected to work correctly"); + asset_burning_test(&config).expect("Asset burning example is expected to work correctly"); // output_visualising_test(&config).expect(msg: "Visualising outputs example is expected to work correctly"); println!("Success!"); } -fn domain_registration_test(config: Config) -> Result<(), Error> { +fn domain_registration_test(config: &Config) -> Result<(), Error> { // #region domain_register_example_crates use iroha::{ client::Client, @@ -93,7 +91,7 @@ fn account_definition_test() -> Result<(), Error> { Ok(()) } -fn account_registration_test(config: Config) -> Result<(), Error> { +fn account_registration_test(config: &Config) -> Result<(), Error> { // #region register_account_crates use iroha::{ client::Client, @@ -139,7 +137,7 @@ fn account_registration_test(config: Config) -> Result<(), Error> { Ok(()) } -fn asset_registration_test(config: Config) -> Result<(), Error> { +fn asset_registration_test(config: &Config) -> Result<(), Error> { // #region register_asset_crates use iroha::{ client::Client, @@ -187,7 +185,7 @@ fn asset_registration_test(config: Config) -> Result<(), Error> { Ok(()) } -fn asset_minting_test(config: Config) -> Result<(), Error> { +fn asset_minting_test(config: &Config) -> Result<(), Error> { // #region mint_asset_crates use iroha::{ client::Client, @@ -239,7 +237,7 @@ fn asset_minting_test(config: Config) -> Result<(), Error> { Ok(()) } -fn asset_burning_test(config: Config) -> Result<(), Error> { +fn asset_burning_test(config: &Config) -> Result<(), Error> { // #region burn_asset_crates use iroha::{ client::Client, diff --git a/crates/iroha/src/client.rs b/crates/iroha/src/client.rs index a2381b338df..27dd8171b4f 100644 --- a/crates/iroha/src/client.rs +++ b/crates/iroha/src/client.rs @@ -143,7 +143,7 @@ pub struct Client { impl Client { /// Constructor for client from configuration #[inline] - pub fn new(configuration: Config) -> Self { + pub fn new(configuration: &Config) -> Self { Self::with_headers(configuration, HashMap::new()) } @@ -151,7 +151,7 @@ impl Client { /// /// *Authorization* header will be added if `basic_auth` is presented #[inline] - pub fn with_headers(config: Config, mut headers: HashMap) -> Self { + pub fn with_headers(config: &Config, mut headers: HashMap) -> Self { if let Some(basic_auth) = config.basic_auth().clone() { let credentials = format!( "{}:{}", @@ -167,11 +167,11 @@ impl Client { chain: config.chain().clone(), torii_url: config.torii_api_url().clone(), key_pair: config.key_pair().clone(), - transaction_ttl: Some(config.transaction_ttl().clone()), - transaction_status_timeout: config.transaction_status_timeout().clone(), + transaction_ttl: Some(*config.transaction_ttl()), + transaction_status_timeout: *config.transaction_status_timeout(), account: config.account().clone(), headers, - add_transaction_nonce: config.transaction_add_nonce().clone(), + add_transaction_nonce: *config.transaction_add_nonce(), } } @@ -998,7 +998,7 @@ mod tests { .transaction_add_nonce(true) .build() .expect("Can't build config"); - let client = Client::new(config); + let client = Client::new(&config); let build_transaction = || client.build_transaction(Vec::::new(), Metadata::default()); @@ -1033,7 +1033,7 @@ mod tests { })) .build() .expect("Can't build config"); - let client = Client::new(config); + let client = Client::new(&config); let value = client .headers diff --git a/crates/iroha_cli/src/main.rs b/crates/iroha_cli/src/main.rs index 2270d10e52b..542256fa2a6 100644 --- a/crates/iroha_cli/src/main.rs +++ b/crates/iroha_cli/src/main.rs @@ -121,7 +121,7 @@ trait RunContext { fn configuration(&self) -> &Config; fn client_from_config(&self) -> Client { - Client::new(self.configuration().clone()) + Client::new(self.configuration()) } /// Serialize and print data @@ -1199,7 +1199,7 @@ mod json { .wrap_err("Failed to submit parsed instructions") } Variant::Query => { - let client = Client::new(context.configuration().clone()); + let client = Client::new(context.configuration()); let query: AnyQueryBox = json5::from_str(&string_content)?; match query { diff --git a/crates/iroha_core/benches/kura.rs b/crates/iroha_core/benches/kura.rs index df53c0782ad..d82f3498c44 100644 --- a/crates/iroha_core/benches/kura.rs +++ b/crates/iroha_core/benches/kura.rs @@ -3,7 +3,7 @@ use criterion::{criterion_group, criterion_main, Criterion}; use iroha_config::{ base::WithOrigin, - parameters::{actual::Kura as Config, defaults::kura::BLOCKS_IN_MEMORY}, + parameters::{actual::KuraBuilder as ConfigBuilder, defaults::kura::BLOCKS_IN_MEMORY}, }; use iroha_core::{ block::*, @@ -21,12 +21,13 @@ use tokio::{fs, runtime::Runtime}; async fn measure_block_size_for_n_executors(n_executors: u32) { let dir = tempfile::tempdir().expect("Could not create tempfile."); - let cfg = Config { - init_mode: iroha_config::kura::InitMode::Strict, - debug_output_new_blocks: false, - blocks_in_memory: BLOCKS_IN_MEMORY, - store_dir: WithOrigin::inline(dir.path().to_path_buf()), - }; + let cfg = ConfigBuilder::default() + .init_mode(iroha_config::kura::InitMode::Strict) + .debug_output_new_blocks(false) + .blocks_in_memory(BLOCKS_IN_MEMORY) + .store_dir(WithOrigin::inline(dir.path().to_path_buf())) + .build() + .expect("Should build config"); let chain_id = ChainId::from("00000000-0000-0000-0000-000000000000"); let (kura, _) = iroha_core::kura::Kura::new(&cfg).unwrap(); let _thread_handle = iroha_core::kura::Kura::start(kura.clone(), ShutdownSignal::new()); diff --git a/crates/iroha_core/src/block_sync.rs b/crates/iroha_core/src/block_sync.rs index 10170aec155..ae1de6a4199 100644 --- a/crates/iroha_core/src/block_sync.rs +++ b/crates/iroha_core/src/block_sync.rs @@ -153,8 +153,8 @@ impl BlockSynchronizer { peer, sumeragi, kura, - gossip_period: config.gossip_period().clone(), - gossip_size: config.gossip_size().clone(), + gossip_period: *config.gossip_period(), + gossip_size: *config.gossip_size(), network, state, seen_blocks: BTreeSet::new(), diff --git a/crates/iroha_core/src/gossiper.rs b/crates/iroha_core/src/gossiper.rs index 7af38b077e2..ec02a05f5fb 100644 --- a/crates/iroha_core/src/gossiper.rs +++ b/crates/iroha_core/src/gossiper.rs @@ -68,8 +68,8 @@ impl TransactionGossiper { ) -> Self { Self { chain_id, - gossip_period: config.gossip_period().clone(), - gossip_size: config.gossip_size().clone(), + gossip_period: *config.gossip_period(), + gossip_size: *config.gossip_size(), network, queue, state, diff --git a/crates/iroha_core/src/kiso.rs b/crates/iroha_core/src/kiso.rs index 8964bf16ab6..53008b760b8 100644 --- a/crates/iroha_core/src/kiso.rs +++ b/crates/iroha_core/src/kiso.rs @@ -28,7 +28,7 @@ pub struct KisoHandle { impl KisoHandle { /// Spawn a new actor - pub fn start(state: Config) -> (Self, Child) { + pub fn start(state: &Config) -> (Self, Child) { let (actor_sender, actor_receiver) = mpsc::channel(DEFAULT_CHANNEL_SIZE); let (log_level_update, _) = watch::channel(state.logger().level().clone()); let mut actor = Actor { @@ -187,7 +187,7 @@ mod tests { config.logger_mut().set_level(INIT_LOG_LEVEL.into()); - let (kiso, _) = KisoHandle::start(config); + let (kiso, _) = KisoHandle::start(&config); let mut recv = kiso .subscribe_on_log_level() diff --git a/crates/iroha_core/src/kura.rs b/crates/iroha_core/src/kura.rs index 9ca15acdb5d..89c2521450b 100644 --- a/crates/iroha_core/src/kura.rs +++ b/crates/iroha_core/src/kura.rs @@ -66,7 +66,7 @@ impl Kura { .debug_output_new_blocks() .then(|| store_dir.join("blocks.json")); - let block_data = Kura::init(&mut block_store, config.init_mode().clone())?; + let block_data = Kura::init(&mut block_store, *config.init_mode())?; let block_count = block_data.len(); info!(mode=?config.init_mode(), block_count, "Kura init complete"); @@ -74,7 +74,7 @@ impl Kura { block_store: Mutex::new(block_store), block_data: Mutex::new(block_data), block_plain_text_path, - blocks_in_memory: config.blocks_in_memory().clone(), + blocks_in_memory: *config.blocks_in_memory(), init_block_count: block_count, }); diff --git a/crates/iroha_core/src/peers_gossiper.rs b/crates/iroha_core/src/peers_gossiper.rs index 5380bdc10c3..23faa96f54c 100644 --- a/crates/iroha_core/src/peers_gossiper.rs +++ b/crates/iroha_core/src/peers_gossiper.rs @@ -68,7 +68,7 @@ pub struct PeersGossiper { impl PeersGossiper { /// Start actor. pub fn start( - trusted_peers: TrustedPeers, + trusted_peers: &TrustedPeers, network: IrohaNetwork, shutdown_signal: ShutdownSignal, ) -> (PeersGossiperHandle, Child) { diff --git a/crates/iroha_core/src/query/store.rs b/crates/iroha_core/src/query/store.rs index 4f0b5f025f1..d2700e54f26 100644 --- a/crates/iroha_core/src/query/store.rs +++ b/crates/iroha_core/src/query/store.rs @@ -97,9 +97,9 @@ impl LiveQueryStore { Self { queries: DashMap::new(), queries_per_user: DashMap::new(), - idle_time: cfg.idle_time().clone(), - capacity: cfg.capacity().clone(), - capacity_per_user: cfg.capacity_per_user().clone(), + idle_time: *cfg.idle_time(), + capacity: *cfg.capacity(), + capacity_per_user: *cfg.capacity_per_user(), shutdown_signal, } } diff --git a/crates/iroha_core/src/queue.rs b/crates/iroha_core/src/queue.rs index 09afddf0f82..54feb118490 100644 --- a/crates/iroha_core/src/queue.rs +++ b/crates/iroha_core/src/queue.rs @@ -107,10 +107,10 @@ impl Queue { tx_hashes: ArrayQueue::new(config.capacity().get()), txs: DashMap::new(), txs_per_user: DashMap::new(), - capacity: config.capacity().clone(), - capacity_per_user: config.capacity_per_user().clone(), + capacity: *config.capacity(), + capacity_per_user: *config.capacity_per_user(), time_source: TimeSource::new_system(), - tx_time_to_live: config.transaction_time_to_live().clone(), + tx_time_to_live: *config.transaction_time_to_live(), tx_gossip: ArrayQueue::new(config.capacity().get()), } } @@ -426,10 +426,10 @@ pub mod tests { tx_gossip: ArrayQueue::new(cfg.capacity().get()), txs: DashMap::new(), txs_per_user: DashMap::new(), - capacity: cfg.capacity().clone(), - capacity_per_user: cfg.capacity_per_user().clone(), + capacity: *cfg.capacity(), + capacity_per_user: *cfg.capacity_per_user(), time_source: time_source.clone(), - tx_time_to_live: cfg.transaction_time_to_live().clone(), + tx_time_to_live: *cfg.transaction_time_to_live(), } } } diff --git a/crates/iroha_core/src/snapshot.rs b/crates/iroha_core/src/snapshot.rs index 602444ab46a..e4527e0d0a6 100644 --- a/crates/iroha_core/src/snapshot.rs +++ b/crates/iroha_core/src/snapshot.rs @@ -110,7 +110,7 @@ impl SnapshotMaker { let latest_block_hash = state.view().latest_block_hash(); Some(Self { state, - create_every: config.create_every().clone(), + create_every: *config.create_every(), store_dir: config.store_dir().resolve_relative_path(), latest_block_hash, }) diff --git a/crates/iroha_core/src/sumeragi/main_loop.rs b/crates/iroha_core/src/sumeragi/main_loop.rs index ac3a05d813a..c168de6e85f 100644 --- a/crates/iroha_core/src/sumeragi/main_loop.rs +++ b/crates/iroha_core/src/sumeragi/main_loop.rs @@ -324,7 +324,7 @@ impl Sumeragi { }) .collect::>() .join("\n"); - panic!("Genesis contains invalid transactions:\n{}", errors); + panic!("Genesis contains invalid transactions:\n {errors}"); } // NOTE: By this time genesis block is executed and list of trusted peers is updated diff --git a/crates/iroha_core/src/sumeragi/mod.rs b/crates/iroha_core/src/sumeragi/mod.rs index 36cd6ba0c68..c6371cef5ec 100644 --- a/crates/iroha_core/src/sumeragi/mod.rs +++ b/crates/iroha_core/src/sumeragi/mod.rs @@ -194,7 +194,7 @@ impl SumeragiStartArgs { for block in blocks_iter { let mut state_block = state.block(block.header()); SumeragiHandle::replay_block( - &common_config.chain(), + common_config.chain(), &genesis_account, &block, &mut state_block, @@ -219,7 +219,7 @@ impl SumeragiStartArgs { peers_gossiper, control_message_receiver, message_receiver, - debug_force_soft_fork: config.debug_force_soft_fork().clone(), + debug_force_soft_fork: *config.debug_force_soft_fork(), topology, transaction_cache: Vec::new(), #[cfg(feature = "telemetry")] diff --git a/crates/iroha_p2p/src/network.rs b/crates/iroha_p2p/src/network.rs index afc08e10853..838bd1cbdb8 100644 --- a/crates/iroha_p2p/src/network.rs +++ b/crates/iroha_p2p/src/network.rs @@ -113,7 +113,7 @@ impl NetworkBaseHandle { current_conn_id: 0, current_topology: HashSet::new(), current_peers_addresses: Vec::new(), - idle_timeout: config.idle_timeout().clone(), + idle_timeout: *config.idle_timeout(), _key_exchange: core::marker::PhantomData::, _encryptor: core::marker::PhantomData::, }; diff --git a/crates/iroha_telemetry/src/ws.rs b/crates/iroha_telemetry/src/ws.rs index 28e073ad3ba..0a6333f553e 100644 --- a/crates/iroha_telemetry/src/ws.rs +++ b/crates/iroha_telemetry/src/ws.rs @@ -40,8 +40,8 @@ pub async fn start( write, WebsocketSinkFactory::new(config.url().clone()), RetryPeriod::new( - config.min_retry_period().clone(), - config.max_retry_delay_exponent().clone(), + *config.min_retry_period(), + *config.max_retry_delay_exponent(), ), internal_sender, ); diff --git a/crates/iroha_test_network/src/lib.rs b/crates/iroha_test_network/src/lib.rs index 5058c9417d3..f41a695eebf 100644 --- a/crates/iroha_test_network/src/lib.rs +++ b/crates/iroha_test_network/src/lib.rs @@ -810,7 +810,7 @@ impl NetworkPeer { .parse() .expect("peer client config should be valid"); - Client::new(config) + Client::new(&config) } /// Client for Alice. ([`Self::client_for`] + [`Signatory::Alice`]) diff --git a/crates/iroha_torii/src/lib.rs b/crates/iroha_torii/src/lib.rs index 54c1b640f2a..37cb2ea0e88 100644 --- a/crates/iroha_torii/src/lib.rs +++ b/crates/iroha_torii/src/lib.rs @@ -71,7 +71,7 @@ impl Torii { pub fn new( chain_id: ChainId, kiso: KisoHandle, - config: Config, + config: &Config, queue: Arc, events: EventsSender, query_service: LiveQueryStoreHandle, @@ -90,7 +90,7 @@ impl Torii { #[cfg(feature = "telemetry")] metrics_reporter, address: config.address().clone(), - transaction_max_content_len: config.max_content_len().clone(), + transaction_max_content_len: *config.max_content_len(), } } diff --git a/crates/irohad/src/main.rs b/crates/irohad/src/main.rs index a180189cc9a..130dd3deb44 100644 --- a/crates/irohad/src/main.rs +++ b/crates/irohad/src/main.rs @@ -194,11 +194,9 @@ impl Iroha { let child = Kura::start(kura.clone(), supervisor.shutdown_signal()); supervisor.monitor(child); - let (live_query_store, child) = LiveQueryStore::from_config( - config.live_query_store().clone(), - supervisor.shutdown_signal(), - ) - .start(); + let (live_query_store, child) = + LiveQueryStore::from_config(*config.live_query_store(), supervisor.shutdown_signal()) + .start(); supervisor.monitor(child); let state = match try_read_snapshot( @@ -238,10 +236,7 @@ impl Iroha { let state = Arc::new(state); let (events_sender, _) = broadcast::channel(EVENTS_BUFFER_CAPACITY); - let queue = Arc::new(Queue::from_config( - config.queue().clone(), - events_sender.clone(), - )); + let queue = Arc::new(Queue::from_config(*config.queue(), events_sender.clone())); let (network, child) = IrohaNetwork::start( config.common().key_pair().clone(), @@ -265,14 +260,14 @@ impl Iroha { ); let (peers_gossiper, child) = PeersGossiper::start( - config.common().trusted_peers().value().clone(), + config.common().trusted_peers().value(), network.clone(), supervisor.shutdown_signal(), ); supervisor.monitor(child); let (sumeragi, child) = SumeragiStartArgs { - config: config.sumeragi().clone(), + config: *config.sumeragi(), common_config: config.common().clone(), events_sender: events_sender.clone(), state: state.clone(), @@ -295,7 +290,7 @@ impl Iroha { supervisor.monitor(child); let (block_sync, child) = BlockSynchronizer::from_config( - &config.block_sync(), + config.block_sync(), sumeragi.clone(), kura.clone(), config.common().peer().clone(), @@ -307,7 +302,7 @@ impl Iroha { let (tx_gossiper, child) = TransactionGossiper::from_config( config.common().chain().clone(), - config.transaction_gossiper().clone(), + *config.transaction_gossiper(), network.clone(), Arc::clone(&queue), Arc::clone(&state), @@ -332,13 +327,13 @@ impl Iroha { supervisor.monitor(snapshot_maker.start(supervisor.shutdown_signal())); } - let (kiso, child) = KisoHandle::start(config.clone()); + let (kiso, child) = KisoHandle::start(&config); supervisor.monitor(child); let torii_run = Torii::new( config.common().chain().clone(), kiso.clone(), - config.torii().clone(), + config.torii(), queue, events_sender, live_query_store, @@ -555,7 +550,7 @@ fn validate_config(config: &Config) -> Result<(), ConfigError> { } validate_directory_path(&mut emitter, config.kura().store_dir()); // maybe validate only if snapshot mode is enabled - validate_directory_path(&mut emitter, &config.snapshot().store_dir()); + validate_directory_path(&mut emitter, config.snapshot().store_dir()); if config.genesis().file().is_none() && !config @@ -581,7 +576,7 @@ fn validate_config(config: &Config) -> Result<(), ConfigError> { } #[cfg(not(feature = "telemetry"))] - if config.telemetry.is_some() { + if config.telemetry().is_some() { // TODO: use a centralized configuration logging // https://github.com/hyperledger-iroha/iroha/issues/4300 eprintln!("`telemetry` config is specified, but ignored, because Iroha is compiled without `telemetry` feature enabled");