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: replace toml with cli config #732

Open
wants to merge 14 commits into
base: next
Choose a base branch
from
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
- [BREAKING] Added `block_prover_url` to block producer configuration (#719).
- [BREAKING] Updated to Rust Edition 2024 (#727).
- [BREAKING] MSRV bumped to 1.85 (#727).
- [BREAKING] Replaced `toml` configuration with CLI (#732).

### Enhancements

Expand Down
5 changes: 1 addition & 4 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion bin/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ tracing-forest = ["miden-node-block-producer/tracing-forest"]

[dependencies]
anyhow = { version = "1.0" }
clap = { version = "4.5", features = ["derive", "string"] }
clap = { version = "4.5", features = ["derive", "env", "string"] }
miden-lib = { workspace = true }
miden-node-block-producer = { workspace = true }
miden-node-rpc = { workspace = true }
Expand Down
75 changes: 75 additions & 0 deletions bin/node/src/commands/block_producer.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
use anyhow::Context;
use miden_node_block_producer::server::BlockProducer;
use miden_node_utils::grpc::UrlExt;
use url::Url;

use super::{
ENV_BATCH_PROVER_URL, ENV_BLOCK_PRODUCER_URL, ENV_BLOCK_PROVER_URL, ENV_ENABLE_OTEL,
ENV_STORE_URL,
};

#[derive(clap::Subcommand)]
pub enum BlockProducerCommand {
/// Starts the block-producer component.
Start {
/// Url at which to serve the gRPC API.
#[arg(env = ENV_BLOCK_PRODUCER_URL)]
url: Url,

/// The store's gRPC url.
#[arg(long = "store.url", env = ENV_STORE_URL)]
store_url: Url,

/// The remote batch prover's gRPC url. If unset, will default to running a prover
/// in-process which is expensive.
#[arg(long = "batch_prover.url", env = ENV_BATCH_PROVER_URL)]
batch_prover_url: Option<Url>,

/// The remote block prover's gRPC url. If unset, will default to running a prover
/// in-process which is expensive.
#[arg(long = "block_prover.url", env = ENV_BLOCK_PROVER_URL)]
block_prover_url: Option<Url>,

/// Enables the exporting of traces for OpenTelemetry.
///
/// This can be further configured using environment variables as defined in the official
/// OpenTelemetry documentation. See our operator manual for further details.
#[arg(long = "open-telemetry", default_value_t = false, env = ENV_ENABLE_OTEL)]
open_telemetry: bool,
},
}

impl BlockProducerCommand {
pub async fn handle(self) -> anyhow::Result<()> {
let Self::Start {
url,
store_url,
batch_prover_url,
block_prover_url,
// Note: open-telemetry is handled in main.
open_telemetry: _,
} = self;

let store_url = store_url
.to_socket()
.context("Failed to extract socket address from store URL")?;

let listener =
url.to_socket().context("Failed to extract socket address from store URL")?;
let listener = tokio::net::TcpListener::bind(listener)
.await
.context("Failed to bind to store's gRPC URL")?;

BlockProducer::init(listener, store_url, batch_prover_url, block_prover_url)
.await
.context("Loading store")?
.serve()
.await
.context("Serving store")
}

pub fn is_open_telemetry_enabled(&self) -> bool {
let Self::Start { open_telemetry, .. } = self;
*open_telemetry
}
}
55 changes: 0 additions & 55 deletions bin/node/src/commands/genesis/inputs.rs

This file was deleted.

Loading