Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: use multi fork type for IndexedAttestation #7399

Merged
merged 1 commit into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
createAggregateSignatureSetFromComponents,
isAggregatorFromCommitteeLength,
} from "@lodestar/state-transition";
import {IndexedAttestation, RootHex, SignedAggregateAndProof, electra, phase0, ssz} from "@lodestar/types";
import {IndexedAttestation, RootHex, SignedAggregateAndProof, electra, ssz} from "@lodestar/types";
import {toRootHex} from "@lodestar/utils";
import {AttestationError, AttestationErrorCode, GossipAction} from "../errors/index.js";
import {IBeaconChain} from "../index.js";
Expand Down Expand Up @@ -178,15 +178,11 @@ async function validateAggregateAndProof(
}
const attestingIndices = aggregate.aggregationBits.intersectValues(committeeIndices);

const indexedAttestationContent: IndexedAttestation = {
const indexedAttestation: IndexedAttestation = {
attestingIndices,
data: attData,
signature: aggregate.signature,
};
const indexedAttestation =
ForkSeq[fork] >= ForkSeq.electra
? (indexedAttestationContent as electra.IndexedAttestation)
: (indexedAttestationContent as phase0.IndexedAttestation);

// TODO: Check this before regen
// [REJECT] The attestation has participants -- that is,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
getEffectiveBalanceIncrementsZeroed,
} from "@lodestar/state-transition";
import {getTemporaryBlockHeader, processSlots} from "@lodestar/state-transition";
import {Slot, ValidatorIndex, phase0, ssz} from "@lodestar/types";
import {IndexedAttestation, Slot, ValidatorIndex, phase0, ssz} from "@lodestar/types";
import {beforeAll, beforeEach, describe, expect, it, vi} from "vitest";
import {ChainEventEmitter, initializeForkChoice} from "../../../../src/chain/index.js";
import {createCachedBeaconStateTest} from "../../../utils/cachedBeaconState.js";
Expand Down Expand Up @@ -418,7 +418,7 @@ function createIndexedAttestation(
target: phase0.SignedBeaconBlock,
block: phase0.SignedBeaconBlock,
validatorIndex: ValidatorIndex
): phase0.IndexedAttestation {
): IndexedAttestation {
return {
attestingIndices: [validatorIndex],
data: {
Expand Down
17 changes: 14 additions & 3 deletions packages/fork-choice/src/forkChoice/forkChoice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,18 @@ import {
isExecutionStateType,
} from "@lodestar/state-transition";
import {computeUnrealizedCheckpoints} from "@lodestar/state-transition/epoch";
import {BeaconBlock, Epoch, Root, RootHex, Slot, ValidatorIndex, bellatrix, phase0, ssz} from "@lodestar/types";
import {
BeaconBlock,
Epoch,
IndexedAttestation,
Root,
RootHex,
Slot,
ValidatorIndex,
bellatrix,
phase0,
ssz,
} from "@lodestar/types";
import {Logger, MapDef, fromHex, toRootHex} from "@lodestar/utils";

import {computeDeltas} from "../protoArray/computeDeltas.js";
Expand Down Expand Up @@ -686,7 +697,7 @@ export class ForkChoice implements IForkChoice {
* The supplied `attestation` **must** pass the `in_valid_indexed_attestation` function as it
* will not be run here.
*/
onAttestation(attestation: phase0.IndexedAttestation, attDataRoot: string, forceImport?: boolean): void {
onAttestation(attestation: IndexedAttestation, attDataRoot: string, forceImport?: boolean): void {
// Ignore any attestations to the zero hash.
//
// This is an edge case that results from the spec aliasing the zero hash to the genesis
Expand Down Expand Up @@ -1199,7 +1210,7 @@ export class ForkChoice implements IForkChoice {
* https://github.com/ethereum/consensus-specs/blob/v1.1.10/specs/phase0/fork-choice.md#validate_on_attestation
*/
private validateOnAttestation(
indexedAttestation: phase0.IndexedAttestation,
indexedAttestation: IndexedAttestation,
slot: Slot,
blockRootHex: string,
targetEpoch: Epoch,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {ForkSeq, MAX_COMMITTEES_PER_SLOT, MAX_VALIDATORS_PER_COMMITTEE} from "@lodestar/params";
import {phase0} from "@lodestar/types";
import {IndexedAttestation, IndexedAttestationBigint} from "@lodestar/types";
import {getIndexedAttestationBigintSignatureSet, getIndexedAttestationSignatureSet} from "../signatureSets/index.js";
import {CachedBeaconStateAllForks} from "../types.js";
import {verifySignatureSet} from "../util/index.js";
Expand All @@ -9,7 +9,7 @@ import {verifySignatureSet} from "../util/index.js";
*/
export function isValidIndexedAttestation(
state: CachedBeaconStateAllForks,
indexedAttestation: phase0.IndexedAttestation,
indexedAttestation: IndexedAttestation,
verifySignature: boolean
): boolean {
if (!isValidIndexedAttestationIndices(state, indexedAttestation.attestingIndices)) {
Expand All @@ -24,7 +24,7 @@ export function isValidIndexedAttestation(

export function isValidIndexedAttestationBigint(
state: CachedBeaconStateAllForks,
indexedAttestation: phase0.IndexedAttestationBigint,
indexedAttestation: IndexedAttestationBigint,
verifySignature: boolean
): boolean {
if (!isValidIndexedAttestationIndices(state, indexedAttestation.attestingIndices)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {DOMAIN_BEACON_ATTESTER} from "@lodestar/params";
import {SignedBeaconBlock, phase0, ssz} from "@lodestar/types";
import {IndexedAttestation, SignedBeaconBlock, phase0, ssz} from "@lodestar/types";
import {CachedBeaconStateAllForks} from "../types.js";
import {
ISignatureSet,
Expand Down Expand Up @@ -32,7 +32,7 @@ export function getAttestationWithIndicesSignatureSet(

export function getIndexedAttestationSignatureSet(
state: CachedBeaconStateAllForks,
indexedAttestation: phase0.IndexedAttestation
indexedAttestation: IndexedAttestation
): ISignatureSet {
return getAttestationWithIndicesSignatureSet(state, indexedAttestation, indexedAttestation.attestingIndices);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {config} from "@lodestar/config/default";
import {FAR_FUTURE_EPOCH, MAX_EFFECTIVE_BALANCE} from "@lodestar/params";
import {phase0, ssz} from "@lodestar/types";
import {IndexedAttestation, ssz} from "@lodestar/types";
import {describe, expect, it} from "vitest";
import {isValidIndexedAttestation} from "../../../src/block/isValidIndexedAttestation.js";
import {EMPTY_SIGNATURE} from "../../../src/index.js";
Expand Down Expand Up @@ -40,7 +40,7 @@ describe("validate indexed attestation", () => {
attestationData.source.epoch = 0;
attestationData.target.epoch = 1;

const indexedAttestation: phase0.IndexedAttestation = {
const indexedAttestation: IndexedAttestation = {
attestingIndices: indices,
data: attestationData,
signature: EMPTY_SIGNATURE,
Expand Down
Loading