mirror of
https://github.com/sigp/lighthouse.git
synced 2026-07-04 21:34:36 +00:00
Make proposer duties work pre-genesis (#4789)
* Make proposer duties work pre-genesis
This commit is contained in:
@@ -22,7 +22,10 @@ pub fn proposer_duties<T: BeaconChainTypes>(
|
|||||||
log: &Logger,
|
log: &Logger,
|
||||||
) -> Result<ApiDuties, warp::reject::Rejection> {
|
) -> Result<ApiDuties, warp::reject::Rejection> {
|
||||||
let current_epoch = chain
|
let current_epoch = chain
|
||||||
.epoch()
|
.slot_clock
|
||||||
|
.now_or_genesis()
|
||||||
|
.map(|slot| slot.epoch(T::EthSpec::slots_per_epoch()))
|
||||||
|
.ok_or(BeaconChainError::UnableToReadSlot)
|
||||||
.map_err(warp_utils::reject::beacon_chain_error)?;
|
.map_err(warp_utils::reject::beacon_chain_error)?;
|
||||||
|
|
||||||
// Determine what the current epoch would be if we fast-forward our system clock by
|
// Determine what the current epoch would be if we fast-forward our system clock by
|
||||||
@@ -31,11 +34,17 @@ pub fn proposer_duties<T: BeaconChainTypes>(
|
|||||||
// Most of the time, `tolerant_current_epoch` will be equal to `current_epoch`. However, during
|
// 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`
|
// the first `MAXIMUM_GOSSIP_CLOCK_DISPARITY` duration of the epoch `tolerant_current_epoch`
|
||||||
// will equal `current_epoch + 1`
|
// will equal `current_epoch + 1`
|
||||||
let tolerant_current_epoch = chain
|
let tolerant_current_epoch = if chain.slot_clock.is_prior_to_genesis().unwrap_or(true) {
|
||||||
.slot_clock
|
current_epoch
|
||||||
.now_with_future_tolerance(chain.spec.maximum_gossip_clock_disparity())
|
} else {
|
||||||
.ok_or_else(|| warp_utils::reject::custom_server_error("unable to read slot clock".into()))?
|
chain
|
||||||
.epoch(T::EthSpec::slots_per_epoch());
|
.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 == tolerant_current_epoch {
|
if request_epoch == current_epoch || request_epoch == tolerant_current_epoch {
|
||||||
// If we could consider ourselves in the `request_epoch` when allowing for clock disparity
|
// If we could consider ourselves in the `request_epoch` when allowing for clock disparity
|
||||||
|
|||||||
Reference in New Issue
Block a user