Skip to content

Commit

Permalink
fix tests and handle 204
Browse files Browse the repository at this point in the history
  • Loading branch information
realbigsean committed Jul 1, 2022
1 parent 14005f4 commit 882b8fa
Show file tree
Hide file tree
Showing 7 changed files with 172 additions and 141 deletions.
11 changes: 8 additions & 3 deletions beacon_node/builder_client/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use eth2::ok_or_error;
use eth2::types::builder_bid::SignedBuilderBid;
use eth2::types::{
BlindedPayload, EthSpec, ExecPayload, ExecutionBlockHash, ExecutionPayload,
ForkVersionedResponse, PublicKeyBytes, SignedBeaconBlock, SignedValidatorRegistrationData,
Slot,
};
pub use eth2::Error;
use eth2::{ok_or_error, StatusCode};
use reqwest::{IntoUrl, Response};
use sensitive_url::SensitiveUrl;
use serde::de::DeserializeOwned;
Expand Down Expand Up @@ -160,7 +160,7 @@ impl BuilderHttpClient {
slot: Slot,
parent_hash: ExecutionBlockHash,
pubkey: &PublicKeyBytes,
) -> Result<ForkVersionedResponse<SignedBuilderBid<E, Payload>>, Error> {
) -> Result<Option<ForkVersionedResponse<SignedBuilderBid<E, Payload>>>, Error> {
let mut path = self.server.full.clone();

path.path_segments_mut()
Expand All @@ -173,7 +173,12 @@ impl BuilderHttpClient {
.push(format!("{parent_hash:?}").as_str())
.push(pubkey.as_hex_string().as_str());

self.get_with_timeout(path, self.timeouts.get_header).await
let resp = self.get_with_timeout(path, self.timeouts.get_header).await;
if matches!(resp, Err(Error::StatusCode(StatusCode::NO_CONTENT))) {
return Ok(None);
} else {
resp.map(Some)
}
}

/// `GET /eth/v1/builder/status`
Expand Down
16 changes: 11 additions & 5 deletions beacon_node/execution_layer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ pub enum Error {
NoPayloadBuilder,
ApiError(ApiError),
Builder(builder_client::Error),
NoHeaderFromBuilder,
EngineErrors(Vec<EngineError>),
NotSynced,
ShuttingDown,
Expand Down Expand Up @@ -608,10 +609,14 @@ impl<T: EthSpec> ExecutionLayer<T> {

match (relay_result, local_result) {
(Err(e), Ok(local)) => {
warn!(self.log(),"Unable to retrieve a payload from a relay, falling back to the local execution client: {e:?}");
warn!(self.log(),"Unable to retrieve a payload from a connected builder, falling back to the local execution client: {e:?}");
Ok(local)
}
(Ok(relay), Ok(local)) => {
(Ok(None), Ok(local)) => {
warn!(self.log(), "No payload provided by connected builder. Attempting to propose through local execution engine");
Ok(local)
}
(Ok(Some(relay)), Ok(local)) => {
//TODO(sean) check fork?
//TODO(sean) verify value vs local payload?
//TODO(sean) verify bid signature?
Expand All @@ -636,11 +641,12 @@ impl<T: EthSpec> ExecutionLayer<T> {
Ok(header)
}
}
(relay_reult, Err(local_error)) => {
(relay_result, Err(local_error)) => {
warn!(self.log(), "Failure from local execution engine. Attempting to propose through connected builder"; "error" => ?local_error);
relay_reult
relay_result
.map_err(Error::Builder)?
.ok_or(Error::NoHeaderFromBuilder)
.map(|d| d.data.message.header)
.map_err(Error::Builder)
}
}
} else {
Expand Down
Loading

0 comments on commit 882b8fa

Please sign in to comment.