Skip to content

Commit

Permalink
fix: initialize da layer type and consts import
Browse files Browse the repository at this point in the history
  • Loading branch information
sebasti810 authored and distractedm1nd committed Jul 8, 2024
1 parent 06cc291 commit 8e254d4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
19 changes: 7 additions & 12 deletions src/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub struct Config {

#[derive(Debug, Default, Clone, Eq, PartialEq, Deserialize)]
#[cfg_attr(feature = "serde", derive(SerializeDisplay, DeserializeFromStr))]
enum DALayerOption {
pub enum DALayerOption {
#[default]
Celestia,
#[cfg(test)]
Expand Down Expand Up @@ -165,9 +165,7 @@ pub fn load_config(args: CommandLineArgs) -> Result<Config, config::ConfigError>
}

#[cfg(not(test))]
pub async fn initialize_da_layer(
config: &Config,
) -> Option<Arc<dyn DataAvailabilityLayer + 'static>> {
pub async fn initialize_da_layer(config: &Config) -> Arc<dyn DataAvailabilityLayer + 'static> {
match &config.da_layer {
DALayerOption::Celestia => {
let celestia_conf = config.clone().celestia_config.unwrap();
Expand All @@ -178,20 +176,17 @@ pub async fn initialize_da_layer(
)
.await
{
Ok(da) => Some(Arc::new(da) as Arc<dyn DataAvailabilityLayer + 'static>),
Ok(da) => Arc::new(da) as Arc<dyn DataAvailabilityLayer + 'static>,
Err(e) => {
error!("Failed to connect to Celestia: {}", e);
None
panic!("Failed to connect to Celestia: {}", e);
}
}
}
DALayerOption::None => None,
DALayerOption::None => panic!("No DALayer"),
}
}

#[cfg(test)]
pub async fn initialize_da_layer(
_config: &Config,
) -> Option<Arc<dyn DataAvailabilityLayer + 'static>> {
Some(Arc::new(LocalDataAvailabilityLayer::new()) as Arc<dyn DataAvailabilityLayer + 'static>)
pub async fn initialize_da_layer(_config: &Config) -> Arc<dyn DataAvailabilityLayer + 'static> {
Arc::new(LocalDataAvailabilityLayer::new()) as Arc<dyn DataAvailabilityLayer + 'static>
}
3 changes: 2 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
mod cfg;
pub mod consts;
pub mod da;
pub mod error;
mod node_types;
Expand Down Expand Up @@ -44,7 +45,7 @@ async fn main() -> std::io::Result<()> {

let node: Arc<dyn NodeType> = match args.command {
// LightClients need a DA layer, so we can unwrap here
Commands::LightClient {} => Arc::new(LightClient::new(da.unwrap(), config.public_key)),
Commands::LightClient {} => Arc::new(LightClient::new(da, config.public_key)),
Commands::Sequencer {} => Arc::new(Sequencer::new(
// TODO: convert error to std::io::Error...is there a better solution?
Arc::new(
Expand Down

0 comments on commit 8e254d4

Please sign in to comment.