Skip to content

Commit

Permalink
Enforce max skip value for proposer cache
Browse files Browse the repository at this point in the history
  • Loading branch information
paulhauner committed Sep 13, 2020
1 parent 9c99d05 commit a377ed9
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions beacon_node/http_api/src/beacon_proposer_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use fork_choice::ProtoBlock;
use state_processing::per_slot_processing;
use types::{Epoch, EthSpec, Hash256, PublicKeyBytes};

const EPOCHS_TO_SKIP: u64 = 2;

pub struct BeaconProposerCache {
epoch: Epoch,
epoch_boundary_root: Hash256,
Expand All @@ -13,8 +15,17 @@ pub struct BeaconProposerCache {
impl BeaconProposerCache {
pub fn new<T: BeaconChainTypes>(chain: &BeaconChain<T>) -> Result<Self, BeaconChainError> {
let (head_root, head_block) = Self::current_head_block(chain)?;
let current_epoch = chain.epoch()?;
Self::for_head_block(chain, current_epoch, head_root, head_block)

let epoch = {
let epoch_now = chain.epoch()?;
if epoch_now > state.current_epoch() + EPOCHS_TO_SKIP {
state.current_epoch()
} else {
epoch_now
}
};

Self::for_head_block(chain, epoch, head_root, head_block)
}

fn for_head_block<T: BeaconChainTypes>(
Expand Down

0 comments on commit a377ed9

Please sign in to comment.