@lodestar/beacon-node 1.41.0-dev.95cf2edc4c → 1.41.0-dev.96f78af84b
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/api/impl/node/utils.d.ts +1 -1
- package/lib/api/impl/node/utils.d.ts.map +1 -1
- package/lib/api/impl/node/utils.js.map +1 -1
- package/lib/constants/network.d.ts +2 -1
- package/lib/constants/network.d.ts.map +1 -1
- package/lib/constants/network.js +1 -0
- package/lib/constants/network.js.map +1 -1
- package/lib/db/repositories/blockArchive.d.ts.map +1 -1
- package/lib/db/repositories/blockArchive.js +1 -2
- package/lib/db/repositories/blockArchive.js.map +1 -1
- package/lib/execution/engine/http.d.ts +1 -0
- package/lib/execution/engine/http.d.ts.map +1 -1
- package/lib/execution/engine/http.js +3 -0
- package/lib/execution/engine/http.js.map +1 -1
- package/lib/metrics/metrics/lodestar.d.ts +3 -0
- package/lib/metrics/metrics/lodestar.d.ts.map +1 -1
- package/lib/metrics/metrics/lodestar.js +5 -0
- package/lib/metrics/metrics/lodestar.js.map +1 -1
- package/lib/network/core/networkCore.d.ts +3 -3
- package/lib/network/core/networkCore.d.ts.map +1 -1
- package/lib/network/core/networkCore.js.map +1 -1
- package/lib/network/core/networkCoreWorkerHandler.d.ts +3 -3
- package/lib/network/core/networkCoreWorkerHandler.d.ts.map +1 -1
- package/lib/network/core/types.d.ts +2 -2
- package/lib/network/core/types.d.ts.map +1 -1
- package/lib/network/events.d.ts +2 -1
- package/lib/network/events.d.ts.map +1 -1
- package/lib/network/events.js.map +1 -1
- package/lib/network/gossip/encoding.d.ts +3 -3
- package/lib/network/gossip/encoding.d.ts.map +1 -1
- package/lib/network/gossip/encoding.js.map +1 -1
- package/lib/network/gossip/gossipsub.d.ts +13 -4
- package/lib/network/gossip/gossipsub.d.ts.map +1 -1
- package/lib/network/gossip/gossipsub.js +47 -20
- package/lib/network/gossip/gossipsub.js.map +1 -1
- package/lib/network/gossip/interface.d.ts +3 -3
- package/lib/network/gossip/interface.d.ts.map +1 -1
- package/lib/network/gossip/scoringParameters.d.ts +1 -1
- package/lib/network/gossip/scoringParameters.d.ts.map +1 -1
- package/lib/network/gossip/scoringParameters.js +1 -1
- package/lib/network/gossip/scoringParameters.js.map +1 -1
- package/lib/network/interface.d.ts +3 -3
- package/lib/network/interface.d.ts.map +1 -1
- package/lib/network/libp2p/index.d.ts +1 -1
- package/lib/network/libp2p/index.d.ts.map +1 -1
- package/lib/network/libp2p/index.js +7 -2
- package/lib/network/libp2p/index.js.map +1 -1
- package/lib/network/network.d.ts +2 -2
- package/lib/network/network.d.ts.map +1 -1
- package/lib/network/network.js.map +1 -1
- package/lib/network/options.d.ts.map +1 -1
- package/lib/network/options.js +3 -0
- package/lib/network/options.js.map +1 -1
- package/lib/network/peers/datastore.d.ts +7 -5
- package/lib/network/peers/datastore.d.ts.map +1 -1
- package/lib/network/peers/datastore.js +10 -10
- package/lib/network/peers/datastore.js.map +1 -1
- package/lib/network/peers/peerManager.d.ts +11 -0
- package/lib/network/peers/peerManager.d.ts.map +1 -1
- package/lib/network/peers/peerManager.js +148 -53
- package/lib/network/peers/peerManager.js.map +1 -1
- package/lib/network/peers/utils/prioritizePeers.d.ts +3 -3
- package/lib/network/peers/utils/prioritizePeers.d.ts.map +1 -1
- package/lib/network/processor/gossipValidatorFn.js +1 -1
- package/lib/network/processor/types.d.ts +1 -1
- package/lib/network/processor/types.d.ts.map +1 -1
- package/lib/network/reqresp/score.d.ts.map +1 -1
- package/lib/network/reqresp/score.js +0 -1
- package/lib/network/reqresp/score.js.map +1 -1
- package/lib/network/util.js +2 -2
- package/lib/network/util.js.map +1 -1
- package/package.json +38 -41
- package/src/api/impl/node/utils.ts +3 -3
- package/src/constants/network.ts +1 -0
- package/src/db/repositories/blockArchive.ts +1 -2
- package/src/execution/engine/http.ts +3 -0
- package/src/metrics/metrics/lodestar.ts +5 -0
- package/src/network/core/networkCore.ts +3 -3
- package/src/network/core/networkCoreWorkerHandler.ts +3 -3
- package/src/network/core/types.ts +2 -2
- package/src/network/events.ts +2 -1
- package/src/network/gossip/encoding.ts +3 -3
- package/src/network/gossip/gossipsub.ts +86 -25
- package/src/network/gossip/interface.ts +3 -3
- package/src/network/gossip/scoringParameters.ts +4 -4
- package/src/network/interface.ts +3 -3
- package/src/network/libp2p/index.ts +8 -3
- package/src/network/network.ts +3 -3
- package/src/network/options.ts +3 -0
- package/src/network/peers/datastore.ts +13 -10
- package/src/network/peers/peerManager.ts +175 -54
- package/src/network/peers/utils/prioritizePeers.ts +3 -3
- package/src/network/processor/gossipValidatorFn.ts +1 -1
- package/src/network/processor/types.ts +1 -1
- package/src/network/reqresp/score.ts +0 -1
- package/src/network/util.ts +2 -2
- package/src/util/workerEvents.ts +1 -1
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"bugs": {
|
|
12
12
|
"url": "https://github.com/ChainSafe/lodestar/issues"
|
|
13
13
|
},
|
|
14
|
-
"version": "1.41.0-dev.
|
|
14
|
+
"version": "1.41.0-dev.96f78af84b",
|
|
15
15
|
"type": "module",
|
|
16
16
|
"exports": {
|
|
17
17
|
".": {
|
|
@@ -110,10 +110,9 @@
|
|
|
110
110
|
"dependencies": {
|
|
111
111
|
"@chainsafe/as-sha256": "^1.2.0",
|
|
112
112
|
"@chainsafe/blst": "^2.2.0",
|
|
113
|
-
"@chainsafe/discv5": "^
|
|
114
|
-
"@chainsafe/enr": "^
|
|
115
|
-
"@chainsafe/libp2p-
|
|
116
|
-
"@chainsafe/libp2p-noise": "^16.1.5",
|
|
113
|
+
"@chainsafe/discv5": "^12.0.0",
|
|
114
|
+
"@chainsafe/enr": "^6.0.0",
|
|
115
|
+
"@chainsafe/libp2p-noise": "^17.0.0",
|
|
117
116
|
"@chainsafe/persistent-merkle-tree": "^1.2.1",
|
|
118
117
|
"@chainsafe/prometheus-gc-stats": "^1.0.0",
|
|
119
118
|
"@chainsafe/pubkey-index-map": "^3.0.0",
|
|
@@ -125,39 +124,38 @@
|
|
|
125
124
|
"@fastify/cors": "^10.0.1",
|
|
126
125
|
"@fastify/swagger": "^9.0.0",
|
|
127
126
|
"@fastify/swagger-ui": "^5.0.1",
|
|
128
|
-
"@libp2p/bootstrap": "^
|
|
129
|
-
"@libp2p/crypto": "^5.
|
|
130
|
-
"@libp2p/
|
|
131
|
-
"@libp2p/
|
|
132
|
-
"@libp2p/
|
|
133
|
-
"@libp2p/
|
|
134
|
-
"@libp2p/
|
|
135
|
-
"@libp2p/
|
|
136
|
-
"@libp2p/
|
|
137
|
-
"@
|
|
138
|
-
"@lodestar/
|
|
139
|
-
"@lodestar/
|
|
140
|
-
"@lodestar/
|
|
141
|
-
"@lodestar/
|
|
142
|
-
"@lodestar/
|
|
143
|
-
"@lodestar/
|
|
144
|
-
"@lodestar/
|
|
145
|
-
"@lodestar/
|
|
146
|
-
"@lodestar/
|
|
147
|
-
"@lodestar/
|
|
148
|
-
"@lodestar/
|
|
149
|
-
"@
|
|
150
|
-
"
|
|
151
|
-
"datastore-
|
|
152
|
-
"datastore-
|
|
127
|
+
"@libp2p/bootstrap": "^12.0.11",
|
|
128
|
+
"@libp2p/crypto": "^5.1.13",
|
|
129
|
+
"@libp2p/gossipsub": "^15.0.12",
|
|
130
|
+
"@libp2p/identify": "^4.0.10",
|
|
131
|
+
"@libp2p/interface": "^3.1.0",
|
|
132
|
+
"@libp2p/mdns": "^12.0.11",
|
|
133
|
+
"@libp2p/mplex": "^12.0.11",
|
|
134
|
+
"@libp2p/peer-id": "^6.0.4",
|
|
135
|
+
"@libp2p/prometheus-metrics": "^5.0.10",
|
|
136
|
+
"@libp2p/tcp": "^11.0.10",
|
|
137
|
+
"@lodestar/api": "^1.41.0-dev.96f78af84b",
|
|
138
|
+
"@lodestar/config": "^1.41.0-dev.96f78af84b",
|
|
139
|
+
"@lodestar/db": "^1.41.0-dev.96f78af84b",
|
|
140
|
+
"@lodestar/fork-choice": "^1.41.0-dev.96f78af84b",
|
|
141
|
+
"@lodestar/light-client": "^1.41.0-dev.96f78af84b",
|
|
142
|
+
"@lodestar/logger": "^1.41.0-dev.96f78af84b",
|
|
143
|
+
"@lodestar/params": "^1.41.0-dev.96f78af84b",
|
|
144
|
+
"@lodestar/reqresp": "^1.41.0-dev.96f78af84b",
|
|
145
|
+
"@lodestar/state-transition": "^1.41.0-dev.96f78af84b",
|
|
146
|
+
"@lodestar/types": "^1.41.0-dev.96f78af84b",
|
|
147
|
+
"@lodestar/utils": "^1.41.0-dev.96f78af84b",
|
|
148
|
+
"@lodestar/validator": "^1.41.0-dev.96f78af84b",
|
|
149
|
+
"@multiformats/multiaddr": "^13.0.1",
|
|
150
|
+
"datastore-core": "^11.0.2",
|
|
151
|
+
"datastore-fs": "^11.0.2",
|
|
152
|
+
"datastore-level": "^12.0.2",
|
|
153
153
|
"deepmerge": "^4.3.1",
|
|
154
154
|
"fastify": "^5.7.4",
|
|
155
|
-
"interface-datastore": "^
|
|
156
|
-
"it-all": "^3.0.4",
|
|
157
|
-
"it-pipe": "^3.0.1",
|
|
155
|
+
"interface-datastore": "^9.0.2",
|
|
158
156
|
"jwt-simple": "0.5.6",
|
|
159
|
-
"libp2p": "
|
|
160
|
-
"multiformats": "^
|
|
157
|
+
"libp2p": "3.1.3",
|
|
158
|
+
"multiformats": "^13.4.2",
|
|
161
159
|
"prom-client": "^15.1.0",
|
|
162
160
|
"qs": "^6.11.1",
|
|
163
161
|
"strict-event-emitter-types": "^2.0.0",
|
|
@@ -167,14 +165,13 @@
|
|
|
167
165
|
},
|
|
168
166
|
"devDependencies": {
|
|
169
167
|
"@chainsafe/swap-or-not-shuffle": "^1.2.1",
|
|
170
|
-
"@libp2p/interface-internal": "^
|
|
171
|
-
"@libp2p/logger": "^
|
|
172
|
-
"@
|
|
168
|
+
"@libp2p/interface-internal": "^3.0.10",
|
|
169
|
+
"@libp2p/logger": "^6.2.2",
|
|
170
|
+
"@libp2p/utils": "^7.0.10",
|
|
171
|
+
"@lodestar/spec-test-util": "^1.41.0-dev.96f78af84b",
|
|
173
172
|
"@types/js-yaml": "^4.0.5",
|
|
174
173
|
"@types/qs": "^6.9.7",
|
|
175
174
|
"@types/tmp": "^0.2.3",
|
|
176
|
-
"it-drain": "^3.0.3",
|
|
177
|
-
"it-pair": "^2.0.6",
|
|
178
175
|
"js-yaml": "^4.1.0",
|
|
179
176
|
"rewiremock": "^3.14.5",
|
|
180
177
|
"rimraf": "^4.4.1",
|
|
@@ -188,5 +185,5 @@
|
|
|
188
185
|
"beacon",
|
|
189
186
|
"blockchain"
|
|
190
187
|
],
|
|
191
|
-
"gitHead": "
|
|
188
|
+
"gitHead": "dcfa128a0a200089e3202b92999624bfb8a7fa41"
|
|
192
189
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {Connection,
|
|
1
|
+
import type {Connection, ConnectionStatus} from "@libp2p/interface";
|
|
2
2
|
import {routes} from "@lodestar/api";
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -24,7 +24,7 @@ export function formatNodePeer(peerIdStr: string, connections: Connection[]): ro
|
|
|
24
24
|
* - Otherwise, the first closed connection
|
|
25
25
|
*/
|
|
26
26
|
export function getRelevantConnection(connections: Connection[]): Connection | null {
|
|
27
|
-
const byStatus = new Map<
|
|
27
|
+
const byStatus = new Map<ConnectionStatus, Connection>();
|
|
28
28
|
for (const conn of connections) {
|
|
29
29
|
if (conn.status === "open") return conn;
|
|
30
30
|
if (!byStatus.has(conn.status)) byStatus.set(conn.status, conn);
|
|
@@ -37,7 +37,7 @@ export function getRelevantConnection(connections: Connection[]): Connection | n
|
|
|
37
37
|
* Map libp2p connection status to the API's peer state notation
|
|
38
38
|
* @param status
|
|
39
39
|
*/
|
|
40
|
-
function getPeerState(status:
|
|
40
|
+
function getPeerState(status: ConnectionStatus): routes.node.PeerState {
|
|
41
41
|
switch (status) {
|
|
42
42
|
case "open":
|
|
43
43
|
return "connected";
|
package/src/constants/network.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import all from "it-all";
|
|
2
1
|
import {ChainForkConfig} from "@lodestar/config";
|
|
3
2
|
import {Db, FilterOptions, KeyValue, Repository} from "@lodestar/db";
|
|
4
3
|
import {Root, SignedBeaconBlock, Slot, ssz} from "@lodestar/types";
|
|
@@ -121,7 +120,7 @@ export class BlockArchiveRepository extends Repository<Slot, SignedBeaconBlock>
|
|
|
121
120
|
}
|
|
122
121
|
|
|
123
122
|
async values(opts?: BlockFilterOptions): Promise<SignedBeaconBlock[]> {
|
|
124
|
-
return
|
|
123
|
+
return await Array.fromAsync(this.valuesStream(opts));
|
|
125
124
|
}
|
|
126
125
|
|
|
127
126
|
// INDEX
|
|
@@ -128,6 +128,7 @@ const getClientVersionOpts: ReqOpts = {routeId: "getClientVersion"};
|
|
|
128
128
|
*/
|
|
129
129
|
export class ExecutionEngineHttp implements IExecutionEngine {
|
|
130
130
|
private logger: Logger;
|
|
131
|
+
private metrics: Metrics | null;
|
|
131
132
|
|
|
132
133
|
// The default state is ONLINE, it will be updated to SYNCING once we receive the first payload
|
|
133
134
|
// This assumption is better than the OFFLINE state, since we can't be sure if the EL is offline and being offline may trigger some notifications
|
|
@@ -167,6 +168,7 @@ export class ExecutionEngineHttp implements IExecutionEngine {
|
|
|
167
168
|
metrics?.engineHttpProcessorQueue
|
|
168
169
|
);
|
|
169
170
|
this.logger = logger;
|
|
171
|
+
this.metrics = metrics ?? null;
|
|
170
172
|
|
|
171
173
|
this.rpc.emitter.on(JsonRpcHttpClientEvent.ERROR, ({error}) => {
|
|
172
174
|
this.updateEngineState(getExecutionEngineState({payloadError: error, oldState: this.state}));
|
|
@@ -369,6 +371,7 @@ export class ExecutionEngineHttp implements IExecutionEngine {
|
|
|
369
371
|
} = await request;
|
|
370
372
|
|
|
371
373
|
this.updateEngineState(getExecutionEngineState({payloadStatus: status, oldState: this.state}));
|
|
374
|
+
this.metrics?.engineNotifyForkchoiceUpdateResult.inc({result: status});
|
|
372
375
|
|
|
373
376
|
switch (status) {
|
|
374
377
|
case ExecutionPayloadStatus.VALID:
|
|
@@ -928,6 +928,11 @@ export function createLodestarMetrics(
|
|
|
928
928
|
help: "The total result of calling notifyNewPayload execution engine api",
|
|
929
929
|
labelNames: ["result"],
|
|
930
930
|
}),
|
|
931
|
+
engineNotifyForkchoiceUpdateResult: register.gauge<{result: ExecutionPayloadStatus}>({
|
|
932
|
+
name: "lodestar_execution_engine_notify_forkchoice_update_result_total",
|
|
933
|
+
help: "The total result of calling notifyForkchoiceUpdate execution engine api",
|
|
934
|
+
labelNames: ["result"],
|
|
935
|
+
}),
|
|
931
936
|
backfillSync: {
|
|
932
937
|
backfilledTillSlot: register.gauge({
|
|
933
938
|
name: "lodestar_backfill_till_slot",
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {PeerScoreStatsDump} from "@libp2p/gossipsub/score";
|
|
2
|
+
import type {PublishOpts} from "@libp2p/gossipsub/types";
|
|
3
|
+
import type {Connection, PrivateKey} from "@libp2p/interface";
|
|
2
4
|
import {peerIdFromPrivateKey} from "@libp2p/peer-id";
|
|
3
5
|
import {multiaddr} from "@multiformats/multiaddr";
|
|
4
|
-
import {PeerScoreStatsDump} from "@chainsafe/libp2p-gossipsub/score";
|
|
5
|
-
import {PublishOpts} from "@chainsafe/libp2p-gossipsub/types";
|
|
6
6
|
import {routes} from "@lodestar/api";
|
|
7
7
|
import {BeaconConfig, ForkBoundary} from "@lodestar/config";
|
|
8
8
|
import type {LoggerNode} from "@lodestar/logger/node";
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
import workerThreads from "node:worker_threads";
|
|
3
3
|
import {privateKeyToProtobuf} from "@libp2p/crypto/keys";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
4
|
+
import type {PeerScoreStatsDump} from "@libp2p/gossipsub/score";
|
|
5
|
+
import type {PublishOpts} from "@libp2p/gossipsub/types";
|
|
6
|
+
import type {PrivateKey} from "@libp2p/interface";
|
|
7
7
|
import {ModuleThread, Thread, Worker, spawn} from "@chainsafe/threads";
|
|
8
8
|
import {routes} from "@lodestar/api";
|
|
9
9
|
import {BeaconConfig, chainConfigToJson} from "@lodestar/config";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {PeerScoreStatsDump} from "@
|
|
2
|
-
import {PublishOpts} from "@
|
|
1
|
+
import type {PeerScoreStatsDump} from "@libp2p/gossipsub/score";
|
|
2
|
+
import type {PublishOpts} from "@libp2p/gossipsub/types";
|
|
3
3
|
import {routes} from "@lodestar/api";
|
|
4
4
|
import {SpecJson} from "@lodestar/config";
|
|
5
5
|
import {LoggerNodeOpts} from "@lodestar/logger/node";
|
package/src/network/events.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {EventEmitter} from "node:events";
|
|
2
|
-
import {
|
|
2
|
+
import type {TopicValidatorResult} from "@libp2p/gossipsub";
|
|
3
|
+
import type {PeerId} from "@libp2p/interface";
|
|
3
4
|
import {CustodyIndex, Status} from "@lodestar/types";
|
|
4
5
|
import {PeerIdStr} from "../util/peerId.js";
|
|
5
6
|
import {StrictEventEmitterSingleArg} from "../util/strictEvents.js";
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {Message} from "@libp2p/
|
|
1
|
+
import type {Message} from "@libp2p/gossipsub";
|
|
2
|
+
import type {RPC} from "@libp2p/gossipsub/message";
|
|
3
|
+
import type {DataTransform} from "@libp2p/gossipsub/types";
|
|
2
4
|
// snappyjs is better for compression for smaller payloads
|
|
3
5
|
import xxhashFactory from "xxhash-wasm";
|
|
4
6
|
import {digest} from "@chainsafe/as-sha256";
|
|
5
|
-
import {RPC} from "@chainsafe/libp2p-gossipsub/message";
|
|
6
|
-
import {DataTransform} from "@chainsafe/libp2p-gossipsub/types";
|
|
7
7
|
import snappyWasm from "@chainsafe/snappy-wasm";
|
|
8
8
|
import {ForkName} from "@lodestar/params";
|
|
9
9
|
import {intToBytes} from "@lodestar/utils";
|
|
@@ -1,10 +1,18 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type GossipSub,
|
|
3
|
+
type GossipSubEvents,
|
|
4
|
+
type PublishResult,
|
|
5
|
+
StrictNoSign,
|
|
6
|
+
type TopicValidatorResult,
|
|
7
|
+
gossipsub,
|
|
8
|
+
} from "@libp2p/gossipsub";
|
|
9
|
+
import type {MetricsRegister, TopicLabel, TopicStrToLabel} from "@libp2p/gossipsub/metrics";
|
|
10
|
+
import type {PeerScoreParams, PeerScoreStatsDump} from "@libp2p/gossipsub/score";
|
|
11
|
+
import type {AddrInfo, PublishOpts, TopicStr} from "@libp2p/gossipsub/types";
|
|
12
|
+
import type {PeerId} from "@libp2p/interface";
|
|
1
13
|
import {peerIdFromString} from "@libp2p/peer-id";
|
|
2
14
|
import {multiaddr} from "@multiformats/multiaddr";
|
|
3
15
|
import {ENR} from "@chainsafe/enr";
|
|
4
|
-
import {GossipSub, GossipsubEvents} from "@chainsafe/libp2p-gossipsub";
|
|
5
|
-
import {MetricsRegister, TopicLabel, TopicStrToLabel} from "@chainsafe/libp2p-gossipsub/metrics";
|
|
6
|
-
import {PeerScoreParams} from "@chainsafe/libp2p-gossipsub/score";
|
|
7
|
-
import {AddrInfo, SignaturePolicy, TopicStr} from "@chainsafe/libp2p-gossipsub/types";
|
|
8
16
|
import {routes} from "@lodestar/api";
|
|
9
17
|
import {BeaconConfig, ForkBoundary} from "@lodestar/config";
|
|
10
18
|
import {ATTESTATION_SUBNET_COUNT, SLOTS_PER_EPOCH, SYNC_COMMITTEE_SUBNET_COUNT} from "@lodestar/params";
|
|
@@ -69,6 +77,24 @@ export type Eth2GossipsubOpts = {
|
|
|
69
77
|
|
|
70
78
|
export type ForkBoundaryLabel = string;
|
|
71
79
|
|
|
80
|
+
// Many of the internal properties we need are not available on the public interface,
|
|
81
|
+
// so we create an extended type here to avoid excessive type assertions throughout the codebase.
|
|
82
|
+
// Mind that any updates to the gossipsub package may require updates to this type.
|
|
83
|
+
type GossipSubInternal = GossipSub & {
|
|
84
|
+
mesh: Map<string, Set<string>>;
|
|
85
|
+
peers: Map<string, PeerId>;
|
|
86
|
+
score: {score: (peerIdStr: string) => number};
|
|
87
|
+
direct: Set<string>;
|
|
88
|
+
topics: Map<string, Set<string>>;
|
|
89
|
+
start: () => Promise<void>;
|
|
90
|
+
stop: () => Promise<void>;
|
|
91
|
+
publish: (topic: TopicStr, data: Uint8Array, opts?: PublishOpts) => Promise<PublishResult>;
|
|
92
|
+
getMeshPeers: (topic: TopicStr) => string[];
|
|
93
|
+
dumpPeerScoreStats: () => PeerScoreStatsDump;
|
|
94
|
+
getScore: (peerIdStr: string) => number;
|
|
95
|
+
reportMessageValidationResult: (msgId: string, propagationSource: string, acceptance: TopicValidatorResult) => void;
|
|
96
|
+
};
|
|
97
|
+
|
|
72
98
|
/**
|
|
73
99
|
* Wrapper around js-libp2p-gossipsub with the following extensions:
|
|
74
100
|
* - Eth2 message id
|
|
@@ -82,13 +108,14 @@ export type ForkBoundaryLabel = string;
|
|
|
82
108
|
*
|
|
83
109
|
* See https://github.com/ethereum/consensus-specs/blob/v1.1.10/specs/phase0/p2p-interface.md#the-gossip-domain-gossipsub
|
|
84
110
|
*/
|
|
85
|
-
export class Eth2Gossipsub
|
|
111
|
+
export class Eth2Gossipsub {
|
|
86
112
|
readonly scoreParams: Partial<PeerScoreParams>;
|
|
87
113
|
private readonly config: BeaconConfig;
|
|
88
114
|
private readonly logger: Logger;
|
|
89
115
|
private readonly peersData: PeersData;
|
|
90
116
|
private readonly events: NetworkEventBus;
|
|
91
117
|
private readonly libp2p: Libp2p;
|
|
118
|
+
private readonly gossipsub: GossipSubInternal;
|
|
92
119
|
|
|
93
120
|
// Internal caches
|
|
94
121
|
private readonly gossipTopicCache: GossipTopicCache;
|
|
@@ -103,9 +130,6 @@ export class Eth2Gossipsub extends GossipSub {
|
|
|
103
130
|
let metrics: Eth2GossipsubMetrics | null = null;
|
|
104
131
|
if (metricsRegister) {
|
|
105
132
|
metrics = createEth2GossipsubMetrics(metricsRegister);
|
|
106
|
-
metrics.gossipMesh.peersByType.addCollect(() =>
|
|
107
|
-
this.onScrapeLodestarMetrics(metrics as Eth2GossipsubMetrics, networkConfig)
|
|
108
|
-
);
|
|
109
133
|
}
|
|
110
134
|
|
|
111
135
|
// Parse direct peers from multiaddr strings to AddrInfo objects
|
|
@@ -113,8 +137,8 @@ export class Eth2Gossipsub extends GossipSub {
|
|
|
113
137
|
|
|
114
138
|
// Gossipsub parameters defined here:
|
|
115
139
|
// https://github.com/ethereum/consensus-specs/blob/v1.1.10/specs/phase0/p2p-interface.md#the-gossip-domain-gossipsub
|
|
116
|
-
|
|
117
|
-
globalSignaturePolicy:
|
|
140
|
+
const gossipsubInstance = gossipsub({
|
|
141
|
+
globalSignaturePolicy: StrictNoSign,
|
|
118
142
|
allowPublishToZeroTopicPeers: allowPublishToZeroPeers,
|
|
119
143
|
D: gossipsubD ?? GOSSIP_D,
|
|
120
144
|
Dlo: gossipsubDLow ?? GOSSIP_D_LOW,
|
|
@@ -155,7 +179,12 @@ export class Eth2Gossipsub extends GossipSub {
|
|
|
155
179
|
// This should be large enough to not send IDONTWANT for "small" messages
|
|
156
180
|
// See https://github.com/ChainSafe/lodestar/pull/7077#issuecomment-2383679472
|
|
157
181
|
idontwantMinDataSize: 16829,
|
|
158
|
-
});
|
|
182
|
+
})(modules.libp2p.services.components) as GossipSubInternal;
|
|
183
|
+
|
|
184
|
+
if (metrics) {
|
|
185
|
+
metrics.gossipMesh.peersByType.addCollect(() => this.onScrapeLodestarMetrics(metrics, networkConfig));
|
|
186
|
+
}
|
|
187
|
+
this.gossipsub = gossipsubInstance;
|
|
159
188
|
this.scoreParams = scoreParams;
|
|
160
189
|
this.config = config;
|
|
161
190
|
this.logger = logger;
|
|
@@ -164,7 +193,7 @@ export class Eth2Gossipsub extends GossipSub {
|
|
|
164
193
|
this.libp2p = modules.libp2p;
|
|
165
194
|
this.gossipTopicCache = gossipTopicCache;
|
|
166
195
|
|
|
167
|
-
this.addEventListener("gossipsub:message", this.onGossipsubMessage.bind(this));
|
|
196
|
+
this.gossipsub.addEventListener("gossipsub:message", this.onGossipsubMessage.bind(this));
|
|
168
197
|
this.events.on(NetworkEvent.gossipMessageValidationResult, this.onValidationResult.bind(this));
|
|
169
198
|
|
|
170
199
|
// Having access to this data is CRUCIAL for debugging. While this is a massive log, it must not be deleted.
|
|
@@ -174,6 +203,38 @@ export class Eth2Gossipsub extends GossipSub {
|
|
|
174
203
|
}
|
|
175
204
|
}
|
|
176
205
|
|
|
206
|
+
async start(): Promise<void> {
|
|
207
|
+
await this.gossipsub.start();
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
async stop(): Promise<void> {
|
|
211
|
+
await this.gossipsub.stop();
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
get mesh(): Map<string, Set<string>> {
|
|
215
|
+
return this.gossipsub.mesh;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
getTopics(): TopicStr[] {
|
|
219
|
+
return this.gossipsub.getTopics();
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
getMeshPeers(topic: TopicStr): string[] {
|
|
223
|
+
return this.gossipsub.getMeshPeers(topic);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
publish(topic: TopicStr, data: Uint8Array, opts?: PublishOpts): Promise<PublishResult> {
|
|
227
|
+
return this.gossipsub.publish(topic, data, opts);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
dumpPeerScoreStats(): PeerScoreStatsDump {
|
|
231
|
+
return this.gossipsub.dumpPeerScoreStats();
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
getScore(peerIdStr: string): number {
|
|
235
|
+
return this.gossipsub.getScore(peerIdStr);
|
|
236
|
+
}
|
|
237
|
+
|
|
177
238
|
/**
|
|
178
239
|
* Subscribe to a `GossipTopic`
|
|
179
240
|
*/
|
|
@@ -183,7 +244,7 @@ export class Eth2Gossipsub extends GossipSub {
|
|
|
183
244
|
this.gossipTopicCache.setTopic(topicStr, topic);
|
|
184
245
|
|
|
185
246
|
this.logger.verbose("Subscribe to gossipsub topic", {topic: topicStr});
|
|
186
|
-
this.subscribe(topicStr);
|
|
247
|
+
this.gossipsub.subscribe(topicStr);
|
|
187
248
|
}
|
|
188
249
|
|
|
189
250
|
/**
|
|
@@ -192,15 +253,14 @@ export class Eth2Gossipsub extends GossipSub {
|
|
|
192
253
|
unsubscribeTopic(topic: GossipTopic): void {
|
|
193
254
|
const topicStr = stringifyGossipTopic(this.config, topic);
|
|
194
255
|
this.logger.verbose("Unsubscribe to gossipsub topic", {topic: topicStr});
|
|
195
|
-
this.unsubscribe(topicStr);
|
|
256
|
+
this.gossipsub.unsubscribe(topicStr);
|
|
196
257
|
}
|
|
197
258
|
|
|
198
259
|
private onScrapeLodestarMetrics(metrics: Eth2GossipsubMetrics, networkConfig: NetworkConfig): void {
|
|
199
|
-
const mesh = this.mesh;
|
|
200
|
-
|
|
201
|
-
const
|
|
202
|
-
const
|
|
203
|
-
const score = this.score;
|
|
260
|
+
const mesh = this.gossipsub.mesh;
|
|
261
|
+
const topics = this.gossipsub.topics;
|
|
262
|
+
const peers = this.gossipsub.peers;
|
|
263
|
+
const score = this.gossipsub.score;
|
|
204
264
|
const meshPeersByClient = new Map<string, number>();
|
|
205
265
|
const meshPeerIdStrs = new Set<string>();
|
|
206
266
|
|
|
@@ -305,7 +365,7 @@ export class Eth2Gossipsub extends GossipSub {
|
|
|
305
365
|
metrics.gossipPeer.score.set(gossipScores);
|
|
306
366
|
}
|
|
307
367
|
|
|
308
|
-
private onGossipsubMessage(event:
|
|
368
|
+
private onGossipsubMessage(event: GossipSubEvents["gossipsub:message"]): void {
|
|
309
369
|
const {propagationSource, msgId, msg} = event.detail;
|
|
310
370
|
|
|
311
371
|
// Also validates that the topicStr is known
|
|
@@ -341,7 +401,7 @@ export class Eth2Gossipsub extends GossipSub {
|
|
|
341
401
|
// Without this we'll have huge event loop lag
|
|
342
402
|
// See https://github.com/ChainSafe/lodestar/issues/5604
|
|
343
403
|
callInNextEventLoop(() => {
|
|
344
|
-
this.reportMessageValidationResult(data.msgId, data.propagationSource, data.acceptance);
|
|
404
|
+
this.gossipsub.reportMessageValidationResult(data.msgId, data.propagationSource, data.acceptance);
|
|
345
405
|
});
|
|
346
406
|
}
|
|
347
407
|
|
|
@@ -379,7 +439,7 @@ export class Eth2Gossipsub extends GossipSub {
|
|
|
379
439
|
}
|
|
380
440
|
|
|
381
441
|
// Add to direct peers set only after addresses are stored
|
|
382
|
-
this.direct.add(peerIdStr);
|
|
442
|
+
this.gossipsub.direct.add(peerIdStr);
|
|
383
443
|
|
|
384
444
|
this.logger.info("Added direct peer via API", {peerId: peerIdStr});
|
|
385
445
|
return peerIdStr;
|
|
@@ -389,7 +449,7 @@ export class Eth2Gossipsub extends GossipSub {
|
|
|
389
449
|
* Remove a peer from direct peers.
|
|
390
450
|
*/
|
|
391
451
|
removeDirectPeer(peerIdStr: string): boolean {
|
|
392
|
-
const removed = this.direct.delete(peerIdStr);
|
|
452
|
+
const removed = this.gossipsub.direct.delete(peerIdStr);
|
|
393
453
|
if (removed) {
|
|
394
454
|
this.logger.info("Removed direct peer via API", {peerId: peerIdStr});
|
|
395
455
|
}
|
|
@@ -400,7 +460,7 @@ export class Eth2Gossipsub extends GossipSub {
|
|
|
400
460
|
* Get list of current direct peer IDs.
|
|
401
461
|
*/
|
|
402
462
|
getDirectPeers(): string[] {
|
|
403
|
-
return Array.from(this.direct);
|
|
463
|
+
return Array.from(this.gossipsub.direct);
|
|
404
464
|
}
|
|
405
465
|
}
|
|
406
466
|
|
|
@@ -498,7 +558,8 @@ export function parseDirectPeers(directPeerStrs: routes.lodestar.DirectPeer[], l
|
|
|
498
558
|
try {
|
|
499
559
|
const ma = multiaddr(peerStr);
|
|
500
560
|
|
|
501
|
-
const
|
|
561
|
+
const peerIdComponent = ma.getComponents().findLast((component) => component.name === "p2p");
|
|
562
|
+
const peerIdStr = peerIdComponent?.value;
|
|
502
563
|
if (!peerIdStr) {
|
|
503
564
|
logger.warn("Direct peer multiaddr must contain /p2p/ component with peer ID", {multiaddr: peerStr});
|
|
504
565
|
continue;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {Message, TopicValidatorResult} from "@libp2p/
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import type {Message, TopicValidatorResult} from "@libp2p/gossipsub";
|
|
2
|
+
import type {PeerIdStr} from "@libp2p/gossipsub/types";
|
|
3
|
+
import type {Libp2p} from "libp2p";
|
|
4
4
|
import {BeaconConfig, ForkBoundary} from "@lodestar/config";
|
|
5
5
|
import {
|
|
6
6
|
AttesterSlashing,
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
|
-
PeerScoreParams,
|
|
3
|
-
PeerScoreThresholds,
|
|
4
|
-
TopicScoreParams,
|
|
2
|
+
type PeerScoreParams,
|
|
3
|
+
type PeerScoreThresholds,
|
|
4
|
+
type TopicScoreParams,
|
|
5
5
|
defaultTopicScoreParams,
|
|
6
|
-
} from "@
|
|
6
|
+
} from "@libp2p/gossipsub/score";
|
|
7
7
|
import {BeaconConfig} from "@lodestar/config";
|
|
8
8
|
import {ATTESTATION_SUBNET_COUNT, PTC_SIZE, SLOTS_PER_EPOCH, TARGET_AGGREGATORS_PER_COMMITTEE} from "@lodestar/params";
|
|
9
9
|
import {computeCommitteeCount} from "@lodestar/state-transition";
|
package/src/network/interface.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {Identify} from "@libp2p/identify";
|
|
2
|
-
import {
|
|
1
|
+
import type {Identify} from "@libp2p/identify";
|
|
2
|
+
import type {
|
|
3
3
|
ComponentLogger,
|
|
4
4
|
ConnectionGater,
|
|
5
5
|
ConnectionProtector,
|
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
} from "@libp2p/interface";
|
|
17
17
|
import type {AddressManager, ConnectionManager, Registrar, TransportManager} from "@libp2p/interface-internal";
|
|
18
18
|
import type {Datastore} from "interface-datastore";
|
|
19
|
-
import {Libp2p as ILibp2p} from "libp2p";
|
|
19
|
+
import type {Libp2p as ILibp2p} from "libp2p";
|
|
20
20
|
import {
|
|
21
21
|
AttesterSlashing,
|
|
22
22
|
DataColumnSidecar,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {bootstrap} from "@libp2p/bootstrap";
|
|
2
2
|
import {identify} from "@libp2p/identify";
|
|
3
|
-
import {PrivateKey} from "@libp2p/interface";
|
|
3
|
+
import type {PrivateKey} from "@libp2p/interface";
|
|
4
4
|
import {mdns} from "@libp2p/mdns";
|
|
5
5
|
import {mplex} from "@libp2p/mplex";
|
|
6
6
|
import {prometheusMetrics} from "@libp2p/prometheus-metrics";
|
|
@@ -39,6 +39,7 @@ export async function createNodeJsLibp2p(
|
|
|
39
39
|
nodeJsLibp2pOpts: NodeJsLibp2pOpts = {}
|
|
40
40
|
): Promise<Libp2p> {
|
|
41
41
|
const localMultiaddrs = networkOpts.localMultiaddrs || defaultNetworkOptions.localMultiaddrs;
|
|
42
|
+
const disconnectThreshold = networkOpts.disconnectThreshold ?? defaultNetworkOptions.disconnectThreshold;
|
|
42
43
|
const {peerStoreDir, disablePeerDiscovery} = nodeJsLibp2pOpts;
|
|
43
44
|
|
|
44
45
|
let datastore: undefined | Eth2PeerDataStore = undefined;
|
|
@@ -74,6 +75,11 @@ export async function createNodeJsLibp2p(
|
|
|
74
75
|
|
|
75
76
|
return createLibp2p({
|
|
76
77
|
privateKey,
|
|
78
|
+
nodeInfo: {
|
|
79
|
+
name: "lodestar",
|
|
80
|
+
version: networkOpts.version ?? "unknown",
|
|
81
|
+
userAgent: networkOpts.private ? "" : networkOpts.version ? `lodestar/${networkOpts.version}` : "lodestar",
|
|
82
|
+
},
|
|
77
83
|
addresses: {
|
|
78
84
|
listen: localMultiaddrs,
|
|
79
85
|
announce: [],
|
|
@@ -93,7 +99,7 @@ export async function createNodeJsLibp2p(
|
|
|
93
99
|
},
|
|
94
100
|
}),
|
|
95
101
|
],
|
|
96
|
-
streamMuxers: [mplex({
|
|
102
|
+
streamMuxers: [mplex({disconnectThreshold})],
|
|
97
103
|
peerDiscovery,
|
|
98
104
|
metrics: nodeJsLibp2pOpts.metrics
|
|
99
105
|
? prometheusMetrics({
|
|
@@ -124,7 +130,6 @@ export async function createNodeJsLibp2p(
|
|
|
124
130
|
datastore,
|
|
125
131
|
services: {
|
|
126
132
|
identify: identify({
|
|
127
|
-
agentVersion: networkOpts.private ? "" : networkOpts.version ? `lodestar/${networkOpts.version}` : "lodestar",
|
|
128
133
|
runOnConnectionOpen: false,
|
|
129
134
|
}),
|
|
130
135
|
// individual components are specified because the components object is a Proxy
|
package/src/network/network.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {PeerScoreStatsDump} from "@libp2p/gossipsub/score";
|
|
2
|
+
import type {PublishOpts} from "@libp2p/gossipsub/types";
|
|
3
|
+
import type {PeerId, PrivateKey} from "@libp2p/interface";
|
|
2
4
|
import {peerIdFromPrivateKey} from "@libp2p/peer-id";
|
|
3
|
-
import {PeerScoreStatsDump} from "@chainsafe/libp2p-gossipsub/score";
|
|
4
|
-
import {PublishOpts} from "@chainsafe/libp2p-gossipsub/types";
|
|
5
5
|
import {routes} from "@lodestar/api";
|
|
6
6
|
import {BeaconConfig} from "@lodestar/config";
|
|
7
7
|
import {LoggerNode} from "@lodestar/logger/node";
|
package/src/network/options.ts
CHANGED
|
@@ -72,4 +72,7 @@ export const defaultNetworkOptions: NetworkOptions = {
|
|
|
72
72
|
// - for fusaka-devnets, we have 25-30 peers per subnet
|
|
73
73
|
// - for public testnets or mainnet, average number of peers per group is SAMPLES_PER_SLOT * targetPeers / NUMBER_OF_CUSTODY_GROUPS = 6.25 so this should not be an issue
|
|
74
74
|
targetGroupPeers: 6,
|
|
75
|
+
// Keep this high enough for normal req/resp bursts on stable connections.
|
|
76
|
+
// libp2p-mplex default (5) is too low and can cause frequent connection resets.
|
|
77
|
+
disconnectThreshold: 50,
|
|
75
78
|
};
|