Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ensi321 committed May 7, 2024
1 parent 0de6dfa commit 4760572
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 14 deletions.
1 change: 1 addition & 0 deletions packages/beacon-node/src/chain/blocks/importBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ export async function importBlock(

for (const attestation of attestations) {
try {
// TODO Electra: figure out how to reuse the attesting indices computed from state transition
const indexedAttestation = postState.epochCtx.getIndexedAttestation(fork, attestation);
const {target, beaconBlockRoot} = attestation.data;

Expand Down
5 changes: 4 additions & 1 deletion packages/beacon-node/test/spec/presets/fork_choice.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,10 @@ const forkChoiceTest =
if (!attestation) throw Error(`No attestation ${step.attestation}`);
const headState = chain.getHeadState();
const attDataRootHex = toHexString(ssz.phase0.AttestationData.hashTreeRoot(attestation.data));
chain.forkChoice.onAttestation(headState.epochCtx.getIndexedAttestation(ForkSeq[fork], attestation), attDataRootHex);
chain.forkChoice.onAttestation(
headState.epochCtx.getIndexedAttestation(ForkSeq[fork], attestation),
attDataRootHex
);
}

// attester slashing step
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
ApiAttestation,
GossipAttestation,
validateApiAttestation,
validateAttestation,
validateAttestation,
} from "../../../../../src/chain/validation/index.js";
import {getAttDataBase64FromAttestationSerialized} from "../../../../../src/util/sszBytes.js";
import {memoOnce} from "../../../../utils/cache.js";
Expand Down
15 changes: 7 additions & 8 deletions packages/state-transition/src/block/processAttestationPhase0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {toHexString} from "@chainsafe/ssz";
import {Slot, allForks, electra, phase0, ssz} from "@lodestar/types";

import {MIN_ATTESTATION_INCLUSION_DELAY, SLOTS_PER_EPOCH, ForkSeq} from "@lodestar/params";
import {assert} from "@lodestar/utils";
import {computeEpochAtSlot} from "../util/index.js";
import {CachedBeaconStatePhase0, CachedBeaconStateAllForks} from "../types.js";
import {isValidIndexedAttestation} from "./index.js";
Expand Down Expand Up @@ -89,9 +90,7 @@ export function validateAttestation(
}

if (fork >= ForkSeq.electra) {
if (data.index !== 0) {
throw new Error(`AttestationData.index must be zero: index=${data.index}`);
}
assert.equal(data.index, 0, `AttestationData.index must be zero: index=${data.index}`);
const attestationElectra = attestation as electra.Attestation;
const committeeBitsLength = attestationElectra.committeeBits.bitLen;

Expand All @@ -109,11 +108,11 @@ export function validateAttestation(
.map((committeeIndex) => epochCtx.getBeaconCommittee(data.slot, committeeIndex).length)
.reduce((acc, committeeSize) => acc + committeeSize, 0);

if (attestationElectra.aggregationBits.bitLen !== participantCount) {
throw new Error(
`Attestation aggregation bits length does not match total number of committee participant aggregationBitsLength=${attestation.aggregationBits.bitLen} participantCount=${participantCount}`
);
}
assert.equal(
attestationElectra.aggregationBits.bitLen,
participantCount,
`Attestation aggregation bits length does not match total number of committee participant aggregationBitsLength=${attestation.aggregationBits.bitLen} participantCount=${participantCount}`
);
} else {
if (!(data.index < committeeCount)) {
throw new Error(
Expand Down
6 changes: 2 additions & 4 deletions packages/state-transition/src/cache/epochCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,6 @@ export class EpochCache {
* Return a single Uint32Array representing concatted committees of indices
*/
getBeaconCommittees(slot: Slot, indices: CommitteeIndex[]): Uint32Array {

if (indices.length === 0) {
throw new Error("Attempt to get committees without providing CommitteeIndex");
}
Expand Down Expand Up @@ -809,13 +808,12 @@ export class EpochCache {
// In Lodestar it usually means a list of validator indices of participants in a committee
// In the spec it means a list of committee indices according to committeeBits
// This `committeeIndices` refers to the latter
// TODO Electra: resolve the naming conflicts
const committeeIndices = committeeBits.getTrueBitIndexes();

const validatorIndices = this.getBeaconCommittees(data.slot, committeeIndices);

const attestingIndices = new Set(aggregationBits.intersectValues(validatorIndices));

return Array.from(attestingIndices);
return aggregationBits.intersectValues(validatorIndices);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export function getAttestationsSignatureSets(
state: CachedBeaconStateAllForks,
signedBlock: allForks.SignedBeaconBlock
): ISignatureSet[] {
// TODO: figure how to get attesting indices of an attestation once per block processing
return signedBlock.message.body.attestations.map((attestation) =>
getIndexedAttestationSignatureSet(
state,
Expand Down

0 comments on commit 4760572

Please sign in to comment.