Skip to content

Commit 3f2ffec

Browse files
committed
Make proposer duties work pre-genesis
1 parent 441fc16 commit 3f2ffec

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

beacon_node/http_api/src/proposer_duties.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ pub fn proposer_duties<T: BeaconChainTypes>(
2222
log: &Logger,
2323
) -> Result<ApiDuties, warp::reject::Rejection> {
2424
let current_epoch = chain
25-
.epoch()
25+
.slot_clock
26+
.now_or_genesis()
27+
.map(|slot| slot.epoch(T::EthSpec::slots_per_epoch()))
28+
.ok_or(BeaconChainError::UnableToReadSlot)
2629
.map_err(warp_utils::reject::beacon_chain_error)?;
2730

2831
// 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>(
3134
// Most of the time, `tolerant_current_epoch` will be equal to `current_epoch`. However, during
3235
// the first `MAXIMUM_GOSSIP_CLOCK_DISPARITY` duration of the epoch `tolerant_current_epoch`
3336
// will equal `current_epoch + 1`
34-
let tolerant_current_epoch = chain
35-
.slot_clock
36-
.now_with_future_tolerance(chain.spec.maximum_gossip_clock_disparity())
37-
.ok_or_else(|| warp_utils::reject::custom_server_error("unable to read slot clock".into()))?
38-
.epoch(T::EthSpec::slots_per_epoch());
37+
let tolerant_current_epoch = if chain.slot_clock.is_prior_to_genesis().unwrap_or(true) {
38+
current_epoch
39+
} else {
40+
chain
41+
.slot_clock
42+
.now_with_future_tolerance(chain.spec.maximum_gossip_clock_disparity())
43+
.ok_or_else(|| {
44+
warp_utils::reject::custom_server_error("unable to read slot clock".into())
45+
})?
46+
.epoch(T::EthSpec::slots_per_epoch())
47+
};
3948

4049
if request_epoch == current_epoch || request_epoch == tolerant_current_epoch {
4150
// If we could consider ourselves in the `request_epoch` when allowing for clock disparity

0 commit comments

Comments
 (0)