diff --git a/z2/src/deployer.rs b/z2/src/deployer.rs index f52b2193a..ac95cc85b 100644 --- a/z2/src/deployer.rs +++ b/z2/src/deployer.rs @@ -8,11 +8,11 @@ use tokio::{fs, sync::Semaphore, task}; use crate::{ address::EthereumAddress, - chain::Chain, chain::{ config::NetworkConfig, instance::ChainInstance, node::{self, ChainNode, NodeRole}, + Chain, }, secret::Secret, validators, @@ -63,7 +63,7 @@ pub async fn install_or_upgrade( node_selection: bool, max_parallel: usize, persistence_url: Option, - machines: &Vec, + machines: &[String], ) -> Result<()> { let config = NetworkConfig::from_file(config_file).await?; let mut chain = ChainInstance::new(config).await?; @@ -75,7 +75,7 @@ pub async fn install_or_upgrade( .collect::>(); let selected_machines = if !machines.is_empty() { - machines.clone() + machines.to_owned() } else if !node_selection { node_names } else { diff --git a/z2/src/plumbing.rs b/z2/src/plumbing.rs index 04f06d23e..3c816c1af 100644 --- a/z2/src/plumbing.rs +++ b/z2/src/plumbing.rs @@ -176,7 +176,7 @@ pub async fn run_deployer_install( node_selection: bool, max_parallel: Option, persistence_url: Option, - machines: &Vec, + machines: &[String], ) -> Result<()> { println!("🦆 Installing {config_file} .. "); deployer::install_or_upgrade( @@ -195,7 +195,7 @@ pub async fn run_deployer_upgrade( config_file: &str, node_selection: bool, max_parallel: Option, - machines: &Vec, + machines: &[String], ) -> Result<()> { println!("🦆 Upgrading {config_file} .. "); deployer::install_or_upgrade( @@ -484,7 +484,7 @@ pub async fn test( base_dir: &str, log_spec: &str, watch: bool, - rest: &Vec, + rest: &[String], ) -> Result<()> { let mut setup_obj = setup::Setup::load(config_dir, log_spec, base_dir, watch).await?; if rest.is_empty() { diff --git a/z2/src/setup.rs b/z2/src/setup.rs index 4f9d48d86..e9683b8fe 100644 --- a/z2/src/setup.rs +++ b/z2/src/setup.rs @@ -1,4 +1,10 @@ -use crate::address::EthereumAddress; +use core::net::Ipv4Addr; +use std::{ + collections::HashMap, + path::{Path, PathBuf}, + str::FromStr, +}; + use alloy::{ primitives::{address, Address}, signers::local::LocalSigner, @@ -8,11 +14,6 @@ use k256::ecdsa::SigningKey; use libp2p::{Multiaddr, PeerId}; use serde::{Deserialize, Serialize}; use serde_yaml; -use std::{ - collections::HashMap, - path::{Path, PathBuf}, - str::FromStr, -}; use tera::Tera; use tokio::fs; use zilliqa::{ @@ -36,13 +37,13 @@ use zilliqa::{ }; use crate::{ + address::EthereumAddress, chain, collector::{self, Collector}, components::{Component, Requirements}, node_spec::Composition, scilla, utils, validators, }; -use core::net::Ipv4Addr; const GENESIS_DEPOSIT: u128 = 10000000000000000000000000; const DATADIR_PREFIX: &str = "z2_node_"; @@ -277,7 +278,7 @@ impl Setup { } pub fn get_p2p_port(&self, index: u16) -> u16 { - return self.config.base_port + 301 + index + self.config.base_port; + self.config.base_port + 301 + index + self.config.base_port } pub fn get_external_addr(&self, index: u16) -> Result { diff --git a/z2/src/testing.rs b/z2/src/testing.rs index 130e5e594..9495a769f 100644 --- a/z2/src/testing.rs +++ b/z2/src/testing.rs @@ -1,17 +1,25 @@ // Code to stress-test z2 networks. #![allow(unused_imports)] -use crate::{node_spec, setup::Setup}; +use std::{ + cmp::{Ordering, PartialOrd}, + collections::{BinaryHeap, HashSet}, +}; + use anyhow::{anyhow, Error, Result}; -use jsonrpsee::core::{client::ClientT, params::ArrayParams}; -use jsonrpsee::http_client::HttpClientBuilder; -use jsonrpsee::rpc_params; -use std::cmp::{Ordering, PartialOrd}; -use std::collections::{BinaryHeap, HashSet}; -use tokio::process::Command; -use tokio::time::{self, Duration, Instant}; +use jsonrpsee::{ + core::{client::ClientT, params::ArrayParams}, + http_client::HttpClientBuilder, + rpc_params, +}; +use tokio::{ + process::Command, + time::{self, Duration, Instant}, +}; use tower_http::trace::TraceLayer; +use crate::{node_spec, setup::Setup}; + // This is inherently reversed, since BinaryHeap is a max-heap // Not very artistic, but it'll do . @@ -43,13 +51,7 @@ struct HeapEntry { impl Ord for HeapEntry { fn cmp(&self, other: &Self) -> Ordering { // Backwards because BinaryHeap is a max-heap. - if self.when_ms > other.when_ms { - Ordering::Less - } else if self.when_ms < other.when_ms { - Ordering::Greater - } else { - Ordering::Equal - } + other.when_ms.cmp(&self.when_ms) } } @@ -103,8 +105,8 @@ impl Partition { if times.len() != 2 { return Err(anyhow!("Arg '{arg}' - there must be two times, separated by a '/' after the ':' - found {0}", times.len())); } - let start_ms = u64::from_str_radix(times[0], 10)?; - let end_ms = u64::from_str_radix(times[1], 10)?; + let start_ms = times[0].parse::()?; + let end_ms = times[1].parse::()?; entries.push(PartitionEntry { nodes_to_talk_to, nodes_to_tell, diff --git a/z2/src/zq2.rs b/z2/src/zq2.rs index f2607a964..ce2028619 100644 --- a/z2/src/zq2.rs +++ b/z2/src/zq2.rs @@ -1,6 +1,7 @@ +use std::env; + use anyhow::Result; use futures::future::JoinAll; -use std::env; use tokio::{process::Command, sync::mpsc, task::JoinHandle}; use crate::{ diff --git a/zilliqa/src/block_store.rs b/zilliqa/src/block_store.rs index 31143a69b..e8f16eb3c 100644 --- a/zilliqa/src/block_store.rs +++ b/zilliqa/src/block_store.rs @@ -107,7 +107,7 @@ impl BlockCache { } // Dump out a graphviz dotfile fragment containing the cache with links. - pub fn illustrate(&self, from_db: &Vec) -> Result { + pub fn illustrate(&self, from_db: &[Hash]) -> Result { // Print out the structure of the cache (fairly slowly!). let mut by_hash: HashMap> = HashMap::new(); let mut result = String::new(); @@ -123,10 +123,7 @@ impl BlockCache { for (key, entry) in self.cache.iter().chain(self.head_cache.iter()) { let hash = entry.proposal.hash(); - by_hash - .entry(hash) - .or_insert_with(|| HashSet::new()) - .insert(*key); + by_hash.entry(hash).or_default().insert(*key); } for (key, entry) in self.cache.iter().chain(self.head_cache.iter()) { @@ -154,7 +151,7 @@ impl BlockCache { } } } - result.push_str("\n"); + result.push('\n'); Ok(result) } @@ -188,7 +185,7 @@ impl BlockCache { Ok(self .by_hash .get(hash) - .map(|entry_set: &HashSet| { + .and_then(|entry_set: &HashSet| { entry_set .iter() .take(1) @@ -199,8 +196,7 @@ impl BlockCache { .map(|entry| entry.proposal.clone()) }) .last() - }) - .flatten()) + })) } /// Find any view gaps known to exist in the cache and add them to the known view gap @@ -276,7 +272,7 @@ impl BlockCache { .head_cache .range::((Bound::Included(key), Bound::Unbounded)); if let Some((_, v)) = head_iter.next() { - return Some((v.proposal.view(), v.proposal.number())); + Some((v.proposal.view(), v.proposal.number())) } else { None } @@ -494,11 +490,8 @@ impl BlockCache { .get_mut(&entry.parent_hash) .map(|x| x.remove(&key)) }); - by_parent_hash - .entry(*parent_hash) - .or_insert(HashSet::new()) - .insert(key); - by_hash.entry(hash).or_insert(HashSet::new()).insert(key); + by_parent_hash.entry(*parent_hash).or_default().insert(key); + by_hash.entry(hash).or_default().insert(key); } if proposal.header.view <= highest_confirmed_view { @@ -1515,7 +1508,7 @@ impl BlockStore { } } - pub fn illustrate(&self, from_db: &Vec) -> Result { + pub fn illustrate(&self, from_db: &[Hash]) -> Result { self.buffered.illustrate(from_db) } } diff --git a/zilliqa/src/cfg.rs b/zilliqa/src/cfg.rs index d4ace0a9e..c0546c331 100644 --- a/zilliqa/src/cfg.rs +++ b/zilliqa/src/cfg.rs @@ -1,4 +1,4 @@ -use std::{ops::Deref, str::FromStr, time::Duration}; +use std::{net::Ipv4Addr, ops::Deref, str::FromStr, time::Duration}; use alloy::primitives::Address; use libp2p::{Multiaddr, PeerId}; @@ -9,7 +9,6 @@ use crate::{ crypto::{Hash, NodePublicKey}, transaction::EvmGas, }; -use std::net::Ipv4Addr; // Note that z2 constructs instances of this to save as a configuration so it must be both // serializable and deserializable. diff --git a/zilliqa/src/director.rs b/zilliqa/src/director.rs index 15e06be45..c324990cb 100644 --- a/zilliqa/src/director.rs +++ b/zilliqa/src/director.rs @@ -1,8 +1,9 @@ // Director: directs the behaviour of other parts of the system. +use std::collections::HashSet; + use anyhow::Result; use libp2p::PeerId; -use std::collections::HashSet; use tracing::*; #[derive(Debug)] diff --git a/zilliqa/tests/it/consensus.rs b/zilliqa/tests/it/consensus.rs index 9e2c6099a..9764f665b 100644 --- a/zilliqa/tests/it/consensus.rs +++ b/zilliqa/tests/it/consensus.rs @@ -99,7 +99,7 @@ async fn block_production(mut network: Network) { .map_or(0, |b| b.number()) >= 5 }, - 50, + 100, ) .await .unwrap(); diff --git a/zilliqa/tests/it/eth.rs b/zilliqa/tests/it/eth.rs index 54d55ed00..73750d05b 100644 --- a/zilliqa/tests/it/eth.rs +++ b/zilliqa/tests/it/eth.rs @@ -1427,7 +1427,7 @@ async fn test_eth_syncing(mut network: Network) { network .run_until_async( || async { wallet.get_block_number().await.unwrap().as_u64() > 4 }, - 50, + 100, ) .await .unwrap();