@lodestar/beacon-node 1.52.0-dev.025dabac49 → 1.52.0-dev.0f379f3b22
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 +45 -34
- package/lib/api/impl/beacon/blocks/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 +3 -1
- package/lib/api/impl/beacon/pool/index.js.map +1 -1
- package/lib/api/impl/validator/index.d.ts.map +1 -1
- package/lib/api/impl/validator/index.js +4 -3
- package/lib/api/impl/validator/index.js.map +1 -1
- package/lib/chain/chain.d.ts.map +1 -1
- package/lib/chain/chain.js +12 -6
- package/lib/chain/chain.js.map +1 -1
- package/lib/chain/errors/executionPayloadBid.d.ts +3 -2
- package/lib/chain/errors/executionPayloadBid.d.ts.map +1 -1
- package/lib/chain/errors/executionPayloadBid.js +1 -1
- package/lib/chain/errors/executionPayloadBid.js.map +1 -1
- package/lib/chain/opPools/opPool.js +6 -6
- package/lib/chain/opPools/opPool.js.map +1 -1
- package/lib/chain/seenCache/seenExecutionPayloadBids.d.ts +13 -4
- package/lib/chain/seenCache/seenExecutionPayloadBids.d.ts.map +1 -1
- package/lib/chain/seenCache/seenExecutionPayloadBids.js +13 -12
- package/lib/chain/seenCache/seenExecutionPayloadBids.js.map +1 -1
- package/lib/chain/validation/executionPayloadBid.js +29 -11
- package/lib/chain/validation/executionPayloadBid.js.map +1 -1
- package/lib/network/gossip/topic.d.ts +1 -7
- package/lib/network/gossip/topic.d.ts.map +1 -1
- package/lib/network/gossip/topic.js +0 -13
- package/lib/network/gossip/topic.js.map +1 -1
- package/lib/network/network.d.ts +1 -0
- package/lib/network/network.d.ts.map +1 -1
- package/lib/network/network.js +20 -11
- package/lib/network/network.js.map +1 -1
- package/lib/network/processor/gossipHandlers.d.ts.map +1 -1
- package/lib/network/processor/gossipHandlers.js +4 -1
- package/lib/network/processor/gossipHandlers.js.map +1 -1
- package/lib/network/processor/gossipValidatorFn.d.ts.map +1 -1
- package/lib/network/processor/gossipValidatorFn.js +4 -1
- package/lib/network/processor/gossipValidatorFn.js.map +1 -1
- package/lib/network/reqresp/utils/collect.d.ts +4 -4
- package/lib/network/reqresp/utils/collect.d.ts.map +1 -1
- package/lib/network/reqresp/utils/collect.js +9 -8
- package/lib/network/reqresp/utils/collect.js.map +1 -1
- package/lib/network/reqresp/utils/collectSequentialBlocksInRange.d.ts +1 -1
- package/lib/network/reqresp/utils/collectSequentialBlocksInRange.d.ts.map +1 -1
- package/lib/network/reqresp/utils/collectSequentialBlocksInRange.js +2 -2
- package/lib/network/reqresp/utils/collectSequentialBlocksInRange.js.map +1 -1
- package/lib/sync/unknownBlock.d.ts.map +1 -1
- package/lib/sync/unknownBlock.js +2 -1
- package/lib/sync/unknownBlock.js.map +1 -1
- package/package.json +16 -16
- package/src/api/impl/beacon/blocks/index.ts +54 -42
- package/src/api/impl/beacon/pool/index.ts +9 -7
- package/src/api/impl/validator/index.ts +4 -2
- package/src/chain/chain.ts +12 -6
- package/src/chain/errors/executionPayloadBid.ts +3 -2
- package/src/chain/opPools/opPool.ts +6 -6
- package/src/chain/seenCache/seenExecutionPayloadBids.ts +35 -15
- package/src/chain/validation/executionPayloadBid.ts +39 -11
- package/src/network/gossip/topic.ts +1 -14
- package/src/network/network.ts +33 -11
- package/src/network/processor/gossipHandlers.ts +10 -7
- package/src/network/processor/gossipValidatorFn.ts +4 -0
- package/src/network/reqresp/utils/collect.ts +16 -8
- package/src/network/reqresp/utils/collectSequentialBlocksInRange.ts +3 -2
- package/src/sync/unknownBlock.ts +2 -1
|
@@ -7,7 +7,7 @@ export enum ExecutionPayloadBidErrorCode {
|
|
|
7
7
|
NON_ZERO_EXECUTION_PAYMENT = "EXECUTION_PAYLOAD_BID_ERROR_NON_ZERO_EXECUTION_PAYMENT",
|
|
8
8
|
BLOCK_HASH_EQUALS_PARENT_BLOCK_HASH = "EXECUTION_PAYLOAD_BID_ERROR_BLOCK_HASH_EQUALS_PARENT_BLOCK_HASH",
|
|
9
9
|
INCOMPATIBLE_WITH_HEAD = "EXECUTION_PAYLOAD_BID_ERROR_INCOMPATIBLE_WITH_HEAD",
|
|
10
|
-
|
|
10
|
+
BID_LIMIT_REACHED = "EXECUTION_PAYLOAD_BID_ERROR_BID_LIMIT_REACHED",
|
|
11
11
|
BID_TOO_LOW = "EXECUTION_PAYLOAD_BID_ERROR_BID_TOO_LOW",
|
|
12
12
|
BID_TOO_HIGH = "EXECUTION_PAYLOAD_BID_ERROR_BID_TOO_HIGH",
|
|
13
13
|
BUILDER_MAY_EXIT = "EXECUTION_PAYLOAD_BID_ERROR_BUILDER_MAY_EXIT",
|
|
@@ -46,11 +46,12 @@ export type ExecutionPayloadBidErrorType =
|
|
|
46
46
|
headBlockRoot: RootHex;
|
|
47
47
|
}
|
|
48
48
|
| {
|
|
49
|
-
code: ExecutionPayloadBidErrorCode.
|
|
49
|
+
code: ExecutionPayloadBidErrorCode.BID_LIMIT_REACHED;
|
|
50
50
|
builderIndex: BuilderIndex;
|
|
51
51
|
slot: Slot;
|
|
52
52
|
parentBlockRoot: RootHex;
|
|
53
53
|
parentBlockHash: RootHex;
|
|
54
|
+
bidLimit: number;
|
|
54
55
|
}
|
|
55
56
|
| {code: ExecutionPayloadBidErrorCode.BID_TOO_LOW; bidValue: number; currentHighestBid: number}
|
|
56
57
|
| {code: ExecutionPayloadBidErrorCode.BID_TOO_HIGH; bidValue: number; builderBalance: number}
|
|
@@ -290,7 +290,7 @@ export class OpPool {
|
|
|
290
290
|
const endAttesterSlashings = stepsMetrics?.startTimer();
|
|
291
291
|
const attesterSlashings: AttesterSlashing[] = [];
|
|
292
292
|
const maxAttesterSlashings = stateFork >= ForkSeq.electra ? MAX_ATTESTER_SLASHINGS_ELECTRA : MAX_ATTESTER_SLASHINGS;
|
|
293
|
-
|
|
293
|
+
for (const [key, attesterSlashing] of this.attesterSlashings) {
|
|
294
294
|
const domains = getAttesterSlashingSignatureDomains(this.config, state.slot, attesterSlashing.attesterSlashing);
|
|
295
295
|
if (!attesterSlashing.verifiedDomains.every((domain, i) => byteArrayEquals(domain, domains[i]))) {
|
|
296
296
|
this.attesterSlashings.delete(key);
|
|
@@ -300,18 +300,15 @@ export class OpPool {
|
|
|
300
300
|
const slashableIndices = new Set<ValidatorIndex>();
|
|
301
301
|
for (let i = 0; i < attesterSlashing.intersectingIndices.length; i++) {
|
|
302
302
|
const index = attesterSlashing.intersectingIndices[i];
|
|
303
|
-
//
|
|
303
|
+
// Covered by an earlier slashing in this block, the remaining indices may still be slashable
|
|
304
304
|
if (toBeSlashedIndices.has(index)) {
|
|
305
|
-
continue
|
|
305
|
+
continue;
|
|
306
306
|
}
|
|
307
307
|
|
|
308
308
|
const validator = state.getValidator(index);
|
|
309
309
|
if (isSlashableAtEpoch(validator, stateEpoch)) {
|
|
310
310
|
slashableIndices.add(index);
|
|
311
311
|
}
|
|
312
|
-
if (attesterSlashings.length >= maxAttesterSlashings) {
|
|
313
|
-
break attesterSlashing;
|
|
314
|
-
}
|
|
315
312
|
}
|
|
316
313
|
|
|
317
314
|
// If there were slashable indices in this slashing
|
|
@@ -321,6 +318,9 @@ export class OpPool {
|
|
|
321
318
|
for (const index of slashableIndices) {
|
|
322
319
|
toBeSlashedIndices.add(index);
|
|
323
320
|
}
|
|
321
|
+
if (attesterSlashings.length >= maxAttesterSlashings) {
|
|
322
|
+
break;
|
|
323
|
+
}
|
|
324
324
|
}
|
|
325
325
|
}
|
|
326
326
|
endAttesterSlashings?.({
|
|
@@ -6,38 +6,58 @@ import {MapDef} from "@lodestar/utils";
|
|
|
6
6
|
*/
|
|
7
7
|
const SLOTS_RETAINED = 2;
|
|
8
8
|
|
|
9
|
+
export type SeenBuilderBids = {
|
|
10
|
+
/** Number of valid bids seen */
|
|
11
|
+
count: number;
|
|
12
|
+
/**
|
|
13
|
+
* The builder's bid limit. Bids for the same slot and parent root are validated against the same state,
|
|
14
|
+
* so it is known without the state once a bid was valid
|
|
15
|
+
*/
|
|
16
|
+
limit: number;
|
|
17
|
+
};
|
|
18
|
+
|
|
9
19
|
/**
|
|
10
|
-
*
|
|
20
|
+
* Counts the valid execution payload bids seen per
|
|
11
21
|
* (slot, builder, parent block hash, parent block root).
|
|
12
22
|
*/
|
|
13
23
|
export class SeenExecutionPayloadBids {
|
|
14
|
-
private readonly
|
|
15
|
-
() => new MapDef<BuilderIndex,
|
|
24
|
+
private readonly bidsByBranchByBuilderBySlot = new MapDef<Slot, MapDef<BuilderIndex, Map<string, SeenBuilderBids>>>(
|
|
25
|
+
() => new MapDef<BuilderIndex, Map<string, SeenBuilderBids>>(() => new Map<string, SeenBuilderBids>())
|
|
16
26
|
);
|
|
17
27
|
private lowestPermissibleSlot: Slot = 0;
|
|
18
28
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
29
|
+
get(
|
|
30
|
+
slot: Slot,
|
|
31
|
+
builderIndex: BuilderIndex,
|
|
32
|
+
parentBlockHash: RootHex,
|
|
33
|
+
parentBlockRoot: RootHex
|
|
34
|
+
): SeenBuilderBids | undefined {
|
|
35
|
+
return this.bidsByBranchByBuilderBySlot
|
|
36
|
+
.get(slot)
|
|
37
|
+
?.get(builderIndex)
|
|
38
|
+
?.get(branchKey(parentBlockHash, parentBlockRoot));
|
|
24
39
|
}
|
|
25
40
|
|
|
26
|
-
add(
|
|
41
|
+
add(
|
|
42
|
+
slot: Slot,
|
|
43
|
+
builderIndex: BuilderIndex,
|
|
44
|
+
parentBlockHash: RootHex,
|
|
45
|
+
parentBlockRoot: RootHex,
|
|
46
|
+
bidLimit: number
|
|
47
|
+
): void {
|
|
27
48
|
if (slot < this.lowestPermissibleSlot) {
|
|
28
49
|
throw Error(`slot ${slot} < lowestPermissibleSlot ${this.lowestPermissibleSlot}`);
|
|
29
50
|
}
|
|
30
|
-
this.
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
.add(branchKey(parentBlockHash, parentBlockRoot));
|
|
51
|
+
const bidsByBranch = this.bidsByBranchByBuilderBySlot.getOrDefault(slot).getOrDefault(builderIndex);
|
|
52
|
+
const key = branchKey(parentBlockHash, parentBlockRoot);
|
|
53
|
+
bidsByBranch.set(key, {count: (bidsByBranch.get(key)?.count ?? 0) + 1, limit: bidLimit});
|
|
34
54
|
}
|
|
35
55
|
|
|
36
56
|
prune(currentSlot: Slot): void {
|
|
37
57
|
this.lowestPermissibleSlot = Math.max(currentSlot - SLOTS_RETAINED, 0);
|
|
38
|
-
for (const slot of this.
|
|
58
|
+
for (const slot of this.bidsByBranchByBuilderBySlot.keys()) {
|
|
39
59
|
if (slot < this.lowestPermissibleSlot) {
|
|
40
|
-
this.
|
|
60
|
+
this.bidsByBranchByBuilderBySlot.delete(slot);
|
|
41
61
|
}
|
|
42
62
|
}
|
|
43
63
|
}
|
|
@@ -165,17 +165,23 @@ async function validateExecutionPayloadBid(
|
|
|
165
165
|
});
|
|
166
166
|
}
|
|
167
167
|
|
|
168
|
-
// [IGNORE]
|
|
169
|
-
// the
|
|
170
|
-
//
|
|
171
|
-
|
|
172
|
-
|
|
168
|
+
// [IGNORE] The builder has not reached its bid limit, checked against the limit of its last valid bid.
|
|
169
|
+
// Bids for the same slot and parent root are validated against the same state, so bids past the
|
|
170
|
+
// limit can be dropped before state regeneration and the other expensive validation steps.
|
|
171
|
+
const seenBids = chain.seenExecutionPayloadBids.get(
|
|
172
|
+
bid.slot,
|
|
173
|
+
bid.builderIndex,
|
|
174
|
+
bidParentBlockHash,
|
|
175
|
+
bidParentBlockRoot
|
|
176
|
+
);
|
|
177
|
+
if (seenBids !== undefined && seenBids.count >= seenBids.limit) {
|
|
173
178
|
throw new ExecutionPayloadBidError(GossipAction.IGNORE, {
|
|
174
|
-
code: ExecutionPayloadBidErrorCode.
|
|
179
|
+
code: ExecutionPayloadBidErrorCode.BID_LIMIT_REACHED,
|
|
175
180
|
builderIndex: bid.builderIndex,
|
|
176
181
|
slot: bid.slot,
|
|
177
182
|
parentBlockRoot: bidParentBlockRoot,
|
|
178
183
|
parentBlockHash: bidParentBlockHash,
|
|
184
|
+
bidLimit: seenBids.limit,
|
|
179
185
|
});
|
|
180
186
|
}
|
|
181
187
|
|
|
@@ -366,6 +372,24 @@ async function validateExecutionPayloadBid(
|
|
|
366
372
|
});
|
|
367
373
|
}
|
|
368
374
|
|
|
375
|
+
// [IGNORE] The builder has not reached its bid limit for the tuple
|
|
376
|
+
// `(bid.slot, bid.parent_block_hash, bid.parent_block_root)` -- i.e. one bid per ETH of builder balance
|
|
377
|
+
// not owed in pending withdrawals, `get_builder_bid_limit(state, bid.builder_index)`.
|
|
378
|
+
const bidLimit = state.getBuilderBidLimit(bid.builderIndex);
|
|
379
|
+
if (
|
|
380
|
+
(chain.seenExecutionPayloadBids.get(bid.slot, bid.builderIndex, bidParentBlockHash, bidParentBlockRoot)?.count ??
|
|
381
|
+
0) >= bidLimit
|
|
382
|
+
) {
|
|
383
|
+
throw new ExecutionPayloadBidError(GossipAction.IGNORE, {
|
|
384
|
+
code: ExecutionPayloadBidErrorCode.BID_LIMIT_REACHED,
|
|
385
|
+
builderIndex: bid.builderIndex,
|
|
386
|
+
slot: bid.slot,
|
|
387
|
+
parentBlockRoot: bidParentBlockRoot,
|
|
388
|
+
parentBlockHash: bidParentBlockHash,
|
|
389
|
+
bidLimit,
|
|
390
|
+
});
|
|
391
|
+
}
|
|
392
|
+
|
|
369
393
|
// [IGNORE] `bid.value` is less or equal than the builder's excess balance --
|
|
370
394
|
// i.e. `can_builder_cover_bid(state, builder_index, amount)` returns `True`.
|
|
371
395
|
if (!state.canBuilderCoverBid(bid.builderIndex, bid.value)) {
|
|
@@ -426,20 +450,24 @@ async function validateExecutionPayloadBid(
|
|
|
426
450
|
});
|
|
427
451
|
}
|
|
428
452
|
|
|
429
|
-
// Repeat the
|
|
430
|
-
// for the same builder and tuple from
|
|
431
|
-
if (
|
|
453
|
+
// Repeat the bid limit check after the awaited signature verification to prevent concurrent bids
|
|
454
|
+
// for the same builder and tuple from all passing validation.
|
|
455
|
+
if (
|
|
456
|
+
(chain.seenExecutionPayloadBids.get(bid.slot, bid.builderIndex, bidParentBlockHash, bidParentBlockRoot)?.count ??
|
|
457
|
+
0) >= bidLimit
|
|
458
|
+
) {
|
|
432
459
|
throw new ExecutionPayloadBidError(GossipAction.IGNORE, {
|
|
433
|
-
code: ExecutionPayloadBidErrorCode.
|
|
460
|
+
code: ExecutionPayloadBidErrorCode.BID_LIMIT_REACHED,
|
|
434
461
|
builderIndex: bid.builderIndex,
|
|
435
462
|
slot: bid.slot,
|
|
436
463
|
parentBlockRoot: bidParentBlockRoot,
|
|
437
464
|
parentBlockHash: bidParentBlockHash,
|
|
465
|
+
bidLimit,
|
|
438
466
|
});
|
|
439
467
|
}
|
|
440
468
|
|
|
441
469
|
// Valid
|
|
442
|
-
chain.seenExecutionPayloadBids.add(bid.slot, bid.builderIndex, bidParentBlockHash, bidParentBlockRoot);
|
|
470
|
+
chain.seenExecutionPayloadBids.add(bid.slot, bid.builderIndex, bidParentBlockHash, bidParentBlockRoot, bidLimit);
|
|
443
471
|
|
|
444
472
|
return {proposerIndex: proposerPreferences.message.validatorIndex};
|
|
445
473
|
}
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
isForkPostGloas,
|
|
13
13
|
} from "@lodestar/params";
|
|
14
14
|
import {TypeSizes} from "@lodestar/reqresp";
|
|
15
|
-
import {
|
|
15
|
+
import {SingleAttestation, ssz, sszTypesFor} from "@lodestar/types";
|
|
16
16
|
import {GossipAction, GossipActionError, GossipErrorCode} from "../../chain/errors/gossipValidation.js";
|
|
17
17
|
import {computeMaxGloasDataColumnSidecarSize} from "../../util/sszBytes.js";
|
|
18
18
|
import {NetworkConfig} from "../networkConfig.js";
|
|
@@ -173,19 +173,6 @@ export function sszDeserialize<T extends GossipTopic>(topic: T, serializedData:
|
|
|
173
173
|
}
|
|
174
174
|
}
|
|
175
175
|
|
|
176
|
-
/**
|
|
177
|
-
* @deprecated
|
|
178
|
-
* Deserialize a gossip serialized data into an Attestation object.
|
|
179
|
-
* No longer used post-electra. Use `sszDeserializeSingleAttestation` instead
|
|
180
|
-
*/
|
|
181
|
-
export function sszDeserializeAttestation(fork: ForkName, serializedData: Uint8Array): Attestation {
|
|
182
|
-
try {
|
|
183
|
-
return sszTypesFor(fork).Attestation.deserialize(serializedData);
|
|
184
|
-
} catch (_e) {
|
|
185
|
-
throw new GossipActionError(GossipAction.REJECT, {code: GossipErrorCode.INVALID_SERIALIZED_BYTES_ERROR_CODE});
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
|
|
189
176
|
/**
|
|
190
177
|
* Deserialize a gossip seralized data into an SingleAttestation object.
|
|
191
178
|
*/
|
package/src/network/network.ts
CHANGED
|
@@ -596,7 +596,8 @@ export class Network implements INetwork {
|
|
|
596
596
|
request
|
|
597
597
|
),
|
|
598
598
|
request,
|
|
599
|
-
this.chain.serializedCache
|
|
599
|
+
this.chain.serializedCache,
|
|
600
|
+
() => this.reportInvalidResponse(peerId)
|
|
600
601
|
);
|
|
601
602
|
}
|
|
602
603
|
|
|
@@ -611,7 +612,8 @@ export class Network implements INetwork {
|
|
|
611
612
|
),
|
|
612
613
|
request.length,
|
|
613
614
|
responseSszTypeByMethod[ReqRespMethod.BeaconBlocksByRoot],
|
|
614
|
-
this.chain.serializedCache
|
|
615
|
+
this.chain.serializedCache,
|
|
616
|
+
() => this.reportInvalidResponse(peerId)
|
|
615
617
|
);
|
|
616
618
|
}
|
|
617
619
|
|
|
@@ -623,28 +625,32 @@ export class Network implements INetwork {
|
|
|
623
625
|
this.sendReqRespRequest(peerId, ReqRespMethod.BeaconBlocksByHead, [Version.V1], request),
|
|
624
626
|
Math.min(request.count, this.config.MAX_REQUEST_BLOCKS_DENEB),
|
|
625
627
|
responseSszTypeByMethod[ReqRespMethod.BeaconBlocksByHead],
|
|
626
|
-
this.chain.serializedCache
|
|
628
|
+
this.chain.serializedCache,
|
|
629
|
+
() => this.reportInvalidResponse(peerId)
|
|
627
630
|
);
|
|
628
631
|
}
|
|
629
632
|
|
|
630
633
|
async sendLightClientBootstrap(peerId: PeerIdStr, request: Root): Promise<LightClientBootstrap> {
|
|
631
634
|
return collectExactOneTyped(
|
|
632
635
|
this.sendReqRespRequest(peerId, ReqRespMethod.LightClientBootstrap, [Version.V1], request),
|
|
633
|
-
responseSszTypeByMethod[ReqRespMethod.LightClientBootstrap]
|
|
636
|
+
responseSszTypeByMethod[ReqRespMethod.LightClientBootstrap],
|
|
637
|
+
() => this.reportInvalidResponse(peerId)
|
|
634
638
|
);
|
|
635
639
|
}
|
|
636
640
|
|
|
637
641
|
async sendLightClientOptimisticUpdate(peerId: PeerIdStr): Promise<LightClientOptimisticUpdate> {
|
|
638
642
|
return collectExactOneTyped(
|
|
639
643
|
this.sendReqRespRequest(peerId, ReqRespMethod.LightClientOptimisticUpdate, [Version.V1], null),
|
|
640
|
-
responseSszTypeByMethod[ReqRespMethod.LightClientOptimisticUpdate]
|
|
644
|
+
responseSszTypeByMethod[ReqRespMethod.LightClientOptimisticUpdate],
|
|
645
|
+
() => this.reportInvalidResponse(peerId)
|
|
641
646
|
);
|
|
642
647
|
}
|
|
643
648
|
|
|
644
649
|
async sendLightClientFinalityUpdate(peerId: PeerIdStr): Promise<LightClientFinalityUpdate> {
|
|
645
650
|
return collectExactOneTyped(
|
|
646
651
|
this.sendReqRespRequest(peerId, ReqRespMethod.LightClientFinalityUpdate, [Version.V1], null),
|
|
647
|
-
responseSszTypeByMethod[ReqRespMethod.LightClientFinalityUpdate]
|
|
652
|
+
responseSszTypeByMethod[ReqRespMethod.LightClientFinalityUpdate],
|
|
653
|
+
() => this.reportInvalidResponse(peerId)
|
|
648
654
|
);
|
|
649
655
|
}
|
|
650
656
|
|
|
@@ -655,7 +661,9 @@ export class Network implements INetwork {
|
|
|
655
661
|
return collectMaxResponseTyped(
|
|
656
662
|
this.sendReqRespRequest(peerId, ReqRespMethod.LightClientUpdatesByRange, [Version.V1], request),
|
|
657
663
|
request.count,
|
|
658
|
-
responseSszTypeByMethod[ReqRespMethod.LightClientUpdatesByRange]
|
|
664
|
+
responseSszTypeByMethod[ReqRespMethod.LightClientUpdatesByRange],
|
|
665
|
+
undefined,
|
|
666
|
+
() => this.reportInvalidResponse(peerId)
|
|
659
667
|
);
|
|
660
668
|
}
|
|
661
669
|
|
|
@@ -666,7 +674,9 @@ export class Network implements INetwork {
|
|
|
666
674
|
return collectMaxResponseTyped(
|
|
667
675
|
this.sendReqRespRequest(peerId, ReqRespMethod.DataColumnSidecarsByRange, [Version.V1], request),
|
|
668
676
|
request.count * request.columns.length,
|
|
669
|
-
responseSszTypeByMethod[ReqRespMethod.DataColumnSidecarsByRange]
|
|
677
|
+
responseSszTypeByMethod[ReqRespMethod.DataColumnSidecarsByRange],
|
|
678
|
+
undefined,
|
|
679
|
+
() => this.reportInvalidResponse(peerId)
|
|
670
680
|
);
|
|
671
681
|
}
|
|
672
682
|
|
|
@@ -678,7 +688,8 @@ export class Network implements INetwork {
|
|
|
678
688
|
this.sendReqRespRequest(peerId, ReqRespMethod.DataColumnSidecarsByRoot, [Version.V1], request),
|
|
679
689
|
request.reduce((total, {columns}) => total + columns.length, 0),
|
|
680
690
|
responseSszTypeByMethod[ReqRespMethod.DataColumnSidecarsByRoot],
|
|
681
|
-
this.chain.serializedCache
|
|
691
|
+
this.chain.serializedCache,
|
|
692
|
+
() => this.reportInvalidResponse(peerId)
|
|
682
693
|
);
|
|
683
694
|
}
|
|
684
695
|
|
|
@@ -689,7 +700,9 @@ export class Network implements INetwork {
|
|
|
689
700
|
return collectMaxResponseTyped(
|
|
690
701
|
this.sendReqRespRequest(peerId, ReqRespMethod.ExecutionPayloadEnvelopesByRange, [Version.V1], request),
|
|
691
702
|
request.count,
|
|
692
|
-
responseSszTypeByMethod[ReqRespMethod.ExecutionPayloadEnvelopesByRange]
|
|
703
|
+
responseSszTypeByMethod[ReqRespMethod.ExecutionPayloadEnvelopesByRange],
|
|
704
|
+
undefined,
|
|
705
|
+
() => this.reportInvalidResponse(peerId)
|
|
693
706
|
);
|
|
694
707
|
}
|
|
695
708
|
|
|
@@ -701,10 +714,19 @@ export class Network implements INetwork {
|
|
|
701
714
|
this.sendReqRespRequest(peerId, ReqRespMethod.ExecutionPayloadEnvelopesByRoot, [Version.V1], request),
|
|
702
715
|
request.length,
|
|
703
716
|
responseSszTypeByMethod[ReqRespMethod.ExecutionPayloadEnvelopesByRoot],
|
|
704
|
-
this.chain.serializedCache
|
|
717
|
+
this.chain.serializedCache,
|
|
718
|
+
() => this.reportInvalidResponse(peerId)
|
|
705
719
|
);
|
|
706
720
|
}
|
|
707
721
|
|
|
722
|
+
private async reportInvalidResponse(peerId: PeerIdStr): Promise<void> {
|
|
723
|
+
try {
|
|
724
|
+
await this.core.reportPeer(peerId, PeerAction.LowToleranceError, "InvalidResponseSsz");
|
|
725
|
+
} catch (error) {
|
|
726
|
+
this.logger.debug("Failed to report invalid response", {peerId}, error as Error);
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
|
|
708
730
|
private sendReqRespRequest<Req>(
|
|
709
731
|
peerId: PeerIdStr,
|
|
710
732
|
method: ReqRespMethod,
|
|
@@ -1301,13 +1301,16 @@ function getSequentialHandlers(modules: ValidatorFnsModules, options: GossipHand
|
|
|
1301
1301
|
}
|
|
1302
1302
|
}
|
|
1303
1303
|
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1304
|
+
// Gossip accepts adjacent slots within the clock disparity but fork choice only counts the current slot
|
|
1305
|
+
if (payloadAttestationMessage.data.slot === chain.clock.currentSlot) {
|
|
1306
|
+
chain.forkChoice.notifyPtcMessages(
|
|
1307
|
+
toRootHex(payloadAttestationMessage.data.beaconBlockRoot),
|
|
1308
|
+
payloadAttestationMessage.data.slot,
|
|
1309
|
+
validationResult.validatorCommitteeIndices,
|
|
1310
|
+
payloadAttestationMessage.data.payloadPresent,
|
|
1311
|
+
payloadAttestationMessage.data.blobDataAvailable
|
|
1312
|
+
);
|
|
1313
|
+
}
|
|
1311
1314
|
|
|
1312
1315
|
chain.emitter.emit(routes.events.EventType.payloadAttestationMessage, {
|
|
1313
1316
|
version: config.getForkName(payloadAttestationMessage.data.slot),
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
ExecutionPayloadEnvelopeErrorCode,
|
|
13
13
|
GossipAction,
|
|
14
14
|
GossipActionError,
|
|
15
|
+
GossipErrorCode,
|
|
15
16
|
InclusionListErrorCode,
|
|
16
17
|
PayloadAttestationErrorCode,
|
|
17
18
|
ProposerPreferencesErrorCode,
|
|
@@ -116,6 +117,9 @@ const gossipRejectPeerAction: Record<GossipType, RejectPeerActionRule> = {
|
|
|
116
117
|
};
|
|
117
118
|
|
|
118
119
|
export function rejectPeerAction(type: GossipType, code: string): PeerAction {
|
|
120
|
+
if (code === GossipErrorCode.INVALID_SERIALIZED_BYTES_ERROR_CODE) {
|
|
121
|
+
return PeerAction.LowToleranceError;
|
|
122
|
+
}
|
|
119
123
|
const rule = gossipRejectPeerAction[type];
|
|
120
124
|
return rule.byCode?.[code] ?? rule.default;
|
|
121
125
|
}
|
|
@@ -12,11 +12,12 @@ import {ResponseTypeGetter} from "../types.js";
|
|
|
12
12
|
*/
|
|
13
13
|
export async function collectExactOneTyped<T>(
|
|
14
14
|
source: AsyncIterable<ResponseIncoming>,
|
|
15
|
-
typeFn: ResponseTypeGetter<T
|
|
15
|
+
typeFn: ResponseTypeGetter<T>,
|
|
16
|
+
onInvalidResponse?: (chunk: ResponseIncoming) => void
|
|
16
17
|
): Promise<T> {
|
|
17
18
|
for await (const chunk of source) {
|
|
18
19
|
const type = typeFn(chunk.fork, chunk.protocolVersion);
|
|
19
|
-
const response = sszDeserializeResponse(type, chunk
|
|
20
|
+
const response = sszDeserializeResponse(type, chunk, onInvalidResponse);
|
|
20
21
|
return response;
|
|
21
22
|
}
|
|
22
23
|
throw new RequestError({code: RequestErrorCode.EMPTY_RESPONSE});
|
|
@@ -33,13 +34,14 @@ export async function collectMaxResponseTyped<T>(
|
|
|
33
34
|
source: AsyncIterable<ResponseIncoming>,
|
|
34
35
|
maxResponses: number,
|
|
35
36
|
typeFn: ResponseTypeGetter<T>,
|
|
36
|
-
serializedCache?: SerializedCache
|
|
37
|
+
serializedCache?: SerializedCache,
|
|
38
|
+
onInvalidResponse?: (chunk: ResponseIncoming) => void
|
|
37
39
|
): Promise<T[]> {
|
|
38
40
|
// else: zero or more responses
|
|
39
41
|
const responses: T[] = [];
|
|
40
42
|
for await (const chunk of source) {
|
|
41
43
|
const type = typeFn(chunk.fork, chunk.protocolVersion);
|
|
42
|
-
const response = sszDeserializeResponse(type, chunk
|
|
44
|
+
const response = sszDeserializeResponse(type, chunk, onInvalidResponse);
|
|
43
45
|
// optionally cache the serialized response if the cache is available
|
|
44
46
|
serializedCache?.set(response as object, chunk.data);
|
|
45
47
|
responses.push(response);
|
|
@@ -62,13 +64,14 @@ export async function collectMaxResponseTypedWithBytes<T>(
|
|
|
62
64
|
source: AsyncIterable<ResponseIncoming>,
|
|
63
65
|
maxResponses: number,
|
|
64
66
|
typeFn: ResponseTypeGetter<T>,
|
|
65
|
-
serializedCache?: SerializedCache
|
|
67
|
+
serializedCache?: SerializedCache,
|
|
68
|
+
onInvalidResponse?: (chunk: ResponseIncoming) => void
|
|
66
69
|
): Promise<T[]> {
|
|
67
70
|
// else: zero or more responses
|
|
68
71
|
const responses: T[] = [];
|
|
69
72
|
for await (const chunk of source) {
|
|
70
73
|
const type = typeFn(chunk.fork, chunk.protocolVersion);
|
|
71
|
-
const data = sszDeserializeResponse(type, chunk
|
|
74
|
+
const data = sszDeserializeResponse(type, chunk, onInvalidResponse);
|
|
72
75
|
responses.push(data);
|
|
73
76
|
// optionally cache the serialized response if the cache is available
|
|
74
77
|
serializedCache?.set(data as object, chunk.data);
|
|
@@ -81,10 +84,15 @@ export async function collectMaxResponseTypedWithBytes<T>(
|
|
|
81
84
|
}
|
|
82
85
|
|
|
83
86
|
/** Light wrapper on type to wrap deserialize errors */
|
|
84
|
-
export function sszDeserializeResponse<T>(
|
|
87
|
+
export function sszDeserializeResponse<T>(
|
|
88
|
+
type: Type<T>,
|
|
89
|
+
chunk: ResponseIncoming,
|
|
90
|
+
onInvalidResponse?: (chunk: ResponseIncoming) => void
|
|
91
|
+
): T {
|
|
85
92
|
try {
|
|
86
|
-
return type.deserialize(
|
|
93
|
+
return type.deserialize(chunk.data);
|
|
87
94
|
} catch (e) {
|
|
95
|
+
onInvalidResponse?.(chunk);
|
|
88
96
|
throw new RequestError({code: RequestErrorCode.INVALID_RESPONSE_SSZ, errorMessage: (e as Error).message});
|
|
89
97
|
}
|
|
90
98
|
}
|
|
@@ -12,13 +12,14 @@ import {sszDeserializeResponse} from "./collect.js";
|
|
|
12
12
|
export async function collectSequentialBlocksInRange(
|
|
13
13
|
blockStream: AsyncIterable<ResponseIncoming>,
|
|
14
14
|
{count, startSlot}: Pick<phase0.BeaconBlocksByRangeRequest, "count" | "startSlot">,
|
|
15
|
-
serializedCache?: SerializedCache
|
|
15
|
+
serializedCache?: SerializedCache,
|
|
16
|
+
onInvalidResponse?: (chunk: ResponseIncoming) => void
|
|
16
17
|
): Promise<SignedBeaconBlock[]> {
|
|
17
18
|
const blocks: SignedBeaconBlock[] = [];
|
|
18
19
|
|
|
19
20
|
for await (const chunk of blockStream) {
|
|
20
21
|
const blockType = responseSszTypeByMethod[ReqRespMethod.BeaconBlocksByRange](chunk.fork, chunk.protocolVersion);
|
|
21
|
-
const block = sszDeserializeResponse(blockType, chunk
|
|
22
|
+
const block = sszDeserializeResponse(blockType, chunk, onInvalidResponse);
|
|
22
23
|
|
|
23
24
|
const blockSlot = block.message.slot;
|
|
24
25
|
|
package/src/sync/unknownBlock.ts
CHANGED
|
@@ -376,7 +376,8 @@ export class BlockInputSync {
|
|
|
376
376
|
// because the payload at the finalized block is not finalized
|
|
377
377
|
const finalizedSlot = this.chain.forkChoice.getFinalizedBlock().slot;
|
|
378
378
|
const nowSec = Date.now() / 1000;
|
|
379
|
-
const
|
|
379
|
+
const slotDurationMs = this.config.getSlotDurationMs(this.config.getForkName(this.chain.clock.currentSlot));
|
|
380
|
+
const maxSecInCache = (PRUNE_UNRESOLVED_SLOT_EPOCHS * SLOTS_PER_EPOCH * slotDurationMs) / 1000;
|
|
380
381
|
|
|
381
382
|
let belowFinalizedPayloads = 0;
|
|
382
383
|
let agedOutPayloads = 0;
|