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: added key generation command to EN #2461

Merged
merged 15 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 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 core/bin/external_node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ zksync_vlog.workspace = true

zksync_concurrency.workspace = true
zksync_consensus_roles.workspace = true
zksync_consensus_crypto.workspace = true
vise.workspace = true

async-trait.workspace = true
Expand Down
14 changes: 14 additions & 0 deletions core/bin/external_node/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ use zksync_config::{
},
ObjectStoreConfig,
};
use zksync_consensus_crypto::TextFmt;
use zksync_consensus_roles as roles;
use zksync_core_leftovers::temp_config_store::{decode_yaml_repr, read_yaml_repr};
#[cfg(test)]
use zksync_dal::{ConnectionPool, Core};
Expand Down Expand Up @@ -1126,6 +1128,18 @@ impl ExperimentalENConfig {
}
}

pub fn generate_consensus_secrets() {
pompon0 marked this conversation as resolved.
Show resolved Hide resolved
let validator_key = roles::validator::SecretKey::generate();
let attester_key = roles::attester::SecretKey::generate();
let node_key = roles::node::SecretKey::generate();
println!("# {}", validator_key.public().encode());
println!("- validator_key: '{}'", validator_key.encode());
println!("# {}", attester_key.public().encode());
println!("- attester_key: '{}'", attester_key.encode());
println!("# {}", node_key.public().encode());
println!("- node_key: '{}'", node_key.encode());
pompon0 marked this conversation as resolved.
Show resolved Hide resolved
}

pub(crate) fn read_consensus_secrets() -> anyhow::Result<Option<ConsensusSecrets>> {
let Ok(path) = env::var("EN_CONSENSUS_SECRETS_PATH") else {
return Ok(None);
Expand Down
31 changes: 29 additions & 2 deletions core/bin/external_node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ use zksync_web3_decl::{
};

use crate::{
config::ExternalNodeConfig,
config::{generate_consensus_secrets, ExternalNodeConfig},
init::{ensure_storage_initialized, SnapshotRecoveryConfig},
};

Expand Down Expand Up @@ -695,10 +695,20 @@ async fn shutdown_components(
Ok(())
}

#[derive(Debug, Clone, clap::Subcommand)]
enum Command {
/// Generates consensus secret keys to use in the secrets file.
/// Prints the keys to the stdout, you need to copy the relevant keys into your secrets file.
GenerateSecrets,
}

/// External node for ZKsync Era.
#[derive(Debug, Parser)]
#[command(author = "Matter Labs", version)]
struct Cli {
#[command(subcommand)]
command: Option<Command>,

/// Enables consensus-based syncing instead of JSON-RPC based one. This is an experimental and incomplete feature;
/// do not use unless you know what you're doing.
#[arg(long)]
Expand All @@ -720,7 +730,14 @@ struct Cli {
/// Path to the yaml with external node specific configuration. If set, it will be used instead of env vars.
#[arg(long, requires = "config_path", requires = "secrets_path")]
external_node_config_path: Option<std::path::PathBuf>,
/// Path to the yaml with consensus.
/// Path to the yaml with consensus config. If set, it will be used instead of env vars.
#[arg(
long,
requires = "config_path",
requires = "secrets_path",
requires = "external_node_config_path",
requires = "enable_consensus"
)]
consensus_path: Option<std::path::PathBuf>,
}

Expand Down Expand Up @@ -778,9 +795,19 @@ async fn main() -> anyhow::Result<()> {
// Initial setup.
let opt = Cli::parse();

if let Some(cmd) = &opt.command {
match cmd {
Command::GenerateSecrets => generate_consensus_secrets(),
}
return Ok(());
}

let mut config = if let Some(config_path) = opt.config_path.clone() {
let secrets_path = opt.secrets_path.clone().unwrap();
let external_node_config_path = opt.external_node_config_path.clone().unwrap();
if opt.enable_consensus {
anyhow::ensure!(opt.consensus_path.is_some());
pompon0 marked this conversation as resolved.
Show resolved Hide resolved
}
ExternalNodeConfig::from_files(
config_path,
external_node_config_path,
Expand Down
Loading