Skip to content

Commit

Permalink
try_cast
Browse files Browse the repository at this point in the history
  • Loading branch information
rob-maron committed Jun 14, 2024
1 parent 98ad78b commit 257727b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
15 changes: 12 additions & 3 deletions sequencer/src/bin/cdn-broker.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! The following is the main `Broker` binary, which just instantiates and runs
//! a `Broker` object.
use anyhow::Result;
use anyhow::{Context, Result};
use cdn_broker::reexports::crypto::signature::KeyPair;
use cdn_broker::{Broker, Config};
use clap::Parser;
Expand Down Expand Up @@ -83,7 +83,7 @@ struct Args {
value_parser = parse_size,
env = "ESPRESSO_CDN_BROKER_GLOBAL_MEMORY_POOL_SIZE"
)]
global_memory_pool_size: usize,
global_memory_pool_size: u64,
}
#[async_std::main]
async fn main() -> Result<()> {
Expand All @@ -107,6 +107,15 @@ async fn main() -> Result<()> {
let (public_key, private_key) =
<SeqTypes as NodeType>::SignatureKey::generated_from_seed_indexed(key_hash.into(), 1337);

// Cast the memory pool size to a `usize`
let global_memory_pool_size =
usize::try_from(args.global_memory_pool_size).with_context(|| {
format!(
"Failed to convert global memory pool size to usize: {}",
args.global_memory_pool_size
)
})?;

// Create config
let broker_config: Config<ProductionDef<SeqTypes>> = Config {
ca_cert_path: args.ca_cert_path,
Expand All @@ -123,7 +132,7 @@ async fn main() -> Result<()> {
public_advertise_endpoint: args.public_advertise_endpoint,
private_bind_endpoint: args.private_bind_endpoint,
private_advertise_endpoint: args.private_advertise_endpoint,
global_memory_pool_size: Some(args.global_memory_pool_size),
global_memory_pool_size: Some(global_memory_pool_size),
};

// Create new `Broker`
Expand Down
13 changes: 11 additions & 2 deletions sequencer/src/bin/cdn-marshal.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! The following is the main `Marshal` binary, which just instantiates and runs
//! a `Marshal` object.
use anyhow::Result;
use anyhow::{Context, Result};
use cdn_marshal::{Config, Marshal};
use clap::Parser;
use sequencer::{network::cdn::ProductionDef, options::parse_size, SeqTypes};
Expand Down Expand Up @@ -68,14 +68,23 @@ async fn main() -> Result<()> {
.init();
}

// Cast the memory pool size to a `usize`
let global_memory_pool_size =
usize::try_from(args.global_memory_pool_size).with_context(|| {
format!(
"Failed to convert global memory pool size to usize: {}",
args.global_memory_pool_size
)
})?;

// Create a new `Config`
let config = Config {
discovery_endpoint: args.discovery_endpoint,
bind_endpoint: format!("0.0.0.0:{}", args.bind_port),
metrics_bind_endpoint: args.metrics_bind_endpoint,
ca_cert_path: args.ca_cert_path,
ca_key_path: args.ca_key_path,
global_memory_pool_size: Some(args.global_memory_pool_size),
global_memory_pool_size: Some(global_memory_pool_size),
};

// Create new `Marshal` from the config
Expand Down

0 comments on commit 257727b

Please sign in to comment.