Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 41 additions & 14 deletions src/tasks/block/sim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,30 @@ pub struct SimResult {
/// The block built with the successfully simulated transactions
pub block: BuiltBlock,
/// The block environment the transactions were simulated against.
pub env: SimEnv,
pub sim_env: SimEnv,
}

impl SimResult {
/// Returns the block number of the built block.
pub const fn block_number(&self) -> u64 {
self.block.block_number()
}

/// Returns the host block number for the built block.
pub const fn host_block_number(&self) -> u64 {
self.sim_env.host_block_number()
}

/// Returns a reference to the tracing span associated with this simulation
/// result.
pub const fn span(&self) -> &tracing::Span {
self.sim_env.span()
}

/// Clones the span for use in other tasks.
pub fn clone_span(&self) -> tracing::Span {
self.sim_env.clone_span()
}
}

impl Simulator {
Expand Down Expand Up @@ -182,27 +205,31 @@ impl Simulator {
return;
}
let Some(sim_env) = self.sim_env.borrow_and_update().clone() else { return };
let block_number = sim_env.block_env.number.to::<u64>();
info!(block_number, "new block environment received");

let span = sim_env.span();

span.in_scope(|| {
info!("new block environment received");
});

// Calculate the deadline for this block simulation.
// NB: This must happen _after_ taking a reference to the sim cache,
// waiting for a new block, and checking current slot authorization.
let finish_by = self.calculate_deadline();
let sim_cache = cache.clone();
match self

let Ok(block) = self
.handle_build(constants.clone(), sim_cache, finish_by, sim_env.block_env.clone())
.instrument(span.clone())
.await
{
Ok(block) => {
debug!(block = ?block.block_number(), tx_count = block.transactions().len(), "built simulated block");
let _ = submit_sender.send(SimResult { block, env: sim_env });
}
Err(e) => {
error!(err = %e, "failed to build block");
continue;
}
}
.inspect_err(|err| span.in_scope(|| error!(%err, "error during block build")))
else {
continue;
};

let _guard = span.clone().entered();
debug!(block = ?block.block_number(), tx_count = block.transactions().len(), "built simulated block");
let _ = submit_sender.send(SimResult { block, sim_env });
}
}

Expand Down
27 changes: 26 additions & 1 deletion src/tasks/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,30 @@ pub struct SimEnv {
pub prev_header: Header,
/// The header of the previous host block.
pub prev_host: Header,
/// A tracing span associated with this block
pub span: tracing::Span,
}

impl SimEnv {
/// Returns the block number of the signet block environment.
pub const fn block_number(&self) -> u64 {
self.prev_header.number.saturating_add(1)
}

/// Returns the host block number for the signet block environment.
pub const fn host_block_number(&self) -> u64 {
self.prev_host.number.saturating_add(1)
}

/// Returns a reference to the tracing span associated with this block env.
pub const fn span(&self) -> &tracing::Span {
&self.span
}

/// Clones the span for use in other tasks.
pub fn clone_span(&self) -> tracing::Span {
self.span.clone()
}
}

impl EnvTask {
Expand Down Expand Up @@ -95,7 +119,7 @@ impl EnvTask {
let host_block_number =
self.constants.rollup_block_to_host_block_num(rollup_header.number);

let span = info_span!("EnvTask::task_fut::loop", %host_block_number, %rollup_header.hash, %rollup_header.number);
let span = info_span!("SimEnv", %host_block_number, %rollup_header.hash, %rollup_header.number);

let host_block_opt = res_unwrap_or_continue!(
self.host_provider.get_block_by_number(host_block_number.into()).await,
Expand All @@ -120,6 +144,7 @@ impl EnvTask {

if sender
.send(Some(SimEnv {
span,
block_env: signet_env,
prev_header: rollup_header.inner,
prev_host,
Expand Down
10 changes: 2 additions & 8 deletions src/tasks/submit/builder_helper/submit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,13 +244,7 @@ impl BuilderHelperTask {
let ru_block_number = sim_result.block.block_number();
let host_block_number = self.constants.rollup_block_to_host_block_num(ru_block_number);

let span = debug_span!(
parent: None,
"SubmitTask::task_future::transaction_prep",
ru_block_number,
host_block_number,
block_tx_count = sim_result.block.tx_count(),
);
let span = sim_result.sim_env.span.clone();

let guard = span.enter();

Expand Down Expand Up @@ -283,7 +277,7 @@ impl BuilderHelperTask {
self.constants.clone(),
);
let bumpable = res_unwrap_or_continue!(
prep.prep_transaction(&sim_result.env.prev_host)
prep.prep_transaction(&sim_result.sim_env.prev_host)
.instrument(submission_span.clone())
.await,
submission_span,
Expand Down
Loading