Skip to content

Commit

Permalink
Several corrections on naming and coding style
Browse files Browse the repository at this point in the history
  • Loading branch information
ElFantasma committed Feb 15, 2024
1 parent 1ef6877 commit 5e8b011
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 27 deletions.
11 changes: 4 additions & 7 deletions node/tools/src/bin/deployer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@ use clap::{Parser, Subcommand};
use rand::Rng;
use zksync_consensus_crypto::{Text, TextFmt};
use zksync_consensus_roles::node::SecretKey;
use zksync_consensus_tools::k8s;
use zksync_consensus_tools::AppConfig;
use zksync_consensus_tools::NodeAddr;
use zksync_consensus_tools::{k8s, AppConfig, NodeAddr, NODES_PORT};

const NAMESPACE: &str = "consensus";
const NODES_PORT: u16 = 3054;

/// Command line arguments.
#[derive(Debug, Parser)]
Expand Down Expand Up @@ -98,7 +95,7 @@ async fn deploy(nodes: usize) -> anyhow::Result<()> {

// deploy seed peer(s)
for i in 0..seed_nodes {
k8s::create_deployment(
k8s::deploy_node(
&client,
i,
true,
Expand All @@ -109,7 +106,7 @@ async fn deploy(nodes: usize) -> anyhow::Result<()> {
}

// obtain seed peer(s) IP(s)
let peer_ips = k8s::get_seed_node_addrs(&client, seed_nodes).await?;
let peer_ips = k8s::get_seed_node_addrs(&client, seed_nodes, NAMESPACE).await?;

let mut peers = vec![];

Expand All @@ -125,7 +122,7 @@ async fn deploy(nodes: usize) -> anyhow::Result<()> {

// deploy the rest of nodes
for i in seed_nodes..nodes {
k8s::create_deployment(&client, i, false, peers.clone(), NAMESPACE).await?;
k8s::deploy_node(&client, i, false, peers.clone(), NAMESPACE).await?;
}

Ok(())
Expand Down
18 changes: 8 additions & 10 deletions node/tools/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use zksync_consensus_storage::{BlockStore, BlockStoreRunner, PersistentBlockStor
use zksync_protobuf::{required, serde::Serde, ProtoFmt};

/// Ports for the nodes to listen on kubernetes pod.
const NODES_PORT: u16 = 3054;
pub const NODES_PORT: u16 = 3054;

/// Decodes a proto message from json for arbitrary ProtoFmt.
pub fn decode_json<T: serde::de::DeserializeOwned>(json: &str) -> anyhow::Result<T> {
Expand Down Expand Up @@ -89,15 +89,6 @@ pub struct AppConfig {
pub gossip_static_outbound: HashMap<node::PublicKey, SocketAddr>,
}

impl AppConfig {
pub fn check_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}"))?;
}
Ok(())
}
}

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

Expand Down Expand Up @@ -304,6 +295,13 @@ impl AppConfig {
self.max_payload_size = max_payload_size;
self
}

pub fn check_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}"))?;
}
Ok(())
}
}

impl Configs {
Expand Down
19 changes: 10 additions & 9 deletions node/tools/src/k8s.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ pub async fn create_or_reuse_namespace(client: &Client, name: &str) -> anyhow::R
"apiVersion": "v1",
"kind": "Namespace",
"metadata": {
"name": "consensus",
"name": name,
"labels": {
"name": "consensus"
"name": name
}
}
}))?;
Expand Down Expand Up @@ -64,22 +64,22 @@ pub async fn create_or_reuse_namespace(client: &Client, name: &str) -> anyhow::R
}

/// Creates a deployment
pub async fn create_deployment(
pub async fn deploy_node(
client: &Client,
node_number: usize,
node_index: usize,
is_seed: bool,
peers: Vec<NodeAddr>,
namespace: &str,
) -> anyhow::Result<()> {
let cli_args = get_cli_args(peers);
let node_name = format!("consensus-node-{node_number:0>2}");
let node_id = format!("node_{node_number:0>2}");
let node_name = format!("consensus-node-{node_index:0>2}");
let node_id = format!("node_{node_index:0>2}");
let deployment: Deployment = serde_json::from_value(json!({
"apiVersion": "apps/v1",
"kind": "Deployment",
"metadata": {
"name": node_name,
"namespace": "consensus"
"namespace": namespace
},
"spec": {
"selector": {
Expand Down Expand Up @@ -120,7 +120,7 @@ pub async fn create_deployment(
"imagePullPolicy": "Never",
"ports": [
{
"containerPort": 3054
"containerPort": config::NODES_PORT
},
{
"containerPort": 3154
Expand Down Expand Up @@ -163,9 +163,10 @@ pub async fn create_deployment(
pub async fn get_seed_node_addrs(
client: &Client,
amount: usize,
namespace: &str,
) -> anyhow::Result<HashMap<String, String>> {
let mut seed_nodes = HashMap::new();
let pods: Api<Pod> = Api::namespaced(client.clone(), "consensus");
let pods: Api<Pod> = Api::namespaced(client.clone(), namespace);

// Will retry 15 times during 15 seconds to allow pods to start and obtain an IP
let retry_strategy = FixedInterval::from_millis(1000).take(15);
Expand Down
2 changes: 1 addition & 1 deletion node/tools/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ mod store;
#[cfg(test)]
mod tests;

pub use config::{decode_json, AppConfig, ConfigPaths, NodeAddr};
pub use config::{decode_json, AppConfig, ConfigPaths, NodeAddr, NODES_PORT};
pub use rpc::server::RPCServer;

0 comments on commit 5e8b011

Please sign in to comment.