diff --git a/crates/common/src/commit/client.rs b/crates/common/src/commit/client.rs index 62ce146e..9b6f7c27 100644 --- a/crates/common/src/commit/client.rs +++ b/crates/common/src/commit/client.rs @@ -9,6 +9,7 @@ use super::{ error::SignerClientError, request::SignRequest, }; +use crate::DEFAULT_REQUEST_TIMEOUT; #[derive(Debug, Clone, Deserialize, Serialize)] pub struct GetPubkeysResponse { @@ -34,14 +35,17 @@ impl SignerClient { HeaderValue::from_str(&format!("Bearer {}", jwt)).expect("invalid jwt"); auth_value.set_sensitive(true); headers.insert(AUTHORIZATION, auth_value); - - let client = reqwest::Client::builder().default_headers(headers).build().unwrap(); + let client = reqwest::Client::builder() + .timeout(DEFAULT_REQUEST_TIMEOUT) + .default_headers(headers) + .build() + .unwrap(); Self { url: url.into(), client } } - /// Request a list of validator pubkeys for which signatures can be requested. - /// TODO: add more docs on how proxy keys work + /// Request a list of validator pubkeys for which signatures can be + /// requested. TODO: add more docs on how proxy keys work pub async fn get_pubkeys(&self) -> Result { let url = format!("{}{}", self.url, GET_PUBKEYS_PATH); let res = self.client.get(&url).send().await?; diff --git a/crates/common/src/lib.rs b/crates/common/src/lib.rs index 8d47c1a4..b13075c1 100644 --- a/crates/common/src/lib.rs +++ b/crates/common/src/lib.rs @@ -1,3 +1,5 @@ +use std::time::Duration; + pub mod commit; pub mod config; pub mod constants; @@ -7,3 +9,6 @@ pub mod signature; pub mod signer; pub mod types; pub mod utils; + + +pub const DEFAULT_REQUEST_TIMEOUT: Duration = Duration::from_secs(12); \ No newline at end of file diff --git a/crates/pbs/src/state.rs b/crates/pbs/src/state.rs index d7a11436..c270ace4 100644 --- a/crates/pbs/src/state.rs +++ b/crates/pbs/src/state.rs @@ -4,12 +4,12 @@ use std::{ sync::{Arc, Mutex}, }; -use alloy::primitives::B256; -use alloy::rpc::types::beacon::BlsPublicKey; +use alloy::{primitives::B256, rpc::types::beacon::BlsPublicKey}; use axum::http::{HeaderMap, HeaderName, HeaderValue}; use cb_common::{ config::{PbsConfig, PbsModuleConfig}, pbs::{RelayEntry, HEADER_VERSION_KEY, HEAVER_VERSION_VALUE}, + DEFAULT_REQUEST_TIMEOUT, }; use dashmap::DashMap; use tokio::sync::broadcast; @@ -62,6 +62,7 @@ where let relay_client = reqwest::Client::builder() .default_headers(headers) + .timeout(DEFAULT_REQUEST_TIMEOUT) .build() .expect("failed to build relay client"); @@ -115,9 +116,10 @@ where self.relay_client.clone() } - /// Add some bids to the cache, the bids are all assumed to be for the provided slot - /// Returns the bid with the max value - /// TODO: this doesnt handle cancellations if we call multiple times get_header + /// Add some bids to the cache, the bids are all assumed to be for the + /// provided slot Returns the bid with the max value + /// TODO: this doesnt handle cancellations if we call multiple times + /// get_header pub fn add_bids(&self, slot: u64, bids: Vec) -> Option { let mut slot_entry = self.bid_cache.entry(slot).or_default(); slot_entry.extend(bids);