Skip to content

Commit

Permalink
everything compiles
Browse files Browse the repository at this point in the history
  • Loading branch information
pompon0 committed Mar 26, 2024
1 parent ae381b8 commit 5b58d5e
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 31 deletions.
1 change: 0 additions & 1 deletion node/actors/bft/src/testonly/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ async fn run_nodes(ctx: &ctx::Ctx, network: Network, specs: &[Node]) -> anyhow::
let mut nodes = vec![];
for (i, spec) in specs.iter().enumerate() {
let (node, runner) = network::testonly::Instance::new(
ctx,
spec.net.clone(),
spec.block_store.clone(),
);
Expand Down
7 changes: 3 additions & 4 deletions node/actors/executor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub struct Config {
pub server_addr: std::net::SocketAddr,
/// Public TCP address that other nodes are expected to connect to.
/// It is announced over gossip network.
pub public_addr: std::net::SocketAddr,
pub public_addr: net::Host,
/// Maximal size of the block payload.
pub max_payload_size: usize,

Expand All @@ -59,7 +59,7 @@ pub struct Config {
pub gossip_static_inbound: HashSet<node::PublicKey>,
/// Outbound connections that the node should actively try to
/// establish and maintain.
pub gossip_static_outbound: HashMap<node::PublicKey, std::net::SocketAddr>,
pub gossip_static_outbound: HashMap<node::PublicKey, net::Host>,
}

impl Config {
Expand Down Expand Up @@ -90,7 +90,7 @@ impl Executor {
fn network_config(&self) -> network::Config {
network::Config {
server_addr: net::tcp::ListenerAddr::new(self.config.server_addr),
public_addr: self.config.public_addr,
public_addr: self.config.public_addr.clone(),
gossip: self.config.gossip(),
validator_key: self.validator.as_ref().map(|v| v.key.clone()),
ping_timeout: Some(time::Duration::seconds(10)),
Expand Down Expand Up @@ -136,7 +136,6 @@ impl Executor {
s.spawn_blocking(|| dispatcher.run(ctx).context("IO Dispatcher stopped"));
s.spawn(async {
let (net, runner) = network::Network::new(
ctx,
network_config,
self.block_store.clone(),
network_actor_pipe,
Expand Down
2 changes: 1 addition & 1 deletion node/actors/executor/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use zksync_consensus_storage::{
fn config(cfg: &network::Config) -> Config {
Config {
server_addr: *cfg.server_addr,
public_addr: cfg.public_addr,
public_addr: cfg.public_addr.clone(),
max_payload_size: usize::MAX,
node_key: cfg.gossip.key.clone(),
gossip_dynamic_inbound_limit: cfg.gossip.dynamic_inbound_limit,
Expand Down
2 changes: 1 addition & 1 deletion node/actors/sync_blocks/src/tests/end_to_end.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl NodeRunner {
let key = self.network.gossip.key.public();
let (sync_blocks_actor_pipe, sync_blocks_dispatcher_pipe) = pipe::new();
let (mut network, network_runner) =
network::testonly::Instance::new(ctx, self.network.clone(), self.store.clone());
network::testonly::Instance::new(self.network.clone(), self.store.clone());
let sync_blocks_config = Config::new();
let res = scope::run!(ctx, |ctx, s| async {
s.spawn_bg(self.store_runner.run(ctx));
Expand Down
6 changes: 3 additions & 3 deletions node/tools/src/bin/localnet_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,21 @@ fn main() -> anyhow::Result<()> {
default_config.with_metrics_server_addr(metrics_server_addr);
}
let mut cfgs: Vec<_> = (0..nodes)
.map(|i| default_config.with_public_addr(addrs[i]).clone())
.map(|i| default_config.with_public_addr(addrs[i].into()).clone())
.collect();

// Construct a gossip network with optimal diameter.
for i in 0..nodes {
for j in 0..peers {
let next = (i * peers + j + 1) % nodes;
cfgs[i].add_gossip_static_outbound(node_keys[next].public(), addrs[next]);
cfgs[i].add_gossip_static_outbound(node_keys[next].public(), addrs[next].into());
cfgs[next].add_gossip_static_inbound(node_keys[i].public());
}
}

for (i, cfg) in cfgs.into_iter().enumerate() {
// Recreate the directory for the node's config.
let root = args.output_dir.join(cfg.public_addr.to_string());
let root = args.output_dir.join(&cfg.public_addr.0);
let _ = fs::remove_dir_all(&root);
fs::create_dir_all(&root).with_context(|| format!("create_dir_all({:?})", root))?;
cfg.write_to_file(&root)?;
Expand Down
33 changes: 17 additions & 16 deletions node/tools/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::{
path::{Path, PathBuf},
str::FromStr,
};
use zksync_concurrency::ctx;
use zksync_concurrency::{ctx,net};
use zksync_consensus_bft as bft;
use zksync_consensus_crypto::{read_optional_text, read_required_text, Text, TextFmt};
use zksync_consensus_executor as executor;
Expand Down Expand Up @@ -43,26 +43,26 @@ pub(crate) fn encode_with_serializer<T: serde::ser::Serialize, F: Formatter>(
String::from_utf8(serializer.into_inner()).unwrap()
}

/// Pair of (public key, ip address) for a gossip network node.
/// Pair of (public key, host addr) for a gossip network node.
#[derive(Debug, Clone)]
pub struct NodeAddr {
pub key: node::PublicKey,
pub addr: SocketAddr,
pub addr: net::Host,
}

impl ProtoFmt for NodeAddr {
type Proto = proto::NodeAddr;

fn read(r: &Self::Proto) -> anyhow::Result<Self> {
let key = read_required_text(&r.key).context("key")?;
let addr = read_required_text(&r.addr).context("addr")?;
let addr = net::Host(required(&r.addr).context("addr")?.clone());
Ok(Self { addr, key })
}

fn build(&self) -> Self::Proto {
Self::Proto {
key: Some(TextFmt::encode(&self.key)),
addr: Some(TextFmt::encode(&self.addr)),
addr: Some(self.addr.0.clone()),
}
}
}
Expand All @@ -72,15 +72,15 @@ impl ProtoFmt for NodeAddr {
#[derive(Debug, PartialEq, Clone)]
pub struct AppConfig {
pub server_addr: SocketAddr,
pub public_addr: SocketAddr,
pub public_addr: net::Host,
pub metrics_server_addr: Option<SocketAddr>,

pub genesis: validator::Genesis,
pub max_payload_size: usize,

pub gossip_dynamic_inbound_limit: usize,
pub gossip_static_inbound: HashSet<node::PublicKey>,
pub gossip_static_outbound: HashMap<node::PublicKey, SocketAddr>,
pub gossip_static_outbound: HashMap<node::PublicKey, net::Host>,
}

impl ProtoFmt for AppConfig {
Expand All @@ -104,7 +104,7 @@ impl ProtoFmt for AppConfig {
}
Ok(Self {
server_addr: read_required_text(&r.server_addr).context("server_addr")?,
public_addr: read_required_text(&r.public_addr).context("public_addr")?,
public_addr: net::Host(required(&r.public_addr).context("public_addr")?.clone()),
metrics_server_addr: read_optional_text(&r.metrics_server_addr)
.context("metrics_server_addr")?,

Expand All @@ -124,7 +124,7 @@ impl ProtoFmt for AppConfig {
fn build(&self) -> Self::Proto {
Self::Proto {
server_addr: Some(self.server_addr.encode()),
public_addr: Some(self.public_addr.encode()),
public_addr: Some(self.public_addr.0.clone()),
metrics_server_addr: self.metrics_server_addr.as_ref().map(TextFmt::encode),

genesis: Some(self.genesis.build()),
Expand All @@ -143,7 +143,7 @@ impl ProtoFmt for AppConfig {
.iter()
.map(|(key, addr)| proto::NodeAddr {
key: Some(TextFmt::encode(key)),
addr: Some(TextFmt::encode(addr)),
addr: Some(addr.0.clone()),
})
.collect(),
}
Expand Down Expand Up @@ -234,7 +234,7 @@ impl AppConfig {
pub fn default_for(genesis: validator::Genesis) -> AppConfig {
Self {
server_addr: SocketAddr::new(Ipv4Addr::UNSPECIFIED.into(), NODES_PORT),
public_addr: SocketAddr::new(Ipv4Addr::UNSPECIFIED.into(), NODES_PORT),
public_addr: SocketAddr::new(Ipv4Addr::LOCALHOST.into(), NODES_PORT).into(),
metrics_server_addr: None,

genesis,
Expand All @@ -251,7 +251,7 @@ impl AppConfig {
self
}

pub fn with_public_addr(&mut self, public_addr: SocketAddr) -> &mut Self {
pub fn with_public_addr(&mut self, public_addr: net::Host) -> &mut Self {
self.public_addr = public_addr;
self
}
Expand All @@ -272,7 +272,7 @@ impl AppConfig {
pub fn add_gossip_static_outbound(
&mut self,
key: node::PublicKey,
addr: SocketAddr,
addr: net::Host,
) -> &mut Self {
self.gossip_static_outbound.insert(key, addr);
self
Expand All @@ -292,9 +292,10 @@ impl AppConfig {
self
}

pub fn check_public_addr(&mut self) -> anyhow::Result<()> {
/// Tries to load the public_addr IP from the env var.
pub fn try_load_public_addr(&mut self) -> anyhow::Result<()> {
if let Ok(public_addr) = std::env::var("PUBLIC_ADDR") {
self.public_addr = SocketAddr::from_str(&format!("{public_addr}:{NODES_PORT}"))?;
self.public_addr = SocketAddr::from_str(&format!("{public_addr}:{NODES_PORT}"))?.into();
}
Ok(())
}
Expand All @@ -310,7 +311,7 @@ impl Configs {
let e = executor::Executor {
config: executor::Config {
server_addr: self.app.server_addr,
public_addr: self.app.public_addr,
public_addr: self.app.public_addr.clone(),
node_key: self.node_key.clone(),
gossip_dynamic_inbound_limit: self.app.gossip_dynamic_inbound_limit,
gossip_static_inbound: self.app.gossip_static_inbound.clone(),
Expand Down
2 changes: 1 addition & 1 deletion node/tools/src/k8s.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl ConsensusNode {
.context("Pod IP address not present")?;
self.node_addr = Some(NodeAddr {
key: self.key.public(),
addr: SocketAddr::new(ip.parse()?, config::NODES_PORT),
addr: SocketAddr::new(ip.parse()?, config::NODES_PORT).into(),
});
Ok(())
}
Expand Down
4 changes: 2 additions & 2 deletions node/tools/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,14 @@ async fn main() -> anyhow::Result<()> {
let mut configs = args.config_args().load().context("config_args().load()")?;

// if `PUBLIC_ADDR` env var is set, use it to override publicAddr in config
configs.app.check_public_addr().context("Public Address")?;
configs.app.try_load_public_addr().context("Public Address")?;

let (executor, runner) = configs
.make_executor(ctx)
.await
.context("configs.into_executor()")?;

let mut rpc_addr = configs.app.public_addr;
let mut rpc_addr = configs.app.server_addr;
if let Some(port) = args.rpc_port {
rpc_addr.set_port(port);
} else {
Expand Down
4 changes: 2 additions & 2 deletions node/tools/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ impl Distribution<AppConfig> for Standard {
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> AppConfig {
AppConfig {
server_addr: make_addr(rng),
public_addr: make_addr(rng),
public_addr: make_addr(rng).into(),
metrics_server_addr: Some(make_addr(rng)),

genesis: rng.gen(),
Expand All @@ -27,7 +27,7 @@ impl Distribution<AppConfig> for Standard {
.map(|_| rng.gen::<node::SecretKey>().public())
.collect(),
gossip_static_outbound: (0..6)
.map(|_| (rng.gen::<node::SecretKey>().public(), make_addr(rng)))
.map(|_| (rng.gen::<node::SecretKey>().public(), make_addr(rng).into()))
.collect(),
max_payload_size: rng.gen(),
}
Expand Down

0 comments on commit 5b58d5e

Please sign in to comment.