@lodestar/beacon-node
Version:
A Typescript implementation of the beacon chain
117 lines • 4.74 kB
TypeScript
import { SlotRootHex } from "@lodestar/types";
import { Logger } from "@lodestar/utils";
import { BlockInputSource } from "../../chain/blocks/blockInput/types.js";
import { IBeaconChain } from "../../chain/interface.js";
import { IBeaconDb } from "../../db/interface.js";
import { Metrics } from "../../metrics/metrics.js";
import { PeerIdStr } from "../../util/peerId.js";
import { NetworkEventBus } from "../events.js";
import { GossipHandlers, GossipType } from "../gossip/interface.js";
import { GossipHandlerOpts, ValidatorFnsModules } from "./gossipHandlers.js";
import { ValidatorFnModules } from "./gossipValidatorFn.js";
import { PendingGossipsubMessage } from "./types.js";
export * from "./types.js";
export type NetworkProcessorModules = ValidatorFnsModules & ValidatorFnModules & {
chain: IBeaconChain;
db: IBeaconDb;
events: NetworkEventBus;
logger: Logger;
metrics: Metrics | null;
gossipHandlers?: GossipHandlers;
};
export type NetworkProcessorOpts = GossipHandlerOpts & {
maxGossipTopicConcurrency?: number;
};
/**
* Reprocess reject reason for metrics
*/
export declare enum ReprocessRejectReason {
/**
* There are too many gossip messages that have unknown block root.
*/
reached_limit = "reached_limit",
/**
* The awaiting gossip message is pruned per clock slot.
*/
expired = "expired"
}
/**
* Cannot accept work reason for metrics
*/
export declare enum CannotAcceptWorkReason {
/**
* bls is busy.
*/
bls = "bls_busy",
/**
* regen is busy.
*/
regen = "regen_busy"
}
/**
* Network processor handles the gossip queues and throtles processing to not overload the main thread
* - Decides when to process work and what to process
*
* What triggers execute work?
*
* - When work is submitted
* - When downstream workers become available
*
* ### PendingGossipsubMessage beacon_attestation example
*
* For gossip messages, processing the message includes the steps:
* 1. Pre shuffling sync validation
* 2. Retrieve shuffling: async + goes into the regen queue and can be expensive
* 3. Pre sig validation sync validation
* 4. Validate BLS signature: async + goes into workers through another manager
*
* The gossip queues should receive "backpressue" from the regen and BLS workers queues.
* Such that enough work is processed to fill either one of the queue.
*/
export declare class NetworkProcessor {
private readonly opts;
private readonly chain;
private readonly events;
private readonly logger;
private readonly metrics;
private readonly gossipValidatorFn;
private readonly gossipValidatorBatchFn;
private readonly gossipQueues;
private readonly gossipTopicConcurrency;
private readonly extractBlockSlotRootFns;
private readonly awaitingMessagesByBlockRoot;
private readonly awaitingMessagesByPayloadBlockRoot;
private unknownBlocksBySlot;
private unknownEnvelopesBySlot;
constructor(modules: NetworkProcessorModules, opts: NetworkProcessorOpts);
stop(): Promise<void>;
dropAllJobs(): void;
dumpGossipQueue(topic: GossipType): PendingGossipsubMessage[];
/**
* Search block via `ChainEvent.unknownBlockRoot` event
* Slot is the message slot, which is not necessarily the same as the block's slot, but it can be used for a good prune strategy.
* In the rare case, if 2 messages on 2 slots search for the same root (for example beacon_attestation) we may emit the same root twice but BlockInputSync should handle it well.
*/
searchUnknownBlock({ slot, root }: SlotRootHex, source: BlockInputSource, peer?: PeerIdStr): void;
/**
* Search envelope via `ChainEvent.unknownEnvelopeBlockRoot` event
* Slot is the message slot, which is not necessarily the same as the envelope's slot, but it can be used for a good prune strategy.
* In the rare case, if 2 messages on 2 slots search for the same root (for example beacon_attestation) we may emit the same root twice but BlockInputSync should handle it well.
*/
searchUnknownEnvelope({ slot, root }: SlotRootHex, source: BlockInputSource, peer?: PeerIdStr): void;
private onPendingGossipsubMessage;
private pushPendingGossipsubMessageToQueue;
private onBlockProcessed;
private onPayloadEnvelopeProcessed;
private onClockSlot;
private executeWork;
private processPendingGossipsubMessage;
private trackJobTime;
/**
* Return null if chain can accept work, otherwise return the reason why it cannot accept work
*/
private checkAcceptWork;
private get unknownBlockGossipsubMessagesCount();
private get unknownPayloadGossipsubMessagesCount();
}
//# sourceMappingURL=index.d.ts.map