Skip to content

Commit 3ad3bbc

Browse files
authored
chore: more launch builder style function (#7897)
1 parent 844bcb8 commit 3ad3bbc

File tree

2 files changed

+35
-10
lines changed

2 files changed

+35
-10
lines changed

crates/node-builder/src/launch/common.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,16 @@ impl<T> LaunchContextWith<T> {
145145
attachment: Attached::new(self.attachment, attachment),
146146
}
147147
}
148+
149+
/// Consumes the type and calls a function with a reference to the context.
150+
// Returns the context again
151+
pub fn inspect<F>(self, f: F) -> Self
152+
where
153+
F: FnOnce(&Self),
154+
{
155+
f(&self);
156+
self
157+
}
148158
}
149159

150160
impl<L, R> LaunchContextWith<Attached<L, R>> {
@@ -338,6 +348,12 @@ where
338348
)
339349
}
340350

351+
/// Convenience function to [Self::init_genesis]
352+
pub fn with_genesis(self) -> Result<Self, InitDatabaseError> {
353+
init_genesis(self.provider_factory().clone())?;
354+
Ok(self)
355+
}
356+
341357
/// Write the genesis block and state if it has not already been written
342358
pub fn init_genesis(&self) -> Result<B256, InitDatabaseError> {
343359
init_genesis(self.provider_factory().clone())
@@ -352,6 +368,12 @@ where
352368
self.node_config().max_block(client, self.provider_factory().clone()).await
353369
}
354370

371+
/// Convenience function to [Self::start_prometheus_endpoint]
372+
pub async fn with_prometheus(self) -> eyre::Result<Self> {
373+
self.start_prometheus_endpoint().await?;
374+
Ok(self)
375+
}
376+
355377
/// Starts the prometheus endpoint.
356378
pub async fn start_prometheus_endpoint(&self) -> eyre::Result<()> {
357379
let prometheus_handle = self.node_config().install_prometheus_recorder()?;

crates/node-builder/src/launch/mod.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ where
9595
config,
9696
} = target;
9797

98+
// setup the launch context
9899
let ctx = ctx
99100
.with_configured_globals()
100101
// load the toml config
@@ -104,16 +105,18 @@ where
104105
// ensure certain settings take effect
105106
.with_adjusted_configs()
106107
// Create the provider factory
107-
.with_provider_factory()?;
108-
109-
info!(target: "reth::cli", "Database opened");
110-
111-
ctx.start_prometheus_endpoint().await?;
112-
113-
debug!(target: "reth::cli", chain=%ctx.chain_id(), genesis=?ctx.genesis_hash(), "Initializing genesis");
114-
ctx.init_genesis()?;
115-
116-
info!(target: "reth::cli", "\n{}", ctx.chain_spec().display_hardforks());
108+
.with_provider_factory()?
109+
.inspect(|_| {
110+
info!(target: "reth::cli", "Database opened");
111+
})
112+
.with_prometheus().await?
113+
.inspect(|this| {
114+
debug!(target: "reth::cli", chain=%this.chain_id(), genesis=?this.genesis_hash(), "Initializing genesis");
115+
})
116+
.with_genesis()?
117+
.inspect(|this| {
118+
info!(target: "reth::cli", "\n{}", this.chain_spec().display_hardforks());
119+
});
117120

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

0 commit comments

Comments
 (0)