Skip to content

Commit

Permalink
feat(p2p-client): bootstrapping
Browse files Browse the repository at this point in the history
  • Loading branch information
storopoli committed Feb 27, 2025
1 parent f120207 commit 19aca8f
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 10 deletions.
22 changes: 14 additions & 8 deletions Cargo.lock

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

7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ members = [
"bin/p2p-client",
]

default-members = ["bin/strata-bridge", "bin/dev-cli", "bin/assert-splitter"]
default-members = [
"bin/strata-bridge",
"bin/dev-cli",
"bin/assert-splitter",
"bin/p2p-client",
]

resolver = "2"

Expand Down
8 changes: 8 additions & 0 deletions bin/p2p-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,11 @@ rust.unused_must_use = "deny"
strata-p2p.workspace = true
strata-p2p-types.workspace = true
strata-p2p-wire.workspace = true

strata-common.workspace = true

anyhow.workspace = true
chrono.workspace = true
clap.workspace = true
tokio.workspace = true
tracing.workspace = true
8 changes: 8 additions & 0 deletions bin/p2p-client/src/bootstrap.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//! Module to bootstrap the p2p node by hooking up all the required services.
use crate::cli::Cli;

/// Bootstrap the p2p node by hooking up all the required services.
pub(crate) async fn bootstrap(args: Cli) {
todo!()
}
32 changes: 32 additions & 0 deletions bin/p2p-client/src/cli.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//! Parses command-line arguments for the p2p-client CLI.
use clap::{crate_version, Parser};

use crate::constants::{
DEFAULT_NUM_THREADS, DEFAULT_RPC_HOST, DEFAULT_RPC_PORT, DEFAULT_STACK_SIZE_MB,
};

/// CLI arguments for the p2p-client.
#[derive(Debug, Parser)]
#[clap(
name = "strata-bridge",
about = "The bridge node for Strata",
version = crate_version!()
)]
pub(crate) struct Cli {
/// RPC server host for the p2p node.
#[clap(long, help = "RPC server host for the p2p node", default_value_t = DEFAULT_RPC_HOST.to_string())]
pub rpc_host: String,

/// RPC server port for the p2p node.
#[clap(long, help = "RPC server port for the p2p node", default_value_t = DEFAULT_RPC_PORT)]
pub rpc_port: u32,

/// The number of tokio threads to use.
#[clap(long, help = "The number of tokio threads to use", default_value_t = DEFAULT_NUM_THREADS)]
pub num_threads: usize,

/// The stack size per thread (in MB).
#[clap(long, help = "The stack size per thread (in MB)", default_value_t = DEFAULT_STACK_SIZE_MB)]
pub stack_size: usize,
}
13 changes: 13 additions & 0 deletions bin/p2p-client/src/constants.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//! Constants used throughout the p2p-client.
/// Default RPC host.
pub(crate) const DEFAULT_RPC_HOST: &str = "127.0.0.1";

/// Default RPC port.
pub(crate) const DEFAULT_RPC_PORT: u32 = 4780;

/// Default number of threads.
pub(crate) const DEFAULT_NUM_THREADS: usize = 2;

/// Default stack size in MB.
pub(crate) const DEFAULT_STACK_SIZE_MB: usize = 512;
36 changes: 35 additions & 1 deletion bin/p2p-client/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,37 @@
//! The p2p-client binary main entry point.
#![expect(incomplete_features)] // the generic_const_exprs feature is incomplete
#![feature(generic_const_exprs)] // but necessary for using const generic bounds in p2p crate

use clap::Parser;
use cli::Cli;
use strata_common::logging::{self, LoggerConfig};
use tokio::runtime;
use tracing::{info, trace};

use crate::bootstrap::bootstrap;

mod bootstrap;
mod cli;
mod constants;

/// Main function for the p2p-client binary.
fn main() {
println!("Hello, world!");
logging::init(LoggerConfig::new("bridge-node".to_string()));

let cli_args: Cli = Cli::parse();

info!("starting node");
trace!(action = "creating runtime", num_threads = %cli_args.num_threads, stack_size_per_thread_mb = %cli_args.stack_size);

const NUM_BYTES_PER_MB: usize = 1024 * 1024;
let runtime = runtime::Builder::new_multi_thread()
.worker_threads(cli_args.num_threads)
.thread_stack_size(cli_args.stack_size * NUM_BYTES_PER_MB)
.enable_all()
.build()
.expect("must be able to create runtime");

runtime.block_on(async {
bootstrap(cli_args).await;
});
}

0 comments on commit 19aca8f

Please sign in to comment.