Skip to content

Commit

Permalink
Fix get state for attestation verification logic
Browse files Browse the repository at this point in the history
  • Loading branch information
dapplion committed Dec 5, 2022
1 parent ad2c300 commit f1e4aaa
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions packages/beacon-node/src/chain/validation/attestation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,20 @@ export async function validateGossipAttestation(
// > Altready check in `verifyHeadBlockAndTargetRoot()`

// TODO: Must be a state in the same chain as attHeadBlock, but dialed to target.epoch
const attHeadState = await chain.regen
.getState(attHeadBlock.stateRoot, RegenCaller.validateGossipAttestation)
.catch((e: Error) => {
throw new AttestationError(GossipAction.REJECT, {
code: AttestationErrorCode.MISSING_ATTESTATION_HEAD_STATE,
error: e as Error,
});
});
const attHeadState =
computeEpochAtSlot(attHeadBlock.slot) < attEpoch
? await chain.regen.getCheckpointState(attTarget, RegenCaller.validateGossipAttestation).catch((e: Error) => {
throw new AttestationError(GossipAction.REJECT, {
code: AttestationErrorCode.MISSING_ATTESTATION_HEAD_STATE,
error: e as Error,
});
})
: await chain.regen.getState(attHeadBlock.stateRoot, RegenCaller.validateGossipAttestation).catch((e: Error) => {
throw new AttestationError(GossipAction.REJECT, {
code: AttestationErrorCode.MISSING_ATTESTATION_HEAD_STATE,
error: e as Error,
});
});

// [REJECT] The committee index is within the expected range
// -- i.e. data.index < get_committee_count_per_slot(state, data.target.epoch)
Expand Down

0 comments on commit f1e4aaa

Please sign in to comment.