Skip to content

retry FCU if it returns SYNCING #387

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
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
2 changes: 2 additions & 0 deletions crates/rollup-boost/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ impl RollupBoostArgs {
l2_auth_jwt,
l2_client_args.l2_timeout,
PayloadSource::L2,
l2_client_args.retry_config(),
)?;

let builder_args = self.builder;
Expand All @@ -134,6 +135,7 @@ impl RollupBoostArgs {
builder_auth_jwt,
builder_args.builder_timeout,
PayloadSource::Builder,
builder_args.retry_config(),
)?;

let (probe_layer, probes) = ProbeLayer::new();
Expand Down
73 changes: 65 additions & 8 deletions crates/rollup-boost/src/client/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::version::{CARGO_PKG_VERSION, VERGEN_GIT_SHA};
use alloy_primitives::{B256, Bytes};
use alloy_rpc_types_engine::{
ExecutionPayloadV3, ForkchoiceState, ForkchoiceUpdated, JwtError, JwtSecret, PayloadId,
PayloadStatus,
PayloadStatus, PayloadStatusEnum,
};
use alloy_rpc_types_eth::{Block, BlockNumberOrTag};
use clap::{Parser, arg};
Expand Down Expand Up @@ -109,6 +109,17 @@ pub struct RpcClient {
auth_rpc: Uri,
/// The source of the payload
payload_source: PayloadSource,
/// Retry configuration for forkChoiceUpdated
fcu_retry_config: Option<RetryConfig>,
}

/// Configuration for retry strategy
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct RetryConfig {
/// Maximum number of retry attempts
pub max_attempts: u32,
/// Delay between retries in milliseconds
pub delay_ms: u64,
}

impl RpcClient {
Expand All @@ -118,6 +129,7 @@ impl RpcClient {
auth_rpc_jwt_secret: JwtSecret,
timeout: u64,
payload_source: PayloadSource,
fcu_retry_config: Option<RetryConfig>,
) -> Result<Self, RpcClientError> {
let version = format!("{CARGO_PKG_VERSION}-{VERGEN_GIT_SHA}");
let mut headers = HeaderMap::new();
Expand All @@ -134,6 +146,7 @@ impl RpcClient {
auth_client,
auth_rpc,
payload_source,
fcu_retry_config,
})
}

Expand All @@ -155,11 +168,35 @@ impl RpcClient {
payload_attributes: Option<OpPayloadAttributes>,
) -> ClientResult<ForkchoiceUpdated> {
info!("Sending fork_choice_updated_v3 to {}", self.payload_source);
let res = self
.auth_client
.fork_choice_updated_v3(fork_choice_state, payload_attributes.clone())
.await
.set_code()?;

// Retry FCU if the response is SYNCING
let res = if let Some(retry_config) = &self.fcu_retry_config {
// Initialize a dummy result because we can't break out of a
// for-loop with a value
let mut res =
ForkchoiceUpdated::new(PayloadStatus::from_status(PayloadStatusEnum::Syncing));
for _ in 0..retry_config.max_attempts {
res = self
.auth_client
.fork_choice_updated_v3(fork_choice_state, payload_attributes.clone())
.await
.set_code()?;

if !res.is_syncing() {
break;
}

tokio::time::sleep(Duration::from_millis(retry_config.delay_ms)).await;
// Just return the response even if it's SYNCING for now, we're
// just trying to reduce the likelihood of it with these retries
}
res
} else {
self.auth_client
.fork_choice_updated_v3(fork_choice_state, payload_attributes.clone())
.await
.set_code()?
};

if let Some(payload_id) = res.payload_id {
tracing::Span::current().record("payload_id", payload_id.to_string());
Expand Down Expand Up @@ -398,6 +435,26 @@ macro_rules! define_rpc_args {
/// Timeout for http calls in milliseconds
#[arg(long, env, default_value_t = 1000)]
pub [<$prefix _timeout>]: u64,

/// Optional retry max attempts for forkChoiceUpdate
#[arg(long, env)]
[<$prefix _fcu_retry_max_attempts>]: Option<u32>,

/// Optional retry delay ms for forkChoiceUpdate
#[arg(long, env)]
[<$prefix _fcu_retry_delay_ms>]: Option<u64>,
}

impl $name {
pub fn retry_config(&self) -> Option<RetryConfig> {
match (self.[<$prefix _fcu_retry_max_attempts>], self.[<$prefix _fcu_retry_delay_ms>]) {
(Some(max_attempts), Some(delay_ms)) => Some(RetryConfig {
max_attempts,
delay_ms,
}),
_ => None,
}
}
}
}
)*
Expand Down Expand Up @@ -456,8 +513,8 @@ pub mod tests {
async fn valid_jwt() {
let port = get_available_port();
let secret = JwtSecret::from_hex(SECRET).unwrap();
let auth_rpc = Uri::from_str(&format!("http://{}:{}", AUTH_ADDR, port)).unwrap();
let client = RpcClient::new(auth_rpc, secret, 1000, PayloadSource::L2).unwrap();
let auth_rpc = Uri::from_str(&format!("http://{AUTH_ADDR}:{port}")).unwrap();
let client = RpcClient::new(auth_rpc, secret, 1000, PayloadSource::L2, None).unwrap();
let response = send_request(client.auth_client, port).await;
assert!(response.is_ok());
assert_eq!(response.unwrap(), "You are the dark lord");
Expand Down
2 changes: 2 additions & 0 deletions crates/rollup-boost/src/flashblocks/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ mod tests {
jwt_secret,
2000,
PayloadSource::Builder,
None,
)?;

let service =
Expand Down Expand Up @@ -439,6 +440,7 @@ mod tests {
jwt_secret,
2000,
PayloadSource::Builder,
None,
)?;

let service =
Expand Down
5 changes: 5 additions & 0 deletions crates/rollup-boost/src/health.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ mod tests {
JwtSecret::random(),
100,
PayloadSource::Builder,
None,
)?);

let health_handle = HealthHandle {
Expand Down Expand Up @@ -304,6 +305,7 @@ mod tests {
JwtSecret::random(),
100,
PayloadSource::Builder,
None,
)?);

let health_handle = HealthHandle {
Expand Down Expand Up @@ -336,6 +338,7 @@ mod tests {
JwtSecret::random(),
100,
PayloadSource::Builder,
None,
)?);

let health_handle = HealthHandle {
Expand Down Expand Up @@ -368,6 +371,7 @@ mod tests {
JwtSecret::random(),
100,
PayloadSource::Builder,
None,
)?);

let health_handle = HealthHandle {
Expand All @@ -393,6 +397,7 @@ mod tests {
JwtSecret::random(),
100,
PayloadSource::Builder,
None,
)?);

let health_handle = HealthHandle {
Expand Down
11 changes: 9 additions & 2 deletions crates/rollup-boost/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -652,8 +652,14 @@ pub mod tests {
let (builder_server, builder_server_addr) = spawn_server(builder_mock.clone()).await;

let l2_auth_rpc = Uri::from_str(&format!("http://{l2_server_addr}")).unwrap();
let l2_client =
RpcClient::new(l2_auth_rpc.clone(), jwt_secret, 2000, PayloadSource::L2).unwrap();
let l2_client = RpcClient::new(
l2_auth_rpc.clone(),
jwt_secret,
2000,
PayloadSource::L2,
None,
)
.unwrap();

let builder_auth_rpc = Uri::from_str(&format!("http://{builder_server_addr}")).unwrap();
let builder_client = Arc::new(
Expand All @@ -662,6 +668,7 @@ pub mod tests {
jwt_secret,
2000,
PayloadSource::Builder,
None,
)
.unwrap(),
);
Expand Down
Loading