Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(configs): Add port parameter to ConsensusConfig #2986

Merged
merged 29 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
68fc9e4
Update consensus config
matias-gonz Sep 30, 2024
0d87c22
Fix executor config
matias-gonz Sep 30, 2024
f2adb09
Fix make_config
matias-gonz Sep 30, 2024
328bd32
Update proto
matias-gonz Sep 30, 2024
73dddab
Reserve fields
matias-gonz Sep 30, 2024
88b7023
Fix reserved
matias-gonz Sep 30, 2024
85f81cf
Fix reserved
matias-gonz Sep 30, 2024
c4e9c04
Fix duplicated reserved name
matias-gonz Sep 30, 2024
55b60e1
lint
matias-gonz Oct 1, 2024
480a747
Remove unused import
matias-gonz Oct 1, 2024
fc84686
add consensus to general yaml
matias-gonz Oct 2, 2024
f8a2103
Remove manual main node port allocation for reapre configs
matias-gonz Oct 2, 2024
fd2902f
Refactor `prepare_configs`
matias-gonz Oct 2, 2024
ac46b2e
Merge branch 'main' of github.com:matter-labs/zksync-era into matias-…
matias-gonz Oct 2, 2024
d34a546
Remove DEFAULT_CONSENSUS_PORT
matias-gonz Oct 2, 2024
d45d768
Merge branch 'main' into matias-consensus-ports
matias-gonz Oct 2, 2024
2c2a658
Use get_genesis_specs in chain init
matias-gonz Oct 2, 2024
044c356
Remove `get_consensus_config`
matias-gonz Oct 2, 2024
8b93be3
Make it backward compatible
matias-gonz Oct 2, 2024
ff2ca1d
Update consensus deserialize
matias-gonz Oct 2, 2024
626cf52
Rollback url rename
matias-gonz Oct 2, 2024
aedfa54
Fix executor
matias-gonz Oct 2, 2024
db3b7e0
Fix testonly
matias-gonz Oct 2, 2024
368af7d
Remove unnecessary match
matias-gonz Oct 2, 2024
8adfd5b
Merge branch 'main' into matias-consensus-ports
matias-gonz Oct 2, 2024
66995f5
Merge branch 'main' of github.com:matter-labs/zksync-era into matias-…
matias-gonz Oct 3, 2024
7ddc653
Merge branch 'main' into matias-consensus-ports
matias-gonz Oct 7, 2024
cc467c5
Merge branch 'main' into matias-consensus-ports
matias-gonz Oct 8, 2024
8ef95c3
Merge branch 'main' into matias-consensus-ports
Deniallugo Oct 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions core/lib/config/src/configs/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,13 @@ impl RpcConfig {
/// Config (shared between main node and external node).
#[derive(Clone, Debug, PartialEq)]
pub struct ConsensusConfig {
pub port: u16,
Deniallugo marked this conversation as resolved.
Show resolved Hide resolved
/// Local socket address to listen for the incoming connections.
pub server_addr: std::net::SocketAddr,
pub server_url: std::net::SocketAddr,
/// Public address of this node (should forward to `server_addr`)
/// that will be advertised to peers, so that they can connect to this
/// node.
pub public_addr: Host,
pub public_url: Host,
Deniallugo marked this conversation as resolved.
Show resolved Hide resolved

/// Maximal allowed size of the payload in bytes.
pub max_payload_size: usize,
Expand Down
5 changes: 3 additions & 2 deletions core/lib/config/src/testonly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -799,8 +799,9 @@ impl Distribution<configs::consensus::ConsensusConfig> for EncodeDist {
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> configs::consensus::ConsensusConfig {
use configs::consensus::{ConsensusConfig, Host, NodePublicKey};
ConsensusConfig {
server_addr: self.sample(rng),
public_addr: Host(self.sample(rng)),
port: self.sample(rng),
server_url: self.sample(rng),
public_url: Host(self.sample(rng)),
max_payload_size: self.sample(rng),
max_batch_size: self.sample(rng),
gossip_dynamic_inbound_limit: self.sample(rng),
Expand Down
14 changes: 9 additions & 5 deletions core/lib/protobuf_config/src/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,13 @@ impl ProtoRepr for proto::Config {
};

Ok(Self::Type {
server_addr: required(&self.server_addr)
port: required(&self.port)
.and_then(|x| Ok((*x).try_into()?))
.context("port")?,
server_url: required(&self.server_url)
.and_then(|x| Ok(x.parse()?))
.context("server_addr")?,
public_addr: Host(required(&self.public_addr).context("public_addr")?.clone()),
.context("server_url")?,
public_url: Host(required(&self.public_url).context("public_url")?.clone()),
max_payload_size,
max_batch_size,
gossip_dynamic_inbound_limit: required(&self.gossip_dynamic_inbound_limit)
Expand Down Expand Up @@ -182,8 +185,9 @@ impl ProtoRepr for proto::Config {

fn build(this: &Self::Type) -> Self {
Self {
server_addr: Some(this.server_addr.to_string()),
public_addr: Some(this.public_addr.0.clone()),
port: Some(this.port.into()),
server_url: Some(this.server_url.to_string()),
public_url: Some(this.public_url.0.clone()),
max_payload_size: Some(this.max_payload_size.try_into().unwrap()),
max_batch_size: Some(this.max_batch_size.try_into().unwrap()),
gossip_dynamic_inbound_limit: Some(
Expand Down
13 changes: 10 additions & 3 deletions core/lib/protobuf_config/src/proto/core/consensus.proto
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,23 @@ message RpcConfig {
}

message Config {
reserved 1;
reserved "server_addr";
reserved 2;
reserved "public_addr";
reserved 3;
reserved "validators";

// Port to listen on, for incoming TCP connections.
optional uint32 port = 12; // required

// IP:port to listen on, for incoming TCP connections.
// Use `0.0.0.0:<port>` to listen on all network interfaces (i.e. on all IPs exposed by this VM).
optional string server_addr = 1; // required; IpAddr
optional string server_url = 13; // required; IpAddr

// Public IP:port to advertise, should forward to server_addr.
// Public IP:port to advertise, should forward to server_url.
// Can be `127.0.0.1:<port>` for local tests.
optional string public_addr = 2; // required; Host
optional string public_url = 14; // required; Host

// Maximal allowed size of the payload.
optional uint64 max_payload_size = 4; // required; bytes
Expand Down
4 changes: 2 additions & 2 deletions core/node/consensus/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ pub(super) fn executor(

Ok(executor::Config {
build_version,
server_addr: cfg.server_addr,
public_addr: net::Host(cfg.public_addr.0.clone()),
server_addr: cfg.server_url,
public_addr: net::Host(cfg.public_url.0.clone()),
max_payload_size: cfg.max_payload_size,
max_batch_size: cfg.max_batch_size,
node_key: node_key(secrets)
Expand Down
5 changes: 3 additions & 2 deletions core/node/consensus/src/testonly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,9 @@ fn make_config(
genesis_spec: Option<config::GenesisSpec>,
) -> config::ConsensusConfig {
config::ConsensusConfig {
server_addr: *cfg.server_addr,
public_addr: config::Host(cfg.public_addr.0.clone()),
port: cfg.server_addr.port(),
server_url: *cfg.server_addr,
public_url: config::Host(cfg.public_addr.0.clone()),
max_payload_size: usize::MAX,
max_batch_size: usize::MAX,
gossip_dynamic_inbound_limit: cfg.gossip.dynamic_inbound_limit,
Expand Down
5 changes: 3 additions & 2 deletions etc/env/consensus_config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
server_addr: "127.0.0.1:3054"
public_addr: "127.0.0.1:3054"
port: 3054
server_url: "127.0.0.1:3054"
public_url: "127.0.0.1:3054"
max_payload_size: 2500000
gossip_dynamic_inbound_limit: 1
# LOCALHOST TEST CONFIGURATION ONLY, don't copy to other environments.
Expand Down
5 changes: 3 additions & 2 deletions etc/env/en_consensus_config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
server_addr: '127.0.0.1:3055'
public_addr: '127.0.0.1:3055'
port: 3055
server_url: '127.0.0.1:3055'
public_url: '127.0.0.1:3055'
max_payload_size: 2500000
gossip_dynamic_inbound_limit: 0
gossip_static_outbound:
Expand Down
7 changes: 7 additions & 0 deletions etc/env/file_based/general.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -375,3 +375,10 @@ da_dispatcher:

external_proof_integration_api:
http_port: 3073

consensus:
port: 3054
server_url: "127.0.0.1:3054"
public_url: "127.0.0.1:3054"
max_payload_size: 2500000
gossip_dynamic_inbound_limit: 100
2 changes: 0 additions & 2 deletions zk_toolbox/crates/config/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ pub const DEFAULT_EXPLORER_WORKER_PORT: u16 = 3001;
pub const DEFAULT_EXPLORER_API_PORT: u16 = 3002;
/// Default port for the explorer data fetcher service
pub const DEFAULT_EXPLORER_DATA_FETCHER_PORT: u16 = 3040;
/// Default port for consensus service
pub const DEFAULT_CONSENSUS_PORT: u16 = 3054;

pub const EXPLORER_API_DOCKER_IMAGE: &str = "matterlabs/block-explorer-api";
pub const EXPLORER_DATA_FETCHER_DOCKER_IMAGE: &str = "matterlabs/block-explorer-data-fetcher";
Expand Down
27 changes: 10 additions & 17 deletions zk_toolbox/crates/zk_inception/src/commands/chain/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use anyhow::Context;
use common::{git, logger, spinner::Spinner};
use config::{
copy_configs, set_l1_rpc_url, traits::SaveConfigWithBasePath, update_from_chain_config,
ChainConfig, EcosystemConfig, DEFAULT_CONSENSUS_PORT,
ChainConfig, EcosystemConfig,
};
use types::BaseToken;
use xshell::Shell;
Expand All @@ -20,15 +20,15 @@ use crate::{
},
portal::update_portal_config,
},
defaults::PORT_RANGE_END,
messages::{
msg_initializing_chain, MSG_ACCEPTING_ADMIN_SPINNER, MSG_CHAIN_INITIALIZED,
MSG_CHAIN_NOT_FOUND_ERR, MSG_DEPLOYING_PAYMASTER, MSG_GENESIS_DATABASE_ERR,
MSG_PORTAL_FAILED_TO_CREATE_CONFIG_ERR, MSG_REGISTERING_CHAIN_SPINNER, MSG_SELECTED_CONFIG,
MSG_CHAIN_NOT_FOUND_ERR, MSG_CONSENSUS_CONFIG_MISSING_ERR, MSG_DEPLOYING_PAYMASTER,
MSG_GENESIS_DATABASE_ERR, MSG_PORTAL_FAILED_TO_CREATE_CONFIG_ERR,
MSG_REGISTERING_CHAIN_SPINNER, MSG_SELECTED_CONFIG,
MSG_UPDATING_TOKEN_MULTIPLIER_SETTER_SPINNER, MSG_WALLET_TOKEN_MULTIPLIER_SETTER_NOT_FOUND,
},
utils::{
consensus::{generate_consensus_keys, get_consensus_config, get_consensus_secrets},
consensus::{generate_consensus_keys, get_consensus_secrets, get_genesis_specs},
ports::EcosystemPortsScanner,
},
};
Expand Down Expand Up @@ -67,20 +67,13 @@ pub async fn init(
)?;
}
let mut general_config = chain_config.get_general_config()?;

// TODO: This is a temporary solution. We should allocate consensus port using `EcosystemPorts::allocate_ports_in_yaml`
let offset = ((chain_config.id - 1) * 100) as u16;
let consensus_port_range = DEFAULT_CONSENSUS_PORT + offset..PORT_RANGE_END;
let consensus_port =
ecosystem_ports.allocate_port(consensus_port_range, "Consensus".to_string())?;
let mut consensus_config = general_config
.consensus_config
.context(MSG_CONSENSUS_CONFIG_MISSING_ERR)?;

let consensus_keys = generate_consensus_keys();
let consensus_config = get_consensus_config(
chain_config,
consensus_port,
Some(consensus_keys.clone()),
None,
)?;
consensus_config.genesis_spec = Some(get_genesis_specs(chain_config, &consensus_keys));

general_config.consensus_config = Some(consensus_config);
general_config.save_with_base_path(shell, &chain_config.configs)?;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,26 @@ use config::{
external_node::ENConfig,
set_rocks_db_config,
traits::{FileConfigWithDefaultName, SaveConfigWithBasePath},
ChainConfig, EcosystemConfig, GeneralConfig, SecretsConfig, DEFAULT_CONSENSUS_PORT,
ChainConfig, EcosystemConfig, GeneralConfig, SecretsConfig,
};
use xshell::Shell;
use zksync_basic_types::url::SensitiveUrl;
use zksync_config::configs::{
consensus::{ConsensusSecrets, NodeSecretKey, Secret},
consensus::{ConsensusConfig, ConsensusSecrets, NodeSecretKey, Secret},
DatabaseSecrets, L1Secrets,
};
use zksync_consensus_crypto::TextFmt;
use zksync_consensus_roles as roles;

use crate::{
commands::external_node::args::prepare_configs::{PrepareConfigArgs, PrepareConfigFinal},
defaults::PORT_RANGE_END,
messages::{
msg_preparing_en_config_is_done, MSG_CHAIN_NOT_INITIALIZED,
MSG_CONSENSUS_CONFIG_MISSING_ERR, MSG_CONSENSUS_SECRETS_MISSING_ERR,
MSG_CONSENSUS_SECRETS_NODE_KEY_MISSING_ERR, MSG_PREPARING_EN_CONFIGS,
},
utils::{
consensus::{get_consensus_config, node_public_key},
consensus::node_public_key,
ports::EcosystemPortsScanner,
rocks_db::{recreate_rocksdb_dirs, RocksDBDirOption},
},
Expand Down Expand Up @@ -78,19 +77,12 @@ fn prepare_configs(
gateway_url: None,
};
let mut general_en = general.clone();
general_en.consensus_config = None;

let main_node_consensus_config = general
.consensus_config
.context(MSG_CONSENSUS_CONFIG_MISSING_ERR)?;

// TODO: This is a temporary solution. We should allocate consensus port using `EcosystemPorts::allocate_ports_in_yaml`
ports.add_port_info(
main_node_consensus_config.server_addr.port(),
"Main node consensus".to_string(),
);
let offset = ((config.id - 1) * 100) as u16;
let consensus_port_range = DEFAULT_CONSENSUS_PORT + offset..PORT_RANGE_END;
let consensus_port = ports.allocate_port(consensus_port_range, "Consensus".to_string())?;
let mut en_consensus_config = main_node_consensus_config.clone();

let mut gossip_static_outbound = BTreeMap::new();
let main_node_public_key = node_public_key(
Expand All @@ -100,13 +92,8 @@ fn prepare_configs(
.context(MSG_CONSENSUS_SECRETS_MISSING_ERR)?,
)?
.context(MSG_CONSENSUS_SECRETS_NODE_KEY_MISSING_ERR)?;

gossip_static_outbound.insert(main_node_public_key, main_node_consensus_config.public_addr);

let en_consensus_config =
get_consensus_config(config, consensus_port, None, Some(gossip_static_outbound))?;
general_en.consensus_config = Some(en_consensus_config.clone());
en_consensus_config.save_with_base_path(shell, en_configs_path)?;
gossip_static_outbound.insert(main_node_public_key, main_node_consensus_config.public_url);
en_consensus_config.gossip_static_outbound = gossip_static_outbound;

// Set secrets config
let node_key = roles::node::SecretKey::generate().encode();
Expand All @@ -127,16 +114,25 @@ fn prepare_configs(
}),
data_availability: None,
};
secrets.save_with_base_path(shell, en_configs_path)?;

let dirs = recreate_rocksdb_dirs(shell, &config.rocks_db_path, RocksDBDirOption::ExternalNode)?;
set_rocks_db_config(&mut general_en, dirs)?;

general_en.save_with_base_path(shell, en_configs_path)?;
en_config.save_with_base_path(shell, en_configs_path)?;
en_consensus_config.save_with_base_path(shell, en_configs_path)?;
secrets.save_with_base_path(shell, en_configs_path)?;

let offset = 0; // This is zero because general_en ports already have a chain offset
ports.allocate_ports_in_yaml(
shell,
&GeneralConfig::get_path_with_base_path(en_configs_path),
0, // This is zero because general_en ports already have a chain offset
offset,
)?;
ports.allocate_ports_in_yaml(
shell,
&ConsensusConfig::get_path_with_base_path(en_configs_path),
offset,
)?;

Ok(())
Expand Down
23 changes: 0 additions & 23 deletions zk_toolbox/crates/zk_inception/src/consts.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::net::{IpAddr, Ipv4Addr};

pub const AMOUNT_FOR_DISTRIBUTION_TO_WALLETS: u128 = 1000000000000000000000;

pub const MINIMUM_BALANCE_FOR_WALLET: u128 = 5000000000000000000;
Expand All @@ -12,27 +10,6 @@ pub const DEFAULT_UNSIGNED_TRANSACTIONS_DIR: &str = "transactions";
pub const BELLMAN_CUDA_DIR: &str = "era-bellman-cuda";
pub const L2_BASE_TOKEN_ADDRESS: &str = "0x000000000000000000000000000000000000800A";

#[allow(non_upper_case_globals)]
const kB: usize = 1024;

/// Max payload size for consensus in bytes
pub const MAX_PAYLOAD_SIZE: usize = 2_500_000;
/// Max batch size for consensus in bytes
/// Compute a default batch size, so operators are not caught out by the missing setting
/// while we're still working on batch syncing. The batch interval is ~1 minute,
/// so there will be ~60 blocks, and an Ethereum Merkle proof is ~1kB, but under high
/// traffic there can be thousands of huge transactions that quickly fill up blocks
/// and there could be more blocks in a batch then expected. We chose a generous
/// limit so as not to prevent any legitimate batch from being transmitted.
pub const MAX_BATCH_SIZE: usize = MAX_PAYLOAD_SIZE * 5000 + kB;
/// Gossip dynamic inbound limit for consensus
Deniallugo marked this conversation as resolved.
Show resolved Hide resolved
pub const GOSSIP_DYNAMIC_INBOUND_LIMIT: usize = 100;

/// Public address for consensus
pub const CONSENSUS_PUBLIC_ADDRESS_HOST: IpAddr = IpAddr::V4(Ipv4Addr::UNSPECIFIED);
/// Server address for consensus
pub const CONSENSUS_SERVER_ADDRESS_HOST: IpAddr = IpAddr::V4(Ipv4Addr::LOCALHOST);

/// Path to the JS runtime config for the block-explorer-app docker container to be mounted to
pub const EXPLORER_APP_DOCKER_CONFIG_PATH: &str = "/usr/src/app/packages/app/dist/config.js";
pub const EXPLORER_APP_DOCKER_IMAGE: &str = "matterlabs/block-explorer-app";
Expand Down
42 changes: 3 additions & 39 deletions zk_toolbox/crates/zk_inception/src/utils/consensus.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,14 @@
use std::{
collections::{BTreeMap, BTreeSet},
net::SocketAddr,
};

use anyhow::Context as _;
use config::ChainConfig;
use secrecy::{ExposeSecret, Secret};
use zksync_config::configs::consensus::{
AttesterPublicKey, AttesterSecretKey, ConsensusConfig, ConsensusSecrets, GenesisSpec, Host,
NodePublicKey, NodeSecretKey, ProtocolVersion, ValidatorPublicKey, ValidatorSecretKey,
WeightedAttester, WeightedValidator,
AttesterPublicKey, AttesterSecretKey, ConsensusSecrets, GenesisSpec, NodePublicKey,
NodeSecretKey, ProtocolVersion, ValidatorPublicKey, ValidatorSecretKey, WeightedAttester,
WeightedValidator,
};
use zksync_consensus_crypto::{Text, TextFmt};
use zksync_consensus_roles::{attester, node, validator};

use crate::consts::{
CONSENSUS_PUBLIC_ADDRESS_HOST, CONSENSUS_SERVER_ADDRESS_HOST, GOSSIP_DYNAMIC_INBOUND_LIMIT,
MAX_BATCH_SIZE, MAX_PAYLOAD_SIZE,
};

pub(crate) fn parse_attester_committee(
attesters: &[WeightedAttester],
) -> anyhow::Result<attester::Committee> {
Expand Down Expand Up @@ -48,32 +38,6 @@ pub struct ConsensusPublicKeys {
attester_key: attester::PublicKey,
}

pub fn get_consensus_config(
chain_config: &ChainConfig,
consensus_port: u16,
consensus_keys: Option<ConsensusSecretKeys>,
gossip_static_outbound: Option<BTreeMap<NodePublicKey, Host>>,
) -> anyhow::Result<ConsensusConfig> {
let genesis_spec =
consensus_keys.map(|consensus_keys| get_genesis_specs(chain_config, &consensus_keys));

let public_addr = SocketAddr::new(CONSENSUS_PUBLIC_ADDRESS_HOST, consensus_port);
let server_addr = SocketAddr::new(CONSENSUS_SERVER_ADDRESS_HOST, consensus_port);

Ok(ConsensusConfig {
server_addr,
public_addr: Host(public_addr.encode()),
genesis_spec,
max_payload_size: MAX_PAYLOAD_SIZE,
gossip_dynamic_inbound_limit: GOSSIP_DYNAMIC_INBOUND_LIMIT,
max_batch_size: MAX_BATCH_SIZE,
gossip_static_inbound: BTreeSet::new(),
gossip_static_outbound: gossip_static_outbound.unwrap_or_default(),
rpc: None,
debug_page_addr: None,
})
}

pub fn generate_consensus_keys() -> ConsensusSecretKeys {
ConsensusSecretKeys {
validator_key: validator::SecretKey::generate(),
Expand Down
Loading
Loading