Skip to content

Commit

Permalink
Misc
Browse files Browse the repository at this point in the history
  • Loading branch information
ensi321 committed May 6, 2024
1 parent 4f8fdcf commit f7ae62b
Show file tree
Hide file tree
Showing 8 changed files with 18 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 @@ -433,7 +433,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
2 changes: 2 additions & 0 deletions packages/types/src/electra/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,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 f7ae62b

Please sign in to comment.