@aztec/sequencer-client 0.0.1-commit.023c3e5 → 0.0.1-commit.031e54b

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 (125) hide show
  1. package/README.md +281 -21
  2. package/dest/client/sequencer-client.d.ts +19 -9
  3. package/dest/client/sequencer-client.d.ts.map +1 -1
  4. package/dest/client/sequencer-client.js +65 -32
  5. package/dest/config.d.ts +28 -6
  6. package/dest/config.d.ts.map +1 -1
  7. package/dest/config.js +76 -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 -2
  21. package/dest/index.d.ts.map +1 -1
  22. package/dest/index.js +1 -1
  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 +11 -5
  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.d.ts +94 -67
  47. package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
  48. package/dest/publisher/sequencer-publisher.js +439 -378
  49. package/dest/sequencer/automine/automine_factory.d.ts +54 -0
  50. package/dest/sequencer/automine/automine_factory.d.ts.map +1 -0
  51. package/dest/sequencer/automine/automine_factory.js +84 -0
  52. package/dest/sequencer/automine/automine_sequencer.d.ts +151 -0
  53. package/dest/sequencer/automine/automine_sequencer.d.ts.map +1 -0
  54. package/dest/sequencer/automine/automine_sequencer.js +509 -0
  55. package/dest/sequencer/chain_state_overrides.d.ts +61 -0
  56. package/dest/sequencer/chain_state_overrides.d.ts.map +1 -0
  57. package/dest/sequencer/chain_state_overrides.js +98 -0
  58. package/dest/sequencer/checkpoint_proposal_job.d.ts +65 -11
  59. package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -1
  60. package/dest/sequencer/checkpoint_proposal_job.js +849 -249
  61. package/dest/sequencer/checkpoint_proposal_job_metrics.d.ts +34 -0
  62. package/dest/sequencer/checkpoint_proposal_job_metrics.d.ts.map +1 -0
  63. package/dest/sequencer/checkpoint_proposal_job_metrics.js +72 -0
  64. package/dest/sequencer/checkpoint_voter.d.ts +1 -2
  65. package/dest/sequencer/checkpoint_voter.d.ts.map +1 -1
  66. package/dest/sequencer/checkpoint_voter.js +2 -5
  67. package/dest/sequencer/events.d.ts +48 -2
  68. package/dest/sequencer/events.d.ts.map +1 -1
  69. package/dest/sequencer/index.d.ts +3 -1
  70. package/dest/sequencer/index.d.ts.map +1 -1
  71. package/dest/sequencer/index.js +2 -0
  72. package/dest/sequencer/metrics.d.ts +23 -8
  73. package/dest/sequencer/metrics.d.ts.map +1 -1
  74. package/dest/sequencer/metrics.js +117 -21
  75. package/dest/sequencer/sequencer.d.ts +85 -22
  76. package/dest/sequencer/sequencer.d.ts.map +1 -1
  77. package/dest/sequencer/sequencer.js +380 -137
  78. package/dest/sequencer/timetable.d.ts +14 -6
  79. package/dest/sequencer/timetable.d.ts.map +1 -1
  80. package/dest/sequencer/timetable.js +47 -46
  81. package/dest/sequencer/types.d.ts +2 -2
  82. package/dest/sequencer/types.d.ts.map +1 -1
  83. package/dest/test/index.d.ts +3 -5
  84. package/dest/test/index.d.ts.map +1 -1
  85. package/dest/test/mock_checkpoint_builder.d.ts +11 -11
  86. package/dest/test/mock_checkpoint_builder.d.ts.map +1 -1
  87. package/dest/test/mock_checkpoint_builder.js +45 -34
  88. package/dest/test/utils.d.ts +3 -3
  89. package/dest/test/utils.d.ts.map +1 -1
  90. package/dest/test/utils.js +10 -8
  91. package/package.json +27 -28
  92. package/src/client/sequencer-client.ts +91 -35
  93. package/src/config.ts +98 -46
  94. package/src/global_variable_builder/README.md +44 -0
  95. package/src/global_variable_builder/fee_predictor.ts +172 -0
  96. package/src/global_variable_builder/fee_provider.ts +75 -0
  97. package/src/global_variable_builder/global_builder.ts +26 -63
  98. package/src/global_variable_builder/index.ts +3 -1
  99. package/src/index.ts +10 -1
  100. package/src/publisher/config.ts +157 -45
  101. package/src/publisher/index.ts +3 -0
  102. package/src/publisher/l1_tx_failed_store/factory.ts +32 -0
  103. package/src/publisher/l1_tx_failed_store/failed_tx_store.ts +57 -0
  104. package/src/publisher/l1_tx_failed_store/file_store_failed_tx_store.ts +46 -0
  105. package/src/publisher/l1_tx_failed_store/index.ts +3 -0
  106. package/src/publisher/sequencer-bundle-simulator.ts +254 -0
  107. package/src/publisher/sequencer-publisher-factory.ts +38 -9
  108. package/src/publisher/sequencer-publisher.ts +532 -469
  109. package/src/sequencer/README.md +162 -450
  110. package/src/sequencer/automine/README.md +46 -0
  111. package/src/sequencer/automine/automine_factory.ts +145 -0
  112. package/src/sequencer/automine/automine_sequencer.ts +595 -0
  113. package/src/sequencer/chain_state_overrides.ts +162 -0
  114. package/src/sequencer/checkpoint_proposal_job.ts +1026 -268
  115. package/src/sequencer/checkpoint_proposal_job_metrics.ts +128 -0
  116. package/src/sequencer/checkpoint_voter.ts +1 -12
  117. package/src/sequencer/events.ts +51 -2
  118. package/src/sequencer/index.ts +2 -0
  119. package/src/sequencer/metrics.ts +132 -25
  120. package/src/sequencer/sequencer.ts +470 -156
  121. package/src/sequencer/timetable.ts +62 -56
  122. package/src/sequencer/types.ts +1 -1
  123. package/src/test/index.ts +2 -4
  124. package/src/test/mock_checkpoint_builder.ts +63 -49
  125. package/src/test/utils.ts +31 -10
@@ -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,12 @@ 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
+ /**
78
+ * How far into the target slot assembly and attestation collection can start when pipelining.
79
+ * Production-like timing keeps this at zero; fast local publishing profiles can use the attestation window.
80
+ */
81
+ public readonly pipeliningAttestationGracePeriod: number;
82
+
72
83
  constructor(
73
84
  opts: {
74
85
  ethereumSlotDuration: number;
@@ -79,59 +90,36 @@ export class SequencerTimetable {
79
90
  enforce: boolean;
80
91
  },
81
92
  private readonly metrics?: SequencerMetrics,
82
- private readonly log = createLogger('sequencer:timetable'),
93
+ private readonly log?: Logger,
83
94
  ) {
84
95
  this.ethereumSlotDuration = opts.ethereumSlotDuration;
85
96
  this.aztecSlotDuration = opts.aztecSlotDuration;
86
97
  this.l1PublishingTime = opts.l1PublishingTime;
87
- this.p2pPropagationTime = opts.p2pPropagationTime ?? DEFAULT_P2P_PROPAGATION_TIME;
88
98
  this.blockDuration = opts.blockDurationMs ? opts.blockDurationMs / 1000 : undefined;
89
99
  this.enforce = opts.enforce;
90
100
 
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
- }
101
+ this.checkpointTiming = createCheckpointTimingModel({
102
+ aztecSlotDuration: this.aztecSlotDuration,
103
+ ethereumSlotDuration: this.ethereumSlotDuration,
104
+ blockDuration: this.blockDuration,
105
+ l1PublishingTime: this.l1PublishingTime,
106
+ p2pPropagationTime: opts.p2pPropagationTime ?? DEFAULT_P2P_PROPAGATION_TIME,
107
+ });
98
108
 
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
- }
109
+ this.p2pPropagationTime = this.checkpointTiming.p2pPropagationTime;
110
+ this.checkpointAssembleTime = this.checkpointTiming.checkpointAssembleTime;
111
+ this.checkpointInitializationTime = this.checkpointTiming.checkpointInitializationTime;
112
+ this.minExecutionTime = this.checkpointTiming.minExecutionTime;
103
113
 
104
114
  // Calculate initialization offset - estimate of time needed for sync + proposer check
105
115
  // 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
- }
124
-
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;
116
+ this.initializationOffset = this.checkpointTiming.checkpointInitializationTime;
117
+ this.checkpointFinalizationTime = this.checkpointTiming.checkpointFinalizationTime;
118
+ this.pipeliningAttestationGracePeriod = this.checkpointTiming.pipeliningAttestationGracePeriod;
119
+ this.maxNumberOfBlocks = this.checkpointTiming.calculateMaxBlocksPerSlot();
120
+ this.initializeDeadline = this.checkpointTiming.initializeDeadline;
130
121
 
131
- const initializeDeadline = this.aztecSlotDuration - minWorkToDo;
132
- this.initializeDeadline = initializeDeadline;
133
-
134
- this.log.verbose(
122
+ this.log?.info(
135
123
  `Sequencer timetable initialized with ${this.maxNumberOfBlocks} blocks per slot (${this.enforce ? 'enforced' : 'not enforced'})`,
136
124
  {
137
125
  ethereumSlotDuration: this.ethereumSlotDuration,
@@ -143,19 +131,36 @@ export class SequencerTimetable {
143
131
  blockAssembleTime: this.checkpointAssembleTime,
144
132
  initializeDeadline: this.initializeDeadline,
145
133
  enforce: this.enforce,
146
- minWorkToDo,
134
+ pipeliningAttestationGracePeriod: this.pipeliningAttestationGracePeriod,
135
+ minWorkToDo: this.checkpointTiming.minimumBuildSlotWork,
147
136
  blockDuration: this.blockDuration,
148
137
  maxNumberOfBlocks: this.maxNumberOfBlocks,
149
138
  },
150
139
  );
151
140
 
152
- if (initializeDeadline <= 0) {
141
+ if (this.initializeDeadline <= 0) {
153
142
  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}).`,
143
+ `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
144
  );
156
145
  }
157
146
  }
158
147
 
148
+ public getCheckpointAssemblyDeadline(): number {
149
+ return this.checkpointTiming.checkpointAssemblyDeadline;
150
+ }
151
+
152
+ public getCheckpointAttestationDeadline(): number {
153
+ return this.checkpointTiming.checkpointAttestationDeadline;
154
+ }
155
+
156
+ public getCheckpointAttestationStartDeadline(): number {
157
+ return this.checkpointTiming.checkpointAttestationStartDeadline;
158
+ }
159
+
160
+ public getCheckpointPublishingDeadline(): number {
161
+ return this.checkpointTiming.checkpointPublishingDeadline;
162
+ }
163
+
159
164
  public getMaxAllowedTime(
160
165
  state: Extract<SequencerState, SequencerState.STOPPED | SequencerState.IDLE | SequencerState.SYNCHRONIZING>,
161
166
  ): undefined;
@@ -178,10 +183,11 @@ export class SequencerTimetable {
178
183
  case SequencerState.WAITING_UNTIL_NEXT_BLOCK:
179
184
  return this.initializeDeadline + this.checkpointInitializationTime;
180
185
  case SequencerState.ASSEMBLING_CHECKPOINT:
186
+ return this.getCheckpointAssemblyDeadline();
181
187
  case SequencerState.COLLECTING_ATTESTATIONS:
182
- return this.aztecSlotDuration - this.l1PublishingTime - 2 * this.p2pPropagationTime;
188
+ return this.getCheckpointAttestationStartDeadline();
183
189
  case SequencerState.PUBLISHING_CHECKPOINT:
184
- return this.aztecSlotDuration - this.l1PublishingTime;
190
+ return this.getCheckpointPublishingDeadline();
185
191
  default: {
186
192
  const _exhaustiveCheck: never = state;
187
193
  throw new Error(`Unexpected state: ${state}`);
@@ -205,7 +211,7 @@ export class SequencerTimetable {
205
211
  }
206
212
 
207
213
  this.metrics?.recordStateTransitionBufferMs(Math.floor(bufferSeconds * 1000), newState);
208
- this.log.trace(`Enough time to transition to ${newState}`, { maxAllowedTime, secondsIntoSlot });
214
+ this.log?.trace(`Enough time to transition to ${newState}`, { maxAllowedTime, secondsIntoSlot });
209
215
  }
210
216
 
211
217
  /**
@@ -241,7 +247,7 @@ export class SequencerTimetable {
241
247
  const canStart = available >= this.minExecutionTime;
242
248
  const deadline = secondsIntoSlot + available;
243
249
 
244
- this.log.verbose(
250
+ this.log?.verbose(
245
251
  `${canStart ? 'Can' : 'Cannot'} start single-block checkpoint at ${secondsIntoSlot}s into slot`,
246
252
  { secondsIntoSlot, maxAllowed, available, deadline },
247
253
  );
@@ -261,7 +267,7 @@ export class SequencerTimetable {
261
267
  // Found an available sub-slot! Is this the last one?
262
268
  const isLastBlock = subSlot === this.maxNumberOfBlocks;
263
269
 
264
- this.log.verbose(
270
+ this.log?.verbose(
265
271
  `Can start ${isLastBlock ? 'last block' : 'block'} in sub-slot ${subSlot} with deadline ${deadline}s`,
266
272
  { secondsIntoSlot, deadline, timeUntilDeadline, subSlot, maxBlocks: this.maxNumberOfBlocks },
267
273
  );
@@ -271,7 +277,7 @@ export class SequencerTimetable {
271
277
  }
272
278
 
273
279
  // No sub-slots available with enough time
274
- this.log.verbose(`No time left to start any more blocks`, {
280
+ this.log?.verbose(`No time left to start any more blocks`, {
275
281
  secondsIntoSlot,
276
282
  maxBlocks: this.maxNumberOfBlocks,
277
283
  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,18 +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
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
8
  import { Sequencer } from '../sequencer/sequencer.js';
10
9
  import type { SequencerTimetable } from '../sequencer/timetable.js';
11
10
 
12
11
  class TestSequencer_ extends Sequencer {
13
12
  declare public publicProcessorFactory: PublicProcessorFactory;
14
13
  declare public timetable: SequencerTimetable;
15
- declare public publisher: SequencerPublisher;
16
14
  declare public publisherFactory: SequencerPublisherFactory;
17
15
  declare public validatorClient: ValidatorClient;
18
16
  declare public checkpointsBuilder: FullNodeCheckpointsBuilder;
@@ -22,7 +20,7 @@ export type TestSequencer = TestSequencer_;
22
20
 
23
21
  class TestSequencerClient_ extends SequencerClient {
24
22
  declare public sequencer: TestSequencer;
25
- declare public publisherManager: PublisherManager<L1TxUtilsWithBlobs>;
23
+ declare public publisherManager: PublisherManager<L1TxUtils>;
26
24
  }
27
25
 
28
26
  export type TestSequencerClient = TestSequencerClient_;
@@ -1,14 +1,14 @@
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 { unfreeze } from '@aztec/foundation/types';
3
4
  import { L2Block } from '@aztec/stdlib/block';
4
5
  import { Checkpoint } from '@aztec/stdlib/checkpoint';
5
- import { Gas } from '@aztec/stdlib/gas';
6
6
  import type {
7
+ BlockBuilderOptions,
7
8
  FullNodeBlockBuilderConfig,
8
9
  ICheckpointBlockBuilder,
9
10
  ICheckpointsBuilder,
10
11
  MerkleTreeWriteOperations,
11
- PublicProcessorLimits,
12
12
  } from '@aztec/stdlib/interfaces/server';
13
13
  import { CheckpointHeader } from '@aztec/stdlib/rollup';
14
14
  import { makeAppendOnlyTreeSnapshot } from '@aztec/stdlib/testing';
@@ -32,7 +32,7 @@ export class MockCheckpointBuilder implements ICheckpointBlockBuilder {
32
32
  public buildBlockCalls: Array<{
33
33
  blockNumber: BlockNumber;
34
34
  timestamp: bigint;
35
- opts: PublicProcessorLimits;
35
+ opts: BlockBuilderOptions;
36
36
  }> = [];
37
37
  /** Track all consumed transaction hashes across buildBlock calls */
38
38
  public consumedTxHashes: Set<string> = new Set();
@@ -74,7 +74,7 @@ export class MockCheckpointBuilder implements ICheckpointBlockBuilder {
74
74
  pendingTxs: Iterable<Tx> | AsyncIterable<Tx>,
75
75
  blockNumber: BlockNumber,
76
76
  timestamp: bigint,
77
- opts: PublicProcessorLimits,
77
+ opts: BlockBuilderOptions,
78
78
  ): Promise<BuildBlockInCheckpointResult> {
79
79
  this.buildBlockCalls.push({ blockNumber, timestamp, opts });
80
80
 
@@ -86,8 +86,10 @@ export class MockCheckpointBuilder implements ICheckpointBlockBuilder {
86
86
  let usedTxs: Tx[];
87
87
 
88
88
  if (this.blockProvider) {
89
- // Dynamic mode: get block from provider
90
- 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();
91
93
  usedTxs = [];
92
94
  this.builtBlocks.push(block);
93
95
  } else {
@@ -113,81 +115,79 @@ export class MockCheckpointBuilder implements ICheckpointBlockBuilder {
113
115
 
114
116
  return {
115
117
  block,
116
- publicGas: Gas.empty(),
117
118
  publicProcessorDuration: 0,
118
119
  numTxs: block?.body?.txEffects?.length ?? usedTxs.length,
119
120
  usedTxs,
120
121
  failedTxs: [],
121
- usedTxBlobFields: block?.body?.txEffects?.reduce((sum, tx) => sum + tx.getNumBlobFields(), 0) ?? 0,
122
122
  };
123
123
  }
124
124
 
125
125
  completeCheckpoint(): Promise<Checkpoint> {
126
126
  this.completeCheckpointCalled = true;
127
127
  const allBlocks = this.blockProvider ? this.builtBlocks : this.blocks;
128
- const lastBlock = allBlocks[allBlocks.length - 1];
129
- // Create a CheckpointHeader from the last block's header for testing
130
- const checkpointHeader = this.createCheckpointHeader(lastBlock);
131
- return Promise.resolve(
132
- new Checkpoint(
133
- makeAppendOnlyTreeSnapshot(lastBlock.header.globalVariables.blockNumber + 1),
134
- checkpointHeader,
135
- allBlocks,
136
- this.checkpointNumber,
137
- ),
138
- );
128
+ return this.buildCheckpoint(allBlocks);
139
129
  }
140
130
 
141
131
  getCheckpoint(): Promise<Checkpoint> {
142
132
  this.getCheckpointCalled = true;
143
133
  const builtBlocks = this.blockProvider ? this.builtBlocks : this.blocks.slice(0, this.blockIndex);
144
- const lastBlock = builtBlocks[builtBlocks.length - 1];
145
- if (!lastBlock) {
134
+ if (builtBlocks.length === 0) {
146
135
  throw new Error('No blocks built yet');
147
136
  }
148
- // Create a CheckpointHeader from the last block's header for testing
149
- const checkpointHeader = this.createCheckpointHeader(lastBlock);
150
- return Promise.resolve(
151
- new Checkpoint(
152
- makeAppendOnlyTreeSnapshot(lastBlock.header.globalVariables.blockNumber + 1),
153
- checkpointHeader,
154
- builtBlocks,
155
- this.checkpointNumber,
156
- ),
157
- );
137
+ return this.buildCheckpoint(builtBlocks);
158
138
  }
159
139
 
160
- /**
161
- * Creates a CheckpointHeader from a block's header for testing.
162
- * This is a simplified version that creates a minimal CheckpointHeader.
163
- */
164
- private createCheckpointHeader(block: L2Block): CheckpointHeader {
165
- const header = block.header;
166
- const gv = header.globalVariables;
167
- return CheckpointHeader.empty({
168
- lastArchiveRoot: header.lastArchive.root,
169
- 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(),
170
158
  slotNumber: gv.slotNumber,
171
159
  timestamp: gv.timestamp,
172
160
  coinbase: gv.coinbase,
173
161
  feeRecipient: gv.feeRecipient,
174
162
  gasFees: gv.gasFees,
175
- totalManaUsed: header.totalManaUsed,
163
+ totalManaUsed: lastBlock.header.totalManaUsed,
176
164
  });
165
+
166
+ return new Checkpoint(
167
+ makeAppendOnlyTreeSnapshot(lastBlock.header.globalVariables.blockNumber + 1),
168
+ checkpointHeader,
169
+ blocks,
170
+ this.checkpointNumber,
171
+ );
177
172
  }
178
173
 
179
- /** Reset for reuse in another test */
180
- reset(): void {
181
- this.blocks = [];
174
+ /** Resets per-checkpoint state (built blocks, consumed txs) while preserving config (blockProvider, seeded blocks). */
175
+ resetCheckpointState(): void {
182
176
  this.builtBlocks = [];
183
- this.usedTxsPerBlock = [];
184
177
  this.blockIndex = 0;
185
- this.buildBlockCalls = [];
186
178
  this.consumedTxHashes.clear();
187
179
  this.completeCheckpointCalled = false;
188
180
  this.getCheckpointCalled = false;
181
+ }
182
+
183
+ /** Reset for reuse in another test */
184
+ reset(): void {
185
+ this.blocks = [];
186
+ this.usedTxsPerBlock = [];
187
+ this.buildBlockCalls = [];
189
188
  this.errorOnBuild = undefined;
190
189
  this.blockProvider = undefined;
190
+ this.resetCheckpointState();
191
191
  }
192
192
  }
193
193
 
@@ -205,6 +205,7 @@ export class MockCheckpointsBuilder implements ICheckpointsBuilder {
205
205
  constants: CheckpointGlobalVariables;
206
206
  l1ToL2Messages: Fr[];
207
207
  previousCheckpointOutHashes: Fr[];
208
+ feeAssetPriceModifier: bigint;
208
209
  }> = [];
209
210
  public openCheckpointCalls: Array<{
210
211
  checkpointNumber: CheckpointNumber;
@@ -212,6 +213,7 @@ export class MockCheckpointsBuilder implements ICheckpointsBuilder {
212
213
  l1ToL2Messages: Fr[];
213
214
  previousCheckpointOutHashes: Fr[];
214
215
  existingBlocks: L2Block[];
216
+ feeAssetPriceModifier: bigint;
215
217
  }> = [];
216
218
  public updateConfigCalls: Array<Partial<FullNodeBlockBuilderConfig>> = [];
217
219
 
@@ -247,6 +249,7 @@ export class MockCheckpointsBuilder implements ICheckpointsBuilder {
247
249
  slotDuration: 24,
248
250
  l1ChainId: 1,
249
251
  rollupVersion: 1,
252
+ rollupManaLimit: 200_000_000,
250
253
  };
251
254
  }
252
255
 
@@ -257,15 +260,24 @@ export class MockCheckpointsBuilder implements ICheckpointsBuilder {
257
260
  startCheckpoint(
258
261
  checkpointNumber: CheckpointNumber,
259
262
  constants: CheckpointGlobalVariables,
263
+ feeAssetPriceModifier: bigint,
260
264
  l1ToL2Messages: Fr[],
261
265
  previousCheckpointOutHashes: Fr[],
262
266
  _fork: MerkleTreeWriteOperations,
263
267
  ): Promise<ICheckpointBlockBuilder> {
264
- this.startCheckpointCalls.push({ checkpointNumber, constants, l1ToL2Messages, previousCheckpointOutHashes });
268
+ this.startCheckpointCalls.push({
269
+ checkpointNumber,
270
+ constants,
271
+ l1ToL2Messages,
272
+ previousCheckpointOutHashes,
273
+ feeAssetPriceModifier,
274
+ });
265
275
 
266
276
  if (!this.checkpointBuilder) {
267
277
  // Auto-create a builder if none was set
268
278
  this.checkpointBuilder = new MockCheckpointBuilder(constants, checkpointNumber);
279
+ } else {
280
+ this.checkpointBuilder.resetCheckpointState();
269
281
  }
270
282
 
271
283
  return Promise.resolve(this.checkpointBuilder);
@@ -274,6 +286,7 @@ export class MockCheckpointsBuilder implements ICheckpointsBuilder {
274
286
  openCheckpoint(
275
287
  checkpointNumber: CheckpointNumber,
276
288
  constants: CheckpointGlobalVariables,
289
+ feeAssetPriceModifier: bigint,
277
290
  l1ToL2Messages: Fr[],
278
291
  previousCheckpointOutHashes: Fr[],
279
292
  _fork: MerkleTreeWriteOperations,
@@ -285,6 +298,7 @@ export class MockCheckpointsBuilder implements ICheckpointsBuilder {
285
298
  l1ToL2Messages,
286
299
  previousCheckpointOutHashes,
287
300
  existingBlocks,
301
+ feeAssetPriceModifier,
288
302
  });
289
303
 
290
304
  if (!this.checkpointBuilder) {
package/src/test/utils.ts CHANGED
@@ -10,7 +10,11 @@ import { PublicDataWrite } from '@aztec/stdlib/avm';
10
10
  import { CommitteeAttestation, L2Block } from '@aztec/stdlib/block';
11
11
  import { BlockProposal, CheckpointAttestation, CheckpointProposal, ConsensusPayload } from '@aztec/stdlib/p2p';
12
12
  import { CheckpointHeader } from '@aztec/stdlib/rollup';
13
- import { makeAppendOnlyTreeSnapshot, mockTxForRollup } from '@aztec/stdlib/testing';
13
+ import {
14
+ TEST_COORDINATION_SIGNATURE_CONTEXT,
15
+ makeAppendOnlyTreeSnapshot,
16
+ mockTxForRollup,
17
+ } from '@aztec/stdlib/testing';
14
18
  import { BlockHeader, GlobalVariables, type Tx, makeProcessedTxFromPrivateOnlyTx } from '@aztec/stdlib/tx';
15
19
 
16
20
  import type { MockProxy } from 'jest-mock-extended';
@@ -56,6 +60,7 @@ export async function makeBlock(txs: Tx[], globalVariables: GlobalVariables): Pr
56
60
  export function mockPendingTxs(p2p: MockProxy<P2P>, txs: Tx[]): void {
57
61
  p2p.getPendingTxCount.mockResolvedValue(txs.length);
58
62
  p2p.iteratePendingTxs.mockImplementation(() => mockTxIterator(Promise.resolve(txs)));
63
+ p2p.iterateEligiblePendingTxs.mockImplementation(() => mockTxIterator(Promise.resolve(txs)));
59
64
  }
60
65
 
61
66
  /**
@@ -108,6 +113,7 @@ export function createBlockProposal(block: L2Block, signature: Signature): Block
108
113
  block.archive.root,
109
114
  txHashes,
110
115
  signature,
116
+ TEST_COORDINATION_SIGNATURE_CONTEXT,
111
117
  );
112
118
  }
113
119
 
@@ -118,15 +124,23 @@ export function createCheckpointProposal(
118
124
  block: L2Block,
119
125
  checkpointSignature: Signature,
120
126
  blockSignature?: Signature,
127
+ feeAssetPriceModifier: bigint = 0n,
121
128
  ): CheckpointProposal {
122
129
  const txHashes = block.body.txEffects.map(tx => tx.txHash);
123
130
  const checkpointHeader = createCheckpointHeaderFromBlock(block);
124
- return new CheckpointProposal(checkpointHeader, block.archive.root, checkpointSignature, {
125
- blockHeader: block.header,
126
- indexWithinCheckpoint: block.indexWithinCheckpoint,
127
- txHashes,
128
- signature: blockSignature ?? checkpointSignature, // Use checkpoint signature as block signature if not provided
129
- });
131
+ return new CheckpointProposal(
132
+ checkpointHeader,
133
+ block.archive.root,
134
+ feeAssetPriceModifier,
135
+ checkpointSignature,
136
+ TEST_COORDINATION_SIGNATURE_CONTEXT,
137
+ {
138
+ blockHeader: block.header,
139
+ indexWithinCheckpoint: block.indexWithinCheckpoint,
140
+ txHashes,
141
+ signature: blockSignature ?? checkpointSignature, // Use checkpoint signature as block signature if not provided
142
+ },
143
+ );
130
144
  }
131
145
 
132
146
  /**
@@ -138,12 +152,19 @@ export function createCheckpointAttestation(
138
152
  block: L2Block,
139
153
  signature: Signature,
140
154
  sender: EthAddress,
155
+ feeAssetPriceModifier: bigint = 0n,
141
156
  ): CheckpointAttestation {
142
157
  const checkpointHeader = createCheckpointHeaderFromBlock(block);
143
- const payload = new ConsensusPayload(checkpointHeader, block.archive.root);
158
+ const payload = new ConsensusPayload(
159
+ checkpointHeader,
160
+ block.archive.root,
161
+ feeAssetPriceModifier,
162
+ TEST_COORDINATION_SIGNATURE_CONTEXT,
163
+ );
144
164
  const attestation = new CheckpointAttestation(payload, signature, signature);
145
- // Set sender directly for testing (bypasses signature recovery)
146
- (attestation as any).sender = sender;
165
+ // Bypass signature recovery for testing since we use random signatures
166
+ (attestation as any).getSender = () => sender;
167
+ (attestation as any).getProposer = () => sender;
147
168
  return attestation;
148
169
  }
149
170