mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
chore: more launch builder style function (#7897)
This commit is contained in:
@ -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>> {
|
||||
@ -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())
|
||||
@ -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()?;
|
||||
|
||||
@ -95,6 +95,7 @@ where
|
||||
config,
|
||||
} = target;
|
||||
|
||||
// setup the launch context
|
||||
let ctx = ctx
|
||||
.with_configured_globals()
|
||||
// load the toml config
|
||||
@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user