@lodestar/beacon-node 2.1.0-dev.9d37cdf84a → 2.1.0-dev.9d8b35c280

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 (137) hide show
  1. package/lib/api/impl/beacon/blocks/index.d.ts.map +1 -1
  2. package/lib/api/impl/beacon/blocks/index.js +1 -3
  3. package/lib/api/impl/beacon/blocks/index.js.map +1 -1
  4. package/lib/api/impl/beacon/pool/index.d.ts.map +1 -1
  5. package/lib/api/impl/beacon/pool/index.js +8 -0
  6. package/lib/api/impl/beacon/pool/index.js.map +1 -1
  7. package/lib/api/impl/beacon/state/index.d.ts.map +1 -1
  8. package/lib/api/impl/beacon/state/index.js +3 -2
  9. package/lib/api/impl/beacon/state/index.js.map +1 -1
  10. package/lib/api/impl/beacon/state/utils.js +1 -1
  11. package/lib/api/impl/beacon/state/utils.js.map +1 -1
  12. package/lib/api/impl/validator/index.js +1 -1
  13. package/lib/api/impl/validator/index.js.map +1 -1
  14. package/lib/chain/ColumnReconstructionTracker.d.ts +3 -0
  15. package/lib/chain/ColumnReconstructionTracker.d.ts.map +1 -1
  16. package/lib/chain/ColumnReconstructionTracker.js +3 -1
  17. package/lib/chain/ColumnReconstructionTracker.js.map +1 -1
  18. package/lib/chain/GetBlobsTracker.d.ts +3 -0
  19. package/lib/chain/GetBlobsTracker.d.ts.map +1 -1
  20. package/lib/chain/GetBlobsTracker.js +3 -1
  21. package/lib/chain/GetBlobsTracker.js.map +1 -1
  22. package/lib/chain/blocks/payloadEnvelopeInput/types.d.ts +2 -1
  23. package/lib/chain/blocks/payloadEnvelopeInput/types.d.ts.map +1 -1
  24. package/lib/chain/chain.d.ts +2 -1
  25. package/lib/chain/chain.d.ts.map +1 -1
  26. package/lib/chain/chain.js +12 -3
  27. package/lib/chain/chain.js.map +1 -1
  28. package/lib/chain/errors/dataColumnSidecarError.d.ts +7 -0
  29. package/lib/chain/errors/dataColumnSidecarError.d.ts.map +1 -1
  30. package/lib/chain/errors/dataColumnSidecarError.js +1 -0
  31. package/lib/chain/errors/dataColumnSidecarError.js.map +1 -1
  32. package/lib/chain/forkChoice/index.d.ts.map +1 -1
  33. package/lib/chain/forkChoice/index.js +1 -2
  34. package/lib/chain/forkChoice/index.js.map +1 -1
  35. package/lib/chain/interface.d.ts +2 -1
  36. package/lib/chain/interface.d.ts.map +1 -1
  37. package/lib/chain/interface.js.map +1 -1
  38. package/lib/chain/seenCache/index.d.ts +1 -0
  39. package/lib/chain/seenCache/index.d.ts.map +1 -1
  40. package/lib/chain/seenCache/index.js +1 -0
  41. package/lib/chain/seenCache/index.js.map +1 -1
  42. package/lib/chain/seenCache/seenBlockProposers.d.ts +1 -0
  43. package/lib/chain/seenCache/seenBlockProposers.d.ts.map +1 -1
  44. package/lib/chain/seenCache/seenBlockProposers.js +5 -1
  45. package/lib/chain/seenCache/seenBlockProposers.js.map +1 -1
  46. package/lib/chain/seenCache/seenDataColumnSidecars.d.ts +16 -0
  47. package/lib/chain/seenCache/seenDataColumnSidecars.d.ts.map +1 -0
  48. package/lib/chain/seenCache/seenDataColumnSidecars.js +56 -0
  49. package/lib/chain/seenCache/seenDataColumnSidecars.js.map +1 -0
  50. package/lib/chain/seenCache/seenPayloadEnvelopeInput.d.ts +11 -2
  51. package/lib/chain/seenCache/seenPayloadEnvelopeInput.d.ts.map +1 -1
  52. package/lib/chain/seenCache/seenPayloadEnvelopeInput.js +28 -2
  53. package/lib/chain/seenCache/seenPayloadEnvelopeInput.js.map +1 -1
  54. package/lib/chain/validation/attestation.d.ts.map +1 -1
  55. package/lib/chain/validation/attestation.js +4 -2
  56. package/lib/chain/validation/attestation.js.map +1 -1
  57. package/lib/chain/validation/block.d.ts.map +1 -1
  58. package/lib/chain/validation/block.js +12 -2
  59. package/lib/chain/validation/block.js.map +1 -1
  60. package/lib/chain/validation/dataColumnSidecar.js +1 -1
  61. package/lib/chain/validation/dataColumnSidecar.js.map +1 -1
  62. package/lib/network/forks.d.ts +2 -2
  63. package/lib/network/forks.d.ts.map +1 -1
  64. package/lib/network/forks.js +3 -3
  65. package/lib/network/forks.js.map +1 -1
  66. package/lib/network/gossip/scoringParameters.js +19 -14
  67. package/lib/network/gossip/scoringParameters.js.map +1 -1
  68. package/lib/network/peers/discover.d.ts +1 -0
  69. package/lib/network/peers/discover.d.ts.map +1 -1
  70. package/lib/network/peers/discover.js +43 -47
  71. package/lib/network/peers/discover.js.map +1 -1
  72. package/lib/network/peers/score/store.d.ts.map +1 -1
  73. package/lib/network/peers/score/store.js +1 -2
  74. package/lib/network/peers/score/store.js.map +1 -1
  75. package/lib/network/processor/gossipHandlers.d.ts.map +1 -1
  76. package/lib/network/processor/gossipHandlers.js +75 -9
  77. package/lib/network/processor/gossipHandlers.js.map +1 -1
  78. package/lib/network/reqresp/handlers/dataColumnSidecarsByRange.d.ts.map +1 -1
  79. package/lib/network/reqresp/handlers/dataColumnSidecarsByRange.js +3 -1
  80. package/lib/network/reqresp/handlers/dataColumnSidecarsByRange.js.map +1 -1
  81. package/lib/sync/range/chain.d.ts.map +1 -1
  82. package/lib/sync/range/chain.js +1 -0
  83. package/lib/sync/range/chain.js.map +1 -1
  84. package/lib/sync/unknownBlock.d.ts.map +1 -1
  85. package/lib/sync/unknownBlock.js +14 -1
  86. package/lib/sync/unknownBlock.js.map +1 -1
  87. package/lib/sync/utils/downloadByRange.d.ts +6 -0
  88. package/lib/sync/utils/downloadByRange.d.ts.map +1 -1
  89. package/lib/sync/utils/downloadByRange.js +17 -8
  90. package/lib/sync/utils/downloadByRange.js.map +1 -1
  91. package/lib/sync/utils/downloadByRoot.d.ts.map +1 -1
  92. package/lib/sync/utils/downloadByRoot.js +1 -1
  93. package/lib/sync/utils/downloadByRoot.js.map +1 -1
  94. package/lib/sync/utils/pendingBlocksTree.d.ts.map +1 -1
  95. package/lib/sync/utils/pendingBlocksTree.js +6 -1
  96. package/lib/sync/utils/pendingBlocksTree.js.map +1 -1
  97. package/lib/util/dataColumns.d.ts +2 -1
  98. package/lib/util/dataColumns.d.ts.map +1 -1
  99. package/lib/util/dataColumns.js +7 -2
  100. package/lib/util/dataColumns.js.map +1 -1
  101. package/lib/util/execution.d.ts +2 -1
  102. package/lib/util/execution.d.ts.map +1 -1
  103. package/lib/util/execution.js +7 -2
  104. package/lib/util/execution.js.map +1 -1
  105. package/package.json +18 -21
  106. package/src/api/impl/beacon/blocks/index.ts +1 -5
  107. package/src/api/impl/beacon/pool/index.ts +11 -0
  108. package/src/api/impl/beacon/state/index.ts +3 -7
  109. package/src/api/impl/beacon/state/utils.ts +1 -1
  110. package/src/api/impl/validator/index.ts +1 -1
  111. package/src/chain/ColumnReconstructionTracker.ts +5 -1
  112. package/src/chain/GetBlobsTracker.ts +5 -0
  113. package/src/chain/blocks/payloadEnvelopeInput/types.ts +8 -1
  114. package/src/chain/chain.ts +17 -2
  115. package/src/chain/errors/dataColumnSidecarError.ts +8 -0
  116. package/src/chain/forkChoice/index.ts +1 -3
  117. package/src/chain/interface.ts +2 -0
  118. package/src/chain/seenCache/index.ts +1 -0
  119. package/src/chain/seenCache/seenBlockProposers.ts +11 -1
  120. package/src/chain/seenCache/seenDataColumnSidecars.ts +64 -0
  121. package/src/chain/seenCache/seenPayloadEnvelopeInput.ts +28 -2
  122. package/src/chain/validation/attestation.ts +4 -2
  123. package/src/chain/validation/block.ts +11 -2
  124. package/src/chain/validation/dataColumnSidecar.ts +1 -1
  125. package/src/network/forks.ts +7 -3
  126. package/src/network/gossip/scoringParameters.ts +23 -14
  127. package/src/network/peers/discover.ts +41 -51
  128. package/src/network/peers/score/store.ts +1 -2
  129. package/src/network/processor/gossipHandlers.ts +134 -17
  130. package/src/network/reqresp/handlers/dataColumnSidecarsByRange.ts +4 -1
  131. package/src/sync/range/chain.ts +1 -0
  132. package/src/sync/unknownBlock.ts +20 -1
  133. package/src/sync/utils/downloadByRange.ts +30 -7
  134. package/src/sync/utils/downloadByRoot.ts +12 -9
  135. package/src/sync/utils/pendingBlocksTree.ts +6 -1
  136. package/src/util/dataColumns.ts +13 -1
  137. package/src/util/execution.ts +16 -1
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "bugs": {
12
12
  "url": "https://github.com/ChainSafe/lodestar/issues"
13
13
  },
14
- "version": "2.1.0-dev.9d37cdf84a",
14
+ "version": "2.1.0-dev.9d8b35c280",
15
15
  "type": "module",
16
16
  "exports": {
17
17
  ".": {
@@ -89,8 +89,6 @@
89
89
  "test:e2e": "vitest run --project e2e --project e2e-sync --project e2e-mainnet",
90
90
  "test:sim": "vitest run test/sim/**/*.test.ts",
91
91
  "test:sim:blobs": "vitest run test/sim/4844-interop.test.ts",
92
- "download-spec-tests": "node --import tsx test/spec/downloadTests.ts",
93
- "download-comptests": "node --import tsx test/spec/downloadComptests.ts",
94
92
  "test:comptest": "vitest run --project comptest",
95
93
  "test:spec:bls": "vitest run --project spec-minimal test/spec/bls/",
96
94
  "test:spec:general": "vitest run --project spec-minimal test/spec/general/",
@@ -105,10 +103,10 @@
105
103
  "@chainsafe/enr": "^6.0.2",
106
104
  "@chainsafe/libp2p-noise": "^17.0.0",
107
105
  "@chainsafe/libp2p-quic": "^2.1.6",
108
- "@chainsafe/persistent-merkle-tree": "^1.3.1",
106
+ "@chainsafe/persistent-merkle-tree": "^1.3.2",
109
107
  "@chainsafe/prometheus-gc-stats": "^1.0.0",
110
108
  "@chainsafe/snappy-wasm": "^0.5.2",
111
- "@chainsafe/ssz": "^1.9.2",
109
+ "@chainsafe/ssz": "^1.9.3",
112
110
  "@chainsafe/threads": "^1.11.3",
113
111
  "@crate-crypto/node-eth-kzg": "0.9.1",
114
112
  "@fastify/bearer-auth": "^10.0.1",
@@ -126,18 +124,18 @@
126
124
  "@libp2p/prometheus-metrics": "^5.0.31",
127
125
  "@libp2p/tcp": "^11.0.30",
128
126
  "@libp2p/utils": "^7.4.6",
129
- "@lodestar/api": "^2.1.0-dev.9d37cdf84a",
130
- "@lodestar/config": "^2.1.0-dev.9d37cdf84a",
131
- "@lodestar/db": "^2.1.0-dev.9d37cdf84a",
132
- "@lodestar/fork-choice": "^2.1.0-dev.9d37cdf84a",
133
- "@lodestar/logger": "^2.1.0-dev.9d37cdf84a",
134
- "@lodestar/native": "^2.1.0-dev.9d37cdf84a",
135
- "@lodestar/params": "^2.1.0-dev.9d37cdf84a",
136
- "@lodestar/reqresp": "^2.1.0-dev.9d37cdf84a",
137
- "@lodestar/state-transition": "^2.1.0-dev.9d37cdf84a",
138
- "@lodestar/types": "^2.1.0-dev.9d37cdf84a",
139
- "@lodestar/utils": "^2.1.0-dev.9d37cdf84a",
140
- "@lodestar/validator": "^2.1.0-dev.9d37cdf84a",
127
+ "@lodestar/api": "^2.1.0-dev.9d8b35c280",
128
+ "@lodestar/config": "^2.1.0-dev.9d8b35c280",
129
+ "@lodestar/db": "^2.1.0-dev.9d8b35c280",
130
+ "@lodestar/fork-choice": "^2.1.0-dev.9d8b35c280",
131
+ "@lodestar/logger": "^2.1.0-dev.9d8b35c280",
132
+ "@lodestar/native": "^2.1.0-dev.9d8b35c280",
133
+ "@lodestar/params": "^2.1.0-dev.9d8b35c280",
134
+ "@lodestar/reqresp": "^2.1.0-dev.9d8b35c280",
135
+ "@lodestar/state-transition": "^2.1.0-dev.9d8b35c280",
136
+ "@lodestar/types": "^2.1.0-dev.9d8b35c280",
137
+ "@lodestar/utils": "^2.1.0-dev.9d8b35c280",
138
+ "@lodestar/validator": "^2.1.0-dev.9d8b35c280",
141
139
  "@multiformats/multiaddr": "^13.0.1",
142
140
  "datastore-core": "^12.0.1",
143
141
  "datastore-level": "^13.0.1",
@@ -159,12 +157,11 @@
159
157
  "@ethereumjs/rlp": "^10.1.3",
160
158
  "@libp2p/interface-internal": "^3.2.3",
161
159
  "@libp2p/logger": "^6.2.16",
162
- "@lodestar/spec-test-util": "^2.1.0-dev.9d37cdf84a",
163
- "@lodestar/test-utils": "^2.1.0-dev.9d37cdf84a",
160
+ "@lodestar/spec-test-util": "^2.1.0-dev.9d8b35c280",
161
+ "@lodestar/test-utils": "^2.1.0-dev.9d8b35c280",
164
162
  "@types/js-yaml": "^4.0.5",
165
163
  "@types/qs": "^6.9.7",
166
164
  "@types/tmp": "^0.2.3",
167
- "dotenv": "^16.4.5",
168
165
  "js-yaml": "^4.1.0",
169
166
  "tmp": "^0.2.1"
170
167
  },
@@ -174,5 +171,5 @@
174
171
  "beacon",
175
172
  "blockchain"
176
173
  ],
177
- "gitHead": "d462be00e046bb5f55095110e63dfd198e6a7e2f"
174
+ "gitHead": "fe372effb6db2bb1368c1685089a1a7d2f636dc6"
178
175
  }
@@ -542,11 +542,7 @@ export function getBeaconBlockApi(
542
542
  })
543
543
  );
544
544
  return {
545
- data: result.filter(
546
- (item) =>
547
- // skip if no slot filter
548
- !(slot !== undefined && slot !== 0) || item.header.message.slot === slot
549
- ),
545
+ data: result.filter((item) => slot === undefined || item.header.message.slot === slot),
550
546
  meta: {executionOptimistic, finalized},
551
547
  };
552
548
  }
@@ -200,12 +200,23 @@ export function getBeaconPoolApi({
200
200
  const verifiedDomains = await validateApiAttesterSlashing(chain, attesterSlashing);
201
201
  const fork = chain.config.getForkName(Number(attesterSlashing.attestation1.data.slot));
202
202
  chain.opPool.insertAttesterSlashing(fork, attesterSlashing, verifiedDomains);
203
+ try {
204
+ chain.forkChoice.onAttesterSlashing(attesterSlashing);
205
+ } catch (e) {
206
+ logger.warn(
207
+ "Error processing AttesterSlashing from api",
208
+ {slot: attesterSlashing.attestation1.data.slot},
209
+ e as Error
210
+ );
211
+ }
212
+ chain.emitter.emit(routes.events.EventType.attesterSlashing, attesterSlashing);
203
213
  await network.publishAttesterSlashing(attesterSlashing);
204
214
  },
205
215
 
206
216
  async submitPoolProposerSlashings({proposerSlashing}) {
207
217
  const verifiedDomain = await validateApiProposerSlashing(chain, proposerSlashing);
208
218
  chain.opPool.insertProposerSlashing(proposerSlashing, verifiedDomain);
219
+ chain.emitter.emit(routes.events.EventType.proposerSlashing, proposerSlashing);
209
220
  await network.publishProposerSlashing(proposerSlashing);
210
221
  },
211
222
 
@@ -114,16 +114,12 @@ export function getBeaconStateApi({
114
114
  if (resp.valid) {
115
115
  const validatorIndex = resp.validatorIndex;
116
116
  const validator = state.getValidator(validatorIndex);
117
- const status = getValidatorStatus(validator, currentEpoch);
117
+ const balance = state.getBalance(validatorIndex);
118
+ const status = getValidatorStatus(validator, balance, currentEpoch);
118
119
  if (statuses.length && !statuses.includes(status) && !statuses.includes(mapToGeneralStatus(status))) {
119
120
  continue;
120
121
  }
121
- const validatorResponse = toValidatorResponse(
122
- validatorIndex,
123
- validator,
124
- state.getBalance(validatorIndex),
125
- currentEpoch
126
- );
122
+ const validatorResponse = toValidatorResponse(validatorIndex, validator, balance, currentEpoch);
127
123
  validatorResponses.push(validatorResponse);
128
124
  }
129
125
  }
@@ -109,7 +109,7 @@ export function toValidatorResponse(
109
109
  ): routes.beacon.ValidatorResponse {
110
110
  return {
111
111
  index,
112
- status: getValidatorStatus(validator, currentEpoch),
112
+ status: getValidatorStatus(validator, balance, currentEpoch),
113
113
  balance,
114
114
  validator,
115
115
  };
@@ -2174,7 +2174,7 @@ export function getValidatorApi(
2174
2174
  if (validatorIndex === null || validatorIndex >= headState.validatorCount) return false;
2175
2175
 
2176
2176
  const validator = headState.getValidator(validatorIndex);
2177
- const status = getValidatorStatus(validator, currentEpoch);
2177
+ const status = getValidatorStatus(validator, headState.getBalance(validatorIndex), currentEpoch);
2178
2178
  return (
2179
2179
  status === "active_exiting" ||
2180
2180
  status === "active_ongoing" ||
@@ -8,6 +8,7 @@ import {JobItemQueue} from "../util/queue/index.js";
8
8
  import {BlockInputColumns} from "./blocks/blockInput/index.js";
9
9
  import {PayloadEnvelopeInput} from "./blocks/payloadEnvelopeInput/index.js";
10
10
  import {ChainEventEmitter} from "./emitter.js";
11
+ import {SeenDataColumnSidecars} from "./seenCache/seenDataColumnSidecars.js";
11
12
 
12
13
  /**
13
14
  * Minimum time to wait before attempting reconstruction
@@ -31,6 +32,7 @@ export type ColumnReconstructionInput = BlockInputColumns | PayloadEnvelopeInput
31
32
  export type ColumnReconstructionTrackerInit = {
32
33
  logger: Logger;
33
34
  emitter: ChainEventEmitter;
35
+ seenDataColumnSidecars: SeenDataColumnSidecars;
34
36
  metrics: Metrics | null;
35
37
  config: ChainForkConfig;
36
38
  signal: AbortSignal;
@@ -44,6 +46,7 @@ export type ColumnReconstructionTrackerInit = {
44
46
  export class ColumnReconstructionTracker {
45
47
  logger: Logger;
46
48
  emitter: ChainEventEmitter;
49
+ seenDataColumnSidecars: SeenDataColumnSidecars;
47
50
  metrics: Metrics | null;
48
51
  config: ChainForkConfig;
49
52
 
@@ -54,6 +57,7 @@ export class ColumnReconstructionTracker {
54
57
  constructor(init: ColumnReconstructionTrackerInit) {
55
58
  this.logger = init.logger;
56
59
  this.emitter = init.emitter;
60
+ this.seenDataColumnSidecars = init.seenDataColumnSidecars;
57
61
  this.metrics = init.metrics;
58
62
  this.config = init.config;
59
63
  this.signal = init.signal;
@@ -104,7 +108,7 @@ export class ColumnReconstructionTracker {
104
108
  const logCtx = {slot: input.slot, root: input.blockRootHex};
105
109
  this.logger.debug("Attempting data column sidecar reconstruction", logCtx);
106
110
  try {
107
- const result = await recoverDataColumnSidecars(input, this.emitter, this.metrics);
111
+ const result = await recoverDataColumnSidecars(input, this.emitter, this.seenDataColumnSidecars, this.metrics);
108
112
  this.metrics?.recoverDataColumnSidecars.reconstructionResult.inc({result});
109
113
  this.logger.debug("Data column sidecar reconstruction complete", {...logCtx, result});
110
114
  } catch (e) {
@@ -8,6 +8,7 @@ import {DataColumnEngineResult, getDataColumnSidecarsFromExecution} from "../uti
8
8
  import {IBlockInput, isBlockInputColumns} from "./blocks/blockInput/index.js";
9
9
  import {PayloadEnvelopeInput} from "./blocks/payloadEnvelopeInput/index.js";
10
10
  import {ChainEventEmitter} from "./emitter.js";
11
+ import {SeenDataColumnSidecars} from "./seenCache/seenDataColumnSidecars.js";
11
12
 
12
13
  /** A `null` answer only changes if the EL receives the transactions later, so retries are few and spaced out */
13
14
  export const MAX_GET_BLOBS_ATTEMPTS = 3;
@@ -18,6 +19,7 @@ export type GetBlobsTrackerInit = {
18
19
  logger: Logger;
19
20
  executionEngine: Pick<IExecutionEngine, "getBlobs">;
20
21
  emitter: ChainEventEmitter;
22
+ seenDataColumnSidecars: SeenDataColumnSidecars;
21
23
  metrics: Metrics | null;
22
24
  config: ChainForkConfig;
23
25
  };
@@ -29,6 +31,7 @@ export class GetBlobsTracker {
29
31
  logger: Logger;
30
32
  executionEngine: Pick<IExecutionEngine, "getBlobs">;
31
33
  emitter: ChainEventEmitter;
34
+ seenDataColumnSidecars: SeenDataColumnSidecars;
32
35
  metrics: Metrics | null;
33
36
  config: ChainForkConfig;
34
37
  activeReconstructions = new Set<string>();
@@ -42,6 +45,7 @@ export class GetBlobsTracker {
42
45
  this.logger = init.logger;
43
46
  this.executionEngine = init.executionEngine;
44
47
  this.emitter = init.emitter;
48
+ this.seenDataColumnSidecars = init.seenDataColumnSidecars;
45
49
  this.metrics = init.metrics;
46
50
  this.config = init.config;
47
51
  }
@@ -101,6 +105,7 @@ export class GetBlobsTracker {
101
105
  this.config,
102
106
  this.executionEngine,
103
107
  this.emitter,
108
+ this.seenDataColumnSidecars,
104
109
  input,
105
110
  this.metrics,
106
111
  this.blobsAndProofsBuffers[freeIndex].buffers
@@ -22,9 +22,16 @@ export enum PayloadEnvelopeInputSource {
22
22
  * - finalized: below the finalized slot
23
23
  * - prune: explicit prune by root
24
24
  * - cap: insertion-order backstop cap (MAX_PAYLOAD_ENVELOPE_INPUT_CACHE_SIZE)
25
+ * - capUnvalidated: cap eviction of an entry whose block is not validated and imported yet, evicted before the rest
25
26
  * - invalid: the cached envelope failed import with a definitive invalid verdict
26
27
  */
27
- export type PayloadEnvelopeInputPruneReason = "belowParent" | "finalized" | "remove" | "cap" | "invalid";
28
+ export type PayloadEnvelopeInputPruneReason =
29
+ | "belowParent"
30
+ | "finalized"
31
+ | "remove"
32
+ | "cap"
33
+ | "capUnvalidated"
34
+ | "invalid";
28
35
 
29
36
  export type SourceMeta = {
30
37
  source: PayloadEnvelopeInputSource;
@@ -127,6 +127,7 @@ import {
127
127
  SeenAttesters,
128
128
  SeenBlockProposers,
129
129
  SeenContributionAndProof,
130
+ SeenDataColumnSidecars,
130
131
  SeenExecutionPayloadBids,
131
132
  SeenPayloadAttesters,
132
133
  SeenPayloadEnvelopeInput,
@@ -224,6 +225,7 @@ export class BeaconChain implements IBeaconChain {
224
225
  readonly seenAggregatedAttestations: SeenAggregatedAttestations;
225
226
  readonly seenExecutionPayloadBids = new SeenExecutionPayloadBids();
226
227
  readonly seenBlockProposers = new SeenBlockProposers();
228
+ readonly seenDataColumnSidecars = new SeenDataColumnSidecars();
227
229
  /** Proposer indexes with an in-flight proposer slashing production */
228
230
  private readonly producingProposerSlashing = new Set<ValidatorIndex>();
229
231
  readonly seenSyncCommitteeMessages = new SeenSyncCommitteeMessages();
@@ -527,12 +529,14 @@ export class BeaconChain implements IBeaconChain {
527
529
  logger,
528
530
  executionEngine: this.executionEngine,
529
531
  emitter,
532
+ seenDataColumnSidecars: this.seenDataColumnSidecars,
530
533
  metrics,
531
534
  config,
532
535
  });
533
536
  this.columnReconstructionTracker = new ColumnReconstructionTracker({
534
537
  logger,
535
538
  emitter,
539
+ seenDataColumnSidecars: this.seenDataColumnSidecars,
536
540
  metrics,
537
541
  config,
538
542
  signal,
@@ -2039,9 +2043,18 @@ export class BeaconChain implements IBeaconChain {
2039
2043
 
2040
2044
  const finalizedSlot = computeStartSlotAtEpoch(cp.epoch);
2041
2045
  this.seenBlockProposers.prune(finalizedSlot);
2046
+ this.seenDataColumnSidecars.prune(finalizedSlot);
2042
2047
 
2043
2048
  // Update validator custody to account for effective balance changes
2044
- await this.updateValidatorsCustodyRequirement(cp);
2049
+ try {
2050
+ await this.updateValidatorsCustodyRequirement(cp);
2051
+ } catch (e) {
2052
+ this.logger.warn(
2053
+ "Error updating validators custody requirement",
2054
+ {epoch: cp.epoch, root: cp.rootHex},
2055
+ e as Error
2056
+ );
2057
+ }
2045
2058
 
2046
2059
  // TODO: Improve using regen here
2047
2060
  const {blockRoot, stateRoot, slot} = this.forkChoice.getHead();
@@ -2147,7 +2160,9 @@ export class BeaconChain implements IBeaconChain {
2147
2160
  if (stateOrBytes instanceof Uint8Array) {
2148
2161
  effectiveBalances = getEffectiveBalancesFromStateBytes(this.config, stateOrBytes, validatorIndices);
2149
2162
  } else {
2150
- effectiveBalances = validatorIndices.map((index) => stateOrBytes.getValidator(index).effectiveBalance ?? 0);
2163
+ effectiveBalances = validatorIndices.map((index) =>
2164
+ index < stateOrBytes.validatorCount ? stateOrBytes.getValidator(index).effectiveBalance : 0
2165
+ );
2151
2166
  }
2152
2167
  }
2153
2168
 
@@ -35,6 +35,7 @@ export enum DataColumnSidecarErrorCode {
35
35
 
36
36
  // following errors are adapted from the block errors
37
37
  ALREADY_KNOWN = "DATA_COLUMN_SIDECAR_ERROR_ALREADY_KNOWN",
38
+ REPEAT_PROPOSAL = "DATA_COLUMN_SIDECAR_ERROR_REPEAT_PROPOSAL",
38
39
  FUTURE_SLOT = "DATA_COLUMN_SIDECAR_ERROR_FUTURE_SLOT",
39
40
  WOULD_REVERT_FINALIZED_SLOT = "DATA_COLUMN_SIDECAR_ERROR_WOULD_REVERT_FINALIZED_SLOT",
40
41
  PARENT_UNKNOWN = "DATA_COLUMN_SIDECAR_ERROR_PARENT_UNKNOWN",
@@ -79,6 +80,13 @@ export type DataColumnSidecarErrorType =
79
80
  limit: number;
80
81
  }
81
82
  | {code: DataColumnSidecarErrorCode.ALREADY_KNOWN; columnIndex: number; slot: Slot}
83
+ | {
84
+ code: DataColumnSidecarErrorCode.REPEAT_PROPOSAL;
85
+ slot: Slot;
86
+ proposerIndex: number;
87
+ columnIndex: number;
88
+ root: RootHex;
89
+ }
82
90
  | {code: DataColumnSidecarErrorCode.FUTURE_SLOT; blockSlot: Slot; currentSlot: Slot}
83
91
  | {code: DataColumnSidecarErrorCode.WOULD_REVERT_FINALIZED_SLOT; blockSlot: Slot; finalizedSlot: Slot}
84
92
  | {
@@ -318,9 +318,7 @@ export function initializeNativeForkChoice(
318
318
  : isPostGloas
319
319
  ? Number(state.latestExecutionPayloadBid.gasLimit)
320
320
  : state.latestExecutionPayloadHeader.gasLimit,
321
- // A Gloas payload is judged when its envelope arrives, the genesis one included
322
- executionStatus:
323
- blockHeader.slot === GENESIS_SLOT && !isPostGloasAnchor ? ExecutionStatus.Valid : ExecutionStatus.Syncing,
321
+ executionStatus: blockHeader.slot === GENESIS_SLOT ? ExecutionStatus.Valid : ExecutionStatus.Syncing,
324
322
  }
325
323
  : {executionPayloadBlockHash: null, executionStatus: ExecutionStatus.PreMerge}),
326
324
 
@@ -68,6 +68,7 @@ import {
68
68
  SeenAttesters,
69
69
  SeenBlockProposers,
70
70
  SeenContributionAndProof,
71
+ SeenDataColumnSidecars,
71
72
  SeenExecutionPayloadBids,
72
73
  SeenPayloadAttesters,
73
74
  SeenSyncCommitteeMessages,
@@ -147,6 +148,7 @@ export interface IBeaconChain {
147
148
  readonly seenAggregatedAttestations: SeenAggregatedAttestations;
148
149
  readonly seenExecutionPayloadBids: SeenExecutionPayloadBids;
149
150
  readonly seenBlockProposers: SeenBlockProposers;
151
+ readonly seenDataColumnSidecars: SeenDataColumnSidecars;
150
152
  readonly seenSyncCommitteeMessages: SeenSyncCommitteeMessages;
151
153
  readonly seenContributionAndProof: SeenContributionAndProof;
152
154
  readonly seenAttestationDatas: SeenAttestationDatas;
@@ -2,6 +2,7 @@ export {SeenAggregators, SeenAttesters, SeenPayloadAttesters} from "./seenAttest
2
2
  export {SeenBlockProposers} from "./seenBlockProposers.js";
3
3
  export {SeenSyncCommitteeMessages} from "./seenCommittee.js";
4
4
  export {SeenContributionAndProof} from "./seenCommitteeContribution.js";
5
+ export {SeenDataColumnSidecars} from "./seenDataColumnSidecars.js";
5
6
  export {SeenExecutionPayloadBids} from "./seenExecutionPayloadBids.js";
6
7
  export {SeenBlockInput} from "./seenGossipBlockInput.js";
7
8
  export {PayloadEnvelopeInput, SeenPayloadEnvelopeInput} from "./seenPayloadEnvelopeInput.js";
@@ -1,6 +1,6 @@
1
1
  import {computeStartSlotAtEpoch} from "@lodestar/state-transition";
2
2
  import {Epoch, RootHex, Slot, ValidatorIndex, phase0} from "@lodestar/types";
3
- import {MapDef} from "@lodestar/utils";
3
+ import {MapDef, byteArrayEquals} from "@lodestar/utils";
4
4
 
5
5
  /** Two distinct block roots signed by the same proposer for the same slot are sufficient to establish an equivocation */
6
6
  const MIN_EQUIVOCATION_BLOCK_ROOTS_PER_PROPOSAL = 2;
@@ -44,6 +44,16 @@ export class SeenBlockProposers {
44
44
  return this.signedBlockHeadersBySlot.get(blockSlot)?.get(proposerIndex)?.has(blockRoot) === true;
45
45
  }
46
46
 
47
+ hasBlockSignature(
48
+ blockSlot: Slot,
49
+ proposerIndex: ValidatorIndex,
50
+ blockRoot: RootHex,
51
+ signature: Uint8Array
52
+ ): boolean {
53
+ const signedBlockHeader = this.signedBlockHeadersBySlot.get(blockSlot)?.get(proposerIndex)?.get(blockRoot);
54
+ return signedBlockHeader !== undefined && byteArrayEquals(signedBlockHeader.signature, signature);
55
+ }
56
+
47
57
  isEquivocating(blockSlot: Slot, proposerIndex: ValidatorIndex): boolean {
48
58
  return (
49
59
  (this.signedBlockHeadersBySlot.get(blockSlot)?.get(proposerIndex)?.size ?? 0) >=
@@ -0,0 +1,64 @@
1
+ import {ColumnIndex, RootHex, Slot, ValidatorIndex} from "@lodestar/types";
2
+ import {MapDef} from "@lodestar/utils";
3
+
4
+ /**
5
+ * Tracks the column indices of valid gossip data column sidecars per slot, proposer and block root,
6
+ * to ignore sidecars of a repeated proposal. Pruned on finalization.
7
+ */
8
+ export class SeenDataColumnSidecars {
9
+ private readonly columnIndicesBySlot = new MapDef<Slot, MapDef<ValidatorIndex, MapDef<RootHex, Set<ColumnIndex>>>>(
10
+ () => new MapDef(() => new MapDef(() => new Set()))
11
+ );
12
+ private readonly evidenceChecksBySlot = new MapDef<Slot, Set<ValidatorIndex>>(() => new Set());
13
+ private finalizedSlot: Slot = 0;
14
+
15
+ isRepeatProposal(slot: Slot, proposerIndex: ValidatorIndex, columnIndex: ColumnIndex, blockRoot: RootHex): boolean {
16
+ const columnIndicesByRoot = this.columnIndicesBySlot.get(slot)?.get(proposerIndex);
17
+ if (columnIndicesByRoot === undefined) {
18
+ return false;
19
+ }
20
+ for (const [root, columnIndices] of columnIndicesByRoot) {
21
+ if (root !== blockRoot && columnIndices.has(columnIndex)) {
22
+ return true;
23
+ }
24
+ }
25
+ return false;
26
+ }
27
+
28
+ isKnown(slot: Slot, proposerIndex: ValidatorIndex, columnIndex: ColumnIndex, blockRoot: RootHex): boolean {
29
+ return this.columnIndicesBySlot.get(slot)?.get(proposerIndex)?.get(blockRoot)?.has(columnIndex) === true;
30
+ }
31
+
32
+ add(slot: Slot, proposerIndex: ValidatorIndex, columnIndex: ColumnIndex, blockRoot: RootHex): void {
33
+ if (slot < this.finalizedSlot || this.isRepeatProposal(slot, proposerIndex, columnIndex, blockRoot)) {
34
+ return;
35
+ }
36
+ this.columnIndicesBySlot.getOrDefault(slot).getOrDefault(proposerIndex).getOrDefault(blockRoot).add(columnIndex);
37
+ }
38
+
39
+ markEvidenceCheck(slot: Slot, proposerIndex: ValidatorIndex): boolean {
40
+ if (slot < this.finalizedSlot) {
41
+ return false;
42
+ }
43
+ const proposers = this.evidenceChecksBySlot.getOrDefault(slot);
44
+ if (proposers.has(proposerIndex)) {
45
+ return false;
46
+ }
47
+ proposers.add(proposerIndex);
48
+ return true;
49
+ }
50
+
51
+ prune(finalizedSlot: Slot): void {
52
+ this.finalizedSlot = finalizedSlot;
53
+ for (const slot of this.columnIndicesBySlot.keys()) {
54
+ if (slot < finalizedSlot) {
55
+ this.columnIndicesBySlot.delete(slot);
56
+ }
57
+ }
58
+ for (const slot of this.evidenceChecksBySlot.keys()) {
59
+ if (slot < finalizedSlot) {
60
+ this.evidenceChecksBySlot.delete(slot);
61
+ }
62
+ }
63
+ }
64
+ }
@@ -64,6 +64,7 @@ export class SeenPayloadEnvelopeInput {
64
64
  private readonly metrics: Metrics | null;
65
65
  private readonly logger?: Logger;
66
66
  private payloadInputs = new Map<RootHex, PayloadEnvelopeInput>();
67
+ private readonly unvalidatedRoots = new Set<RootHex>();
67
68
  // Dedup concurrent DB reloads of the same root so callers share one reconstructed object.
68
69
  private readonly reloading = new Map<RootHex, Promise<PayloadEnvelopeInput | undefined>>();
69
70
 
@@ -127,9 +128,17 @@ export class SeenPayloadEnvelopeInput {
127
128
  });
128
129
  };
129
130
 
130
- add(props: Omit<CreateFromBlockProps, "daOutOfRange">): PayloadEnvelopeInput {
131
+ /**
132
+ * Set `unvalidated` for a block of which only the proposer signature is verified, e.g. one retained for unknown
133
+ * parent sync. Such entries are evicted first when the cache is over its max size, until the block passes gossip
134
+ * validation or is imported. Adding an existing entry without `unvalidated` promotes it without replacing it.
135
+ */
136
+ add(props: Omit<CreateFromBlockProps, "daOutOfRange">, opts?: {unvalidated?: boolean}): PayloadEnvelopeInput {
131
137
  const existing = this.payloadInputs.get(props.blockRootHex);
132
138
  if (existing !== undefined) {
139
+ if (!opts?.unvalidated) {
140
+ this.unvalidatedRoots.delete(props.blockRootHex);
141
+ }
133
142
  this.logger?.verbose("SeenPayloadEnvelopeInput.add reused existing entry", {
134
143
  slot: existing.slot,
135
144
  root: props.blockRootHex,
@@ -139,6 +148,9 @@ export class SeenPayloadEnvelopeInput {
139
148
  const daOutOfRange = isDaOutOfRange(this.config, props.forkName, props.block.message.slot, this.clock.currentEpoch);
140
149
  const input = PayloadEnvelopeInput.createFromBlock({...props, daOutOfRange});
141
150
  this.payloadInputs.set(props.blockRootHex, input);
151
+ if (opts?.unvalidated) {
152
+ this.unvalidatedRoots.add(props.blockRootHex);
153
+ }
142
154
  this.metrics?.seenCache.payloadEnvelopeInput.created.inc({source: props.source});
143
155
  this.logger?.verbose("SeenPayloadEnvelopeInput.add created new entry", {
144
156
  slot: input.slot,
@@ -300,12 +312,25 @@ export class SeenPayloadEnvelopeInput {
300
312
 
301
313
  /**
302
314
  * Bound this cache to have at most MAX_PAYLOAD_ENVELOPE_INPUT_CACHE_SIZE items.
303
- * Evicts by insertion order so a just-reloaded old-slot entry is not evicted right after.
315
+ * Evicts entries of unvalidated blocks that are not imported yet first, then the rest by insertion order so a
316
+ * just-reloaded old-slot entry is not evicted right after.
304
317
  * On unstable network, we may need to query an evicted item, UnknownBlockInput will recover
305
318
  * it from db via getOrReload() api. Runs after every single insert, so it evicts ~1 per call.
306
319
  */
307
320
  private pruneToMaxSize(): void {
308
321
  let evicted = 0;
322
+ for (const blockRootHex of this.unvalidatedRoots) {
323
+ if (this.payloadInputs.size <= MAX_PAYLOAD_ENVELOPE_INPUT_CACHE_SIZE) {
324
+ break;
325
+ }
326
+ const input = this.payloadInputs.get(blockRootHex);
327
+ if (input === undefined || this.forkChoice.hasBlockHex(blockRootHex)) {
328
+ this.unvalidatedRoots.delete(blockRootHex);
329
+ continue;
330
+ }
331
+ this.evictPayloadInput(input, "capUnvalidated");
332
+ evicted++;
333
+ }
309
334
  for (const input of this.payloadInputs.values()) {
310
335
  if (this.payloadInputs.size <= MAX_PAYLOAD_ENVELOPE_INPUT_CACHE_SIZE) {
311
336
  break;
@@ -331,5 +356,6 @@ export class SeenPayloadEnvelopeInput {
331
356
  });
332
357
  this.serializedCache.delete(payloadInput.getSerializedCacheKeys());
333
358
  this.payloadInputs.delete(payloadInput.blockRootHex);
359
+ this.unvalidatedRoots.delete(payloadInput.blockRootHex);
334
360
  }
335
361
  }
@@ -261,10 +261,12 @@ async function validateAttestationNoSignatureCheck(
261
261
  const attSlot = attestationOrBytes.attSlot;
262
262
  attDataKey = getSeenAttDataKeyFromGossipAttestation(attestationOrBytes);
263
263
  const committeeIndexForLookup = isForkPostElectra(fork)
264
- ? (getCommitteeIndexFromAttestationOrBytes(fork, attestationOrBytes) ?? 0)
264
+ ? getCommitteeIndexFromAttestationOrBytes(fork, attestationOrBytes)
265
265
  : PRE_ELECTRA_SINGLE_ATTESTATION_COMMITTEE_INDEX;
266
266
  const cachedAttData =
267
- attDataKey !== null ? chain.seenAttestationDatas.get(attSlot, committeeIndexForLookup, attDataKey) : null;
267
+ attDataKey !== null && committeeIndexForLookup !== null
268
+ ? chain.seenAttestationDatas.get(attSlot, committeeIndexForLookup, attDataKey)
269
+ : null;
268
270
  if (cachedAttData === null) {
269
271
  const attestation = sszDeserializeSingleAttestation(fork, attestationOrBytes.serializedData);
270
272
  // only deserialize on the first AttestationData that's not cached
@@ -76,8 +76,17 @@ export async function validateGossipBlock(
76
76
  const proposerIndex = block.proposerIndex;
77
77
  if (chain.seenBlockProposers.isKnown(blockSlot, proposerIndex)) {
78
78
  if (chain.seenBlockProposers.isRepeatProposal(blockSlot, proposerIndex, blockRoot)) {
79
- const hasBlockRoot = chain.seenBlockProposers.hasBlockRoot(blockSlot, proposerIndex, blockRoot);
80
- if (!hasBlockRoot && !chain.seenBlockProposers.isEquivocating(blockSlot, proposerIndex)) {
79
+ if (chain.seenBlockProposers.hasBlockRoot(blockSlot, proposerIndex, blockRoot)) {
80
+ // The root is known with a verified signature, e.g. from the header of a data column sidecar, and a valid
81
+ // BLS signature of the same message by the same proposer is unique
82
+ if (!chain.seenBlockProposers.hasBlockSignature(blockSlot, proposerIndex, blockRoot, signedBlock.signature)) {
83
+ throw new BlockGossipError(GossipAction.REJECT, {
84
+ code: BlockErrorCode.PROPOSAL_SIGNATURE_INVALID,
85
+ slot: blockSlot,
86
+ root: blockRoot,
87
+ });
88
+ }
89
+ } else if (!chain.seenBlockProposers.isEquivocating(blockSlot, proposerIndex)) {
81
90
  await verifyBlockProposerSignature(chain, signedBlock, blockRoot, {verifyOnMainThread: false});
82
91
  chain.seenBlockProposers.observeBlockRoot(blockSlot, proposerIndex, blockRoot, signedBlockHeader);
83
92
  }
@@ -225,7 +225,7 @@ export async function validateGossipFuluDataColumnSidecar(
225
225
 
226
226
  // 12) [IGNORE] The sidecar is the first sidecar for the tuple (block_header.slot, block_header.proposer_index,
227
227
  // sidecar.index) with valid header signature, sidecar inclusion proof, and kzg proof
228
- // -- Handled in seenGossipBlockInput
228
+ // -- Handled in gossip handler with seenDataColumnSidecars
229
229
  }
230
230
 
231
231
  // SPEC FUNCTION
@@ -29,10 +29,14 @@ import {Epoch} from "@lodestar/types";
29
29
  export const FORK_EPOCH_LOOKAHEAD = 2;
30
30
 
31
31
  /**
32
- * Return the list of `ForkBoundary`s meant to be active at `epoch`
32
+ * Return the fork boundaries active at any epoch in the inclusive range.
33
33
  * @see FORK_EPOCH_LOOKAHEAD for details on when fork boundaries are considered 'active'
34
34
  */
35
- export function getActiveForkBoundaries(config: ChainForkConfig, epoch: Epoch): ForkBoundary[] {
35
+ export function getActiveForkBoundaries(
36
+ config: ChainForkConfig,
37
+ fromEpoch: Epoch,
38
+ toEpoch = fromEpoch
39
+ ): ForkBoundary[] {
36
40
  const activeBoundaries: ForkBoundary[] = [];
37
41
  const {forkBoundariesAscendingEpochOrder} = config;
38
42
 
@@ -48,7 +52,7 @@ export function getActiveForkBoundaries(config: ChainForkConfig, epoch: Epoch):
48
52
  continue;
49
53
  }
50
54
 
51
- if (epoch >= currentEpoch - FORK_EPOCH_LOOKAHEAD && epoch <= nextEpoch + FORK_EPOCH_LOOKAHEAD) {
55
+ if (toEpoch >= currentEpoch - FORK_EPOCH_LOOKAHEAD && fromEpoch <= nextEpoch + FORK_EPOCH_LOOKAHEAD) {
52
56
  activeBoundaries.push(currentForkBoundary);
53
57
  }
54
58
  }