@aztec/validator-client 0.0.1-commit.5914bae → 0.0.1-commit.59a0419c6

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.
@@ -1,3 +1,4 @@
1
+ import type { Archiver } from '@aztec/archiver';
1
2
  import type { BlobClientInterface } from '@aztec/blob-client/client';
2
3
  import { type Blob, encodeCheckpointBlobDataFromBlocks, getBlobsPerL1Block } from '@aztec/blob-lib';
3
4
  import { INITIAL_L2_BLOCK_NUM } from '@aztec/constants';
@@ -23,7 +24,7 @@ import {
23
24
  accumulateCheckpointOutHashes,
24
25
  computeInHashFromL1ToL2Messages,
25
26
  } from '@aztec/stdlib/messaging';
26
- import type { BlockProposal, CheckpointProposalCore } from '@aztec/stdlib/p2p';
27
+ import type { BlockProposal, CheckpointAttestation, CheckpointProposalCore } from '@aztec/stdlib/p2p';
27
28
  import { MerkleTreeId } from '@aztec/stdlib/trees';
28
29
  import type { CheckpointGlobalVariables, FailedTx, Tx } from '@aztec/stdlib/tx';
29
30
  import {
@@ -75,7 +76,9 @@ export type BlockProposalValidationFailureResult = {
75
76
 
76
77
  export type BlockProposalValidationResult = BlockProposalValidationSuccessResult | BlockProposalValidationFailureResult;
77
78
 
78
- export type CheckpointProposalValidationResult = { isValid: true } | { isValid: false; reason: string };
79
+ export type CheckpointProposalValidationResult =
80
+ | { isValid: true; checkpointNumber: CheckpointNumber }
81
+ | { isValid: false; reason: string };
79
82
 
80
83
  type CheckpointComputationResult =
81
84
  | { checkpointNumber: CheckpointNumber; reason?: undefined }
@@ -85,6 +88,19 @@ type CheckpointComputationResult =
85
88
  export class ProposalHandler {
86
89
  public readonly tracer: Tracer;
87
90
 
91
+ /** Cached last checkpoint validation result to avoid double-validation on validator nodes. */
92
+ private lastCheckpointValidationResult?: {
93
+ archive: Fr;
94
+ slotNumber: SlotNumber;
95
+ result: CheckpointProposalValidationResult;
96
+ };
97
+
98
+ /** Archiver reference for setting proposed checkpoints (pipelining). Set via register(). */
99
+ private archiver?: Pick<Archiver, 'setProposedCheckpoint' | 'getL1Constants'>;
100
+
101
+ /** Returns current validator addresses for own-proposal detection. Set via register(). */
102
+ private getOwnValidatorAddresses?: () => string[];
103
+
88
104
  constructor(
89
105
  private checkpointsBuilder: FullNodeCheckpointsBuilder,
90
106
  private worldState: WorldStateSynchronizer,
@@ -107,10 +123,21 @@ export class ProposalHandler {
107
123
  }
108
124
 
109
125
  /**
110
- * Registers non-validator handlers for block and checkpoint proposals on the p2p client.
111
- * Block proposals are always registered. Checkpoint proposals are registered if the blob client can upload.
126
+ * Registers handlers for block and checkpoint proposals on the p2p client.
127
+ * Block proposals are registered for non-validator nodes (validators register their own enhanced handler).
128
+ * The all-nodes checkpoint proposal handler is always registered for validation, caching, and pipelining.
129
+ * @param archiver - Archiver reference for setting proposed checkpoints (pipelining)
130
+ * @param getOwnValidatorAddresses - Returns current validator addresses for own-proposal detection
112
131
  */
113
- register(p2pClient: P2P, shouldReexecute: boolean): ProposalHandler {
132
+ register(
133
+ p2pClient: P2P,
134
+ shouldReexecute: boolean,
135
+ archiver?: Pick<Archiver, 'setProposedCheckpoint' | 'getL1Constants'>,
136
+ getOwnValidatorAddresses?: () => string[],
137
+ ): ProposalHandler {
138
+ this.archiver = archiver;
139
+ this.getOwnValidatorAddresses = getOwnValidatorAddresses;
140
+
114
141
  // Non-validator handler that processes or re-executes for monitoring but does not attest.
115
142
  // Returns boolean indicating whether the proposal was valid.
116
143
  const blockHandler = async (proposal: BlockProposal, proposalSender: PeerId): Promise<boolean> => {
@@ -142,32 +169,48 @@ export class ProposalHandler {
142
169
 
143
170
  p2pClient.registerBlockProposalHandler(blockHandler);
144
171
 
145
- // Register checkpoint proposal handler if blob uploads are enabled and we are reexecuting
146
- if (this.blobClient.canUpload() && shouldReexecute) {
147
- const checkpointHandler = async (checkpoint: CheckpointProposalCore, _sender: PeerId) => {
148
- try {
149
- const proposalInfo = {
150
- proposalSlotNumber: checkpoint.slotNumber,
151
- archive: checkpoint.archive.toString(),
152
- proposer: checkpoint.getSender()?.toString(),
153
- };
154
- const result = await this.handleCheckpointProposal(checkpoint, proposalInfo);
155
- if (result.isValid) {
156
- this.log.info(`Non-validator checkpoint proposal at slot ${checkpoint.slotNumber} handled`, proposalInfo);
157
- } else {
158
- this.log.warn(
159
- `Non-validator checkpoint proposal at slot ${checkpoint.slotNumber} failed: ${result.reason}`,
160
- proposalInfo,
161
- );
172
+ // All-nodes checkpoint proposal handler: validates, caches, and sets proposed checkpoint for pipelining.
173
+ // Runs for all nodes (validators and non-validators). Validators get the cached result in the
174
+ // validator-specific callback (attestToCheckpointProposal) which runs after this one.
175
+ const checkpointHandler = async (
176
+ proposal: CheckpointProposalCore,
177
+ _sender: PeerId,
178
+ ): Promise<CheckpointAttestation[] | undefined> => {
179
+ try {
180
+ const pipeliningTimer = new Timer();
181
+ const proposalInfo: LogData = {
182
+ slot: proposal.slotNumber,
183
+ archive: proposal.archive.toString(),
184
+ proposer: proposal.getSender()?.toString(),
185
+ };
186
+
187
+ // For own proposals, skip validation — the proposer already built and validated the checkpoint
188
+ const proposer = proposal.getSender();
189
+ const ownAddresses = this.getOwnValidatorAddresses?.();
190
+ const isOwnProposal = proposer && ownAddresses?.some(addr => addr === proposer.toString());
191
+
192
+ if (isOwnProposal) {
193
+ this.log.debug(`Skipping validation for own checkpoint proposal at slot ${proposal.slotNumber}`);
194
+ if (this.archiver && this.epochCache.isProposerPipeliningEnabled()) {
195
+ await this.setProposedCheckpointFromBlocks(proposal);
162
196
  }
163
- } catch (error) {
164
- this.log.error('Error processing checkpoint proposal in non-validator handler', error);
197
+ return undefined;
165
198
  }
166
- // Non-validators don't attest
167
- return undefined;
168
- };
169
- p2pClient.registerCheckpointProposalHandler(checkpointHandler);
170
- }
199
+
200
+ const result = await this.handleCheckpointProposal(proposal, proposalInfo);
201
+ if (result.isValid && this.archiver && this.epochCache.isProposerPipeliningEnabled()) {
202
+ const set = await this.setProposedCheckpointFromValidation(proposal);
203
+ if (set) {
204
+ this.metrics?.recordCheckpointProposalToPipelinedStateDuration(pipeliningTimer.ms());
205
+ }
206
+ }
207
+ } catch (err) {
208
+ this.log.warn(`Error handling checkpoint proposal for slot ${proposal.slotNumber}`, { err });
209
+ }
210
+ return undefined;
211
+ };
212
+
213
+ p2pClient.registerAllNodesCheckpointProposalHandler(checkpointHandler);
171
214
 
172
215
  return this;
173
216
  }
@@ -208,14 +251,18 @@ export class ProposalHandler {
208
251
  }
209
252
 
210
253
  // Ensure the block source is synced before checking for existing blocks,
211
- // since a pending checkpoint prune may remove blocks we'd otherwise find.
254
+ // since a proposed checkpoint prune may remove blocks we'd otherwise find.
212
255
  // This affects mostly the block_number_already_exists check, since a pending
213
256
  // checkpoint prune could remove a block that would conflict with this proposal.
214
- // TODO(@Maddiaa0): This may break staggered slots.
215
- const blockSourceSync = await this.waitForBlockSourceSync(slotNumber);
216
- if (!blockSourceSync) {
217
- this.log.warn(`Block source is not synced, skipping processing`, proposalInfo);
218
- return { isValid: false, reason: 'block_source_not_synced' };
257
+ // When pipelining is enabled, the proposer builds ahead of L1 submission, so the
258
+ // block source won't have synced to the proposed slot yet. Skip the sync wait to
259
+ // avoid eating into the attestation window.
260
+ if (!this.epochCache.isProposerPipeliningEnabled()) {
261
+ const blockSourceSync = await this.waitForBlockSourceSync(slotNumber);
262
+ if (!blockSourceSync) {
263
+ this.log.warn(`Block source is not synced, skipping processing`, proposalInfo);
264
+ return { isValid: false, reason: 'block_source_not_synced' };
265
+ }
219
266
  }
220
267
 
221
268
  // Check that the parent proposal is a block we know, otherwise reexecution would fail.
@@ -320,7 +367,7 @@ export class ProposalHandler {
320
367
 
321
368
  // If we succeeded, push this block into the archiver (unless disabled)
322
369
  if (reexecutionResult?.block && this.config.skipPushProposedBlocksToArchiver === false) {
323
- await this.blockSource.addBlock(reexecutionResult?.block);
370
+ await this.blockSource.addBlock(reexecutionResult.block);
324
371
  }
325
372
 
326
373
  this.log.info(
@@ -333,7 +380,6 @@ export class ProposalHandler {
333
380
 
334
381
  private async getParentBlock(proposal: BlockProposal): Promise<'genesis' | BlockData | undefined> {
335
382
  const parentArchive = proposal.blockHeader.lastArchive.root;
336
- const slot = proposal.slotNumber;
337
383
  const config = this.checkpointsBuilder.getConfig();
338
384
  const { genesisArchiveRoot } = await this.blockSource.getGenesisValues();
339
385
 
@@ -341,7 +387,7 @@ export class ProposalHandler {
341
387
  return 'genesis';
342
388
  }
343
389
 
344
- const deadline = this.getReexecutionDeadline(slot, config);
390
+ const deadline = this.getReexecutionDeadline(proposal.slotNumber, config);
345
391
  const currentTime = this.dateProvider.now();
346
392
  const timeoutDurationMs = deadline.getTime() - currentTime;
347
393
 
@@ -490,8 +536,14 @@ export class ProposalHandler {
490
536
  return undefined;
491
537
  }
492
538
 
493
- private getReexecutionDeadline(slot: SlotNumber, config: { l1GenesisTime: bigint; slotDuration: number }): Date {
494
- const nextSlotTimestampSeconds = Number(getTimestampForSlot(SlotNumber(slot + 1), config));
539
+ private getReexecutionDeadline(
540
+ slotNumber: SlotNumber,
541
+ config: { l1GenesisTime: bigint; slotDuration: number },
542
+ ): Date {
543
+ // Under proposer pipelining, the proposal slot may be ahead of wall clock time.
544
+ // Reexecution budgets should still be bounded by the current slot we are in now.
545
+ const wallclockSlot = slotNumber - this.epochCache.pipeliningOffset();
546
+ const nextSlotTimestampSeconds = Number(getTimestampForSlot(SlotNumber(wallclockSlot + 1), config));
495
547
  return new Date(nextSlotTimestampSeconds * 1000);
496
548
  }
497
549
 
@@ -504,8 +556,9 @@ export class ProposalHandler {
504
556
  }
505
557
 
506
558
  // Make a quick check before triggering an archiver sync
559
+ // If we are pipelining and have a pending checkpoint number stored, we will allow the block proposal to be for a slot further
507
560
  const syncedSlot = await this.blockSource.getSyncedL2SlotNumber();
508
- if (syncedSlot !== undefined && syncedSlot + 1 >= slot) {
561
+ if (syncedSlot !== undefined && syncedSlot + 1 + this.epochCache.pipeliningOffset() >= slot) {
509
562
  return true;
510
563
  }
511
564
 
@@ -514,8 +567,8 @@ export class ProposalHandler {
514
567
  return await retryUntil(
515
568
  async () => {
516
569
  await this.blockSource.syncImmediate();
517
- const syncedSlot = await this.blockSource.getSyncedL2SlotNumber();
518
- return syncedSlot !== undefined && syncedSlot + 1 >= slot;
570
+ const updatedSyncedSlot = await this.blockSource.getSyncedL2SlotNumber();
571
+ return updatedSyncedSlot !== undefined && updatedSyncedSlot + 1 >= slot;
519
572
  },
520
573
  'wait for block source sync',
521
574
  timeoutMs / 1000,
@@ -672,27 +725,45 @@ export class ProposalHandler {
672
725
  }
673
726
 
674
727
  /**
675
- * Validates a checkpoint proposal and uploads blobs if configured.
676
- * Used by both non-validator nodes (via register) and the validator client (via delegation).
728
+ * Validates a checkpoint proposal, caches the result, and uploads blobs if configured.
729
+ * Returns a cached result if the same proposal (archive + slot) was already validated.
730
+ * Used by both the all-nodes callback (via register) and the validator client (via delegation).
677
731
  */
678
732
  async handleCheckpointProposal(
679
733
  proposal: CheckpointProposalCore,
680
734
  proposalInfo: LogData,
681
735
  ): Promise<CheckpointProposalValidationResult> {
736
+ const slot = proposal.slotNumber;
737
+
738
+ // Check cache: same archive+slot means we already validated this proposal
739
+ if (
740
+ this.lastCheckpointValidationResult &&
741
+ this.lastCheckpointValidationResult.archive.equals(proposal.archive) &&
742
+ this.lastCheckpointValidationResult.slotNumber === slot
743
+ ) {
744
+ this.log.debug(`Returning cached validation result for checkpoint proposal at slot ${slot}`, proposalInfo);
745
+ return this.lastCheckpointValidationResult.result;
746
+ }
747
+
682
748
  const proposer = proposal.getSender();
683
749
  if (!proposer) {
684
750
  this.log.warn(`Received checkpoint proposal with invalid signature for slot ${proposal.slotNumber}`);
685
- return { isValid: false, reason: 'invalid_signature' };
751
+ const result: CheckpointProposalValidationResult = { isValid: false, reason: 'invalid_signature' };
752
+ this.lastCheckpointValidationResult = { archive: proposal.archive, slotNumber: slot, result };
753
+ return result;
686
754
  }
687
755
 
688
756
  if (!validateFeeAssetPriceModifier(proposal.feeAssetPriceModifier)) {
689
757
  this.log.warn(
690
758
  `Received checkpoint proposal with invalid feeAssetPriceModifier ${proposal.feeAssetPriceModifier} for slot ${proposal.slotNumber}`,
691
759
  );
692
- return { isValid: false, reason: 'invalid_fee_asset_price_modifier' };
760
+ const result: CheckpointProposalValidationResult = { isValid: false, reason: 'invalid_fee_asset_price_modifier' };
761
+ this.lastCheckpointValidationResult = { archive: proposal.archive, slotNumber: slot, result };
762
+ return result;
693
763
  }
694
764
 
695
765
  const result = await this.validateCheckpointProposal(proposal, proposalInfo);
766
+ this.lastCheckpointValidationResult = { archive: proposal.archive, slotNumber: slot, result };
696
767
 
697
768
  // Upload blobs to filestore if validation passed (fire and forget)
698
769
  if (result.isValid) {
@@ -777,79 +848,75 @@ export class ProposalHandler {
777
848
 
778
849
  // Fork world state at the block before the first block
779
850
  const parentBlockNumber = BlockNumber(firstBlock.number - 1);
780
- const fork = await this.worldState.fork(parentBlockNumber);
851
+ await using fork = await this.checkpointsBuilder.getFork(parentBlockNumber);
781
852
 
782
- try {
783
- // Create checkpoint builder with all existing blocks
784
- const checkpointBuilder = await this.checkpointsBuilder.openCheckpoint(
785
- checkpointNumber,
786
- constants,
787
- proposal.feeAssetPriceModifier,
788
- l1ToL2Messages,
789
- previousCheckpointOutHashes,
790
- fork,
791
- blocks,
792
- this.log.getBindings(),
793
- );
853
+ // Create checkpoint builder with all existing blocks
854
+ const checkpointBuilder = await this.checkpointsBuilder.openCheckpoint(
855
+ checkpointNumber,
856
+ constants,
857
+ proposal.feeAssetPriceModifier,
858
+ l1ToL2Messages,
859
+ previousCheckpointOutHashes,
860
+ fork,
861
+ blocks,
862
+ this.log.getBindings(),
863
+ );
794
864
 
795
- // Complete the checkpoint to get computed values
796
- const computedCheckpoint = await checkpointBuilder.completeCheckpoint();
797
-
798
- // Compare checkpoint header with proposal
799
- if (!computedCheckpoint.header.equals(proposal.checkpointHeader)) {
800
- this.log.warn(`Checkpoint header mismatch`, {
801
- ...proposalInfo,
802
- computed: computedCheckpoint.header.toInspect(),
803
- proposal: proposal.checkpointHeader.toInspect(),
804
- });
805
- return { isValid: false, reason: 'checkpoint_header_mismatch' };
806
- }
865
+ // Complete the checkpoint to get computed values
866
+ const computedCheckpoint = await checkpointBuilder.completeCheckpoint();
807
867
 
808
- // Compare archive root with proposal
809
- if (!computedCheckpoint.archive.root.equals(proposal.archive)) {
810
- this.log.warn(`Archive root mismatch`, {
811
- ...proposalInfo,
812
- computed: computedCheckpoint.archive.root.toString(),
813
- proposal: proposal.archive.toString(),
814
- });
815
- return { isValid: false, reason: 'archive_mismatch' };
816
- }
868
+ // Compare checkpoint header with proposal
869
+ if (!computedCheckpoint.header.equals(proposal.checkpointHeader)) {
870
+ this.log.warn(`Checkpoint header mismatch`, {
871
+ ...proposalInfo,
872
+ computed: computedCheckpoint.header.toInspect(),
873
+ proposal: proposal.checkpointHeader.toInspect(),
874
+ });
875
+ return { isValid: false, reason: 'checkpoint_header_mismatch' };
876
+ }
817
877
 
818
- // Check that the accumulated epoch out hash matches the value in the proposal.
819
- // The epoch out hash is the accumulated hash of all checkpoint out hashes in the epoch.
820
- const checkpointOutHash = computedCheckpoint.getCheckpointOutHash();
821
- const computedEpochOutHash = accumulateCheckpointOutHashes([...previousCheckpointOutHashes, checkpointOutHash]);
822
- const proposalEpochOutHash = proposal.checkpointHeader.epochOutHash;
823
- if (!computedEpochOutHash.equals(proposalEpochOutHash)) {
824
- this.log.warn(`Epoch out hash mismatch`, {
825
- proposalEpochOutHash: proposalEpochOutHash.toString(),
826
- computedEpochOutHash: computedEpochOutHash.toString(),
827
- checkpointOutHash: checkpointOutHash.toString(),
828
- previousCheckpointOutHashes: previousCheckpointOutHashes.map(h => h.toString()),
829
- ...proposalInfo,
830
- });
831
- return { isValid: false, reason: 'out_hash_mismatch' };
832
- }
878
+ // Compare archive root with proposal
879
+ if (!computedCheckpoint.archive.root.equals(proposal.archive)) {
880
+ this.log.warn(`Archive root mismatch`, {
881
+ ...proposalInfo,
882
+ computed: computedCheckpoint.archive.root.toString(),
883
+ proposal: proposal.archive.toString(),
884
+ });
885
+ return { isValid: false, reason: 'archive_mismatch' };
886
+ }
833
887
 
834
- // Final round of validations on the checkpoint, just in case.
835
- try {
836
- validateCheckpoint(computedCheckpoint, {
837
- rollupManaLimit: this.checkpointsBuilder.getConfig().rollupManaLimit,
838
- maxDABlockGas: this.config.validateMaxDABlockGas,
839
- maxL2BlockGas: this.config.validateMaxL2BlockGas,
840
- maxTxsPerBlock: this.config.validateMaxTxsPerBlock,
841
- maxTxsPerCheckpoint: this.config.validateMaxTxsPerCheckpoint,
842
- });
843
- } catch (err) {
844
- this.log.warn(`Checkpoint validation failed: ${err}`, proposalInfo);
845
- return { isValid: false, reason: 'checkpoint_validation_failed' };
846
- }
888
+ // Check that the accumulated epoch out hash matches the value in the proposal.
889
+ // The epoch out hash is the accumulated hash of all checkpoint out hashes in the epoch.
890
+ const checkpointOutHash = computedCheckpoint.getCheckpointOutHash();
891
+ const computedEpochOutHash = accumulateCheckpointOutHashes([...previousCheckpointOutHashes, checkpointOutHash]);
892
+ const proposalEpochOutHash = proposal.checkpointHeader.epochOutHash;
893
+ if (!computedEpochOutHash.equals(proposalEpochOutHash)) {
894
+ this.log.warn(`Epoch out hash mismatch`, {
895
+ proposalEpochOutHash: proposalEpochOutHash.toString(),
896
+ computedEpochOutHash: computedEpochOutHash.toString(),
897
+ checkpointOutHash: checkpointOutHash.toString(),
898
+ previousCheckpointOutHashes: previousCheckpointOutHashes.map(h => h.toString()),
899
+ ...proposalInfo,
900
+ });
901
+ return { isValid: false, reason: 'out_hash_mismatch' };
902
+ }
847
903
 
848
- this.log.verbose(`Checkpoint proposal validation successful for slot ${slot}`, proposalInfo);
849
- return { isValid: true };
850
- } finally {
851
- await fork.close();
904
+ // Final round of validations on the checkpoint, just in case.
905
+ try {
906
+ validateCheckpoint(computedCheckpoint, {
907
+ rollupManaLimit: this.checkpointsBuilder.getConfig().rollupManaLimit,
908
+ maxDABlockGas: this.config.validateMaxDABlockGas,
909
+ maxL2BlockGas: this.config.validateMaxL2BlockGas,
910
+ maxTxsPerBlock: this.config.validateMaxTxsPerBlock,
911
+ maxTxsPerCheckpoint: this.config.validateMaxTxsPerCheckpoint,
912
+ });
913
+ } catch (err) {
914
+ this.log.warn(`Checkpoint validation failed: ${err}`, proposalInfo);
915
+ return { isValid: false, reason: 'checkpoint_validation_failed' };
852
916
  }
917
+
918
+ this.log.verbose(`Checkpoint proposal validation successful for slot ${slot}`, proposalInfo);
919
+ return { isValid: true, checkpointNumber };
853
920
  }
854
921
 
855
922
  /** Extracts checkpoint global variables from a block. */
@@ -900,4 +967,76 @@ export class ProposalHandler {
900
967
  this.log.warn(`Failed to upload blobs for checkpoint: ${err}`, proposalInfo);
901
968
  }
902
969
  }
970
+
971
+ /**
972
+ * Derives proposed checkpoint data from validated blocks and sets it on the archiver.
973
+ * Used after successful validation of a foreign proposal.
974
+ * Does not retry since we already waited for the block during validation.
975
+ */
976
+ private async setProposedCheckpointFromValidation(proposal: CheckpointProposalCore): Promise<boolean> {
977
+ if (!this.archiver) {
978
+ return false;
979
+ }
980
+ const blockData = await this.blockSource.getBlockDataByArchive(proposal.archive);
981
+ if (!blockData) {
982
+ this.log.debug(`Block data not found for checkpoint proposal archive, cannot set proposed checkpoint`, {
983
+ archive: proposal.archive.toString(),
984
+ });
985
+ return false;
986
+ }
987
+
988
+ await this.archiver.setProposedCheckpoint({
989
+ header: proposal.checkpointHeader,
990
+ checkpointNumber: blockData.checkpointNumber,
991
+ startBlock: BlockNumber(blockData.header.getBlockNumber() - blockData.indexWithinCheckpoint),
992
+ blockCount: blockData.indexWithinCheckpoint + 1,
993
+ totalManaUsed: proposal.checkpointHeader.totalManaUsed.toBigInt(),
994
+ feeAssetPriceModifier: proposal.feeAssetPriceModifier,
995
+ });
996
+ return true;
997
+ }
998
+
999
+ /**
1000
+ * Sets proposed checkpoint from blocks for own proposals (skips full validation).
1001
+ * Retries fetching block data since the checkpoint proposal often arrives before the last block
1002
+ * finishes re-execution.
1003
+ */
1004
+ private async setProposedCheckpointFromBlocks(proposal: CheckpointProposalCore): Promise<boolean> {
1005
+ if (!this.archiver) {
1006
+ return false;
1007
+ }
1008
+ let blockData = await this.blockSource.getBlockDataByArchive(proposal.archive);
1009
+
1010
+ if (!blockData) {
1011
+ // The checkpoint proposal often arrives before the last block finishes re-execution.
1012
+ // Retry until we find the data or give up at the end of the slot.
1013
+ const nextSlot = this.epochCache.getSlotNow() + 1;
1014
+ const timeOfNextSlot = getTimestampForSlot(SlotNumber(nextSlot), await this.archiver.getL1Constants());
1015
+ const timeoutSeconds = Math.max(1, Number(timeOfNextSlot) - Math.floor(this.dateProvider.now() / 1000));
1016
+
1017
+ blockData = await retryUntil(
1018
+ () => this.blockSource.getBlockDataByArchive(proposal.archive),
1019
+ 'block data for own checkpoint proposal',
1020
+ timeoutSeconds,
1021
+ 0.25,
1022
+ ).catch(() => undefined);
1023
+ }
1024
+
1025
+ if (blockData) {
1026
+ await this.archiver.setProposedCheckpoint({
1027
+ header: proposal.checkpointHeader,
1028
+ checkpointNumber: blockData.checkpointNumber,
1029
+ startBlock: BlockNumber(blockData.header.getBlockNumber() - blockData.indexWithinCheckpoint),
1030
+ blockCount: blockData.indexWithinCheckpoint + 1,
1031
+ totalManaUsed: proposal.checkpointHeader.totalManaUsed.toBigInt(),
1032
+ feeAssetPriceModifier: proposal.feeAssetPriceModifier,
1033
+ });
1034
+ return true;
1035
+ } else {
1036
+ this.log.debug(`Block data not found for own checkpoint proposal archive, cannot set proposed checkpoint`, {
1037
+ archive: proposal.archive.toString(),
1038
+ });
1039
+ return false;
1040
+ }
1041
+ }
903
1042
  }