Skip to content

Commit

Permalink
fix: Use magic from source in daemon bootstrap (#166)
Browse files Browse the repository at this point in the history
  • Loading branch information
scarmuega authored Feb 26, 2022
1 parent c706fb2 commit 5c15b60
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
27 changes: 24 additions & 3 deletions src/bin/oura/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use oura::{
BootstrapResult, FilterProvider, PartialBootstrapResult, SinkProvider, SourceProvider,
StageReceiver,
},
sources::MagicArg,
utils::{cursor, metrics, ChainWellKnownInfo, Utils, WithUtils},
Error,
};
Expand Down Expand Up @@ -51,6 +52,13 @@ fn bootstrap_source(config: Source, utils: Arc<Utils>) -> PartialBootstrapResult
}
}

fn infer_magic_from_source(config: &Source) -> Option<MagicArg> {
match config {
Source::N2C(config) => config.magic.clone(),
Source::N2N(config) => config.magic.clone(),
}
}

#[derive(Debug, Deserialize)]
#[serde(tag = "type")]
enum Filter {
Expand Down Expand Up @@ -151,13 +159,22 @@ impl ConfigRoot {
}
}

fn define_chain_info(
explicit: Option<ChainWellKnownInfo>,
magic: &MagicArg,
) -> Result<ChainWellKnownInfo, Error> {
match explicit {
Some(x) => Ok(x),
None => ChainWellKnownInfo::try_from_magic(**magic),
}
}

fn bootstrap_utils(
chain: Option<ChainWellKnownInfo>,
chain: ChainWellKnownInfo,
cursor: Option<cursor::Config>,
metrics: Option<metrics::Config>,
) -> Utils {
let well_known = chain.unwrap_or_default();
let mut utils = Utils::new(well_known);
let mut utils = Utils::new(chain);

if let Some(cursor) = cursor {
utils = utils.with_cursor(cursor);
Expand All @@ -181,6 +198,10 @@ fn bootstrap(config: ConfigRoot) -> Result<Vec<JoinHandle<()>>, Error> {
metrics,
} = config;

let magic = infer_magic_from_source(&source).unwrap_or_default();

let chain = define_chain_info(chain, &magic)?;

let utils = Arc::new(bootstrap_utils(chain, cursor, metrics));

let mut threads = Vec::with_capacity(10);
Expand Down
2 changes: 1 addition & 1 deletion src/sources/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl ToString for PointArg {
}
}

#[derive(Debug, Deserialize)]
#[derive(Debug, Deserialize, Clone)]
pub struct MagicArg(pub u64);

impl Deref for MagicArg {
Expand Down

0 comments on commit 5c15b60

Please sign in to comment.