UNPKG

@lodestar/beacon-node

Version:

A Typescript implementation of the beacon chain

87 lines 4.14 kB
import { Signature } from "@chainsafe/blst"; import { BitArray } from "@chainsafe/ssz"; import { ChainForkConfig } from "@lodestar/config"; import { Attestation, RootHex, SingleAttestation, Slot } from "@lodestar/types"; import { Metrics } from "../../metrics/metrics.js"; import { IClock } from "../../util/clock.js"; import { InsertOutcome } from "./types.js"; type AggregateFastPhase0 = { data: Attestation["data"]; aggregationBits: BitArray; signature: Signature; }; export type AggregateFastElectra = AggregateFastPhase0 & { committeeBits: BitArray; }; export type AggregateFast = AggregateFastPhase0 | AggregateFastElectra; /** CommitteeIndex must be null for pre-electra. Must not be null post-electra */ type CommitteeIndex = number | null; /** * A pool of `Attestation` that is specially designed to store "unaggregated" attestations from * the native aggregation scheme. * * **The `NaiveAggregationPool` does not do any signature or attestation verification. It assumes * that all `Attestation` objects provided are valid.** * * ## Details * * The pool sorts the `Attestation` by `attestation.data.slot`, then by `attestation.data`. * * As each unaggregated attestation is added it is aggregated with any existing `attestation` with * the same `AttestationData`. Considering that the pool only accepts attestations with a single * signature, there should only ever be a single aggregated `Attestation` for any given * `AttestationData`. * * The pool has a capacity for `SLOTS_RETAINED` slots, when a new `attestation.data.slot` is * provided, the oldest slot is dropped and replaced with the new slot. The pool can also be * pruned by supplying a `current_slot`; all existing attestations with a slot lower than * `current_slot - SLOTS_RETAINED` will be removed and any future attestation with a slot lower * than that will also be refused. Pruning is done automatically based upon the attestations it * receives and it can be triggered manually. */ export declare class AttestationPool { private readonly config; private readonly clock; private readonly cutOffSecFromSlot; private readonly preaggregateSlotDistance; private readonly metrics; private readonly aggregateByIndexByRootBySlot; private lowestPermissibleSlot; constructor(config: ChainForkConfig, clock: IClock, cutOffSecFromSlot: number, preaggregateSlotDistance?: number, metrics?: Metrics | null); /** Returns current count of pre-aggregated attestations with unique data */ getAttestationCount(): number; /** * Accepts an `VerifiedUnaggregatedAttestation` and attempts to apply it to the "naive * aggregation pool". * * The naive aggregation pool is used by local validators to produce * `SignedAggregateAndProof`. * * If the attestation is too old (low slot) to be included in the pool it is simply dropped * and no error is returned. Also if it's at clock slot but come to the pool later than 2/3 * of slot time, it's dropped too since it's not helpful for the validator anymore * * Expects the attestation to be fully validated: * - Valid signature * - Consistent bitlength * - Valid committeeIndex * - Valid data */ add(committeeIndex: CommitteeIndex, attestation: SingleAttestation, attDataRootHex: RootHex, committeeValidatorIndex: number, committeeSize: number, priority?: boolean): InsertOutcome; /** * For validator API to get an aggregate */ getAggregate(slot: Slot, dataRootHex: RootHex, committeeIndex: CommitteeIndex): Attestation | null; /** * Removes any attestations with a slot lower than `current_slot - preaggregateSlotDistance`. * By default, not interested in attestations in old slots, we only preaggregate attestations for the current slot. */ prune(clockSlot: Slot): void; /** * Get all attestations optionally filtered by `attestation.data.slot` * @param bySlot slot to filter, `bySlot === attestation.data.slot` */ getAll(bySlot?: Slot): Attestation[]; } export {}; //# sourceMappingURL=attestationPool.d.ts.map