Fix issues with per_epoch block_root calls

They were being called with the wrong slot.
This commit is contained in:
Paul Hauner 2019-01-31 18:28:54 +11:00
parent 5c44f97fba
commit 3f13c25c05
No known key found for this signature in database
GPG Key ID: D362883A9218FCC6
3 changed files with 13 additions and 8 deletions

View File

@ -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 {

View File

@ -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.

View File

@ -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.
//