@lodestar/beacon-node 1.52.0-dev.4996a91d93 → 1.52.0-dev.4c4ee3042c

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.
Files changed (60) hide show
  1. package/lib/api/impl/validator/index.d.ts.map +1 -1
  2. package/lib/api/impl/validator/index.js +12 -3
  3. package/lib/api/impl/validator/index.js.map +1 -1
  4. package/lib/chain/archiveStore/historicalState/getHistoricalState.d.ts.map +1 -1
  5. package/lib/chain/archiveStore/historicalState/getHistoricalState.js +7 -0
  6. package/lib/chain/archiveStore/historicalState/getHistoricalState.js.map +1 -1
  7. package/lib/chain/archiveStore/utils/pruneHistory.d.ts.map +1 -1
  8. package/lib/chain/archiveStore/utils/pruneHistory.js +8 -4
  9. package/lib/chain/archiveStore/utils/pruneHistory.js.map +1 -1
  10. package/lib/chain/errors/attestationError.d.ts +15 -1
  11. package/lib/chain/errors/attestationError.d.ts.map +1 -1
  12. package/lib/chain/errors/attestationError.js +8 -0
  13. package/lib/chain/errors/attestationError.js.map +1 -1
  14. package/lib/chain/errors/executionPayloadEnvelope.d.ts +48 -0
  15. package/lib/chain/errors/executionPayloadEnvelope.d.ts.map +1 -1
  16. package/lib/chain/errors/executionPayloadEnvelope.js +7 -0
  17. package/lib/chain/errors/executionPayloadEnvelope.js.map +1 -1
  18. package/lib/chain/validation/aggregateAndProof.d.ts.map +1 -1
  19. package/lib/chain/validation/aggregateAndProof.js +24 -7
  20. package/lib/chain/validation/aggregateAndProof.js.map +1 -1
  21. package/lib/chain/validation/attestation.d.ts.map +1 -1
  22. package/lib/chain/validation/attestation.js +32 -16
  23. package/lib/chain/validation/attestation.js.map +1 -1
  24. package/lib/chain/validation/block.d.ts.map +1 -1
  25. package/lib/chain/validation/block.js +9 -1
  26. package/lib/chain/validation/block.js.map +1 -1
  27. package/lib/chain/validation/executionPayloadEnvelope.d.ts.map +1 -1
  28. package/lib/chain/validation/executionPayloadEnvelope.js +79 -4
  29. package/lib/chain/validation/executionPayloadEnvelope.js.map +1 -1
  30. package/lib/network/gossip/gossipsub.js +2 -2
  31. package/lib/network/gossip/gossipsub.js.map +1 -1
  32. package/lib/network/processor/gossipHandlers.js +2 -2
  33. package/lib/network/processor/gossipHandlers.js.map +1 -1
  34. package/lib/sync/unknownBlock.d.ts +3 -2
  35. package/lib/sync/unknownBlock.d.ts.map +1 -1
  36. package/lib/sync/unknownBlock.js +42 -6
  37. package/lib/sync/unknownBlock.js.map +1 -1
  38. package/lib/sync/utils/downloadByRoot.d.ts +24 -2
  39. package/lib/sync/utils/downloadByRoot.d.ts.map +1 -1
  40. package/lib/sync/utils/downloadByRoot.js +41 -1
  41. package/lib/sync/utils/downloadByRoot.js.map +1 -1
  42. package/lib/util/eventLoop.d.ts +3 -3
  43. package/lib/util/eventLoop.d.ts.map +1 -1
  44. package/lib/util/eventLoop.js +3 -3
  45. package/lib/util/eventLoop.js.map +1 -1
  46. package/package.json +16 -16
  47. package/src/api/impl/validator/index.ts +14 -3
  48. package/src/chain/archiveStore/historicalState/getHistoricalState.ts +9 -0
  49. package/src/chain/archiveStore/utils/pruneHistory.ts +9 -4
  50. package/src/chain/errors/attestationError.ts +11 -1
  51. package/src/chain/errors/executionPayloadEnvelope.ts +50 -0
  52. package/src/chain/validation/aggregateAndProof.ts +24 -9
  53. package/src/chain/validation/attestation.ts +31 -20
  54. package/src/chain/validation/block.ts +9 -1
  55. package/src/chain/validation/executionPayloadEnvelope.ts +87 -3
  56. package/src/network/gossip/gossipsub.ts +2 -2
  57. package/src/network/processor/gossipHandlers.ts +2 -2
  58. package/src/sync/unknownBlock.ts +47 -5
  59. package/src/sync/utils/downloadByRoot.ts +66 -2
  60. package/src/util/eventLoop.ts +3 -3
@@ -19,10 +19,10 @@ export function callInNextEventLoop(callback) {
19
19
  setTimeout(callback, 0);
20
20
  }
21
21
  /**
22
- * Schedules a callback for the `check` phase. Pending promise continuations run first,
23
- * and there is no 1ms timer delay.
22
+ * Schedules a callback for the `check` phase, after the `poll` phase handles ready I/O.
23
+ * Pending promise continuations run first, and there is no 1ms timer delay.
24
24
  */
25
- export function callImmediate(callback) {
25
+ export function callAfterIO(callback) {
26
26
  setImmediate(callback);
27
27
  }
28
28
  //# sourceMappingURL=eventLoop.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"eventLoop.js","sourceRoot":"","sources":["../../src/util/eventLoop.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAC,MAAM,iBAAiB,CAAC;AAEtC;;;;;GAKG;AACH,MAAM,UAAU,aAAa;IAC3B,qCAAqC;IACrC,uEAAuE;IACvE,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAC,QAAoB;IACtD,qCAAqC;IACrC,uEAAuE;IACvE,UAAU,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC;AAC1B,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,QAAoB;IAChD,YAAY,CAAC,QAAQ,CAAC,CAAC;AACzB,CAAC"}
1
+ {"version":3,"file":"eventLoop.js","sourceRoot":"","sources":["../../src/util/eventLoop.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAC,MAAM,iBAAiB,CAAC;AAEtC;;;;;GAKG;AACH,MAAM,UAAU,aAAa;IAC3B,qCAAqC;IACrC,uEAAuE;IACvE,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAC,QAAoB;IACtD,qCAAqC;IACrC,uEAAuE;IACvE,UAAU,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC;AAC1B,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,QAAoB;IAC9C,YAAY,CAAC,QAAQ,CAAC,CAAC;AACzB,CAAC"}
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "bugs": {
12
12
  "url": "https://github.com/ChainSafe/lodestar/issues"
13
13
  },
14
- "version": "1.52.0-dev.4996a91d93",
14
+ "version": "1.52.0-dev.4c4ee3042c",
15
15
  "type": "module",
16
16
  "exports": {
17
17
  ".": {
@@ -126,18 +126,18 @@
126
126
  "@libp2p/prometheus-metrics": "^5.0.31",
127
127
  "@libp2p/tcp": "^11.0.30",
128
128
  "@libp2p/utils": "^7.4.3",
129
- "@lodestar/api": "^1.52.0-dev.4996a91d93",
130
- "@lodestar/config": "^1.52.0-dev.4996a91d93",
131
- "@lodestar/db": "^1.52.0-dev.4996a91d93",
132
- "@lodestar/fork-choice": "^1.52.0-dev.4996a91d93",
133
- "@lodestar/logger": "^1.52.0-dev.4996a91d93",
134
- "@lodestar/native": "^1.52.0-dev.4996a91d93",
135
- "@lodestar/params": "^1.52.0-dev.4996a91d93",
136
- "@lodestar/reqresp": "^1.52.0-dev.4996a91d93",
137
- "@lodestar/state-transition": "^1.52.0-dev.4996a91d93",
138
- "@lodestar/types": "^1.52.0-dev.4996a91d93",
139
- "@lodestar/utils": "^1.52.0-dev.4996a91d93",
140
- "@lodestar/validator": "^1.52.0-dev.4996a91d93",
129
+ "@lodestar/api": "^1.52.0-dev.4c4ee3042c",
130
+ "@lodestar/config": "^1.52.0-dev.4c4ee3042c",
131
+ "@lodestar/db": "^1.52.0-dev.4c4ee3042c",
132
+ "@lodestar/fork-choice": "^1.52.0-dev.4c4ee3042c",
133
+ "@lodestar/logger": "^1.52.0-dev.4c4ee3042c",
134
+ "@lodestar/native": "^1.52.0-dev.4c4ee3042c",
135
+ "@lodestar/params": "^1.52.0-dev.4c4ee3042c",
136
+ "@lodestar/reqresp": "^1.52.0-dev.4c4ee3042c",
137
+ "@lodestar/state-transition": "^1.52.0-dev.4c4ee3042c",
138
+ "@lodestar/types": "^1.52.0-dev.4c4ee3042c",
139
+ "@lodestar/utils": "^1.52.0-dev.4c4ee3042c",
140
+ "@lodestar/validator": "^1.52.0-dev.4c4ee3042c",
141
141
  "@multiformats/multiaddr": "^13.0.1",
142
142
  "datastore-core": "^12.0.1",
143
143
  "datastore-level": "^13.0.1",
@@ -159,8 +159,8 @@
159
159
  "@ethereumjs/rlp": "^4.0.1",
160
160
  "@libp2p/interface-internal": "^3.2.0",
161
161
  "@libp2p/logger": "^6.2.15",
162
- "@lodestar/spec-test-util": "^1.52.0-dev.4996a91d93",
163
- "@lodestar/test-utils": "^1.52.0-dev.4996a91d93",
162
+ "@lodestar/spec-test-util": "^1.52.0-dev.4c4ee3042c",
163
+ "@lodestar/test-utils": "^1.52.0-dev.4c4ee3042c",
164
164
  "@types/js-yaml": "^4.0.5",
165
165
  "@types/qs": "^6.9.7",
166
166
  "@types/tmp": "^0.2.3",
@@ -174,5 +174,5 @@
174
174
  "beacon",
175
175
  "blockchain"
176
176
  ],
177
- "gitHead": "676718df6a2f613e16064dbf990063dff45281b6"
177
+ "gitHead": "e968a89171ab9a2a1642a1a884b588458eb3aef5"
178
178
  }
@@ -409,7 +409,7 @@ export function getValidatorApi(
409
409
  * Both the above scenarios could be problematic and hence validator shouldn't participate
410
410
  * or weigh its vote on a head till it resolves to a Valid execution status.
411
411
  * Following activities should be skipped on an Optimistic head (with Syncing status):
412
- * 1. Attestation if targetRoot is optimistic
412
+ * 1. Attestation if the head block voted for (post-gloas the variant voted for) or the targetRoot is optimistic
413
413
  * 2. SyncCommitteeContribution if if the root for which to produce contribution is Optimistic.
414
414
  * 3. ProduceBlock if the parentRoot (chain's current head) is optimistic. Must be checked
415
415
  * explicitly as only local payload production consults the EL, blinded blocks from an
@@ -1397,10 +1397,18 @@ export function getValidatorApi(
1397
1397
  // After Gloas, attestation.data.index signals payload status in fork-choice:
1398
1398
  // - 0 = EMPTY / not present, 1 = FULL / present
1399
1399
  // - same-slot attestations must always use index = 0
1400
+ // Validator shouldn't vote on an optimistic head, post-gloas that is the variant voted for
1400
1401
  if (canonicalBlock.slot !== slot) {
1401
1402
  index = canonicalBlock.payloadStatus === PayloadStatus.FULL ? 1 : 0;
1403
+ if (isOptimisticBlock(canonicalBlock)) {
1404
+ throw new NodeIsSyncing(
1405
+ `Head block's execution payload not yet validated, executionPayloadBlockHash=${canonicalBlock.executionPayloadBlockHash}`
1406
+ );
1407
+ }
1402
1408
  } else {
1403
1409
  index = 0;
1410
+ // Same-slot votes support the PENDING variant, which does not depend on the block's own payload
1411
+ notOnOptimisticBlockRoot(beaconBlockRoot);
1404
1412
  }
1405
1413
  } else if (isForkPostElectra(fork)) {
1406
1414
  index = 0;
@@ -1418,8 +1426,11 @@ export function getValidatorApi(
1418
1426
  headBlockRoot
1419
1427
  : headState.getBlockRootAtSlot(targetSlot);
1420
1428
 
1421
- // Check the execution status as validator shouldn't vote on an optimistic head
1422
- // Check on target is sufficient as a valid target would imply a valid source
1429
+ // Check the execution status as validator shouldn't vote on an optimistic head, post-gloas the
1430
+ // variant voted for is checked above. Check on target is sufficient for a valid source
1431
+ if (!isForkPostGloas(fork)) {
1432
+ notOnOptimisticBlockRoot(beaconBlockRoot);
1433
+ }
1423
1434
  notOnOptimisticBlockRoot(targetRoot);
1424
1435
  notOnOutOfRangeData(targetRoot);
1425
1436
 
@@ -50,6 +50,15 @@ export async function getHistoricalState(
50
50
  const transitionTimer = metrics?.stateTransitionTime.startTimer();
51
51
  let blockCount = 0;
52
52
  for await (const block of db.blockArchive.valuesStream({gt: state.slot, lte: slot})) {
53
+ // Pruned history keeps the genesis state but not the blocks after it, without this check the
54
+ // first block would only be rejected after processing every slot in between
55
+ if (
56
+ blockCount === 0 &&
57
+ !byteArrayEquals(block.message.parentRoot, state.computeAnchorCheckpoint().checkpoint.root)
58
+ ) {
59
+ metrics?.regenErrorCount.inc({reason: RegenErrorType.blockProcessing});
60
+ throw Error(`Archived blocks do not extend nearest state slot=${state.slot} blockSlot=${block.message.slot}`);
61
+ }
53
62
  try {
54
63
  state = state.stateTransition(
55
64
  {block},
@@ -1,4 +1,5 @@
1
1
  import {ChainForkConfig} from "@lodestar/config";
2
+ import {GENESIS_SLOT} from "@lodestar/params";
2
3
  import {computeStartSlotAtEpoch} from "@lodestar/state-transition";
3
4
  import {Epoch, Slot} from "@lodestar/types";
4
5
  import {Logger, prettyPrintIndices} from "@lodestar/utils";
@@ -13,6 +14,9 @@ import {Metrics} from "../../../metrics/index.js";
13
14
  */
14
15
  export const MAX_PRUNE_BLOCK_SLOTS_PER_RUN = 4096;
15
16
 
17
+ // Genesis is kept so the block and state stay available via the API, e.g. for checkpoint providers
18
+ const FIRST_PRUNABLE_SLOT = GENESIS_SLOT + 1;
19
+
16
20
  export async function pruneHistory(
17
21
  config: ChainForkConfig,
18
22
  db: IBeaconDb,
@@ -30,11 +34,12 @@ export async function pruneHistory(
30
34
  // ensure that during (extremely lol) long periods of non-finality we don't delete unfinalized epoch data
31
35
  finalizedEpoch
32
36
  );
33
- const firstBlockSlot = (await db.blockArchive.firstKey()) ?? 0;
37
+ const [firstBlockSlot = FIRST_PRUNABLE_SLOT] = await db.blockArchive.keys({gte: FIRST_PRUNABLE_SLOT, limit: 1});
34
38
  const blockCutoffSlot = Math.min(computeStartSlotAtEpoch(blockCutoffEpoch), firstBlockSlot + maxBlockSlots);
35
39
  // The latest archived state is the anchor on restart and can trail finalization by a few epochs
36
40
  const lastArchivedStateSlot = (await db.stateArchive.lastKey()) ?? 0;
37
41
  const stateCutoffSlot = Math.min(computeStartSlotAtEpoch(finalizedEpoch), lastArchivedStateSlot);
42
+ const stateStartSlot = Math.max(statePruneFromSlot, FIRST_PRUNABLE_SLOT);
38
43
 
39
44
  logger.debug("Preparing to prune history", {
40
45
  currentEpoch,
@@ -46,9 +51,9 @@ export async function pruneHistory(
46
51
 
47
52
  const step0 = metrics?.pruneHistory.fetchKeys.startTimer();
48
53
  const [blocks, envelopes, states] = await Promise.all([
49
- db.blockArchive.keys({gte: 0, lt: blockCutoffSlot}),
50
- db.executionPayloadEnvelopeArchive.keys({gte: 0, lt: blockCutoffSlot}),
51
- stateCutoffSlot > statePruneFromSlot ? db.stateArchive.keys({gte: statePruneFromSlot, lt: stateCutoffSlot}) : [],
54
+ db.blockArchive.keys({gte: FIRST_PRUNABLE_SLOT, lt: blockCutoffSlot}),
55
+ db.executionPayloadEnvelopeArchive.keys({gte: FIRST_PRUNABLE_SLOT, lt: blockCutoffSlot}),
56
+ stateCutoffSlot > stateStartSlot ? db.stateArchive.keys({gte: stateStartSlot, lt: stateCutoffSlot}) : [],
52
57
  ]);
53
58
  step0?.();
54
59
 
@@ -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> {
@@ -9,10 +9,17 @@ 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",
16
23
  INVALID_SIGNATURE = "EXECUTION_PAYLOAD_ENVELOPE_ERROR_INVALID_SIGNATURE",
17
24
  PAYLOAD_ENVELOPE_INPUT_MISSING = "EXECUTION_PAYLOAD_ENVELOPE_ERROR_PAYLOAD_ENVELOPE_INPUT_MISSING",
18
25
  }
@@ -34,6 +41,13 @@ export type ExecutionPayloadEnvelopeErrorType =
34
41
  envelopeSlot: Slot;
35
42
  blockSlot: Slot;
36
43
  }
44
+ | {
45
+ code: ExecutionPayloadEnvelopeErrorCode.PARENT_BEACON_BLOCK_ROOT_MISMATCH;
46
+ slot: Slot;
47
+ root: RootHex;
48
+ envelopeParentBeaconBlockRoot: RootHex;
49
+ blockParentRoot: RootHex;
50
+ }
37
51
  | {
38
52
  code: ExecutionPayloadEnvelopeErrorCode.BUILDER_INDEX_MISMATCH;
39
53
  slot: Slot;
@@ -41,6 +55,20 @@ export type ExecutionPayloadEnvelopeErrorType =
41
55
  envelopeBuilderIndex: BuilderIndex;
42
56
  bidBuilderIndex: BuilderIndex | null;
43
57
  }
58
+ | {
59
+ code: ExecutionPayloadEnvelopeErrorCode.PREV_RANDAO_MISMATCH;
60
+ slot: Slot;
61
+ root: RootHex;
62
+ envelopePrevRandao: RootHex;
63
+ bidPrevRandao: RootHex;
64
+ }
65
+ | {
66
+ code: ExecutionPayloadEnvelopeErrorCode.GAS_LIMIT_MISMATCH;
67
+ slot: Slot;
68
+ root: RootHex;
69
+ envelopeGasLimit: number;
70
+ bidGasLimit: bigint;
71
+ }
44
72
  | {
45
73
  code: ExecutionPayloadEnvelopeErrorCode.BLOCK_HASH_MISMATCH;
46
74
  slot: Slot;
@@ -62,6 +90,28 @@ export type ExecutionPayloadEnvelopeErrorType =
62
90
  transactionCount: number;
63
91
  maxTransactionCount: number;
64
92
  }
93
+ | {
94
+ code: ExecutionPayloadEnvelopeErrorCode.PARENT_HASH_MISMATCH;
95
+ slot: Slot;
96
+ root: RootHex;
97
+ envelopeParentHash: RootHex;
98
+ latestBlockHash: RootHex;
99
+ }
100
+ | {
101
+ code: ExecutionPayloadEnvelopeErrorCode.INCORRECT_TIMESTAMP;
102
+ slot: Slot;
103
+ root: RootHex;
104
+ envelopeTimestamp: number;
105
+ expectedTimestamp: number;
106
+ }
107
+ | {code: ExecutionPayloadEnvelopeErrorCode.EMPTY_TRANSACTION; slot: Slot; root: RootHex; transactionIndex: number}
108
+ | {
109
+ code: ExecutionPayloadEnvelopeErrorCode.WITHDRAWALS_MISMATCH;
110
+ slot: Slot;
111
+ root: RootHex;
112
+ envelopeWithdrawalsRoot: RootHex;
113
+ expectedWithdrawalsRoot: RootHex;
114
+ }
65
115
  | {code: ExecutionPayloadEnvelopeErrorCode.INVALID_SIGNATURE; slot: Slot; root: RootHex}
66
116
  | {code: ExecutionPayloadEnvelopeErrorCode.PAYLOAD_ENVELOPE_INPUT_MISSING; blockRoot: RootHex};
67
117
 
@@ -1,3 +1,4 @@
1
+ import {ExecutionStatus, PayloadStatus} from "@lodestar/fork-choice";
1
2
  import {ForkName, ForkSeq} from "@lodestar/params";
2
3
  import {
3
4
  ISignatureSet,
@@ -100,15 +101,29 @@ async function validateAggregateAndProof(
100
101
  // (a client MAY queue attestations for processing until the payload is imported and SHOULD
101
102
  // request the payload envelope via `ExecutionPayloadEnvelopesByRoot` using
102
103
  // `aggregate.data.beacon_block_root`).
103
- if (
104
- block !== null &&
105
- attData.index === 1 &&
106
- !chain.forkChoice.hasPayloadHexUnsafe(toRootHex(attData.beaconBlockRoot))
107
- ) {
108
- throw new AttestationError(GossipAction.IGNORE, {
109
- code: AttestationErrorCode.EXECUTION_PAYLOAD_NOT_SEEN,
110
- beaconBlockRoot: toRootHex(attData.beaconBlockRoot),
111
- });
104
+ if (block !== null && attData.index === 1) {
105
+ const beaconBlockRoot = toRootHex(attData.beaconBlockRoot);
106
+ const fullBlock = chain.forkChoice.getBlockHex(beaconBlockRoot, PayloadStatus.FULL);
107
+ if (fullBlock === null) {
108
+ throw new AttestationError(GossipAction.IGNORE, {
109
+ code: AttestationErrorCode.EXECUTION_PAYLOAD_NOT_SEEN,
110
+ beaconBlockRoot,
111
+ });
112
+ }
113
+ // [IGNORE] The attested execution payload is optimistic
114
+ if (fullBlock.executionStatus === ExecutionStatus.Syncing) {
115
+ throw new AttestationError(GossipAction.IGNORE, {
116
+ code: AttestationErrorCode.EXECUTION_PAYLOAD_OPTIMISTIC,
117
+ beaconBlockRoot,
118
+ });
119
+ }
120
+ // [REJECT] The attested execution payload is processed and invalid
121
+ if (fullBlock.executionStatus === ExecutionStatus.Invalid) {
122
+ throw new AttestationError(GossipAction.REJECT, {
123
+ code: AttestationErrorCode.EXECUTION_PAYLOAD_INVALID,
124
+ beaconBlockRoot,
125
+ });
126
+ }
112
127
  }
113
128
 
114
129
  // [REJECT] len(committee_indices) == 1, where committee_indices = get_committee_indices(aggregate)
@@ -1,6 +1,6 @@
1
1
  import {BitArray} from "@chainsafe/ssz";
2
2
  import {BeaconConfig} from "@lodestar/config";
3
- import {ProtoBlock} from "@lodestar/fork-choice";
3
+ import {ExecutionStatus, PayloadStatus, ProtoBlock} from "@lodestar/fork-choice";
4
4
  import {
5
5
  ATTESTATION_SUBNET_COUNT,
6
6
  DOMAIN_BEACON_ATTESTER,
@@ -309,25 +309,6 @@ async function validateAttestationNoSignatureCheck(
309
309
  code: AttestationErrorCode.PREMATURELY_INDICATED_PAYLOAD_PRESENT,
310
310
  });
311
311
  }
312
-
313
- // [REJECT] If `attestation.data.index == 1` (payload present for a past block),
314
- // the execution payload for `block` passes validation.
315
- // [IGNORE] When `attestation.data.index == 1` (payload present for a past block),
316
- // the execution payload for `block` has been fully imported, including its data -- i.e.
317
- // `is_payload_verified(store, attestation.data.beacon_block_root)` returns `True`
318
- // (a client MAY queue attestations for processing until the payload is imported and
319
- // SHOULD request the payload envelope via `ExecutionPayloadEnvelopesByRoot` using
320
- // `attestation.data.beacon_block_root`).
321
- if (
322
- block !== null &&
323
- attData.index === 1 &&
324
- !chain.forkChoice.hasPayloadHexUnsafe(toRootHex(attData.beaconBlockRoot))
325
- ) {
326
- throw new AttestationError(GossipAction.IGNORE, {
327
- code: AttestationErrorCode.EXECUTION_PAYLOAD_NOT_SEEN,
328
- beaconBlockRoot: toRootHex(attData.beaconBlockRoot),
329
- });
330
- }
331
312
  } else {
332
313
  // [REJECT] attestation.data.index == 0
333
314
  if (attData.index !== 0) {
@@ -343,6 +324,36 @@ async function validateAttestationNoSignatureCheck(
343
324
  committeeIndex = attestationOrCache.cache.committeeIndex;
344
325
  }
345
326
 
327
+ // The payload status can change after the attestation data was cached, so this runs for cached data too
328
+ if (isForkPostGloas(fork) && attData.index === 1) {
329
+ const beaconBlockRoot = toRootHex(attData.beaconBlockRoot);
330
+ const fullBlock = chain.forkChoice.getBlockHex(beaconBlockRoot, PayloadStatus.FULL);
331
+ // [IGNORE] The corresponding execution payload envelope has been seen and verified
332
+ // (a client MAY queue attestations for processing until the payload is imported and
333
+ // SHOULD request the payload envelope via `ExecutionPayloadEnvelopesByRoot`).
334
+ // An unknown block is handled by `verifyHeadBlockAndTargetRoot`
335
+ if (fullBlock === null) {
336
+ if (chain.forkChoice.hasBlockHexUnsafe(beaconBlockRoot)) {
337
+ throw new AttestationError(GossipAction.IGNORE, {
338
+ code: AttestationErrorCode.EXECUTION_PAYLOAD_NOT_SEEN,
339
+ beaconBlockRoot,
340
+ });
341
+ }
342
+ } else if (fullBlock.executionStatus === ExecutionStatus.Syncing) {
343
+ // [IGNORE] The attested execution payload is optimistic
344
+ throw new AttestationError(GossipAction.IGNORE, {
345
+ code: AttestationErrorCode.EXECUTION_PAYLOAD_OPTIMISTIC,
346
+ beaconBlockRoot,
347
+ });
348
+ } else if (fullBlock.executionStatus === ExecutionStatus.Invalid) {
349
+ // [REJECT] The attested execution payload is processed and invalid
350
+ throw new AttestationError(GossipAction.REJECT, {
351
+ code: AttestationErrorCode.EXECUTION_PAYLOAD_INVALID,
352
+ beaconBlockRoot,
353
+ });
354
+ }
355
+ }
356
+
346
357
  chain.metrics?.gossipAttestation.attestationSlotToClockSlot.observe(
347
358
  {caller: RegenCaller.validateGossipAttestation},
348
359
  chain.clock.currentSlot - attSlot
@@ -121,13 +121,21 @@ export async function validateGossipBlock(
121
121
  // (via gossip or non-gossip sources) (a client MAY queue blocks for processing once the parent payload is retrieved).
122
122
  if (isGloasBeaconBlock(block)) {
123
123
  const parentBlockHashHex = toRootHex(block.body.signedExecutionPayloadBid.message.parentBlockHash);
124
- if (chain.forkChoice.getBlockHexAndBlockHash(parentRoot, parentBlockHashHex) === null) {
124
+ const parentPayloadBlock = chain.forkChoice.getBlockHexAndBlockHash(parentRoot, parentBlockHashHex);
125
+ if (parentPayloadBlock === null) {
125
126
  throw new BlockGossipError(GossipAction.IGNORE, {
126
127
  code: BlockErrorCode.PARENT_PAYLOAD_UNKNOWN,
127
128
  parentRoot,
128
129
  parentBlockHash: parentBlockHashHex,
129
130
  });
130
131
  }
132
+ // [IGNORE] The block's parent passed validation but the payload it builds on is invalid
133
+ if (parentPayloadBlock.executionStatus === ExecutionStatus.Invalid) {
134
+ throw new BlockGossipError(GossipAction.IGNORE, {
135
+ code: BlockErrorCode.PARENT_EXECUTION_INVALID,
136
+ parentRoot,
137
+ });
138
+ }
131
139
  }
132
140
 
133
141
  // [REJECT] The block is from a higher slot than its parent.
@@ -1,6 +1,7 @@
1
1
  import {PayloadStatus, ProtoBlock} from "@lodestar/fork-choice";
2
2
  import {
3
3
  computeStartSlotAtEpoch,
4
+ computeTimeAtSlot,
4
5
  getExecutionPayloadEnvelopeSignatureSet,
5
6
  isStatePostGloas,
6
7
  } from "@lodestar/state-transition";
@@ -129,6 +130,17 @@ async function validateExecutionPayloadEnvelope(
129
130
  });
130
131
  }
131
132
 
133
+ // [REJECT] `envelope.parent_beacon_block_root == block.parent_root`
134
+ if (toRootHex(envelope.parentBeaconBlockRoot) !== block.parentRoot) {
135
+ throw new ExecutionPayloadEnvelopeError(GossipAction.REJECT, {
136
+ code: ExecutionPayloadEnvelopeErrorCode.PARENT_BEACON_BLOCK_ROOT_MISMATCH,
137
+ slot: payload.slotNumber,
138
+ root: blockRootHex,
139
+ envelopeParentBeaconBlockRoot: toRootHex(envelope.parentBeaconBlockRoot),
140
+ blockParentRoot: block.parentRoot,
141
+ });
142
+ }
143
+
132
144
  // [REJECT] `envelope.builder_index == bid.builder_index`
133
145
  if (envelope.builderIndex !== payloadInput.getBuilderIndex()) {
134
146
  throw new ExecutionPayloadEnvelopeError(GossipAction.REJECT, {
@@ -140,6 +152,30 @@ async function validateExecutionPayloadEnvelope(
140
152
  });
141
153
  }
142
154
 
155
+ const bid = payloadInput.getBid();
156
+
157
+ // [REJECT] `payload.prev_randao == bid.prev_randao`
158
+ if (!byteArrayEquals(payload.prevRandao, bid.prevRandao)) {
159
+ throw new ExecutionPayloadEnvelopeError(GossipAction.REJECT, {
160
+ code: ExecutionPayloadEnvelopeErrorCode.PREV_RANDAO_MISMATCH,
161
+ slot: payload.slotNumber,
162
+ root: blockRootHex,
163
+ envelopePrevRandao: toRootHex(payload.prevRandao),
164
+ bidPrevRandao: toRootHex(bid.prevRandao),
165
+ });
166
+ }
167
+
168
+ // [REJECT] `payload.gas_limit == bid.gas_limit`
169
+ if (BigInt(payload.gasLimit) !== bid.gasLimit) {
170
+ throw new ExecutionPayloadEnvelopeError(GossipAction.REJECT, {
171
+ code: ExecutionPayloadEnvelopeErrorCode.GAS_LIMIT_MISMATCH,
172
+ slot: payload.slotNumber,
173
+ root: blockRootHex,
174
+ envelopeGasLimit: payload.gasLimit,
175
+ bidGasLimit: bid.gasLimit,
176
+ });
177
+ }
178
+
143
179
  // [REJECT] `payload.block_hash == bid.block_hash`
144
180
  if (toRootHex(payload.blockHash) !== payloadInput.getBlockHashHex()) {
145
181
  throw new ExecutionPayloadEnvelopeError(GossipAction.REJECT, {
@@ -153,13 +189,13 @@ async function validateExecutionPayloadEnvelope(
153
189
 
154
190
  // [REJECT] `hash_tree_root(envelope.execution_requests) == bid.execution_requests_root`
155
191
  const requestsRoot = ssz.gloas.ExecutionRequests.hashTreeRoot(envelope.executionRequests);
156
- if (!byteArrayEquals(requestsRoot, payloadInput.getBid().executionRequestsRoot)) {
192
+ if (!byteArrayEquals(requestsRoot, bid.executionRequestsRoot)) {
157
193
  throw new ExecutionPayloadEnvelopeError(GossipAction.REJECT, {
158
194
  code: ExecutionPayloadEnvelopeErrorCode.EXECUTION_REQUESTS_ROOT_MISMATCH,
159
195
  slot: payload.slotNumber,
160
196
  root: blockRootHex,
161
197
  envelopeRequestsRoot: toRootHex(requestsRoot),
162
- bidRequestsRoot: toRootHex(payloadInput.getBid().executionRequestsRoot),
198
+ bidRequestsRoot: toRootHex(bid.executionRequestsRoot),
163
199
  });
164
200
  }
165
201
 
@@ -177,7 +213,7 @@ async function validateExecutionPayloadEnvelope(
177
213
  });
178
214
  }
179
215
 
180
- // Get the block state to verify the builder's signature.
216
+ // Get the block state to verify the payload against it and the builder's signature.
181
217
  const blockState = await chain.regen
182
218
  .getState(block.stateRoot, RegenCaller.validateGossipPayloadEnvelope)
183
219
  .catch(() => {
@@ -191,6 +227,54 @@ async function validateExecutionPayloadEnvelope(
191
227
  throw new Error(`Expected gloas+ state for execution payload envelope validation, got fork=${blockState.forkName}`);
192
228
  }
193
229
 
230
+ // [REJECT] `payload.parent_hash == state.latest_block_hash`
231
+ if (!byteArrayEquals(payload.parentHash, blockState.latestBlockHash)) {
232
+ throw new ExecutionPayloadEnvelopeError(GossipAction.REJECT, {
233
+ code: ExecutionPayloadEnvelopeErrorCode.PARENT_HASH_MISMATCH,
234
+ slot: payload.slotNumber,
235
+ root: blockRootHex,
236
+ envelopeParentHash: toRootHex(payload.parentHash),
237
+ latestBlockHash: toRootHex(blockState.latestBlockHash),
238
+ });
239
+ }
240
+
241
+ // [REJECT] `payload.timestamp == compute_time_at_slot(state.genesis_time, block.slot)`
242
+ const expectedTimestamp = computeTimeAtSlot(chain.config, block.slot, blockState.genesisTime);
243
+ if (payload.timestamp !== expectedTimestamp) {
244
+ throw new ExecutionPayloadEnvelopeError(GossipAction.REJECT, {
245
+ code: ExecutionPayloadEnvelopeErrorCode.INCORRECT_TIMESTAMP,
246
+ slot: payload.slotNumber,
247
+ root: blockRootHex,
248
+ envelopeTimestamp: payload.timestamp,
249
+ expectedTimestamp,
250
+ });
251
+ }
252
+
253
+ // [REJECT] The payload contains no empty transactions
254
+ for (let i = 0; i < payload.transactions.length; i++) {
255
+ if (payload.transactions.getSize(i) === 0) {
256
+ throw new ExecutionPayloadEnvelopeError(GossipAction.REJECT, {
257
+ code: ExecutionPayloadEnvelopeErrorCode.EMPTY_TRANSACTION,
258
+ slot: payload.slotNumber,
259
+ root: blockRootHex,
260
+ transactionIndex: i,
261
+ });
262
+ }
263
+ }
264
+
265
+ // [REJECT] `hash_tree_root(payload.withdrawals) == hash_tree_root(state.payload_expected_withdrawals)`
266
+ const withdrawalsRoot = ssz.gloas.Withdrawals.hashTreeRoot(payload.withdrawals);
267
+ const expectedWithdrawalsRoot = ssz.gloas.Withdrawals.hashTreeRoot(blockState.payloadExpectedWithdrawals);
268
+ if (!byteArrayEquals(withdrawalsRoot, expectedWithdrawalsRoot)) {
269
+ throw new ExecutionPayloadEnvelopeError(GossipAction.REJECT, {
270
+ code: ExecutionPayloadEnvelopeErrorCode.WITHDRAWALS_MISMATCH,
271
+ slot: payload.slotNumber,
272
+ root: blockRootHex,
273
+ envelopeWithdrawalsRoot: toRootHex(withdrawalsRoot),
274
+ expectedWithdrawalsRoot: toRootHex(expectedWithdrawalsRoot),
275
+ });
276
+ }
277
+
194
278
  // [REJECT] `signed_execution_payload_envelope.signature` is valid as verified
195
279
  // by `verify_execution_payload_envelope_signature`.
196
280
  const signatureSet = getExecutionPayloadEnvelopeSignatureSet(
@@ -25,7 +25,7 @@ import {getSlotDurations} from "@lodestar/state-transition";
25
25
  import {SubnetID} from "@lodestar/types";
26
26
  import {Logger, Map2d, Map2dArr} from "@lodestar/utils";
27
27
  import {RegistryMetricCreator} from "../../metrics/index.js";
28
- import {callImmediate, callInNextEventLoop} from "../../util/eventLoop.js";
28
+ import {callAfterIO, callInNextEventLoop} from "../../util/eventLoop.js";
29
29
  import {NetworkEvent, NetworkEventBus, NetworkEventData} from "../events.js";
30
30
  import {Libp2p} from "../interface.js";
31
31
  import {NetworkConfig} from "../networkConfig.js";
@@ -433,7 +433,7 @@ export class Eth2Gossipsub {
433
433
  // See https://github.com/ChainSafe/lodestar/issues/5604
434
434
  // A block arrives once per slot and cannot cause that lag, so it skips the 1ms timer delay
435
435
  if (topic.type === GossipType.beacon_block) {
436
- callImmediate(emitPendingMessage);
436
+ callAfterIO(emitPendingMessage);
437
437
  } else {
438
438
  callInNextEventLoop(emitPendingMessage);
439
439
  }
@@ -89,7 +89,7 @@ import {validateGossipProposerPreferences} from "../../chain/validation/proposer
89
89
  import {OpSource} from "../../chain/validatorMonitor.js";
90
90
  import {Metrics} from "../../metrics/index.js";
91
91
  import {getBlobKzgCommitments, getDataColumnSidecarSlot} from "../../util/dataColumns.js";
92
- import {callImmediate, callInNextEventLoop} from "../../util/eventLoop.js";
92
+ import {callAfterIO, callInNextEventLoop} from "../../util/eventLoop.js";
93
93
  import {INetworkCore} from "../core/index.js";
94
94
  import {NetworkEventBus} from "../events.js";
95
95
  import {
@@ -686,7 +686,7 @@ function getSequentialHandlers(modules: ValidatorFnsModules, options: GossipHand
686
686
  try {
687
687
  const blockInput = await validateBeaconBlock(signedBlock, topic.boundary.fork, peerIdStr, seenTimestampSec);
688
688
  // Runs after the validation result is reported, except with `network.useWorker: false`
689
- callImmediate(() => {
689
+ callAfterIO(() => {
690
690
  try {
691
691
  chain.serializedCache.set(signedBlock, serializedData);
692
692
  handleValidBeaconBlock(blockInput, peerIdStr, seenTimestampSec);