Skip to content

Commit

Permalink
Merge pull request #59 from gattaca-com/ltitanb/fix-tests
Browse files Browse the repository at this point in the history
chore: fix tests
  • Loading branch information
0w3n-d authored Dec 6, 2024
2 parents 540c27b + ee91446 commit 17fb43b
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 66 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 9 additions & 17 deletions crates/api/src/builder/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ use helix_common::{
use helix_database::DatabaseService;
use helix_datastore::{types::SaveBidAndUpdateTopBidResponse, Auctioneer};
use helix_housekeeper::{ChainUpdate, PayloadAttributesUpdate, SlotUpdate};
use helix_utils::{get_payload_attributes_key, has_reached_fork};
use helix_utils::{extract_request_id, get_payload_attributes_key, has_reached_fork};

use serde::Deserialize;

Expand Down Expand Up @@ -307,10 +307,8 @@ where
headers: HeaderMap,
req: Request<Body>,
) -> Result<StatusCode, BuilderApiError> {
let request_id = Uuid::parse_str(
headers.get("x-request-id").map(|v| v.to_str().unwrap_or_default()).unwrap_or_default(),
)
.unwrap();
let request_id = extract_request_id(&headers);

let mut trace = SubmissionTrace { receive: get_nanos_timestamp()?, ..Default::default() };
let (head_slot, next_duty) = api.curr_slot_info.read().await.clone();

Expand Down Expand Up @@ -575,10 +573,8 @@ where
headers: HeaderMap,
req: Request<Body>,
) -> Result<StatusCode, BuilderApiError> {
let request_id = Uuid::parse_str(
headers.get("x-request-id").map(|v| v.to_str().unwrap_or_default()).unwrap_or_default(),
)
.unwrap();
let request_id = extract_request_id(&headers);

let mut trace =
HeaderSubmissionTrace { receive: get_nanos_timestamp()?, ..Default::default() };
let (head_slot, next_duty) = api.curr_slot_info.read().await.clone();
Expand Down Expand Up @@ -824,10 +820,8 @@ where
headers: HeaderMap,
req: Request<Body>,
) -> Result<StatusCode, BuilderApiError> {
let request_id = Uuid::parse_str(
headers.get("x-request-id").map(|v| v.to_str().unwrap_or_default()).unwrap_or_default(),
)
.unwrap();
let request_id = extract_request_id(&headers);

let now = SystemTime::now();
let mut trace = SubmissionTrace { receive: get_nanos_from(now)?, ..Default::default() };
let (head_slot, next_duty) = api.curr_slot_info.read().await.clone();
Expand Down Expand Up @@ -1048,10 +1042,8 @@ where
headers: HeaderMap,
Json(mut signed_cancellation): Json<SignedCancellation>,
) -> Result<StatusCode, BuilderApiError> {
let request_id = Uuid::parse_str(
headers.get("x-request-id").map(|v| v.to_str().unwrap_or_default()).unwrap_or_default(),
)
.unwrap();
let request_id = extract_request_id(&headers);

let (head_slot, _next_duty) = api.curr_slot_info.read().await.clone();

let slot = signed_cancellation.message.slot;
Expand Down
21 changes: 8 additions & 13 deletions crates/api/src/proposer/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ use helix_common::{
use helix_database::DatabaseService;
use helix_datastore::{error::AuctioneerError, Auctioneer};
use helix_housekeeper::{ChainUpdate, SlotUpdate};
use helix_utils::signing::{verify_signed_builder_message, verify_signed_consensus_message};
use helix_utils::{
extract_request_id,
signing::{verify_signed_builder_message, verify_signed_consensus_message},
};

use crate::{
gossiper::{
Expand Down Expand Up @@ -167,10 +170,7 @@ where
return Err(ProposerApiError::EmptyRequest)
}

let request_id = Uuid::parse_str(
headers.get("x-request-id").map(|v| v.to_str().unwrap_or_default()).unwrap_or_default(),
)
.unwrap();
let request_id = extract_request_id(&headers);

let mut trace =
RegisterValidatorsTrace { receive: get_nanos_timestamp()?, ..Default::default() };
Expand Down Expand Up @@ -386,10 +386,7 @@ where
return Err(ProposerApiError::ServiceUnavailableError)
}

let request_id = Uuid::parse_str(
headers.get("x-request-id").map(|v| v.to_str().unwrap_or_default()).unwrap_or_default(),
)
.unwrap();
let request_id = extract_request_id(&headers);

let mut trace = GetHeaderTrace { receive: get_nanos_timestamp()?, ..Default::default() };

Expand Down Expand Up @@ -651,11 +648,9 @@ where
headers: HeaderMap,
req: Request<Body>,
) -> Result<impl IntoResponse, ProposerApiError> {
let request_id = extract_request_id(&headers);

let mut trace = GetPayloadTrace { receive: get_nanos_timestamp()?, ..Default::default() };
let request_id = Uuid::parse_str(
headers.get("x-request-id").map(|v| v.to_str().unwrap_or_default()).unwrap_or_default(),
)
.unwrap();

let user_agent =
headers.get("user-agent").and_then(|v| v.to_str().ok()).map(|v| v.to_string());
Expand Down
9 changes: 4 additions & 5 deletions crates/api/src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use helix_beacon_client::{beacon_client::BeaconClient, multi_beacon_client::Mult
use helix_common::{Route, RouterConfig};
use helix_database::postgres::postgres_db_service::PostgresDatabaseService;
use helix_datastore::redis::redis_cache::RedisCache;
use helix_utils::extract_request_id;
use hyper::HeaderMap;
use std::{collections::HashMap, sync::Arc, time::Duration};
use tower::{timeout::TimeoutLayer, BoxError, ServiceBuilder};
Expand Down Expand Up @@ -171,11 +172,9 @@ pub fn build_router(
router = router.layer(
ServiceBuilder::new()
.layer(HandleErrorLayer::new(|headers: HeaderMap, e: BoxError| async move {
let request_id = headers
.get("x-request-id")
.map(|v| v.to_str().unwrap_or_default())
.unwrap_or_default();
warn!(request_id = request_id, "Request timed out {:?}", e);
let request_id = extract_request_id(&headers);

warn!(%request_id, "Request timed out {:?}", e);
StatusCode::REQUEST_TIMEOUT
}))
.layer(TimeoutLayer::new(API_REQUEST_TIMEOUT)),
Expand Down
3 changes: 3 additions & 0 deletions crates/datastore/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,6 @@ redis.workspace = true
auto_impl.workspace = true
thiserror.workspace = true
tracing.workspace = true

[dev-dependencies]
serial_test.workspace = true
Loading

0 comments on commit 17fb43b

Please sign in to comment.