@lodestar/beacon-node 1.52.0-dev.1f4a364fc5 → 1.52.0-dev.20cca3c9f1
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/validator/index.d.ts.map +1 -1
- package/lib/api/impl/validator/index.js +15 -9
- package/lib/api/impl/validator/index.js.map +1 -1
- package/lib/chain/ColumnReconstructionTracker.d.ts +4 -0
- package/lib/chain/ColumnReconstructionTracker.d.ts.map +1 -1
- package/lib/chain/ColumnReconstructionTracker.js +4 -0
- package/lib/chain/ColumnReconstructionTracker.js.map +1 -1
- package/lib/chain/archiveStore/historicalState/getHistoricalState.d.ts.map +1 -1
- package/lib/chain/archiveStore/historicalState/getHistoricalState.js +7 -0
- package/lib/chain/archiveStore/historicalState/getHistoricalState.js.map +1 -1
- package/lib/chain/archiveStore/utils/pruneHistory.d.ts.map +1 -1
- package/lib/chain/archiveStore/utils/pruneHistory.js +8 -4
- package/lib/chain/archiveStore/utils/pruneHistory.js.map +1 -1
- package/lib/chain/blocks/importExecutionPayload.d.ts +1 -1
- package/lib/chain/blocks/importExecutionPayload.d.ts.map +1 -1
- package/lib/chain/blocks/importExecutionPayload.js +9 -3
- package/lib/chain/blocks/importExecutionPayload.js.map +1 -1
- package/lib/chain/blocks/index.js +0 -1
- package/lib/chain/blocks/index.js.map +1 -1
- package/lib/chain/chain.d.ts +3 -2
- package/lib/chain/chain.d.ts.map +1 -1
- package/lib/chain/chain.js +30 -7
- package/lib/chain/chain.js.map +1 -1
- package/lib/chain/errors/attestationError.d.ts +15 -1
- package/lib/chain/errors/attestationError.d.ts.map +1 -1
- package/lib/chain/errors/attestationError.js +8 -0
- package/lib/chain/errors/attestationError.js.map +1 -1
- package/lib/chain/errors/executionPayloadBid.d.ts +6 -1
- package/lib/chain/errors/executionPayloadBid.d.ts.map +1 -1
- package/lib/chain/errors/executionPayloadBid.js +1 -0
- package/lib/chain/errors/executionPayloadBid.js.map +1 -1
- package/lib/chain/errors/executionPayloadEnvelope.d.ts +55 -0
- package/lib/chain/errors/executionPayloadEnvelope.d.ts.map +1 -1
- package/lib/chain/errors/executionPayloadEnvelope.js +8 -0
- package/lib/chain/errors/executionPayloadEnvelope.js.map +1 -1
- package/lib/chain/lightClient/index.d.ts +13 -6
- package/lib/chain/lightClient/index.d.ts.map +1 -1
- package/lib/chain/lightClient/index.js +95 -115
- package/lib/chain/lightClient/index.js.map +1 -1
- package/lib/chain/prepareNextSlot.d.ts +45 -0
- package/lib/chain/prepareNextSlot.d.ts.map +1 -1
- package/lib/chain/prepareNextSlot.js +265 -69
- package/lib/chain/prepareNextSlot.js.map +1 -1
- package/lib/chain/produceBlock/produceBlockBody.d.ts +1 -0
- package/lib/chain/produceBlock/produceBlockBody.d.ts.map +1 -1
- package/lib/chain/produceBlock/produceBlockBody.js +23 -15
- package/lib/chain/produceBlock/produceBlockBody.js.map +1 -1
- package/lib/chain/seenCache/seenAttesters.d.ts +1 -0
- package/lib/chain/seenCache/seenAttesters.d.ts.map +1 -1
- package/lib/chain/seenCache/seenAttesters.js +1 -1
- package/lib/chain/seenCache/seenAttesters.js.map +1 -1
- package/lib/chain/seenCache/seenBlockAttesters.d.ts +8 -2
- package/lib/chain/seenCache/seenBlockAttesters.d.ts.map +1 -1
- package/lib/chain/seenCache/seenBlockAttesters.js +43 -6
- package/lib/chain/seenCache/seenBlockAttesters.js.map +1 -1
- package/lib/chain/validation/aggregateAndProof.d.ts.map +1 -1
- package/lib/chain/validation/aggregateAndProof.js +24 -7
- package/lib/chain/validation/aggregateAndProof.js.map +1 -1
- package/lib/chain/validation/attestation.d.ts.map +1 -1
- package/lib/chain/validation/attestation.js +32 -16
- 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 +9 -1
- package/lib/chain/validation/block.js.map +1 -1
- package/lib/chain/validation/executionPayloadBid.d.ts.map +1 -1
- package/lib/chain/validation/executionPayloadBid.js +17 -2
- package/lib/chain/validation/executionPayloadBid.js.map +1 -1
- package/lib/chain/validation/executionPayloadEnvelope.d.ts.map +1 -1
- package/lib/chain/validation/executionPayloadEnvelope.js +100 -9
- package/lib/chain/validation/executionPayloadEnvelope.js.map +1 -1
- package/lib/chain/validation/payloadAttestationMessage.js +9 -0
- package/lib/chain/validation/payloadAttestationMessage.js.map +1 -1
- package/lib/chain/validation/voluntaryExit.d.ts.map +1 -1
- package/lib/chain/validation/voluntaryExit.js +39 -6
- package/lib/chain/validation/voluntaryExit.js.map +1 -1
- package/lib/execution/engine/blockHash.d.ts +12 -0
- package/lib/execution/engine/blockHash.d.ts.map +1 -0
- package/lib/execution/engine/blockHash.js +17 -0
- package/lib/execution/engine/blockHash.js.map +1 -0
- package/lib/execution/engine/http.d.ts +2 -2
- package/lib/execution/engine/http.d.ts.map +1 -1
- package/lib/execution/engine/http.js +13 -7
- package/lib/execution/engine/http.js.map +1 -1
- package/lib/execution/engine/interface.d.ts +16 -3
- package/lib/execution/engine/interface.d.ts.map +1 -1
- package/lib/execution/engine/interface.js +11 -0
- package/lib/execution/engine/interface.js.map +1 -1
- package/lib/execution/engine/jsonRpcHttpClient.d.ts +2 -0
- package/lib/execution/engine/jsonRpcHttpClient.d.ts.map +1 -1
- package/lib/execution/engine/jsonRpcHttpClient.js +14 -6
- package/lib/execution/engine/jsonRpcHttpClient.js.map +1 -1
- package/lib/execution/engine/jsonRpcTransport.d.ts +2 -2
- package/lib/execution/engine/jsonRpcTransport.d.ts.map +1 -1
- package/lib/execution/engine/jsonRpcTransport.js +4 -4
- package/lib/execution/engine/jsonRpcTransport.js.map +1 -1
- package/lib/execution/engine/mock.d.ts.map +1 -1
- package/lib/execution/engine/mock.js +6 -6
- package/lib/execution/engine/mock.js.map +1 -1
- package/lib/execution/engine/payloadIdCache.d.ts +6 -1
- package/lib/execution/engine/payloadIdCache.d.ts.map +1 -1
- package/lib/execution/engine/payloadIdCache.js +7 -2
- package/lib/execution/engine/payloadIdCache.js.map +1 -1
- package/lib/execution/engine/restHttpClient.d.ts.map +1 -1
- package/lib/execution/engine/restHttpClient.js +9 -5
- package/lib/execution/engine/restHttpClient.js.map +1 -1
- package/lib/execution/engine/restTransport.d.ts +2 -2
- package/lib/execution/engine/restTransport.d.ts.map +1 -1
- package/lib/execution/engine/restTransport.js +4 -4
- package/lib/execution/engine/restTransport.js.map +1 -1
- package/lib/execution/engine/signal.d.ts +6 -0
- package/lib/execution/engine/signal.d.ts.map +1 -0
- package/lib/execution/engine/signal.js +24 -0
- package/lib/execution/engine/signal.js.map +1 -0
- package/lib/execution/engine/transport.d.ts +2 -2
- package/lib/execution/engine/transport.d.ts.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/metrics/metrics/beacon.d.ts +5 -0
- package/lib/metrics/metrics/beacon.d.ts.map +1 -1
- package/lib/metrics/metrics/beacon.js +5 -0
- package/lib/metrics/metrics/beacon.js.map +1 -1
- package/lib/metrics/metrics/lodestar.d.ts +1 -0
- package/lib/metrics/metrics/lodestar.d.ts.map +1 -1
- package/lib/metrics/metrics/lodestar.js +5 -0
- package/lib/metrics/metrics/lodestar.js.map +1 -1
- package/lib/network/gossip/gossipsub.d.ts +1 -0
- package/lib/network/gossip/gossipsub.d.ts.map +1 -1
- package/lib/network/gossip/gossipsub.js +5 -2
- package/lib/network/gossip/gossipsub.js.map +1 -1
- package/lib/network/network.d.ts.map +1 -1
- package/lib/network/network.js +6 -1
- package/lib/network/network.js.map +1 -1
- package/lib/network/peers/peerManager.d.ts.map +1 -1
- package/lib/network/peers/peerManager.js +22 -2
- package/lib/network/peers/peerManager.js.map +1 -1
- package/lib/network/peers/utils/prioritizePeers.d.ts +2 -0
- package/lib/network/peers/utils/prioritizePeers.d.ts.map +1 -1
- package/lib/network/peers/utils/prioritizePeers.js +11 -2
- package/lib/network/peers/utils/prioritizePeers.js.map +1 -1
- package/lib/network/processor/gossipHandlers.d.ts.map +1 -1
- package/lib/network/processor/gossipHandlers.js +15 -6
- package/lib/network/processor/gossipHandlers.js.map +1 -1
- package/lib/network/processor/index.d.ts.map +1 -1
- package/lib/network/processor/index.js +4 -2
- package/lib/network/processor/index.js.map +1 -1
- package/lib/sync/range/batch.d.ts +6 -0
- package/lib/sync/range/batch.d.ts.map +1 -1
- package/lib/sync/range/batch.js +17 -0
- package/lib/sync/range/batch.js.map +1 -1
- package/lib/sync/range/chain.d.ts.map +1 -1
- package/lib/sync/range/chain.js +8 -1
- package/lib/sync/range/chain.js.map +1 -1
- package/lib/sync/range/range.d.ts.map +1 -1
- package/lib/sync/range/range.js +43 -3
- package/lib/sync/range/range.js.map +1 -1
- package/lib/sync/types.d.ts +14 -1
- package/lib/sync/types.d.ts.map +1 -1
- package/lib/sync/types.js +2 -0
- package/lib/sync/types.js.map +1 -1
- package/lib/sync/unknownBlock.d.ts +28 -1
- package/lib/sync/unknownBlock.d.ts.map +1 -1
- package/lib/sync/unknownBlock.js +338 -26
- package/lib/sync/unknownBlock.js.map +1 -1
- package/lib/sync/utils/downloadByRange.d.ts +14 -1
- package/lib/sync/utils/downloadByRange.d.ts.map +1 -1
- package/lib/sync/utils/downloadByRange.js +12 -2
- package/lib/sync/utils/downloadByRange.js.map +1 -1
- package/lib/sync/utils/downloadByRoot.d.ts +24 -2
- package/lib/sync/utils/downloadByRoot.d.ts.map +1 -1
- package/lib/sync/utils/downloadByRoot.js +48 -5
- package/lib/sync/utils/downloadByRoot.js.map +1 -1
- package/lib/util/eventLoop.d.ts +3 -3
- package/lib/util/eventLoop.d.ts.map +1 -1
- package/lib/util/eventLoop.js +3 -3
- package/lib/util/eventLoop.js.map +1 -1
- package/package.json +27 -27
- package/src/api/impl/validator/index.ts +17 -10
- package/src/chain/ColumnReconstructionTracker.ts +5 -0
- package/src/chain/archiveStore/historicalState/getHistoricalState.ts +9 -0
- package/src/chain/archiveStore/utils/pruneHistory.ts +9 -4
- package/src/chain/blocks/importExecutionPayload.ts +9 -2
- package/src/chain/blocks/index.ts +0 -1
- package/src/chain/chain.ts +35 -8
- package/src/chain/errors/attestationError.ts +11 -1
- package/src/chain/errors/executionPayloadBid.ts +6 -0
- package/src/chain/errors/executionPayloadEnvelope.ts +58 -0
- package/src/chain/lightClient/index.ts +108 -142
- package/src/chain/prepareNextSlot.ts +347 -89
- package/src/chain/produceBlock/produceBlockBody.ts +25 -16
- package/src/chain/seenCache/seenAttesters.ts +1 -1
- package/src/chain/seenCache/seenBlockAttesters.ts +48 -6
- package/src/chain/validation/aggregateAndProof.ts +24 -9
- package/src/chain/validation/attestation.ts +31 -20
- package/src/chain/validation/block.ts +9 -1
- package/src/chain/validation/executionPayloadBid.ts +20 -2
- package/src/chain/validation/executionPayloadEnvelope.ts +115 -8
- package/src/chain/validation/payloadAttestationMessage.ts +10 -0
- package/src/chain/validation/voluntaryExit.ts +44 -6
- package/src/execution/engine/blockHash.ts +27 -0
- package/src/execution/engine/http.ts +18 -10
- package/src/execution/engine/interface.ts +18 -3
- package/src/execution/engine/jsonRpcHttpClient.ts +26 -14
- package/src/execution/engine/jsonRpcTransport.ts +8 -4
- package/src/execution/engine/mock.ts +13 -8
- package/src/execution/engine/payloadIdCache.ts +12 -4
- package/src/execution/engine/restHttpClient.ts +17 -11
- package/src/execution/engine/restTransport.ts +5 -4
- package/src/execution/engine/signal.ts +28 -0
- package/src/execution/engine/transport.ts +3 -2
- package/src/index.ts +6 -1
- package/src/metrics/metrics/beacon.ts +9 -0
- package/src/metrics/metrics/lodestar.ts +5 -0
- package/src/network/gossip/gossipsub.ts +6 -2
- package/src/network/network.ts +6 -2
- package/src/network/peers/peerManager.ts +26 -2
- package/src/network/peers/utils/prioritizePeers.ts +14 -1
- package/src/network/processor/gossipHandlers.ts +15 -7
- package/src/network/processor/index.ts +7 -2
- package/src/sync/range/batch.ts +20 -0
- package/src/sync/range/chain.ts +8 -0
- package/src/sync/range/range.ts +56 -3
- package/src/sync/types.ts +13 -0
- package/src/sync/unknownBlock.ts +387 -28
- package/src/sync/utils/downloadByRange.ts +29 -3
- package/src/sync/utils/downloadByRoot.ts +75 -7
- package/src/util/eventLoop.ts +3 -3
package/src/chain/chain.ts
CHANGED
|
@@ -93,7 +93,7 @@ import {persistBlockInput} from "./blocks/writeBlockInputToDb.js";
|
|
|
93
93
|
import {persistPayloadEnvelopeInput} from "./blocks/writePayloadEnvelopeInputToDb.js";
|
|
94
94
|
import {BlsMultiThreadWorkerPool, BlsSingleThreadVerifier, IBlsVerifier} from "./bls/index.js";
|
|
95
95
|
import {BuilderCircuitBreaker} from "./builderCircuitBreaker.js";
|
|
96
|
-
import {ColumnReconstructionTracker} from "./ColumnReconstructionTracker.js";
|
|
96
|
+
import {ColumnReconstructionTracker, RECONSTRUCTED_COLUMNS_WAIT_BPS} from "./ColumnReconstructionTracker.js";
|
|
97
97
|
import {ChainEvent, ChainEventEmitter, ReorgEventData} from "./emitter.js";
|
|
98
98
|
import {ForkchoiceCaller, initializeForkChoice} from "./forkChoice/index.js";
|
|
99
99
|
import {ForkChoiceExecutionEngine} from "./forkChoiceExecutionEngine.js";
|
|
@@ -896,16 +896,18 @@ export class BeaconChain implements IBeaconChain {
|
|
|
896
896
|
): Promise<{block: SignedBeaconBlock; executionOptimistic: boolean; finalized: boolean} | null> {
|
|
897
897
|
const block = this.forkChoice.getBlockHexDefaultStatus(root);
|
|
898
898
|
if (block) {
|
|
899
|
+
// The finalized block stays in fork-choice and the hot db until the archiver has migrated it
|
|
900
|
+
const finalized = block.slot <= this.forkChoice.getFinalizedBlock().slot;
|
|
899
901
|
// Block found in fork-choice.
|
|
900
902
|
// It may be in the block input cache, awaiting full DA reconstruction, check there first
|
|
901
903
|
// Otherwise (most likely), check the hot db
|
|
902
904
|
const blockInput = this.seenBlockInputCache.get(block.blockRoot);
|
|
903
905
|
if (blockInput?.hasBlock()) {
|
|
904
|
-
return {block: blockInput.getBlock(), executionOptimistic: isOptimisticBlock(block), finalized
|
|
906
|
+
return {block: blockInput.getBlock(), executionOptimistic: isOptimisticBlock(block), finalized};
|
|
905
907
|
}
|
|
906
908
|
const data = await this.db.block.get(fromHex(root));
|
|
907
909
|
if (data) {
|
|
908
|
-
return {block: data, executionOptimistic: isOptimisticBlock(block), finalized
|
|
910
|
+
return {block: data, executionOptimistic: isOptimisticBlock(block), finalized};
|
|
909
911
|
}
|
|
910
912
|
// If block is not found in hot db, try cold db since there could be an archive cycle happening
|
|
911
913
|
// TODO: Add a lock to the archiver to have deterministic behavior on where are blocks
|
|
@@ -920,6 +922,8 @@ export class BeaconChain implements IBeaconChain {
|
|
|
920
922
|
): Promise<{block: Uint8Array; executionOptimistic: boolean; finalized: boolean; slot: Slot} | null> {
|
|
921
923
|
const block = this.forkChoice.getBlockHexDefaultStatus(root);
|
|
922
924
|
if (block) {
|
|
925
|
+
// The finalized block stays in fork-choice and the hot db until the archiver has migrated it
|
|
926
|
+
const finalized = block.slot <= this.forkChoice.getFinalizedBlock().slot;
|
|
923
927
|
// Block found in fork-choice.
|
|
924
928
|
// It may be in the block input cache, awaiting full DA reconstruction, check there first
|
|
925
929
|
// Otherwise (most likely), check the hot db
|
|
@@ -931,14 +935,14 @@ export class BeaconChain implements IBeaconChain {
|
|
|
931
935
|
return {
|
|
932
936
|
block: serialized,
|
|
933
937
|
executionOptimistic: isOptimisticBlock(block),
|
|
934
|
-
finalized
|
|
938
|
+
finalized,
|
|
935
939
|
slot: blockInput.slot,
|
|
936
940
|
};
|
|
937
941
|
}
|
|
938
942
|
return {
|
|
939
943
|
block: sszTypesFor(blockInput.forkName).SignedBeaconBlock.serialize(signedBlock),
|
|
940
944
|
executionOptimistic: isOptimisticBlock(block),
|
|
941
|
-
finalized
|
|
945
|
+
finalized,
|
|
942
946
|
slot: blockInput.slot,
|
|
943
947
|
};
|
|
944
948
|
}
|
|
@@ -946,7 +950,7 @@ export class BeaconChain implements IBeaconChain {
|
|
|
946
950
|
if (data) {
|
|
947
951
|
const slot = getSlotFromSignedBeaconBlockSerialized(data);
|
|
948
952
|
if (slot === null) throw new Error(`Invalid block data stored in DB for root: ${root}`);
|
|
949
|
-
return {block: data, executionOptimistic: isOptimisticBlock(block), finalized
|
|
953
|
+
return {block: data, executionOptimistic: isOptimisticBlock(block), finalized, slot};
|
|
950
954
|
}
|
|
951
955
|
// If block is not found in hot db, try cold db since there could be an archive cycle happening
|
|
952
956
|
// TODO: Add a lock to the archiver to have deterministic behavior on where are blocks
|
|
@@ -1129,6 +1133,17 @@ export class BeaconChain implements IBeaconChain {
|
|
|
1129
1133
|
// After gloas, columns are tracked in PayloadEnvelopeInput
|
|
1130
1134
|
const payloadInput = this.seenPayloadEnvelopeInputCache.get(blockRootHex);
|
|
1131
1135
|
if (payloadInput) {
|
|
1136
|
+
// Available with half the columns, peers that saw it attested expect the reconstructed rest
|
|
1137
|
+
if (
|
|
1138
|
+
!payloadInput.hasComputedAllData() &&
|
|
1139
|
+
payloadInput.hasAllData() &&
|
|
1140
|
+
indices.some((index) => !payloadInput.hasColumn(index))
|
|
1141
|
+
) {
|
|
1142
|
+
this.columnReconstructionTracker.triggerColumnReconstruction(payloadInput);
|
|
1143
|
+
await payloadInput
|
|
1144
|
+
.waitForComputedAllData(this.config.getSlotComponentDurationMs(fork, RECONSTRUCTED_COLUMNS_WAIT_BPS))
|
|
1145
|
+
.catch(() => this.logger.debug("Columns not reconstructed in time", {slot: blockSlot, root: blockRootHex}));
|
|
1146
|
+
}
|
|
1132
1147
|
for (let i = 0; i < indices.length; i++) {
|
|
1133
1148
|
const index = indices[i];
|
|
1134
1149
|
const sidecar = payloadInput.getColumn(index);
|
|
@@ -1150,6 +1165,17 @@ export class BeaconChain implements IBeaconChain {
|
|
|
1150
1165
|
if (!isBlockInputColumns(blockInput)) {
|
|
1151
1166
|
throw new Error(`Expected block input to have columns: slot=${blockSlot} root=${blockRootHex}`);
|
|
1152
1167
|
}
|
|
1168
|
+
// Available with half the columns, peers that saw it attested expect the reconstructed rest
|
|
1169
|
+
if (
|
|
1170
|
+
!blockInput.hasComputedAllData() &&
|
|
1171
|
+
blockInput.hasAllData() &&
|
|
1172
|
+
indices.some((index) => !blockInput.hasColumn(index))
|
|
1173
|
+
) {
|
|
1174
|
+
this.columnReconstructionTracker.triggerColumnReconstruction(blockInput);
|
|
1175
|
+
await blockInput
|
|
1176
|
+
.waitForComputedAllData(this.config.getSlotComponentDurationMs(fork, RECONSTRUCTED_COLUMNS_WAIT_BPS))
|
|
1177
|
+
.catch(() => this.logger.debug("Columns not reconstructed in time", {slot: blockSlot, root: blockRootHex}));
|
|
1178
|
+
}
|
|
1153
1179
|
for (let i = 0; i < indices.length; i++) {
|
|
1154
1180
|
const index = indices[i];
|
|
1155
1181
|
const sidecar = blockInput.getColumn(index);
|
|
@@ -1476,9 +1502,10 @@ export class BeaconChain implements IBeaconChain {
|
|
|
1476
1502
|
|
|
1477
1503
|
/**
|
|
1478
1504
|
* Emit `head` and `head_v2` when the fork choice head differs between two observations. Every caller that
|
|
1479
|
-
* can move the head, `updateAndGetHead()` and `
|
|
1505
|
+
* can move the head, `updateAndGetHead()`, `updateTime()` and `onExecutionPayload()`, must capture the head before
|
|
1506
|
+
* and pass both.
|
|
1480
1507
|
*/
|
|
1481
|
-
|
|
1508
|
+
emitHeadEvents(prevHead: ProtoBlock, head: ProtoBlock): void {
|
|
1482
1509
|
const headRootChanged = head.blockRoot !== prevHead.blockRoot;
|
|
1483
1510
|
|
|
1484
1511
|
if (!headRootChanged && prevHead.payloadStatus === head.payloadStatus) {
|
|
@@ -151,6 +151,14 @@ export enum AttestationErrorCode {
|
|
|
151
151
|
* Gloas: index-1 attestation but the execution payload has not been seen yet
|
|
152
152
|
*/
|
|
153
153
|
EXECUTION_PAYLOAD_NOT_SEEN = "ATTESTATION_ERROR_EXECUTION_PAYLOAD_NOT_SEEN",
|
|
154
|
+
/**
|
|
155
|
+
* Gloas: index-1 attestation to a block whose execution payload is not yet validated by the execution engine
|
|
156
|
+
*/
|
|
157
|
+
EXECUTION_PAYLOAD_OPTIMISTIC = "ATTESTATION_ERROR_EXECUTION_PAYLOAD_OPTIMISTIC",
|
|
158
|
+
/**
|
|
159
|
+
* Gloas: index-1 attestation to a block whose execution payload was invalidated
|
|
160
|
+
*/
|
|
161
|
+
EXECUTION_PAYLOAD_INVALID = "ATTESTATION_ERROR_EXECUTION_PAYLOAD_INVALID",
|
|
154
162
|
}
|
|
155
163
|
|
|
156
164
|
export type AttestationErrorType =
|
|
@@ -190,7 +198,9 @@ export type AttestationErrorType =
|
|
|
190
198
|
| {code: AttestationErrorCode.ATTESTER_NOT_IN_COMMITTEE}
|
|
191
199
|
| {code: AttestationErrorCode.INVALID_PAYLOAD_STATUS_VALUE; attDataIndex: number}
|
|
192
200
|
| {code: AttestationErrorCode.PREMATURELY_INDICATED_PAYLOAD_PRESENT}
|
|
193
|
-
| {code: AttestationErrorCode.EXECUTION_PAYLOAD_NOT_SEEN; beaconBlockRoot: RootHex}
|
|
201
|
+
| {code: AttestationErrorCode.EXECUTION_PAYLOAD_NOT_SEEN; beaconBlockRoot: RootHex}
|
|
202
|
+
| {code: AttestationErrorCode.EXECUTION_PAYLOAD_OPTIMISTIC; beaconBlockRoot: RootHex}
|
|
203
|
+
| {code: AttestationErrorCode.EXECUTION_PAYLOAD_INVALID; beaconBlockRoot: RootHex};
|
|
194
204
|
|
|
195
205
|
export class AttestationError extends GossipActionError<AttestationErrorType> {
|
|
196
206
|
getMetadata(): Record<string, string | number | null> {
|
|
@@ -23,6 +23,7 @@ export enum ExecutionPayloadBidErrorCode {
|
|
|
23
23
|
PROPOSER_PREFERENCES_GAS_LIMIT_MISMATCH = "EXECUTION_PAYLOAD_BID_ERROR_PROPOSER_PREFERENCES_GAS_LIMIT_MISMATCH",
|
|
24
24
|
INCLUSION_LIST_BITS_NOT_INCLUSIVE = "EXECUTION_PAYLOAD_BID_ERROR_INCLUSION_LIST_BITS_NOT_INCLUSIVE",
|
|
25
25
|
BEFORE_INCLUSION_LIST_DEADLINE = "EXECUTION_PAYLOAD_BID_ERROR_BEFORE_INCLUSION_LIST_DEADLINE",
|
|
26
|
+
BEFORE_PAYLOAD_ATTESTATION_DEADLINE = "EXECUTION_PAYLOAD_BID_ERROR_BEFORE_PAYLOAD_ATTESTATION_DEADLINE",
|
|
26
27
|
}
|
|
27
28
|
|
|
28
29
|
export type ExecutionPayloadBidErrorType =
|
|
@@ -99,6 +100,11 @@ export type ExecutionPayloadBidErrorType =
|
|
|
99
100
|
builderIndex: BuilderIndex;
|
|
100
101
|
slot: Slot;
|
|
101
102
|
}
|
|
103
|
+
| {
|
|
104
|
+
code: ExecutionPayloadBidErrorCode.BEFORE_PAYLOAD_ATTESTATION_DEADLINE;
|
|
105
|
+
builderIndex: BuilderIndex;
|
|
106
|
+
slot: Slot;
|
|
107
|
+
}
|
|
102
108
|
| {
|
|
103
109
|
code: ExecutionPayloadBidErrorCode.PROPOSER_PREFERENCES_GAS_LIMIT_MISMATCH;
|
|
104
110
|
builderIndex: BuilderIndex;
|
|
@@ -9,10 +9,18 @@ export enum ExecutionPayloadEnvelopeErrorCode {
|
|
|
9
9
|
ENVELOPE_ALREADY_KNOWN = "EXECUTION_PAYLOAD_ENVELOPE_ERROR_ALREADY_KNOWN",
|
|
10
10
|
INVALID_BLOCK = "EXECUTION_PAYLOAD_ENVELOPE_ERROR_INVALID_BLOCK",
|
|
11
11
|
SLOT_MISMATCH = "EXECUTION_PAYLOAD_ENVELOPE_ERROR_SLOT_MISMATCH",
|
|
12
|
+
PARENT_BEACON_BLOCK_ROOT_MISMATCH = "EXECUTION_PAYLOAD_ENVELOPE_ERROR_PARENT_BEACON_BLOCK_ROOT_MISMATCH",
|
|
12
13
|
BUILDER_INDEX_MISMATCH = "EXECUTION_PAYLOAD_ENVELOPE_ERROR_BUILDER_INDEX_MISMATCH",
|
|
14
|
+
PREV_RANDAO_MISMATCH = "EXECUTION_PAYLOAD_ENVELOPE_ERROR_PREV_RANDAO_MISMATCH",
|
|
15
|
+
GAS_LIMIT_MISMATCH = "EXECUTION_PAYLOAD_ENVELOPE_ERROR_GAS_LIMIT_MISMATCH",
|
|
13
16
|
BLOCK_HASH_MISMATCH = "EXECUTION_PAYLOAD_ENVELOPE_ERROR_BLOCK_HASH_MISMATCH",
|
|
14
17
|
EXECUTION_REQUESTS_ROOT_MISMATCH = "EXECUTION_PAYLOAD_ENVELOPE_ERROR_EXECUTION_REQUESTS_ROOT_MISMATCH",
|
|
15
18
|
TOO_MANY_TRANSACTIONS = "EXECUTION_PAYLOAD_ENVELOPE_ERROR_TOO_MANY_TRANSACTIONS",
|
|
19
|
+
PARENT_HASH_MISMATCH = "EXECUTION_PAYLOAD_ENVELOPE_ERROR_PARENT_HASH_MISMATCH",
|
|
20
|
+
INCORRECT_TIMESTAMP = "EXECUTION_PAYLOAD_ENVELOPE_ERROR_INCORRECT_TIMESTAMP",
|
|
21
|
+
EMPTY_TRANSACTION = "EXECUTION_PAYLOAD_ENVELOPE_ERROR_EMPTY_TRANSACTION",
|
|
22
|
+
WITHDRAWALS_MISMATCH = "EXECUTION_PAYLOAD_ENVELOPE_ERROR_WITHDRAWALS_MISMATCH",
|
|
23
|
+
INVALID_BLOCK_HASH = "EXECUTION_PAYLOAD_ENVELOPE_ERROR_INVALID_BLOCK_HASH",
|
|
16
24
|
INVALID_SIGNATURE = "EXECUTION_PAYLOAD_ENVELOPE_ERROR_INVALID_SIGNATURE",
|
|
17
25
|
PAYLOAD_ENVELOPE_INPUT_MISSING = "EXECUTION_PAYLOAD_ENVELOPE_ERROR_PAYLOAD_ENVELOPE_INPUT_MISSING",
|
|
18
26
|
}
|
|
@@ -34,6 +42,13 @@ export type ExecutionPayloadEnvelopeErrorType =
|
|
|
34
42
|
envelopeSlot: Slot;
|
|
35
43
|
blockSlot: Slot;
|
|
36
44
|
}
|
|
45
|
+
| {
|
|
46
|
+
code: ExecutionPayloadEnvelopeErrorCode.PARENT_BEACON_BLOCK_ROOT_MISMATCH;
|
|
47
|
+
slot: Slot;
|
|
48
|
+
root: RootHex;
|
|
49
|
+
envelopeParentBeaconBlockRoot: RootHex;
|
|
50
|
+
blockParentRoot: RootHex;
|
|
51
|
+
}
|
|
37
52
|
| {
|
|
38
53
|
code: ExecutionPayloadEnvelopeErrorCode.BUILDER_INDEX_MISMATCH;
|
|
39
54
|
slot: Slot;
|
|
@@ -41,6 +56,20 @@ export type ExecutionPayloadEnvelopeErrorType =
|
|
|
41
56
|
envelopeBuilderIndex: BuilderIndex;
|
|
42
57
|
bidBuilderIndex: BuilderIndex | null;
|
|
43
58
|
}
|
|
59
|
+
| {
|
|
60
|
+
code: ExecutionPayloadEnvelopeErrorCode.PREV_RANDAO_MISMATCH;
|
|
61
|
+
slot: Slot;
|
|
62
|
+
root: RootHex;
|
|
63
|
+
envelopePrevRandao: RootHex;
|
|
64
|
+
bidPrevRandao: RootHex;
|
|
65
|
+
}
|
|
66
|
+
| {
|
|
67
|
+
code: ExecutionPayloadEnvelopeErrorCode.GAS_LIMIT_MISMATCH;
|
|
68
|
+
slot: Slot;
|
|
69
|
+
root: RootHex;
|
|
70
|
+
envelopeGasLimit: number;
|
|
71
|
+
bidGasLimit: bigint;
|
|
72
|
+
}
|
|
44
73
|
| {
|
|
45
74
|
code: ExecutionPayloadEnvelopeErrorCode.BLOCK_HASH_MISMATCH;
|
|
46
75
|
slot: Slot;
|
|
@@ -62,6 +91,35 @@ export type ExecutionPayloadEnvelopeErrorType =
|
|
|
62
91
|
transactionCount: number;
|
|
63
92
|
maxTransactionCount: number;
|
|
64
93
|
}
|
|
94
|
+
| {
|
|
95
|
+
code: ExecutionPayloadEnvelopeErrorCode.PARENT_HASH_MISMATCH;
|
|
96
|
+
slot: Slot;
|
|
97
|
+
root: RootHex;
|
|
98
|
+
envelopeParentHash: RootHex;
|
|
99
|
+
latestBlockHash: RootHex;
|
|
100
|
+
}
|
|
101
|
+
| {
|
|
102
|
+
code: ExecutionPayloadEnvelopeErrorCode.INCORRECT_TIMESTAMP;
|
|
103
|
+
slot: Slot;
|
|
104
|
+
root: RootHex;
|
|
105
|
+
envelopeTimestamp: number;
|
|
106
|
+
expectedTimestamp: number;
|
|
107
|
+
}
|
|
108
|
+
| {code: ExecutionPayloadEnvelopeErrorCode.EMPTY_TRANSACTION; slot: Slot; root: RootHex; transactionIndex: number}
|
|
109
|
+
| {
|
|
110
|
+
code: ExecutionPayloadEnvelopeErrorCode.WITHDRAWALS_MISMATCH;
|
|
111
|
+
slot: Slot;
|
|
112
|
+
root: RootHex;
|
|
113
|
+
envelopeWithdrawalsRoot: RootHex;
|
|
114
|
+
expectedWithdrawalsRoot: RootHex;
|
|
115
|
+
}
|
|
116
|
+
| {
|
|
117
|
+
code: ExecutionPayloadEnvelopeErrorCode.INVALID_BLOCK_HASH;
|
|
118
|
+
slot: Slot;
|
|
119
|
+
root: RootHex;
|
|
120
|
+
blockHash: RootHex;
|
|
121
|
+
computedBlockHash: RootHex;
|
|
122
|
+
}
|
|
65
123
|
| {code: ExecutionPayloadEnvelopeErrorCode.INVALID_SIGNATURE; slot: Slot; root: RootHex}
|
|
66
124
|
| {code: ExecutionPayloadEnvelopeErrorCode.PAYLOAD_ENVELOPE_INPUT_MISSING; blockRoot: RootHex};
|
|
67
125
|
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
ForkPostGloas,
|
|
9
9
|
ForkPreGloas,
|
|
10
10
|
ForkSeq,
|
|
11
|
+
GENESIS_EPOCH,
|
|
11
12
|
MIN_SYNC_COMMITTEE_PARTICIPANTS,
|
|
12
13
|
SLOTS_PER_EPOCH,
|
|
13
14
|
SYNC_COMMITTEE_SIZE,
|
|
@@ -16,8 +17,6 @@ import {
|
|
|
16
17
|
} from "@lodestar/params";
|
|
17
18
|
import {
|
|
18
19
|
type IBeaconStateViewAltair,
|
|
19
|
-
computeStartSlotAtEpoch,
|
|
20
|
-
computeSyncPeriodAtEpoch,
|
|
21
20
|
computeSyncPeriodAtSlot,
|
|
22
21
|
executionPayloadToPayloadHeader,
|
|
23
22
|
} from "@lodestar/state-transition";
|
|
@@ -44,8 +43,7 @@ import {
|
|
|
44
43
|
phase0,
|
|
45
44
|
ssz,
|
|
46
45
|
} from "@lodestar/types";
|
|
47
|
-
import {Logger, MapDef,
|
|
48
|
-
import {ZERO_HASH} from "../../constants/index.js";
|
|
46
|
+
import {Logger, MapDef, pruneSetToMax, toRootHex} from "@lodestar/utils";
|
|
49
47
|
import {IBeaconDb} from "../../db/index.js";
|
|
50
48
|
import {NUM_WITNESS, NUM_WITNESS_ELECTRA} from "../../db/repositories/lightclientSyncCommitteeWitness.js";
|
|
51
49
|
import {Metrics} from "../../metrics/index.js";
|
|
@@ -72,16 +70,9 @@ export type SyncAttestedData = {
|
|
|
72
70
|
attestedHeader: LightClientHeader;
|
|
73
71
|
/** Precomputed root to prevent re-hashing */
|
|
74
72
|
blockRoot: Uint8Array;
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
finalityBranch: Uint8Array[];
|
|
79
|
-
finalizedCheckpoint: phase0.Checkpoint;
|
|
80
|
-
}
|
|
81
|
-
| {
|
|
82
|
-
isFinalized: false;
|
|
83
|
-
}
|
|
84
|
-
);
|
|
73
|
+
finalizedCheckpoint: phase0.Checkpoint;
|
|
74
|
+
finalityBranch: Uint8Array[];
|
|
75
|
+
};
|
|
85
76
|
|
|
86
77
|
type LightClientServerModules = {
|
|
87
78
|
config: ChainForkConfig;
|
|
@@ -435,33 +426,14 @@ export class LightClientServer {
|
|
|
435
426
|
// Store header in case it is referenced latter by a future finalized checkpoint
|
|
436
427
|
await this.db.checkpointHeader.put(blockRoot, header);
|
|
437
428
|
|
|
438
|
-
// Store finalized checkpoint data
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
finalizedCheckpoint.epoch !== 0 &&
|
|
447
|
-
!byteArrayEquals(finalizedCheckpoint.root, ZERO_HASH);
|
|
448
|
-
|
|
449
|
-
this.prevHeadData.set(
|
|
450
|
-
blockRootHex,
|
|
451
|
-
isFinalized
|
|
452
|
-
? {
|
|
453
|
-
isFinalized: true,
|
|
454
|
-
attestedHeader: header,
|
|
455
|
-
blockRoot,
|
|
456
|
-
finalityBranch: postState.getFinalizedRootProof(),
|
|
457
|
-
finalizedCheckpoint,
|
|
458
|
-
}
|
|
459
|
-
: {
|
|
460
|
-
isFinalized: false,
|
|
461
|
-
attestedHeader: header,
|
|
462
|
-
blockRoot,
|
|
463
|
-
}
|
|
464
|
-
);
|
|
429
|
+
// Store finalized checkpoint data. The finality branch only depends on the post state, so it is
|
|
430
|
+
// collected for every block; see `buildUpdate` for the cases in which it is served.
|
|
431
|
+
this.prevHeadData.set(blockRootHex, {
|
|
432
|
+
attestedHeader: header,
|
|
433
|
+
blockRoot,
|
|
434
|
+
finalizedCheckpoint: postState.finalizedCheckpoint,
|
|
435
|
+
finalityBranch: postState.getFinalizedRootProof(),
|
|
436
|
+
});
|
|
465
437
|
|
|
466
438
|
pruneSetToMax(this.prevHeadData, MAX_PREV_HEAD_DATA);
|
|
467
439
|
}
|
|
@@ -505,7 +477,7 @@ export class LightClientServer {
|
|
|
505
477
|
return;
|
|
506
478
|
}
|
|
507
479
|
|
|
508
|
-
const {attestedHeader
|
|
480
|
+
const {attestedHeader} = attestedData;
|
|
509
481
|
const attestedPeriod = computeSyncPeriodAtSlot(attestedHeader.beacon.slot);
|
|
510
482
|
if (syncPeriod !== attestedPeriod) {
|
|
511
483
|
this.logger.debug("attested data period different than signature period", {syncPeriod, attestedPeriod});
|
|
@@ -555,41 +527,36 @@ export class LightClientServer {
|
|
|
555
527
|
this.metrics?.lightclientServer.onSyncAggregate.inc({event: "update_latest_head_update"});
|
|
556
528
|
}
|
|
557
529
|
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
if (!isStaleLightClientUpdate) {
|
|
581
|
-
// Note: Ignores gossip rule to always emit finality_update with higher finalized_header.slot, for simplicity
|
|
582
|
-
this.emitter.emit(routes.events.EventType.lightClientFinalityUpdate, {
|
|
583
|
-
version: attestedFork,
|
|
584
|
-
data: this.finalized,
|
|
585
|
-
});
|
|
586
|
-
}
|
|
530
|
+
const builtUpdate = await this.buildUpdate(attestedData, syncAggregate, signatureSlot);
|
|
531
|
+
if (
|
|
532
|
+
builtUpdate?.hasFinality &&
|
|
533
|
+
(!this.finalized ||
|
|
534
|
+
builtUpdate.update.finalizedHeader.beacon.slot > this.finalized.finalizedHeader.beacon.slot ||
|
|
535
|
+
syncAggregateParticipation > sumBits(this.finalized.syncAggregate.syncCommitteeBits))
|
|
536
|
+
) {
|
|
537
|
+
this.finalized = {
|
|
538
|
+
attestedHeader,
|
|
539
|
+
finalizedHeader: builtUpdate.update.finalizedHeader,
|
|
540
|
+
syncAggregate,
|
|
541
|
+
finalityBranch: builtUpdate.update.finalityBranch,
|
|
542
|
+
signatureSlot,
|
|
543
|
+
};
|
|
544
|
+
this.metrics?.lightclientServer.onSyncAggregate.inc({event: "update_latest_finalized_update"});
|
|
545
|
+
|
|
546
|
+
if (!isStaleLightClientUpdate) {
|
|
547
|
+
// Note: Ignores gossip rule to always emit finality_update with higher finalized_header.slot, for simplicity
|
|
548
|
+
this.emitter.emit(routes.events.EventType.lightClientFinalityUpdate, {
|
|
549
|
+
version: attestedFork,
|
|
550
|
+
data: this.finalized,
|
|
551
|
+
});
|
|
587
552
|
}
|
|
588
553
|
}
|
|
589
554
|
|
|
590
555
|
// Check if this update is better, otherwise ignore
|
|
591
556
|
try {
|
|
592
|
-
|
|
557
|
+
if (builtUpdate) {
|
|
558
|
+
await this.maybeStoreNewBestUpdate(syncPeriod, builtUpdate);
|
|
559
|
+
}
|
|
593
560
|
} catch (e) {
|
|
594
561
|
this.logger.error(
|
|
595
562
|
"Error updating best LightClientUpdate",
|
|
@@ -605,36 +572,50 @@ export class LightClientServer {
|
|
|
605
572
|
*/
|
|
606
573
|
private async maybeStoreNewBestUpdate(
|
|
607
574
|
syncPeriod: SyncPeriod,
|
|
608
|
-
|
|
609
|
-
signatureSlot: Slot,
|
|
610
|
-
attestedData: SyncAttestedData
|
|
575
|
+
built: {update: LightClientUpdate; summary: LightClientUpdateSummary}
|
|
611
576
|
): Promise<void> {
|
|
612
577
|
const prevBestUpdate = await this.db.bestLightClientUpdate.get(syncPeriod);
|
|
613
|
-
|
|
578
|
+
if (prevBestUpdate && !isBetterUpdate(built.summary, toLightClientUpdateSummary(prevBestUpdate))) {
|
|
579
|
+
this.metrics?.lightclientServer.updateNotBetter.inc();
|
|
580
|
+
return;
|
|
581
|
+
}
|
|
614
582
|
|
|
615
|
-
|
|
616
|
-
|
|
583
|
+
// attestedData and the block of syncAggregate may not be in same sync period
|
|
584
|
+
// should not use attested data slot as sync period
|
|
585
|
+
// see https://github.com/ChainSafe/lodestar/issues/3933
|
|
586
|
+
await this.db.bestLightClientUpdate.put(syncPeriod, built.update);
|
|
587
|
+
this.logger.debug("Stored new PartialLightClientUpdate", {
|
|
588
|
+
syncPeriod,
|
|
589
|
+
isFinalized: built.summary.isFinalityUpdate,
|
|
590
|
+
participation: sumBits(built.update.syncAggregate.syncCommitteeBits) / SYNC_COMMITTEE_SIZE,
|
|
591
|
+
});
|
|
617
592
|
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
// All updates include a valid `nextSyncCommitteeBranch`, see below code
|
|
629
|
-
isSyncCommitteeUpdate: true,
|
|
630
|
-
isFinalityUpdate: attestedData.isFinalized,
|
|
631
|
-
};
|
|
593
|
+
// Count total persisted updates per type. DB metrics don't diff between each type.
|
|
594
|
+
// The frequency of finalized vs non-finalized is critical to debug if finalizedHeader is not available
|
|
595
|
+
this.metrics?.lightclientServer.onSyncAggregate.inc({
|
|
596
|
+
event: built.summary.isFinalityUpdate ? "store_finalized_update" : "store_nonfinalized_update",
|
|
597
|
+
});
|
|
598
|
+
this.metrics?.lightclientServer.highestSlot.set(
|
|
599
|
+
{item: built.summary.isFinalityUpdate ? "best_finalized_update" : "best_nonfinalized_update"},
|
|
600
|
+
built.update.attestedHeader.beacon.slot
|
|
601
|
+
);
|
|
602
|
+
}
|
|
632
603
|
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
604
|
+
/**
|
|
605
|
+
* Build the update for `syncAggregate` attesting to `attestedData`.
|
|
606
|
+
*
|
|
607
|
+
* Finality is indicated whenever it can be proven, in one of three ways:
|
|
608
|
+
* - the finalized checkpoint is genesis: the branch is served, the header stays empty, since
|
|
609
|
+
* genesis cannot be proven by a header and the branch alone proves that `finalized_root` is zero
|
|
610
|
+
* - the finalized header is available locally: both the header and the branch are served
|
|
611
|
+
* - the finalized header is not available: neither is served, and `hasFinality` is false
|
|
612
|
+
*/
|
|
613
|
+
private async buildUpdate(
|
|
614
|
+
attestedData: SyncAttestedData,
|
|
615
|
+
syncAggregate: altair.SyncAggregate,
|
|
616
|
+
signatureSlot: Slot
|
|
617
|
+
): Promise<{update: LightClientUpdate; summary: LightClientUpdateSummary; hasFinality: boolean} | null> {
|
|
618
|
+
const {attestedHeader} = attestedData;
|
|
638
619
|
|
|
639
620
|
const syncCommitteeWitness = await this.db.syncCommitteeWitness.get(attestedData.blockRoot);
|
|
640
621
|
if (!syncCommitteeWitness) {
|
|
@@ -662,41 +643,34 @@ export class LightClientServer {
|
|
|
662
643
|
throw Error("nextSyncCommittee not available");
|
|
663
644
|
}
|
|
664
645
|
const nextSyncCommitteeBranch = getNextSyncCommitteeBranch(syncCommitteeWitness);
|
|
665
|
-
const finalizedHeaderAttested = attestedData.isFinalized
|
|
666
|
-
? await this.getFinalizedHeader(attestedData.finalizedCheckpoint.root)
|
|
667
|
-
: null;
|
|
668
646
|
|
|
669
|
-
|
|
647
|
+
const zeroFinality = this.getZeroFinality(attestedFork, attestedHeader.beacon.slot);
|
|
648
|
+
const {finalizedCheckpoint} = attestedData;
|
|
649
|
+
let finalityBranch = zeroFinality.finalityBranch;
|
|
650
|
+
let finalizedHeader = zeroFinality.finalizedHeader;
|
|
651
|
+
let hasFinality = false;
|
|
670
652
|
|
|
671
|
-
if (
|
|
672
|
-
|
|
673
|
-
finalizedHeaderAttested &&
|
|
674
|
-
computeSyncPeriodAtSlot(finalizedHeaderAttested.beacon.slot) === syncPeriod
|
|
675
|
-
) {
|
|
676
|
-
isFinalized = true;
|
|
653
|
+
if (finalizedCheckpoint.epoch === GENESIS_EPOCH) {
|
|
654
|
+
// Genesis cannot be proven by a header, the branch alone proves that finalized_root is zero
|
|
677
655
|
finalityBranch = attestedData.finalityBranch;
|
|
678
|
-
|
|
679
|
-
// Fork of LightClientUpdate is based off on attested header's fork
|
|
680
|
-
if (this.config.getForkName(finalizedHeader.beacon.slot) !== attestedFork) {
|
|
681
|
-
finalizedHeader = upgradeLightClientHeader(this.config, attestedFork, finalizedHeader);
|
|
682
|
-
}
|
|
656
|
+
hasFinality = true;
|
|
683
657
|
} else {
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
if (
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
this.
|
|
658
|
+
const finalizedHeaderAttested = await this.getFinalizedHeader(finalizedCheckpoint.root);
|
|
659
|
+
// If the finalized block is not available locally, both stay empty
|
|
660
|
+
if (finalizedHeaderAttested) {
|
|
661
|
+
finalityBranch = attestedData.finalityBranch;
|
|
662
|
+
finalizedHeader = finalizedHeaderAttested;
|
|
663
|
+
hasFinality = true;
|
|
664
|
+
// Fork of LightClientUpdate is based off on attested header's fork
|
|
665
|
+
if (this.config.getForkName(finalizedHeader.beacon.slot) !== attestedFork) {
|
|
666
|
+
finalizedHeader = upgradeLightClientHeader(this.config, attestedFork, finalizedHeader);
|
|
667
|
+
}
|
|
692
668
|
}
|
|
693
|
-
finalityBranch = zeroFinality.finalityBranch;
|
|
694
|
-
finalizedHeader = zeroFinality.finalizedHeader;
|
|
695
669
|
}
|
|
696
670
|
|
|
697
|
-
const
|
|
671
|
+
const update = {
|
|
698
672
|
attestedHeader,
|
|
699
|
-
nextSyncCommittee
|
|
673
|
+
nextSyncCommittee,
|
|
700
674
|
nextSyncCommitteeBranch,
|
|
701
675
|
finalizedHeader,
|
|
702
676
|
finalityBranch,
|
|
@@ -704,25 +678,17 @@ export class LightClientServer {
|
|
|
704
678
|
signatureSlot,
|
|
705
679
|
} as LightClientUpdate;
|
|
706
680
|
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
// see https://github.com/ChainSafe/lodestar/issues/3933
|
|
710
|
-
await this.db.bestLightClientUpdate.put(syncPeriod, newUpdate);
|
|
711
|
-
this.logger.debug("Stored new PartialLightClientUpdate", {
|
|
712
|
-
syncPeriod,
|
|
713
|
-
isFinalized,
|
|
714
|
-
participation: sumBits(syncAggregate.syncCommitteeBits) / SYNC_COMMITTEE_SIZE,
|
|
715
|
-
});
|
|
681
|
+
return {update, summary: toLightClientUpdateSummary(update), hasFinality};
|
|
682
|
+
}
|
|
716
683
|
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
);
|
|
684
|
+
private getZeroFinality(attestedFork: ForkName, attestedSlot: Slot): LightClientZeroFinality {
|
|
685
|
+
let zeroFinality = this.zeroFinalityByFork.get(attestedFork);
|
|
686
|
+
if (!zeroFinality) {
|
|
687
|
+
const zero = this.config.getPostAltairForkTypes(attestedSlot).LightClientUpdate.defaultValue();
|
|
688
|
+
zeroFinality = {finalityBranch: zero.finalityBranch, finalizedHeader: zero.finalizedHeader};
|
|
689
|
+
this.zeroFinalityByFork.set(attestedFork, zeroFinality);
|
|
690
|
+
}
|
|
691
|
+
return zeroFinality;
|
|
726
692
|
}
|
|
727
693
|
|
|
728
694
|
private async storeSyncCommittee(syncCommittee: altair.SyncCommittee, syncCommitteeRoot: Uint8Array): Promise<void> {
|