@lodestar/beacon-node 1.37.0 → 1.38.0-dev.1f2a3a4524

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.
Files changed (45) hide show
  1. package/README.md +1 -1
  2. package/lib/api/impl/beacon/state/utils.d.ts.map +1 -1
  3. package/lib/api/impl/beacon/state/utils.js +5 -3
  4. package/lib/api/impl/beacon/state/utils.js.map +1 -1
  5. package/lib/chain/blocks/importBlock.d.ts.map +1 -1
  6. package/lib/chain/blocks/importBlock.js +4 -4
  7. package/lib/chain/blocks/importBlock.js.map +1 -1
  8. package/lib/chain/blocks/index.d.ts.map +1 -1
  9. package/lib/chain/blocks/index.js +2 -1
  10. package/lib/chain/blocks/index.js.map +1 -1
  11. package/lib/chain/blocks/types.d.ts +5 -1
  12. package/lib/chain/blocks/types.d.ts.map +1 -1
  13. package/lib/chain/blocks/verifyBlock.d.ts +2 -0
  14. package/lib/chain/blocks/verifyBlock.d.ts.map +1 -1
  15. package/lib/chain/blocks/verifyBlock.js +18 -10
  16. package/lib/chain/blocks/verifyBlock.js.map +1 -1
  17. package/lib/chain/blocks/verifyBlocksSignatures.d.ts +2 -2
  18. package/lib/chain/blocks/verifyBlocksSignatures.d.ts.map +1 -1
  19. package/lib/chain/blocks/verifyBlocksSignatures.js +2 -2
  20. package/lib/chain/blocks/verifyBlocksSignatures.js.map +1 -1
  21. package/lib/chain/opPools/aggregatedAttestationPool.d.ts.map +1 -1
  22. package/lib/chain/opPools/aggregatedAttestationPool.js +3 -1
  23. package/lib/chain/opPools/aggregatedAttestationPool.js.map +1 -1
  24. package/lib/network/gossip/encoding.d.ts +4 -2
  25. package/lib/network/gossip/encoding.d.ts.map +1 -1
  26. package/lib/network/gossip/encoding.js +7 -2
  27. package/lib/network/gossip/encoding.js.map +1 -1
  28. package/lib/network/gossip/gossipsub.d.ts.map +1 -1
  29. package/lib/network/gossip/gossipsub.js +6 -5
  30. package/lib/network/gossip/gossipsub.js.map +1 -1
  31. package/lib/network/gossip/metrics.d.ts +8 -0
  32. package/lib/network/gossip/metrics.d.ts.map +1 -1
  33. package/lib/network/gossip/metrics.js +12 -0
  34. package/lib/network/gossip/metrics.js.map +1 -1
  35. package/package.json +14 -14
  36. package/src/api/impl/beacon/state/utils.ts +5 -3
  37. package/src/chain/blocks/importBlock.ts +5 -4
  38. package/src/chain/blocks/index.ts +2 -1
  39. package/src/chain/blocks/types.ts +5 -1
  40. package/src/chain/blocks/verifyBlock.ts +34 -11
  41. package/src/chain/blocks/verifyBlocksSignatures.ts +3 -2
  42. package/src/chain/opPools/aggregatedAttestationPool.ts +5 -1
  43. package/src/network/gossip/encoding.ts +7 -2
  44. package/src/network/gossip/gossipsub.ts +8 -6
  45. package/src/network/gossip/metrics.ts +12 -0
@@ -8,6 +8,7 @@ import {DataTransform} from "@chainsafe/libp2p-gossipsub/types";
8
8
  import {ForkName} from "@lodestar/params";
9
9
  import {intToBytes} from "@lodestar/utils";
10
10
  import {MESSAGE_DOMAIN_VALID_SNAPPY} from "./constants.js";
11
+ import {Eth2GossipsubMetrics} from "./metrics.js";
11
12
  import {GossipTopicCache, getGossipSSZType} from "./topic.js";
12
13
 
13
14
  // Load WASM
@@ -70,7 +71,8 @@ export function msgIdFn(gossipTopicCache: GossipTopicCache, msg: Message): Uint8
70
71
  export class DataTransformSnappy implements DataTransform {
71
72
  constructor(
72
73
  private readonly gossipTopicCache: GossipTopicCache,
73
- private readonly maxSizePerMessage: number
74
+ private readonly maxSizePerMessage: number,
75
+ private readonly metrics: Eth2GossipsubMetrics | null
74
76
  ) {}
75
77
 
76
78
  /**
@@ -87,6 +89,7 @@ export class DataTransformSnappy implements DataTransform {
87
89
  const uncompressedDataLength = uncompressedData.length;
88
90
  const topic = this.gossipTopicCache.getTopic(topicStr);
89
91
  const sszType = getGossipSSZType(topic);
92
+ this.metrics?.dataTransform.inbound.inc({type: topic.type});
90
93
 
91
94
  if (uncompressedDataLength < sszType.minSize) {
92
95
  throw Error(`ssz_snappy decoded data length ${uncompressedDataLength} < ${sszType.minSize}`);
@@ -102,7 +105,9 @@ export class DataTransformSnappy implements DataTransform {
102
105
  * Takes the data to be published (a topic and associated data) transforms the data. The
103
106
  * transformed data will then be used to create a `RawGossipsubMessage` to be sent to peers.
104
107
  */
105
- outboundTransform(_topicStr: string, data: Uint8Array): Uint8Array {
108
+ outboundTransform(topicStr: string, data: Uint8Array): Uint8Array {
109
+ const topic = this.gossipTopicCache.getTopic(topicStr);
110
+ this.metrics?.dataTransform.outbound.inc({type: topic.type});
106
111
  if (data.length > this.maxSizePerMessage) {
107
112
  throw Error(`ssz_snappy encoded data length ${data.length} > ${this.maxSizePerMessage}`);
108
113
  }
@@ -89,6 +89,13 @@ export class Eth2Gossipsub extends GossipSub {
89
89
  const gossipTopicCache = new GossipTopicCache(config);
90
90
 
91
91
  const scoreParams = computeGossipPeerScoreParams({config, eth2Context: modules.eth2Context});
92
+ let metrics: Eth2GossipsubMetrics | null = null;
93
+ if (metricsRegister) {
94
+ metrics = createEth2GossipsubMetrics(metricsRegister);
95
+ metrics.gossipMesh.peersByType.addCollect(() =>
96
+ this.onScrapeLodestarMetrics(metrics as Eth2GossipsubMetrics, networkConfig)
97
+ );
98
+ }
92
99
 
93
100
  // Gossipsub parameters defined here:
94
101
  // https://github.com/ethereum/consensus-specs/blob/v1.1.10/specs/phase0/p2p-interface.md#the-gossip-domain-gossipsub
@@ -116,7 +123,7 @@ export class Eth2Gossipsub extends GossipSub {
116
123
  fastMsgIdFn: fastMsgIdFn,
117
124
  msgIdFn: msgIdFn.bind(msgIdFn, gossipTopicCache),
118
125
  msgIdToStrFn: msgIdToStrFn,
119
- dataTransform: new DataTransformSnappy(gossipTopicCache, config.MAX_PAYLOAD_SIZE),
126
+ dataTransform: new DataTransformSnappy(gossipTopicCache, config.MAX_PAYLOAD_SIZE, metrics),
120
127
  metricsRegister: metricsRegister as MetricsRegister | null,
121
128
  metricsTopicStrToLabel: metricsRegister
122
129
  ? getMetricsTopicStrToLabel(networkConfig, {disableLightClientServer: opts.disableLightClientServer ?? false})
@@ -141,11 +148,6 @@ export class Eth2Gossipsub extends GossipSub {
141
148
  this.events = events;
142
149
  this.gossipTopicCache = gossipTopicCache;
143
150
 
144
- if (metricsRegister) {
145
- const metrics = createEth2GossipsubMetrics(metricsRegister);
146
- metrics.gossipMesh.peersByType.addCollect(() => this.onScrapeLodestarMetrics(metrics, networkConfig));
147
- }
148
-
149
151
  this.addEventListener("gossipsub:message", this.onGossipsubMessage.bind(this));
150
152
  this.events.on(NetworkEvent.gossipMessageValidationResult, this.onValidationResult.bind(this));
151
153
 
@@ -67,5 +67,17 @@ export function createEth2GossipsubMetrics(register: RegistryMetricCreator) {
67
67
  labelNames: ["subnet", "boundary"],
68
68
  }),
69
69
  },
70
+ dataTransform: {
71
+ inbound: register.counter<{type: GossipType}>({
72
+ name: "lodestar_gossip_data_transform_inbound_total",
73
+ help: "Total number of inbound data transforms by gossip type",
74
+ labelNames: ["type"],
75
+ }),
76
+ outbound: register.counter<{type: GossipType}>({
77
+ name: "lodestar_gossip_data_transform_outbound_total",
78
+ help: "Total number of outbound data transforms by gossip type",
79
+ labelNames: ["type"],
80
+ }),
81
+ },
70
82
  };
71
83
  }