Skip to content

Commit

Permalink
misc: address review
Browse files Browse the repository at this point in the history
  • Loading branch information
namn-grg committed Sep 29, 2024
1 parent e67a8f9 commit c06381a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
17 changes: 11 additions & 6 deletions crates/api/src/builder/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ use helix_database::{error::DatabaseError, DatabaseService};
use helix_datastore::{types::SaveBidAndUpdateTopBidResponse, Auctioneer};
use helix_housekeeper::{ChainUpdate, PayloadAttributesUpdate, SlotUpdate};
use helix_utils::{get_payload_attributes_key, has_reached_fork, try_decode_into};
use serde::Deserialize;
use serde::{de, Deserialize};

use crate::{builder::{
error::{self, BuilderApiError}, traits::BlockSimulator, BlockSimRequest, DbInfo, OptimisticVersion,
Expand Down Expand Up @@ -167,7 +167,7 @@ where
let slot = slot.slot;
let head_slot = api.curr_slot_info.read().await.0;

if slot > head_slot || slot < head_slot - 32 {
if slot < head_slot || slot > head_slot + 32 {
return Err(BuilderApiError::IncorrectSlot(slot));
}

Expand All @@ -181,6 +181,7 @@ where
Ok(Json(constraints))
}
Ok(None) => {
debug!("No constraints found for slot");
Ok(Json(vec![])) // Return an empty vector if no delegations found
}
Err(err) => {
Expand Down Expand Up @@ -228,8 +229,12 @@ where
Query(slot): Query<SlotQuery>,
) -> Result<impl IntoResponse, BuilderApiError> {
let slot = slot.slot;
let duty_bytes = api.proposer_duties_response.read().await.clone();
let proposer_duties: Vec<BuilderGetValidatorsResponse> = serde_json::from_slice(&duty_bytes.unwrap()).unwrap();
let Some(duty_bytes) = &*api.proposer_duties_response.read().await else {
return Err(BuilderApiError::ProposerDutyNotFound);
};
let Ok(proposer_duties) = serde_json::from_slice::<Vec<BuilderGetValidatorsResponse>>(duty_bytes) else {
return Err(BuilderApiError::DeserializeError);
};

let duty = proposer_duties
.iter()
Expand All @@ -244,7 +249,7 @@ where
Err(err) => {
match err {
DatabaseError::ValidatorDelegationNotFound => {
warn!("No delegations found for validator");
debug!("No delegations found for validator");
Ok(Json(vec![])) // Return an empty vector if no delegations found
}
_ => {
Expand Down Expand Up @@ -1482,7 +1487,7 @@ where
let root = root.to_vec().as_slice().try_into().expect("failed to convert to hash32");

let proofs = payload.proofs().expect("proofs not found");
let constraints: Vec<ConstraintsWithProofData> = constraints.iter().map(|c| ConstraintsWithProofData {
let constraints: Vec<_> = constraints.iter().map(|c| ConstraintsWithProofData {
message: c.signed_constraints.message.clone(),
proof_data: c.proof_data.clone(),
}).collect();
Expand Down
10 changes: 8 additions & 2 deletions crates/api/src/builder/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ pub enum BuilderApiError {
#[error("ssz serialize error")]
SszSerializeError,

#[error("failed to deserialize")]
DeserializeError,

#[error("failed to decode header-submission")]
FailedToDecodeHeaderSubmission,

Expand Down Expand Up @@ -159,11 +162,14 @@ impl IntoResponse for BuilderApiError {
BuilderApiError::IOError(err) => {
(StatusCode::BAD_REQUEST, format!("IO error: {err}")).into_response()
},
BuilderApiError::SszDeserializeError(err) => {
(StatusCode::BAD_REQUEST, format!("SSZ deserialize error: {err}")).into_response()
},
BuilderApiError::SszSerializeError => {
(StatusCode::BAD_REQUEST, format!("SSZ serialize error")).into_response()
},
BuilderApiError::SszDeserializeError(err) => {
(StatusCode::BAD_REQUEST, format!("SSZ deserialize error: {err}")).into_response()
BuilderApiError::DeserializeError => {
(StatusCode::BAD_REQUEST, "Failed to deserialize").into_response()
},
BuilderApiError::FailedToDecodeHeaderSubmission => {
(StatusCode::BAD_REQUEST, "Failed to decode header submission").into_response()
Expand Down
4 changes: 1 addition & 3 deletions crates/api/src/constraints/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,13 @@ where
// Once we support sending messages signed with correct validator pubkey on the sidecar,
// return error if invalid

let message = constraint.message.clone();

// Send to the constraints channel
api.constraints_handle.send_constraints(constraint.clone());

// Finally add the constraints to the redis cache
if let Err(err) = api.save_constraints_to_auctioneer(
&mut trace,
message.slot,
constraint.message.slot,
constraint,
&request_id
).await {
Expand Down

0 comments on commit c06381a

Please sign in to comment.