Skip to content

Commit

Permalink
Str 786 main refactor part1 (#561)
Browse files Browse the repository at this point in the history
* Update task manager interface

* Add DbManagers to consolidate managers

* Move db helpers to rocksdb crate

* Move config to common

* (config): Add a new crate config

* Some cleanup in args module

* storage: Rename DbManagers to NodeStorage

---------

Co-authored-by: Bibek Pandey <[email protected]>
  • Loading branch information
bewakes and Bibek Pandey authored Jan 3, 2025
1 parent 6a48602 commit ef1097b
Show file tree
Hide file tree
Showing 25 changed files with 546 additions and 467 deletions.
17 changes: 16 additions & 1 deletion Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ members = [
"crates/btcio",
"crates/chaintsn",
"crates/common",
"crates/config",
"crates/consensus-logic",
"crates/crypto",
"crates/db",
Expand Down Expand Up @@ -82,6 +83,7 @@ strata-bridge-tx-builder = { path = "crates/bridge-tx-builder" }
strata-btcio = { path = "crates/btcio" }
strata-chaintsn = { path = "crates/chaintsn" }
strata-common = { path = "crates/common" }
strata-config = { path = "crates/config" }
strata-consensus-logic = { path = "crates/consensus-logic" }
strata-crypto = { path = "crates/crypto", default-features = false }
strata-db = { path = "crates/db" }
Expand Down
1 change: 1 addition & 0 deletions bin/strata-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ strata-bridge-relay.workspace = true
strata-bridge-tx-builder.workspace = true
strata-btcio.workspace = true
strata-common.workspace = true
strata-config.workspace = true
strata-consensus-logic.workspace = true
strata-db.workspace = true
strata-eectl.workspace = true
Expand Down
106 changes: 105 additions & 1 deletion bin/strata-client/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ use std::path::PathBuf;

use argh::FromArgs;
use bitcoin::Network;
use strata_config::{
BitcoindConfig, ClientConfig, ClientMode, Config, ExecConfig, FullNodeConfig, RelayerConfig,
RethELConfig, SequencerConfig, SyncConfig,
};

#[derive(Debug, Clone, FromArgs)]
#[argh(description = "Alpen Strata sequencer")]
Expand Down Expand Up @@ -45,7 +49,7 @@ pub struct Args {
pub reth_authrpc: Option<String>,

#[argh(option, description = "path to reth authrpc jwtsecret")]
pub reth_jwtsecret: Option<PathBuf>,
pub reth_jwtsecret: PathBuf,

#[argh(option, short = 's', description = "sequencer bitcoin address")]
pub sequencer_bitcoin_address: Option<String>,
Expand All @@ -57,3 +61,103 @@ pub struct Args {
#[argh(option, description = "database retry count")]
pub db_retry_count: Option<u16>,
}

impl Args {
pub fn derive_config(&self) -> Result<Config, String> {
let args = self.clone();
Ok(Config {
bitcoind_rpc: BitcoindConfig {
rpc_url: require(args.bitcoind_host, "args: no bitcoin --rpc-url provided")?,
rpc_user: require(args.bitcoind_user, "args: no bitcoin --rpc-user provided")?,
rpc_password: require(
args.bitcoind_password,
"args: no bitcoin --rpc-password provided",
)?,
network: require(args.network, "args: no bitcoin --network provided")?,
},
client: ClientConfig {
rpc_host: require(args.rpc_host, "args: no client --rpc-host provided")?,
rpc_port: require(args.rpc_port, "args: no client --rpc-port provided")?,
datadir: require(args.datadir, "args: no client --datadir provided")?,
client_mode: {
if let Some(sequencer_key) = args.sequencer_key {
ClientMode::Sequencer(SequencerConfig {
sequencer_key,
sequencer_bitcoin_address: args.sequencer_bitcoin_address,
})
} else if let Some(sequencer_rpc) = args.sequencer_rpc {
ClientMode::FullNode(FullNodeConfig { sequencer_rpc })
} else {
return Err(
"args: no client --sequencer-key or --sequencer-bitcion-address provided or --sequencer-rpc provided"
.to_string(),
);
}
},
l2_blocks_fetch_limit: 1_000,
db_retry_count: 5,
},
sync: SyncConfig {
l1_follow_distance: 6,
max_reorg_depth: 4,
client_poll_dur_ms: 200,
client_checkpoint_interval: 10,
},
exec: ExecConfig {
reth: RethELConfig {
rpc_url: args.reth_authrpc.unwrap_or("".to_string()), // TODO: sensible default
secret: args.reth_jwtsecret,
},
},
relayer: RelayerConfig {
refresh_interval: 10,
stale_duration: 120,
relay_misc: true,
},
})
}

pub fn update_config(&self, config: &mut Config) {
let args = self.clone();
config.exec.reth.secret = args.reth_jwtsecret;

if let Some(rpc_user) = args.bitcoind_user {
config.bitcoind_rpc.rpc_user = rpc_user;
}
if let Some(rpc_url) = args.bitcoind_host {
config.bitcoind_rpc.rpc_url = rpc_url;
}
if let Some(rpc_password) = args.bitcoind_password {
config.bitcoind_rpc.rpc_password = rpc_password;
}
if let Some(rpc_host) = args.rpc_host {
config.client.rpc_host = rpc_host;
}
if let Some(rpc_port) = args.rpc_port {
config.client.rpc_port = rpc_port;
}
if let Some(datadir) = args.datadir {
config.client.datadir = datadir;
}
// sequencer_key has priority over sequencer_rpc if both are provided

if let Some(sequencer_key) = args.sequencer_key {
config.client.client_mode = ClientMode::Sequencer(SequencerConfig {
sequencer_key,
sequencer_bitcoin_address: args.sequencer_bitcoin_address,
});
} else if let Some(sequencer_rpc) = args.sequencer_rpc {
config.client.client_mode = ClientMode::FullNode(FullNodeConfig { sequencer_rpc });
}
if let Some(rpc_url) = args.reth_authrpc {
config.exec.reth.rpc_url = rpc_url;
}
if let Some(db_retry_count) = args.db_retry_count {
config.client.db_retry_count = db_retry_count;
}
}
}

fn require<T>(field: Option<T>, err_msg: &str) -> Result<T, String> {
field.ok_or_else(|| err_msg.to_string())
}
Loading

0 comments on commit ef1097b

Please sign in to comment.