Fix issues with per_epoch block_root calls
They were being called with the wrong slot.
This commit is contained in:
parent
5c44f97fba
commit
3f13c25c05
@ -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 {
|
||||
|
@ -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.
|
||||
|
@ -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.
|
||||
//
|
||||
|
Loading…
Reference in New Issue
Block a user