Skip to content
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
9 changes: 7 additions & 2 deletions packages/beacon-node/src/network/gossip/encoding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {DataTransform} from "@chainsafe/libp2p-gossipsub/types";
import {ForkName} from "@lodestar/params";
import {intToBytes} from "@lodestar/utils";
import {MESSAGE_DOMAIN_VALID_SNAPPY} from "./constants.js";
import {Eth2GossipsubMetrics} from "./metrics.js";
import {GossipTopicCache, getGossipSSZType} from "./topic.js";

// Load WASM
Expand Down Expand Up @@ -70,7 +71,8 @@ export function msgIdFn(gossipTopicCache: GossipTopicCache, msg: Message): Uint8
export class DataTransformSnappy implements DataTransform {
constructor(
private readonly gossipTopicCache: GossipTopicCache,
private readonly maxSizePerMessage: number
private readonly maxSizePerMessage: number,
private readonly metrics: Eth2GossipsubMetrics | null
) {}

/**
Expand All @@ -87,6 +89,7 @@ export class DataTransformSnappy implements DataTransform {
const uncompressedDataLength = uncompressedData.length;
const topic = this.gossipTopicCache.getTopic(topicStr);
const sszType = getGossipSSZType(topic);
this.metrics?.dataTransform.inbound.inc({type: topic.type});

if (uncompressedDataLength < sszType.minSize) {
throw Error(`ssz_snappy decoded data length ${uncompressedDataLength} < ${sszType.minSize}`);
Expand All @@ -102,7 +105,9 @@ export class DataTransformSnappy implements DataTransform {
* Takes the data to be published (a topic and associated data) transforms the data. The
* transformed data will then be used to create a `RawGossipsubMessage` to be sent to peers.
*/
outboundTransform(_topicStr: string, data: Uint8Array): Uint8Array {
outboundTransform(topicStr: string, data: Uint8Array): Uint8Array {
const topic = this.gossipTopicCache.getTopic(topicStr);
this.metrics?.dataTransform.outbound.inc({type: topic.type});
if (data.length > this.maxSizePerMessage) {
throw Error(`ssz_snappy encoded data length ${data.length} > ${this.maxSizePerMessage}`);
}
Expand Down
14 changes: 8 additions & 6 deletions packages/beacon-node/src/network/gossip/gossipsub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ export class Eth2Gossipsub extends GossipSub {
const gossipTopicCache = new GossipTopicCache(config);

const scoreParams = computeGossipPeerScoreParams({config, eth2Context: modules.eth2Context});
let metrics: Eth2GossipsubMetrics | null = null;
if (metricsRegister) {
metrics = createEth2GossipsubMetrics(metricsRegister);
metrics.gossipMesh.peersByType.addCollect(() =>
this.onScrapeLodestarMetrics(metrics as Eth2GossipsubMetrics, networkConfig)
);
Comment thread
twoeths marked this conversation as resolved.
}

// Gossipsub parameters defined here:
// https://github.com/ethereum/consensus-specs/blob/v1.1.10/specs/phase0/p2p-interface.md#the-gossip-domain-gossipsub
Expand Down Expand Up @@ -116,7 +123,7 @@ export class Eth2Gossipsub extends GossipSub {
fastMsgIdFn: fastMsgIdFn,
msgIdFn: msgIdFn.bind(msgIdFn, gossipTopicCache),
msgIdToStrFn: msgIdToStrFn,
dataTransform: new DataTransformSnappy(gossipTopicCache, config.MAX_PAYLOAD_SIZE),
dataTransform: new DataTransformSnappy(gossipTopicCache, config.MAX_PAYLOAD_SIZE, metrics),
metricsRegister: metricsRegister as MetricsRegister | null,
metricsTopicStrToLabel: metricsRegister
? getMetricsTopicStrToLabel(networkConfig, {disableLightClientServer: opts.disableLightClientServer ?? false})
Expand All @@ -141,11 +148,6 @@ export class Eth2Gossipsub extends GossipSub {
this.events = events;
this.gossipTopicCache = gossipTopicCache;

if (metricsRegister) {
const metrics = createEth2GossipsubMetrics(metricsRegister);
metrics.gossipMesh.peersByType.addCollect(() => this.onScrapeLodestarMetrics(metrics, networkConfig));
}

this.addEventListener("gossipsub:message", this.onGossipsubMessage.bind(this));
this.events.on(NetworkEvent.gossipMessageValidationResult, this.onValidationResult.bind(this));

Expand Down
12 changes: 12 additions & 0 deletions packages/beacon-node/src/network/gossip/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,17 @@ export function createEth2GossipsubMetrics(register: RegistryMetricCreator) {
labelNames: ["subnet", "boundary"],
}),
},
dataTransform: {
inbound: register.counter<{type: GossipType}>({
name: "lodestar_gossip_data_transform_inbound_total",
help: "Total number of inbound data transforms by gossip type",
labelNames: ["type"],
}),
outbound: register.counter<{type: GossipType}>({
name: "lodestar_gossip_data_transform_outbound_total",
help: "Total number of outbound data transforms by gossip type",
labelNames: ["type"],
}),
},
Comment thread
twoeths marked this conversation as resolved.
};
}
Loading