From f13dd04f422703803a931d50d5348fbc54f924ff Mon Sep 17 00:00:00 2001 From: MaboroshiChan Date: Mon, 5 Sep 2022 04:50:46 +0000 Subject: [PATCH] Add timeout for --checkpoint-sync-url (#3521) ## Issue Addressed [Have --checkpoint-sync-url timeout](https://github.com/sigp/lighthouse/issues/3478) ## Proposed Changes I added a parameter for `get_bytes_opt_accept_header` which accept a timeout duration, and modified the body of `get_beacon_blocks_ssz` and `get_debug_beacon_states_ssz` to pass corresponding timeout durations. --- common/eth2/src/lib.rs | 11 ++++++++--- validator_client/src/lib.rs | 6 ++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/common/eth2/src/lib.rs b/common/eth2/src/lib.rs index 6317523fe..f096aca97 100644 --- a/common/eth2/src/lib.rs +++ b/common/eth2/src/lib.rs @@ -112,6 +112,8 @@ pub struct Timeouts { pub proposer_duties: Duration, pub sync_committee_contribution: Duration, pub sync_duties: Duration, + pub get_beacon_blocks_ssz: Duration, + pub get_debug_beacon_states: Duration, } impl Timeouts { @@ -124,6 +126,8 @@ impl Timeouts { proposer_duties: timeout, sync_committee_contribution: timeout, sync_duties: timeout, + get_beacon_blocks_ssz: timeout, + get_debug_beacon_states: timeout, } } } @@ -239,9 +243,10 @@ impl BeaconNodeHttpClient { &self, url: U, accept_header: Accept, + timeout: Duration, ) -> Result>, Error> { let opt_response = self - .get_response(url, |b| b.accept(accept_header)) + .get_response(url, |b| b.accept(accept_header).timeout(timeout)) .await .optional()?; match opt_response { @@ -701,7 +706,7 @@ impl BeaconNodeHttpClient { ) -> Result>, Error> { let path = self.get_beacon_blocks_path(block_id)?; - self.get_bytes_opt_accept_header(path, Accept::Ssz) + self.get_bytes_opt_accept_header(path, Accept::Ssz, self.timeouts.get_beacon_blocks_ssz) .await? .map(|bytes| SignedBeaconBlock::from_ssz_bytes(&bytes, spec).map_err(Error::InvalidSsz)) .transpose() @@ -1167,7 +1172,7 @@ impl BeaconNodeHttpClient { ) -> Result>, Error> { let path = self.get_debug_beacon_states_path(state_id)?; - self.get_bytes_opt_accept_header(path, Accept::Ssz) + self.get_bytes_opt_accept_header(path, Accept::Ssz, self.timeouts.get_debug_beacon_states) .await? .map(|bytes| BeaconState::from_ssz_bytes(&bytes, spec).map_err(Error::InvalidSsz)) .transpose() diff --git a/validator_client/src/lib.rs b/validator_client/src/lib.rs index ac6969f4c..c05507576 100644 --- a/validator_client/src/lib.rs +++ b/validator_client/src/lib.rs @@ -75,6 +75,8 @@ const HTTP_PROPOSAL_TIMEOUT_QUOTIENT: u32 = 2; const HTTP_PROPOSER_DUTIES_TIMEOUT_QUOTIENT: u32 = 4; const HTTP_SYNC_COMMITTEE_CONTRIBUTION_TIMEOUT_QUOTIENT: u32 = 4; const HTTP_SYNC_DUTIES_TIMEOUT_QUOTIENT: u32 = 4; +const HTTP_GET_BEACON_BLOCK_SSZ_TIMEOUT_QUOTIENT: u32 = 4; +const HTTP_GET_DEBUG_BEACON_STATE_QUOTIENT: u32 = 4; const DOPPELGANGER_SERVICE_NAME: &str = "doppelganger"; @@ -285,6 +287,10 @@ impl ProductionValidatorClient { sync_committee_contribution: slot_duration / HTTP_SYNC_COMMITTEE_CONTRIBUTION_TIMEOUT_QUOTIENT, sync_duties: slot_duration / HTTP_SYNC_DUTIES_TIMEOUT_QUOTIENT, + get_beacon_blocks_ssz: slot_duration + / HTTP_GET_BEACON_BLOCK_SSZ_TIMEOUT_QUOTIENT, + get_debug_beacon_states: slot_duration + / HTTP_GET_DEBUG_BEACON_STATE_QUOTIENT, } } else { Timeouts::set_all(slot_duration)