Skip to content

feat: simplify ExecutionMode #198

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
May 13, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
12 changes: 0 additions & 12 deletions src/debug_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,17 +152,5 @@ mod tests {
// Verify again with get_execution_mode
let status = client.get_execution_mode().await.unwrap();
assert_eq!(status.execution_mode, ExecutionMode::Enabled);

// Test setting fallback execution mode
let result = client
.set_execution_mode(ExecutionMode::Fallback)
.await
.unwrap();

assert_eq!(result.execution_mode, ExecutionMode::Fallback);

// Verify again with get_execution_mode
let status = client.get_execution_mode().await.unwrap();
assert_eq!(status.execution_mode, ExecutionMode::Fallback);
}
}
103 changes: 61 additions & 42 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,23 +140,16 @@ pub enum ExecutionMode {
DryRun,
// Not sending any requests
Disabled,
// Defaulting to op-geth payloads
Fallback,
}

impl ExecutionMode {
fn is_get_payload_enabled(&self) -> bool {
// get payload is only enabled in 'enabled' mode
matches!(self, ExecutionMode::Enabled)
fn is_dry_run(&self) -> bool {
matches!(self, ExecutionMode::DryRun)
}

fn is_disabled(&self) -> bool {
matches!(self, ExecutionMode::Disabled)
}

fn is_fallback_enabled(&self) -> bool {
matches!(self, ExecutionMode::Fallback)
}
}

pub struct RollupBoostServer {
Expand Down Expand Up @@ -612,26 +605,14 @@ impl RollupBoostServer {
) -> RpcResult<OpExecutionPayloadEnvelope> {
let l2_client_future = self.l2_client.get_payload(payload_id, version);
let builder_client_future = Box::pin(async move {
let execution_mode = self.execution_mode();
if !execution_mode.is_get_payload_enabled() {
info!(message = "dry run mode is enabled, skipping get payload builder call");

// We are in dry run mode, so we do not want to call the builder.
return Err(ErrorObject::owned(
INVALID_REQUEST_CODE,
"Dry run mode is enabled",
None::<String>,
));
}

if let Some(cause) = self.payload_trace_context.trace_id(&payload_id) {
tracing::Span::current().follows_from(cause);
}

if !self.payload_trace_context.has_builder_payload(&payload_id) {
// block builder won't build a block without attributes
info!(message = "builder has no payload, skipping get_payload call to builder");
return Ok(None);
return RpcResult::Ok(None);
}

let builder = self.builder_client.clone();
Expand All @@ -648,30 +629,68 @@ impl RollupBoostServer {
Ok(Some(payload))
});

let (l2_payload, builder_payload) = tokio::join!(l2_client_future, builder_client_future);
let (payload, context) = match (builder_payload, l2_payload) {
(Ok(Some(builder)), Ok(l2_payload)) => {
// builder successfully returned a payload
self.probes.set_health(Health::Healthy);
if self.execution_mode().is_fallback_enabled() {
// Default to op-geth's payload
Ok((l2_payload, PayloadSource::L2))
} else {
let execution_mode = self.execution_mode();

// if mode is `dry_run` dont want to wait for the builder payload
let (payload, context) = if execution_mode.is_dry_run() {
let result = match l2_client_future.await {
Ok(payload) => {
self.probes.set_health(Health::Healthy);
Ok((payload, PayloadSource::L2))
}
Err(e) => {
self.probes.set_health(Health::ServiceUnavailable);
Err(e)
}
};
result
} else {
let (l2_payload, builder_payload) =
tokio::join!(l2_client_future, builder_client_future);
let result = match (builder_payload, l2_payload) {
(Ok(Some(builder)), Ok(_)) => {
// builder successfully returned a payload
self.probes.set_health(Health::Healthy);
Ok((builder, PayloadSource::Builder))
}
}
(_, Ok(l2)) => {
// builder failed to return a payload
self.probes.set_health(Health::PartialContent);
Ok((l2, PayloadSource::L2))
}
(_, Err(e)) => {
// builder and l2 failed to return a payload
self.probes.set_health(Health::ServiceUnavailable);
Err(e)
}
(_, Ok(l2)) => {
// builder failed to return a payload
self.probes.set_health(Health::PartialContent);
Ok((l2, PayloadSource::L2))
}
(_, Err(e)) => {
// builder and l2 failed to return a payload
self.probes.set_health(Health::ServiceUnavailable);
Err(e)
}
};
result
}?;

// let (l2_payload, builder_payload) = tokio::join!(l2_client_future, builder_client_future);
// let (payload, context) = match (builder_payload, l2_payload) {
// (Ok(Some(builder)), Ok(l2_payload)) => {
// // builder successfully returned a payload
// self.probes.set_health(Health::Healthy);
// if self.execution_mode().is_dry_run() {
// // Default to op-geth's payload
// Ok((l2_payload, PayloadSource::L2))
// } else {
// Ok((builder, PayloadSource::Builder))
// }
// }
// (_, Ok(l2)) => {
// // builder failed to return a payload
// self.probes.set_health(Health::PartialContent);
// Ok((l2, PayloadSource::L2))
// }
// (_, Err(e)) => {
// // builder and l2 failed to return a payload
// self.probes.set_health(Health::ServiceUnavailable);
// Err(e)
// }
// }?;

tracing::Span::current().record("payload_source", context.to_string());
// To maintain backwards compatibility with old metrics, we need to record blocks built
// This is temporary until we migrate to the new metrics
Expand Down
Loading