Skip to content

Commit d61d898

Browse files
dappliontwoethswemeetagain
authored
Bump to new gossipsub (#3858)
* Bump to new gossipsub * Fix test type errors * Add getMeshPeers method * Cleanup test nodes on success and error * Add allowPublishToZeroPeers option * Add allowPublishToZeroPeers to dev options * Add scripts to run dev servers * Bump gossipsub * Bump gossipsub * Expose gossip peer score stats * bump gossipsub * Dump gossipsub score params * Bump lodestar * Add behaviourPenaltyThreshold to gossip scoring params * Switch to latest gossipsub update * Fix cli unit test * Fix unknownBlockSync e2e test * Update latest gossipsub * Fix e2e - network addr in use * Use latest gossipsub 3efae56c9d39ff3a047a7e6c65fa32e5756bebde * Use latest gossipsub 039af54c7bf47396c1be414d9fa33aa2e8cc2697 * Increase meshMessageDeliveriesWindow and gossipsubIWantFollowupMs * Set gossipsubIWantFollowupMs and meshMessageDeliveriesWindow 12s * Reset gossipsub metric behaviourPenalty per scrape * Compute score using lodestar score and gossipsub score (#3875) * Refactor PeerRpcScoreStore: add PeerScore class * Aggregate lodestarScore, gossipsubScore to compute final score * updateGossipsubScores util and unit test * Populate PeerScore on updateGossipsubScore * Fix peerManager e2e test * Fix test/sim/multiNodeSingleThread.test.ts * Update latest gossipsub * lodestar_gossip_mesh_peers_by_client_count metric * Log sent peers in gossipsub.publishObject() * Fix lodestar_gossip_mesh_peers_by_client_count metric * Fix lodestar_gossip_mesh_peers_by_client_count metric * Add asyncValidation=true option to gossipsub * Fix sha256 usage * Go with libp2p-gossipsub 0.14.0 Co-authored-by: Tuyen Nguyen <[email protected]> Co-authored-by: Cayman <[email protected]>
1 parent 111b194 commit d61d898

35 files changed

+643
-584
lines changed

packages/api/src/routes/lodestar.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ export type SyncChainDebugState = {
1717

1818
export type GossipQueueItem = {
1919
topic: unknown;
20-
receivedFrom: string;
20+
propagationSource: string;
2121
data: Uint8Array;
2222
addedTimeMs: number;
23+
seenTimestampSec: number;
2324
};
2425

2526
export type RegenQueueItem = {
@@ -66,6 +67,8 @@ export type Api = {
6667
getStateCacheItems(): Promise<StateCacheItem[]>;
6768
/** Dump a summary of the states in the CheckpointStateCache */
6869
getCheckpointStateCacheItems(): Promise<StateCacheItem[]>;
70+
/** Dump peer gossip stats by peer */
71+
getGossipPeerScoreStats(): Promise<Record<string, unknown>>;
6972
/** Run GC with `global.gc()` */
7073
runGC(): Promise<void>;
7174
/** Drop all states in the state cache */
@@ -95,6 +98,7 @@ export const routesData: RoutesData<Api> = {
9598
getBlockProcessorQueueItems: {url: "/eth/v1/lodestar/block-processor-queue-items", method: "GET"},
9699
getStateCacheItems: {url: "/eth/v1/lodestar/state-cache-items", method: "GET"},
97100
getCheckpointStateCacheItems: {url: "/eth/v1/lodestar/checkpoint-state-cache-items", method: "GET"},
101+
getGossipPeerScoreStats: {url: "/eth/v1/lodestar/gossip-peer-score-stats", method: "GET"},
98102
runGC: {url: "/eth/v1/lodestar/gc", method: "POST"},
99103
dropStateCache: {url: "/eth/v1/lodestar/drop-state-cache", method: "POST"},
100104
connectPeer: {url: "/eth/v1/lodestar/connect_peer", method: "POST"},
@@ -113,6 +117,7 @@ export type ReqTypes = {
113117
getBlockProcessorQueueItems: ReqEmpty;
114118
getStateCacheItems: ReqEmpty;
115119
getCheckpointStateCacheItems: ReqEmpty;
120+
getGossipPeerScoreStats: ReqEmpty;
116121
runGC: ReqEmpty;
117122
dropStateCache: ReqEmpty;
118123
connectPeer: {query: {peerId: string; multiaddr: string[]}};
@@ -140,6 +145,7 @@ export function getReqSerializers(): ReqSerializers<Api, ReqTypes> {
140145
getBlockProcessorQueueItems: reqEmpty,
141146
getStateCacheItems: reqEmpty,
142147
getCheckpointStateCacheItems: reqEmpty,
148+
getGossipPeerScoreStats: reqEmpty,
143149
runGC: reqEmpty,
144150
dropStateCache: reqEmpty,
145151
connectPeer: {
@@ -173,6 +179,7 @@ export function getReturnTypes(): ReturnTypes<Api> {
173179
getBlockProcessorQueueItems: jsonType("camel"),
174180
getStateCacheItems: jsonType("camel"),
175181
getCheckpointStateCacheItems: jsonType("camel"),
182+
getGossipPeerScoreStats: jsonType("camel"),
176183
getPeers: jsonType("camel"),
177184
discv5GetKadValues: jsonType("camel"),
178185
};

packages/cli/src/cmds/dev/options.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ const devOwnOptions: ICliCommandOptions<IDevOwnArgs> = {
3535
},
3636

3737
startValidators: {
38-
description: "Start interop validators in given range",
39-
default: "0:7",
38+
description: "Start interop validators in inclusive range with notation '0:7'",
4039
type: "string",
4140
group: "dev",
4241
},
@@ -74,6 +73,11 @@ const externalOptionsOverrides: {[k: string]: Options} = {
7473
defaultDescription: undefined,
7574
default: true,
7675
},
76+
"network.allowPublishToZeroPeers": {
77+
...beaconNodeOptions["network.allowPublishToZeroPeers"],
78+
defaultDescription: undefined,
79+
default: true,
80+
},
7781
"network.maxPeers": {
7882
...beaconNodeOptions["network.maxPeers"],
7983
defaultDescription: undefined,

packages/cli/src/options/beaconNodeOptions/network.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export interface INetworkArgs {
1717
"network.blockCountPeerLimit": number;
1818
"network.rateTrackerTimeoutMs": number;
1919
"network.dontSendGossipAttestationsToForkchoice": boolean;
20+
"network.allowPublishToZeroPeers": boolean;
2021
}
2122

2223
export function parseArgs(args: INetworkArgs): IBeaconNodeOptions["network"] {
@@ -40,6 +41,7 @@ export function parseArgs(args: INetworkArgs): IBeaconNodeOptions["network"] {
4041
blockCountPeerLimit: args["network.blockCountPeerLimit"],
4142
rateTrackerTimeoutMs: args["network.rateTrackerTimeoutMs"],
4243
dontSendGossipAttestationsToForkchoice: args["network.dontSendGossipAttestationsToForkchoice"],
44+
allowPublishToZeroPeers: args["network.allowPublishToZeroPeers"],
4345
};
4446
}
4547

@@ -153,4 +155,11 @@ export const options: ICliCommandOptions<INetworkArgs> = {
153155
description: "Pass gossip attestations to forkchoice or not",
154156
group: "network",
155157
},
158+
159+
"network.allowPublishToZeroPeers": {
160+
hidden: true,
161+
type: "boolean",
162+
description: "Don't error when publishing to zero peers",
163+
group: "network",
164+
},
156165
};

packages/cli/test/unit/options/beaconNodeOptions.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ describe("options / beaconNodeOptions", () => {
5555
"network.blockCountPeerLimit": 500,
5656
"network.rateTrackerTimeoutMs": 60000,
5757
"network.dontSendGossipAttestationsToForkchoice": true,
58+
"network.allowPublishToZeroPeers": true,
5859
"sync.isSingleNode": true,
5960
"sync.disableProcessAsChainSegment": true,
6061
"sync.backfillBatchSize": 64,
@@ -120,6 +121,7 @@ describe("options / beaconNodeOptions", () => {
120121
blockCountPeerLimit: 500,
121122
rateTrackerTimeoutMs: 60000,
122123
dontSendGossipAttestationsToForkchoice: true,
124+
allowPublishToZeroPeers: true,
123125
},
124126
sync: {
125127
isSingleNode: true,

packages/lodestar/package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,10 @@
8080
"@chainsafe/ssz": "^0.9.0",
8181
"@ethersproject/abi": "^5.0.0",
8282
"@types/datastore-level": "^3.0.0",
83-
"datastore-core": "^7.0.1",
8483
"bl": "^5.0.0",
8584
"buffer-xor": "^2.0.2",
8685
"cross-fetch": "^3.1.4",
86+
"datastore-core": "^7.0.1",
8787
"datastore-level": "^6.0.2",
8888
"deepmerge": "^3.2.0",
8989
"fastify": "3.15.1",
@@ -96,8 +96,7 @@
9696
"jwt-simple": "0.5.6",
9797
"libp2p": "^0.36.2",
9898
"libp2p-bootstrap": "^0.14.0",
99-
"libp2p-gossipsub": "^0.13.2",
100-
"libp2p-interfaces": "^4.0.4",
99+
"libp2p-gossipsub": "^0.14.0",
101100
"libp2p-mdns": "^0.18.0",
102101
"libp2p-mplex": "^0.10.5",
103102
"libp2p-tcp": "^0.17.2",

packages/lodestar/src/api/impl/lodestar/index.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,13 @@ export function getLodestarApi({
8888
}
8989

9090
return jobQueue.getItems().map((item) => {
91-
const [topic, message] = item.args;
91+
const [topic, message, propagationSource, seenTimestampSec] = item.args;
9292
return {
9393
topic: topic,
94-
receivedFrom: message.receivedFrom,
94+
propagationSource,
9595
data: message.data,
9696
addedTimeMs: item.addedTimeMs,
97+
seenTimestampSec,
9798
};
9899
});
99100
},
@@ -130,6 +131,10 @@ export function getLodestarApi({
130131
return (chain as BeaconChain)["checkpointStateCache"].dumpSummary();
131132
},
132133

134+
async getGossipPeerScoreStats() {
135+
return network.gossip.dumpPeerScoreStats();
136+
},
137+
133138
async runGC() {
134139
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
135140
if (!global.gc) throw Error("You must expose GC running the Node.js process with 'node --expose_gc'");

packages/lodestar/src/metrics/metrics.ts

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*/
44
import {BeaconStateAllForks, getCurrentSlot} from "@chainsafe/lodestar-beacon-state-transition";
55
import {IChainForkConfig} from "@chainsafe/lodestar-config";
6-
import {collectDefaultMetrics, Counter, Registry} from "prom-client";
6+
import {collectDefaultMetrics, Counter, Metric, Registry} from "prom-client";
77
import gcStats from "prometheus-gc-stats";
88
import {DbMetricLabels, IDbMetrics} from "@chainsafe/lodestar-db";
99
import {createBeaconMetrics, IBeaconMetrics} from "./metrics/beacon";
@@ -12,13 +12,13 @@ import {IMetricsOptions} from "./options";
1212
import {RegistryMetricCreator} from "./utils/registryMetricCreator";
1313
import {createValidatorMonitor, IValidatorMonitor} from "./validatorMonitor";
1414

15-
export type IMetrics = IBeaconMetrics & ILodestarMetrics & IValidatorMonitor & {register: Registry};
15+
export type IMetrics = IBeaconMetrics & ILodestarMetrics & IValidatorMonitor & {register: RegistryMetricCreator};
1616

1717
export function createMetrics(
1818
opts: IMetricsOptions,
1919
config: IChainForkConfig,
2020
anchorState: BeaconStateAllForks,
21-
registries: Registry[] = []
21+
externalRegistries: Registry[] = []
2222
): IMetrics {
2323
const register = new RegistryMetricCreator();
2424
const beacon = createBeaconMetrics(register);
@@ -47,7 +47,24 @@ export function createMetrics(
4747
// - nodejs_gc_reclaimed_bytes_total: The number of bytes GC has freed
4848
gcStats(register)();
4949

50-
return {...beacon, ...lodestar, ...validatorMonitor, register: Registry.merge([register, ...registries])};
50+
// Merge external registries
51+
register;
52+
for (const externalRegister of externalRegistries) {
53+
// Wrong types, does not return a promise
54+
const metrics = (externalRegister.getMetricsAsArray() as unknown) as Resolves<
55+
typeof externalRegister.getMetricsAsArray
56+
>;
57+
for (const metric of metrics) {
58+
register.registerMetric((metric as unknown) as Metric<string>);
59+
}
60+
}
61+
62+
return {
63+
...beacon,
64+
...lodestar,
65+
...validatorMonitor,
66+
register,
67+
};
5168
}
5269

5370
export function createDbMetrics(): {metrics: IDbMetrics; registry: Registry} {
@@ -68,3 +85,6 @@ export function createDbMetrics(): {metrics: IDbMetrics; registry: Registry} {
6885
registry.registerMetric(metrics.dbWrites);
6986
return {metrics, registry};
7087
}
88+
89+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
90+
type Resolves<F extends (...args: any[]) => Promise<any>> = F extends (...args: any[]) => Promise<infer T> ? T : never;

packages/lodestar/src/metrics/metrics/lodestar.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,11 @@ export function createLodestarMetrics(
189189
help: "Gossip peer score by threashold",
190190
labelNames: ["threshold"],
191191
}),
192+
meshPeersByClient: register.gauge<"client">({
193+
name: "lodestar_gossip_mesh_peers_by_client_count",
194+
help: "number of mesh peers, labeled by client",
195+
labelNames: ["client"],
196+
}),
192197
score: register.avgMinMax({
193198
name: "lodestar_gossip_score_avg_min_max",
194199
help: "Avg min max of all gossip peer scores",

0 commit comments

Comments
 (0)