Allow /validator apis to work pre-genesis (#7729)

N/A


  Lighthouse BN http endpoint would return a server error pre-genesis on the `validator/duties/attester` and `validator/prepare_beacon_proposer` because `slot_clock.now()` would return a `None` pre-genesis.

The prysm VC depends on the endpoints pre-genesis and was having issues interoping with the lighthouse bn because of this reason.

The proposer duties endpoint explicitly handles the pre-genesis case here
538067f1ff/beacon_node/http_api/src/proposer_duties.rs (L23-L28)

I see no reason why we can't make the other endpoints more flexible to work pre-genesis. This PR handles the pre-genesis case on the attester and prepare_beacon_proposer endpoints as well.

Thanks for raising @james-prysm.
This commit is contained in:
Pawan Dhananjay
2025-07-13 23:42:55 -07:00
committed by GitHub
parent 6409a32274
commit 309c301363
2 changed files with 22 additions and 7 deletions

View File

@@ -16,7 +16,12 @@ pub fn attester_duties<T: BeaconChainTypes>(
request_indices: &[u64],
chain: &BeaconChain<T>,
) -> Result<ApiDuties, warp::reject::Rejection> {
let current_epoch = chain.epoch().map_err(warp_utils::reject::unhandled_error)?;
let current_epoch = chain
.slot_clock
.now_or_genesis()
.map(|slot| slot.epoch(T::EthSpec::slots_per_epoch()))
.ok_or(BeaconChainError::UnableToReadSlot)
.map_err(warp_utils::reject::unhandled_error)?;
// Determine what the current epoch would be if we fast-forward our system clock by
// `MAXIMUM_GOSSIP_CLOCK_DISPARITY`.
@@ -24,11 +29,17 @@ pub fn attester_duties<T: BeaconChainTypes>(
// Most of the time, `tolerant_current_epoch` will be equal to `current_epoch`. However, during
// the first `MAXIMUM_GOSSIP_CLOCK_DISPARITY` duration of the epoch `tolerant_current_epoch`
// will equal `current_epoch + 1`
let tolerant_current_epoch = chain
.slot_clock
.now_with_future_tolerance(chain.spec.maximum_gossip_clock_disparity())
.ok_or_else(|| warp_utils::reject::custom_server_error("unable to read slot clock".into()))?
.epoch(T::EthSpec::slots_per_epoch());
let tolerant_current_epoch = if chain.slot_clock.is_prior_to_genesis().unwrap_or(true) {
current_epoch
} else {
chain
.slot_clock
.now_with_future_tolerance(chain.spec.maximum_gossip_clock_disparity())
.ok_or_else(|| {
warp_utils::reject::custom_server_error("unable to read slot clock".into())
})?
.epoch(T::EthSpec::slots_per_epoch())
};
if request_epoch == current_epoch
|| request_epoch == current_epoch + 1

View File

@@ -3790,7 +3790,11 @@ pub fn serve<T: BeaconChainTypes>(
.ok_or(BeaconChainError::ExecutionLayerMissing)
.map_err(warp_utils::reject::unhandled_error)?;
let current_slot = chain.slot().map_err(warp_utils::reject::unhandled_error)?;
let current_slot = chain
.slot_clock
.now_or_genesis()
.ok_or(BeaconChainError::UnableToReadSlot)
.map_err(warp_utils::reject::unhandled_error)?;
let current_epoch = current_slot.epoch(T::EthSpec::slots_per_epoch());
debug!(