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

Full config in cli (BFT-427) #71

Merged
merged 146 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
146 commits
Select commit Hold shift + click to select a range
6bd6170
Add dockerfile for executable node
IAvecilla Jan 10, 2024
b2fb9ab
Add compose file for testing purposes
IAvecilla Jan 10, 2024
e768bc6
Add entrypoint for node consensus dockerfile
IAvecilla Jan 12, 2024
e6b6487
Add some comments and improve compose test file
IAvecilla Jan 12, 2024
4ca7fdc
Add new makefile commands to run dockerized consensus node
IAvecilla Jan 12, 2024
28df58b
Update readme with docs to run consensus node in docker
IAvecilla Jan 12, 2024
3e4b881
Delete unnecesary building dependency in compose file
IAvecilla Jan 15, 2024
febcafc
Rename docker image
IAvecilla Jan 15, 2024
b2e7e9c
Set container names manually in compose file
IAvecilla Jan 15, 2024
5e27e6e
Separate config directory for nodes running in docker
IAvecilla Jan 15, 2024
6e2236a
Fix node configuration for docker consensus example
IAvecilla Jan 15, 2024
810a4b5
Improve command to run a node in a container
IAvecilla Jan 15, 2024
4088c0a
Generate the node configs in release mode
IAvecilla Jan 15, 2024
4475489
Fix docker cleanup to force deletion
IAvecilla Jan 15, 2024
689b6d5
Remove unnecesary copies to container
IAvecilla Jan 15, 2024
99dc691
Add target dir to docker ignore
IAvecilla Jan 16, 2024
a3b270d
Move every docker related config file to the project root
IAvecilla Jan 16, 2024
f93890f
Fix typo in README
IAvecilla Jan 17, 2024
f3893cf
Fix typo in makefile command
IAvecilla Jan 17, 2024
1c721c8
Make the path to makefile be the same for local and docker
IAvecilla Jan 17, 2024
8cac863
disabled clipply lint
pompon0 Jan 17, 2024
d24c8bc
fixed lint, updated deps
pompon0 Jan 17, 2024
9520c4c
Change file name for the docker entrypoint and add comment to the script
IAvecilla Jan 18, 2024
54c72ce
Move version to latest for rust image
IAvecilla Jan 18, 2024
13e61e1
Change name of command and dir generation for node config
IAvecilla Jan 18, 2024
3b8d299
Add command to stop dockerized nodes
IAvecilla Jan 18, 2024
2d09c1d
Add example file with local address for node configuration
IAvecilla Jan 18, 2024
c287c56
Update README with new updates
IAvecilla Jan 18, 2024
e66cec9
Write a general overview on the README
IAvecilla Jan 18, 2024
eb7077e
Add tonic as dependency
IAvecilla Jan 19, 2024
058418e
Create test proto file with helathcheck endpoint
IAvecilla Jan 19, 2024
f323873
Add basic rpc server implementation
IAvecilla Jan 19, 2024
d0d9b13
Add basic rpc client implementation to use with CLI
IAvecilla Jan 19, 2024
a332327
Run RPC server for the standalone node
IAvecilla Jan 19, 2024
8e2d83c
Update docker config files to expose rpc server
IAvecilla Jan 19, 2024
96e18b7
Replace tonic crate for jsonrpsee
IAvecilla Jan 23, 2024
6b57f2a
Delete protobuff related files
IAvecilla Jan 23, 2024
c0aaa9b
Delete unnecesary RPC client
IAvecilla Jan 23, 2024
88a5b23
Add new jsonrpsee server and health endpoint
IAvecilla Jan 23, 2024
890bdee
Add inner docs for new rpc module
IAvecilla Jan 23, 2024
8f806bc
quick and dirty k8s deployment scripts for test framework
ElFantasma Jan 23, 2024
7592041
Merge branch 'main' into rpc_test_layer
IAvecilla Jan 23, 2024
23b8ea4
Merge branch 'rpc_test_layer' into k8s_deploy_script
IAvecilla Jan 23, 2024
438a2b8
Change name for generated config folders
IAvecilla Jan 24, 2024
19d7fcc
Update localnet config bin
IAvecilla Jan 24, 2024
b49af96
Delete old docker entrypoint file
IAvecilla Jan 24, 2024
2fd8061
Update k8s deployment manifest adding node env var
IAvecilla Jan 24, 2024
758ff9e
Add new stage in dockerfile to generate executor binary
IAvecilla Jan 25, 2024
addacc8
Build correct target in compose file
IAvecilla Jan 25, 2024
e263eb6
Update Makefile with all new targets
IAvecilla Jan 25, 2024
9503f05
Add addresses example file for docker config
IAvecilla Jan 25, 2024
8bcdb88
Remove docker config dir from clean command
IAvecilla Jan 25, 2024
2323211
Added some utility targets to Makefile
ElFantasma Jan 25, 2024
2720e74
Make rpc port a CLI argument for the executor
IAvecilla Jan 25, 2024
af1caaa
Change param type to run the server
IAvecilla Jan 25, 2024
77591f3
Merge branch 'rpc_test_layer' into k8s_deploy_script
IAvecilla Jan 25, 2024
24cddea
Add config generation for k8s node deployer
IAvecilla Jan 25, 2024
2cfaff4
Add makefile target to clean k8s config
IAvecilla Jan 25, 2024
4ed83cc
Improve config generation struct
IAvecilla Jan 26, 2024
00a008a
Use new config app functions to build localent and k8s config
IAvecilla Jan 26, 2024
4ce804b
Add kube as dependency for tools crate
IAvecilla Jan 26, 2024
b723715
Fix node config generation
IAvecilla Jan 29, 2024
83589a1
Add k8s-openapi as dependency
IAvecilla Jan 29, 2024
6248277
Add subcommands to generate config and deploy pods
IAvecilla Jan 29, 2024
87d9def
Override entrypoint to run node in k8s pod
IAvecilla Jan 29, 2024
251052f
Add makefile target to run k8s pods
IAvecilla Jan 29, 2024
09484fd
Merge branch 'main' into rpc_test_layer
IAvecilla Jan 30, 2024
ac145ee
Merge branch 'rpc_test_layer' into k8s_deploy_script
IAvecilla Jan 30, 2024
10ba6d6
Update nodes argument type to generate nodes config
IAvecilla Jan 30, 2024
991a8ac
Fix deployer config generation after merge
IAvecilla Jan 30, 2024
926b387
Fix clippy and format warnings
IAvecilla Jan 30, 2024
5fca6b8
Improve RPC server API to scale it easier
IAvecilla Jan 30, 2024
0726aff
Fix concurrency management for rpc server
IAvecilla Jan 30, 2024
21fb1c6
Add missing docs to solve clippy warnings
IAvecilla Jan 30, 2024
41ec845
Revert change for executor new flag
IAvecilla Jan 30, 2024
7ba8cb3
shutting down server when context is cancelled
pompon0 Jan 31, 2024
d859f39
Removed k8s yml files and modularized kube.rs access
ElFantasma Feb 1, 2024
95ec2b7
Update consensus docker example with new rpc ports
IAvecilla Feb 1, 2024
d697cc1
Add new endpoint to get peers of the node
IAvecilla Feb 1, 2024
7fe6ed9
Fix format and linter
IAvecilla Feb 1, 2024
57f600a
Update cargo.lock
IAvecilla Feb 1, 2024
8ffa0c0
Delete unnecesary features in added crates
IAvecilla Feb 1, 2024
44c979e
Added k8s module
ElFantasma Feb 1, 2024
5257592
Add old crate versions to deny.toml file
IAvecilla Feb 2, 2024
75cd2cf
Use new app config api for test in tools crate
IAvecilla Feb 2, 2024
958954f
Merge branch 'rpc_test_layer' into k8s_deploy_script
IAvecilla Feb 2, 2024
b0803dc
Deploying seed peers in a different phase
ElFantasma Feb 5, 2024
3a249dc
Retrieving seed peers IPs and using it in the rest of the peers
ElFantasma Feb 5, 2024
d612889
Busy waiting for pods to start to obtain their IPs
ElFantasma Feb 7, 2024
6bd5394
Revert change to have node ips as directory names for local config
IAvecilla Feb 8, 2024
1d58431
Making cli argument optional and forwarding arguments in entrypoint …
ElFantasma Feb 9, 2024
960ff13
Merge branch 'main' into k8s_deploy_script
ElFantasma Feb 9, 2024
c864f51
Fixed compiler warnings
ElFantasma Feb 9, 2024
b5b5ee6
Consensus node now can obtain it's public address from an ENV VAR. Al…
ElFantasma Feb 14, 2024
702a587
Added config RPC endpoint
ElFantasma Feb 15, 2024
1ef6877
Corrected k8s_entrypoint.sh script to forward cli arguments
ElFantasma Feb 15, 2024
5e8b011
Several corrections on naming and coding style
ElFantasma Feb 15, 2024
c62f0b4
Fixed deny.toml for kube.rs
ElFantasma Feb 16, 2024
2e89af8
Fixed clippy suggestions
ElFantasma Feb 19, 2024
fb0c345
Added amount of seed nodes as cli argument
ElFantasma Feb 19, 2024
3b1256f
Merge branch 'main' into k8s_deploy_script
ElFantasma Feb 19, 2024
23a7761
Added brief description for k8s deployment in README.md
ElFantasma Feb 20, 2024
7dbf270
Unified node_name and node_id values
ElFantasma Feb 20, 2024
336a28b
Replaced plain json with k8s_openapi structs in Namespace and Deploym…
ElFantasma Feb 21, 2024
8ec4af5
Fixed clippy suggestions
ElFantasma Feb 21, 2024
bbb6c3e
Improved code quality
ElFantasma Feb 22, 2024
7a817d7
Improved code quality
ElFantasma Feb 22, 2024
4c230b3
Merge branch 'main' into k8s_deploy_script
ElFantasma Feb 22, 2024
755ac47
Fixed deny.toml
ElFantasma Feb 22, 2024
822a94c
Created ConsensusNode struct to make the script more OO
ElFantasma Feb 23, 2024
177bf21
Merge branch 'replace_json_k8s' into improve_get_addrs
ElFantasma Feb 23, 2024
04669a5
Added node and validator key cli args
ElFantasma Feb 27, 2024
5cfde6b
Merge branch 'main' into replace_json_k8s
ElFantasma Feb 27, 2024
10be650
Merge branch 'replace_json_k8s' into improve_get_addrs
ElFantasma Feb 27, 2024
3d7fd70
Fixed clippy suggestions
ElFantasma Feb 27, 2024
af54335
Merge branch 'improve_get_addrs' into full_config_in_cli
ElFantasma Feb 27, 2024
d5a72f4
Added config arg group
ElFantasma Feb 28, 2024
4007877
Merge branch 'main' into improve_get_addrs
ElFantasma Feb 28, 2024
566352c
Merge branch 'improve_get_addrs' into full_config_in_cli
ElFantasma Feb 28, 2024
d328ca5
Config generation in memory and pass it through cli args in entrypoint
ElFantasma Feb 29, 2024
d58f427
Fixed clippy suggestions
ElFantasma Feb 29, 2024
88e5a38
Fixed clippy suggestions
ElFantasma Feb 29, 2024
b63f987
Improved clap argument parsing and making them mutually exclusive
ElFantasma Mar 5, 2024
ee2602d
Upgraded mio version
ElFantasma Mar 6, 2024
f8d46c2
Fixed clippy suggestions
ElFantasma Mar 6, 2024
29cd3a8
Fixed clippy suggestions
ElFantasma Mar 6, 2024
3fcc9ab
Obtain pod ip inside each ConsensusNode
ElFantasma Mar 7, 2024
c1e3711
Upgraded mio version
ElFantasma Mar 7, 2024
e983eee
Merge branch 'main' into improve_get_addrs
ElFantasma Mar 7, 2024
cf28e72
Minor code improvements
ElFantasma Mar 7, 2024
dd280a9
Minor code improvements
ElFantasma Mar 7, 2024
1d7a745
Minor code improvements
ElFantasma Mar 7, 2024
b88646e
Merge branch 'main' into improve_get_addrs
ElFantasma Mar 7, 2024
446ed33
Replaced tokio-retry with simple retry loop
ElFantasma Mar 7, 2024
feb1fa2
Merge branch 'improve_get_addrs' into full_config_in_cli
ElFantasma Mar 7, 2024
14259dd
Improved retry code
ElFantasma Mar 11, 2024
37319e5
Slight code improvement
ElFantasma Mar 12, 2024
7d855e1
Merge branch 'improve_get_addrs' into full_config_in_cli
ElFantasma Mar 12, 2024
0c028dc
Merge branch 'main' into full_config_in_cli
ElFantasma Mar 13, 2024
8d70eec
typo
pompon0 Mar 15, 2024
31db3aa
Merge branch 'main' into full_config_in_cli
ElFantasma Mar 18, 2024
9be2f43
Merge branch 'main' into full_config_in_cli
ElFantasma Mar 18, 2024
a61822d
Making file config and cli config mutually exclusive
ElFantasma Mar 18, 2024
557a05a
Remove test file and reverted clap version
ElFantasma Mar 19, 2024
b4ec675
Restored previous Cargo.toml version to prevent version error in heck
ElFantasma Mar 19, 2024
2c7089a
Merge branch 'main' into full_config_in_cli
ElFantasma Mar 19, 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
4 changes: 0 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,9 @@ COPY --from=builder /app/target/release/tester .
FROM debian:stable-slim as executor-runtime

COPY /node/tools/docker_binaries/executor /node/
COPY /node/tools/k8s_configs/ /node/k8s_config
COPY /node/tools/docker-config/ /node/docker_config
COPY docker-entrypoint.sh /node/
COPY k8s_entrypoint.sh /node/

WORKDIR /node
RUN chmod +x docker-entrypoint.sh
RUN chmod +x k8s_entrypoint.sh

ENTRYPOINT ["./docker-entrypoint.sh"]
Expand Down
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ docker_node_image:
# Kubernetes commands

start_k8s_nodes:
cd ${EXECUTABLE_NODE_DIR} && cargo run --bin deployer generate-config --nodes ${NODES}
$(MAKE) docker_node_image
minikube image load consensus-node:latest
cd ${EXECUTABLE_NODE_DIR} && cargo run --release --bin deployer deploy --nodes ${NODES} --seed-nodes ${SEED_NODES}
cd ${EXECUTABLE_NODE_DIR} && cargo run --release --bin deployer -- --nodes ${NODES} --seed-nodes ${SEED_NODES}

# Clean commands

Expand Down
3 changes: 1 addition & 2 deletions k8s_entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/bin/bash
# This file works as an entrypoint of the kubernetes cluster running the node binary copied inside of it.

cd k8s_config/${NODE_ID}
export RUST_LOG=INFO
../../executor $@
./executor $@
2 changes: 2 additions & 0 deletions node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -156,5 +156,7 @@ wildcard_dependencies = "warn"
redundant_locals = "allow"
needless_pass_by_ref_mut = "allow"
box_default = "allow"
# remove once fix to https://github.com/rust-lang/rust-clippy/issues/11764 is available on CI.
map_identity = "allow"
# &*x is not equivalent to x, because it affects borrowing in closures.
borrow_deref_ref = "allow"
120 changes: 31 additions & 89 deletions node/tools/src/bin/deployer.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
//! Deployer for the kubernetes cluster.
use anyhow::Context;
use clap::{Parser, Subcommand};
use std::{collections::HashMap, fs, path::PathBuf};
use zksync_consensus_crypto::{Text, TextFmt};
use clap::Parser;
use std::collections::HashMap;
use zksync_consensus_roles::{node, validator};
use zksync_consensus_tools::k8s::ConsensusNode;
use zksync_consensus_tools::{k8s, AppConfig};

/// K8s namespace for consensus nodes.
Expand All @@ -13,14 +12,6 @@ const NAMESPACE: &str = "consensus";
#[derive(Debug, Parser)]
#[command(name = "deployer")]
struct DeployerCLI {
/// Subcommand to run.
#[command(subcommand)]
command: DeployerCommands,
}

/// Subcommand arguments.
#[derive(Debug, Parser)]
struct SubCommandArgs {
/// Number of total nodes to deploy.
#[arg(long)]
nodes: usize,
Expand All @@ -29,19 +20,11 @@ struct SubCommandArgs {
seed_nodes: Option<usize>,
}

/// Subcommands.
#[derive(Subcommand, Debug)]
enum DeployerCommands {
/// Generate configs for the nodes.
GenerateConfig(SubCommandArgs),
/// Deploy the nodes.
Deploy(SubCommandArgs),
}

/// Generates config for the nodes to run in the kubernetes cluster
/// Creates a directory for each node in the parent k8s_configs directory.
fn generate_config(nodes: usize) -> anyhow::Result<()> {
/// Generates the configuration for all the nodes to run in the kubernetes cluster
/// and creates a ConsensusNode for each to track their progress
fn generate_consensus_nodes(nodes: usize, seed_nodes_amount: Option<usize>) -> Vec<ConsensusNode> {
assert!(nodes > 0, "at least 1 node has to be specified");
let seed_nodes_amount = seed_nodes_amount.unwrap_or(1);

// Generate the keys for all the replicas.
let rng = &mut rand::thread_rng();
Expand All @@ -56,54 +39,40 @@ fn generate_config(nodes: usize) -> anyhow::Result<()> {

let default_config = AppConfig::default_for(setup.genesis.clone());

let mut cfgs: Vec<_> = (0..nodes).map(|_| default_config.clone()).collect();
let mut cfgs: Vec<ConsensusNode> = (0..nodes)
.map(|i| ConsensusNode {
id: format!("consensus-node-{i:0>2}"),
config: default_config.clone(),
key: node_keys[i].clone(),
validator_key: Some(validator_keys[i].clone()),
node_addr: None, //It's not assigned yet
is_seed: i < seed_nodes_amount,
})
.collect();

// Construct a gossip network with optimal diameter.
for (i, node) in node_keys.iter().enumerate() {
for j in 0..peers {
let next = (i * peers + j + 1) % nodes;
cfgs[next].add_gossip_static_inbound(node.public());
cfgs[next].config.add_gossip_static_inbound(node.public());
}
}

let manifest_path = std::env::var("CARGO_MANIFEST_DIR")?;
let root = PathBuf::from(manifest_path).join("k8s_configs");
let _ = fs::remove_dir_all(&root);
for (i, cfg) in cfgs.into_iter().enumerate() {
let node_config_dir = root.join(format!("consensus-node-{i:0>2}"));
fs::create_dir_all(&node_config_dir)
.with_context(|| format!("create_dir_all({:?})", node_config_dir))?;

cfg.write_to_file(&node_config_dir)?;
fs::write(
node_config_dir.join("validator_key"),
&TextFmt::encode(&validator_keys[i]),
)
.context("fs::write()")?;
fs::write(
node_config_dir.join("node_key"),
&TextFmt::encode(&node_keys[i]),
)
.context("fs::write()")?;
}

Ok(())
cfgs
}

/// Deploys the nodes to the kubernetes cluster.
async fn deploy(nodes_amount: usize, seed_nodes_amount: Option<usize>) -> anyhow::Result<()> {
let mut consensus_nodes = generate_consensus_nodes(nodes_amount, seed_nodes_amount);
let client = k8s::get_client().await?;
k8s::create_or_reuse_namespace(&client, NAMESPACE).await?;
let seed_nodes_amount = seed_nodes_amount.unwrap_or(1);

let seed_nodes = &mut HashMap::new();
let mut non_seed_nodes = HashMap::new();

// Split the nodes in different hash maps as they will be deployed at different stages
let mut consensus_nodes = from_configs(nodes_amount)?;
for (index, node) in consensus_nodes.iter_mut().enumerate() {
if index < seed_nodes_amount {
node.is_seed = true;
for node in consensus_nodes.iter_mut() {
if node.is_seed {
seed_nodes.insert(node.id.to_owned(), node);
} else {
non_seed_nodes.insert(node.id.to_owned(), node);
Expand All @@ -120,58 +89,31 @@ async fn deploy(nodes_amount: usize, seed_nodes_amount: Option<usize>) -> anyhow
node.fetch_and_assign_pod_ip(&client, NAMESPACE).await?;
}

// Build a vector of seed peers NodeAddrs to provide as gossip_static_outbound to the rest of the nodes
// Build a vector of (PublicKey, SocketAddr) to provide as gossip_static_outbound
// to the rest of the nodes
let peers: Vec<_> = seed_nodes
.values()
.map(|n| {
n.node_addr
let node_addr = n
.node_addr
.as_ref()
.expect("Seed node address not defined")
.clone()
.clone();
(node_addr.key, node_addr.addr)
})
.collect();

// Deploy the rest of the nodes
for node in non_seed_nodes.values_mut() {
node.gossip_static_outbound = peers.clone();
node.config.gossip_static_outbound.extend(peers.clone());
node.deploy(&client, NAMESPACE).await?;
}

Ok(())
}

/// Build ConsensusNodes representation list from configurations
// TODO once we can provide config via cli args, this will be replaced
// using in-memory config structs
fn from_configs(nodes: usize) -> anyhow::Result<Vec<k8s::ConsensusNode>> {
let manifest_path = std::env::var("CARGO_MANIFEST_DIR")?;
let root = PathBuf::from(manifest_path).join("k8s_configs");
let mut consensus_nodes = vec![];

for i in 0..nodes {
let node_id = format!("consensus-node-{i:0>2}");
let node_key_path = root.join(&node_id).join("node_key");
let key_string = fs::read_to_string(node_key_path).context("failed reading file")?;
let key = Text::new(&key_string)
.decode()
.context("failed decoding key")?;
consensus_nodes.push(k8s::ConsensusNode {
id: node_id,
key,
node_addr: None,
is_seed: false,
gossip_static_outbound: vec![],
});
}
Ok(consensus_nodes)
}

#[tokio::main]
async fn main() -> anyhow::Result<()> {
let DeployerCLI { command } = DeployerCLI::parse();

match command {
DeployerCommands::GenerateConfig(args) => generate_config(args.nodes),
DeployerCommands::Deploy(args) => deploy(args.nodes, args.seed_nodes).await,
}
let args = DeployerCLI::parse();
deploy(args.nodes, args.seed_nodes).await
}
100 changes: 63 additions & 37 deletions node/tools/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,57 +150,83 @@ impl ProtoFmt for AppConfig {
}
}

/// This struct holds the file path to each of the config files.
/// Configuration information.
#[derive(Debug)]
pub struct ConfigPaths<'a> {
/// Path to a JSON file with node configuration.
pub app: &'a Path,
/// Path to a validator key file.
pub validator_key: Option<&'a Path>,
/// Path to a node key file.
pub node_key: &'a Path,
pub struct ConfigArgs<'a> {
/// Node configuration.
pub config_args: ConfigSource<'a>,
/// Path to the rocksdb database.
pub database: &'a Path,
}

#[derive(Debug)]
pub enum ConfigSource<'a> {
CliConfig {
/// Node configuration from command line.
config: AppConfig,
/// Node key as a string.
node_key: node::SecretKey,
/// Validator key as a string.
validator_key: Option<validator::SecretKey>,
},
PathConfig {
/// Path to a JSON file with node configuration.
config_file: &'a Path,
/// Path to a validator key file.
validator_key_file: &'a Path,
/// Path to a node key file.
node_key_file: &'a Path,
},
}

pub struct Configs {
pub app: AppConfig,
pub validator_key: Option<validator::SecretKey>,
pub node_key: node::SecretKey,
pub database: PathBuf,
}

impl<'a> ConfigPaths<'a> {
impl<'a> ConfigArgs<'a> {
// Loads configs from the file system.
pub fn load(self) -> anyhow::Result<Configs> {
Ok(Configs {
app: (|| {
let app = fs::read_to_string(self.app).context("failed reading file")?;
decode_json::<Serde<AppConfig>>(&app).context("failed decoding JSON")
})()
.with_context(|| self.app.display().to_string())?
.0,

validator_key: self
.validator_key
.as_ref()
.map(|file| {
(|| {
let key = fs::read_to_string(file).context("failed reading file")?;
Text::new(&key).decode().context("failed decoding key")
})()
.with_context(|| file.display().to_string())
})
.transpose()?,

node_key: (|| {
let key = fs::read_to_string(self.node_key).context("failed reading file")?;
Text::new(&key).decode().context("failed decoding key")
})()
.with_context(|| self.node_key.display().to_string())?,

database: self.database.into(),
})
match self.config_args {
ConfigSource::CliConfig {
config,
node_key,
validator_key,
} => Ok(Configs {
app: config.clone(),
validator_key: validator_key.clone(),
node_key: node_key.clone(),
database: self.database.into(),
}),
ConfigSource::PathConfig {
config_file,
validator_key_file,
node_key_file,
} => Ok(Configs {
app: (|| {
let app = fs::read_to_string(config_file).context("failed reading file")?;
decode_json::<Serde<AppConfig>>(&app).context("failed decoding JSON")
})()
.with_context(|| config_file.display().to_string())?
.0,

validator_key: fs::read_to_string(validator_key_file)
.ok()
.map(|value| Text::new(&value).decode().context("failed decoding key"))
.transpose()
.with_context(|| validator_key_file.display().to_string())?,

node_key: (|| {
let key = fs::read_to_string(node_key_file).context("failed reading file")?;
Text::new(&key).decode().context("failed decoding key")
})()
.with_context(|| node_key_file.display().to_string())?,

database: self.database.into(),
}),
}
}
}

Expand Down
Loading
Loading