Skip to content

Commit

Permalink
Merge b45b708 into 40620a8
Browse files Browse the repository at this point in the history
  • Loading branch information
twoeths authored Dec 12, 2022
2 parents 40620a8 + b45b708 commit ad0dcea
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 34 deletions.
30 changes: 11 additions & 19 deletions packages/beacon-node/src/chain/validation/aggregateAndProof.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,25 +76,17 @@ export async function validateGossipAggregateAndProof(
// -- i.e. get_ancestor(store, aggregate.data.beacon_block_root, compute_start_slot_at_epoch(store.finalized_checkpoint.epoch)) == store.finalized_checkpoint.root
// > Altready check in `chain.forkChoice.hasBlock(attestation.data.beaconBlockRoot)`

// TODO: Must be a state in the same chain as attHeadBlock, but dialed to target.epoch
const attHeadState =
computeEpochAtSlot(attHeadBlock.slot) < attEpoch
? await chain.regen
.getCheckpointState(attTarget, RegenCaller.validateGossipAggregateAndProof)
.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.validateGossipAggregateAndProof)
.catch((e: Error) => {
throw new AttestationError(GossipAction.REJECT, {
code: AttestationErrorCode.MISSING_ATTESTATION_HEAD_STATE,
error: e as Error,
});
});
// Using the target checkpoint state here caused unstable memory issue
// See https://github.com/ChainSafe/lodestar/issues/4896
// TODO: https://github.com/ChainSafe/lodestar/issues/4900
const attHeadState = await chain.regen
.getState(attHeadBlock.stateRoot, RegenCaller.validateGossipAggregateAndProof)
.catch((e: Error) => {
throw new AttestationError(GossipAction.REJECT, {
code: AttestationErrorCode.MISSING_ATTESTATION_HEAD_STATE,
error: e as Error,
});
});

const committeeIndices: number[] = getCommitteeIndices(attHeadState, attSlot, attIndex);

Expand Down
26 changes: 11 additions & 15 deletions packages/beacon-node/src/chain/validation/attestation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,21 +76,17 @@ export async function validateGossipAttestation(
// --i.e. get_ancestor(store, attestation.data.beacon_block_root, compute_start_slot_at_epoch(attestation.data.target.epoch)) == attestation.data.target.root
// > Altready check in `verifyHeadBlockAndTargetRoot()`

// TODO: Must be a state in the same chain as attHeadBlock, but dialed to target.epoch
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,
});
});
// Using the target checkpoint state here caused unstable memory issue
// See https://github.com/ChainSafe/lodestar/issues/4896
// TODO: https://github.com/ChainSafe/lodestar/issues/4900
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,
});
});

// [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 ad0dcea

Please sign in to comment.