Skip to content

Commit

Permalink
feat: Add version cmd to all bins (#4343)
Browse files Browse the repository at this point in the history
* feat: add version cmd to LP API & Broker

* feat: Added version check to in-eg-tracker

* docs: update readmes with version cmd

* chore: address PR comments
  • Loading branch information
j4m1ef0rd committed Dec 14, 2023
1 parent d710192 commit f28c005
Show file tree
Hide file tree
Showing 16 changed files with 140 additions and 38 deletions.
5 changes: 5 additions & 0 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions api/bin/chainflip-broker-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,6 @@ sp-rpc = { git = "https://github.com/chainflip-io/substrate.git", tag = "chainfl
tokio = "1.20.1"
tracing = "0.1.34"
tracing-subscriber = { version = "0.3.3", features = ["env-filter"] }

[build-dependencies]
substrate-build-script-utils = { git = "https://github.com/chainflip-io/substrate.git", tag = 'chainflip-monthly-2023-08+3' }
5 changes: 4 additions & 1 deletion api/bin/chainflip-broker-api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ OPTIONS:
Print help information

--port <PORT>
The port number on which the broker will listen for connections. Use 0 to assing a
The port number on which the broker will listen for connections. Use 0 to assign a
random port. [default: 80]

--state_chain.signing_key_file <SIGNING_KEY_FILE>
Expand All @@ -34,6 +34,9 @@ OPTIONS:
--state_chain.ws_endpoint <WS_ENDPOINT>
The state chain node's rpc endpoint. [default: ws://localhost:9944]

-v, --version
Print the version of the API
```

## Example
Expand Down
3 changes: 3 additions & 0 deletions api/bin/chainflip-broker-api/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
substrate_build_script_utils::generate_cargo_keys();
}
1 change: 1 addition & 0 deletions api/bin/chainflip-broker-api/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ impl RpcServer for RpcServerImpl {
}

#[derive(Parser, Debug, Clone, Default)]
#[clap(version = env!("SUBSTRATE_CLI_IMPL_VERSION"), version_short = 'v')]
pub struct BrokerOptions {
#[clap(
long = "port",
Expand Down
2 changes: 1 addition & 1 deletion api/bin/chainflip-cli/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use std::{
};

#[derive(Parser, Clone, Debug)]
#[clap(version = env!("SUBSTRATE_CLI_IMPL_VERSION"))]
#[clap(version = env!("SUBSTRATE_CLI_IMPL_VERSION"), version_short = 'v')]
pub struct CLICommandLineOptions {
#[clap(short = 'c', long = "config-root", env = CONFIG_ROOT, default_value = DEFAULT_CONFIG_ROOT)]
pub config_root: String,
Expand Down
5 changes: 5 additions & 0 deletions api/bin/chainflip-ingress-egress-tracker/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ tokio = "1.29.1"
tracing = "0.1.34"
tracing-subscriber = { version = "0.3.3", features = ["env-filter"] }
tempfile = "3.8"
clap = { version = "3.2.23", features = ["derive", "env"] }
config = "0.13.1"

sp-core = { git = "https://github.com/chainflip-io/substrate.git", tag = "chainflip-monthly-2023-08+3" }
codec = { package = "parity-scale-codec", version = "3.6.1", features = [
Expand All @@ -31,3 +33,6 @@ cf-primitives = { path = "../../../state-chain/primitives" }
pallet-cf-environment = { path = "../../../state-chain/pallets/cf-environment" }
state-chain-runtime = { path = "../../../state-chain/runtime" }
cf-chains = { path = "../../../state-chain/chains" }

[build-dependencies]
substrate-build-script-utils = { git = "https://github.com/chainflip-io/substrate.git", tag = 'chainflip-monthly-2023-08+3' }
3 changes: 3 additions & 0 deletions api/bin/chainflip-ingress-egress-tracker/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
substrate_build_script_utils::generate_cargo_keys();
}
133 changes: 101 additions & 32 deletions api/bin/chainflip-ingress-egress-tracker/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,110 @@
use chainflip_engine::settings::{HttpBasicAuthEndpoint, WsHttpEndpoints};
use chainflip_engine::settings::{
insert_command_line_option, CfSettings, HttpBasicAuthEndpoint, WsHttpEndpoints,
};
use clap::Parser;
use config::{Config, ConfigBuilder, ConfigError, Environment, Map, Source, Value};
use futures::FutureExt;
use jsonrpsee::{core::Error, server::ServerBuilder, RpcModule};
use std::{env, net::SocketAddr};
use serde::Deserialize;
use std::{collections::HashMap, env, net::SocketAddr};
use tracing::log;
use utilities::task_scope;

mod witnessing;

#[derive(Clone)]
#[derive(Clone, Deserialize, Debug)]
pub struct DepositTrackerSettings {
eth_node: WsHttpEndpoints,
dot_node: WsHttpEndpoints,
eth: WsHttpEndpoints,
dot: WsHttpEndpoints,
state_chain_ws_endpoint: String,
btc: HttpBasicAuthEndpoint,
}

#[derive(Parser, Debug, Clone, Default)]
#[clap(version = env!("SUBSTRATE_CLI_IMPL_VERSION"), version_short = 'v')]
pub struct TrackerOptions {
#[clap(long = "eth.rpc.ws_endpoint")]
eth_ws_endpoint: Option<String>,
#[clap(long = "eth.rpc.http_endpoint")]
eth_http_endpoint: Option<String>,
#[clap(long = "dot.rpc.ws_endpoint")]
dot_ws_endpoint: Option<String>,
#[clap(long = "dot.rpc.http_endpoint")]
dot_http_endpoint: Option<String>,
#[clap(long = "state_chain.ws_endpoint")]
state_chain_ws_endpoint: Option<String>,
#[clap(long = "btc.rpc.http_endpoint")]
btc_endpoint: Option<String>,
#[clap(long = "btc.rpc.basic_auth_user")]
btc_username: Option<String>,
#[clap(long = "btc.rpc.basic_auth_password")]
btc_password: Option<String>,
}

impl CfSettings for DepositTrackerSettings {
type CommandLineOptions = TrackerOptions;

fn load_settings_from_all_sources(
config_root: String,
_settings_dir: &str,
opts: Self::CommandLineOptions,
) -> Result<Self, ConfigError> {
Self::set_defaults(Config::builder(), &config_root)?
.add_source(Environment::default().separator("__"))
.add_source(opts)
.build()?
.try_deserialize()
}

fn set_defaults(
config_builder: ConfigBuilder<config::builder::DefaultState>,
_config_root: &str,
) -> Result<ConfigBuilder<config::builder::DefaultState>, ConfigError> {
// These defaults are for a localnet setup
config_builder
.set_default("eth.ws_endpoint", "ws://localhost:8546")?
.set_default("eth.http_endpoint", "http://localhost:8545")?
.set_default("dot.ws_endpoint", "ws://localhost:9947")?
.set_default("dot.http_endpoint", "http://localhost:9947")?
.set_default("state_chain_ws_endpoint", "ws://localhost:9944")?
.set_default("btc.http_endpoint", "http://127.0.0.1:8332")?
.set_default("btc.basic_auth_user", "flip")?
.set_default("btc.basic_auth_password", "flip")
}

fn validate_settings(
&mut self,
_config_root: &std::path::Path,
) -> anyhow::Result<(), ConfigError> {
Ok(())
}
}

impl Source for TrackerOptions {
fn clone_into_box(&self) -> Box<dyn Source + Send + Sync> {
Box::new((*self).clone())
}

fn collect(&self) -> std::result::Result<Map<String, Value>, ConfigError> {
let mut map: HashMap<String, Value> = HashMap::new();

insert_command_line_option(&mut map, "eth.ws_endpoint", &self.eth_ws_endpoint);
insert_command_line_option(&mut map, "eth.http_endpoint", &self.eth_http_endpoint);
insert_command_line_option(&mut map, "dot.ws_endpoint", &self.dot_ws_endpoint);
insert_command_line_option(&mut map, "dot.http_endpoint", &self.dot_http_endpoint);
insert_command_line_option(
&mut map,
"state_chain_ws_endpoint",
&self.state_chain_ws_endpoint,
);
insert_command_line_option(&mut map, "btc.http_endpoint", &self.btc_endpoint);
insert_command_line_option(&mut map, "btc.basic_auth_user", &self.btc_username);
insert_command_line_option(&mut map, "btc.basic_auth_password", &self.btc_password);

Ok(map)
}
}

async fn start(
scope: &task_scope::Scope<'_, anyhow::Error>,
settings: DepositTrackerSettings,
Expand Down Expand Up @@ -81,33 +171,12 @@ async fn start(

#[tokio::main]
async fn main() -> anyhow::Result<()> {
let settings = DepositTrackerSettings {
eth_node: WsHttpEndpoints {
ws_endpoint: env::var("ETH_WS_ENDPOINT")
.unwrap_or("ws://localhost:8546".to_string())
.into(),
http_endpoint: env::var("ETH_HTTP_ENDPOINT")
.unwrap_or("http://localhost:8545".to_string())
.into(),
},
dot_node: WsHttpEndpoints {
ws_endpoint: env::var("DOT_WS_ENDPOINT")
.unwrap_or("ws://localhost:9947".to_string())
.into(),
http_endpoint: env::var("DOT_HTTP_ENDPOINT")
.unwrap_or("http://localhost:9947".to_string())
.into(),
},
state_chain_ws_endpoint: env::var("SC_WS_ENDPOINT")
.unwrap_or("ws://localhost:9944".to_string()),
btc: HttpBasicAuthEndpoint {
http_endpoint: env::var("BTC_ENDPOINT")
.unwrap_or("http://127.0.0.1:8332".to_string())
.into(),
basic_auth_user: env::var("BTC_USERNAME").unwrap_or("flip".to_string()),
basic_auth_password: env::var("BTC_PASSWORD").unwrap_or("flip".to_string()),
},
};
let settings = DepositTrackerSettings::load_settings_from_all_sources(
// Not using the config root or settings dir.
"".to_string(),
"",
TrackerOptions::parse(),
)?;

task_scope::task_scope(|scope| async move { start(scope, settings).await }.boxed()).await
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ where
{
let dot_client = DotRetryRpcClient::new(
scope,
NodeContainer { primary: settings.dot_node, backup: None },
NodeContainer { primary: settings.dot, backup: None },
env_params.dot_genesis_hash,
)?;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ where
ProcessingFut: futures::Future<Output = ()> + Send + 'static,
{
let eth_client = {
let nodes = NodeContainer { primary: settings.eth_node.clone(), backup: None };
let nodes = NodeContainer { primary: settings.eth.clone(), backup: None };

EthRetryRpcClient::<EthRpcClient>::new(scope, nodes, env_params.eth_chain_id.into())?
};
Expand Down
5 changes: 4 additions & 1 deletion api/bin/chainflip-lp-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ name = "chainflip-lp-api"

[dependencies]
anyhow = "1.0"
clap = { version = "3.2.23", features = ["derive"] }
clap = { version = "3.2.23", features = ["derive", "env"] }
futures = "0.3"
hex = "0.4.3"
jsonrpsee = { version = "0.20", features = ["full"] }
Expand All @@ -39,3 +39,6 @@ frame-system = { git = 'https://github.com/chainflip-io/substrate.git', tag = 'c
# Local
chainflip-api = { path = "../../lib" }
cf-utilities = { package = "utilities", path = "../../../utilities" }

[build-dependencies]
substrate-build-script-utils = { git = "https://github.com/chainflip-io/substrate.git", tag = 'chainflip-monthly-2023-08+3' }
3 changes: 3 additions & 0 deletions api/bin/chainflip-lp-api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ OPTIONS:

--state_chain.ws_endpoint <WS_ENDPOINT>
The state chain nodes RPC endpoint. [default: ws://localhost:9944]

-v, --version
Print the version of the API
```

## Working Example
Expand Down
3 changes: 3 additions & 0 deletions api/bin/chainflip-lp-api/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
substrate_build_script_utils::generate_cargo_keys();
}
1 change: 1 addition & 0 deletions api/bin/chainflip-lp-api/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,7 @@ impl RpcServer for RpcServerImpl {
}

#[derive(Parser, Debug, Clone, Default)]
#[clap(version = env!("SUBSTRATE_CLI_IMPL_VERSION"), version_short = 'v')]
pub struct LPOptions {
#[clap(
long = "port",
Expand Down
2 changes: 1 addition & 1 deletion engine/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ pub struct P2POptions {
}

#[derive(Parser, Debug, Clone)]
#[clap(version = env!("SUBSTRATE_CLI_IMPL_VERSION"))]
#[clap(version = env!("SUBSTRATE_CLI_IMPL_VERSION"), version_short = 'v')]
pub struct CommandLineOptions {
// Misc Options
#[clap(short = 'c', long = "config-root", env = CONFIG_ROOT, default_value = DEFAULT_CONFIG_ROOT)]
Expand Down

0 comments on commit f28c005

Please sign in to comment.