@aztec/sequencer-client 0.0.1-commit.03f7ef2 → 0.0.1-commit.04d373f

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 (145) hide show
  1. package/README.md +282 -21
  2. package/dest/client/sequencer-client.d.ts +20 -11
  3. package/dest/client/sequencer-client.d.ts.map +1 -1
  4. package/dest/client/sequencer-client.js +67 -33
  5. package/dest/config.d.ts +29 -7
  6. package/dest/config.d.ts.map +1 -1
  7. package/dest/config.js +82 -37
  8. package/dest/global_variable_builder/fee_predictor.d.ts +37 -0
  9. package/dest/global_variable_builder/fee_predictor.d.ts.map +1 -0
  10. package/dest/global_variable_builder/fee_predictor.js +128 -0
  11. package/dest/global_variable_builder/fee_provider.d.ts +21 -0
  12. package/dest/global_variable_builder/fee_provider.d.ts.map +1 -0
  13. package/dest/global_variable_builder/fee_provider.js +58 -0
  14. package/dest/global_variable_builder/global_builder.d.ts +14 -16
  15. package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
  16. package/dest/global_variable_builder/global_builder.js +16 -50
  17. package/dest/global_variable_builder/index.d.ts +4 -2
  18. package/dest/global_variable_builder/index.d.ts.map +1 -1
  19. package/dest/global_variable_builder/index.js +2 -0
  20. package/dest/index.d.ts +2 -3
  21. package/dest/index.d.ts.map +1 -1
  22. package/dest/index.js +1 -2
  23. package/dest/publisher/config.d.ts +47 -17
  24. package/dest/publisher/config.d.ts.map +1 -1
  25. package/dest/publisher/config.js +121 -42
  26. package/dest/publisher/index.d.ts +2 -1
  27. package/dest/publisher/index.d.ts.map +1 -1
  28. package/dest/publisher/l1_tx_failed_store/factory.d.ts +11 -0
  29. package/dest/publisher/l1_tx_failed_store/factory.d.ts.map +1 -0
  30. package/dest/publisher/l1_tx_failed_store/factory.js +22 -0
  31. package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts +58 -0
  32. package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts.map +1 -0
  33. package/dest/publisher/l1_tx_failed_store/failed_tx_store.js +1 -0
  34. package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts +15 -0
  35. package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts.map +1 -0
  36. package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.js +34 -0
  37. package/dest/publisher/l1_tx_failed_store/index.d.ts +4 -0
  38. package/dest/publisher/l1_tx_failed_store/index.d.ts.map +1 -0
  39. package/dest/publisher/l1_tx_failed_store/index.js +2 -0
  40. package/dest/publisher/sequencer-bundle-simulator.d.ts +96 -0
  41. package/dest/publisher/sequencer-bundle-simulator.d.ts.map +1 -0
  42. package/dest/publisher/sequencer-bundle-simulator.js +198 -0
  43. package/dest/publisher/sequencer-publisher-factory.d.ts +12 -6
  44. package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -1
  45. package/dest/publisher/sequencer-publisher-factory.js +27 -3
  46. package/dest/publisher/sequencer-publisher-metrics.d.ts +1 -1
  47. package/dest/publisher/sequencer-publisher-metrics.d.ts.map +1 -1
  48. package/dest/publisher/sequencer-publisher-metrics.js +23 -86
  49. package/dest/publisher/sequencer-publisher.d.ts +108 -81
  50. package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
  51. package/dest/publisher/sequencer-publisher.js +876 -403
  52. package/dest/sequencer/automine/automine_factory.d.ts +54 -0
  53. package/dest/sequencer/automine/automine_factory.d.ts.map +1 -0
  54. package/dest/sequencer/automine/automine_factory.js +84 -0
  55. package/dest/sequencer/automine/automine_sequencer.d.ts +151 -0
  56. package/dest/sequencer/automine/automine_sequencer.d.ts.map +1 -0
  57. package/dest/sequencer/automine/automine_sequencer.js +506 -0
  58. package/dest/sequencer/chain_state_overrides.d.ts +61 -0
  59. package/dest/sequencer/chain_state_overrides.d.ts.map +1 -0
  60. package/dest/sequencer/chain_state_overrides.js +98 -0
  61. package/dest/sequencer/checkpoint_proposal_job.d.ts +87 -16
  62. package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -1
  63. package/dest/sequencer/checkpoint_proposal_job.js +1331 -203
  64. package/dest/sequencer/checkpoint_proposal_job_metrics.d.ts +34 -0
  65. package/dest/sequencer/checkpoint_proposal_job_metrics.d.ts.map +1 -0
  66. package/dest/sequencer/checkpoint_proposal_job_metrics.js +72 -0
  67. package/dest/sequencer/checkpoint_voter.d.ts +3 -3
  68. package/dest/sequencer/checkpoint_voter.d.ts.map +1 -1
  69. package/dest/sequencer/checkpoint_voter.js +34 -13
  70. package/dest/sequencer/events.d.ts +47 -2
  71. package/dest/sequencer/events.d.ts.map +1 -1
  72. package/dest/sequencer/index.d.ts +3 -3
  73. package/dest/sequencer/index.d.ts.map +1 -1
  74. package/dest/sequencer/index.js +2 -2
  75. package/dest/sequencer/metrics.d.ts +23 -8
  76. package/dest/sequencer/metrics.d.ts.map +1 -1
  77. package/dest/sequencer/metrics.js +158 -143
  78. package/dest/sequencer/sequencer.d.ts +92 -29
  79. package/dest/sequencer/sequencer.d.ts.map +1 -1
  80. package/dest/sequencer/sequencer.js +818 -157
  81. package/dest/sequencer/timetable.d.ts +17 -6
  82. package/dest/sequencer/timetable.d.ts.map +1 -1
  83. package/dest/sequencer/timetable.js +51 -46
  84. package/dest/sequencer/types.d.ts +2 -2
  85. package/dest/sequencer/types.d.ts.map +1 -1
  86. package/dest/test/index.d.ts +4 -7
  87. package/dest/test/index.d.ts.map +1 -1
  88. package/dest/test/mock_checkpoint_builder.d.ts +29 -17
  89. package/dest/test/mock_checkpoint_builder.d.ts.map +1 -1
  90. package/dest/test/mock_checkpoint_builder.js +86 -34
  91. package/dest/test/utils.d.ts +13 -9
  92. package/dest/test/utils.d.ts.map +1 -1
  93. package/dest/test/utils.js +31 -20
  94. package/package.json +29 -28
  95. package/src/client/sequencer-client.ts +94 -38
  96. package/src/config.ts +107 -46
  97. package/src/global_variable_builder/README.md +44 -0
  98. package/src/global_variable_builder/fee_predictor.ts +172 -0
  99. package/src/global_variable_builder/fee_provider.ts +75 -0
  100. package/src/global_variable_builder/global_builder.ts +26 -63
  101. package/src/global_variable_builder/index.ts +3 -1
  102. package/src/index.ts +5 -4
  103. package/src/publisher/config.ts +157 -45
  104. package/src/publisher/index.ts +3 -0
  105. package/src/publisher/l1_tx_failed_store/factory.ts +32 -0
  106. package/src/publisher/l1_tx_failed_store/failed_tx_store.ts +57 -0
  107. package/src/publisher/l1_tx_failed_store/file_store_failed_tx_store.ts +46 -0
  108. package/src/publisher/l1_tx_failed_store/index.ts +3 -0
  109. package/src/publisher/sequencer-bundle-simulator.ts +254 -0
  110. package/src/publisher/sequencer-publisher-factory.ts +39 -10
  111. package/src/publisher/sequencer-publisher-metrics.ts +17 -69
  112. package/src/publisher/sequencer-publisher.ts +611 -521
  113. package/src/sequencer/README.md +152 -450
  114. package/src/sequencer/automine/README.md +46 -0
  115. package/src/sequencer/automine/automine_factory.ts +145 -0
  116. package/src/sequencer/automine/automine_sequencer.ts +592 -0
  117. package/src/sequencer/chain_state_overrides.ts +162 -0
  118. package/src/sequencer/checkpoint_proposal_job.ts +1138 -230
  119. package/src/sequencer/checkpoint_proposal_job_metrics.ts +128 -0
  120. package/src/sequencer/checkpoint_voter.ts +31 -17
  121. package/src/sequencer/events.ts +50 -2
  122. package/src/sequencer/index.ts +2 -2
  123. package/src/sequencer/metrics.ts +168 -151
  124. package/src/sequencer/sequencer.ts +535 -162
  125. package/src/sequencer/timetable.ts +70 -57
  126. package/src/sequencer/types.ts +1 -1
  127. package/src/test/index.ts +3 -6
  128. package/src/test/mock_checkpoint_builder.ts +149 -73
  129. package/src/test/utils.ts +78 -30
  130. package/dest/sequencer/block_builder.d.ts +0 -26
  131. package/dest/sequencer/block_builder.d.ts.map +0 -1
  132. package/dest/sequencer/block_builder.js +0 -129
  133. package/dest/sequencer/checkpoint_builder.d.ts +0 -63
  134. package/dest/sequencer/checkpoint_builder.d.ts.map +0 -1
  135. package/dest/sequencer/checkpoint_builder.js +0 -131
  136. package/dest/tx_validator/nullifier_cache.d.ts +0 -14
  137. package/dest/tx_validator/nullifier_cache.d.ts.map +0 -1
  138. package/dest/tx_validator/nullifier_cache.js +0 -24
  139. package/dest/tx_validator/tx_validator_factory.d.ts +0 -18
  140. package/dest/tx_validator/tx_validator_factory.d.ts.map +0 -1
  141. package/dest/tx_validator/tx_validator_factory.js +0 -53
  142. package/src/sequencer/block_builder.ts +0 -217
  143. package/src/sequencer/checkpoint_builder.ts +0 -217
  144. package/src/tx_validator/nullifier_cache.ts +0 -30
  145. package/src/tx_validator/tx_validator_factory.ts +0 -133
@@ -1,15 +1,20 @@
1
- import { createLogger } from '@aztec/aztec.js/log';
1
+ import type { Logger } from '@aztec/foundation/log';
2
+ import {
3
+ CHECKPOINT_ASSEMBLE_TIME,
4
+ CHECKPOINT_INITIALIZATION_TIME,
5
+ type CheckpointTiming,
6
+ DEFAULT_P2P_PROPAGATION_TIME,
7
+ MIN_EXECUTION_TIME,
8
+ createCheckpointTimingModel,
9
+ } from '@aztec/stdlib/timetable';
2
10
 
3
- import { DEFAULT_ATTESTATION_PROPAGATION_TIME as DEFAULT_P2P_PROPAGATION_TIME } from '../config.js';
4
11
  import { SequencerTooSlowError } from './errors.js';
5
12
  import type { SequencerMetrics } from './metrics.js';
6
13
  import { SequencerState } from './utils.js';
7
14
 
8
- export const MIN_EXECUTION_TIME = 2;
9
- export const CHECKPOINT_INITIALIZATION_TIME = 1;
10
- export const CHECKPOINT_ASSEMBLE_TIME = 1;
11
-
12
15
  export class SequencerTimetable {
16
+ private readonly checkpointTiming: CheckpointTiming;
17
+
13
18
  /**
14
19
  * How late into the slot can we be to start working. Computed as the total time needed for assembling and publishing a block,
15
20
  * assuming an execution time equal to `minExecutionTime`, subtracted from the slot duration. This means that, if the proposer
@@ -69,6 +74,15 @@ export class SequencerTimetable {
69
74
  /** Maximum number of blocks that can be built in this slot configuration */
70
75
  public readonly maxNumberOfBlocks: number;
71
76
 
77
+ /** Whether pipelining is enabled (checkpoint finalization deferred to next slot). */
78
+ public readonly pipelining: boolean;
79
+
80
+ /**
81
+ * How far into the target slot attestation collection can extend when pipelining.
82
+ * Covers validator re-execution (one block duration) plus one-way attestation return.
83
+ */
84
+ public readonly pipeliningAttestationGracePeriod: number;
85
+
72
86
  constructor(
73
87
  opts: {
74
88
  ethereumSlotDuration: number;
@@ -77,61 +91,41 @@ export class SequencerTimetable {
77
91
  p2pPropagationTime?: number;
78
92
  blockDurationMs?: number;
79
93
  enforce: boolean;
94
+ pipelining?: boolean;
80
95
  },
81
96
  private readonly metrics?: SequencerMetrics,
82
- private readonly log = createLogger('sequencer:timetable'),
97
+ private readonly log?: Logger,
83
98
  ) {
84
99
  this.ethereumSlotDuration = opts.ethereumSlotDuration;
85
100
  this.aztecSlotDuration = opts.aztecSlotDuration;
86
101
  this.l1PublishingTime = opts.l1PublishingTime;
87
- this.p2pPropagationTime = opts.p2pPropagationTime ?? DEFAULT_P2P_PROPAGATION_TIME;
88
102
  this.blockDuration = opts.blockDurationMs ? opts.blockDurationMs / 1000 : undefined;
89
103
  this.enforce = opts.enforce;
104
+ this.pipelining = opts.pipelining ?? false;
105
+
106
+ this.checkpointTiming = createCheckpointTimingModel({
107
+ aztecSlotDuration: this.aztecSlotDuration,
108
+ ethereumSlotDuration: this.ethereumSlotDuration,
109
+ blockDuration: this.blockDuration,
110
+ l1PublishingTime: this.l1PublishingTime,
111
+ p2pPropagationTime: opts.p2pPropagationTime ?? DEFAULT_P2P_PROPAGATION_TIME,
112
+ pipelining: this.pipelining,
113
+ });
90
114
 
91
- // Assume zero-cost propagation time and faster runs in test environments where L1 slot duration is shortened
92
- if (this.ethereumSlotDuration < 8) {
93
- this.p2pPropagationTime = 0;
94
- this.checkpointAssembleTime = 0.5;
95
- this.checkpointInitializationTime = 0.5;
96
- this.minExecutionTime = 1;
97
- }
98
-
99
- // Min execution time cannot be less than the block duration if set
100
- if (this.blockDuration !== undefined && this.minExecutionTime > this.blockDuration) {
101
- this.minExecutionTime = this.blockDuration;
102
- }
115
+ this.p2pPropagationTime = this.checkpointTiming.p2pPropagationTime;
116
+ this.checkpointAssembleTime = this.checkpointTiming.checkpointAssembleTime;
117
+ this.checkpointInitializationTime = this.checkpointTiming.checkpointInitializationTime;
118
+ this.minExecutionTime = this.checkpointTiming.minExecutionTime;
103
119
 
104
120
  // Calculate initialization offset - estimate of time needed for sync + proposer check
105
121
  // This is the baseline for all sub-slot deadlines
106
- this.initializationOffset = this.checkpointInitializationTime;
107
-
108
- // Calculate total checkpoint finalization time (assembly + attestations + L1 publishing)
109
- this.checkpointFinalizationTime =
110
- this.checkpointAssembleTime +
111
- this.p2pPropagationTime * 2 + // Round-trip propagation
112
- this.l1PublishingTime; // L1 publishing
113
-
114
- // Calculate maximum number of blocks that fit in this slot
115
- if (!this.blockDuration) {
116
- this.maxNumberOfBlocks = 1; // Single block per slot
117
- } else {
118
- const timeReservedAtEnd =
119
- this.blockDuration + // Last sub-slot for validator re-execution
120
- this.checkpointFinalizationTime; // Checkpoint finalization
121
- const timeAvailableForBlocks = this.aztecSlotDuration - this.initializationOffset - timeReservedAtEnd;
122
- this.maxNumberOfBlocks = Math.floor(timeAvailableForBlocks / this.blockDuration);
123
- }
122
+ this.initializationOffset = this.checkpointTiming.checkpointInitializationTime;
123
+ this.checkpointFinalizationTime = this.checkpointTiming.checkpointFinalizationTime;
124
+ this.pipeliningAttestationGracePeriod = this.checkpointTiming.pipeliningAttestationGracePeriod;
125
+ this.maxNumberOfBlocks = this.checkpointTiming.calculateMaxBlocksPerSlot();
126
+ this.initializeDeadline = this.checkpointTiming.initializeDeadline;
124
127
 
125
- // Minimum work to do within a slot for building a block with the minimum time for execution and publishing its checkpoint
126
- const minWorkToDo =
127
- this.initializationOffset +
128
- this.minExecutionTime * 2 + // Execution and reexecution
129
- this.checkpointFinalizationTime;
130
-
131
- const initializeDeadline = this.aztecSlotDuration - minWorkToDo;
132
- this.initializeDeadline = initializeDeadline;
133
-
134
- this.log.verbose(
128
+ this.log?.info(
135
129
  `Sequencer timetable initialized with ${this.maxNumberOfBlocks} blocks per slot (${this.enforce ? 'enforced' : 'not enforced'})`,
136
130
  {
137
131
  ethereumSlotDuration: this.ethereumSlotDuration,
@@ -143,19 +137,37 @@ export class SequencerTimetable {
143
137
  blockAssembleTime: this.checkpointAssembleTime,
144
138
  initializeDeadline: this.initializeDeadline,
145
139
  enforce: this.enforce,
146
- minWorkToDo,
140
+ pipelining: this.pipelining,
141
+ pipeliningAttestationGracePeriod: this.pipeliningAttestationGracePeriod,
142
+ minWorkToDo: this.checkpointTiming.minimumBuildSlotWork,
147
143
  blockDuration: this.blockDuration,
148
144
  maxNumberOfBlocks: this.maxNumberOfBlocks,
149
145
  },
150
146
  );
151
147
 
152
- if (initializeDeadline <= 0) {
148
+ if (this.initializeDeadline <= 0) {
153
149
  throw new Error(
154
- `Block proposal initialize deadline cannot be negative (got ${initializeDeadline} from total time needed ${minWorkToDo} and a slot duration of ${this.aztecSlotDuration}).`,
150
+ `Block proposal initialize deadline cannot be negative (got ${this.initializeDeadline} from total time needed ${this.checkpointTiming.minimumBuildSlotWork} and a slot duration of ${this.aztecSlotDuration}).`,
155
151
  );
156
152
  }
157
153
  }
158
154
 
155
+ public getCheckpointAssemblyDeadline(): number {
156
+ return this.checkpointTiming.checkpointAssemblyDeadline;
157
+ }
158
+
159
+ public getCheckpointAttestationDeadline(): number {
160
+ return this.checkpointTiming.checkpointAttestationDeadline;
161
+ }
162
+
163
+ public getCheckpointAttestationStartDeadline(): number {
164
+ return this.checkpointTiming.checkpointAttestationStartDeadline;
165
+ }
166
+
167
+ public getCheckpointPublishingDeadline(): number {
168
+ return this.checkpointTiming.checkpointPublishingDeadline;
169
+ }
170
+
159
171
  public getMaxAllowedTime(
160
172
  state: Extract<SequencerState, SequencerState.STOPPED | SequencerState.IDLE | SequencerState.SYNCHRONIZING>,
161
173
  ): undefined;
@@ -178,10 +190,11 @@ export class SequencerTimetable {
178
190
  case SequencerState.WAITING_UNTIL_NEXT_BLOCK:
179
191
  return this.initializeDeadline + this.checkpointInitializationTime;
180
192
  case SequencerState.ASSEMBLING_CHECKPOINT:
193
+ return this.getCheckpointAssemblyDeadline();
181
194
  case SequencerState.COLLECTING_ATTESTATIONS:
182
- return this.aztecSlotDuration - this.l1PublishingTime - 2 * this.p2pPropagationTime;
195
+ return this.getCheckpointAttestationStartDeadline();
183
196
  case SequencerState.PUBLISHING_CHECKPOINT:
184
- return this.aztecSlotDuration - this.l1PublishingTime;
197
+ return this.getCheckpointPublishingDeadline();
185
198
  default: {
186
199
  const _exhaustiveCheck: never = state;
187
200
  throw new Error(`Unexpected state: ${state}`);
@@ -205,7 +218,7 @@ export class SequencerTimetable {
205
218
  }
206
219
 
207
220
  this.metrics?.recordStateTransitionBufferMs(Math.floor(bufferSeconds * 1000), newState);
208
- this.log.trace(`Enough time to transition to ${newState}`, { maxAllowedTime, secondsIntoSlot });
221
+ this.log?.trace(`Enough time to transition to ${newState}`, { maxAllowedTime, secondsIntoSlot });
209
222
  }
210
223
 
211
224
  /**
@@ -241,7 +254,7 @@ export class SequencerTimetable {
241
254
  const canStart = available >= this.minExecutionTime;
242
255
  const deadline = secondsIntoSlot + available;
243
256
 
244
- this.log.verbose(
257
+ this.log?.verbose(
245
258
  `${canStart ? 'Can' : 'Cannot'} start single-block checkpoint at ${secondsIntoSlot}s into slot`,
246
259
  { secondsIntoSlot, maxAllowed, available, deadline },
247
260
  );
@@ -261,7 +274,7 @@ export class SequencerTimetable {
261
274
  // Found an available sub-slot! Is this the last one?
262
275
  const isLastBlock = subSlot === this.maxNumberOfBlocks;
263
276
 
264
- this.log.verbose(
277
+ this.log?.verbose(
265
278
  `Can start ${isLastBlock ? 'last block' : 'block'} in sub-slot ${subSlot} with deadline ${deadline}s`,
266
279
  { secondsIntoSlot, deadline, timeUntilDeadline, subSlot, maxBlocks: this.maxNumberOfBlocks },
267
280
  );
@@ -271,7 +284,7 @@ export class SequencerTimetable {
271
284
  }
272
285
 
273
286
  // No sub-slots available with enough time
274
- this.log.verbose(`No time left to start any more blocks`, {
287
+ this.log?.verbose(`No time left to start any more blocks`, {
275
288
  secondsIntoSlot,
276
289
  maxBlocks: this.maxNumberOfBlocks,
277
290
  initializationOffset: this.initializationOffset,
@@ -2,5 +2,5 @@ import type { L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
2
2
 
3
3
  export type SequencerRollupConstants = Pick<
4
4
  L1RollupConstants,
5
- 'ethereumSlotDuration' | 'l1GenesisTime' | 'slotDuration'
5
+ 'ethereumSlotDuration' | 'l1GenesisTime' | 'slotDuration' | 'rollupManaLimit' | 'epochDuration'
6
6
  >;
package/src/test/index.ts CHANGED
@@ -1,19 +1,16 @@
1
- import type { L1TxUtilsWithBlobs } from '@aztec/ethereum/l1-tx-utils-with-blobs';
1
+ import type { L1TxUtils } from '@aztec/ethereum/l1-tx-utils';
2
2
  import type { PublisherManager } from '@aztec/ethereum/publisher-manager';
3
3
  import type { PublicProcessorFactory } from '@aztec/simulator/server';
4
- import type { ValidatorClient } from '@aztec/validator-client';
4
+ import type { FullNodeCheckpointsBuilder, ValidatorClient } from '@aztec/validator-client';
5
5
 
6
6
  import { SequencerClient } from '../client/sequencer-client.js';
7
7
  import type { SequencerPublisherFactory } from '../publisher/sequencer-publisher-factory.js';
8
- import type { SequencerPublisher } from '../publisher/sequencer-publisher.js';
9
- import type { FullNodeCheckpointsBuilder } from '../sequencer/checkpoint_builder.js';
10
8
  import { Sequencer } from '../sequencer/sequencer.js';
11
9
  import type { SequencerTimetable } from '../sequencer/timetable.js';
12
10
 
13
11
  class TestSequencer_ extends Sequencer {
14
12
  declare public publicProcessorFactory: PublicProcessorFactory;
15
13
  declare public timetable: SequencerTimetable;
16
- declare public publisher: SequencerPublisher;
17
14
  declare public publisherFactory: SequencerPublisherFactory;
18
15
  declare public validatorClient: ValidatorClient;
19
16
  declare public checkpointsBuilder: FullNodeCheckpointsBuilder;
@@ -23,7 +20,7 @@ export type TestSequencer = TestSequencer_;
23
20
 
24
21
  class TestSequencerClient_ extends SequencerClient {
25
22
  declare public sequencer: TestSequencer;
26
- declare public publisherManager: PublisherManager<L1TxUtilsWithBlobs>;
23
+ declare public publisherManager: PublisherManager<L1TxUtils>;
27
24
  }
28
25
 
29
26
  export type TestSequencerClient = TestSequencerClient_;
@@ -1,40 +1,41 @@
1
- import { type BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
1
+ import { type BlockNumber, CheckpointNumber, IndexWithinCheckpoint } from '@aztec/foundation/branded-types';
2
2
  import { Fr } from '@aztec/foundation/curves/bn254';
3
- import { Timer } from '@aztec/foundation/timer';
4
- import type { FunctionsOf } from '@aztec/foundation/types';
5
- import { L2BlockNew } from '@aztec/stdlib/block';
3
+ import { unfreeze } from '@aztec/foundation/types';
4
+ import { L2Block } from '@aztec/stdlib/block';
6
5
  import { Checkpoint } from '@aztec/stdlib/checkpoint';
7
- import { Gas } from '@aztec/stdlib/gas';
8
- import type { FullNodeBlockBuilderConfig, PublicProcessorLimits } from '@aztec/stdlib/interfaces/server';
6
+ import type {
7
+ BlockBuilderOptions,
8
+ FullNodeBlockBuilderConfig,
9
+ ICheckpointBlockBuilder,
10
+ ICheckpointsBuilder,
11
+ MerkleTreeWriteOperations,
12
+ } from '@aztec/stdlib/interfaces/server';
9
13
  import { CheckpointHeader } from '@aztec/stdlib/rollup';
10
14
  import { makeAppendOnlyTreeSnapshot } from '@aztec/stdlib/testing';
11
15
  import type { CheckpointGlobalVariables, Tx } from '@aztec/stdlib/tx';
12
-
13
- import type {
14
- BuildBlockInCheckpointResult,
15
- CheckpointBuilder,
16
- FullNodeCheckpointsBuilder,
17
- } from '../sequencer/checkpoint_builder.js';
16
+ import type { BuildBlockInCheckpointResult } from '@aztec/validator-client';
18
17
 
19
18
  /**
20
19
  * A fake CheckpointBuilder for testing that implements the same interface as the real one.
21
20
  * Can be seeded with blocks to return sequentially on each `buildBlock` call.
22
21
  */
23
- export class MockCheckpointBuilder implements FunctionsOf<CheckpointBuilder> {
24
- private blocks: L2BlockNew[] = [];
25
- private builtBlocks: L2BlockNew[] = [];
22
+ export class MockCheckpointBuilder implements ICheckpointBlockBuilder {
23
+ private blocks: L2Block[] = [];
24
+ private builtBlocks: L2Block[] = [];
26
25
  private usedTxsPerBlock: Tx[][] = [];
27
26
  private blockIndex = 0;
28
27
 
29
28
  /** Optional function to dynamically provide the block (alternative to seedBlocks) */
30
- private blockProvider: (() => L2BlockNew) | undefined = undefined;
29
+ private blockProvider: (() => L2Block) | undefined = undefined;
31
30
 
32
31
  /** Track calls for assertions */
33
32
  public buildBlockCalls: Array<{
34
33
  blockNumber: BlockNumber;
35
34
  timestamp: bigint;
36
- opts: PublicProcessorLimits;
35
+ opts: BlockBuilderOptions;
37
36
  }> = [];
37
+ /** Track all consumed transaction hashes across buildBlock calls */
38
+ public consumedTxHashes: Set<string> = new Set();
38
39
  public completeCheckpointCalled = false;
39
40
  public getCheckpointCalled = false;
40
41
 
@@ -47,7 +48,7 @@ export class MockCheckpointBuilder implements FunctionsOf<CheckpointBuilder> {
47
48
  ) {}
48
49
 
49
50
  /** Seed the builder with blocks to return on successive buildBlock calls */
50
- seedBlocks(blocks: L2BlockNew[], usedTxsPerBlock?: Tx[][]): this {
51
+ seedBlocks(blocks: L2Block[], usedTxsPerBlock?: Tx[][]): this {
51
52
  this.blocks = blocks;
52
53
  this.usedTxsPerBlock = usedTxsPerBlock ?? blocks.map(() => []);
53
54
  this.blockIndex = 0;
@@ -59,7 +60,7 @@ export class MockCheckpointBuilder implements FunctionsOf<CheckpointBuilder> {
59
60
  * Set a function that provides blocks dynamically.
60
61
  * Useful for tests where the block is determined at call time (e.g., sequencer tests).
61
62
  */
62
- setBlockProvider(provider: () => L2BlockNew): this {
63
+ setBlockProvider(provider: () => L2Block): this {
63
64
  this.blockProvider = provider;
64
65
  this.blocks = [];
65
66
  return this;
@@ -69,24 +70,26 @@ export class MockCheckpointBuilder implements FunctionsOf<CheckpointBuilder> {
69
70
  return this.constants;
70
71
  }
71
72
 
72
- buildBlock(
73
- _pendingTxs: Iterable<Tx> | AsyncIterable<Tx>,
73
+ async buildBlock(
74
+ pendingTxs: Iterable<Tx> | AsyncIterable<Tx>,
74
75
  blockNumber: BlockNumber,
75
76
  timestamp: bigint,
76
- opts: PublicProcessorLimits,
77
+ opts: BlockBuilderOptions,
77
78
  ): Promise<BuildBlockInCheckpointResult> {
78
79
  this.buildBlockCalls.push({ blockNumber, timestamp, opts });
79
80
 
80
81
  if (this.errorOnBuild) {
81
- return Promise.reject(this.errorOnBuild);
82
+ throw this.errorOnBuild;
82
83
  }
83
84
 
84
- let block: L2BlockNew;
85
+ let block: L2Block;
85
86
  let usedTxs: Tx[];
86
87
 
87
88
  if (this.blockProvider) {
88
- // Dynamic mode: get block from provider
89
- block = this.blockProvider();
89
+ // Dynamic mode: get block from provider, cloning to avoid shared references across multiple buildBlock calls
90
+ block = L2Block.fromBuffer(this.blockProvider().toBuffer());
91
+ block.header.globalVariables.blockNumber = blockNumber;
92
+ await block.header.recomputeHash();
90
93
  usedTxs = [];
91
94
  this.builtBlocks.push(block);
92
95
  } else {
@@ -97,82 +100,94 @@ export class MockCheckpointBuilder implements FunctionsOf<CheckpointBuilder> {
97
100
  this.builtBlocks.push(block);
98
101
  }
99
102
 
100
- return Promise.resolve({
103
+ // Check that no pending tx has already been consumed
104
+ for await (const tx of pendingTxs) {
105
+ const hash = tx.getTxHash().toString();
106
+ if (this.consumedTxHashes.has(hash)) {
107
+ throw new Error(`Transaction ${hash} was already consumed in a previous block`);
108
+ }
109
+ }
110
+
111
+ // Add used txs to consumed set
112
+ for (const tx of usedTxs) {
113
+ this.consumedTxHashes.add(tx.getTxHash().toString());
114
+ }
115
+
116
+ return {
101
117
  block,
102
- publicGas: Gas.empty(),
103
118
  publicProcessorDuration: 0,
104
119
  numTxs: block?.body?.txEffects?.length ?? usedTxs.length,
105
- blockBuildingTimer: new Timer(),
106
120
  usedTxs,
107
121
  failedTxs: [],
108
- });
122
+ };
109
123
  }
110
124
 
111
125
  completeCheckpoint(): Promise<Checkpoint> {
112
126
  this.completeCheckpointCalled = true;
113
127
  const allBlocks = this.blockProvider ? this.builtBlocks : this.blocks;
114
- const lastBlock = allBlocks[allBlocks.length - 1];
115
- // Create a CheckpointHeader from the last block's header for testing
116
- const checkpointHeader = this.createCheckpointHeader(lastBlock);
117
- return Promise.resolve(
118
- new Checkpoint(
119
- makeAppendOnlyTreeSnapshot(lastBlock.header.globalVariables.blockNumber + 1),
120
- checkpointHeader,
121
- allBlocks,
122
- this.checkpointNumber,
123
- ),
124
- );
128
+ return this.buildCheckpoint(allBlocks);
125
129
  }
126
130
 
127
131
  getCheckpoint(): Promise<Checkpoint> {
128
132
  this.getCheckpointCalled = true;
129
133
  const builtBlocks = this.blockProvider ? this.builtBlocks : this.blocks.slice(0, this.blockIndex);
130
- const lastBlock = builtBlocks[builtBlocks.length - 1];
131
- if (!lastBlock) {
134
+ if (builtBlocks.length === 0) {
132
135
  throw new Error('No blocks built yet');
133
136
  }
134
- // Create a CheckpointHeader from the last block's header for testing
135
- const checkpointHeader = this.createCheckpointHeader(lastBlock);
136
- return Promise.resolve(
137
- new Checkpoint(
138
- makeAppendOnlyTreeSnapshot(lastBlock.header.globalVariables.blockNumber + 1),
139
- checkpointHeader,
140
- builtBlocks,
141
- this.checkpointNumber,
142
- ),
143
- );
137
+ return this.buildCheckpoint(builtBlocks);
144
138
  }
145
139
 
146
- /**
147
- * Creates a CheckpointHeader from a block's header for testing.
148
- * This is a simplified version that creates a minimal CheckpointHeader.
149
- */
150
- private createCheckpointHeader(block: L2BlockNew): CheckpointHeader {
151
- const header = block.header;
152
- const gv = header.globalVariables;
153
- return CheckpointHeader.empty({
154
- lastArchiveRoot: header.lastArchive.root,
155
- blockHeadersHash: Fr.random(), // Use random for testing
140
+ /** Builds a structurally valid Checkpoint from a list of blocks, fixing up indexes and archive chaining. */
141
+ private async buildCheckpoint(blocks: L2Block[]): Promise<Checkpoint> {
142
+ // Fix up indexWithinCheckpoint and archive chaining so the checkpoint passes structural validation.
143
+ for (let i = 0; i < blocks.length; i++) {
144
+ blocks[i].indexWithinCheckpoint = IndexWithinCheckpoint(i);
145
+ if (i > 0) {
146
+ unfreeze(blocks[i].header).lastArchive = blocks[i - 1].archive;
147
+ await blocks[i].header.recomputeHash();
148
+ }
149
+ }
150
+
151
+ const firstBlock = blocks[0];
152
+ const lastBlock = blocks[blocks.length - 1];
153
+ const gv = firstBlock.header.globalVariables;
154
+
155
+ const checkpointHeader = CheckpointHeader.empty({
156
+ lastArchiveRoot: firstBlock.header.lastArchive.root,
157
+ blockHeadersHash: Fr.random(),
156
158
  slotNumber: gv.slotNumber,
157
159
  timestamp: gv.timestamp,
158
160
  coinbase: gv.coinbase,
159
161
  feeRecipient: gv.feeRecipient,
160
162
  gasFees: gv.gasFees,
161
- totalManaUsed: header.totalManaUsed,
163
+ totalManaUsed: lastBlock.header.totalManaUsed,
162
164
  });
165
+
166
+ return new Checkpoint(
167
+ makeAppendOnlyTreeSnapshot(lastBlock.header.globalVariables.blockNumber + 1),
168
+ checkpointHeader,
169
+ blocks,
170
+ this.checkpointNumber,
171
+ );
172
+ }
173
+
174
+ /** Resets per-checkpoint state (built blocks, consumed txs) while preserving config (blockProvider, seeded blocks). */
175
+ resetCheckpointState(): void {
176
+ this.builtBlocks = [];
177
+ this.blockIndex = 0;
178
+ this.consumedTxHashes.clear();
179
+ this.completeCheckpointCalled = false;
180
+ this.getCheckpointCalled = false;
163
181
  }
164
182
 
165
183
  /** Reset for reuse in another test */
166
184
  reset(): void {
167
185
  this.blocks = [];
168
- this.builtBlocks = [];
169
186
  this.usedTxsPerBlock = [];
170
- this.blockIndex = 0;
171
187
  this.buildBlockCalls = [];
172
- this.completeCheckpointCalled = false;
173
- this.getCheckpointCalled = false;
174
188
  this.errorOnBuild = undefined;
175
189
  this.blockProvider = undefined;
190
+ this.resetCheckpointState();
176
191
  }
177
192
  }
178
193
 
@@ -181,7 +196,7 @@ export class MockCheckpointBuilder implements FunctionsOf<CheckpointBuilder> {
181
196
  * as FullNodeCheckpointsBuilder. Returns MockCheckpointBuilder instances.
182
197
  * Does NOT use jest mocks - this is a proper test double.
183
198
  */
184
- export class MockCheckpointsBuilder implements FunctionsOf<FullNodeCheckpointsBuilder> {
199
+ export class MockCheckpointsBuilder implements ICheckpointsBuilder {
185
200
  private checkpointBuilder: MockCheckpointBuilder | undefined;
186
201
 
187
202
  /** Track calls for assertions */
@@ -189,6 +204,16 @@ export class MockCheckpointsBuilder implements FunctionsOf<FullNodeCheckpointsBu
189
204
  checkpointNumber: CheckpointNumber;
190
205
  constants: CheckpointGlobalVariables;
191
206
  l1ToL2Messages: Fr[];
207
+ previousCheckpointOutHashes: Fr[];
208
+ feeAssetPriceModifier: bigint;
209
+ }> = [];
210
+ public openCheckpointCalls: Array<{
211
+ checkpointNumber: CheckpointNumber;
212
+ constants: CheckpointGlobalVariables;
213
+ l1ToL2Messages: Fr[];
214
+ previousCheckpointOutHashes: Fr[];
215
+ existingBlocks: L2Block[];
216
+ feeAssetPriceModifier: bigint;
192
217
  }> = [];
193
218
  public updateConfigCalls: Array<Partial<FullNodeBlockBuilderConfig>> = [];
194
219
 
@@ -218,6 +243,16 @@ export class MockCheckpointsBuilder implements FunctionsOf<FullNodeCheckpointsBu
218
243
  return this.checkpointBuilder;
219
244
  }
220
245
 
246
+ getConfig(): FullNodeBlockBuilderConfig {
247
+ return {
248
+ l1GenesisTime: 0n,
249
+ slotDuration: 24,
250
+ l1ChainId: 1,
251
+ rollupVersion: 1,
252
+ rollupManaLimit: 200_000_000,
253
+ };
254
+ }
255
+
221
256
  updateConfig(config: Partial<FullNodeBlockBuilderConfig>): void {
222
257
  this.updateConfigCalls.push(config);
223
258
  }
@@ -225,23 +260,64 @@ export class MockCheckpointsBuilder implements FunctionsOf<FullNodeCheckpointsBu
225
260
  startCheckpoint(
226
261
  checkpointNumber: CheckpointNumber,
227
262
  constants: CheckpointGlobalVariables,
263
+ feeAssetPriceModifier: bigint,
264
+ l1ToL2Messages: Fr[],
265
+ previousCheckpointOutHashes: Fr[],
266
+ _fork: MerkleTreeWriteOperations,
267
+ ): Promise<ICheckpointBlockBuilder> {
268
+ this.startCheckpointCalls.push({
269
+ checkpointNumber,
270
+ constants,
271
+ l1ToL2Messages,
272
+ previousCheckpointOutHashes,
273
+ feeAssetPriceModifier,
274
+ });
275
+
276
+ if (!this.checkpointBuilder) {
277
+ // Auto-create a builder if none was set
278
+ this.checkpointBuilder = new MockCheckpointBuilder(constants, checkpointNumber);
279
+ } else {
280
+ this.checkpointBuilder.resetCheckpointState();
281
+ }
282
+
283
+ return Promise.resolve(this.checkpointBuilder);
284
+ }
285
+
286
+ openCheckpoint(
287
+ checkpointNumber: CheckpointNumber,
288
+ constants: CheckpointGlobalVariables,
289
+ feeAssetPriceModifier: bigint,
228
290
  l1ToL2Messages: Fr[],
229
- _fork: unknown,
230
- ): Promise<CheckpointBuilder> {
231
- this.startCheckpointCalls.push({ checkpointNumber, constants, l1ToL2Messages });
291
+ previousCheckpointOutHashes: Fr[],
292
+ _fork: MerkleTreeWriteOperations,
293
+ existingBlocks: L2Block[] = [],
294
+ ): Promise<ICheckpointBlockBuilder> {
295
+ this.openCheckpointCalls.push({
296
+ checkpointNumber,
297
+ constants,
298
+ l1ToL2Messages,
299
+ previousCheckpointOutHashes,
300
+ existingBlocks,
301
+ feeAssetPriceModifier,
302
+ });
232
303
 
233
304
  if (!this.checkpointBuilder) {
234
305
  // Auto-create a builder if none was set
235
306
  this.checkpointBuilder = new MockCheckpointBuilder(constants, checkpointNumber);
236
307
  }
237
308
 
238
- return Promise.resolve(this.checkpointBuilder as unknown as CheckpointBuilder);
309
+ return Promise.resolve(this.checkpointBuilder);
310
+ }
311
+
312
+ getFork(_blockNumber: BlockNumber): Promise<MerkleTreeWriteOperations> {
313
+ throw new Error('MockCheckpointsBuilder.getFork not implemented');
239
314
  }
240
315
 
241
316
  /** Reset for reuse in another test */
242
317
  reset(): void {
243
318
  this.checkpointBuilder = undefined;
244
319
  this.startCheckpointCalls = [];
320
+ this.openCheckpointCalls = [];
245
321
  this.updateConfigCalls = [];
246
322
  }
247
323
  }