UNPKG

@lodestar/beacon-node

Version:

A Typescript implementation of the beacon chain

111 lines 4.26 kB
import { type PublishResult } from "@libp2p/gossipsub"; import type { PeerScoreParams, PeerScoreStatsDump } from "@libp2p/gossipsub/score"; import type { AddrInfo, PublishOpts, TopicStr } from "@libp2p/gossipsub/types"; import { routes } from "@lodestar/api"; import { Logger } from "@lodestar/utils"; import { RegistryMetricCreator } from "../../metrics/index.js"; import { NetworkEventBus } from "../events.js"; import { Libp2p } from "../interface.js"; import { NetworkConfig } from "../networkConfig.js"; import { PeersData } from "../peers/peersData.js"; import { GossipTopic } from "./interface.js"; export type Eth2Context = { activeValidatorCount: number; currentSlot: number; currentEpoch: number; }; export type Eth2GossipsubModules = { networkConfig: NetworkConfig; libp2p: Libp2p; logger: Logger; metricsRegister: RegistryMetricCreator | null; eth2Context: Eth2Context; peersData: PeersData; events: NetworkEventBus; }; export type Eth2GossipsubOpts = { allowPublishToZeroPeers?: boolean; gossipsubD?: number; gossipsubDLow?: number; gossipsubDHigh?: number; gossipsubAwaitHandler?: boolean; disableFloodPublish?: boolean; skipParamsLog?: boolean; disableLightClientServer?: boolean; /** * Direct peers for GossipSub - these peers maintain permanent mesh connections without GRAFT/PRUNE. * Supports multiaddr strings with peer ID (e.g., "/ip4/192.168.1.1/tcp/9000/p2p/16Uiu2HAmKLhW7...") * or ENR strings (e.g., "enr:-IS4QHCYrYZbAKWCBRlAy5zzaDZXJBGkcnh4MHcBFZntXNFrdvJjX04jRzjzCBOo...") */ directPeers?: string[]; }; export type ForkBoundaryLabel = string; /** * Wrapper around js-libp2p-gossipsub with the following extensions: * - Eth2 message id * - Emits `GossipObject`, not `InMessage` * - Provides convenience interface: * - `publishObject` * - `subscribeTopic` * - `unsubscribeTopic` * - `handleTopic` * - `unhandleTopic` * * See https://github.com/ethereum/consensus-specs/blob/v1.1.10/specs/phase0/p2p-interface.md#the-gossip-domain-gossipsub */ export declare class Eth2Gossipsub { readonly scoreParams: Partial<PeerScoreParams>; private readonly config; private readonly logger; private readonly peersData; private readonly events; private readonly libp2p; private readonly gossipsub; private readonly gossipTopicCache; constructor(opts: Eth2GossipsubOpts, modules: Eth2GossipsubModules); start(): Promise<void>; stop(): Promise<void>; get mesh(): Map<string, Set<string>>; getTopics(): TopicStr[]; getMeshPeers(topic: TopicStr): string[]; publish(topic: TopicStr, data: Uint8Array, opts?: PublishOpts): Promise<PublishResult>; dumpPeerScoreStats(): PeerScoreStatsDump; getScore(peerIdStr: string): number; /** * Subscribe to a `GossipTopic` */ subscribeTopic(topic: GossipTopic): void; /** * Unsubscribe to a `GossipTopic` */ unsubscribeTopic(topic: GossipTopic): void; private onScrapeLodestarMetrics; private onGossipsubMessage; private onValidationResult; /** * Add a peer as a direct peer at runtime. Accepts multiaddr with peer ID or ENR string. * Direct peers maintain permanent mesh connections without GRAFT/PRUNE negotiation. */ addDirectPeer(peerStr: routes.lodestar.DirectPeer): Promise<string | null>; /** * Remove a peer from direct peers. */ removeDirectPeer(peerIdStr: string): boolean; /** * Get list of current direct peer IDs. */ getDirectPeers(): string[]; } /** * Parse direct peer strings into AddrInfo objects for GossipSub. * Direct peers maintain permanent mesh connections without GRAFT/PRUNE negotiation. * * Supported formats: * - Multiaddr with peer ID: `/ip4/192.168.1.1/tcp/9000/p2p/16Uiu2HAmKLhW7...` * - ENR: `enr:-IS4QHCYrYZbAKWCBRlAy5zzaDZXJBGkcnh4MHcBFZntXNFrdvJjX04jRzjzCBOo...` * * For multiaddrs, the string must contain a /p2p/ component with the peer ID. * For ENRs, the TCP multiaddr and peer ID are extracted from the encoded record. */ export declare function parseDirectPeers(directPeerStrs: routes.lodestar.DirectPeer[], logger: Logger): AddrInfo[]; //# sourceMappingURL=gossipsub.d.ts.map