Skip to content

Commit

Permalink
Misc
Browse files Browse the repository at this point in the history
  • Loading branch information
ensi321 committed Apr 29, 2024
1 parent b2d070a commit 35e04d1
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 16 deletions.
4 changes: 2 additions & 2 deletions packages/api/src/beacon/routes/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export type EventData = {
[EventType.attestation]: {version: ForkName; data: allForks.Attestation};
[EventType.voluntaryExit]: phase0.SignedVoluntaryExit;
[EventType.proposerSlashing]: phase0.ProposerSlashing;
[EventType.attesterSlashing]: phase0.AttesterSlashing;
[EventType.attesterSlashing]: {version: ForkName; data: allForks.AttesterSlashing};
[EventType.blsToExecutionChange]: capella.SignedBLSToExecutionChange;
[EventType.finalizedCheckpoint]: {
block: RootHex;
Expand Down Expand Up @@ -183,7 +183,7 @@ export function getTypeByEvent(): {[K in EventType]: TypeJson<EventData[K]>} {
[EventType.attestation]: WithVersion((fork) => ssz.allForks[fork].Attestation),
[EventType.voluntaryExit]: ssz.phase0.SignedVoluntaryExit,
[EventType.proposerSlashing]: ssz.phase0.ProposerSlashing,
[EventType.attesterSlashing]: ssz.phase0.AttesterSlashing,
[EventType.attesterSlashing]: WithVersion((fork) => ssz.allForks[fork].AttesterSlashing),
[EventType.blsToExecutionChange]: ssz.capella.SignedBLSToExecutionChange,

[EventType.finalizedCheckpoint]: new ContainerType(
Expand Down
4 changes: 2 additions & 2 deletions packages/beacon-node/src/chain/blocks/importBlock.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {toHexString} from "@chainsafe/ssz";
import {capella, ssz, allForks, altair} from "@lodestar/types";
import {ForkSeq, INTERVALS_PER_SLOT, MAX_SEED_LOOKAHEAD, SLOTS_PER_EPOCH} from "@lodestar/params";
import {ForkName, ForkSeq, INTERVALS_PER_SLOT, MAX_SEED_LOOKAHEAD, SLOTS_PER_EPOCH} from "@lodestar/params";
import {
CachedBeaconStateAltair,
computeEpochAtSlot,
Expand Down Expand Up @@ -422,7 +422,7 @@ export async function importBlock(
}
if (this.emitter.listenerCount(routes.events.EventType.attesterSlashing)) {
for (const attesterSlashing of block.message.body.attesterSlashings) {
this.emitter.emit(routes.events.EventType.attesterSlashing, attesterSlashing);
this.emitter.emit(routes.events.EventType.attesterSlashing, {version: this.config.getForkName(blockSlot), data: attesterSlashing});
}
}
if (this.emitter.listenerCount(routes.events.EventType.proposerSlashing)) {
Expand Down
9 changes: 5 additions & 4 deletions packages/beacon-node/src/chain/opPools/opPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
BLS_WITHDRAWAL_PREFIX,
MAX_ATTESTER_SLASHINGS,
ForkSeq,
MAX_ATTESTER_SLASHINGS_ELECTRA,
} from "@lodestar/params";
import {Epoch, phase0, capella, ssz, ValidatorIndex, allForks} from "@lodestar/types";
import {IBeaconDb} from "../../db/index.js";
Expand Down Expand Up @@ -173,7 +174,7 @@ export class OpPool {
blockType: BlockType,
metrics: Metrics | null
): [
phase0.AttesterSlashing[],
allForks.AttesterSlashing[],
phase0.ProposerSlashing[],
phase0.SignedVoluntaryExit[],
capella.SignedBLSToExecutionChange[],
Expand Down Expand Up @@ -207,7 +208,8 @@ export class OpPool {
});

const endAttesterSlashings = stepsMetrics?.startTimer();
const attesterSlashings: phase0.AttesterSlashing[] = [];
const attesterSlashings: allForks.AttesterSlashing[] = [];
const maxAttesterSlashing = stateFork >= ForkSeq.electra ? MAX_ATTESTER_SLASHINGS_ELECTRA : MAX_ATTESTER_SLASHINGS;
attesterSlashing: for (const attesterSlashing of this.attesterSlashings.values()) {
/** Indices slashable in this attester slashing */
const slashableIndices = new Set<ValidatorIndex>();
Expand All @@ -222,8 +224,7 @@ export class OpPool {
if (isSlashableAtEpoch(validator, stateEpoch)) {
slashableIndices.add(index);
}
if (attesterSlashings.length >= MAX_ATTESTER_SLASHINGS) {
// TODO Electra: MAX_ATTESTER_SLASHINGS_ELECTRA
if (attesterSlashings.length >= maxAttesterSlashing) {
break attesterSlashing;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ const DEFAULT_CACHE_SLOT_DISTANCE = 2;
/**
* As of April 2023, validating gossip attestation takes ~12% of cpu time for a node subscribing to all subnets on mainnet.
* Having this cache help saves a lot of cpu time since most of the gossip attestations are on the same slot.
* TODO Electra: Handle electra attestations
*/
export class SeenAttestationDatas {
private cacheEntryByAttDataBase64BySlot = new MapDef<Slot, Map<AttDataBase64, AttestationDataCacheEntry>>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ function getDefaultHandlers(modules: ValidatorFnsModules, options: GossipHandler
logger.error("Error adding attesterSlashing to pool", {}, e as Error);
}

chain.emitter.emit(routes.events.EventType.attesterSlashing, attesterSlashing);
chain.emitter.emit(routes.events.EventType.attesterSlashing, {version: topic.fork, data: attesterSlashing});
},

[GossipType.proposer_slashing]: async ({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {allForks, phase0, ssz} from "@lodestar/types";
import {allForks, ssz} from "@lodestar/types";
import {DOMAIN_BEACON_ATTESTER} from "@lodestar/params";
import {computeSigningRoot, computeStartSlotAtEpoch, ISignatureSet, SignatureSetType} from "../util/index.js";
import {CachedBeaconStateAllForks} from "../types.js";
Expand All @@ -16,7 +16,7 @@ export function getAttesterSlashingsSignatureSets(
/** Get signature sets from a single AttesterSlashing object */
export function getAttesterSlashingSignatureSets(
state: CachedBeaconStateAllForks,
attesterSlashing: phase0.AttesterSlashing
attesterSlashing: allForks.AttesterSlashing,
): ISignatureSet[] {
return [attesterSlashing.attestation1, attesterSlashing.attestation2].map((attestation) =>
getIndexedAttestationBigintSignatureSet(state, attestation)
Expand All @@ -25,7 +25,7 @@ export function getAttesterSlashingSignatureSets(

export function getIndexedAttestationBigintSignatureSet(
state: CachedBeaconStateAllForks,
indexedAttestation: phase0.IndexedAttestationBigint
indexedAttestation: allForks.IndexedAttestationBigint
): ISignatureSet {
const slot = computeStartSlotAtEpoch(Number(indexedAttestation.data.target.epoch as bigint));
const domain = state.config.getDomain(state.slot, DOMAIN_BEACON_ATTESTER, slot);
Expand Down
6 changes: 3 additions & 3 deletions packages/state-transition/src/signatureSets/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ export function getBlockSignatureSets(
skipProposerSignature?: boolean;
}
): ISignatureSet[] {
// fork based validations
const fork = state.config.getForkSeq(signedBlock.message.slot);

const signatureSets = [
getRandaoRevealSignatureSet(state, signedBlock.message),
...getProposerSlashingsSignatureSets(state, signedBlock),
Expand All @@ -43,9 +46,6 @@ export function getBlockSignatureSets(
signatureSets.push(getBlockProposerSignatureSet(state, signedBlock));
}

// fork based validations
const fork = state.config.getForkSeq(signedBlock.message.slot);

// Only after altair fork, validate tSyncCommitteeSignature
if (fork >= ForkSeq.altair) {
const syncCommitteeSignatureSet = getSyncCommitteeSignatureSet(
Expand Down
6 changes: 6 additions & 0 deletions packages/types/src/allForks/sszTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const allForks = {
Metadata: phase0.Metadata,
SignedAggregateAndProof: phase0.SignedAggregateAndProof,
Attestation: phase0.Attestation,
AttesterSlashing: phase0.AttesterSlashing,
},
altair: {
BeaconBlockBody: altair.BeaconBlockBody,
Expand All @@ -27,6 +28,7 @@ export const allForks = {
Metadata: altair.Metadata,
SignedAggregateAndProof: phase0.SignedAggregateAndProof,
Attestation: phase0.Attestation,
AttesterSlashing: phase0.AttesterSlashing,
},
bellatrix: {
BeaconBlockBody: bellatrix.BeaconBlockBody,
Expand All @@ -36,6 +38,7 @@ export const allForks = {
Metadata: altair.Metadata,
SignedAggregateAndProof: phase0.SignedAggregateAndProof,
Attestation: phase0.Attestation,
AttesterSlashing: phase0.AttesterSlashing,
},
capella: {
BeaconBlockBody: capella.BeaconBlockBody,
Expand All @@ -45,6 +48,7 @@ export const allForks = {
Metadata: altair.Metadata,
SignedAggregateAndProof: phase0.SignedAggregateAndProof,
Attestation: phase0.Attestation,
AttesterSlashing: phase0.AttesterSlashing,
},
deneb: {
BeaconBlockBody: deneb.BeaconBlockBody,
Expand All @@ -54,6 +58,7 @@ export const allForks = {
Metadata: altair.Metadata,
SignedAggregateAndProof: phase0.SignedAggregateAndProof,
Attestation: phase0.Attestation,
AttesterSlashing: phase0.AttesterSlashing,
},
electra: {
BeaconBlockBody: electra.BeaconBlockBody,
Expand All @@ -63,6 +68,7 @@ export const allForks = {
Metadata: altair.Metadata,
SignedAggregateAndProof: electra.SignedAggregateAndProof,
Attestation: electra.Attestation,
AttesterSlashing: electra.AttesterSlashing,
},
};

Expand Down
2 changes: 2 additions & 0 deletions packages/types/src/allForks/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ export type Attestation = phase0.Attestation | electra.Attestation;
export type AggregateAndProof = phase0.AggregateAndProof | electra.AggregateAndProof;
export type SignedAggregateAndProof = phase0.SignedAggregateAndProof | electra.SignedAggregateAndProof;
export type IndexedAttestation = phase0.IndexedAttestation | electra.IndexedAttestation;
export type IndexedAttestationBigint = phase0.IndexedAttestationBigint | electra.IndexedAttestationBigint;
export type AttesterSlashing = phase0.AttesterSlashing | electra.AttesterSlashing;
export type Metadata = phase0.Metadata | altair.Metadata;

// For easy reference in the assemble block for building payloads
Expand Down
2 changes: 2 additions & 0 deletions packages/types/src/electra/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,5 @@ export type LightClientStore = ValueOf<typeof ssz.LightClientStore>;

export type AggregateAndProof = ValueOf<typeof ssz.AggregateAndProof>;
export type SignedAggregateAndProof = ValueOf<typeof ssz.SignedAggregateAndProof>;
export type AttesterSlashing = ValueOf<typeof ssz.AttesterSlashing>
export type IndexedAttestationBigint = ValueOf<typeof ssz.IndexedAttestationBigint>

0 comments on commit 35e04d1

Please sign in to comment.