Skip to content
Open
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
31 changes: 30 additions & 1 deletion crates/op-rbuilder/src/builder/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,27 @@ pub(super) struct BlockPayloadJobGenerator<Client, Tasks, Builder> {
extra_block_deadline: std::time::Duration,
/// Stored `cached_reads` for new payload jobs.
pre_cached: Option<PrecachedState>,
/// The configured block time
block_time: std::time::Duration,
/// Metrics for recording telemetry
metrics: Arc<crate::metrics::OpRBuilderMetrics>,
}

// === impl EmptyBlockPayloadJobGenerator ===

impl<Client, Tasks, Builder> BlockPayloadJobGenerator<Client, Tasks, Builder> {
/// Creates a new [EmptyBlockPayloadJobGenerator] with the given config and custom
/// [PayloadBuilder]
#[expect(clippy::too_many_arguments)]
pub(super) fn with_builder(
client: Client,
executor: Tasks,
config: BasicPayloadJobGeneratorConfig,
builder: Builder,
ensure_only_one_payload: bool,
extra_block_deadline: std::time::Duration,
block_time: std::time::Duration,
metrics: Arc<crate::metrics::OpRBuilderMetrics>,
) -> Self {
Self {
client,
Expand All @@ -105,6 +112,8 @@ impl<Client, Tasks, Builder> BlockPayloadJobGenerator<Client, Tasks, Builder> {
last_payload: Arc::new(Mutex::new(CancellationToken::new())),
extra_block_deadline,
pre_cached: None,
block_time,
metrics,
}
}

Expand Down Expand Up @@ -139,6 +148,21 @@ where
&self,
attributes: <Builder as PayloadBuilder>::Attributes,
) -> Result<Self::Job, PayloadBuilderError> {
// Calculate and record FCU arrival delay metric in milliseconds
// Expected: FCU should arrive at (payload_timestamp - block_time)
// Positive delay = FCU arrived late, Negative = FCU arrived early
let timestamp = attributes.timestamp();
let now = SystemTime::now();
let expected_fcu_arrival =
SystemTime::UNIX_EPOCH + Duration::from_secs(timestamp) - self.block_time;
let fcu_arrival_delay_ms = now
.duration_since(expected_fcu_arrival)
.map(|d| d.as_millis() as i64)
.unwrap_or_else(|e| -(e.duration().as_millis() as i64));
self.metrics
.fcu_arrival_delay
.record(fcu_arrival_delay_ms as f64);

let cancel_token = if self.ensure_only_one_payload {
// Cancel existing payload
{
Expand Down Expand Up @@ -168,7 +192,10 @@ where
.ok_or_else(|| PayloadBuilderError::MissingParentBlock(attributes.parent()))?
};

info!("Spawn block building job");
info!(
target: "payload_builder",
id = %attributes.payload_id(),
"Spawn block building job");

// The deadline is critical for payload availability. If we reach the deadline,
// the payload job stops and cannot be queried again. With tight deadlines close
Expand Down Expand Up @@ -683,6 +710,8 @@ mod tests {
builder.clone(),
false,
std::time::Duration::from_secs(1),
std::time::Duration::from_secs(2),
Arc::new(crate::metrics::OpRBuilderMetrics::default()),
);

// this is not nice but necessary
Expand Down
4 changes: 2 additions & 2 deletions crates/op-rbuilder/src/builder/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,12 +528,12 @@ where
}

// We adjust our flashblocks timings based on time the fcu block building signal arrived
let timestamp = config.attributes.timestamp();
let flashblock_scheduler = FlashblockScheduler::new(
&self.config.flashblocks_config,
self.config.block_time,
timestamp,
config.attributes.timestamp(),
);

info!(
target: "payload_builder",
id = %fb_payload.payload_id,
Expand Down
2 changes: 2 additions & 0 deletions crates/op-rbuilder/src/builder/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ impl FlashblocksServiceBuilder {
payload_builder,
true,
self.0.block_time_leeway,
self.0.block_time,
metrics.clone(),
);

let (payload_service, payload_builder_handle) =
Expand Down
2 changes: 2 additions & 0 deletions crates/op-rbuilder/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ pub struct OpRBuilderMetrics {
pub flashblocks_time_drift: Histogram,
/// Time offset we used for first flashblock
pub first_flashblock_time_offset: Histogram,
/// Delay in milliseconds between expected and actual FCU arrival time (positive = late, negative = early)
pub fcu_arrival_delay: Histogram,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whats the difference between this metric and flashblocks_time_drift? can you reuse that or rename it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That metric isn't being recorded at all right now :/

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then we can remove flashblocks_time_drift?

/// Number of requests sent to the eth_sendBundle endpoint
pub bundle_requests: Counter,
/// Number of valid bundles received at the eth_sendBundle endpoint
Expand Down
Loading