Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update gossipsub / libp2p #5029

Merged
merged 5 commits into from
Jan 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions packages/beacon-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,22 +95,23 @@
"@chainsafe/as-chacha20poly1305": "^0.1.0",
"@chainsafe/as-sha256": "^0.3.1",
"@chainsafe/bls": "7.1.1",
"@chainsafe/discv5": "^2.0.0",
"@chainsafe/libp2p-gossipsub": "^5.3.0",
"@chainsafe/libp2p-noise": "^10.2.0",
"@chainsafe/discv5": "^2.1.0",
"@chainsafe/libp2p-gossipsub": "^6.1.0",
"@chainsafe/libp2p-noise": "^11.0.0",
"@chainsafe/persistent-merkle-tree": "^0.4.2",
"@chainsafe/snappy-stream": "^5.1.2",
"@chainsafe/ssz": "^0.9.2",
"@chainsafe/threads": "^1.10.0",
"@ethersproject/abi": "^5.0.0",
"@libp2p/bootstrap": "^5.0.0",
"@libp2p/bootstrap": "^6.0.0",
"@libp2p/interface-connection": "^3.0.2",
"@libp2p/interface-connection-manager": "^1.3.0",
"@libp2p/interface-peer-id": "^1.0.5",
"@libp2p/interface-peer-id": "^2.0.1",
"@libp2p/interface-pubsub": "^3.0.0",
"@libp2p/mdns": "^5.1.0",
"@libp2p/interface-registrar": "^2.0.8",
"@libp2p/mdns": "^6.0.0",
"@libp2p/mplex": "^7.1.0",
"@libp2p/peer-id-factory": "^1.0.19",
"@libp2p/peer-id-factory": "^2.0.1",
"@libp2p/prometheus-metrics": "^1.1.2",
"@libp2p/tcp": "^6.0.4",
"@lodestar/api": "^1.3.0",
Expand Down Expand Up @@ -139,7 +140,7 @@
"it-all": "^2.0.0",
"it-pipe": "^2.0.5",
"jwt-simple": "0.5.6",
"libp2p": "0.41.0",
"libp2p": "0.42.2",
"prom-client": "^14.1.0",
"prometheus-gc-stats": "^0.6.3",
"snappyjs": "^0.7.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/beacon-node/src/network/gossip/gossipsub.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* eslint-disable @typescript-eslint/naming-convention */
import {Libp2p} from "libp2p";
import {GossipSub, GossipsubEvents} from "@chainsafe/libp2p-gossipsub";
import {SignaturePolicy, TopicStr} from "@chainsafe/libp2p-gossipsub/types";
import {PeerScore, PeerScoreParams} from "@chainsafe/libp2p-gossipsub/score";
Expand All @@ -15,6 +14,7 @@ import {Eth2Context} from "../../chain/index.js";
import {PeersData} from "../peers/peersData.js";
import {ClientKind} from "../peers/client.js";
import {GOSSIP_MAX_SIZE, GOSSIP_MAX_SIZE_BELLATRIX} from "../../constants/network.js";
import {Libp2p} from "../interface.js";
import {
GossipJobQueues,
GossipTopic,
Expand Down
5 changes: 5 additions & 0 deletions packages/beacon-node/src/network/interface.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import {Libp2p as ILibp2p} from "libp2p";
import {Connection} from "@libp2p/interface-connection";
import {Registrar} from "@libp2p/interface-registrar";
import {Multiaddr} from "@multiformats/multiaddr";
import {PeerId} from "@libp2p/interface-peer-id";
import {ConnectionManager} from "@libp2p/interface-connection-manager";
import {ENR} from "@chainsafe/discv5";
import {phase0} from "@lodestar/types";
import {BlockInput} from "../chain/blocks/types.js";
Expand Down Expand Up @@ -63,3 +66,5 @@ export interface INetwork {

export type PeerDirection = Connection["stat"]["direction"];
export type PeerStatus = Connection["stat"]["status"];

export type Libp2p = ILibp2p & {connectionManager: ConnectionManager; registrar: Registrar};
7 changes: 1 addition & 6 deletions packages/beacon-node/src/network/network.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import {Libp2p} from "libp2p";
import {DefaultConnectionManager} from "libp2p/connection-manager";
import {Connection} from "@libp2p/interface-connection";
import {PeerId} from "@libp2p/interface-peer-id";
import {Multiaddr} from "@multiformats/multiaddr";
Expand All @@ -14,7 +12,7 @@ import {IMetrics} from "../metrics/index.js";
import {ChainEvent, IBeaconChain, IBeaconClock} from "../chain/index.js";
import {BlockInput, BlockInputType, getBlockInput} from "../chain/blocks/types.js";
import {INetworkOptions} from "./options.js";
import {INetwork} from "./interface.js";
import {INetwork, Libp2p} from "./interface.js";
import {ReqRespBeaconNode, ReqRespHandlers, doBeaconBlocksMaybeBlobsByRange} from "./reqresp/index.js";
import {
Eth2Gossipsub,
Expand Down Expand Up @@ -147,9 +145,6 @@ export class Network implements INetwork {

async start(): Promise<void> {
await this.libp2p.start();
// Stop latency monitor since we handle disconnects here and don't want additional load on the event loop
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
((this.libp2p.connectionManager as unknown) as DefaultConnectionManager)["latencyMonitor"].stop();

// Network spec decides version changes based on clock fork, not head fork
const forkCurrentSlot = this.config.getForkName(this.clock.currentSlot);
Expand Down
7 changes: 4 additions & 3 deletions packages/beacon-node/src/network/nodejs/bundle.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {createLibp2p, Libp2p} from "libp2p";
import {createLibp2p} from "libp2p";
import {tcp} from "@libp2p/tcp";
import {mplex} from "@libp2p/mplex";
import {bootstrap} from "@libp2p/bootstrap";
Expand All @@ -9,6 +9,7 @@ import type {PeerDiscovery} from "@libp2p/interface-peer-discovery";
import type {Components} from "libp2p/components";
import {prometheusMetrics} from "@libp2p/prometheus-metrics";
import {Registry} from "prom-client";
import {Libp2p} from "../interface.js";
import {createNoise} from "./noise.js";

export interface ILibp2pOptions {
Expand Down Expand Up @@ -40,7 +41,7 @@ export async function createNodejsLibp2p(options: ILibp2pOptions): Promise<Libp2
peerDiscovery.push(mdns());
}
}
return await createLibp2p({
return (await createLibp2p({
peerId: options.peerId,
addresses: {
listen: options.addresses.listen,
Expand Down Expand Up @@ -104,5 +105,5 @@ export async function createNodejsLibp2p(options: ILibp2pOptions): Promise<Libp2
agentVersion: options.lodestarVersion ? `lodestar/${options.lodestarVersion}` : "lodestar",
},
},
});
})) as Libp2p;
}
2 changes: 1 addition & 1 deletion packages/beacon-node/src/network/nodejs/util.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {PeerId} from "@libp2p/interface-peer-id";
import {Libp2p} from "libp2p";
import {Registry} from "prom-client";
import {ENR} from "@chainsafe/discv5";
import {Libp2p} from "../interface.js";
import {Eth2PeerDataStore} from "../peers/datastore.js";
import {defaultDiscv5Options, defaultNetworkOptions, INetworkOptions} from "../options.js";
import {isLocalMultiAddr, clearMultiaddrUDP} from "../util.js";
Expand Down
2 changes: 1 addition & 1 deletion packages/beacon-node/src/network/peers/discover.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import {Libp2p} from "libp2p";
import {PeerId} from "@libp2p/interface-peer-id";
import {Multiaddr} from "@multiformats/multiaddr";
import {PeerInfo} from "@libp2p/interface-peer-info";
Expand All @@ -7,6 +6,7 @@ import {ILogger, pruneSetToMax, sleep} from "@lodestar/utils";
import {ENR, IDiscv5DiscoveryInputOptions} from "@chainsafe/discv5";
import {ATTESTATION_SUBNET_COUNT, SYNC_COMMITTEE_SUBNET_COUNT} from "@lodestar/params";
import {IMetrics} from "../../metrics/index.js";
import {Libp2p} from "../interface.js";
import {ENRKey, SubnetType} from "../metadata.js";
import {getConnectionsMap, getDefaultDialer, prettyPrintPeerId} from "../util.js";
import {Discv5Worker} from "../discv5/index.js";
Expand Down
2 changes: 1 addition & 1 deletion packages/beacon-node/src/network/peers/peerManager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import {Libp2p} from "libp2p";
import {Connection} from "@libp2p/interface-connection";
import {PeerId} from "@libp2p/interface-peer-id";
import {IDiscv5DiscoveryInputOptions} from "@chainsafe/discv5";
Expand All @@ -11,6 +10,7 @@ import {IBeaconChain} from "../../chain/index.js";
import {GoodByeReasonCode, GOODBYE_KNOWN_CODES, Libp2pEvent} from "../../constants/index.js";
import {IMetrics} from "../../metrics/index.js";
import {NetworkEvent, INetworkEventBus} from "../events.js";
import {Libp2p} from "../interface.js";
import {IReqRespBeaconNode, ReqRespMethod, RequestTypedContainer} from "../reqresp/ReqRespBeaconNode.js";
import {getConnection, getConnectionsMap, prettyPrintPeerId} from "../util.js";
import {ISubnetsService} from "../subnets/index.js";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {Libp2p} from "libp2p";
import {Connection} from "@libp2p/interface-connection";
import {PeerId} from "@libp2p/interface-peer-id";
import type {ConnectionManager} from "@libp2p/interface-connection-manager";
import {Libp2p} from "../../interface.js";
import {getConnectionsMap} from "../../util.js";

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/beacon-node/src/network/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import type {ConnectionManager} from "@libp2p/interface-connection-manager";
import type {Components} from "libp2p/components.js";
import type {DefaultConnectionManager} from "libp2p/connection-manager/index.js";
import type {DefaultDialer} from "libp2p/connection-manager/dialer/index.js";
import type {Libp2p} from "libp2p";
import type {ENR} from "@chainsafe/discv5";
import type {Libp2p} from "./interface.js";

/* eslint-disable @typescript-eslint/no-explicit-any */

Expand Down
3 changes: 1 addition & 2 deletions packages/beacon-node/src/node/nodejs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {setMaxListeners} from "node:events";
import {Libp2p} from "libp2p";
import {Registry} from "prom-client";

import {IBeaconConfig} from "@lodestar/config";
Expand All @@ -10,7 +9,7 @@ import {BeaconStateAllForks} from "@lodestar/state-transition";
import {ProcessShutdownCallback} from "@lodestar/validator";

import {IBeaconDb} from "../db/index.js";
import {INetwork, Network, getReqRespHandlers} from "../network/index.js";
import {Libp2p, INetwork, Network, getReqRespHandlers} from "../network/index.js";
import {BeaconSync, IBeaconSync} from "../sync/index.js";
import {BackfillSync} from "../sync/backfill/index.js";
import {BeaconChain, IBeaconChain, initBeaconMetrics} from "../chain/index.js";
Expand Down
2 changes: 1 addition & 1 deletion packages/beacon-node/test/utils/network.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {PeerId} from "@libp2p/interface-peer-id";
import {Multiaddr} from "@multiformats/multiaddr";
import {Libp2p} from "libp2p";
import {createSecp256k1PeerId} from "@libp2p/peer-id-factory";
import {ATTESTATION_SUBNET_COUNT, SYNC_COMMITTEE_SUBNET_COUNT} from "@lodestar/params";
import {BitArray} from "@chainsafe/ssz";
import {INetwork, Network} from "../../src/network/index.js";
import {createNodejsLibp2p, ILibp2pOptions} from "../../src/network/nodejs/index.js";
import {Libp2p} from "../../src/network/interface.js";
import {Libp2pEvent} from "../../src/constants/index.js";

export async function createNode(
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@
"@chainsafe/bls-keygen": "^0.3.0",
"@chainsafe/bls-keystore": "^2.0.0",
"@chainsafe/blst": "^0.2.8",
"@chainsafe/discv5": "^2.0.0",
"@chainsafe/discv5": "^2.1.0",
"@chainsafe/ssz": "^0.9.2",
"@libp2p/peer-id-factory": "^1.0.19",
"@libp2p/peer-id-factory": "^2.0.1",
"@lodestar/api": "^1.3.0",
"@lodestar/beacon-node": "^1.3.0",
"@lodestar/config": "^1.3.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/reqresp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"dependencies": {
"@chainsafe/snappy-stream": "^5.1.2",
"@libp2p/interface-connection": "^3.0.2",
"@libp2p/interface-peer-id": "^1.0.4",
"@libp2p/interface-peer-id": "^2.0.1",
"@lodestar/config": "^1.3.0",
"@lodestar/params": "^1.3.0",
"@lodestar/types": "^1.3.0",
Expand Down
Loading