@aztec/sequencer-client 0.0.1-commit.10bd49492 → 0.0.1-commit.11bf3dd6e

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 (76) hide show
  1. package/dest/client/sequencer-client.d.ts +6 -12
  2. package/dest/client/sequencer-client.d.ts.map +1 -1
  3. package/dest/client/sequencer-client.js +30 -80
  4. package/dest/config.d.ts +4 -3
  5. package/dest/config.d.ts.map +1 -1
  6. package/dest/config.js +17 -13
  7. package/dest/global_variable_builder/fee_predictor.d.ts +37 -0
  8. package/dest/global_variable_builder/fee_predictor.d.ts.map +1 -0
  9. package/dest/global_variable_builder/fee_predictor.js +128 -0
  10. package/dest/global_variable_builder/fee_provider.d.ts +21 -0
  11. package/dest/global_variable_builder/fee_provider.d.ts.map +1 -0
  12. package/dest/global_variable_builder/fee_provider.js +58 -0
  13. package/dest/global_variable_builder/global_builder.d.ts +15 -14
  14. package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
  15. package/dest/global_variable_builder/global_builder.js +16 -50
  16. package/dest/global_variable_builder/index.d.ts +4 -2
  17. package/dest/global_variable_builder/index.d.ts.map +1 -1
  18. package/dest/global_variable_builder/index.js +2 -0
  19. package/dest/publisher/config.d.ts +13 -1
  20. package/dest/publisher/config.d.ts.map +1 -1
  21. package/dest/publisher/config.js +19 -4
  22. package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts +3 -4
  23. package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts.map +1 -1
  24. package/dest/publisher/sequencer-publisher-factory.d.ts +3 -5
  25. package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -1
  26. package/dest/publisher/sequencer-publisher-factory.js +2 -3
  27. package/dest/publisher/sequencer-publisher.d.ts +51 -43
  28. package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
  29. package/dest/publisher/sequencer-publisher.js +135 -111
  30. package/dest/sequencer/chain_state_overrides.d.ts +25 -0
  31. package/dest/sequencer/chain_state_overrides.d.ts.map +1 -0
  32. package/dest/sequencer/chain_state_overrides.js +39 -0
  33. package/dest/sequencer/checkpoint_proposal_job.d.ts +26 -7
  34. package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -1
  35. package/dest/sequencer/checkpoint_proposal_job.js +291 -181
  36. package/dest/sequencer/checkpoint_proposal_job_metrics.d.ts +34 -0
  37. package/dest/sequencer/checkpoint_proposal_job_metrics.d.ts.map +1 -0
  38. package/dest/sequencer/checkpoint_proposal_job_metrics.js +72 -0
  39. package/dest/sequencer/checkpoint_voter.d.ts +1 -2
  40. package/dest/sequencer/checkpoint_voter.d.ts.map +1 -1
  41. package/dest/sequencer/checkpoint_voter.js +2 -5
  42. package/dest/sequencer/events.d.ts +2 -1
  43. package/dest/sequencer/events.d.ts.map +1 -1
  44. package/dest/sequencer/metrics.d.ts +9 -10
  45. package/dest/sequencer/metrics.d.ts.map +1 -1
  46. package/dest/sequencer/metrics.js +23 -20
  47. package/dest/sequencer/sequencer.d.ts +21 -6
  48. package/dest/sequencer/sequencer.d.ts.map +1 -1
  49. package/dest/sequencer/sequencer.js +125 -60
  50. package/dest/sequencer/timetable.d.ts +14 -1
  51. package/dest/sequencer/timetable.d.ts.map +1 -1
  52. package/dest/sequencer/timetable.js +45 -36
  53. package/dest/test/mock_checkpoint_builder.d.ts +4 -4
  54. package/dest/test/mock_checkpoint_builder.d.ts.map +1 -1
  55. package/package.json +27 -28
  56. package/src/client/sequencer-client.ts +42 -108
  57. package/src/config.ts +20 -12
  58. package/src/global_variable_builder/README.md +44 -0
  59. package/src/global_variable_builder/fee_predictor.ts +172 -0
  60. package/src/global_variable_builder/fee_provider.ts +75 -0
  61. package/src/global_variable_builder/global_builder.ts +26 -62
  62. package/src/global_variable_builder/index.ts +3 -1
  63. package/src/publisher/config.ts +38 -4
  64. package/src/publisher/l1_tx_failed_store/failed_tx_store.ts +3 -1
  65. package/src/publisher/sequencer-publisher-factory.ts +3 -6
  66. package/src/publisher/sequencer-publisher.ts +202 -158
  67. package/src/sequencer/README.md +83 -13
  68. package/src/sequencer/chain_state_overrides.ts +87 -0
  69. package/src/sequencer/checkpoint_proposal_job.ts +379 -201
  70. package/src/sequencer/checkpoint_proposal_job_metrics.ts +128 -0
  71. package/src/sequencer/checkpoint_voter.ts +1 -12
  72. package/src/sequencer/events.ts +1 -1
  73. package/src/sequencer/metrics.ts +29 -25
  74. package/src/sequencer/sequencer.ts +185 -66
  75. package/src/sequencer/timetable.ts +57 -45
  76. package/src/test/mock_checkpoint_builder.ts +3 -3
@@ -2,8 +2,10 @@ import type { Logger } from '@aztec/foundation/log';
2
2
  import {
3
3
  CHECKPOINT_ASSEMBLE_TIME,
4
4
  CHECKPOINT_INITIALIZATION_TIME,
5
+ type CheckpointTiming,
5
6
  DEFAULT_P2P_PROPAGATION_TIME,
6
7
  MIN_EXECUTION_TIME,
8
+ createCheckpointTimingModel,
7
9
  } from '@aztec/stdlib/timetable';
8
10
 
9
11
  import { SequencerTooSlowError } from './errors.js';
@@ -11,6 +13,8 @@ import type { SequencerMetrics } from './metrics.js';
11
13
  import { SequencerState } from './utils.js';
12
14
 
13
15
  export class SequencerTimetable {
16
+ private readonly checkpointTiming: CheckpointTiming;
17
+
14
18
  /**
15
19
  * How late into the slot can we be to start working. Computed as the total time needed for assembling and publishing a block,
16
20
  * assuming an execution time equal to `minExecutionTime`, subtracted from the slot duration. This means that, if the proposer
@@ -70,6 +74,15 @@ export class SequencerTimetable {
70
74
  /** Maximum number of blocks that can be built in this slot configuration */
71
75
  public readonly maxNumberOfBlocks: number;
72
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
+
73
86
  constructor(
74
87
  opts: {
75
88
  ethereumSlotDuration: number;
@@ -78,6 +91,7 @@ export class SequencerTimetable {
78
91
  p2pPropagationTime?: number;
79
92
  blockDurationMs?: number;
80
93
  enforce: boolean;
94
+ pipelining?: boolean;
81
95
  },
82
96
  private readonly metrics?: SequencerMetrics,
83
97
  private readonly log?: Logger,
@@ -85,52 +99,31 @@ export class SequencerTimetable {
85
99
  this.ethereumSlotDuration = opts.ethereumSlotDuration;
86
100
  this.aztecSlotDuration = opts.aztecSlotDuration;
87
101
  this.l1PublishingTime = opts.l1PublishingTime;
88
- this.p2pPropagationTime = opts.p2pPropagationTime ?? DEFAULT_P2P_PROPAGATION_TIME;
89
102
  this.blockDuration = opts.blockDurationMs ? opts.blockDurationMs / 1000 : undefined;
90
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
+ });
91
114
 
92
- // Assume zero-cost propagation time and faster runs in test environments where L1 slot duration is shortened
93
- if (this.ethereumSlotDuration < 8) {
94
- this.p2pPropagationTime = 0;
95
- this.checkpointAssembleTime = 0.5;
96
- this.checkpointInitializationTime = 0.5;
97
- this.minExecutionTime = 1;
98
- }
99
-
100
- // Min execution time cannot be less than the block duration if set
101
- if (this.blockDuration !== undefined && this.minExecutionTime > this.blockDuration) {
102
- this.minExecutionTime = this.blockDuration;
103
- }
115
+ this.p2pPropagationTime = this.checkpointTiming.p2pPropagationTime;
116
+ this.checkpointAssembleTime = this.checkpointTiming.checkpointAssembleTime;
117
+ this.checkpointInitializationTime = this.checkpointTiming.checkpointInitializationTime;
118
+ this.minExecutionTime = this.checkpointTiming.minExecutionTime;
104
119
 
105
120
  // Calculate initialization offset - estimate of time needed for sync + proposer check
106
121
  // This is the baseline for all sub-slot deadlines
107
- this.initializationOffset = this.checkpointInitializationTime;
108
-
109
- // Calculate total checkpoint finalization time (assembly + attestations + L1 publishing)
110
- this.checkpointFinalizationTime =
111
- this.checkpointAssembleTime +
112
- this.p2pPropagationTime * 2 + // Round-trip propagation
113
- this.l1PublishingTime; // L1 publishing
114
-
115
- // Calculate maximum number of blocks that fit in this slot
116
- if (!this.blockDuration) {
117
- this.maxNumberOfBlocks = 1; // Single block per slot
118
- } else {
119
- const timeReservedAtEnd =
120
- this.blockDuration + // Last sub-slot for validator re-execution
121
- this.checkpointFinalizationTime; // Checkpoint finalization
122
- const timeAvailableForBlocks = this.aztecSlotDuration - this.initializationOffset - timeReservedAtEnd;
123
- this.maxNumberOfBlocks = Math.floor(timeAvailableForBlocks / this.blockDuration);
124
- }
125
-
126
- // Minimum work to do within a slot for building a block with the minimum time for execution and publishing its checkpoint
127
- const minWorkToDo =
128
- this.initializationOffset +
129
- this.minExecutionTime * 2 + // Execution and reexecution
130
- this.checkpointFinalizationTime;
131
-
132
- const initializeDeadline = this.aztecSlotDuration - minWorkToDo;
133
- this.initializeDeadline = initializeDeadline;
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;
134
127
 
135
128
  this.log?.info(
136
129
  `Sequencer timetable initialized with ${this.maxNumberOfBlocks} blocks per slot (${this.enforce ? 'enforced' : 'not enforced'})`,
@@ -144,19 +137,37 @@ export class SequencerTimetable {
144
137
  blockAssembleTime: this.checkpointAssembleTime,
145
138
  initializeDeadline: this.initializeDeadline,
146
139
  enforce: this.enforce,
147
- minWorkToDo,
140
+ pipelining: this.pipelining,
141
+ pipeliningAttestationGracePeriod: this.pipeliningAttestationGracePeriod,
142
+ minWorkToDo: this.checkpointTiming.minimumBuildSlotWork,
148
143
  blockDuration: this.blockDuration,
149
144
  maxNumberOfBlocks: this.maxNumberOfBlocks,
150
145
  },
151
146
  );
152
147
 
153
- if (initializeDeadline <= 0) {
148
+ if (this.initializeDeadline <= 0) {
154
149
  throw new Error(
155
- `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}).`,
156
151
  );
157
152
  }
158
153
  }
159
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
+
160
171
  public getMaxAllowedTime(
161
172
  state: Extract<SequencerState, SequencerState.STOPPED | SequencerState.IDLE | SequencerState.SYNCHRONIZING>,
162
173
  ): undefined;
@@ -179,10 +190,11 @@ export class SequencerTimetable {
179
190
  case SequencerState.WAITING_UNTIL_NEXT_BLOCK:
180
191
  return this.initializeDeadline + this.checkpointInitializationTime;
181
192
  case SequencerState.ASSEMBLING_CHECKPOINT:
193
+ return this.getCheckpointAssemblyDeadline();
182
194
  case SequencerState.COLLECTING_ATTESTATIONS:
183
- return this.aztecSlotDuration - this.l1PublishingTime - 2 * this.p2pPropagationTime;
195
+ return this.getCheckpointAttestationStartDeadline();
184
196
  case SequencerState.PUBLISHING_CHECKPOINT:
185
- return this.aztecSlotDuration - this.l1PublishingTime;
197
+ return this.getCheckpointPublishingDeadline();
186
198
  default: {
187
199
  const _exhaustiveCheck: never = state;
188
200
  throw new Error(`Unexpected state: ${state}`);
@@ -4,11 +4,11 @@ import { unfreeze } from '@aztec/foundation/types';
4
4
  import { L2Block } from '@aztec/stdlib/block';
5
5
  import { Checkpoint } from '@aztec/stdlib/checkpoint';
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