@lodestar/beacon-node 1.52.0-dev.8bada2d599 → 1.52.0-dev.97ba67c17e
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/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/blocks/verifyBlock.d.ts.map +1 -1
- package/lib/chain/blocks/verifyBlock.js +12 -11
- package/lib/chain/blocks/verifyBlock.js.map +1 -1
- package/lib/chain/blocks/verifyBlocksSignatures.d.ts +2 -2
- package/lib/chain/blocks/verifyBlocksSignatures.d.ts.map +1 -1
- package/lib/chain/blocks/verifyBlocksSignatures.js +2 -1
- package/lib/chain/blocks/verifyBlocksSignatures.js.map +1 -1
- package/lib/chain/bls/utils.js +1 -1
- package/lib/chain/bls/utils.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/inclusionListStore.d.ts +4 -1
- package/lib/chain/opPools/inclusionListStore.d.ts.map +1 -1
- package/lib/chain/opPools/inclusionListStore.js +5 -2
- package/lib/chain/opPools/inclusionListStore.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/shufflingCache.d.ts +5 -0
- package/lib/chain/shufflingCache.d.ts.map +1 -1
- package/lib/chain/shufflingCache.js +39 -1
- package/lib/chain/shufflingCache.js.map +1 -1
- package/lib/chain/validation/aggregateAndProof.d.ts.map +1 -1
- package/lib/chain/validation/aggregateAndProof.js +13 -2
- package/lib/chain/validation/aggregateAndProof.js.map +1 -1
- package/lib/chain/validation/executionPayloadBid.js +29 -11
- package/lib/chain/validation/executionPayloadBid.js.map +1 -1
- package/lib/metrics/metrics/lodestar.d.ts +2 -0
- package/lib/metrics/metrics/lodestar.d.ts.map +1 -1
- package/lib/metrics/metrics/lodestar.js +9 -0
- package/lib/metrics/metrics/lodestar.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/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/validator/index.ts +4 -2
- package/src/chain/blocks/verifyBlock.ts +14 -10
- package/src/chain/blocks/verifyBlocksSignatures.ts +3 -0
- package/src/chain/bls/utils.ts +1 -1
- package/src/chain/chain.ts +12 -6
- package/src/chain/errors/executionPayloadBid.ts +3 -2
- package/src/chain/opPools/inclusionListStore.ts +5 -2
- package/src/chain/seenCache/seenExecutionPayloadBids.ts +35 -15
- package/src/chain/shufflingCache.ts +40 -1
- package/src/chain/validation/aggregateAndProof.ts +19 -5
- package/src/chain/validation/executionPayloadBid.ts +39 -11
- package/src/metrics/metrics/lodestar.ts +9 -0
- package/src/network/network.ts +33 -11
- 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
|
@@ -25,6 +25,7 @@ import {
|
|
|
25
25
|
} from "@lodestar/state-transition";
|
|
26
26
|
import {
|
|
27
27
|
ProducedBlockSource,
|
|
28
|
+
RootHex,
|
|
28
29
|
SignedBeaconBlock,
|
|
29
30
|
SignedBlindedBeaconBlock,
|
|
30
31
|
SignedBlockContents,
|
|
@@ -190,28 +191,31 @@ export function getBeaconBlockApi(
|
|
|
190
191
|
|
|
191
192
|
switch (broadcastValidation) {
|
|
192
193
|
case routes.beacon.BroadcastValidation.gossip: {
|
|
193
|
-
|
|
194
|
-
|
|
194
|
+
try {
|
|
195
|
+
if (blockLocallyProduced) {
|
|
196
|
+
// Block production does not cover the proposer signature, the validator client signs the block
|
|
197
|
+
await verifyBlockProposerSignature(chain, signedBlock, blockRoot);
|
|
198
|
+
} else {
|
|
195
199
|
await validateGossipBlock(config, chain, signedBlock, fork);
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
200
|
+
}
|
|
201
|
+
} catch (error) {
|
|
202
|
+
if (error instanceof BlockGossipError) {
|
|
203
|
+
switch (error.type.code) {
|
|
204
|
+
case BlockErrorCode.ALREADY_KNOWN:
|
|
205
|
+
// Block has already been seen, e.g. via gossip racing the publish API. Benign.
|
|
206
|
+
chain.logger.debug("Ignoring already-known block during publishing", valLogMeta);
|
|
207
|
+
return;
|
|
204
208
|
}
|
|
205
|
-
|
|
206
|
-
chain.logger.error("Gossip validations failed while publishing the block", valLogMeta, error as Error);
|
|
207
|
-
chain.persistInvalidSszValue(
|
|
208
|
-
chain.config.getForkTypes(slot).SignedBeaconBlock,
|
|
209
|
-
signedBlock,
|
|
210
|
-
"api_reject_gossip_failure",
|
|
211
|
-
blockRoot
|
|
212
|
-
);
|
|
213
|
-
throw error;
|
|
214
209
|
}
|
|
210
|
+
|
|
211
|
+
chain.logger.error("Gossip validations failed while publishing the block", valLogMeta, error as Error);
|
|
212
|
+
chain.persistInvalidSszValue(
|
|
213
|
+
chain.config.getForkTypes(slot).SignedBeaconBlock,
|
|
214
|
+
signedBlock,
|
|
215
|
+
"api_reject_gossip_failure",
|
|
216
|
+
blockRoot
|
|
217
|
+
);
|
|
218
|
+
throw error;
|
|
215
219
|
}
|
|
216
220
|
chain.logger.debug("Gossip checks validated while publishing the block", valLogMeta);
|
|
217
221
|
break;
|
|
@@ -507,26 +511,32 @@ export function getBeaconBlockApi(
|
|
|
507
511
|
|
|
508
512
|
const result: routes.beacon.BlockHeaderResponse[] = [];
|
|
509
513
|
if (parentRoot) {
|
|
514
|
+
let finalizedRoot: RootHex | null = null;
|
|
510
515
|
const finalizedBlock = await db.blockArchive.getByParentRoot(fromHex(parentRoot));
|
|
511
516
|
if (finalizedBlock) {
|
|
512
|
-
|
|
517
|
+
const header = toBeaconHeaderResponse(config, finalizedBlock, true);
|
|
518
|
+
finalizedRoot = toRootHex(header.root);
|
|
519
|
+
result.push(header);
|
|
513
520
|
}
|
|
514
521
|
const nonFinalizedBlocks = chain.forkChoice.getBlockSummariesByParentRoot(parentRoot);
|
|
515
522
|
await Promise.all(
|
|
516
523
|
nonFinalizedBlocks.map(async (summary) => {
|
|
524
|
+
// The finalized block stays in fork choice as its anchor after it is archived
|
|
525
|
+
if (summary.blockRoot === finalizedRoot) {
|
|
526
|
+
return;
|
|
527
|
+
}
|
|
517
528
|
const blockResult = await chain.getBlockByRoot(summary.blockRoot);
|
|
518
529
|
if (blockResult) {
|
|
530
|
+
// There is no canonical block at the slot of a child that was reorged out by a later sibling
|
|
519
531
|
const canonical = chain.forkChoice.getCanonicalBlockAtSlot(blockResult.block.message.slot);
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
executionOptimistic = true;
|
|
526
|
-
}
|
|
527
|
-
// Block from hot db which only contains unfinalized blocks
|
|
528
|
-
finalized = false;
|
|
532
|
+
result.push(
|
|
533
|
+
toBeaconHeaderResponse(config, blockResult.block, canonical?.blockRoot === summary.blockRoot)
|
|
534
|
+
);
|
|
535
|
+
if (isOptimisticBlock(summary)) {
|
|
536
|
+
executionOptimistic = true;
|
|
529
537
|
}
|
|
538
|
+
// Block from hot db which only contains unfinalized blocks
|
|
539
|
+
finalized = false;
|
|
530
540
|
}
|
|
531
541
|
})
|
|
532
542
|
);
|
|
@@ -551,21 +561,18 @@ export function getBeaconBlockApi(
|
|
|
551
561
|
return {data: [], meta: {executionOptimistic: false, finalized: false}};
|
|
552
562
|
}
|
|
553
563
|
|
|
564
|
+
let canonicalRoot: RootHex | null = null;
|
|
554
565
|
const canonicalBlock = await chain.getCanonicalBlockAtSlot(slot);
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
result.push(toBeaconHeaderResponse(config, canonicalBlock.block, true));
|
|
563
|
-
if (!canonicalBlock.finalized) {
|
|
564
|
-
finalized = false;
|
|
566
|
+
if (canonicalBlock) {
|
|
567
|
+
const header = toBeaconHeaderResponse(config, canonicalBlock.block, true);
|
|
568
|
+
canonicalRoot = toRootHex(header.root);
|
|
569
|
+
result.push(header);
|
|
570
|
+
if (!canonicalBlock.finalized) {
|
|
571
|
+
finalized = false;
|
|
572
|
+
}
|
|
565
573
|
}
|
|
566
574
|
|
|
567
|
-
//
|
|
568
|
-
// TODO: What is this logic?
|
|
575
|
+
// Non-canonical blocks at the slot, also if the canonical chain skipped it
|
|
569
576
|
await Promise.all(
|
|
570
577
|
chain.forkChoice.getBlockSummariesAtSlot(slot).map(async (summary) => {
|
|
571
578
|
if (isOptimisticBlock(summary)) {
|
|
@@ -573,7 +580,7 @@ export function getBeaconBlockApi(
|
|
|
573
580
|
}
|
|
574
581
|
finalized = false;
|
|
575
582
|
|
|
576
|
-
if (summary.blockRoot !==
|
|
583
|
+
if (summary.blockRoot !== canonicalRoot) {
|
|
577
584
|
const blockResult = await chain.getBlockByRoot(summary.blockRoot);
|
|
578
585
|
if (blockResult) {
|
|
579
586
|
result.push(toBeaconHeaderResponse(config, blockResult.block));
|
|
@@ -581,6 +588,11 @@ export function getBeaconBlockApi(
|
|
|
581
588
|
}
|
|
582
589
|
})
|
|
583
590
|
);
|
|
591
|
+
|
|
592
|
+
// skip slot
|
|
593
|
+
if (result.length === 0) {
|
|
594
|
+
return {data: [], meta: {executionOptimistic: false, finalized: false}};
|
|
595
|
+
}
|
|
584
596
|
}
|
|
585
597
|
|
|
586
598
|
return {
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
ForkPreDeneb,
|
|
10
10
|
ForkPreGloas,
|
|
11
11
|
ForkSeq,
|
|
12
|
+
GENESIS_EPOCH,
|
|
12
13
|
GENESIS_SLOT,
|
|
13
14
|
SLOTS_PER_EPOCH,
|
|
14
15
|
SLOTS_PER_HISTORICAL_ROOT,
|
|
@@ -1684,7 +1685,8 @@ export function getValidatorApi(
|
|
|
1684
1685
|
|
|
1685
1686
|
// should not compare to headEpoch in order to handle skipped slots
|
|
1686
1687
|
// Check if the epoch is in the future after waiting for requested slot
|
|
1687
|
-
|
|
1688
|
+
// Before genesis the clock epoch is negative, treat it as GENESIS_EPOCH so the next epoch can be requested
|
|
1689
|
+
if (epoch > Math.max(chain.clock.currentEpoch, GENESIS_EPOCH) + 1) {
|
|
1688
1690
|
throw new ApiError(400, "Cannot get duties for epoch more than one ahead");
|
|
1689
1691
|
}
|
|
1690
1692
|
|
|
@@ -1747,7 +1749,7 @@ export function getValidatorApi(
|
|
|
1747
1749
|
|
|
1748
1750
|
await waitForNextClosestEpoch();
|
|
1749
1751
|
|
|
1750
|
-
if (epoch > chain.clock.currentEpoch + 1) {
|
|
1752
|
+
if (epoch > Math.max(chain.clock.currentEpoch, GENESIS_EPOCH) + 1) {
|
|
1751
1753
|
throw new ApiError(400, "Cannot get PTC duties for epoch more than one ahead");
|
|
1752
1754
|
}
|
|
1753
1755
|
|
|
@@ -2,6 +2,7 @@ import {ExecutionStatus, ProtoBlock} from "@lodestar/fork-choice";
|
|
|
2
2
|
import {ForkName, ForkSeq, isForkPostFulu} from "@lodestar/params";
|
|
3
3
|
import {
|
|
4
4
|
DataAvailabilityStatus,
|
|
5
|
+
EpochShuffling,
|
|
5
6
|
IBeaconStateView,
|
|
6
7
|
computeEpochAtSlot,
|
|
7
8
|
getAttestingIndices,
|
|
@@ -111,22 +112,24 @@ export async function verifyBlocksInEpoch(
|
|
|
111
112
|
|
|
112
113
|
// Store indexed attestations for each block to avoid recomputing them during import
|
|
113
114
|
const indexedAttestationsByBlock: IndexedAttestation[][] = [];
|
|
115
|
+
const attestationShufflingsByBlock: EpochShuffling[][] = [];
|
|
114
116
|
for (const [i, block] of blocks.entries()) {
|
|
115
|
-
|
|
117
|
+
attestationShufflingsByBlock[i] = block.message.body.attestations.map((attestation) => {
|
|
116
118
|
const attEpoch = computeEpochAtSlot(attestation.data.slot);
|
|
117
119
|
// calling getShufflingAtEpoch may take some time for NativeBeaconStateView
|
|
118
120
|
// we should have the shuffling inside ShufflingCache most of the time
|
|
119
|
-
|
|
121
|
+
return (
|
|
120
122
|
this.shufflingCache.getSync(attEpoch, preState0.getShufflingDecisionRoot(attEpoch)) ??
|
|
121
|
-
preState0.getShufflingAtEpoch(attEpoch)
|
|
122
|
-
|
|
123
|
-
// these on mainnet blocks. See FullyVerifiedBlock.indexedAttestations.
|
|
124
|
-
return {
|
|
125
|
-
attestingIndices: getAttestingIndices(shuffling, fork, attestation),
|
|
126
|
-
data: attestation.data,
|
|
127
|
-
signature: attestation.signature,
|
|
128
|
-
};
|
|
123
|
+
preState0.getShufflingAtEpoch(attEpoch)
|
|
124
|
+
);
|
|
129
125
|
});
|
|
126
|
+
// Unlike getIndexedAttestation, keep attestingIndices in committee order: sorting them dominates building
|
|
127
|
+
// these on mainnet blocks. See FullyVerifiedBlock.indexedAttestations.
|
|
128
|
+
indexedAttestationsByBlock[i] = block.message.body.attestations.map((attestation, j) => ({
|
|
129
|
+
attestingIndices: getAttestingIndices(attestationShufflingsByBlock[i][j], fork, attestation),
|
|
130
|
+
data: attestation.data,
|
|
131
|
+
signature: attestation.signature,
|
|
132
|
+
}));
|
|
130
133
|
}
|
|
131
134
|
|
|
132
135
|
// Pick the data-availability source by fork:
|
|
@@ -200,6 +203,7 @@ export async function verifyBlocksInEpoch(
|
|
|
200
203
|
preState0,
|
|
201
204
|
blocks,
|
|
202
205
|
indexedAttestationsByBlock,
|
|
206
|
+
attestationShufflingsByBlock,
|
|
203
207
|
opts
|
|
204
208
|
),
|
|
205
209
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {BeaconConfig} from "@lodestar/config";
|
|
2
2
|
import {
|
|
3
|
+
EpochShuffling,
|
|
3
4
|
IBeaconStateView,
|
|
4
5
|
SyncCommitteeCacheEmpty,
|
|
5
6
|
getBlockSignatureSets,
|
|
@@ -28,6 +29,7 @@ export async function verifyBlocksSignatures(
|
|
|
28
29
|
preState0: IBeaconStateView,
|
|
29
30
|
blocks: SignedBeaconBlock[],
|
|
30
31
|
indexedAttestationsByBlock: IndexedAttestation[][],
|
|
32
|
+
attestationShufflingsByBlock: EpochShuffling[][],
|
|
31
33
|
opts: ImportBlockOpts
|
|
32
34
|
): Promise<{verifySignaturesTime: number}> {
|
|
33
35
|
const isValidPromises: Promise<boolean>[] = [];
|
|
@@ -49,6 +51,7 @@ export async function verifyBlocksSignatures(
|
|
|
49
51
|
bls.verifySignatureSets(
|
|
50
52
|
getBlockSignatureSets(config, currentSyncCommitteeIndexed, preState0, block, indexedAttestationsByBlock[i], {
|
|
51
53
|
skipProposerSignature: opts.validProposerSignature,
|
|
54
|
+
attestationShufflings: attestationShufflingsByBlock[i],
|
|
52
55
|
}),
|
|
53
56
|
// Prioritize block verification over attestations, since
|
|
54
57
|
// attestations already buffer up to `MAX_BUFFER_WAIT_MS`
|
package/src/chain/bls/utils.ts
CHANGED
|
@@ -32,7 +32,7 @@ export function chunkSameMessageSignatureSets(sets: SameMessageSignatureSet[]):
|
|
|
32
32
|
export function getAggregatedPubkeysCount(signatureSets: ISignatureSet[]): number {
|
|
33
33
|
let pubkeysCount = 0;
|
|
34
34
|
for (const set of signatureSets) {
|
|
35
|
-
if (set.type === SignatureSetType.aggregate) {
|
|
35
|
+
if (set.type === SignatureSetType.aggregate || set.type === SignatureSetType.committee) {
|
|
36
36
|
pubkeysCount += set.indices.length;
|
|
37
37
|
}
|
|
38
38
|
}
|
package/src/chain/chain.ts
CHANGED
|
@@ -7,6 +7,8 @@ import {
|
|
|
7
7
|
AncestorStatus,
|
|
8
8
|
CheckpointWithHex,
|
|
9
9
|
EpochDifference,
|
|
10
|
+
ForkChoiceError,
|
|
11
|
+
ForkChoiceErrorCode,
|
|
10
12
|
ForkChoiceStateGetter,
|
|
11
13
|
IForkChoice,
|
|
12
14
|
PayloadStatus,
|
|
@@ -1855,14 +1857,18 @@ export class BeaconChain implements IBeaconChain {
|
|
|
1855
1857
|
private onClockSlot(slot: Slot): void {
|
|
1856
1858
|
this.logger.verbose("Clock slot", {slot});
|
|
1857
1859
|
|
|
1858
|
-
// CRITICAL UPDATE
|
|
1859
|
-
if (this.forkChoice.irrecoverableError) {
|
|
1860
|
-
this.processShutdownCallback(this.forkChoice.irrecoverableError);
|
|
1861
|
-
}
|
|
1862
|
-
|
|
1863
1860
|
// updateTime() recomputes the head on epoch-boundary checkpoint pull-up and under fast confirmation
|
|
1864
1861
|
const prevHead = this.forkChoice.getHead();
|
|
1865
|
-
|
|
1862
|
+
try {
|
|
1863
|
+
this.forkChoice.updateTime(slot);
|
|
1864
|
+
} catch (e) {
|
|
1865
|
+
// Per optimistic sync the node MAY exit once the justified checkpoint is INVALIDATED, fork choice has no head
|
|
1866
|
+
if (e instanceof ForkChoiceError && e.type.code === ForkChoiceErrorCode.INVALID_JUSTIFIED_EXECUTION_STATUS) {
|
|
1867
|
+
this.processShutdownCallback(e);
|
|
1868
|
+
return;
|
|
1869
|
+
}
|
|
1870
|
+
throw e;
|
|
1871
|
+
}
|
|
1866
1872
|
this.emitHeadEvents(prevHead, this.forkChoice.getHead());
|
|
1867
1873
|
this.metrics?.clockSlot.set(slot);
|
|
1868
1874
|
|
|
@@ -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}
|
|
@@ -164,9 +164,12 @@ export class InclusionListStore {
|
|
|
164
164
|
return out;
|
|
165
165
|
}
|
|
166
166
|
|
|
167
|
-
/**
|
|
167
|
+
/**
|
|
168
|
+
* Lists are kept one slot past the MIN_SLOTS_FOR_INCLUSION_LISTS_REQUESTS serving window, the lists of slot N are
|
|
169
|
+
* read when the payload of slot N + 1 is processed, which may happen during slot N + 2
|
|
170
|
+
*/
|
|
168
171
|
prune(clockSlot: Slot): void {
|
|
169
|
-
const horizon = clockSlot - this.config.MIN_SLOTS_FOR_INCLUSION_LISTS_REQUESTS;
|
|
172
|
+
const horizon = clockSlot - this.config.MIN_SLOTS_FOR_INCLUSION_LISTS_REQUESTS - 1;
|
|
170
173
|
|
|
171
174
|
for (const slot of this.inclusionLists.keys()) {
|
|
172
175
|
if (slot < horizon) {
|
|
@@ -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
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {computeCommitteePubkeys, releaseCommitteePubkeys} from "@lodestar/native/committee-pubkeys";
|
|
2
|
+
import {ForkSeq, GENESIS_EPOCH, SLOTS_PER_EPOCH} from "@lodestar/params";
|
|
2
3
|
import {
|
|
3
4
|
EpochShuffling,
|
|
4
5
|
IBeaconStateView,
|
|
@@ -272,6 +273,40 @@ export class ShufflingCache {
|
|
|
272
273
|
// set the shuffling
|
|
273
274
|
shufflingAtEpoch.set(decisionRoot, {type: CacheItemType.shuffling, shuffling});
|
|
274
275
|
this.prune();
|
|
276
|
+
if (this.has(shuffling.epoch, decisionRoot)) {
|
|
277
|
+
this.computeCommitteePubkeys(shuffling, decisionRoot);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* Committee pubkeys make attestation signature sets cheaper to verify. Until they resolve, and if computing them
|
|
283
|
+
* fails, sets aggregate the participants instead.
|
|
284
|
+
*/
|
|
285
|
+
private computeCommitteePubkeys(shuffling: EpochShuffling, decisionRoot: RootHex): void {
|
|
286
|
+
const timer = this.metrics?.shufflingCache.committeePubkeysComputeTime.startTimer();
|
|
287
|
+
const onError = (e: unknown): void => {
|
|
288
|
+
this.metrics?.shufflingCache.committeePubkeysErrors.inc();
|
|
289
|
+
this.logger?.debug("Error computing committee pubkeys", {epoch: shuffling.epoch, decisionRoot}, e as Error);
|
|
290
|
+
};
|
|
291
|
+
|
|
292
|
+
let promise: Promise<number>;
|
|
293
|
+
try {
|
|
294
|
+
promise = computeCommitteePubkeys(shuffling.shuffling, SLOTS_PER_EPOCH, shuffling.committeesPerSlot);
|
|
295
|
+
} catch (e) {
|
|
296
|
+
onError(e);
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
promise.then((id) => {
|
|
301
|
+
timer?.();
|
|
302
|
+
const cacheItem = this.itemsByDecisionRootByEpoch.get(shuffling.epoch)?.get(decisionRoot);
|
|
303
|
+
if (cacheItem !== undefined && isShufflingCacheItem(cacheItem) && cacheItem.shuffling === shuffling) {
|
|
304
|
+
shuffling.committeePubkeysId = id;
|
|
305
|
+
} else {
|
|
306
|
+
// Pruned while computing
|
|
307
|
+
releaseCommitteePubkeys(id);
|
|
308
|
+
}
|
|
309
|
+
}, onError);
|
|
275
310
|
}
|
|
276
311
|
|
|
277
312
|
/**
|
|
@@ -294,6 +329,10 @@ export class ShufflingCache {
|
|
|
294
329
|
this.metrics?.shufflingCache.cancelledPromises.inc({reason: ShufflingPromiseCancelReason.pruned});
|
|
295
330
|
} else {
|
|
296
331
|
prunedShufflings++;
|
|
332
|
+
if (cacheItem.shuffling.committeePubkeysId !== undefined) {
|
|
333
|
+
releaseCommitteePubkeys(cacheItem.shuffling.committeePubkeysId);
|
|
334
|
+
cacheItem.shuffling.committeePubkeysId = undefined;
|
|
335
|
+
}
|
|
297
336
|
}
|
|
298
337
|
}
|
|
299
338
|
this.itemsByDecisionRootByEpoch.delete(epoch);
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import {ForkName, ForkSeq} from "@lodestar/params";
|
|
2
2
|
import {
|
|
3
|
+
ISignatureSet,
|
|
4
|
+
SignatureSetType,
|
|
3
5
|
computeEpochAtSlot,
|
|
4
6
|
createAggregateSignatureSetFromComponents,
|
|
5
7
|
isAggregatorFromCommitteeLength,
|
|
@@ -259,11 +261,23 @@ async function validateAggregateAndProof(
|
|
|
259
261
|
// [REJECT] The aggregator signature, signed_aggregate_and_proof.signature, is valid.
|
|
260
262
|
// [REJECT] The signature of aggregate is valid.
|
|
261
263
|
const signingRoot = cachedAttData ? cachedAttData.signingRoot : getAttestationDataSigningRoot(chain.config, attData);
|
|
262
|
-
const indexedAttestationSignatureSet =
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
264
|
+
const indexedAttestationSignatureSet: ISignatureSet =
|
|
265
|
+
shuffling.committeePubkeysId === undefined
|
|
266
|
+
? createAggregateSignatureSetFromComponents(
|
|
267
|
+
indexedAttestation.attestingIndices,
|
|
268
|
+
signingRoot,
|
|
269
|
+
indexedAttestation.signature
|
|
270
|
+
)
|
|
271
|
+
: {
|
|
272
|
+
type: SignatureSetType.committee,
|
|
273
|
+
indices: indexedAttestation.attestingIndices,
|
|
274
|
+
committeePubkeysId: shuffling.committeePubkeysId,
|
|
275
|
+
slot: attSlot,
|
|
276
|
+
committeeIndices: [committeeIndex],
|
|
277
|
+
aggregationBits: aggregate.aggregationBits,
|
|
278
|
+
signingRoot,
|
|
279
|
+
signature: indexedAttestation.signature,
|
|
280
|
+
};
|
|
267
281
|
const signatureSets = [
|
|
268
282
|
getSelectionProofSignatureSet(chain.config, attSlot, aggregatorIndex, signedAggregateAndProof),
|
|
269
283
|
getAggregateAndProofSignatureSet(chain.config, attEpoch, aggregatorIndex, signedAggregateAndProof),
|
|
@@ -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
|
}
|
|
@@ -1784,6 +1784,15 @@ export function createLodestarMetrics(
|
|
|
1784
1784
|
help: "Time from promise insertion until promise resolution when shuffling was ready in seconds",
|
|
1785
1785
|
buckets: [0.5, 1, 1.5, 2],
|
|
1786
1786
|
}),
|
|
1787
|
+
committeePubkeysComputeTime: register.histogram({
|
|
1788
|
+
name: "lodestar_shuffling_cache_committee_pubkeys_compute_seconds",
|
|
1789
|
+
help: "Time to aggregate the committee pubkeys of a shuffling off the main thread in seconds",
|
|
1790
|
+
buckets: [0.1, 0.25, 0.5, 1, 2, 5],
|
|
1791
|
+
}),
|
|
1792
|
+
committeePubkeysErrors: register.counter({
|
|
1793
|
+
name: "lodestar_shuffling_cache_committee_pubkeys_errors_total",
|
|
1794
|
+
help: "Total number of shufflings whose committee pubkeys could not be computed",
|
|
1795
|
+
}),
|
|
1787
1796
|
},
|
|
1788
1797
|
|
|
1789
1798
|
seenCache: {
|