@lodestar/beacon-node
Version:
A Typescript implementation of the beacon chain
121 lines • 6.49 kB
TypeScript
import { BeaconConfig } from "@lodestar/config";
import { ProtoBlock } from "@lodestar/fork-choice";
import { ForkName, ForkPostElectra, ForkPreElectra } from "@lodestar/params";
import { EpochShuffling, SingleSignatureSet } from "@lodestar/state-transition";
import { CommitteeIndex, Epoch, IndexedAttestation, Root, RootHex, SingleAttestation, Slot, SubnetID, ValidatorIndex, phase0 } from "@lodestar/types";
import { Result } from "../../util/wrapError.js";
import { IBeaconChain } from "../interface.js";
import { RegenCaller } from "../regen/index.js";
import { SeenAttDataKey } from "../seenCache/seenAttestationData.js";
export type BatchResult = {
results: Result<AttestationValidationResult>[];
batchableBls: boolean;
};
export type AttestationValidationResult = {
attestation: SingleAttestation;
indexedAttestation: IndexedAttestation;
subnet: SubnetID;
attDataRootHex: RootHex;
committeeIndex: CommitteeIndex;
committeeValidatorIndex: number;
committeeSize: number;
};
export type AttestationOrBytes = ApiAttestation | GossipAttestation;
/** attestation from api */
export type ApiAttestation = {
attestation: SingleAttestation;
serializedData: null;
};
/** attestation from gossip */
export type GossipAttestation = {
attestation: null;
serializedData: Uint8Array;
attSlot: Slot;
attDataBase64: SeenAttDataKey;
subnet: SubnetID;
};
export type Step0Result = AttestationValidationResult & {
signatureSet: SingleSignatureSet;
validatorIndex: number;
};
/**
* Verify gossip attestations of the same attestation data. The main advantage is we can batch verify bls signatures
* through verifySignatureSetsSameMessage bls api to improve performance.
* - If there are less than 2 signatures (minSameMessageSignatureSetsToBatch), verify each signature individually with batchable = true
* - do not prioritize bls signature set
*/
export declare function validateGossipAttestationsSameAttData(fork: ForkName, chain: IBeaconChain, attestationOrBytesArr: GossipAttestation[], step0ValidationFn?: typeof validateAttestationNoSignatureCheck): Promise<BatchResult>;
/**
* Validate attestations from api
* - no need to deserialize attestation
* - no subnet
* - prioritize bls signature set
*/
export declare function validateApiAttestation(fork: ForkName, chain: IBeaconChain, attestationOrBytes: ApiAttestation): Promise<AttestationValidationResult>;
/**
* Only deserialize the single attestation if needed, use the cached AttestationData instead
* This is to avoid deserializing similar attestation multiple times which could help the gc
*/
declare function validateAttestationNoSignatureCheck(fork: ForkName, chain: IBeaconChain, attestationOrBytes: AttestationOrBytes,
/** Optional, to allow verifying attestations through API with unknown subnet */
subnet: SubnetID | null): Promise<Step0Result>;
/**
* Verify that the `attestation` is within the acceptable gossip propagation range, with reference
* to the current slot of the `chain`.
*
* Accounts for `MAXIMUM_GOSSIP_CLOCK_DISPARITY`.
* Note: We do not queue future attestations for later processing
*/
export declare function verifyPropagationSlotRange(fork: ForkName, chain: IBeaconChain, attestationSlot: Slot): void;
/**
* Verify:
* 1. head block is known
* 2. attestation's target block is an ancestor of the block named in the LMD vote
*/
export declare function verifyHeadBlockAndTargetRoot(chain: IBeaconChain, beaconBlockRoot: Root, targetRoot: Root, attestationSlot: Slot, attestationEpoch: Epoch, caller: RegenCaller, maxSkipSlots?: number): ProtoBlock;
/**
* Get a shuffling for attestation verification from the ShufflingCache.
* - if blockEpoch is attEpoch, use current shuffling of head state
* - if blockEpoch is attEpoch - 1, use next shuffling of head state
* - if blockEpoch is less than attEpoch - 1, dial head state to attEpoch - 1, and add to ShufflingCache
*
* This implementation does not require to dial head state to attSlot at fork boundary because we always get domain of attSlot
* in consumer context.
*
* This is similar to the old getStateForAttestationVerification
* see https://github.com/ChainSafe/lodestar/blob/v1.11.3/packages/beacon-node/src/chain/validation/attestation.ts#L566
*/
export declare function getShufflingForAttestationVerification(chain: IBeaconChain, attEpoch: Epoch, attHeadBlock: ProtoBlock, regenCaller: RegenCaller): Promise<EpochShuffling>;
/**
* Different version of getAttestationDataSigningRoot in state-transition which doesn't require a state.
*/
export declare function getAttestationDataSigningRoot(config: BeaconConfig, data: phase0.AttestationData): Uint8Array;
/**
* Get a list of indices of validators in the given committee
* attestationIndex - Index of the committee in shuffling.committees
*/
export declare function getCommitteeIndices(shuffling: EpochShuffling, attestationSlot: Slot, attestationIndex: number): Uint32Array;
/**
* Compute the correct subnet for a slot/committee index
*/
export declare function computeSubnetForSlot(shuffling: EpochShuffling, slot: number, committeeIndex: number): SubnetID;
/**
* Return fork-dependent seen attestation key
* - for pre-electra, it's the AttestationData base64 from Attestation
* - for electra and later, it's the AttestationData base64 from SingleAttestation
* - consumers need to also pass slot + committeeIndex to get the correct SeenAttestationData
*/
export declare function getSeenAttDataKeyFromGossipAttestation(attestation: GossipAttestation): SeenAttDataKey | null;
/**
* Extract attestation data key from SignedAggregateAndProof Uint8Array to use cached data from SeenAttestationDatas
* - for both electra + pre-electra, it's the AttestationData base64
* - consumers need to also pass slot + committeeIndex to get the correct SeenAttestationData
*/
export declare function getSeenAttDataKeyFromSignedAggregateAndProof(fork: ForkName, aggregateAndProof: Uint8Array): SeenAttDataKey | null;
export declare function getCommitteeIndexFromAttestationOrBytes(fork: ForkName, attestationOrBytes: AttestationOrBytes): CommitteeIndex | null;
/**
* Convert pre-electra single attestation (`phase0.Attestation`) to post-electra `SingleAttestation`
*/
export declare function toElectraSingleAttestation(attestation: SingleAttestation<ForkPreElectra>, attesterIndex: ValidatorIndex): SingleAttestation<ForkPostElectra>;
export {};
//# sourceMappingURL=attestation.d.ts.map