Skip to content

Commit

Permalink
chore: more launch builder style function (#7897)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored Apr 25, 2024
1 parent 844bcb8 commit 3ad3bbc
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 10 deletions.
22 changes: 22 additions & 0 deletions crates/node-builder/src/launch/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,16 @@ impl<T> LaunchContextWith<T> {
attachment: Attached::new(self.attachment, attachment),
}
}

/// Consumes the type and calls a function with a reference to the context.
// Returns the context again
pub fn inspect<F>(self, f: F) -> Self
where
F: FnOnce(&Self),
{
f(&self);
self
}
}

impl<L, R> LaunchContextWith<Attached<L, R>> {
Expand Down Expand Up @@ -338,6 +348,12 @@ where
)
}

/// Convenience function to [Self::init_genesis]
pub fn with_genesis(self) -> Result<Self, InitDatabaseError> {
init_genesis(self.provider_factory().clone())?;
Ok(self)
}

/// Write the genesis block and state if it has not already been written
pub fn init_genesis(&self) -> Result<B256, InitDatabaseError> {
init_genesis(self.provider_factory().clone())
Expand All @@ -352,6 +368,12 @@ where
self.node_config().max_block(client, self.provider_factory().clone()).await
}

/// Convenience function to [Self::start_prometheus_endpoint]
pub async fn with_prometheus(self) -> eyre::Result<Self> {
self.start_prometheus_endpoint().await?;
Ok(self)
}

/// Starts the prometheus endpoint.
pub async fn start_prometheus_endpoint(&self) -> eyre::Result<()> {
let prometheus_handle = self.node_config().install_prometheus_recorder()?;
Expand Down
23 changes: 13 additions & 10 deletions crates/node-builder/src/launch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ where
config,
} = target;

// setup the launch context
let ctx = ctx
.with_configured_globals()
// load the toml config
Expand All @@ -104,16 +105,18 @@ where
// ensure certain settings take effect
.with_adjusted_configs()
// Create the provider factory
.with_provider_factory()?;

info!(target: "reth::cli", "Database opened");

ctx.start_prometheus_endpoint().await?;

debug!(target: "reth::cli", chain=%ctx.chain_id(), genesis=?ctx.genesis_hash(), "Initializing genesis");
ctx.init_genesis()?;

info!(target: "reth::cli", "\n{}", ctx.chain_spec().display_hardforks());
.with_provider_factory()?
.inspect(|_| {
info!(target: "reth::cli", "Database opened");
})
.with_prometheus().await?
.inspect(|this| {
debug!(target: "reth::cli", chain=%this.chain_id(), genesis=?this.genesis_hash(), "Initializing genesis");
})
.with_genesis()?
.inspect(|this| {
info!(target: "reth::cli", "\n{}", this.chain_spec().display_hardforks());
});

// setup the consensus instance
let consensus: Arc<dyn Consensus> = if ctx.is_dev() {
Expand Down

0 comments on commit 3ad3bbc

Please sign in to comment.