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

fix(zk_toolbox): set correct key configs #2831

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions zk_toolbox/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions zk_toolbox/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,4 @@ toml = "0.8.12"
url = { version = "2.5.0", features = ["serde"] }
xshell = "0.2.6"
clap-markdown = "0.1.4"
secrecy = "0.8.0"
1 change: 1 addition & 0 deletions zk_toolbox/crates/zk_inception/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ zksync_basic_types.workspace = true
clap-markdown.workspace = true
zksync_consensus_roles.workspace = true
zksync_consensus_crypto.workspace = true
secrecy.workspace = true
5 changes: 2 additions & 3 deletions zk_toolbox/crates/zk_inception/src/commands/chain/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,17 +335,16 @@ fn get_genesis_specs(chain_config: &ChainConfig, consensus_keys: &ConsensusKeys)
let public_keys = get_consensus_public_keys(consensus_keys);
let validator_key = public_keys.validator_key.encode();
let attester_key = public_keys.attester_key.encode();
let node_key = public_keys.node_key.encode();

let validator = WeightedValidator {
key: ValidatorPublicKey(validator_key),
key: ValidatorPublicKey(validator_key.clone()),
weight: 1,
};
let attester = WeightedAttester {
key: AttesterPublicKey(attester_key),
weight: 1,
};
let leader = ValidatorPublicKey(node_key);
let leader = ValidatorPublicKey(validator_key);

GenesisSpec {
chain_id: chain_config.chain_id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,24 @@ use config::{
external_node::ENConfig, ports_config, set_rocks_db_config, traits::SaveConfigWithBasePath,
update_ports, ChainConfig, EcosystemConfig, SecretsConfig,
};
use secrecy::ExposeSecret as _;
use xshell::Shell;
use zksync_basic_types::url::SensitiveUrl;
use zksync_config::configs::{
consensus::{ConsensusConfig, ConsensusSecrets, Host, NodePublicKey, NodeSecretKey, Secret},
DatabaseSecrets, L1Secrets,
};
use zksync_consensus_crypto::TextFmt;
use zksync_consensus_crypto::{Text, TextFmt};
use zksync_consensus_roles as roles;

use crate::{
commands::external_node::args::prepare_configs::{PrepareConfigArgs, PrepareConfigFinal},
consts::{GOSSIP_DYNAMIC_INBOUND_LIMIT, MAX_BATCH_SIZE, MAX_PAYLOAD_SIZE},
messages::{
msg_preparing_en_config_is_done, MSG_API_CONFIG_MISSING_ERR, MSG_CHAIN_NOT_INITIALIZED,
MSG_CONSENSUS_CONFIG_MISSING_ERR, MSG_GENESIS_SPEC_MISSING_ERR, MSG_PREPARING_EN_CONFIGS,
MSG_CONSENSUS_CONFIG_MISSING_ERR, MSG_CONSENSUS_SECRETS_MISSING_ERR,
MSG_CONSENSUS_SECRETS_NODE_KEY_MISSING_ERR, MSG_GENESIS_SPEC_MISSING_ERR,
MSG_PREPARING_EN_CONFIGS,
},
utils::{
consensus::parse_public_addr,
Expand Down Expand Up @@ -96,11 +99,15 @@ fn prepare_configs(
.context(MSG_API_CONFIG_MISSING_ERR)?;
let public_addr = parse_public_addr(&api_config)?;
let server_addr = public_addr.parse()?;
let genesis_spec = main_node_consensus_config
.genesis_spec
.context(MSG_GENESIS_SPEC_MISSING_ERR)?;
let mut gossip_static_outbound = BTreeMap::new();
let main_node_public_key = NodePublicKey(genesis_spec.leader.0);
let main_node_public_key = node_public_key(
&config
.get_secrets_config()?
.consensus
.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 = ConsensusConfig {
server_addr,
Expand Down Expand Up @@ -142,3 +149,16 @@ fn prepare_configs(

Ok(())
}

fn node_public_key(secrets: &ConsensusSecrets) -> anyhow::Result<Option<NodePublicKey>> {
Ok(node_key(secrets)?.map(|node_secret_key| NodePublicKey(node_secret_key.public().encode())))
}
fn node_key(secrets: &ConsensusSecrets) -> anyhow::Result<Option<roles::node::SecretKey>> {
read_secret_text(secrets.node_key.as_ref().map(|x| &x.0))
}

fn read_secret_text<T: TextFmt>(text: Option<&Secret<String>>) -> anyhow::Result<Option<T>> {
text.map(|text| Text::new(text.expose_secret()).decode())
.transpose()
.map_err(|_| anyhow::format_err!("invalid format"))
}
5 changes: 4 additions & 1 deletion zk_toolbox/crates/zk_inception/src/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,10 @@ pub(super) fn msg_preparing_en_config_is_done(path: &Path) -> String {

pub(super) const MSG_EXTERNAL_NODE_CONFIG_NOT_INITIALIZED: &str =
"External node is not initialized";
pub(super) const MSG_CONSENSUS_CONFIG_MISSING_ERR: &str = "Consensus config missing";
pub(super) const MSG_CONSENSUS_CONFIG_MISSING_ERR: &str = "Consensus config is missing";
pub(super) const MSG_CONSENSUS_SECRETS_MISSING_ERR: &str = "Consensus secrets config is missing";
pub(super) const MSG_CONSENSUS_SECRETS_NODE_KEY_MISSING_ERR: &str = "Consensus node key is missing";

pub(super) const MSG_GENESIS_SPEC_MISSING_ERR: &str = "Genesis spec missing";
pub(super) const MSG_PUBLIC_ADDR_ERR: &str = "Public address error";

Expand Down
Loading