@lodestar/beacon-node 2.1.0-dev.05a73f5e55 → 2.1.0-dev.07a42946c1
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 +1 -3
- package/lib/api/impl/beacon/blocks/index.js.map +1 -1
- package/lib/chain/ColumnReconstructionTracker.d.ts +3 -0
- package/lib/chain/ColumnReconstructionTracker.d.ts.map +1 -1
- package/lib/chain/ColumnReconstructionTracker.js +3 -1
- package/lib/chain/ColumnReconstructionTracker.js.map +1 -1
- package/lib/chain/GetBlobsTracker.d.ts +3 -0
- package/lib/chain/GetBlobsTracker.d.ts.map +1 -1
- package/lib/chain/GetBlobsTracker.js +3 -1
- package/lib/chain/GetBlobsTracker.js.map +1 -1
- package/lib/chain/chain.d.ts +2 -1
- package/lib/chain/chain.d.ts.map +1 -1
- package/lib/chain/chain.js +5 -1
- package/lib/chain/chain.js.map +1 -1
- package/lib/chain/errors/dataColumnSidecarError.d.ts +7 -0
- package/lib/chain/errors/dataColumnSidecarError.d.ts.map +1 -1
- package/lib/chain/errors/dataColumnSidecarError.js +1 -0
- package/lib/chain/errors/dataColumnSidecarError.js.map +1 -1
- package/lib/chain/interface.d.ts +2 -1
- package/lib/chain/interface.d.ts.map +1 -1
- package/lib/chain/interface.js.map +1 -1
- package/lib/chain/seenCache/index.d.ts +1 -0
- package/lib/chain/seenCache/index.d.ts.map +1 -1
- package/lib/chain/seenCache/index.js +1 -0
- package/lib/chain/seenCache/index.js.map +1 -1
- package/lib/chain/seenCache/seenBlockProposers.d.ts +1 -0
- package/lib/chain/seenCache/seenBlockProposers.d.ts.map +1 -1
- package/lib/chain/seenCache/seenBlockProposers.js +5 -1
- package/lib/chain/seenCache/seenBlockProposers.js.map +1 -1
- package/lib/chain/seenCache/seenDataColumnSidecars.d.ts +16 -0
- package/lib/chain/seenCache/seenDataColumnSidecars.d.ts.map +1 -0
- package/lib/chain/seenCache/seenDataColumnSidecars.js +56 -0
- package/lib/chain/seenCache/seenDataColumnSidecars.js.map +1 -0
- package/lib/chain/validation/attestation.d.ts.map +1 -1
- package/lib/chain/validation/attestation.js +4 -2
- 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 +12 -2
- package/lib/chain/validation/block.js.map +1 -1
- package/lib/chain/validation/dataColumnSidecar.js +1 -1
- package/lib/chain/validation/dataColumnSidecar.js.map +1 -1
- package/lib/network/forks.d.ts +2 -2
- package/lib/network/forks.d.ts.map +1 -1
- package/lib/network/forks.js +3 -3
- package/lib/network/forks.js.map +1 -1
- package/lib/network/gossip/scoringParameters.js +19 -14
- package/lib/network/gossip/scoringParameters.js.map +1 -1
- package/lib/network/processor/gossipHandlers.d.ts.map +1 -1
- package/lib/network/processor/gossipHandlers.js +60 -2
- package/lib/network/processor/gossipHandlers.js.map +1 -1
- package/lib/sync/range/chain.d.ts.map +1 -1
- package/lib/sync/range/chain.js +1 -0
- package/lib/sync/range/chain.js.map +1 -1
- package/lib/sync/utils/downloadByRange.d.ts +6 -0
- package/lib/sync/utils/downloadByRange.d.ts.map +1 -1
- package/lib/sync/utils/downloadByRange.js +16 -1
- package/lib/sync/utils/downloadByRange.js.map +1 -1
- package/lib/util/dataColumns.d.ts +2 -1
- package/lib/util/dataColumns.d.ts.map +1 -1
- package/lib/util/dataColumns.js +7 -2
- package/lib/util/dataColumns.js.map +1 -1
- package/lib/util/execution.d.ts +2 -1
- package/lib/util/execution.d.ts.map +1 -1
- package/lib/util/execution.js +7 -2
- package/lib/util/execution.js.map +1 -1
- package/package.json +16 -19
- package/src/api/impl/beacon/blocks/index.ts +1 -5
- package/src/chain/ColumnReconstructionTracker.ts +5 -1
- package/src/chain/GetBlobsTracker.ts +5 -0
- package/src/chain/chain.ts +5 -0
- package/src/chain/errors/dataColumnSidecarError.ts +8 -0
- package/src/chain/interface.ts +2 -0
- package/src/chain/seenCache/index.ts +1 -0
- package/src/chain/seenCache/seenBlockProposers.ts +11 -1
- package/src/chain/seenCache/seenDataColumnSidecars.ts +64 -0
- package/src/chain/validation/attestation.ts +4 -2
- package/src/chain/validation/block.ts +11 -2
- package/src/chain/validation/dataColumnSidecar.ts +1 -1
- package/src/network/forks.ts +7 -3
- package/src/network/gossip/scoringParameters.ts +23 -14
- package/src/network/processor/gossipHandlers.ts +106 -2
- package/src/sync/range/chain.ts +1 -0
- package/src/sync/utils/downloadByRange.ts +29 -1
- package/src/util/dataColumns.ts +13 -1
- package/src/util/execution.ts +16 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {computeStartSlotAtEpoch} from "@lodestar/state-transition";
|
|
2
2
|
import {Epoch, RootHex, Slot, ValidatorIndex, phase0} from "@lodestar/types";
|
|
3
|
-
import {MapDef} from "@lodestar/utils";
|
|
3
|
+
import {MapDef, byteArrayEquals} from "@lodestar/utils";
|
|
4
4
|
|
|
5
5
|
/** Two distinct block roots signed by the same proposer for the same slot are sufficient to establish an equivocation */
|
|
6
6
|
const MIN_EQUIVOCATION_BLOCK_ROOTS_PER_PROPOSAL = 2;
|
|
@@ -44,6 +44,16 @@ export class SeenBlockProposers {
|
|
|
44
44
|
return this.signedBlockHeadersBySlot.get(blockSlot)?.get(proposerIndex)?.has(blockRoot) === true;
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
+
hasBlockSignature(
|
|
48
|
+
blockSlot: Slot,
|
|
49
|
+
proposerIndex: ValidatorIndex,
|
|
50
|
+
blockRoot: RootHex,
|
|
51
|
+
signature: Uint8Array
|
|
52
|
+
): boolean {
|
|
53
|
+
const signedBlockHeader = this.signedBlockHeadersBySlot.get(blockSlot)?.get(proposerIndex)?.get(blockRoot);
|
|
54
|
+
return signedBlockHeader !== undefined && byteArrayEquals(signedBlockHeader.signature, signature);
|
|
55
|
+
}
|
|
56
|
+
|
|
47
57
|
isEquivocating(blockSlot: Slot, proposerIndex: ValidatorIndex): boolean {
|
|
48
58
|
return (
|
|
49
59
|
(this.signedBlockHeadersBySlot.get(blockSlot)?.get(proposerIndex)?.size ?? 0) >=
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import {ColumnIndex, RootHex, Slot, ValidatorIndex} from "@lodestar/types";
|
|
2
|
+
import {MapDef} from "@lodestar/utils";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Tracks the column indices of valid gossip data column sidecars per slot, proposer and block root,
|
|
6
|
+
* to ignore sidecars of a repeated proposal. Pruned on finalization.
|
|
7
|
+
*/
|
|
8
|
+
export class SeenDataColumnSidecars {
|
|
9
|
+
private readonly columnIndicesBySlot = new MapDef<Slot, MapDef<ValidatorIndex, MapDef<RootHex, Set<ColumnIndex>>>>(
|
|
10
|
+
() => new MapDef(() => new MapDef(() => new Set()))
|
|
11
|
+
);
|
|
12
|
+
private readonly evidenceChecksBySlot = new MapDef<Slot, Set<ValidatorIndex>>(() => new Set());
|
|
13
|
+
private finalizedSlot: Slot = 0;
|
|
14
|
+
|
|
15
|
+
isRepeatProposal(slot: Slot, proposerIndex: ValidatorIndex, columnIndex: ColumnIndex, blockRoot: RootHex): boolean {
|
|
16
|
+
const columnIndicesByRoot = this.columnIndicesBySlot.get(slot)?.get(proposerIndex);
|
|
17
|
+
if (columnIndicesByRoot === undefined) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
for (const [root, columnIndices] of columnIndicesByRoot) {
|
|
21
|
+
if (root !== blockRoot && columnIndices.has(columnIndex)) {
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
isKnown(slot: Slot, proposerIndex: ValidatorIndex, columnIndex: ColumnIndex, blockRoot: RootHex): boolean {
|
|
29
|
+
return this.columnIndicesBySlot.get(slot)?.get(proposerIndex)?.get(blockRoot)?.has(columnIndex) === true;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
add(slot: Slot, proposerIndex: ValidatorIndex, columnIndex: ColumnIndex, blockRoot: RootHex): void {
|
|
33
|
+
if (slot < this.finalizedSlot || this.isRepeatProposal(slot, proposerIndex, columnIndex, blockRoot)) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
this.columnIndicesBySlot.getOrDefault(slot).getOrDefault(proposerIndex).getOrDefault(blockRoot).add(columnIndex);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
markEvidenceCheck(slot: Slot, proposerIndex: ValidatorIndex): boolean {
|
|
40
|
+
if (slot < this.finalizedSlot) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
const proposers = this.evidenceChecksBySlot.getOrDefault(slot);
|
|
44
|
+
if (proposers.has(proposerIndex)) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
proposers.add(proposerIndex);
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
prune(finalizedSlot: Slot): void {
|
|
52
|
+
this.finalizedSlot = finalizedSlot;
|
|
53
|
+
for (const slot of this.columnIndicesBySlot.keys()) {
|
|
54
|
+
if (slot < finalizedSlot) {
|
|
55
|
+
this.columnIndicesBySlot.delete(slot);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
for (const slot of this.evidenceChecksBySlot.keys()) {
|
|
59
|
+
if (slot < finalizedSlot) {
|
|
60
|
+
this.evidenceChecksBySlot.delete(slot);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -261,10 +261,12 @@ async function validateAttestationNoSignatureCheck(
|
|
|
261
261
|
const attSlot = attestationOrBytes.attSlot;
|
|
262
262
|
attDataKey = getSeenAttDataKeyFromGossipAttestation(attestationOrBytes);
|
|
263
263
|
const committeeIndexForLookup = isForkPostElectra(fork)
|
|
264
|
-
?
|
|
264
|
+
? getCommitteeIndexFromAttestationOrBytes(fork, attestationOrBytes)
|
|
265
265
|
: PRE_ELECTRA_SINGLE_ATTESTATION_COMMITTEE_INDEX;
|
|
266
266
|
const cachedAttData =
|
|
267
|
-
attDataKey !== null
|
|
267
|
+
attDataKey !== null && committeeIndexForLookup !== null
|
|
268
|
+
? chain.seenAttestationDatas.get(attSlot, committeeIndexForLookup, attDataKey)
|
|
269
|
+
: null;
|
|
268
270
|
if (cachedAttData === null) {
|
|
269
271
|
const attestation = sszDeserializeSingleAttestation(fork, attestationOrBytes.serializedData);
|
|
270
272
|
// only deserialize on the first AttestationData that's not cached
|
|
@@ -76,8 +76,17 @@ export async function validateGossipBlock(
|
|
|
76
76
|
const proposerIndex = block.proposerIndex;
|
|
77
77
|
if (chain.seenBlockProposers.isKnown(blockSlot, proposerIndex)) {
|
|
78
78
|
if (chain.seenBlockProposers.isRepeatProposal(blockSlot, proposerIndex, blockRoot)) {
|
|
79
|
-
|
|
80
|
-
|
|
79
|
+
if (chain.seenBlockProposers.hasBlockRoot(blockSlot, proposerIndex, blockRoot)) {
|
|
80
|
+
// The root is known with a verified signature, e.g. from the header of a data column sidecar, and a valid
|
|
81
|
+
// BLS signature of the same message by the same proposer is unique
|
|
82
|
+
if (!chain.seenBlockProposers.hasBlockSignature(blockSlot, proposerIndex, blockRoot, signedBlock.signature)) {
|
|
83
|
+
throw new BlockGossipError(GossipAction.REJECT, {
|
|
84
|
+
code: BlockErrorCode.PROPOSAL_SIGNATURE_INVALID,
|
|
85
|
+
slot: blockSlot,
|
|
86
|
+
root: blockRoot,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
} else if (!chain.seenBlockProposers.isEquivocating(blockSlot, proposerIndex)) {
|
|
81
90
|
await verifyBlockProposerSignature(chain, signedBlock, blockRoot, {verifyOnMainThread: false});
|
|
82
91
|
chain.seenBlockProposers.observeBlockRoot(blockSlot, proposerIndex, blockRoot, signedBlockHeader);
|
|
83
92
|
}
|
|
@@ -225,7 +225,7 @@ export async function validateGossipFuluDataColumnSidecar(
|
|
|
225
225
|
|
|
226
226
|
// 12) [IGNORE] The sidecar is the first sidecar for the tuple (block_header.slot, block_header.proposer_index,
|
|
227
227
|
// sidecar.index) with valid header signature, sidecar inclusion proof, and kzg proof
|
|
228
|
-
// -- Handled in
|
|
228
|
+
// -- Handled in gossip handler with seenDataColumnSidecars
|
|
229
229
|
}
|
|
230
230
|
|
|
231
231
|
// SPEC FUNCTION
|
package/src/network/forks.ts
CHANGED
|
@@ -29,10 +29,14 @@ import {Epoch} from "@lodestar/types";
|
|
|
29
29
|
export const FORK_EPOCH_LOOKAHEAD = 2;
|
|
30
30
|
|
|
31
31
|
/**
|
|
32
|
-
* Return the
|
|
32
|
+
* Return the fork boundaries active at any epoch in the inclusive range.
|
|
33
33
|
* @see FORK_EPOCH_LOOKAHEAD for details on when fork boundaries are considered 'active'
|
|
34
34
|
*/
|
|
35
|
-
export function getActiveForkBoundaries(
|
|
35
|
+
export function getActiveForkBoundaries(
|
|
36
|
+
config: ChainForkConfig,
|
|
37
|
+
fromEpoch: Epoch,
|
|
38
|
+
toEpoch = fromEpoch
|
|
39
|
+
): ForkBoundary[] {
|
|
36
40
|
const activeBoundaries: ForkBoundary[] = [];
|
|
37
41
|
const {forkBoundariesAscendingEpochOrder} = config;
|
|
38
42
|
|
|
@@ -48,7 +52,7 @@ export function getActiveForkBoundaries(config: ChainForkConfig, epoch: Epoch):
|
|
|
48
52
|
continue;
|
|
49
53
|
}
|
|
50
54
|
|
|
51
|
-
if (
|
|
55
|
+
if (toEpoch >= currentEpoch - FORK_EPOCH_LOOKAHEAD && fromEpoch <= nextEpoch + FORK_EPOCH_LOOKAHEAD) {
|
|
52
56
|
activeBoundaries.push(currentForkBoundary);
|
|
53
57
|
}
|
|
54
58
|
}
|
|
@@ -6,8 +6,8 @@ import {
|
|
|
6
6
|
} from "@libp2p/gossipsub/score";
|
|
7
7
|
import {BeaconConfig} from "@lodestar/config";
|
|
8
8
|
import {ATTESTATION_SUBNET_COUNT, PTC_SIZE, SLOTS_PER_EPOCH, TARGET_AGGREGATORS_PER_COMMITTEE} from "@lodestar/params";
|
|
9
|
-
import {computeCommitteeCount} from "@lodestar/state-transition";
|
|
10
|
-
import {getActiveForkBoundaries} from "../forks.js";
|
|
9
|
+
import {computeCommitteeCount, computeStartSlotAtEpoch} from "@lodestar/state-transition";
|
|
10
|
+
import {FORK_EPOCH_LOOKAHEAD, getActiveForkBoundaries} from "../forks.js";
|
|
11
11
|
import {Eth2Context} from "./gossipsub.js";
|
|
12
12
|
import {GossipType} from "./interface.js";
|
|
13
13
|
import {stringifyGossipTopic} from "./topic.js";
|
|
@@ -132,11 +132,20 @@ function getAllTopicsScoreParams(
|
|
|
132
132
|
precomputedParams: PreComputedParams
|
|
133
133
|
): Record<string, TopicScoreParams> {
|
|
134
134
|
const {epochDurationMs, slotDurationMs} = precomputedParams;
|
|
135
|
-
const epoch = eth2Context.currentEpoch;
|
|
136
135
|
const topicsParams: Record<string, TopicScoreParams> = {};
|
|
137
|
-
|
|
136
|
+
// Gossipsub copies the score parameters at construction, including those for future subscriptions.
|
|
137
|
+
const boundaries = getActiveForkBoundaries(config, eth2Context.currentEpoch, Infinity);
|
|
138
138
|
const beaconAttestationSubnetWeight = 1 / ATTESTATION_SUBNET_COUNT;
|
|
139
139
|
for (const boundary of boundaries) {
|
|
140
|
+
const currentSlot = Math.max(
|
|
141
|
+
eth2Context.currentSlot,
|
|
142
|
+
computeStartSlotAtEpoch(boundary.epoch - FORK_EPOCH_LOOKAHEAD)
|
|
143
|
+
);
|
|
144
|
+
// The node subscribes to a boundary's topics FORK_EPOCH_LOOKAHEAD epochs early, but peers only publish on
|
|
145
|
+
// them from the boundary epoch. Hold back the mesh delivery penalty until then, otherwise every mesh peer
|
|
146
|
+
// is penalized for an empty topic.
|
|
147
|
+
const subscribeEpoch = Math.max(eth2Context.currentEpoch, boundary.epoch - FORK_EPOCH_LOOKAHEAD);
|
|
148
|
+
const activationDelayMs = Math.max(0, boundary.epoch - subscribeEpoch) * epochDurationMs;
|
|
140
149
|
//first all fixed topics
|
|
141
150
|
topicsParams[
|
|
142
151
|
stringifyGossipTopic(config, {
|
|
@@ -225,8 +234,8 @@ function getAllTopicsScoreParams(
|
|
|
225
234
|
meshMessageInfo: {
|
|
226
235
|
decaySlots: SLOTS_PER_EPOCH * 5,
|
|
227
236
|
capFactor: 3,
|
|
228
|
-
activationWindow: epochDurationMs,
|
|
229
|
-
currentSlot
|
|
237
|
+
activationWindow: activationDelayMs + epochDurationMs,
|
|
238
|
+
currentSlot,
|
|
230
239
|
},
|
|
231
240
|
});
|
|
232
241
|
topicsParams[
|
|
@@ -241,8 +250,8 @@ function getAllTopicsScoreParams(
|
|
|
241
250
|
meshMessageInfo: {
|
|
242
251
|
decaySlots: SLOTS_PER_EPOCH * 5,
|
|
243
252
|
capFactor: 3,
|
|
244
|
-
activationWindow: epochDurationMs,
|
|
245
|
-
currentSlot
|
|
253
|
+
activationWindow: activationDelayMs + epochDurationMs,
|
|
254
|
+
currentSlot,
|
|
246
255
|
},
|
|
247
256
|
});
|
|
248
257
|
|
|
@@ -268,8 +277,8 @@ function getAllTopicsScoreParams(
|
|
|
268
277
|
meshMessageInfo: {
|
|
269
278
|
decaySlots: SLOTS_PER_EPOCH * 2,
|
|
270
279
|
capFactor: 4,
|
|
271
|
-
activationWindow: epochDurationMs,
|
|
272
|
-
currentSlot
|
|
280
|
+
activationWindow: activationDelayMs + epochDurationMs,
|
|
281
|
+
currentSlot,
|
|
273
282
|
},
|
|
274
283
|
});
|
|
275
284
|
|
|
@@ -280,10 +289,10 @@ function getAllTopicsScoreParams(
|
|
|
280
289
|
meshMessageInfo: {
|
|
281
290
|
decaySlots: multipleBurstsPerSubnetPerEpoch ? SLOTS_PER_EPOCH * 4 : SLOTS_PER_EPOCH * 16,
|
|
282
291
|
capFactor: 16,
|
|
283
|
-
activationWindow:
|
|
284
|
-
|
|
285
|
-
: epochDurationMs,
|
|
286
|
-
currentSlot
|
|
292
|
+
activationWindow:
|
|
293
|
+
activationDelayMs +
|
|
294
|
+
(multipleBurstsPerSubnetPerEpoch ? slotDurationMs * (SLOTS_PER_EPOCH / 2 + 1) : epochDurationMs),
|
|
295
|
+
currentSlot,
|
|
287
296
|
},
|
|
288
297
|
});
|
|
289
298
|
for (let subnet = 0; subnet < ATTESTATION_SUBNET_COUNT; subnet++) {
|
|
@@ -12,7 +12,11 @@ import {
|
|
|
12
12
|
isForkPostElectra,
|
|
13
13
|
isForkPostGloas,
|
|
14
14
|
} from "@lodestar/params";
|
|
15
|
-
import {
|
|
15
|
+
import {
|
|
16
|
+
computeTimeAtSlot,
|
|
17
|
+
getBlockHeaderProposerSignatureSetByHeaderSlot,
|
|
18
|
+
signedBlockToSignedHeader,
|
|
19
|
+
} from "@lodestar/state-transition";
|
|
16
20
|
import {
|
|
17
21
|
Root,
|
|
18
22
|
RootHex,
|
|
@@ -25,6 +29,7 @@ import {
|
|
|
25
29
|
gloas,
|
|
26
30
|
isGloasBeaconBlock,
|
|
27
31
|
isGloasDataColumnSidecar,
|
|
32
|
+
phase0,
|
|
28
33
|
ssz,
|
|
29
34
|
sszTypesFor,
|
|
30
35
|
} from "@lodestar/types";
|
|
@@ -380,6 +385,28 @@ function getSequentialHandlers(modules: ValidatorFnsModules, options: GossipHand
|
|
|
380
385
|
}
|
|
381
386
|
}
|
|
382
387
|
|
|
388
|
+
// The block input may have been pruned before the block was imported
|
|
389
|
+
if (
|
|
390
|
+
chain.seenDataColumnSidecars.isKnown(
|
|
391
|
+
slot,
|
|
392
|
+
dataColumnBlockHeader.proposerIndex,
|
|
393
|
+
dataColumnSidecar.index,
|
|
394
|
+
blockRootHex
|
|
395
|
+
)
|
|
396
|
+
) {
|
|
397
|
+
metrics?.peerDas.dataColumnSidecarProcessingSkip.inc();
|
|
398
|
+
throw new DataColumnSidecarGossipError(GossipAction.IGNORE, {
|
|
399
|
+
code: DataColumnSidecarErrorCode.ALREADY_KNOWN,
|
|
400
|
+
columnIndex: dataColumnSidecar.index,
|
|
401
|
+
slot,
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
if (isRepeatColumnProposal(chain, dataColumnSidecar, blockRootHex)) {
|
|
406
|
+
await observeRepeatColumnProposal(chain, dataColumnSidecar, blockRootHex);
|
|
407
|
+
throw repeatColumnProposalError(dataColumnSidecar, blockRootHex);
|
|
408
|
+
}
|
|
409
|
+
|
|
383
410
|
const verificationTimer = metrics?.peerDas.dataColumnSidecarGossipVerificationTime.startTimer();
|
|
384
411
|
|
|
385
412
|
const delaySec = chain.clock.secFromSlot(slot, seenTimestampSec);
|
|
@@ -388,6 +415,17 @@ function getSequentialHandlers(modules: ValidatorFnsModules, options: GossipHand
|
|
|
388
415
|
|
|
389
416
|
try {
|
|
390
417
|
await validateGossipFuluDataColumnSidecar(chain, dataColumnSidecar, gossipSubnet, metrics);
|
|
418
|
+
observeColumnBlockHeader(chain, dataColumnSidecar.signedBlockHeader, blockRootHex);
|
|
419
|
+
// Another block root may have been seen for the same tuple while validating
|
|
420
|
+
if (isRepeatColumnProposal(chain, dataColumnSidecar, blockRootHex)) {
|
|
421
|
+
throw repeatColumnProposalError(dataColumnSidecar, blockRootHex);
|
|
422
|
+
}
|
|
423
|
+
chain.seenDataColumnSidecars.add(
|
|
424
|
+
slot,
|
|
425
|
+
dataColumnBlockHeader.proposerIndex,
|
|
426
|
+
dataColumnSidecar.index,
|
|
427
|
+
blockRootHex
|
|
428
|
+
);
|
|
391
429
|
const blockInput = chain.seenBlockInputCache.getByColumn({
|
|
392
430
|
blockRootHex,
|
|
393
431
|
columnSidecar: dataColumnSidecar,
|
|
@@ -719,7 +757,12 @@ function getSequentialHandlers(modules: ValidatorFnsModules, options: GossipHand
|
|
|
719
757
|
e.type.code === BlockErrorCode.REPEAT_PROPOSAL &&
|
|
720
758
|
// Only a signature-verified sibling recorded in the seen cache is imported. The cache holds at most two
|
|
721
759
|
// roots per proposer and slot, which bounds full imports over gossip to one alternate
|
|
722
|
-
chain.seenBlockProposers.
|
|
760
|
+
chain.seenBlockProposers.hasBlockSignature(
|
|
761
|
+
signedBlock.message.slot,
|
|
762
|
+
e.type.proposerIndex,
|
|
763
|
+
e.type.root,
|
|
764
|
+
signedBlock.signature
|
|
765
|
+
) &&
|
|
723
766
|
// A sibling with an unknown parent cannot be imported, sync fetches it if its branch becomes relevant
|
|
724
767
|
chain.forkChoice.getBlockHexDefaultStatus(toRootHex(signedBlock.message.parentRoot)) !== null &&
|
|
725
768
|
(!isGloasBeaconBlock(signedBlock.message) ||
|
|
@@ -1663,3 +1706,64 @@ function getCutoffTimeMs(
|
|
|
1663
1706
|
0
|
|
1664
1707
|
);
|
|
1665
1708
|
}
|
|
1709
|
+
|
|
1710
|
+
/**
|
|
1711
|
+
* [IGNORE] The sidecar is the first sidecar for the tuple (block_header.slot, block_header.proposer_index, sidecar.index)
|
|
1712
|
+
* with valid header signature, sidecar inclusion proof, and kzg proof
|
|
1713
|
+
*/
|
|
1714
|
+
function isRepeatColumnProposal(
|
|
1715
|
+
chain: IBeaconChain,
|
|
1716
|
+
dataColumnSidecar: fulu.DataColumnSidecar,
|
|
1717
|
+
blockRootHex: RootHex
|
|
1718
|
+
): boolean {
|
|
1719
|
+
const {slot, proposerIndex} = dataColumnSidecar.signedBlockHeader.message;
|
|
1720
|
+
return chain.seenDataColumnSidecars.isRepeatProposal(slot, proposerIndex, dataColumnSidecar.index, blockRootHex);
|
|
1721
|
+
}
|
|
1722
|
+
|
|
1723
|
+
function repeatColumnProposalError(
|
|
1724
|
+
dataColumnSidecar: fulu.DataColumnSidecar,
|
|
1725
|
+
blockRootHex: RootHex
|
|
1726
|
+
): DataColumnSidecarGossipError {
|
|
1727
|
+
const {slot, proposerIndex} = dataColumnSidecar.signedBlockHeader.message;
|
|
1728
|
+
return new DataColumnSidecarGossipError(GossipAction.IGNORE, {
|
|
1729
|
+
code: DataColumnSidecarErrorCode.REPEAT_PROPOSAL,
|
|
1730
|
+
slot,
|
|
1731
|
+
proposerIndex,
|
|
1732
|
+
columnIndex: dataColumnSidecar.index,
|
|
1733
|
+
root: blockRootHex,
|
|
1734
|
+
});
|
|
1735
|
+
}
|
|
1736
|
+
|
|
1737
|
+
function observeColumnBlockHeader(
|
|
1738
|
+
chain: IBeaconChain,
|
|
1739
|
+
signedBlockHeader: phase0.SignedBeaconBlockHeader,
|
|
1740
|
+
blockRootHex: RootHex
|
|
1741
|
+
): void {
|
|
1742
|
+
const {slot, proposerIndex} = signedBlockHeader.message;
|
|
1743
|
+
chain.seenBlockProposers.observeBlockRoot(slot, proposerIndex, blockRootHex, signedBlockHeader);
|
|
1744
|
+
if (chain.seenBlockProposers.isEquivocating(slot, proposerIndex)) {
|
|
1745
|
+
chain.processProposerEquivocation(slot, proposerIndex);
|
|
1746
|
+
}
|
|
1747
|
+
}
|
|
1748
|
+
|
|
1749
|
+
async function observeRepeatColumnProposal(
|
|
1750
|
+
chain: IBeaconChain,
|
|
1751
|
+
dataColumnSidecar: fulu.DataColumnSidecar,
|
|
1752
|
+
blockRootHex: RootHex
|
|
1753
|
+
): Promise<void> {
|
|
1754
|
+
const {signedBlockHeader} = dataColumnSidecar;
|
|
1755
|
+
const {slot, proposerIndex} = signedBlockHeader.message;
|
|
1756
|
+
// Only needed as slashing evidence, so verify at most one conflicting header per slot and proposer
|
|
1757
|
+
if (
|
|
1758
|
+
chain.seenBlockProposers.hasBlockRoot(slot, proposerIndex, blockRootHex) ||
|
|
1759
|
+
chain.seenBlockProposers.isEquivocating(slot, proposerIndex) ||
|
|
1760
|
+
!chain.seenDataColumnSidecars.markEvidenceCheck(slot, proposerIndex)
|
|
1761
|
+
) {
|
|
1762
|
+
return;
|
|
1763
|
+
}
|
|
1764
|
+
|
|
1765
|
+
const signatureSet = getBlockHeaderProposerSignatureSetByHeaderSlot(chain.config, signedBlockHeader);
|
|
1766
|
+
if (await chain.bls.verifySignatureSets([signatureSet])) {
|
|
1767
|
+
observeColumnBlockHeader(chain, signedBlockHeader, blockRootHex);
|
|
1768
|
+
}
|
|
1769
|
+
}
|
package/src/sync/range/chain.ts
CHANGED
|
@@ -627,6 +627,7 @@ export class SyncChain {
|
|
|
627
627
|
case DownloadByRangeErrorCode.INVALID_ENVELOPE_BLOCK_HASH:
|
|
628
628
|
case DownloadByRangeErrorCode.INVALID_ENVELOPE_SLOT:
|
|
629
629
|
case DownloadByRangeErrorCode.INVALID_CHAIN_SEGMENT:
|
|
630
|
+
case DownloadByRangeErrorCode.TOO_MANY_KZG_COMMITMENTS:
|
|
630
631
|
case DataColumnSidecarErrorCode.INCORRECT_KZG_COMMITMENTS_COUNT:
|
|
631
632
|
case DataColumnSidecarErrorCode.INCORRECT_KZG_PROOF_COUNT:
|
|
632
633
|
case DataColumnSidecarErrorCode.INVALID_KZG_PROOF_BATCH:
|
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
import {ChainForkConfig} from "@lodestar/config";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
ForkName,
|
|
4
|
+
ForkPostDeneb,
|
|
5
|
+
ForkPostFulu,
|
|
6
|
+
ForkPostGloas,
|
|
7
|
+
isForkPostDeneb,
|
|
8
|
+
isForkPostFulu,
|
|
9
|
+
isForkPostGloas,
|
|
10
|
+
} from "@lodestar/params";
|
|
11
|
+
import {computeEpochAtSlot} from "@lodestar/state-transition";
|
|
3
12
|
import {
|
|
4
13
|
ColumnIndex,
|
|
5
14
|
DataColumnSidecar,
|
|
@@ -28,6 +37,7 @@ import {INetwork} from "../../network/index.js";
|
|
|
28
37
|
import {CustodyConfig, getBlobKzgCommitments} from "../../util/dataColumns.js";
|
|
29
38
|
import {PeerIdStr} from "../../util/peerId.js";
|
|
30
39
|
import {WarnResult} from "../../util/wrapError.js";
|
|
40
|
+
import {getRateLimitedUntilMs} from "./rateLimit.js";
|
|
31
41
|
|
|
32
42
|
export type DownloadByRangeRequests = {
|
|
33
43
|
blocksRequest?: phase0.BeaconBlocksByRangeRequest;
|
|
@@ -327,6 +337,8 @@ export async function downloadByRange({
|
|
|
327
337
|
parentPayloadRequest,
|
|
328
338
|
});
|
|
329
339
|
} catch (err) {
|
|
340
|
+
// Rethrow rate limit errors as is, so range sync can back off from the peer instead of counting a failed download
|
|
341
|
+
if (getRateLimitedUntilMs(err) !== null) throw err;
|
|
330
342
|
throw new DownloadByRangeError({
|
|
331
343
|
code: DownloadByRangeErrorCode.REQ_RESP_ERROR,
|
|
332
344
|
reason: (err as Error).message,
|
|
@@ -697,6 +709,15 @@ export function validateBlockByRangeResponse(
|
|
|
697
709
|
|
|
698
710
|
for (let i = 0; i < blocks.length; i++) {
|
|
699
711
|
const block = blocks[i];
|
|
712
|
+
const slot = block.message.slot;
|
|
713
|
+
const fork = config.getForkName(slot);
|
|
714
|
+
if (isForkPostDeneb(fork)) {
|
|
715
|
+
const count = getBlobKzgCommitments(fork, block as SignedBeaconBlock<ForkPostDeneb>).length;
|
|
716
|
+
const limit = config.getMaxBlobsPerBlock(computeEpochAtSlot(slot));
|
|
717
|
+
if (count > limit) {
|
|
718
|
+
throw new DownloadByRangeError({code: DownloadByRangeErrorCode.TOO_MANY_KZG_COMMITMENTS, slot, count, limit});
|
|
719
|
+
}
|
|
720
|
+
}
|
|
700
721
|
const blockRoot = type.hashTreeRoot(block.message);
|
|
701
722
|
response.push({block, blockRoot});
|
|
702
723
|
|
|
@@ -1025,6 +1046,7 @@ export enum DownloadByRangeErrorCode {
|
|
|
1025
1046
|
|
|
1026
1047
|
PARENT_ROOT_MISMATCH = "DOWNLOAD_BY_RANGE_ERROR_PARENT_ROOT_MISMATCH",
|
|
1027
1048
|
EXTRA_BLOCKS = "DOWNLOAD_BY_RANGE_ERROR_EXTRA_BLOCKS",
|
|
1049
|
+
TOO_MANY_KZG_COMMITMENTS = "DOWNLOAD_BY_RANGE_ERROR_TOO_MANY_KZG_COMMITMENTS",
|
|
1028
1050
|
OUT_OF_RANGE_BLOCKS = "DOWNLOAD_BY_RANGE_OUT_OF_RANGE_BLOCKS",
|
|
1029
1051
|
OUT_OF_ORDER_BLOCKS = "DOWNLOAD_BY_RANGE_OUT_OF_ORDER_BLOCKS",
|
|
1030
1052
|
|
|
@@ -1067,6 +1089,12 @@ export type DownloadByRangeErrorType =
|
|
|
1067
1089
|
columnSidecarCount: number;
|
|
1068
1090
|
payloadEnvelopeCount: number;
|
|
1069
1091
|
}
|
|
1092
|
+
| {
|
|
1093
|
+
code: DownloadByRangeErrorCode.TOO_MANY_KZG_COMMITMENTS;
|
|
1094
|
+
slot: Slot;
|
|
1095
|
+
count: number;
|
|
1096
|
+
limit: number;
|
|
1097
|
+
}
|
|
1070
1098
|
| {
|
|
1071
1099
|
code: DownloadByRangeErrorCode.OUT_OF_RANGE_BLOCKS;
|
|
1072
1100
|
slot: number;
|
package/src/util/dataColumns.ts
CHANGED
|
@@ -33,6 +33,7 @@ import {BlockInputColumns} from "../chain/blocks/blockInput/blockInput.js";
|
|
|
33
33
|
import {BlockInputSource} from "../chain/blocks/blockInput/types.js";
|
|
34
34
|
import {PayloadEnvelopeInput, PayloadEnvelopeInputSource} from "../chain/blocks/payloadEnvelopeInput/index.js";
|
|
35
35
|
import {ChainEvent, ChainEventEmitter} from "../chain/emitter.js";
|
|
36
|
+
import {SeenDataColumnSidecars} from "../chain/seenCache/seenDataColumnSidecars.js";
|
|
36
37
|
import {Metrics} from "../metrics/metrics.js";
|
|
37
38
|
import {NodeId} from "../network/subnets/index.js";
|
|
38
39
|
import {dataColumnMatrixRecovery} from "./blobs.js";
|
|
@@ -434,6 +435,7 @@ export function getGloasDataColumnSidecars(
|
|
|
434
435
|
export async function recoverDataColumnSidecars(
|
|
435
436
|
input: BlockInputColumns | PayloadEnvelopeInput,
|
|
436
437
|
emitter: ChainEventEmitter,
|
|
438
|
+
seenDataColumnSidecars: SeenDataColumnSidecars,
|
|
437
439
|
metrics: Metrics | null
|
|
438
440
|
): Promise<DataColumnReconstructionCode> {
|
|
439
441
|
const existingColumns = input.getAllColumns();
|
|
@@ -486,6 +488,7 @@ export async function recoverDataColumnSidecars(
|
|
|
486
488
|
const sidecarsToPublish: DataColumnSidecar[] = [];
|
|
487
489
|
for (const columnSidecar of fullSidecars) {
|
|
488
490
|
if (!input.hasColumn(columnSidecar.index)) {
|
|
491
|
+
let isRepeatProposal = false;
|
|
489
492
|
if (input instanceof PayloadEnvelopeInput) {
|
|
490
493
|
if (!isGloasDataColumnSidecar(columnSidecar)) {
|
|
491
494
|
throw new Error(`Expected gloas DataColumnSidecar for block ${input.blockRootHex}`);
|
|
@@ -505,9 +508,18 @@ export async function recoverDataColumnSidecars(
|
|
|
505
508
|
seenTimestampSec: Date.now() / 1000,
|
|
506
509
|
source: BlockInputSource.recovery,
|
|
507
510
|
});
|
|
511
|
+
// Reconstructed columns count as received via gossip for the repeat proposal check
|
|
512
|
+
const {slot, proposerIndex} = columnSidecar.signedBlockHeader.message;
|
|
513
|
+
isRepeatProposal = seenDataColumnSidecars.isRepeatProposal(
|
|
514
|
+
slot,
|
|
515
|
+
proposerIndex,
|
|
516
|
+
columnSidecar.index,
|
|
517
|
+
input.blockRootHex
|
|
518
|
+
);
|
|
519
|
+
seenDataColumnSidecars.add(slot, proposerIndex, columnSidecar.index, input.blockRootHex);
|
|
508
520
|
}
|
|
509
521
|
sidecarsReconstructed.push(columnSidecar);
|
|
510
|
-
if (missingSampledColumns.has(columnSidecar.index)) {
|
|
522
|
+
if (missingSampledColumns.has(columnSidecar.index) && !isRepeatProposal) {
|
|
511
523
|
sidecarsToPublish.push(columnSidecar);
|
|
512
524
|
}
|
|
513
525
|
}
|
package/src/util/execution.ts
CHANGED
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
EnvelopeReconstructionError,
|
|
12
12
|
EnvelopeReconstructionErrorCode,
|
|
13
13
|
} from "../chain/errors/envelopeReconstructionError.js";
|
|
14
|
+
import {SeenDataColumnSidecars} from "../chain/seenCache/seenDataColumnSidecars.js";
|
|
14
15
|
import {IBeaconDb} from "../db/index.js";
|
|
15
16
|
import {ArchivedEnvelope, decodeArchivedEnvelope} from "../db/repositories/index.js";
|
|
16
17
|
import {IExecutionEngine} from "../execution/index.js";
|
|
@@ -48,6 +49,7 @@ export async function getDataColumnSidecarsFromExecution(
|
|
|
48
49
|
config: ChainForkConfig,
|
|
49
50
|
executionEngine: Pick<IExecutionEngine, "getBlobs">,
|
|
50
51
|
emitter: ChainEventEmitter,
|
|
52
|
+
seenDataColumnSidecars: SeenDataColumnSidecars,
|
|
51
53
|
input: IBlockInput | PayloadEnvelopeInput,
|
|
52
54
|
metrics: Metrics | null,
|
|
53
55
|
blobAndProofBuffers?: Uint8Array[]
|
|
@@ -112,8 +114,18 @@ export async function getDataColumnSidecarsFromExecution(
|
|
|
112
114
|
const previouslyMissingColumns = input.getMissingSampledColumnMeta().missing;
|
|
113
115
|
const sampledColumns = previouslyMissingColumns.map((columnIndex) => dataColumnSidecars[columnIndex]);
|
|
114
116
|
|
|
117
|
+
const columnsToPublish = sampledColumns.filter(
|
|
118
|
+
(columnSidecar) =>
|
|
119
|
+
isGloasDataColumnSidecar(columnSidecar) ||
|
|
120
|
+
!seenDataColumnSidecars.isRepeatProposal(
|
|
121
|
+
columnSidecar.signedBlockHeader.message.slot,
|
|
122
|
+
columnSidecar.signedBlockHeader.message.proposerIndex,
|
|
123
|
+
columnSidecar.index,
|
|
124
|
+
input.blockRootHex
|
|
125
|
+
)
|
|
126
|
+
);
|
|
115
127
|
// for columns we have already seen, publishDataColumnSidecar() catches PublishError.Duplicate and marks alreadyPublished=true
|
|
116
|
-
emitter.emit(ChainEvent.publishDataColumns,
|
|
128
|
+
emitter.emit(ChainEvent.publishDataColumns, columnsToPublish);
|
|
117
129
|
// TODO: Can we record dataColumns.sentPeersPerSubnet metric here somehow
|
|
118
130
|
|
|
119
131
|
// add all sampled columns to the input, even if we didn't sample them
|
|
@@ -145,6 +157,9 @@ export async function getDataColumnSidecarsFromExecution(
|
|
|
145
157
|
source: BlockInputSource.engine,
|
|
146
158
|
seenTimestampSec,
|
|
147
159
|
});
|
|
160
|
+
// Columns from the execution layer count as received via gossip for the repeat proposal check
|
|
161
|
+
const {slot, proposerIndex} = columnSidecar.signedBlockHeader.message;
|
|
162
|
+
seenDataColumnSidecars.add(slot, proposerIndex, columnSidecar.index, input.blockRootHex);
|
|
148
163
|
}
|
|
149
164
|
|
|
150
165
|
if (emitter.listenerCount(routes.events.EventType.dataColumnSidecar)) {
|