@lodestar/beacon-node 1.45.0-dev.f535421f29 → 1.45.0-dev.f6c521a123
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/beacon/blocks/index.d.ts.map +1 -1
- package/lib/api/impl/beacon/blocks/index.js +3 -2
- package/lib/api/impl/beacon/blocks/index.js.map +1 -1
- package/lib/api/impl/beacon/index.d.ts +1 -1
- package/lib/api/impl/beacon/index.d.ts.map +1 -1
- package/lib/api/impl/beacon/index.js.map +1 -1
- package/lib/api/impl/beacon/pool/index.d.ts.map +1 -1
- package/lib/api/impl/beacon/pool/index.js +6 -43
- package/lib/api/impl/beacon/pool/index.js.map +1 -1
- package/lib/api/impl/beacon/state/index.d.ts +1 -1
- package/lib/api/impl/beacon/state/index.d.ts.map +1 -1
- package/lib/api/impl/beacon/state/index.js +48 -5
- package/lib/api/impl/beacon/state/index.js.map +1 -1
- package/lib/api/impl/beacon/state/utils.d.ts +13 -3
- package/lib/api/impl/beacon/state/utils.d.ts.map +1 -1
- package/lib/api/impl/beacon/state/utils.js +48 -4
- package/lib/api/impl/beacon/state/utils.js.map +1 -1
- package/lib/api/impl/debug/index.d.ts +1 -1
- package/lib/api/impl/debug/index.d.ts.map +1 -1
- package/lib/api/impl/debug/index.js +2 -2
- package/lib/api/impl/debug/index.js.map +1 -1
- package/lib/api/impl/lodestar/index.js +2 -2
- package/lib/api/impl/lodestar/index.js.map +1 -1
- package/lib/api/impl/proof/index.d.ts +1 -1
- package/lib/api/impl/proof/index.d.ts.map +1 -1
- package/lib/api/impl/proof/index.js +2 -2
- package/lib/api/impl/proof/index.js.map +1 -1
- package/lib/api/impl/utils.d.ts +23 -0
- package/lib/api/impl/utils.d.ts.map +1 -1
- package/lib/api/impl/utils.js +44 -1
- package/lib/api/impl/utils.js.map +1 -1
- package/lib/api/impl/validator/index.d.ts +0 -14
- package/lib/api/impl/validator/index.d.ts.map +1 -1
- package/lib/api/impl/validator/index.js +67 -62
- package/lib/api/impl/validator/index.js.map +1 -1
- package/lib/api/rest/base.d.ts.map +1 -1
- package/lib/api/rest/base.js +14 -3
- package/lib/api/rest/base.js.map +1 -1
- package/lib/chain/blocks/importBlock.d.ts.map +1 -1
- package/lib/chain/blocks/importBlock.js +4 -22
- package/lib/chain/blocks/importBlock.js.map +1 -1
- package/lib/chain/blocks/utils/chainSegment.d.ts.map +1 -1
- package/lib/chain/blocks/utils/chainSegment.js +13 -5
- package/lib/chain/blocks/utils/chainSegment.js.map +1 -1
- package/lib/chain/blocks/verifyBlocksExecutionPayloads.js +1 -1
- package/lib/chain/blocks/verifyBlocksExecutionPayloads.js.map +1 -1
- package/lib/chain/blocks/verifyBlocksSanityChecks.js +1 -1
- package/lib/chain/blocks/verifyBlocksSanityChecks.js.map +1 -1
- package/lib/chain/blocks/verifyExecutionPayloadEnvelope.js +2 -2
- package/lib/chain/blocks/verifyExecutionPayloadEnvelope.js.map +1 -1
- package/lib/chain/builderCircuitBreaker.d.ts +31 -0
- package/lib/chain/builderCircuitBreaker.d.ts.map +1 -0
- package/lib/chain/builderCircuitBreaker.js +59 -0
- package/lib/chain/builderCircuitBreaker.js.map +1 -0
- package/lib/chain/chain.d.ts +3 -2
- package/lib/chain/chain.d.ts.map +1 -1
- package/lib/chain/chain.js +27 -5
- package/lib/chain/chain.js.map +1 -1
- package/lib/chain/errors/blockError.d.ts +48 -6
- package/lib/chain/errors/blockError.d.ts.map +1 -1
- package/lib/chain/errors/blockError.js +25 -4
- package/lib/chain/errors/blockError.js.map +1 -1
- package/lib/chain/errors/executionPayloadEnvelope.d.ts +11 -0
- package/lib/chain/errors/executionPayloadEnvelope.d.ts.map +1 -1
- package/lib/chain/errors/executionPayloadEnvelope.js +2 -0
- package/lib/chain/errors/executionPayloadEnvelope.js.map +1 -1
- package/lib/chain/interface.d.ts +3 -2
- package/lib/chain/interface.d.ts.map +1 -1
- package/lib/chain/interface.js.map +1 -1
- package/lib/chain/lightClient/index.d.ts.map +1 -1
- package/lib/chain/lightClient/index.js +11 -6
- package/lib/chain/lightClient/index.js.map +1 -1
- package/lib/chain/lightClient/proofs.d.ts.map +1 -1
- package/lib/chain/lightClient/proofs.js +28 -2
- package/lib/chain/lightClient/proofs.js.map +1 -1
- package/lib/chain/lightClient/types.d.ts +3 -1
- package/lib/chain/lightClient/types.d.ts.map +1 -1
- package/lib/chain/opPools/aggregatedAttestationPool.js +1 -1
- package/lib/chain/opPools/aggregatedAttestationPool.js.map +1 -1
- package/lib/chain/opPools/proposerPreferencesPool.d.ts +3 -2
- package/lib/chain/opPools/proposerPreferencesPool.d.ts.map +1 -1
- package/lib/chain/opPools/proposerPreferencesPool.js +4 -1
- package/lib/chain/opPools/proposerPreferencesPool.js.map +1 -1
- package/lib/chain/options.d.ts +5 -0
- package/lib/chain/options.d.ts.map +1 -1
- package/lib/chain/options.js +1 -0
- package/lib/chain/options.js.map +1 -1
- package/lib/chain/prepareNextSlot.d.ts.map +1 -1
- package/lib/chain/prepareNextSlot.js +12 -7
- package/lib/chain/prepareNextSlot.js.map +1 -1
- package/lib/chain/produceBlock/produceBlockBody.d.ts.map +1 -1
- package/lib/chain/produceBlock/produceBlockBody.js +4 -12
- package/lib/chain/produceBlock/produceBlockBody.js.map +1 -1
- package/lib/chain/seenCache/index.d.ts +0 -1
- package/lib/chain/seenCache/index.d.ts.map +1 -1
- package/lib/chain/seenCache/index.js +0 -1
- package/lib/chain/seenCache/index.js.map +1 -1
- package/lib/chain/validation/aggregateAndProof.js +10 -6
- package/lib/chain/validation/aggregateAndProof.js.map +1 -1
- package/lib/chain/validation/attestation.d.ts.map +1 -1
- package/lib/chain/validation/attestation.js +10 -6
- package/lib/chain/validation/attestation.js.map +1 -1
- package/lib/chain/validation/block.d.ts.map +1 -1
- package/lib/chain/validation/block.js +53 -4
- package/lib/chain/validation/block.js.map +1 -1
- package/lib/chain/validation/executionPayloadBid.js +13 -12
- package/lib/chain/validation/executionPayloadBid.js.map +1 -1
- package/lib/chain/validation/executionPayloadEnvelope.d.ts.map +1 -1
- package/lib/chain/validation/executionPayloadEnvelope.js +29 -0
- package/lib/chain/validation/executionPayloadEnvelope.js.map +1 -1
- package/lib/chain/validation/proposerPreferences.d.ts.map +1 -1
- package/lib/chain/validation/proposerPreferences.js +14 -5
- package/lib/chain/validation/proposerPreferences.js.map +1 -1
- package/lib/chain/validation/signatureSets/aggregateAndProof.d.ts.map +1 -1
- package/lib/chain/validation/signatureSets/aggregateAndProof.js +2 -3
- package/lib/chain/validation/signatureSets/aggregateAndProof.js.map +1 -1
- package/lib/db/repositories/lightclientSyncCommitteeWitness.d.ts.map +1 -1
- package/lib/db/repositories/lightclientSyncCommitteeWitness.js +42 -7
- package/lib/db/repositories/lightclientSyncCommitteeWitness.js.map +1 -1
- package/lib/execution/builder/http.d.ts +18 -0
- package/lib/execution/builder/http.d.ts.map +1 -1
- package/lib/execution/builder/http.js +20 -11
- package/lib/execution/builder/http.js.map +1 -1
- package/lib/metrics/metrics/beacon.d.ts +6 -0
- package/lib/metrics/metrics/beacon.d.ts.map +1 -1
- package/lib/metrics/metrics/beacon.js +18 -0
- package/lib/metrics/metrics/beacon.js.map +1 -1
- package/lib/network/core/metrics.d.ts +65 -0
- package/lib/network/core/metrics.d.ts.map +1 -1
- package/lib/network/core/metrics.js +94 -0
- package/lib/network/core/metrics.js.map +1 -1
- package/lib/network/discv5/utils.d.ts.map +1 -1
- package/lib/network/discv5/utils.js +12 -3
- package/lib/network/discv5/utils.js.map +1 -1
- package/lib/network/gossip/encoding.d.ts +2 -2
- package/lib/network/gossip/encoding.d.ts.map +1 -1
- package/lib/network/gossip/encoding.js +22 -9
- package/lib/network/gossip/encoding.js.map +1 -1
- package/lib/network/gossip/gossipsub.d.ts.map +1 -1
- package/lib/network/gossip/gossipsub.js +4 -3
- package/lib/network/gossip/gossipsub.js.map +1 -1
- package/lib/network/gossip/topic.d.ts +831 -226
- package/lib/network/gossip/topic.d.ts.map +1 -1
- package/lib/network/gossip/topic.js +47 -4
- package/lib/network/gossip/topic.js.map +1 -1
- package/lib/network/peers/peerManager.d.ts.map +1 -1
- package/lib/network/peers/peerManager.js +10 -0
- package/lib/network/peers/peerManager.js.map +1 -1
- package/lib/network/peers/score/score.d.ts +3 -1
- package/lib/network/peers/score/score.d.ts.map +1 -1
- package/lib/network/peers/score/score.js +6 -1
- package/lib/network/peers/score/score.js.map +1 -1
- package/lib/network/peers/score/store.d.ts.map +1 -1
- package/lib/network/peers/score/store.js +6 -1
- package/lib/network/peers/score/store.js.map +1 -1
- package/lib/network/peers/utils/prioritizePeers.d.ts.map +1 -1
- package/lib/network/peers/utils/prioritizePeers.js +14 -0
- package/lib/network/peers/utils/prioritizePeers.js.map +1 -1
- package/lib/network/processor/gossipHandlers.d.ts.map +1 -1
- package/lib/network/processor/gossipHandlers.js +18 -9
- package/lib/network/processor/gossipHandlers.js.map +1 -1
- package/lib/network/reqresp/handlers/executionPayloadEnvelopesByRange.d.ts.map +1 -1
- package/lib/network/reqresp/handlers/executionPayloadEnvelopesByRange.js +4 -2
- package/lib/network/reqresp/handlers/executionPayloadEnvelopesByRange.js.map +1 -1
- package/lib/sync/sync.d.ts.map +1 -1
- package/lib/sync/sync.js +7 -0
- package/lib/sync/sync.js.map +1 -1
- package/lib/sync/unknownBlock.d.ts.map +1 -1
- package/lib/sync/unknownBlock.js +7 -2
- package/lib/sync/unknownBlock.js.map +1 -1
- package/lib/util/graffiti.d.ts +15 -0
- package/lib/util/graffiti.d.ts.map +1 -1
- package/lib/util/graffiti.js +55 -0
- package/lib/util/graffiti.js.map +1 -1
- package/package.json +23 -21
- package/src/api/impl/beacon/blocks/index.ts +3 -2
- package/src/api/impl/beacon/index.ts +1 -1
- package/src/api/impl/beacon/pool/index.ts +5 -53
- package/src/api/impl/beacon/state/index.ts +55 -3
- package/src/api/impl/beacon/state/utils.ts +68 -4
- package/src/api/impl/debug/index.ts +3 -2
- package/src/api/impl/lodestar/index.ts +2 -2
- package/src/api/impl/proof/index.ts +2 -2
- package/src/api/impl/utils.ts +51 -1
- package/src/api/impl/validator/index.ts +75 -67
- package/src/api/rest/base.ts +17 -3
- package/src/chain/blocks/importBlock.ts +2 -24
- package/src/chain/blocks/utils/chainSegment.ts +16 -5
- package/src/chain/blocks/verifyBlocksExecutionPayloads.ts +1 -1
- package/src/chain/blocks/verifyBlocksSanityChecks.ts +1 -1
- package/src/chain/blocks/verifyExecutionPayloadEnvelope.ts +2 -2
- package/src/chain/builderCircuitBreaker.ts +84 -0
- package/src/chain/chain.ts +38 -5
- package/src/chain/errors/blockError.ts +44 -7
- package/src/chain/errors/executionPayloadEnvelope.ts +9 -0
- package/src/chain/interface.ts +2 -2
- package/src/chain/lightClient/index.ts +12 -7
- package/src/chain/lightClient/proofs.ts +36 -1
- package/src/chain/lightClient/types.ts +3 -1
- package/src/chain/opPools/aggregatedAttestationPool.ts +1 -1
- package/src/chain/opPools/proposerPreferencesPool.ts +6 -2
- package/src/chain/options.ts +6 -0
- package/src/chain/prepareNextSlot.ts +11 -7
- package/src/chain/produceBlock/produceBlockBody.ts +9 -17
- package/src/chain/seenCache/index.ts +0 -1
- package/src/chain/validation/aggregateAndProof.ts +12 -6
- package/src/chain/validation/attestation.ts +12 -6
- package/src/chain/validation/block.ts +69 -4
- package/src/chain/validation/executionPayloadBid.ts +16 -11
- package/src/chain/validation/executionPayloadEnvelope.ts +37 -0
- package/src/chain/validation/proposerPreferences.ts +15 -5
- package/src/chain/validation/signatureSets/aggregateAndProof.ts +3 -3
- package/src/db/repositories/lightclientSyncCommitteeWitness.ts +57 -9
- package/src/execution/builder/http.ts +30 -17
- package/src/metrics/metrics/beacon.ts +19 -0
- package/src/network/core/metrics.ts +94 -0
- package/src/network/discv5/utils.ts +11 -3
- package/src/network/gossip/encoding.ts +20 -7
- package/src/network/gossip/gossipsub.ts +9 -3
- package/src/network/gossip/topic.ts +58 -4
- package/src/network/peers/peerManager.ts +11 -0
- package/src/network/peers/score/score.ts +8 -1
- package/src/network/peers/score/store.ts +8 -1
- package/src/network/peers/utils/prioritizePeers.ts +15 -0
- package/src/network/processor/gossipHandlers.ts +18 -8
- package/src/network/reqresp/handlers/executionPayloadEnvelopesByRange.ts +4 -2
- package/src/sync/sync.ts +10 -0
- package/src/sync/unknownBlock.ts +8 -2
- package/src/util/graffiti.ts +78 -0
- package/lib/chain/seenCache/seenProposerPreferences.d.ts +0 -16
- package/lib/chain/seenCache/seenProposerPreferences.d.ts.map +0 -1
- package/lib/chain/seenCache/seenProposerPreferences.js +0 -26
- package/lib/chain/seenCache/seenProposerPreferences.js.map +0 -1
- package/src/chain/seenCache/seenProposerPreferences.ts +0 -32
|
@@ -127,6 +127,100 @@ export function createNetworkCoreMetrics(register: RegistryMetricCreator) {
|
|
|
127
127
|
name: "lodestar_peer_manager_starved_bool",
|
|
128
128
|
help: "Whether lodestar is starved of data while syncing",
|
|
129
129
|
}),
|
|
130
|
+
/**
|
|
131
|
+
* Core selection/pruning phase of the heartbeat, split out of heartbeatDuration so it
|
|
132
|
+
* can be attributed on its own. Divide by peersEvaluated for time-per-peer.
|
|
133
|
+
*/
|
|
134
|
+
prioritizePeersDuration: register.histogram({
|
|
135
|
+
name: "lodestar_peer_manager_prioritize_peers_seconds",
|
|
136
|
+
help: "prioritizePeers function duration in seconds, the core peer selection/pruning algorithm",
|
|
137
|
+
buckets: [0.0005, 0.001, 0.005, 0.01, 0.05, 0.1],
|
|
138
|
+
}),
|
|
139
|
+
/**
|
|
140
|
+
* Score decay + map prune over every tracked peer, split out of heartbeatDuration.
|
|
141
|
+
* This loop iterates the whole score store, so divide by scoreMapSize (not
|
|
142
|
+
* peersEvaluated) for time-per-peer.
|
|
143
|
+
*/
|
|
144
|
+
scoreUpdateDuration: register.histogram({
|
|
145
|
+
name: "lodestar_peer_score_update_seconds",
|
|
146
|
+
help: "Peer score store update (decay + prune over all peers) duration in seconds",
|
|
147
|
+
buckets: [0.0005, 0.001, 0.005, 0.01, 0.05, 0.1],
|
|
148
|
+
}),
|
|
149
|
+
/**
|
|
150
|
+
* Denominator for prioritizePeersDuration: it scales with the number of connected
|
|
151
|
+
* healthy peers, so time-per-peer (prioritizePeersDuration / this) is the comparable
|
|
152
|
+
* figure. For scoreUpdateDuration use scoreMapSize instead.
|
|
153
|
+
*/
|
|
154
|
+
peersEvaluated: register.histogram({
|
|
155
|
+
name: "lodestar_peer_manager_peers_evaluated_count",
|
|
156
|
+
help: "Number of connected healthy peers evaluated by prioritizePeers per heartbeat, denominator for prioritize_peers_seconds",
|
|
157
|
+
buckets: [0, 25, 50, 75, 100, 150, 200],
|
|
158
|
+
}),
|
|
159
|
+
/**
|
|
160
|
+
* Every peer the manager intends to disconnect. Covers both the top-of-heartbeat
|
|
161
|
+
* bad-score disconnects ("banned"/"score_too_low") and the prioritization reasons;
|
|
162
|
+
* the older peersRequestedToDisconnect gauge only recorded the latter. Counts intent,
|
|
163
|
+
* not completion (goodbye is fire-and-forget).
|
|
164
|
+
*/
|
|
165
|
+
peersPruned: register.counter<{reason: string}>({
|
|
166
|
+
name: "lodestar_peer_manager_peers_pruned_total",
|
|
167
|
+
help: "Total peers the peer manager intends to disconnect, labeled by reason (incl. bad-score and prioritization reasons)",
|
|
168
|
+
labelNames: ["reason"],
|
|
169
|
+
}),
|
|
170
|
+
/**
|
|
171
|
+
* Actual peer count per active subnet, to check the min-peers-per-subnet invariant.
|
|
172
|
+
* Buckets straddle the target (TARGET_SUBNET_PEERS = 6).
|
|
173
|
+
*/
|
|
174
|
+
peersPerActiveSubnet: register.histogram<{type: SubnetType}>({
|
|
175
|
+
name: "lodestar_peer_manager_peers_per_active_subnet",
|
|
176
|
+
help: "Histogram of connected peer count per active subnet, labeled by subnet type",
|
|
177
|
+
labelNames: ["type"],
|
|
178
|
+
buckets: [0, 2, 4, 6, 8, 12],
|
|
179
|
+
}),
|
|
180
|
+
/**
|
|
181
|
+
* Live outbound ratio, to check the OUTBOUND_PEERS_RATIO (10%) invariant (issue #2215).
|
|
182
|
+
* Denominator is connected healthy peers (banned/disconnected already removed).
|
|
183
|
+
*/
|
|
184
|
+
outboundPeersRatio: register.gauge({
|
|
185
|
+
name: "lodestar_peer_manager_outbound_peers_ratio",
|
|
186
|
+
help: "Ratio of outbound peers to total connected healthy peers, verifies the outbound peers invariant",
|
|
187
|
+
}),
|
|
188
|
+
/**
|
|
189
|
+
* Score state crossings (Healthy/Disconnected/Banned). Sensitive to the decay formula,
|
|
190
|
+
* thresholds, and gossip-score weighting.
|
|
191
|
+
*/
|
|
192
|
+
scoreStateTransitions: register.counter<{from: string; to: string}>({
|
|
193
|
+
name: "lodestar_peer_score_state_transitions_total",
|
|
194
|
+
help: "Total peer score state transitions, labeled by from and to state (Healthy/Disconnected/Banned)",
|
|
195
|
+
labelNames: ["from", "to"],
|
|
196
|
+
}),
|
|
197
|
+
/**
|
|
198
|
+
* Entry count of the score store (not bytes). Reflects the prune-to-MAX_ENTRIES /
|
|
199
|
+
* SCORE_THRESHOLD retention logic. Also the denominator for scoreUpdateDuration
|
|
200
|
+
* time-per-peer (that loop iterates the whole store, not just connected peers).
|
|
201
|
+
*/
|
|
202
|
+
scoreMapSize: register.gauge({
|
|
203
|
+
name: "lodestar_peer_manager_score_map_size",
|
|
204
|
+
help: "Current number of entries in the peer score store",
|
|
205
|
+
}),
|
|
206
|
+
/**
|
|
207
|
+
* Entry count of the connectedPeers map (not bytes). Should track libp2p_peers; a
|
|
208
|
+
* persistent gap indicates the connection leak guarded by leakedConnectionsCount.
|
|
209
|
+
*/
|
|
210
|
+
connectedPeersMapSize: register.gauge({
|
|
211
|
+
name: "lodestar_peer_manager_connected_peers_map_size",
|
|
212
|
+
help: "Current number of entries in the peer manager connectedPeers map",
|
|
213
|
+
}),
|
|
214
|
+
/**
|
|
215
|
+
* assertPeerRelevance outcome per Status exchange: "relevant", an irrelevant reason
|
|
216
|
+
* code, or "error". Fires on every status evaluation (inbound requests and our own
|
|
217
|
+
* requestStatus responses both route through onStatus).
|
|
218
|
+
*/
|
|
219
|
+
relevanceCheck: register.counter<{result: string}>({
|
|
220
|
+
name: "lodestar_peer_relevance_check_total",
|
|
221
|
+
help: "Total peer relevance checks on Status, labeled by result (relevant or irrelevant reason code)",
|
|
222
|
+
labelNames: ["result"],
|
|
223
|
+
}),
|
|
130
224
|
},
|
|
131
225
|
leakedConnectionsCount: register.gauge({
|
|
132
226
|
name: "lodestar_peer_manager_leaked_connections_count",
|
|
@@ -13,9 +13,17 @@ export enum ENRRelevance {
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
export function enrRelevance(enr: ENR, config: BeaconConfig, clock: IClock): ENRRelevance {
|
|
16
|
-
// We are not interested in peers that don't advertise at least one transport (tcp or quic)
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
// We are not interested in peers that don't advertise at least one transport (tcp or quic).
|
|
17
|
+
let multiaddrTCP: ReturnType<ENR["getLocationMultiaddr"]>;
|
|
18
|
+
let multiaddrQUIC: ReturnType<ENR["getLocationMultiaddr"]>;
|
|
19
|
+
// Malformed ENR endpoint fields can make multiaddr conversion throw.
|
|
20
|
+
// Treat endpoints that cannot be converted as unusable.
|
|
21
|
+
try {
|
|
22
|
+
multiaddrTCP = enr.getLocationMultiaddr(ENRKey.tcp);
|
|
23
|
+
multiaddrQUIC = enr.getLocationMultiaddr(ENRKey.quic);
|
|
24
|
+
} catch {
|
|
25
|
+
return ENRRelevance.no_transport;
|
|
26
|
+
}
|
|
19
27
|
if (!multiaddrTCP && !multiaddrQUIC) {
|
|
20
28
|
return ENRRelevance.no_transport;
|
|
21
29
|
}
|
|
@@ -9,7 +9,7 @@ import {ForkName} from "@lodestar/params";
|
|
|
9
9
|
import {intToBytes} from "@lodestar/utils";
|
|
10
10
|
import {MESSAGE_DOMAIN_VALID_SNAPPY} from "./constants.js";
|
|
11
11
|
import {Eth2GossipsubMetrics} from "./metrics.js";
|
|
12
|
-
import {GossipTopicCache, getGossipSSZType} from "./topic.js";
|
|
12
|
+
import {GossipTopicCache, getGossipSSZMaxSize, getGossipSSZType} from "./topic.js";
|
|
13
13
|
|
|
14
14
|
// Load WASM
|
|
15
15
|
const xxhash = await xxhashFactory();
|
|
@@ -52,6 +52,13 @@ export function fastMsgIdFn(rpcMsg: RPC.Message): string {
|
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
export function msgIdToStrFn(msgId: Uint8Array): string {
|
|
55
|
+
// Spec mandates a 20-byte gossipsub message-id, but control-message IDs from peers
|
|
56
|
+
// can be any length. Reject non-20-byte IDs to avoid a Buffer.set() RangeError on
|
|
57
|
+
// longer IDs and stale shared-buffer bytes on shorter ones.
|
|
58
|
+
// Ref: https://github.com/ethereum/consensus-specs/blob/v1.7.0-alpha.10/specs/phase0/p2p-interface.md?plain=1#L486
|
|
59
|
+
if (msgId.length !== 20) {
|
|
60
|
+
throw Error(`Expect msgId to be 20 bytes, got ${msgId.length}`);
|
|
61
|
+
}
|
|
55
62
|
// this is the same logic to `toHex(msgId)` with better performance
|
|
56
63
|
sharedMsgIdBuf.set(msgId);
|
|
57
64
|
return `0x${sharedMsgIdBuf.toString("hex")}`;
|
|
@@ -91,7 +98,7 @@ export function msgIdFn(gossipTopicCache: GossipTopicCache, msg: Message): Uint8
|
|
|
91
98
|
export class DataTransformSnappy implements DataTransform {
|
|
92
99
|
constructor(
|
|
93
100
|
private readonly gossipTopicCache: GossipTopicCache,
|
|
94
|
-
private readonly
|
|
101
|
+
private readonly maxPayloadSize: number,
|
|
95
102
|
private readonly metrics: Eth2GossipsubMetrics | null
|
|
96
103
|
) {}
|
|
97
104
|
|
|
@@ -104,17 +111,18 @@ export class DataTransformSnappy implements DataTransform {
|
|
|
104
111
|
inboundTransform(topicStr: string, data: Uint8Array): Uint8Array {
|
|
105
112
|
// check uncompressed data length before we actually decompress
|
|
106
113
|
const uncompressedDataLength = snappyWasm.decompress_len(data);
|
|
107
|
-
if (uncompressedDataLength > this.maxSizePerMessage) {
|
|
108
|
-
throw Error(`ssz_snappy decoded data length ${uncompressedDataLength} > ${this.maxSizePerMessage}`);
|
|
109
|
-
}
|
|
110
114
|
|
|
111
115
|
const topic = this.gossipTopicCache.getTopic(topicStr);
|
|
112
116
|
const sszType = getGossipSSZType(topic);
|
|
117
|
+
const maxSize = getGossipSSZMaxSize(topic, this.maxPayloadSize, sszType);
|
|
113
118
|
this.metrics?.dataTransform.inbound.inc({type: topic.type});
|
|
114
119
|
|
|
115
120
|
if (uncompressedDataLength < sszType.minSize) {
|
|
116
121
|
throw Error(`ssz_snappy decoded data length ${uncompressedDataLength} < ${sszType.minSize}`);
|
|
117
122
|
}
|
|
123
|
+
if (uncompressedDataLength > maxSize) {
|
|
124
|
+
throw Error(`ssz_snappy decoded data length ${uncompressedDataLength} > ${maxSize}`);
|
|
125
|
+
}
|
|
118
126
|
if (uncompressedDataLength > sszType.maxSize) {
|
|
119
127
|
throw Error(`ssz_snappy decoded data length ${uncompressedDataLength} > ${sszType.maxSize}`);
|
|
120
128
|
}
|
|
@@ -132,9 +140,14 @@ export class DataTransformSnappy implements DataTransform {
|
|
|
132
140
|
*/
|
|
133
141
|
outboundTransform(topicStr: string, data: Uint8Array): Uint8Array {
|
|
134
142
|
const topic = this.gossipTopicCache.getTopic(topicStr);
|
|
143
|
+
const sszType = getGossipSSZType(topic);
|
|
144
|
+
const maxSize = getGossipSSZMaxSize(topic, this.maxPayloadSize, sszType);
|
|
135
145
|
this.metrics?.dataTransform.outbound.inc({type: topic.type});
|
|
136
|
-
if (data.length >
|
|
137
|
-
throw Error(`ssz_snappy encoded data length ${data.length} > ${
|
|
146
|
+
if (data.length > maxSize) {
|
|
147
|
+
throw Error(`ssz_snappy encoded data length ${data.length} > ${maxSize}`);
|
|
148
|
+
}
|
|
149
|
+
if (data.length > sszType.maxSize) {
|
|
150
|
+
throw Error(`ssz_snappy encoded data length ${data.length} > ${sszType.maxSize}`);
|
|
138
151
|
}
|
|
139
152
|
|
|
140
153
|
// Using Buffer.alloc() instead of Buffer.allocUnsafe() to mitigate high GC pressure observed in some environments
|
|
@@ -15,7 +15,12 @@ import {type Multiaddr, multiaddr} from "@multiformats/multiaddr";
|
|
|
15
15
|
import {ENR} from "@chainsafe/enr";
|
|
16
16
|
import {routes} from "@lodestar/api";
|
|
17
17
|
import {BeaconConfig, ForkBoundary} from "@lodestar/config";
|
|
18
|
-
import {
|
|
18
|
+
import {
|
|
19
|
+
ATTESTATION_SUBNET_COUNT,
|
|
20
|
+
MAX_SIGNED_AGGREGATE_AND_PROOF_SIZE,
|
|
21
|
+
SLOTS_PER_EPOCH,
|
|
22
|
+
SYNC_COMMITTEE_SUBNET_COUNT,
|
|
23
|
+
} from "@lodestar/params";
|
|
19
24
|
import {SubnetID} from "@lodestar/types";
|
|
20
25
|
import {Logger, Map2d, Map2dArr} from "@lodestar/utils";
|
|
21
26
|
import {RegistryMetricCreator} from "../../metrics/index.js";
|
|
@@ -35,7 +40,7 @@ import {
|
|
|
35
40
|
computeGossipPeerScoreParams,
|
|
36
41
|
gossipScoreThresholds,
|
|
37
42
|
} from "./scoringParameters.js";
|
|
38
|
-
import {GossipTopicCache, getCoreTopicsAtFork, stringifyGossipTopic} from "./topic.js";
|
|
43
|
+
import {GossipTopicCache, getAllowedTopics, getCoreTopicsAtFork, stringifyGossipTopic} from "./topic.js";
|
|
39
44
|
|
|
40
45
|
/** As specified in https://github.com/ethereum/consensus-specs/blob/v1.1.10/specs/phase0/p2p-interface.md */
|
|
41
46
|
const GOSSIPSUB_HEARTBEAT_INTERVAL = 0.7 * 1000;
|
|
@@ -140,6 +145,7 @@ export class Eth2Gossipsub {
|
|
|
140
145
|
const gossipsubInstance = gossipsub({
|
|
141
146
|
globalSignaturePolicy: StrictNoSign,
|
|
142
147
|
allowPublishToZeroTopicPeers: allowPublishToZeroPeers,
|
|
148
|
+
allowedTopics: getAllowedTopics(networkConfig),
|
|
143
149
|
D: gossipsubD ?? GOSSIP_D,
|
|
144
150
|
Dlo: gossipsubDLow ?? GOSSIP_D_LOW,
|
|
145
151
|
Dhi: gossipsubDHigh ?? GOSSIP_D_HIGH,
|
|
@@ -178,7 +184,7 @@ export class Eth2Gossipsub {
|
|
|
178
184
|
// Only send IDONTWANT messages if the message size is larger than this
|
|
179
185
|
// This should be large enough to not send IDONTWANT for "small" messages
|
|
180
186
|
// See https://github.com/ChainSafe/lodestar/pull/7077#issuecomment-2383679472
|
|
181
|
-
idontwantMinDataSize:
|
|
187
|
+
idontwantMinDataSize: MAX_SIGNED_AGGREGATE_AND_PROOF_SIZE,
|
|
182
188
|
})(modules.libp2p.services.components) as GossipSubInternal;
|
|
183
189
|
|
|
184
190
|
if (metrics) {
|
|
@@ -1,12 +1,18 @@
|
|
|
1
|
+
import {type CompositeTypeAny} from "@chainsafe/ssz";
|
|
1
2
|
import {ForkDigestContext} from "@lodestar/config";
|
|
2
3
|
import {
|
|
3
4
|
ATTESTATION_SUBNET_COUNT,
|
|
4
5
|
ForkName,
|
|
5
6
|
ForkSeq,
|
|
7
|
+
MAX_ATTESTER_SLASHING_SIZE,
|
|
8
|
+
MAX_DATA_COLUMN_SIDECAR_SIZE,
|
|
9
|
+
MAX_SIGNED_AGGREGATE_AND_PROOF_SIZE,
|
|
10
|
+
MAX_SIGNED_EXECUTION_PAYLOAD_BID_SIZE,
|
|
6
11
|
SYNC_COMMITTEE_SUBNET_COUNT,
|
|
7
12
|
isForkPostAltair,
|
|
8
13
|
isForkPostElectra,
|
|
9
14
|
isForkPostFulu,
|
|
15
|
+
isForkPostGloas,
|
|
10
16
|
} from "@lodestar/params";
|
|
11
17
|
import {Attestation, SingleAttestation, ssz, sszTypesFor} from "@lodestar/types";
|
|
12
18
|
import {GossipAction, GossipActionError, GossipErrorCode} from "../../chain/errors/gossipValidation.js";
|
|
@@ -130,6 +136,30 @@ export function getGossipSSZType(topic: GossipTopic) {
|
|
|
130
136
|
}
|
|
131
137
|
}
|
|
132
138
|
|
|
139
|
+
/**
|
|
140
|
+
* Return the maximum uncompressed SSZ byte length accepted for a gossip object.
|
|
141
|
+
*/
|
|
142
|
+
export function getGossipSSZMaxSize(topic: GossipTopic, maxPayloadSize: number, sszType?: CompositeTypeAny): number {
|
|
143
|
+
const {fork} = topic.boundary;
|
|
144
|
+
// Gloas progressive containers have broad theoretical SSZ max sizes; use the preset p2p bounds instead.
|
|
145
|
+
switch (topic.type) {
|
|
146
|
+
case GossipType.beacon_block:
|
|
147
|
+
return maxPayloadSize;
|
|
148
|
+
case GossipType.beacon_aggregate_and_proof:
|
|
149
|
+
return isForkPostGloas(fork) ? MAX_SIGNED_AGGREGATE_AND_PROOF_SIZE : (sszType ?? getGossipSSZType(topic)).maxSize;
|
|
150
|
+
case GossipType.attester_slashing:
|
|
151
|
+
return isForkPostGloas(fork) ? MAX_ATTESTER_SLASHING_SIZE : (sszType ?? getGossipSSZType(topic)).maxSize;
|
|
152
|
+
case GossipType.data_column_sidecar:
|
|
153
|
+
return isForkPostGloas(fork) ? MAX_DATA_COLUMN_SIDECAR_SIZE : (sszType ?? getGossipSSZType(topic)).maxSize;
|
|
154
|
+
case GossipType.execution_payload:
|
|
155
|
+
return maxPayloadSize;
|
|
156
|
+
case GossipType.execution_payload_bid:
|
|
157
|
+
return MAX_SIGNED_EXECUTION_PAYLOAD_BID_SIZE;
|
|
158
|
+
default:
|
|
159
|
+
return (sszType ?? getGossipSSZType(topic)).maxSize;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
133
163
|
/**
|
|
134
164
|
* Deserialize a gossip serialized data into an ssz object.
|
|
135
165
|
*/
|
|
@@ -246,7 +276,7 @@ export function parseGossipTopic(forkDigestContext: ForkDigestContext, topicStr:
|
|
|
246
276
|
export function getCoreTopicsAtFork(
|
|
247
277
|
networkConfig: NetworkConfig,
|
|
248
278
|
fork: ForkName,
|
|
249
|
-
opts: {subscribeAllSubnets?: boolean; disableLightClientServer?: boolean}
|
|
279
|
+
opts: {subscribeAllSubnets?: boolean; subscribeAllColumnSubnets?: boolean; disableLightClientServer?: boolean}
|
|
250
280
|
): GossipTopicTypeMap[keyof GossipTopicTypeMap][] {
|
|
251
281
|
// Common topics for all forks
|
|
252
282
|
const topics: GossipTopicTypeMap[keyof GossipTopicTypeMap][] = [
|
|
@@ -266,7 +296,7 @@ export function getCoreTopicsAtFork(
|
|
|
266
296
|
|
|
267
297
|
// After fulu also track data_column_sidecar_{index}
|
|
268
298
|
if (ForkSeq[fork] >= ForkSeq.fulu) {
|
|
269
|
-
topics.push(...getDataColumnSidecarTopics(networkConfig));
|
|
299
|
+
topics.push(...getDataColumnSidecarTopics(networkConfig, opts.subscribeAllColumnSubnets));
|
|
270
300
|
}
|
|
271
301
|
|
|
272
302
|
// After Deneb and before Fulu also track blob_sidecar_{subnet_id}
|
|
@@ -309,15 +339,39 @@ export function getCoreTopicsAtFork(
|
|
|
309
339
|
return topics;
|
|
310
340
|
}
|
|
311
341
|
|
|
342
|
+
/**
|
|
343
|
+
* Build the complete set of valid gossip topic strings across every fork boundary.
|
|
344
|
+
*/
|
|
345
|
+
export function getAllowedTopics(networkConfig: NetworkConfig): Set<string> {
|
|
346
|
+
const {config} = networkConfig;
|
|
347
|
+
const allowedTopics = new Set<string>();
|
|
348
|
+
|
|
349
|
+
for (const boundary of config.forkBoundariesAscendingEpochOrder) {
|
|
350
|
+
const topics = getCoreTopicsAtFork(networkConfig, boundary.fork, {
|
|
351
|
+
subscribeAllSubnets: true,
|
|
352
|
+
subscribeAllColumnSubnets: true,
|
|
353
|
+
disableLightClientServer: false,
|
|
354
|
+
});
|
|
355
|
+
for (const topic of topics) {
|
|
356
|
+
allowedTopics.add(stringifyGossipTopic(config, {...topic, boundary}));
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
return allowedTopics;
|
|
361
|
+
}
|
|
362
|
+
|
|
312
363
|
/**
|
|
313
364
|
* Pick data column subnets to subscribe to post-fulu.
|
|
314
365
|
*/
|
|
315
366
|
export function getDataColumnSidecarTopics(
|
|
316
|
-
networkConfig: NetworkConfig
|
|
367
|
+
networkConfig: NetworkConfig,
|
|
368
|
+
subscribeAllColumnSubnets = false
|
|
317
369
|
): GossipTopicTypeMap[keyof GossipTopicTypeMap][] {
|
|
318
370
|
const topics: GossipTopicTypeMap[keyof GossipTopicTypeMap][] = [];
|
|
319
371
|
|
|
320
|
-
const subnets =
|
|
372
|
+
const subnets = subscribeAllColumnSubnets
|
|
373
|
+
? Array.from({length: networkConfig.config.DATA_COLUMN_SIDECAR_SUBNET_COUNT}, (_, i) => i)
|
|
374
|
+
: networkConfig.custodyConfig.sampledSubnets;
|
|
321
375
|
for (const subnet of subnets) {
|
|
322
376
|
topics.push({type: GossipType.data_column_sidecar, subnet});
|
|
323
377
|
}
|
|
@@ -415,8 +415,10 @@ export class PeerManager {
|
|
|
415
415
|
);
|
|
416
416
|
if (irrelevantReasonType === null) {
|
|
417
417
|
isIrrelevant = false;
|
|
418
|
+
this.metrics?.peerManager.relevanceCheck.inc({result: "relevant"});
|
|
418
419
|
} else {
|
|
419
420
|
isIrrelevant = true;
|
|
421
|
+
this.metrics?.peerManager.relevanceCheck.inc({result: irrelevantReasonType.code});
|
|
420
422
|
this.logger.debug("Irrelevant peer", {
|
|
421
423
|
peer: prettyPrintPeerId(peer),
|
|
422
424
|
reason: renderIrrelevantPeerType(irrelevantReasonType),
|
|
@@ -424,6 +426,7 @@ export class PeerManager {
|
|
|
424
426
|
}
|
|
425
427
|
} catch (e) {
|
|
426
428
|
this.logger.error("Irrelevant peer - unexpected error", {peer: prettyPrintPeerId(peer)}, e as Error);
|
|
429
|
+
this.metrics?.peerManager.relevanceCheck.inc({result: "error"});
|
|
427
430
|
isIrrelevant = true;
|
|
428
431
|
}
|
|
429
432
|
|
|
@@ -552,15 +555,18 @@ export class PeerManager {
|
|
|
552
555
|
for (const peer of connectedPeers) {
|
|
553
556
|
switch (this.peerRpcScores.getScoreState(peer)) {
|
|
554
557
|
case ScoreState.Banned:
|
|
558
|
+
this.metrics?.peerManager.peersPruned.inc({reason: "banned"});
|
|
555
559
|
void this.goodbyeAndDisconnect(peer, GoodByeReasonCode.BANNED);
|
|
556
560
|
break;
|
|
557
561
|
case ScoreState.Disconnected:
|
|
562
|
+
this.metrics?.peerManager.peersPruned.inc({reason: "score_too_low"});
|
|
558
563
|
void this.goodbyeAndDisconnect(peer, GoodByeReasonCode.SCORE_TOO_LOW);
|
|
559
564
|
break;
|
|
560
565
|
case ScoreState.Healthy:
|
|
561
566
|
connectedHealthyPeers.push(peer);
|
|
562
567
|
}
|
|
563
568
|
}
|
|
569
|
+
this.metrics?.peerManager.peersEvaluated.observe(connectedHealthyPeers.length);
|
|
564
570
|
|
|
565
571
|
const status = this.statusCache.get();
|
|
566
572
|
const starved =
|
|
@@ -572,6 +578,7 @@ export class PeerManager {
|
|
|
572
578
|
this.metrics?.peerManager.starved.set(starved ? 1 : 0);
|
|
573
579
|
const forkSeq = this.config.getForkSeq(this.clock.currentSlot);
|
|
574
580
|
|
|
581
|
+
const prioritizeTimer = this.metrics?.peerManager.prioritizePeersDuration.startTimer();
|
|
575
582
|
const {peersToDisconnect, peersToConnect, attnetQueries, syncnetQueries, custodyGroupQueries} = prioritizePeers(
|
|
576
583
|
connectedHealthyPeers.map((peer) => {
|
|
577
584
|
const peerData = this.connectedPeers.get(peer.toString());
|
|
@@ -601,6 +608,7 @@ export class PeerManager {
|
|
|
601
608
|
this.config,
|
|
602
609
|
this.metrics
|
|
603
610
|
);
|
|
611
|
+
prioritizeTimer?.();
|
|
604
612
|
|
|
605
613
|
const queriesMerged: SubnetDiscvQueryMs[] = [];
|
|
606
614
|
for (const {type, queries} of [
|
|
@@ -632,6 +640,7 @@ export class PeerManager {
|
|
|
632
640
|
// disconnect first to have more slots before we dial new peers
|
|
633
641
|
for (const [reason, peers] of peersToDisconnect) {
|
|
634
642
|
this.metrics?.peersRequestedToDisconnect.inc({reason}, peers.length);
|
|
643
|
+
this.metrics?.peerManager.peersPruned.inc({reason}, peers.length);
|
|
635
644
|
for (const peer of peers) {
|
|
636
645
|
void this.goodbyeAndDisconnect(peer, GoodByeReasonCode.TOO_MANY_PEERS);
|
|
637
646
|
}
|
|
@@ -659,6 +668,8 @@ export class PeerManager {
|
|
|
659
668
|
}
|
|
660
669
|
}
|
|
661
670
|
|
|
671
|
+
this.metrics?.peerManager.connectedPeersMapSize.set(this.connectedPeers.size);
|
|
672
|
+
|
|
662
673
|
timer?.();
|
|
663
674
|
|
|
664
675
|
this.logger.debug("peerManager heartbeat result", {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {GoodByeReasonCode} from "../../../constants/network.js";
|
|
2
|
+
import {NetworkCoreMetrics} from "../../core/metrics.js";
|
|
2
3
|
import {
|
|
3
4
|
COOL_DOWN_BEFORE_DECAY_MS,
|
|
4
5
|
DEFAULT_SCORE,
|
|
@@ -23,13 +24,15 @@ export class RealScore implements IPeerScore {
|
|
|
23
24
|
/** The final score, computed from the above */
|
|
24
25
|
private score: number;
|
|
25
26
|
private lastUpdate: number;
|
|
27
|
+
private readonly metrics: NetworkCoreMetrics | null;
|
|
26
28
|
|
|
27
|
-
constructor() {
|
|
29
|
+
constructor(metrics: NetworkCoreMetrics | null = null) {
|
|
28
30
|
this.lodestarScore = DEFAULT_SCORE;
|
|
29
31
|
this.gossipScore = DEFAULT_SCORE;
|
|
30
32
|
this.score = DEFAULT_SCORE;
|
|
31
33
|
this.ignoreNegativeGossipScore = false;
|
|
32
34
|
this.lastUpdate = Date.now();
|
|
35
|
+
this.metrics = metrics;
|
|
33
36
|
}
|
|
34
37
|
|
|
35
38
|
isCoolingDown(): boolean {
|
|
@@ -136,6 +139,10 @@ export class RealScore implements IPeerScore {
|
|
|
136
139
|
this.recomputeScore();
|
|
137
140
|
const newState = scoreToState(this.score);
|
|
138
141
|
|
|
142
|
+
if (prevState !== newState) {
|
|
143
|
+
this.metrics?.peerManager.scoreStateTransitions.inc({from: prevState, to: newState});
|
|
144
|
+
}
|
|
145
|
+
|
|
139
146
|
if (prevState !== ScoreState.Banned && newState === ScoreState.Banned) {
|
|
140
147
|
// ban this peer for at least BANNED_BEFORE_DECAY_MS seconds
|
|
141
148
|
this.lastUpdate = Date.now() + COOL_DOWN_BEFORE_DECAY_MS;
|
|
@@ -32,7 +32,9 @@ export class PeerRpcScoreStore implements IPeerRpcScoreStore {
|
|
|
32
32
|
constructor(opts: PeerRpcScoreOpts = {}, metrics: NetworkCoreMetrics | null = null, logger: Logger | null = null) {
|
|
33
33
|
this.metrics = metrics;
|
|
34
34
|
this.logger = logger;
|
|
35
|
-
this.scores = opts.disablePeerScoring
|
|
35
|
+
this.scores = opts.disablePeerScoring
|
|
36
|
+
? new MapDef(() => new MaxScore())
|
|
37
|
+
: new MapDef(() => new RealScore(this.metrics));
|
|
36
38
|
}
|
|
37
39
|
|
|
38
40
|
getScore(peer: PeerId): number {
|
|
@@ -75,6 +77,8 @@ export class PeerRpcScoreStore implements IPeerRpcScoreStore {
|
|
|
75
77
|
}
|
|
76
78
|
|
|
77
79
|
update(): void {
|
|
80
|
+
const timer = this.metrics?.peerManager.scoreUpdateDuration.startTimer();
|
|
81
|
+
|
|
78
82
|
// Bound size of data structures
|
|
79
83
|
pruneSetToMax(this.scores, MAX_ENTRIES);
|
|
80
84
|
|
|
@@ -86,6 +90,9 @@ export class PeerRpcScoreStore implements IPeerRpcScoreStore {
|
|
|
86
90
|
this.scores.delete(peerIdStr);
|
|
87
91
|
}
|
|
88
92
|
}
|
|
93
|
+
|
|
94
|
+
this.metrics?.peerManager.scoreMapSize.set(this.scores.size);
|
|
95
|
+
timer?.();
|
|
89
96
|
}
|
|
90
97
|
|
|
91
98
|
updateGossipsubScore(peerId: PeerIdStr, newScore: number, ignore: boolean): void {
|
|
@@ -7,6 +7,7 @@ import {MapDef} from "@lodestar/utils";
|
|
|
7
7
|
import {shuffle} from "../../../util/shuffle.js";
|
|
8
8
|
import {sortBy} from "../../../util/sortBy.js";
|
|
9
9
|
import {NetworkCoreMetrics} from "../../core/metrics.js";
|
|
10
|
+
import {SubnetType} from "../../metadata.js";
|
|
10
11
|
import {RequestedSubnet} from "./subnetMap.js";
|
|
11
12
|
|
|
12
13
|
/** Target number of peers we'd like to have connected to a given long-lived subnet */
|
|
@@ -189,6 +190,18 @@ export function prioritizePeers(
|
|
|
189
190
|
|
|
190
191
|
const connectedPeerCount = connectedPeers.length;
|
|
191
192
|
|
|
193
|
+
// Track the outbound peers invariant (we keep at least OUTBOUND_PEERS_RATIO outbound peers).
|
|
194
|
+
// Report 0 when there are no peers so the gauge doesn't go stale at its last value.
|
|
195
|
+
if (metrics) {
|
|
196
|
+
let outboundPeerCount = 0;
|
|
197
|
+
for (const peer of connectedPeers) {
|
|
198
|
+
if (peer.direction === "outbound") {
|
|
199
|
+
outboundPeerCount++;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
metrics.peerManager.outboundPeersRatio.set(connectedPeerCount > 0 ? outboundPeerCount / connectedPeerCount : 0);
|
|
203
|
+
}
|
|
204
|
+
|
|
192
205
|
if (connectedPeerCount < targetPeers) {
|
|
193
206
|
// Need more peers.
|
|
194
207
|
// Instead of attempting to connect the exact amount necessary this will overshoot a little since the success
|
|
@@ -256,6 +269,7 @@ function requestSubnetPeers(
|
|
|
256
269
|
|
|
257
270
|
for (const {subnet, toSlot} of activeAttnets) {
|
|
258
271
|
const peersInSubnet = peersPerSubnet.get(subnet) ?? 0;
|
|
272
|
+
metrics?.peerManager.peersPerActiveSubnet.observe({type: SubnetType.attnets}, peersInSubnet);
|
|
259
273
|
if (peersInSubnet < targetSubnetPeers) {
|
|
260
274
|
// We need more peers
|
|
261
275
|
attnetQueries.push({subnet, toSlot, maxPeersToDiscover: targetSubnetPeers - peersInSubnet});
|
|
@@ -282,6 +296,7 @@ function requestSubnetPeers(
|
|
|
282
296
|
|
|
283
297
|
for (const {subnet, toSlot} of activeSyncnets) {
|
|
284
298
|
const peersInSubnet = peersPerSubnet.get(subnet) ?? 0;
|
|
299
|
+
metrics?.peerManager.peersPerActiveSubnet.observe({type: SubnetType.syncnets}, peersInSubnet);
|
|
285
300
|
if (peersInSubnet < targetSubnetPeers) {
|
|
286
301
|
// We need more peers
|
|
287
302
|
syncnetQueries.push({subnet, toSlot, maxPeersToDiscover: targetSubnetPeers - peersInSubnet});
|
|
@@ -176,7 +176,7 @@ function getSequentialHandlers(modules: ValidatorFnsModules, options: GossipHand
|
|
|
176
176
|
|
|
177
177
|
// optimistically add gossip block to the seen cache
|
|
178
178
|
// if validation fails, we will NOT forward this gossip block to peers
|
|
179
|
-
// - if
|
|
179
|
+
// - if PARENT_BLOCK_UNKNOWN error, blockInput will then be queued inside BlockInputSync. If the gossip block is really invalid, it will be pruned there
|
|
180
180
|
// - if other validator errors, blockInput will stay in the seen cache and will be pruned on finalization
|
|
181
181
|
const blockInput = chain.seenBlockInputCache.getByBlock({
|
|
182
182
|
block: signedBlock,
|
|
@@ -187,7 +187,7 @@ function getSequentialHandlers(modules: ValidatorFnsModules, options: GossipHand
|
|
|
187
187
|
});
|
|
188
188
|
|
|
189
189
|
// Optimistically seed the payload-envelope cache too, mirroring seenBlockInputCache above.
|
|
190
|
-
// This ensures we have PayloadEnvelopeInput, even through "
|
|
190
|
+
// This ensures we have PayloadEnvelopeInput, even through "PARENT_BLOCK_UNKNOWN" error
|
|
191
191
|
// see https://github.com/ChainSafe/lodestar/issues/9475
|
|
192
192
|
if (isForkPostGloas(fork)) {
|
|
193
193
|
chain.seenPayloadEnvelopeInputCache.add({
|
|
@@ -227,7 +227,8 @@ function getSequentialHandlers(modules: ValidatorFnsModules, options: GossipHand
|
|
|
227
227
|
if (e instanceof BlockGossipError) {
|
|
228
228
|
logger.debug("Gossip block has error", {slot, root: blockShortHex, code: e.type.code});
|
|
229
229
|
if (
|
|
230
|
-
(e.type.code === BlockErrorCode.
|
|
230
|
+
(e.type.code === BlockErrorCode.PARENT_BLOCK_UNKNOWN ||
|
|
231
|
+
e.type.code === BlockErrorCode.PARENT_PAYLOAD_UNKNOWN) &&
|
|
231
232
|
blockInput
|
|
232
233
|
) {
|
|
233
234
|
chain.emitter.emit(ChainEvent.blockUnknownParent, {
|
|
@@ -661,14 +662,19 @@ function getSequentialHandlers(modules: ValidatorFnsModules, options: GossipHand
|
|
|
661
662
|
break;
|
|
662
663
|
}
|
|
663
664
|
// ALREADY_KNOWN should not happen with ignoreIfKnown=true above
|
|
664
|
-
//
|
|
665
|
+
// PARENT_BLOCK_UNKNOWN should not happen, we handled this in validateBeaconBlock() function above
|
|
665
666
|
case BlockErrorCode.ALREADY_KNOWN:
|
|
666
|
-
case BlockErrorCode.
|
|
667
|
+
case BlockErrorCode.PARENT_BLOCK_UNKNOWN:
|
|
667
668
|
case BlockErrorCode.PRESTATE_MISSING:
|
|
668
669
|
case BlockErrorCode.EXECUTION_ENGINE_ERROR:
|
|
669
|
-
// Errors might indicate an issue with our node or the connected EL client
|
|
670
|
+
// Errors might indicate an issue with our node or the connected EL client.
|
|
670
671
|
logLevel = LogLevel.error;
|
|
671
672
|
break;
|
|
673
|
+
case BlockErrorCode.EXECUTION_ENGINE_INVALID:
|
|
674
|
+
// the peer served a bad block
|
|
675
|
+
core.reportPeer(peerIdStr, PeerAction.LowToleranceError, "ExecutionEngineInvalid");
|
|
676
|
+
logLevel = LogLevel.warn;
|
|
677
|
+
break;
|
|
672
678
|
default:
|
|
673
679
|
// TODO: Should it use PeerId or string?
|
|
674
680
|
core.reportPeer(peerIdStr, PeerAction.LowToleranceError, "BadGossipBlock");
|
|
@@ -1241,6 +1247,11 @@ function getSequentialHandlers(modules: ValidatorFnsModules, options: GossipHand
|
|
|
1241
1247
|
payloadAttestationMessage.data.payloadPresent,
|
|
1242
1248
|
payloadAttestationMessage.data.blobDataAvailable
|
|
1243
1249
|
);
|
|
1250
|
+
|
|
1251
|
+
chain.emitter.emit(routes.events.EventType.payloadAttestationMessage, {
|
|
1252
|
+
version: config.getForkName(payloadAttestationMessage.data.slot),
|
|
1253
|
+
data: payloadAttestationMessage,
|
|
1254
|
+
});
|
|
1244
1255
|
},
|
|
1245
1256
|
[GossipType.execution_payload_bid]: async ({
|
|
1246
1257
|
gossipData,
|
|
@@ -1273,9 +1284,8 @@ function getSequentialHandlers(modules: ValidatorFnsModules, options: GossipHand
|
|
|
1273
1284
|
const signedProposerPreferences = sszDeserialize(topic, serializedData);
|
|
1274
1285
|
await validateGossipProposerPreferences(chain, signedProposerPreferences);
|
|
1275
1286
|
|
|
1276
|
-
chain.proposerPreferencesPool.add(signedProposerPreferences);
|
|
1277
1287
|
chain.emitter.emit(routes.events.EventType.proposerPreferences, {
|
|
1278
|
-
version:
|
|
1288
|
+
version: config.getForkName(signedProposerPreferences.message.proposalSlot),
|
|
1279
1289
|
data: signedProposerPreferences,
|
|
1280
1290
|
});
|
|
1281
1291
|
},
|
|
@@ -107,8 +107,10 @@ export function validateExecutionPayloadEnvelopesByRangeRequest(
|
|
|
107
107
|
// The gloas req/resp spec uses MIN_EPOCHS_FOR_BLOCK_REQUESTS to define the minimum range peers MUST serve.
|
|
108
108
|
// Archival nodes may still serve older retained payloads to allow genesis sync.
|
|
109
109
|
|
|
110
|
-
|
|
111
|
-
|
|
110
|
+
// Spec: EnvelopesByRange response is bounded by MAX_REQUEST_PAYLOADS (consensus-specs #5383),
|
|
111
|
+
// distinct from the MAX_REQUEST_BLOCKS_DENEB cap used for block-by-range.
|
|
112
|
+
if (count > config.MAX_REQUEST_PAYLOADS) {
|
|
113
|
+
count = config.MAX_REQUEST_PAYLOADS;
|
|
112
114
|
}
|
|
113
115
|
|
|
114
116
|
return {startSlot, count};
|
package/src/sync/sync.ts
CHANGED
|
@@ -75,6 +75,11 @@ export class BeaconSync implements IBeaconSync {
|
|
|
75
75
|
if (metrics) {
|
|
76
76
|
metrics.syncStatus.addCollect(() => this.scrapeMetrics(metrics));
|
|
77
77
|
}
|
|
78
|
+
|
|
79
|
+
// A from-scratch or large-gap start boots not synced; updateSyncState resumes once synced
|
|
80
|
+
if (this.state !== SyncState.Synced) {
|
|
81
|
+
this.chain.forkChoice.pauseFastConfirmation();
|
|
82
|
+
}
|
|
78
83
|
}
|
|
79
84
|
|
|
80
85
|
close(): void {
|
|
@@ -228,6 +233,8 @@ export class BeaconSync implements IBeaconSync {
|
|
|
228
233
|
|
|
229
234
|
// We have become synced, subscribe to all the gossip core topics
|
|
230
235
|
if (state === SyncState.Synced && this.chain.clock.currentEpoch >= MIN_EPOCH_TO_START_GOSSIP) {
|
|
236
|
+
this.chain.forkChoice.resumeFastConfirmation();
|
|
237
|
+
|
|
231
238
|
if (!this.network.isSubscribedToGossipCoreTopics()) {
|
|
232
239
|
this.network
|
|
233
240
|
.subscribeGossipCoreTopics()
|
|
@@ -251,6 +258,9 @@ export class BeaconSync implements IBeaconSync {
|
|
|
251
258
|
else if (state !== SyncState.Synced) {
|
|
252
259
|
const syncDiff = this.chain.clock.currentSlot - this.chain.forkChoice.getHead().slot;
|
|
253
260
|
if (syncDiff > this.slotImportTolerance * 2) {
|
|
261
|
+
// Same debounce as gossip: transient blips keep the rule running, only a real gap pauses it
|
|
262
|
+
this.chain.forkChoice.pauseFastConfirmation();
|
|
263
|
+
|
|
254
264
|
if (this.network.isSubscribedToGossipCoreTopics()) {
|
|
255
265
|
this.logger.warn(`Node sync has fallen behind by ${syncDiff} slots`);
|
|
256
266
|
this.network
|
package/src/sync/unknownBlock.ts
CHANGED
|
@@ -819,7 +819,7 @@ export class BlockInputSync {
|
|
|
819
819
|
// case BlockErrorCode.ALREADY_KNOWN:
|
|
820
820
|
// case BlockErrorCode.GENESIS_BLOCK:
|
|
821
821
|
|
|
822
|
-
case BlockErrorCode.
|
|
822
|
+
case BlockErrorCode.PARENT_BLOCK_UNKNOWN:
|
|
823
823
|
case BlockErrorCode.PRESTATE_MISSING:
|
|
824
824
|
// Should not happen, mark as downloaded to try again latter
|
|
825
825
|
this.logger.debug("Attempted to process block but its parent was still unknown", errorData, res.err);
|
|
@@ -841,10 +841,16 @@ export class BlockInputSync {
|
|
|
841
841
|
|
|
842
842
|
case BlockErrorCode.EXECUTION_ENGINE_ERROR:
|
|
843
843
|
// Removing the block(s) without penalizing the peers, hoping for EL to
|
|
844
|
-
// recover on a latter download + verify attempt
|
|
844
|
+
// recover on a latter download + verify attempt.
|
|
845
845
|
this.removeAllDescendants(pendingBlock);
|
|
846
846
|
break;
|
|
847
847
|
|
|
848
|
+
case BlockErrorCode.EXECUTION_ENGINE_INVALID:
|
|
849
|
+
// the peer served a bad block
|
|
850
|
+
this.logger.debug("Execution engine rejected block from unknown parent sync", errorData, res.err);
|
|
851
|
+
this.removeAndDownScoreAllDescendants(pendingBlock);
|
|
852
|
+
break;
|
|
853
|
+
|
|
848
854
|
default:
|
|
849
855
|
// Block is not correct with respect to our chain. Log error loudly
|
|
850
856
|
this.logger.debug("Error processing block from unknown parent sync", errorData, res.err);
|