UNPKG

@lodestar/beacon-node

Version:

A Typescript implementation of the beacon chain

139 lines 7.37 kB
import { PeerScoreStatsDump } from "@chainsafe/libp2p-gossipsub/score"; import { PeerId, PrivateKey } from "@libp2p/interface"; import { routes } from "@lodestar/api"; import { BeaconConfig } from "@lodestar/config"; import { LoggerNode } from "@lodestar/logger/node"; import { AttesterSlashing, LightClientBootstrap, LightClientFinalityUpdate, LightClientOptimisticUpdate, LightClientUpdate, Root, SignedAggregateAndProof, SignedBeaconBlock, SingleAttestation, SlotRootHex, SubnetID, WithBytes, altair, capella, deneb, phase0 } from "@lodestar/types"; import { IBeaconChain } from "../chain/index.js"; import { IBeaconDb } from "../db/interface.js"; import { Metrics } from "../metrics/index.js"; import { PeerIdStr } from "../util/peerId.js"; import { BlobSidecarsByRootRequest } from "../util/types.js"; import { INetworkCore } from "./core/index.js"; import { INetworkEventBus, NetworkEventBus } from "./events.js"; import { GossipHandlers, GossipType } from "./gossip/index.js"; import { INetwork } from "./interface.js"; import { NetworkOptions } from "./options.js"; import { PeerAction, PeerScoreStats } from "./peers/index.js"; import { AggregatorTracker } from "./processor/aggregatorTracker.js"; import { NetworkProcessor, PendingGossipsubMessage } from "./processor/index.js"; import { GetReqRespHandlerFn } from "./reqresp/types.js"; import { CommitteeSubscription } from "./subnets/index.js"; type NetworkModules = { opts: NetworkOptions; privateKey: PrivateKey; config: BeaconConfig; logger: LoggerNode; chain: IBeaconChain; networkEventBus: NetworkEventBus; aggregatorTracker: AggregatorTracker; networkProcessor: NetworkProcessor; core: INetworkCore; }; export type NetworkInitModules = { opts: NetworkOptions; config: BeaconConfig; privateKey: PrivateKey; peerStoreDir?: string; logger: LoggerNode; metrics: Metrics | null; chain: IBeaconChain; db: IBeaconDb; getReqRespHandler: GetReqRespHandlerFn; gossipHandlers?: GossipHandlers; }; /** * Must support running both on worker and on main thread. * * Exists a front class that's what consumers interact with. * This class will multiplex between: * - libp2p in worker * - libp2p in main thread */ export declare class Network implements INetwork { readonly peerId: PeerId; readonly events: INetworkEventBus; private readonly logger; private readonly config; private readonly clock; private readonly chain; private readonly controller; private readonly networkProcessor; private readonly core; private readonly aggregatorTracker; private subscribedToCoreTopics; private connectedPeers; constructor(modules: NetworkModules); static init({ opts, config, logger, metrics, chain, db, gossipHandlers, privateKey, peerStoreDir, getReqRespHandler, }: NetworkInitModules): Promise<Network>; get closed(): boolean; /** Destroy this instance. Can only be called once. */ close(): Promise<void>; scrapeMetrics(): Promise<string>; /** * Request att subnets up `toSlot`. Network will ensure to mantain some peers for each */ prepareBeaconCommitteeSubnets(subscriptions: CommitteeSubscription[]): Promise<void>; prepareSyncCommitteeSubnets(subscriptions: CommitteeSubscription[]): Promise<void>; /** * The app layer needs to refresh the status of some peers. The sync have reached a target */ reStatusPeers(peers: PeerIdStr[]): Promise<void>; searchUnknownSlotRoot(slotRoot: SlotRootHex, peer?: PeerIdStr): void; reportPeer(peer: PeerIdStr, action: PeerAction, actionName: string): Promise<void>; getConnectedPeers(): PeerIdStr[]; getConnectedPeerCount(): number; getNetworkIdentity(): Promise<routes.node.NetworkIdentity>; /** * Subscribe to all gossip events. Safe to call multiple times */ subscribeGossipCoreTopics(): Promise<void>; /** * Unsubscribe from all gossip events. Safe to call multiple times */ unsubscribeGossipCoreTopics(): Promise<void>; isSubscribedToGossipCoreTopics(): boolean; shouldAggregate(subnet: SubnetID, slot: number): boolean; publishBeaconBlock(signedBlock: SignedBeaconBlock): Promise<number>; publishBlobSidecar(blobSidecar: deneb.BlobSidecar): Promise<number>; publishBeaconAggregateAndProof(aggregateAndProof: SignedAggregateAndProof): Promise<number>; publishBeaconAttestation(attestation: SingleAttestation, subnet: SubnetID): Promise<number>; publishVoluntaryExit(voluntaryExit: phase0.SignedVoluntaryExit): Promise<number>; publishBlsToExecutionChange(blsToExecutionChange: capella.SignedBLSToExecutionChange): Promise<number>; publishProposerSlashing(proposerSlashing: phase0.ProposerSlashing): Promise<number>; publishAttesterSlashing(attesterSlashing: AttesterSlashing): Promise<number>; publishSyncCommitteeSignature(signature: altair.SyncCommitteeMessage, subnet: SubnetID): Promise<number>; publishContributionAndProof(contributionAndProof: altair.SignedContributionAndProof): Promise<number>; publishLightClientFinalityUpdate(update: LightClientFinalityUpdate): Promise<number>; publishLightClientOptimisticUpdate(update: LightClientOptimisticUpdate): Promise<number>; private publishGossip; sendBeaconBlocksByRange(peerId: PeerIdStr, request: phase0.BeaconBlocksByRangeRequest): Promise<WithBytes<SignedBeaconBlock>[]>; sendBeaconBlocksByRoot(peerId: PeerIdStr, request: phase0.BeaconBlocksByRootRequest): Promise<WithBytes<SignedBeaconBlock>[]>; sendLightClientBootstrap(peerId: PeerIdStr, request: Root): Promise<LightClientBootstrap>; sendLightClientOptimisticUpdate(peerId: PeerIdStr): Promise<LightClientOptimisticUpdate>; sendLightClientFinalityUpdate(peerId: PeerIdStr): Promise<LightClientFinalityUpdate>; sendLightClientUpdatesByRange(peerId: PeerIdStr, request: altair.LightClientUpdatesByRange): Promise<LightClientUpdate[]>; sendBlobSidecarsByRange(peerId: PeerIdStr, request: deneb.BlobSidecarsByRangeRequest): Promise<deneb.BlobSidecar[]>; sendBlobSidecarsByRoot(peerId: PeerIdStr, request: BlobSidecarsByRootRequest): Promise<deneb.BlobSidecar[]>; private sendReqRespRequest; connectToPeer(peer: string, multiaddr: string[]): Promise<void>; disconnectPeer(peer: string): Promise<void>; dumpPeer(peerIdStr: string): Promise<routes.lodestar.LodestarNodePeer | undefined>; dumpPeers(): Promise<routes.lodestar.LodestarNodePeer[]>; dumpPeerScoreStats(): Promise<PeerScoreStats>; dumpGossipPeerScoreStats(): Promise<PeerScoreStatsDump>; dumpDiscv5KadValues(): Promise<string[]>; dumpMeshPeers(): Promise<Record<string, string[]>>; dumpGossipQueue(gossipType: GossipType): Promise<PendingGossipsubMessage[]>; writeNetworkThreadProfile(durationMs: number, dirpath: string): Promise<string>; writeDiscv5Profile(durationMs: number, dirpath: string): Promise<string>; writeNetworkHeapSnapshot(prefix: string, dirpath: string): Promise<string>; writeDiscv5HeapSnapshot(prefix: string, dirpath: string): Promise<string>; private onLightClientFinalityUpdate; private onLightClientOptimisticUpdate; private waitOneThirdOfSlot; private onHead; private onPeerConnected; private onPeerDisconnected; } export {}; //# sourceMappingURL=network.d.ts.map