Skip to content

Commit

Permalink
(fix) Validation fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
rrw-zilliqa committed Nov 19, 2024
1 parent 4ad5f0b commit 8ac089e
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 53 deletions.
6 changes: 3 additions & 3 deletions z2/src/deployer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -63,7 +63,7 @@ pub async fn install_or_upgrade(
node_selection: bool,
max_parallel: usize,
persistence_url: Option<String>,
machines: &Vec<String>,
machines: &[String],
) -> Result<()> {
let config = NetworkConfig::from_file(config_file).await?;
let mut chain = ChainInstance::new(config).await?;
Expand All @@ -75,7 +75,7 @@ pub async fn install_or_upgrade(
.collect::<Vec<_>>();

let selected_machines = if !machines.is_empty() {
machines.clone()
machines.to_owned()
} else if !node_selection {
node_names
} else {
Expand Down
6 changes: 3 additions & 3 deletions z2/src/plumbing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ pub async fn run_deployer_install(
node_selection: bool,
max_parallel: Option<usize>,
persistence_url: Option<String>,
machines: &Vec<String>,
machines: &[String],
) -> Result<()> {
println!("🦆 Installing {config_file} .. ");
deployer::install_or_upgrade(
Expand All @@ -195,7 +195,7 @@ pub async fn run_deployer_upgrade(
config_file: &str,
node_selection: bool,
max_parallel: Option<usize>,
machines: &Vec<String>,
machines: &[String],
) -> Result<()> {
println!("🦆 Upgrading {config_file} .. ");
deployer::install_or_upgrade(
Expand Down Expand Up @@ -484,7 +484,7 @@ pub async fn test(
base_dir: &str,
log_spec: &str,
watch: bool,
rest: &Vec<String>,
rest: &[String],
) -> Result<()> {
let mut setup_obj = setup::Setup::load(config_dir, log_spec, base_dir, watch).await?;
if rest.is_empty() {
Expand Down
17 changes: 9 additions & 8 deletions z2/src/setup.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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::{
Expand All @@ -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_";
Expand Down Expand Up @@ -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<Multiaddr> {
Expand Down
36 changes: 19 additions & 17 deletions z2/src/testing.rs
Original file line number Diff line number Diff line change
@@ -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 .
Expand Down Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -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::<u64>()?;
let end_ms = times[1].parse::<u64>()?;
entries.push(PartitionEntry {
nodes_to_talk_to,
nodes_to_tell,
Expand Down
3 changes: 2 additions & 1 deletion z2/src/zq2.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand Down
25 changes: 9 additions & 16 deletions zilliqa/src/block_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ impl BlockCache {
}

// Dump out a graphviz dotfile fragment containing the cache with links.
pub fn illustrate(&self, from_db: &Vec<Hash>) -> Result<String> {
pub fn illustrate(&self, from_db: &[Hash]) -> Result<String> {
// Print out the structure of the cache (fairly slowly!).
let mut by_hash: HashMap<Hash, HashSet<u128>> = HashMap::new();
let mut result = String::new();
Expand All @@ -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()) {
Expand Down Expand Up @@ -154,7 +151,7 @@ impl BlockCache {
}
}
}
result.push_str("\n");
result.push('\n');
Ok(result)
}

Expand Down Expand Up @@ -188,7 +185,7 @@ impl BlockCache {
Ok(self
.by_hash
.get(hash)
.map(|entry_set: &HashSet<u128>| {
.and_then(|entry_set: &HashSet<u128>| {
entry_set
.iter()
.take(1)
Expand All @@ -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
Expand Down Expand Up @@ -276,7 +272,7 @@ impl BlockCache {
.head_cache
.range::<u128, _>((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
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -1515,7 +1508,7 @@ impl BlockStore {
}
}

pub fn illustrate(&self, from_db: &Vec<Hash>) -> Result<String> {
pub fn illustrate(&self, from_db: &[Hash]) -> Result<String> {
self.buffered.illustrate(from_db)
}
}
3 changes: 1 addition & 2 deletions zilliqa/src/cfg.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion zilliqa/src/director.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down
2 changes: 1 addition & 1 deletion zilliqa/tests/it/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ async fn block_production(mut network: Network) {
.map_or(0, |b| b.number())
>= 5
},
50,
100,
)
.await
.unwrap();
Expand Down
2 changes: 1 addition & 1 deletion zilliqa/tests/it/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 8ac089e

Please sign in to comment.