@lodestar/beacon-node 1.41.0-dev.afd446235e → 1.41.0-dev.bb273175f2

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 (157) hide show
  1. package/lib/api/impl/beacon/blocks/index.d.ts.map +1 -1
  2. package/lib/api/impl/beacon/blocks/index.js +3 -2
  3. package/lib/api/impl/beacon/blocks/index.js.map +1 -1
  4. package/lib/api/impl/debug/index.d.ts.map +1 -1
  5. package/lib/api/impl/debug/index.js +1 -0
  6. package/lib/api/impl/debug/index.js.map +1 -1
  7. package/lib/api/impl/validator/index.d.ts.map +1 -1
  8. package/lib/api/impl/validator/index.js +26 -10
  9. package/lib/api/impl/validator/index.js.map +1 -1
  10. package/lib/chain/archiveStore/archiveStore.d.ts.map +1 -1
  11. package/lib/chain/archiveStore/archiveStore.js.map +1 -1
  12. package/lib/chain/archiveStore/utils/archiveBlocks.d.ts +3 -8
  13. package/lib/chain/archiveStore/utils/archiveBlocks.d.ts.map +1 -1
  14. package/lib/chain/archiveStore/utils/archiveBlocks.js +1 -1
  15. package/lib/chain/archiveStore/utils/archiveBlocks.js.map +1 -1
  16. package/lib/chain/archiveStore/utils/updateBackfillRange.js +1 -1
  17. package/lib/chain/archiveStore/utils/updateBackfillRange.js.map +1 -1
  18. package/lib/chain/blocks/blockInput/blockInput.d.ts +20 -2
  19. package/lib/chain/blocks/blockInput/blockInput.d.ts.map +1 -1
  20. package/lib/chain/blocks/blockInput/blockInput.js +47 -0
  21. package/lib/chain/blocks/blockInput/blockInput.js.map +1 -1
  22. package/lib/chain/blocks/blockInput/types.d.ts +13 -1
  23. package/lib/chain/blocks/blockInput/types.d.ts.map +1 -1
  24. package/lib/chain/blocks/blockInput/types.js +1 -0
  25. package/lib/chain/blocks/blockInput/types.js.map +1 -1
  26. package/lib/chain/blocks/importBlock.d.ts.map +1 -1
  27. package/lib/chain/blocks/importBlock.js +27 -4
  28. package/lib/chain/blocks/importBlock.js.map +1 -1
  29. package/lib/chain/blocks/verifyBlocksDataAvailability.d.ts.map +1 -1
  30. package/lib/chain/blocks/verifyBlocksDataAvailability.js +3 -0
  31. package/lib/chain/blocks/verifyBlocksDataAvailability.js.map +1 -1
  32. package/lib/chain/blocks/verifyBlocksExecutionPayloads.d.ts +4 -0
  33. package/lib/chain/blocks/verifyBlocksExecutionPayloads.d.ts.map +1 -1
  34. package/lib/chain/blocks/verifyBlocksExecutionPayloads.js +5 -1
  35. package/lib/chain/blocks/verifyBlocksExecutionPayloads.js.map +1 -1
  36. package/lib/chain/blocks/verifyBlocksSanityChecks.d.ts.map +1 -1
  37. package/lib/chain/blocks/verifyBlocksSanityChecks.js +4 -1
  38. package/lib/chain/blocks/verifyBlocksSanityChecks.js.map +1 -1
  39. package/lib/chain/blocks/writeBlockInputToDb.d.ts +12 -3
  40. package/lib/chain/blocks/writeBlockInputToDb.d.ts.map +1 -1
  41. package/lib/chain/blocks/writeBlockInputToDb.js +101 -96
  42. package/lib/chain/blocks/writeBlockInputToDb.js.map +1 -1
  43. package/lib/chain/chain.d.ts +1 -1
  44. package/lib/chain/chain.d.ts.map +1 -1
  45. package/lib/chain/chain.js +11 -11
  46. package/lib/chain/chain.js.map +1 -1
  47. package/lib/chain/emitter.d.ts +3 -3
  48. package/lib/chain/emitter.d.ts.map +1 -1
  49. package/lib/chain/errors/executionPayloadEnvelope.d.ts +2 -2
  50. package/lib/chain/errors/executionPayloadEnvelope.d.ts.map +1 -1
  51. package/lib/chain/errors/executionPayloadEnvelope.js.map +1 -1
  52. package/lib/chain/forkChoice/index.d.ts.map +1 -1
  53. package/lib/chain/forkChoice/index.js +30 -24
  54. package/lib/chain/forkChoice/index.js.map +1 -1
  55. package/lib/chain/opPools/aggregatedAttestationPool.js +1 -1
  56. package/lib/chain/opPools/aggregatedAttestationPool.js.map +1 -1
  57. package/lib/chain/produceBlock/produceBlockBody.d.ts.map +1 -1
  58. package/lib/chain/produceBlock/produceBlockBody.js +1 -2
  59. package/lib/chain/produceBlock/produceBlockBody.js.map +1 -1
  60. package/lib/chain/regen/queued.d.ts.map +1 -1
  61. package/lib/chain/regen/queued.js +4 -1
  62. package/lib/chain/regen/queued.js.map +1 -1
  63. package/lib/chain/regen/regen.d.ts.map +1 -1
  64. package/lib/chain/regen/regen.js +6 -2
  65. package/lib/chain/regen/regen.js.map +1 -1
  66. package/lib/chain/seenCache/seenGossipBlockInput.d.ts.map +1 -1
  67. package/lib/chain/seenCache/seenGossipBlockInput.js +15 -7
  68. package/lib/chain/seenCache/seenGossipBlockInput.js.map +1 -1
  69. package/lib/chain/validation/aggregateAndProof.js +1 -1
  70. package/lib/chain/validation/aggregateAndProof.js.map +1 -1
  71. package/lib/chain/validation/attestation.js +3 -3
  72. package/lib/chain/validation/attestation.js.map +1 -1
  73. package/lib/chain/validation/attesterSlashing.d.ts.map +1 -1
  74. package/lib/chain/validation/attesterSlashing.js +8 -1
  75. package/lib/chain/validation/attesterSlashing.js.map +1 -1
  76. package/lib/chain/validation/blobSidecar.js +2 -2
  77. package/lib/chain/validation/blobSidecar.js.map +1 -1
  78. package/lib/chain/validation/block.d.ts.map +1 -1
  79. package/lib/chain/validation/block.js +6 -3
  80. package/lib/chain/validation/block.js.map +1 -1
  81. package/lib/chain/validation/dataColumnSidecar.js +1 -1
  82. package/lib/chain/validation/dataColumnSidecar.js.map +1 -1
  83. package/lib/chain/validation/executionPayloadBid.js +1 -2
  84. package/lib/chain/validation/executionPayloadBid.js.map +1 -1
  85. package/lib/chain/validation/executionPayloadEnvelope.js +4 -4
  86. package/lib/chain/validation/executionPayloadEnvelope.js.map +1 -1
  87. package/lib/chain/validation/payloadAttestationMessage.js +1 -2
  88. package/lib/chain/validation/payloadAttestationMessage.js.map +1 -1
  89. package/lib/constants/network.d.ts +1 -2
  90. package/lib/constants/network.d.ts.map +1 -1
  91. package/lib/constants/network.js +0 -1
  92. package/lib/constants/network.js.map +1 -1
  93. package/lib/network/peers/peerManager.d.ts +0 -8
  94. package/lib/network/peers/peerManager.d.ts.map +1 -1
  95. package/lib/network/peers/peerManager.js +3 -48
  96. package/lib/network/peers/peerManager.js.map +1 -1
  97. package/lib/network/processor/gossipHandlers.d.ts.map +1 -1
  98. package/lib/network/processor/gossipHandlers.js +4 -1
  99. package/lib/network/processor/gossipHandlers.js.map +1 -1
  100. package/lib/network/reqresp/handlers/beaconBlocksByRange.d.ts.map +1 -1
  101. package/lib/network/reqresp/handlers/beaconBlocksByRange.js +3 -2
  102. package/lib/network/reqresp/handlers/beaconBlocksByRange.js.map +1 -1
  103. package/lib/network/reqresp/handlers/blobSidecarsByRange.d.ts.map +1 -1
  104. package/lib/network/reqresp/handlers/blobSidecarsByRange.js +3 -2
  105. package/lib/network/reqresp/handlers/blobSidecarsByRange.js.map +1 -1
  106. package/lib/network/reqresp/handlers/blobSidecarsByRoot.js +1 -1
  107. package/lib/network/reqresp/handlers/blobSidecarsByRoot.js.map +1 -1
  108. package/lib/network/reqresp/handlers/dataColumnSidecarsByRange.d.ts.map +1 -1
  109. package/lib/network/reqresp/handlers/dataColumnSidecarsByRange.js +3 -2
  110. package/lib/network/reqresp/handlers/dataColumnSidecarsByRange.js.map +1 -1
  111. package/lib/network/reqresp/handlers/dataColumnSidecarsByRoot.js +1 -1
  112. package/lib/network/reqresp/handlers/dataColumnSidecarsByRoot.js.map +1 -1
  113. package/lib/util/clock.d.ts +6 -0
  114. package/lib/util/clock.d.ts.map +1 -1
  115. package/lib/util/clock.js +9 -3
  116. package/lib/util/clock.js.map +1 -1
  117. package/package.json +26 -26
  118. package/src/api/impl/beacon/blocks/index.ts +3 -2
  119. package/src/api/impl/debug/index.ts +1 -0
  120. package/src/api/impl/validator/index.ts +26 -12
  121. package/src/chain/archiveStore/archiveStore.ts +5 -5
  122. package/src/chain/archiveStore/utils/archiveBlocks.ts +4 -5
  123. package/src/chain/archiveStore/utils/updateBackfillRange.ts +1 -1
  124. package/src/chain/blocks/blockInput/blockInput.ts +68 -3
  125. package/src/chain/blocks/blockInput/types.ts +13 -0
  126. package/src/chain/blocks/importBlock.ts +35 -4
  127. package/src/chain/blocks/verifyBlocksDataAvailability.ts +3 -0
  128. package/src/chain/blocks/verifyBlocksExecutionPayloads.ts +9 -2
  129. package/src/chain/blocks/verifyBlocksSanityChecks.ts +7 -2
  130. package/src/chain/blocks/writeBlockInputToDb.ts +119 -101
  131. package/src/chain/chain.ts +26 -14
  132. package/src/chain/emitter.ts +3 -3
  133. package/src/chain/errors/executionPayloadEnvelope.ts +6 -2
  134. package/src/chain/forkChoice/index.ts +39 -21
  135. package/src/chain/opPools/aggregatedAttestationPool.ts +1 -1
  136. package/src/chain/produceBlock/produceBlockBody.ts +1 -2
  137. package/src/chain/regen/queued.ts +7 -2
  138. package/src/chain/regen/regen.ts +9 -3
  139. package/src/chain/seenCache/seenGossipBlockInput.ts +16 -7
  140. package/src/chain/validation/aggregateAndProof.ts +1 -1
  141. package/src/chain/validation/attestation.ts +3 -3
  142. package/src/chain/validation/attesterSlashing.ts +9 -0
  143. package/src/chain/validation/blobSidecar.ts +2 -2
  144. package/src/chain/validation/block.ts +9 -4
  145. package/src/chain/validation/dataColumnSidecar.ts +1 -1
  146. package/src/chain/validation/executionPayloadBid.ts +1 -2
  147. package/src/chain/validation/executionPayloadEnvelope.ts +4 -4
  148. package/src/chain/validation/payloadAttestationMessage.ts +1 -2
  149. package/src/constants/network.ts +0 -1
  150. package/src/network/peers/peerManager.ts +4 -61
  151. package/src/network/processor/gossipHandlers.ts +12 -3
  152. package/src/network/reqresp/handlers/beaconBlocksByRange.ts +3 -2
  153. package/src/network/reqresp/handlers/blobSidecarsByRange.ts +3 -2
  154. package/src/network/reqresp/handlers/blobSidecarsByRoot.ts +1 -1
  155. package/src/network/reqresp/handlers/dataColumnSidecarsByRange.ts +3 -2
  156. package/src/network/reqresp/handlers/dataColumnSidecarsByRoot.ts +1 -1
  157. package/src/util/clock.ts +9 -4
@@ -1,7 +1,15 @@
1
- import {fulu} from "@lodestar/types";
2
- import {prettyPrintIndices, toRootHex} from "@lodestar/utils";
1
+ import {ForkPostDeneb, isForkPostDeneb} from "@lodestar/params";
2
+ import {SignedBeaconBlock} from "@lodestar/types";
3
+ import {fromHex, toRootHex} from "@lodestar/utils";
4
+ import {getBlobKzgCommitments} from "../../util/dataColumns.js";
3
5
  import {BeaconChain} from "../chain.js";
4
- import {IBlockInput, isBlockInputBlobs, isBlockInputColumns} from "./blockInput/index.js";
6
+ import {
7
+ IBlockInput,
8
+ IDataColumnsInput,
9
+ isBlockInputBlobs,
10
+ isBlockInputColumns,
11
+ isBlockInputNoData,
12
+ } from "./blockInput/index.js";
5
13
  import {BLOB_AVAILABILITY_TIMEOUT} from "./verifyBlocksDataAvailability.js";
6
14
 
7
15
  /**
@@ -10,129 +18,139 @@ import {BLOB_AVAILABILITY_TIMEOUT} from "./verifyBlocksDataAvailability.js";
10
18
  *
11
19
  * This operation may be performed before, during or after importing to the fork-choice. As long as errors
12
20
  * are handled properly for eventual consistency.
21
+ *
22
+ * Block+blobs (pre-fulu) and data columns (fulu+) are written in parallel.
13
23
  */
14
- export async function writeBlockInputToDb(this: BeaconChain, blocksInputs: IBlockInput[]): Promise<void> {
15
- const fnPromises: Promise<void>[] = [];
16
- // track slots for logging
17
- const slots: number[] = [];
18
-
19
- for (const blockInput of blocksInputs) {
20
- const block = blockInput.getBlock();
21
- const slot = block.message.slot;
22
- slots.push(slot);
23
- const blockRoot = this.config.getForkTypes(block.message.slot).BeaconBlock.hashTreeRoot(block.message);
24
- const blockRootHex = toRootHex(blockRoot);
25
- const blockBytes = this.serializedCache.get(block);
26
- if (blockBytes) {
27
- // skip serializing data if we already have it
28
- this.metrics?.importBlock.persistBlockWithSerializedDataCount.inc();
29
- fnPromises.push(this.db.block.putBinary(this.db.block.getId(block), blockBytes));
30
- } else {
31
- this.metrics?.importBlock.persistBlockNoSerializedDataCount.inc();
32
- fnPromises.push(this.db.block.add(block));
33
- }
24
+ export async function writeBlockInputToDb(this: BeaconChain, blockInput: IBlockInput): Promise<void> {
25
+ const promises: Promise<void>[] = [writeBlockAndBlobsToDb.call(this, blockInput)];
34
26
 
35
- this.logger.debug("Persist block to hot DB", {
36
- slot: block.message.slot,
37
- root: blockRootHex,
38
- inputType: blockInput.type,
39
- });
27
+ if (isBlockInputColumns(blockInput)) {
28
+ promises.push(writeDataColumnsToDb.call(this, blockInput));
29
+ }
40
30
 
41
- if (!blockInput.hasAllData()) {
42
- await blockInput.waitForAllData(BLOB_AVAILABILITY_TIMEOUT);
43
- }
31
+ await Promise.all(promises);
32
+ this.logger.debug("Persisted blockInput to db", {slot: blockInput.slot, root: blockInput.blockRootHex});
33
+ }
44
34
 
45
- // NOTE: Old data is pruned on archive
46
- if (isBlockInputColumns(blockInput)) {
47
- if (!blockInput.hasComputedAllData()) {
48
- // Supernodes may only have a subset of the data columns by the time the block begins to be imported
49
- // because full data availability can be assumed after NUMBER_OF_COLUMNS / 2 columns are available.
50
- // Here, however, all data columns must be fully available/reconstructed before persisting to the DB.
51
- await blockInput.waitForComputedAllData(BLOB_AVAILABILITY_TIMEOUT).catch(() => {
52
- this.logger.debug("Failed to wait for computed all data", {slot, blockRoot: blockRootHex});
53
- });
54
- }
35
+ async function writeBlockAndBlobsToDb(this: BeaconChain, blockInput: IBlockInput): Promise<void> {
36
+ const block = blockInput.getBlock();
37
+ const slot = block.message.slot;
38
+ const blockRoot = this.config.getForkTypes(slot).BeaconBlock.hashTreeRoot(block.message);
39
+ const blockRootHex = toRootHex(blockRoot);
40
+ const numBlobs = isForkPostDeneb(blockInput.forkName)
41
+ ? getBlobKzgCommitments(blockInput.forkName, block as SignedBeaconBlock<ForkPostDeneb>).length
42
+ : undefined;
43
+ const fnPromises: Promise<void>[] = [];
55
44
 
56
- const {custodyColumns} = this.custodyConfig;
57
- const blobsLen = (block.message as fulu.BeaconBlock).body.blobKzgCommitments.length;
58
- let dataColumnsLen: number;
59
- if (blobsLen === 0) {
60
- dataColumnsLen = 0;
61
- } else {
62
- dataColumnsLen = custodyColumns.length;
63
- }
45
+ const blockBytes = this.serializedCache.get(block);
46
+ if (blockBytes) {
47
+ // skip serializing data if we already have it
48
+ this.metrics?.importBlock.persistBlockWithSerializedDataCount.inc();
49
+ fnPromises.push(this.db.block.putBinary(this.db.block.getId(block), blockBytes));
50
+ } else {
51
+ this.metrics?.importBlock.persistBlockNoSerializedDataCount.inc();
52
+ fnPromises.push(this.db.block.add(block));
53
+ }
64
54
 
65
- const dataColumnSidecars = blockInput.getCustodyColumns();
66
- if (dataColumnSidecars.length !== dataColumnsLen) {
67
- this.logger.debug(
68
- `Invalid dataColumnSidecars=${dataColumnSidecars.length} for custody expected custodyColumnsLen=${dataColumnsLen}`
69
- );
70
- }
55
+ this.logger.debug("Persist block to hot DB", {slot, root: blockRootHex, inputType: blockInput.type, numBlobs});
71
56
 
72
- const binaryPuts = [];
73
- const nonbinaryPuts = [];
74
- for (const dataColumnSidecar of dataColumnSidecars) {
75
- // skip reserializing column if we already have it
76
- const serialized = this.serializedCache.get(dataColumnSidecar);
77
- if (serialized) {
78
- binaryPuts.push({key: dataColumnSidecar.index, value: serialized});
79
- } else {
80
- nonbinaryPuts.push(dataColumnSidecar);
57
+ if (isBlockInputBlobs(blockInput)) {
58
+ fnPromises.push(
59
+ (async () => {
60
+ if (!blockInput.hasAllData()) {
61
+ await blockInput.waitForAllData(BLOB_AVAILABILITY_TIMEOUT);
81
62
  }
82
- }
83
- fnPromises.push(this.db.dataColumnSidecar.putManyBinary(blockRoot, binaryPuts));
84
- fnPromises.push(this.db.dataColumnSidecar.putMany(blockRoot, nonbinaryPuts));
85
- this.logger.debug("Persisted dataColumnSidecars to hot DB", {
86
- slot: block.message.slot,
87
- root: blockRootHex,
88
- dataColumnSidecars: dataColumnSidecars.length,
89
- numBlobs: blobsLen,
90
- custodyColumns: custodyColumns.length,
91
- });
92
- } else if (isBlockInputBlobs(blockInput)) {
93
- const blobSidecars = blockInput.getBlobs();
94
- fnPromises.push(this.db.blobSidecars.add({blockRoot, slot: block.message.slot, blobSidecars}));
95
- this.logger.debug("Persisted blobSidecars to hot DB", {
96
- blobsLen: blobSidecars.length,
97
- slot: block.message.slot,
98
- root: blockRootHex,
99
- });
100
- }
63
+ const blobSidecars = blockInput.getBlobs();
64
+ await this.db.blobSidecars.add({blockRoot, slot, blobSidecars});
65
+ this.logger.debug("Persisted blobSidecars to hot DB", {
66
+ slot,
67
+ root: blockRootHex,
68
+ numBlobs: blobSidecars.length,
69
+ });
70
+ })()
71
+ );
72
+ }
101
73
 
102
- await Promise.all(fnPromises);
103
- this.logger.debug("Persisted blocksInput to db", {
104
- blocksInput: blocksInputs.length,
105
- slots: prettyPrintIndices(slots),
74
+ await Promise.all(fnPromises);
75
+ }
76
+
77
+ /**
78
+ * Persists data columns to DB for a given block. Accepts a narrow sub-interface of IBlockInput
79
+ * so it can be reused across forks (e.g. Fulu, Gloas).
80
+ *
81
+ * NOTE: Old data is pruned on archive.
82
+ */
83
+ export async function writeDataColumnsToDb(this: BeaconChain, blockInput: IDataColumnsInput): Promise<void> {
84
+ const {slot, blockRootHex} = blockInput;
85
+ const blockRoot = fromHex(blockRootHex);
86
+
87
+ if (!blockInput.hasComputedAllData()) {
88
+ // Supernodes may only have a subset of the data columns by the time the block begins to be imported
89
+ // because full data availability can be assumed after NUMBER_OF_COLUMNS / 2 columns are available.
90
+ // Here, however, all data columns must be fully available/reconstructed before persisting to the DB.
91
+ await blockInput.waitForComputedAllData(BLOB_AVAILABILITY_TIMEOUT).catch(() => {
92
+ this.logger.debug("Failed to wait for computed all data", {slot, blockRoot: blockRootHex});
106
93
  });
107
94
  }
95
+
96
+ const {custodyColumns} = this.custodyConfig;
97
+ const dataColumnSidecars = blockInput.getCustodyColumns();
98
+
99
+ const binaryPuts: {key: number; value: Uint8Array}[] = [];
100
+ const nonbinaryPuts = [];
101
+ for (const dataColumnSidecar of dataColumnSidecars) {
102
+ // skip reserializing column if we already have it
103
+ const serialized = this.serializedCache.get(dataColumnSidecar);
104
+ if (serialized) {
105
+ binaryPuts.push({key: dataColumnSidecar.index, value: serialized});
106
+ } else {
107
+ nonbinaryPuts.push(dataColumnSidecar);
108
+ }
109
+ }
110
+
111
+ await Promise.all([
112
+ this.db.dataColumnSidecar.putManyBinary(blockRoot, binaryPuts),
113
+ this.db.dataColumnSidecar.putMany(blockRoot, nonbinaryPuts),
114
+ ]);
115
+
116
+ this.logger.debug("Persisted dataColumnSidecars to hot DB", {
117
+ slot,
118
+ root: blockRootHex,
119
+ dataColumnSidecars: dataColumnSidecars.length,
120
+ custodyColumns: custodyColumns.length,
121
+ numBlobs: dataColumnSidecars[0]?.column.length,
122
+ });
108
123
  }
109
124
 
110
- export async function persistBlockInputs(this: BeaconChain, blockInputs: IBlockInput[]): Promise<void> {
125
+ export async function persistBlockInput(this: BeaconChain, blockInput: IBlockInput): Promise<void> {
111
126
  await writeBlockInputToDb
112
- .call(this, blockInputs)
127
+ .call(this, blockInput)
113
128
  .catch((e) => {
114
129
  this.logger.debug(
115
130
  "Error persisting block input in hot db",
116
131
  {
117
- count: blockInputs.length,
118
- slot: blockInputs[0].slot,
119
- root: blockInputs[0].blockRootHex,
132
+ slot: blockInput.slot,
133
+ root: blockInput.blockRootHex,
120
134
  },
121
135
  e
122
136
  );
123
137
  })
124
138
  .finally(() => {
125
- for (const blockInput of blockInputs) {
126
- this.seenBlockInputCache.prune(blockInput.blockRootHex);
127
- }
139
+ this.seenBlockInputCache.prune(blockInput.blockRootHex);
128
140
  // Without forcefully clearing this cache, we would rely on WeakMap to evict memory which is not reliable.
129
141
  // Clear here (after the DB write) so that writeBlockInputToDb can still use the cached serialized bytes.
130
- this.serializedCache.clear();
131
- if (blockInputs.length === 1) {
132
- this.logger.debug("Pruned block input", {
133
- slot: blockInputs[0].slot,
134
- root: blockInputs[0].blockRootHex,
135
- });
142
+ //
143
+ // For Gloas (BlockInputNoData), the execution payload and columns arrive separately after the beacon block.
144
+ // Do NOT clear the cache here — it must remain available for writeDataColumnsToDb when the payload arrives.
145
+ // The cache is cleared in the Gloas payload persistence path instead.
146
+ if (!isBlockInputNoData(blockInput)) {
147
+ // TODO: enhance this SerializedCache for Gloas because payload may not come
148
+ // see https://github.com/ChainSafe/lodestar/pull/8974#discussion_r2885598229
149
+ this.serializedCache.clear();
136
150
  }
151
+ this.logger.debug("Pruned block input", {
152
+ slot: blockInput.slot,
153
+ root: blockInput.blockRootHex,
154
+ });
137
155
  });
138
156
  }
@@ -2,7 +2,13 @@ import path from "node:path";
2
2
  import {PrivateKey} from "@libp2p/interface";
3
3
  import {CompositeTypeAny, TreeView, Type} from "@chainsafe/ssz";
4
4
  import {BeaconConfig} from "@lodestar/config";
5
- import {CheckpointWithHex, IForkChoice, ProtoBlock, UpdateHeadOpt} from "@lodestar/fork-choice";
5
+ import {
6
+ CheckpointWithHex,
7
+ CheckpointWithPayloadStatus,
8
+ IForkChoice,
9
+ ProtoBlock,
10
+ UpdateHeadOpt,
11
+ } from "@lodestar/fork-choice";
6
12
  import {LoggerNode} from "@lodestar/logger/node";
7
13
  import {
8
14
  BUILDER_INDEX_SELF_BUILD,
@@ -77,7 +83,7 @@ import {CheckpointBalancesCache} from "./balancesCache.js";
77
83
  import {BeaconProposerCache} from "./beaconProposerCache.js";
78
84
  import {IBlockInput, isBlockInputBlobs, isBlockInputColumns} from "./blocks/blockInput/index.js";
79
85
  import {BlockProcessor, ImportBlockOpts} from "./blocks/index.js";
80
- import {persistBlockInputs} from "./blocks/writeBlockInputToDb.ts";
86
+ import {persistBlockInput} from "./blocks/writeBlockInputToDb.ts";
81
87
  import {BlsMultiThreadWorkerPool, BlsSingleThreadVerifier, IBlsVerifier} from "./bls/index.js";
82
88
  import {ColumnReconstructionTracker} from "./ColumnReconstructionTracker.js";
83
89
  import {ChainEvent, ChainEventEmitter} from "./emitter.js";
@@ -164,7 +170,7 @@ export class BeaconChain implements IBeaconChain {
164
170
  readonly lightClientServer?: LightClientServer;
165
171
  readonly reprocessController: ReprocessController;
166
172
  readonly archiveStore: ArchiveStore;
167
- readonly unfinalizedBlockWrites: JobItemQueue<[IBlockInput[]], void>;
173
+ readonly unfinalizedBlockWrites: JobItemQueue<[IBlockInput], void>;
168
174
 
169
175
  // Ops pool
170
176
  readonly attestationPool: AttestationPool;
@@ -429,7 +435,7 @@ export class BeaconChain implements IBeaconChain {
429
435
  );
430
436
 
431
437
  this.unfinalizedBlockWrites = new JobItemQueue(
432
- persistBlockInputs.bind(this),
438
+ persistBlockInput.bind(this),
433
439
  {
434
440
  maxLength: DEFAULT_MAX_PENDING_UNFINALIZED_BLOCK_WRITES,
435
441
  signal,
@@ -600,7 +606,7 @@ export class BeaconChain implements IBeaconChain {
600
606
  ): Promise<{state: CachedBeaconStateAllForks | Uint8Array; executionOptimistic: boolean; finalized: boolean} | null> {
601
607
  if (opts?.allowRegen) {
602
608
  const state = await this.regen.getState(stateRoot, RegenCaller.restApi);
603
- const block = this.forkChoice.getBlock(state.latestBlockHeader.hashTreeRoot());
609
+ const block = this.forkChoice.getBlockDefaultStatus(state.latestBlockHeader.hashTreeRoot());
604
610
  const finalizedEpoch = this.forkChoice.getFinalizedCheckpoint().epoch;
605
611
  return {
606
612
  state,
@@ -616,7 +622,7 @@ export class BeaconChain implements IBeaconChain {
616
622
  // TODO: This is very inneficient for debug requests of serialized content, since it deserializes to serialize again
617
623
  const cachedStateCtx = this.regen.getStateSync(stateRoot);
618
624
  if (cachedStateCtx) {
619
- const block = this.forkChoice.getBlock(cachedStateCtx.latestBlockHeader.hashTreeRoot());
625
+ const block = this.forkChoice.getBlockDefaultStatus(cachedStateCtx.latestBlockHeader.hashTreeRoot());
620
626
  const finalizedEpoch = this.forkChoice.getFinalizedCheckpoint().epoch;
621
627
  return {
622
628
  state: cachedStateCtx,
@@ -650,7 +656,7 @@ export class BeaconChain implements IBeaconChain {
650
656
  // finalized or justified checkpoint states maynot be available with PersistentCheckpointStateCache, use getCheckpointStateOrBytes() api to get Uint8Array
651
657
  const cachedStateCtx = this.regen.getCheckpointStateSync(checkpoint);
652
658
  if (cachedStateCtx) {
653
- const block = this.forkChoice.getBlock(cachedStateCtx.latestBlockHeader.hashTreeRoot());
659
+ const block = this.forkChoice.getBlockDefaultStatus(cachedStateCtx.latestBlockHeader.hashTreeRoot());
654
660
  const finalizedEpoch = this.forkChoice.getFinalizedCheckpoint().epoch;
655
661
  return {
656
662
  state: cachedStateCtx,
@@ -667,7 +673,7 @@ export class BeaconChain implements IBeaconChain {
667
673
  ): Promise<{state: CachedBeaconStateAllForks | Uint8Array; executionOptimistic: boolean; finalized: boolean} | null> {
668
674
  const cachedStateCtx = await this.regen.getCheckpointStateOrBytes(checkpoint);
669
675
  if (cachedStateCtx) {
670
- const block = this.forkChoice.getBlock(checkpoint.root);
676
+ const block = this.forkChoice.getBlockDefaultStatus(checkpoint.root);
671
677
  const finalizedEpoch = this.forkChoice.getFinalizedCheckpoint().epoch;
672
678
  return {
673
679
  state: cachedStateCtx,
@@ -711,7 +717,7 @@ export class BeaconChain implements IBeaconChain {
711
717
  async getBlockByRoot(
712
718
  root: string
713
719
  ): Promise<{block: SignedBeaconBlock; executionOptimistic: boolean; finalized: boolean} | null> {
714
- const block = this.forkChoice.getBlockHex(root);
720
+ const block = this.forkChoice.getBlockHexDefaultStatus(root);
715
721
  if (block) {
716
722
  // Block found in fork-choice.
717
723
  // It may be in the block input cache, awaiting full DA reconstruction, check there first
@@ -735,7 +741,7 @@ export class BeaconChain implements IBeaconChain {
735
741
  async getSerializedBlockByRoot(
736
742
  root: string
737
743
  ): Promise<{block: Uint8Array; executionOptimistic: boolean; finalized: boolean; slot: Slot} | null> {
738
- const block = this.forkChoice.getBlockHex(root);
744
+ const block = this.forkChoice.getBlockHexDefaultStatus(root);
739
745
  if (block) {
740
746
  // Block found in fork-choice.
741
747
  // It may be in the block input cache, awaiting full DA reconstruction, check there first
@@ -1186,7 +1192,7 @@ export class BeaconChain implements IBeaconChain {
1186
1192
  * @param blockState state that declares justified checkpoint `checkpoint`
1187
1193
  */
1188
1194
  private justifiedBalancesGetter(
1189
- checkpoint: CheckpointWithHex,
1195
+ checkpoint: CheckpointWithPayloadStatus,
1190
1196
  blockState: CachedBeaconStateAllForks
1191
1197
  ): EffectiveBalanceIncrements {
1192
1198
  this.metrics?.balancesCache.requests.inc();
@@ -1225,7 +1231,7 @@ export class BeaconChain implements IBeaconChain {
1225
1231
  * @param blockState state that declares justified checkpoint `checkpoint`
1226
1232
  */
1227
1233
  private closestJustifiedBalancesStateToCheckpoint(
1228
- checkpoint: CheckpointWithHex,
1234
+ checkpoint: CheckpointWithPayloadStatus,
1229
1235
  blockState: CachedBeaconStateAllForks
1230
1236
  ): {state: CachedBeaconStateAllForks; stateId: string; shouldWarn: boolean} {
1231
1237
  const state = this.regen.getCheckpointStateSync(checkpoint);
@@ -1239,7 +1245,10 @@ export class BeaconChain implements IBeaconChain {
1239
1245
  }
1240
1246
 
1241
1247
  // Find a state in the same branch of checkpoint at same epoch. Balances should exactly the same
1242
- for (const descendantBlock of this.forkChoice.forwardIterateDescendants(checkpoint.rootHex)) {
1248
+ for (const descendantBlock of this.forkChoice.forwardIterateDescendants(
1249
+ checkpoint.rootHex,
1250
+ checkpoint.payloadStatus
1251
+ )) {
1243
1252
  if (computeEpochAtSlot(descendantBlock.slot) === checkpoint.epoch) {
1244
1253
  const descendantBlockState = this.regen.getStateSync(descendantBlock.stateRoot);
1245
1254
  if (descendantBlockState) {
@@ -1255,7 +1264,10 @@ export class BeaconChain implements IBeaconChain {
1255
1264
 
1256
1265
  // Find a state in the same branch of checkpoint at a latter epoch. Balances are not the same, but should be close
1257
1266
  // Note: must call .forwardIterateDescendants() again since nodes are not sorted
1258
- for (const descendantBlock of this.forkChoice.forwardIterateDescendants(checkpoint.rootHex)) {
1267
+ for (const descendantBlock of this.forkChoice.forwardIterateDescendants(
1268
+ checkpoint.rootHex,
1269
+ checkpoint.payloadStatus
1270
+ )) {
1259
1271
  if (computeEpochAtSlot(descendantBlock.slot) > checkpoint.epoch) {
1260
1272
  const descendantBlockState = this.regen.getStateSync(descendantBlock.stateRoot);
1261
1273
  if (descendantBlockState) {
@@ -1,7 +1,7 @@
1
1
  import {EventEmitter} from "node:events";
2
2
  import {StrictEventEmitter} from "strict-event-emitter-types";
3
3
  import {routes} from "@lodestar/api";
4
- import {CheckpointWithHex} from "@lodestar/fork-choice";
4
+ import {CheckpointWithPayloadStatus} from "@lodestar/fork-choice";
5
5
  import {CachedBeaconStateAllForks} from "@lodestar/state-transition";
6
6
  import {DataColumnSidecars, RootHex, deneb, phase0} from "@lodestar/types";
7
7
  import {PeerIdStr} from "../util/peerId.js";
@@ -83,8 +83,8 @@ export type ChainEventData = {
83
83
  export type IChainEvents = ApiEvents & {
84
84
  [ChainEvent.checkpoint]: (checkpoint: phase0.Checkpoint, state: CachedBeaconStateAllForks) => void;
85
85
 
86
- [ChainEvent.forkChoiceJustified]: (checkpoint: CheckpointWithHex) => void;
87
- [ChainEvent.forkChoiceFinalized]: (checkpoint: CheckpointWithHex) => void;
86
+ [ChainEvent.forkChoiceJustified]: (checkpoint: CheckpointWithPayloadStatus) => void;
87
+ [ChainEvent.forkChoiceFinalized]: (checkpoint: CheckpointWithPayloadStatus) => void;
88
88
 
89
89
  [ChainEvent.updateTargetCustodyGroupCount]: (targetGroupCount: number) => void;
90
90
 
@@ -25,9 +25,13 @@ export type ExecutionPayloadEnvelopeErrorType =
25
25
  | {
26
26
  code: ExecutionPayloadEnvelopeErrorCode.BUILDER_INDEX_MISMATCH;
27
27
  envelopeBuilderIndex: BuilderIndex;
28
- bidBuilderIndex: BuilderIndex;
28
+ bidBuilderIndex: BuilderIndex | null;
29
+ }
30
+ | {
31
+ code: ExecutionPayloadEnvelopeErrorCode.BLOCK_HASH_MISMATCH;
32
+ envelopeBlockHash: RootHex;
33
+ bidBlockHash: RootHex | null;
29
34
  }
30
- | {code: ExecutionPayloadEnvelopeErrorCode.BLOCK_HASH_MISMATCH; envelopeBlockHash: RootHex; bidBlockHash: RootHex}
31
35
  | {code: ExecutionPayloadEnvelopeErrorCode.INVALID_SIGNATURE}
32
36
  | {code: ExecutionPayloadEnvelopeErrorCode.CACHE_FAIL; blockRoot: RootHex};
33
37
 
@@ -4,9 +4,11 @@ import {
4
4
  ForkChoice,
5
5
  ForkChoiceStore,
6
6
  JustifiedBalancesGetter,
7
+ PayloadStatus,
7
8
  ProtoArray,
8
9
  ProtoBlock,
9
10
  ForkChoiceOpts as RawForkChoiceOpts,
11
+ getCheckpointPayloadStatus,
10
12
  } from "@lodestar/fork-choice";
11
13
  import {ZERO_HASH_HEX} from "@lodestar/params";
12
14
  import {
@@ -104,6 +106,14 @@ export function initializeForkChoiceFromFinalizedState(
104
106
  // production code use ForkChoice constructor directly
105
107
  const forkchoiceConstructor = opts.forkchoiceConstructor ?? ForkChoice;
106
108
 
109
+ const isForkPostGloas = (state as CachedBeaconStateGloas).latestBlockHash !== undefined;
110
+
111
+ // Determine justified checkpoint payload status
112
+ const justifiedPayloadStatus = getCheckpointPayloadStatus(state, justifiedCheckpoint.epoch);
113
+
114
+ // Determine finalized checkpoint payload status
115
+ const finalizedPayloadStatus = getCheckpointPayloadStatus(state, finalizedCheckpoint.epoch);
116
+
107
117
  return new forkchoiceConstructor(
108
118
  config,
109
119
 
@@ -113,6 +123,8 @@ export function initializeForkChoiceFromFinalizedState(
113
123
  finalizedCheckpoint,
114
124
  justifiedBalances,
115
125
  justifiedBalancesGetter,
126
+ justifiedPayloadStatus,
127
+ finalizedPayloadStatus,
116
128
  {
117
129
  onJustified: (cp) => emitter.emit(ChainEvent.forkChoiceJustified, cp),
118
130
  onFinalized: (cp) => emitter.emit(ChainEvent.forkChoiceFinalized, cp),
@@ -145,15 +157,12 @@ export function initializeForkChoiceFromFinalizedState(
145
157
  : {executionPayloadBlockHash: null, executionStatus: ExecutionStatus.PreMerge}),
146
158
 
147
159
  dataAvailabilityStatus: DataAvailabilityStatus.PreData,
148
- ...(computeEpochAtSlot(blockHeader.slot) < state.config.GLOAS_FORK_EPOCH
149
- ? {
150
- builderIndex: undefined,
151
- blockHashHex: undefined,
152
- }
153
- : {
154
- builderIndex: (state as CachedBeaconStateGloas).latestExecutionPayloadBid.builderIndex,
155
- blockHashHex: toRootHex((state as CachedBeaconStateGloas).latestExecutionPayloadBid.blockHash),
156
- }),
160
+ payloadStatus: isForkPostGloas ? PayloadStatus.PENDING : PayloadStatus.FULL, // TODO GLOAS: Post-gloas how do we know if the checkpoint payload is FULL or EMPTY?
161
+ builderIndex: isForkPostGloas ? (state as CachedBeaconStateGloas).latestExecutionPayloadBid.builderIndex : null,
162
+ blockHashFromBid: isForkPostGloas
163
+ ? toRootHex((state as CachedBeaconStateGloas).latestExecutionPayloadBid.blockHash)
164
+ : null,
165
+ parentBlockHash: isForkPostGloas ? toRootHex((state as CachedBeaconStateGloas).latestBlockHash) : null,
157
166
  },
158
167
  currentSlot
159
168
  ),
@@ -196,12 +205,22 @@ export function initializeForkChoiceFromUnfinalizedState(
196
205
 
197
206
  // this is not the justified state, but there is no other ways to get justified balances
198
207
  const justifiedBalances = getEffectiveBalanceIncrementsZeroInactive(unfinalizedState);
208
+
209
+ const isForkPostGloas = (unfinalizedState as CachedBeaconStateGloas).latestBlockHash !== undefined;
210
+
211
+ // For unfinalized state, use getCheckpointPayloadStatus to determine the correct status.
212
+ // It checks state.execution_payload_availability to determine EMPTY vs FULL.
213
+ const justifiedPayloadStatus = getCheckpointPayloadStatus(unfinalizedState, justifiedCheckpoint.epoch);
214
+ const finalizedPayloadStatus = getCheckpointPayloadStatus(unfinalizedState, finalizedCheckpoint.epoch);
215
+
199
216
  const store = new ForkChoiceStore(
200
217
  currentSlot,
201
218
  justifiedCheckpoint,
202
219
  finalizedCheckpoint,
203
220
  justifiedBalances,
204
221
  justifiedBalancesGetter,
222
+ justifiedPayloadStatus,
223
+ finalizedPayloadStatus,
205
224
  {
206
225
  onJustified: (cp) => emitter.emit(ChainEvent.forkChoiceJustified, cp),
207
226
  onFinalized: (cp) => emitter.emit(ChainEvent.forkChoiceFinalized, cp),
@@ -235,15 +254,14 @@ export function initializeForkChoiceFromUnfinalizedState(
235
254
  : {executionPayloadBlockHash: null, executionStatus: ExecutionStatus.PreMerge}),
236
255
 
237
256
  dataAvailabilityStatus: DataAvailabilityStatus.PreData,
238
- ...(computeEpochAtSlot(blockHeader.slot) < unfinalizedState.config.GLOAS_FORK_EPOCH
239
- ? {
240
- builderIndex: undefined,
241
- blockHashHex: undefined,
242
- }
243
- : {
244
- builderIndex: (unfinalizedState as CachedBeaconStateGloas).latestExecutionPayloadBid.builderIndex,
245
- blockHashHex: toRootHex((unfinalizedState as CachedBeaconStateGloas).latestExecutionPayloadBid.blockHash),
246
- }),
257
+ payloadStatus: isForkPostGloas ? PayloadStatus.PENDING : PayloadStatus.FULL, // TODO GLOAS: Post-gloas how do we know if the checkpoint payload is FULL or EMPTY?
258
+ builderIndex: isForkPostGloas
259
+ ? (unfinalizedState as CachedBeaconStateGloas).latestExecutionPayloadBid.builderIndex
260
+ : null,
261
+ blockHashFromBid: isForkPostGloas
262
+ ? toRootHex((unfinalizedState as CachedBeaconStateGloas).latestExecutionPayloadBid.blockHash)
263
+ : null,
264
+ parentBlockHash: isForkPostGloas ? toRootHex((unfinalizedState as CachedBeaconStateGloas).latestBlockHash) : null,
247
265
  };
248
266
 
249
267
  const parentSlot = blockHeader.slot - 1;
@@ -285,9 +303,9 @@ export function initializeForkChoiceFromUnfinalizedState(
285
303
  };
286
304
 
287
305
  const protoArray = ProtoArray.initialize(finalizedBlock, currentSlot);
288
- protoArray.onBlock(justifiedBlock, currentSlot);
289
- protoArray.onBlock(parentBlock, currentSlot);
290
- protoArray.onBlock(headBlock, currentSlot);
306
+ protoArray.onBlock(justifiedBlock, currentSlot, null);
307
+ protoArray.onBlock(parentBlock, currentSlot, null);
308
+ protoArray.onBlock(headBlock, currentSlot, null);
291
309
 
292
310
  logger?.verbose("Initialized protoArray successfully", {...logCtx, length: protoArray.length()});
293
311
 
@@ -864,7 +864,7 @@ function isValidShuffling(
864
864
  // attestation's shuffling is the same as the current state's.
865
865
  // To account for skipped slots, find the first block at *or before* the pivot slot.
866
866
  const beaconBlockRootHex = blockRootHex;
867
- const beaconBlock = forkChoice.getBlockHex(beaconBlockRootHex);
867
+ const beaconBlock = forkChoice.getBlockHexDefaultStatus(beaconBlockRootHex);
868
868
  if (!beaconBlock) {
869
869
  return InvalidAttestationData.BlockNotInForkChoice;
870
870
  }
@@ -723,8 +723,7 @@ export function getPayloadAttributesForSSE(
723
723
 
724
724
  let parentBlockNumber: number;
725
725
  if (isForkPostGloas(fork)) {
726
- // TODO GLOAS: revisit this after fork choice changes are merged
727
- const parentBlock = chain.forkChoice.getBlock(parentBlockRoot);
726
+ const parentBlock = chain.forkChoice.getBlockHexAndBlockHash(toRootHex(parentBlockRoot), toRootHex(parentHash));
728
727
  if (parentBlock?.executionPayloadBlockHash == null) {
729
728
  throw Error(`Parent block not found in fork choice root=${toRootHex(parentBlockRoot)}`);
730
729
  }
@@ -1,7 +1,7 @@
1
1
  import {routes} from "@lodestar/api";
2
2
  import {IForkChoice, ProtoBlock} from "@lodestar/fork-choice";
3
3
  import {CachedBeaconStateAllForks, computeEpochAtSlot} from "@lodestar/state-transition";
4
- import {BeaconBlock, Epoch, RootHex, Slot, phase0} from "@lodestar/types";
4
+ import {BeaconBlock, Epoch, RootHex, Slot, isGloasBeaconBlock, phase0} from "@lodestar/types";
5
5
  import {Logger, toRootHex} from "@lodestar/utils";
6
6
  import {Metrics} from "../../metrics/index.js";
7
7
  import {JobItemQueue} from "../../util/queue/index.js";
@@ -88,7 +88,12 @@ export class QueuedStateRegenerator implements IStateRegenerator {
88
88
  */
89
89
  getPreStateSync(block: BeaconBlock): CachedBeaconStateAllForks | null {
90
90
  const parentRoot = toRootHex(block.parentRoot);
91
- const parentBlock = this.forkChoice.getBlockHex(parentRoot);
91
+ const parentBlock = isGloasBeaconBlock(block)
92
+ ? this.forkChoice.getBlockHexAndBlockHash(
93
+ parentRoot,
94
+ toRootHex(block.body.signedExecutionPayloadBid.message.parentBlockHash)
95
+ )
96
+ : this.forkChoice.getBlockHexDefaultStatus(parentRoot);
92
97
  if (!parentBlock) {
93
98
  throw new RegenError({
94
99
  code: RegenErrorCode.BLOCK_NOT_IN_FORKCHOICE,
@@ -11,7 +11,7 @@ import {
11
11
  processSlots,
12
12
  stateTransition,
13
13
  } from "@lodestar/state-transition";
14
- import {BeaconBlock, RootHex, SignedBeaconBlock, Slot} from "@lodestar/types";
14
+ import {BeaconBlock, RootHex, SignedBeaconBlock, Slot, isGloasBeaconBlock} from "@lodestar/types";
15
15
  import {Logger, fromHex, toRootHex} from "@lodestar/utils";
16
16
  import {IBeaconDb} from "../../db/index.js";
17
17
  import {Metrics} from "../../metrics/index.js";
@@ -58,7 +58,13 @@ export class StateRegenerator implements IStateRegeneratorInternal {
58
58
  opts: StateRegenerationOpts,
59
59
  regenCaller: RegenCaller
60
60
  ): Promise<CachedBeaconStateAllForks> {
61
- const parentBlock = this.modules.forkChoice.getBlock(block.parentRoot);
61
+ const parentRoot = toRootHex(block.parentRoot);
62
+ const parentBlock = isGloasBeaconBlock(block)
63
+ ? this.modules.forkChoice.getBlockHexAndBlockHash(
64
+ parentRoot,
65
+ toRootHex(block.body.signedExecutionPayloadBid.message.parentBlockHash)
66
+ )
67
+ : this.modules.forkChoice.getBlockHexDefaultStatus(parentRoot);
62
68
  if (!parentBlock) {
63
69
  throw new RegenError({
64
70
  code: RegenErrorCode.BLOCK_NOT_IN_FORKCHOICE,
@@ -152,7 +158,7 @@ export class StateRegenerator implements IStateRegeneratorInternal {
152
158
 
153
159
  const getSeedStateTimer = this.modules.metrics?.regenGetState.getSeedState.startTimer({caller});
154
160
  // iterateAncestorBlocks only returns ancestor blocks, not the block itself
155
- for (const b of this.modules.forkChoice.iterateAncestorBlocks(block.blockRoot)) {
161
+ for (const b of this.modules.forkChoice.iterateAncestorBlocks(block.blockRoot, block.payloadStatus)) {
156
162
  state = this.modules.blockStateCache.get(b.stateRoot);
157
163
  if (state) {
158
164
  break;