Skip to content

Commit

Permalink
Merge pull request #8 from gattaca-com/propagation_duration_config
Browse files Browse the repository at this point in the history
Propagation duration config
  • Loading branch information
gd-0 authored Jan 24, 2024
2 parents 778b64d + 7c98668 commit 767b24c
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 7 deletions.
12 changes: 6 additions & 6 deletions crates/api/src/proposer/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,7 @@ use helix_common::{
GetPayloadResponse,
ValidatorPreferences,
},
},
fork_info::{ForkInfo, Network},
try_execution_header_from_payload, BidRequest, GetHeaderTrace, GetPayloadTrace,
RegisterValidatorsTrace, signed_proposal::VersionedSignedProposal, versioned_payload::PayloadAndBlobs,
}, fork_info::{ForkInfo, Network}, signed_proposal::VersionedSignedProposal, try_execution_header_from_payload, versioned_payload::PayloadAndBlobs, BidRequest, GetHeaderTrace, GetPayloadTrace, RegisterValidatorsTrace
};
use helix_utils::signing::{verify_signed_builder_message, verify_signed_consensus_message};

Expand All @@ -59,7 +56,6 @@ use crate::proposer::{


const GET_PAYLOAD_REQUEST_CUTOFF_MS: i64 = 4000;
const TARGET_GET_PAYLOAD_PROPAGATION_DURATION_MS: u64 = 1000;

#[derive(Clone)]
pub struct ProposerApi<A, DB, M>
Expand All @@ -78,6 +74,8 @@ where
fork_info: Arc<ForkInfo>,
next_proposer_duty: Arc<RwLock<Option<BuilderGetValidatorsResponseEntry>>>,
validator_preferences: Arc<ValidatorPreferences>,

target_get_payload_propagation_duration_ms: u64,
}

impl<A, DB, M> ProposerApi<A, DB, M>
Expand All @@ -94,6 +92,7 @@ where
fork_info: Arc<ForkInfo>,
slot_update_subscription: Sender<Sender<ChainUpdate>>,
validator_preferences: Arc<ValidatorPreferences>,
target_get_payload_propagation_duration_ms: u64,
) -> Self {
let api = Self {
auctioneer,
Expand All @@ -104,6 +103,7 @@ where
fork_info,
next_proposer_duty: Arc::new(RwLock::new(None)),
validator_preferences,
target_get_payload_propagation_duration_ms,
};

// Spin up the housekeep task
Expand Down Expand Up @@ -615,7 +615,7 @@ where
// Conditionally pause the execution until we hit `TARGET_GET_PAYLOAD_PROPAGATION_DURATION_MS`
// to allow the block to propagate through the network.
let elapsed_since_propagate_start_ms = (get_nanos_timestamp()? - trace.beacon_client_broadcast) / 1_000_000;
let remaining_sleep_ms = TARGET_GET_PAYLOAD_PROPAGATION_DURATION_MS.saturating_sub(elapsed_since_propagate_start_ms);
let remaining_sleep_ms = self.target_get_payload_propagation_duration_ms.saturating_sub(elapsed_since_propagate_start_ms);
if remaining_sleep_ms > 0 && matches!(self.fork_info.network, Network::Mainnet) {
sleep(Duration::from_millis(remaining_sleep_ms)).await;
}
Expand Down
1 change: 1 addition & 0 deletions crates/api/src/proposer/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,7 @@ mod proposer_api_tests {
Arc::new(ForkInfo::for_holesky()),
slot_update_sender.clone(),
Arc::new(ValidatorPreferences::default()),
0
);

let mut x = gen_signed_vr();
Expand Down
1 change: 1 addition & 0 deletions crates/api/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ impl ApiService {
fork_info.clone(),
slot_update_sender,
Arc::new(config.validator_preferences.clone()),
config.target_get_payload_propagation_duration_ms,
));

let data_api = Arc::new(DataApiProd::new(db.clone()));
Expand Down
4 changes: 3 additions & 1 deletion crates/api/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ pub fn app() -> Router {
Arc::new(ForkInfo::for_mainnet()),
slot_update_sender,
Arc::new(ValidatorPreferences::default()),
0
));

let data_api =
Expand Down Expand Up @@ -153,7 +154,8 @@ pub fn proposer_api_app() -> (
Arc::new(MockMultiBeaconClient::default()),
Arc::new(ForkInfo::for_mainnet()),
slot_update_sender.clone(),
Arc::new(ValidatorPreferences::default())
Arc::new(ValidatorPreferences::default()),
0
)
);

Expand Down
6 changes: 6 additions & 0 deletions crates/common/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ pub struct RelayConfig {
pub run_housekeeper: bool,
pub validator_preferences: ValidatorPreferences,
pub router_config: RouterConfig,
#[serde(default = "default_duration")]
pub target_get_payload_propagation_duration_ms: u64,
}

impl RelayConfig {
Expand Down Expand Up @@ -170,6 +172,10 @@ pub enum Route {
ValidatorRegistration,
}

fn default_duration() -> u64 {
1000
}

#[cfg(test)]
#[test]
fn test_config() {
Expand Down

0 comments on commit 767b24c

Please sign in to comment.