diff --git a/beacon_node/beacon_chain/src/attestation_production.rs b/beacon_node/beacon_chain/src/attestation_production.rs index 5adf70a4a..9755f48af 100644 --- a/beacon_node/beacon_chain/src/attestation_production.rs +++ b/beacon_node/beacon_chain/src/attestation_production.rs @@ -30,8 +30,9 @@ where .ok_or_else(|| Error::SlotTooOld)?; let head_slot = self.head().beacon_block.slot; + let previous_epoch_start_slot = head_slot - (head_slot % self.spec.epoch_length); let epoch_boundary_root = *state - .get_block_root(head_slot % self.spec.epoch_length, &self.spec) + .get_block_root(previous_epoch_start_slot, &self.spec) .ok_or_else(|| Error::SlotTooOld)?; Ok(AttestationData { diff --git a/eth2/types/src/beacon_state/committees.rs b/eth2/types/src/beacon_state/committees.rs index d4fd725da..1e1689e92 100644 --- a/eth2/types/src/beacon_state/committees.rs +++ b/eth2/types/src/beacon_state/committees.rs @@ -27,6 +27,14 @@ impl BeaconState { self.current_epoch(spec).saturating_sub(1) } + pub fn current_epoch_start_slot(&self, spec: &ChainSpec) -> u64 { + self.current_epoch(spec) * spec.epoch_length + } + + pub fn previous_epoch_start_slot(&self, spec: &ChainSpec) -> u64 { + self.previous_epoch(spec) * spec.epoch_length + } + /// Returns the number of committees per slot. /// /// Note: this is _not_ the committee size. diff --git a/eth2/types/src/beacon_state/epoch_processing.rs b/eth2/types/src/beacon_state/epoch_processing.rs index 2ff6d58c3..f38024181 100644 --- a/eth2/types/src/beacon_state/epoch_processing.rs +++ b/eth2/types/src/beacon_state/epoch_processing.rs @@ -71,8 +71,7 @@ impl BeaconState { current_epoch_attestations .iter() .filter(|a| { - // TODO: ensure this saturating sub is correct. - match self.get_block_root(self.slot.saturating_sub(spec.epoch_length), spec) { + match self.get_block_root(self.current_epoch_start_slot(spec), spec) { Some(block_root) => { (a.data.epoch_boundary_root == *block_root) && (a.data.justified_slot == self.justified_slot) @@ -142,9 +141,7 @@ impl BeaconState { previous_epoch_justified_attestations .iter() .filter(|a| { - // TODO: ensure this saturating sub is correct. - match self.get_block_root(self.slot.saturating_sub(2 * spec.epoch_length), spec) - { + match self.get_block_root(self.previous_epoch_start_slot(spec), spec) { Some(block_root) => a.data.epoch_boundary_root == *block_root, // Protected by a check that latest_block_roots isn't empty. // @@ -167,8 +164,7 @@ impl BeaconState { previous_epoch_attestations .iter() .filter(|a| { - match self.get_block_root(self.slot.saturating_sub(2 * spec.epoch_length), spec) - { + match self.get_block_root(a.data.slot, spec) { Some(block_root) => a.data.beacon_block_root == *block_root, // Protected by a check that latest_block_roots isn't empty. //