Skip to content

Commit de171b6

Browse files
authored
fallback to v1 api on 404 relay response (#389)
1 parent 8e88e1f commit de171b6

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

crates/common/src/pbs/error.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ impl PbsError {
4747
_ => false,
4848
}
4949
}
50+
51+
pub fn is_not_found(&self) -> bool {
52+
matches!(&self, PbsError::RelayResponse { code: 404, .. })
53+
}
5054
}
5155

5256
#[derive(Debug, Error, PartialEq, Eq)]

crates/pbs/src/mev_boost/submit_block.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ async fn submit_block_with_timeout(
8888
api_version: &BuilderApiVersion,
8989
fork_name: ForkName,
9090
) -> Result<Option<SubmitBlindedBlockResponse>, PbsError> {
91-
let url = relay.submit_block_url(*api_version)?;
91+
let mut url = relay.submit_block_url(*api_version)?;
9292
let mut remaining_timeout_ms = timeout_ms;
9393
let mut retry = 0;
9494
let mut backoff = Duration::from_millis(250);
@@ -121,6 +121,14 @@ async fn submit_block_with_timeout(
121121
}
122122
}
123123

124+
Err(err) if err.is_not_found() && matches!(api_version, BuilderApiVersion::V2) => {
125+
warn!(
126+
relay_id = relay.id.as_ref(),
127+
"relay does not support v2 endpoint, retrying with v1"
128+
);
129+
url = relay.submit_block_url(BuilderApiVersion::V1)?;
130+
}
131+
124132
Err(err) => return Err(err),
125133
};
126134

@@ -184,8 +192,16 @@ async fn send_submit_block(
184192
warn!(relay_id = relay.id.as_ref(), retry, %err, "failed to get payload (this might be ok if other relays have it)");
185193
return Err(err);
186194
};
195+
187196
if api_version != &BuilderApiVersion::V1 {
188197
// v2 response is going to be empty, so just break here
198+
debug!(
199+
relay_id = relay.id.as_ref(),
200+
retry,
201+
latency = ?request_latency,
202+
"successful request"
203+
);
204+
189205
return Ok(None);
190206
}
191207

0 commit comments

Comments
 (0)