@aztec/sequencer-client 0.0.0-test.1 → 0.0.1-commit.017a351

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 (185) hide show
  1. package/README.md +281 -21
  2. package/dest/client/index.d.ts +1 -1
  3. package/dest/client/sequencer-client.d.ts +43 -33
  4. package/dest/client/sequencer-client.d.ts.map +1 -1
  5. package/dest/client/sequencer-client.js +117 -62
  6. package/dest/config.d.ts +38 -17
  7. package/dest/config.d.ts.map +1 -1
  8. package/dest/config.js +172 -85
  9. package/dest/global_variable_builder/fee_predictor.d.ts +37 -0
  10. package/dest/global_variable_builder/fee_predictor.d.ts.map +1 -0
  11. package/dest/global_variable_builder/fee_predictor.js +128 -0
  12. package/dest/global_variable_builder/fee_provider.d.ts +21 -0
  13. package/dest/global_variable_builder/fee_provider.d.ts.map +1 -0
  14. package/dest/global_variable_builder/fee_provider.js +58 -0
  15. package/dest/global_variable_builder/global_builder.d.ts +26 -17
  16. package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
  17. package/dest/global_variable_builder/global_builder.js +45 -61
  18. package/dest/global_variable_builder/index.d.ts +4 -2
  19. package/dest/global_variable_builder/index.d.ts.map +1 -1
  20. package/dest/global_variable_builder/index.js +2 -0
  21. package/dest/index.d.ts +2 -4
  22. package/dest/index.d.ts.map +1 -1
  23. package/dest/index.js +1 -3
  24. package/dest/publisher/config.d.ts +60 -27
  25. package/dest/publisher/config.d.ts.map +1 -1
  26. package/dest/publisher/config.js +124 -32
  27. package/dest/publisher/index.d.ts +4 -1
  28. package/dest/publisher/index.d.ts.map +1 -1
  29. package/dest/publisher/index.js +3 -0
  30. package/dest/publisher/l1_tx_failed_store/factory.d.ts +11 -0
  31. package/dest/publisher/l1_tx_failed_store/factory.d.ts.map +1 -0
  32. package/dest/publisher/l1_tx_failed_store/factory.js +22 -0
  33. package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts +58 -0
  34. package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts.map +1 -0
  35. package/dest/publisher/l1_tx_failed_store/failed_tx_store.js +1 -0
  36. package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts +15 -0
  37. package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts.map +1 -0
  38. package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.js +34 -0
  39. package/dest/publisher/l1_tx_failed_store/index.d.ts +4 -0
  40. package/dest/publisher/l1_tx_failed_store/index.d.ts.map +1 -0
  41. package/dest/publisher/l1_tx_failed_store/index.js +2 -0
  42. package/dest/publisher/sequencer-bundle-simulator.d.ts +96 -0
  43. package/dest/publisher/sequencer-bundle-simulator.d.ts.map +1 -0
  44. package/dest/publisher/sequencer-bundle-simulator.js +198 -0
  45. package/dest/publisher/sequencer-publisher-factory.d.ts +50 -0
  46. package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -0
  47. package/dest/publisher/sequencer-publisher-factory.js +75 -0
  48. package/dest/publisher/sequencer-publisher-metrics.d.ts +5 -4
  49. package/dest/publisher/sequencer-publisher-metrics.d.ts.map +1 -1
  50. package/dest/publisher/sequencer-publisher-metrics.js +34 -62
  51. package/dest/publisher/sequencer-publisher.d.ts +170 -97
  52. package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
  53. package/dest/publisher/sequencer-publisher.js +1255 -276
  54. package/dest/sequencer/automine/automine_factory.d.ts +54 -0
  55. package/dest/sequencer/automine/automine_factory.d.ts.map +1 -0
  56. package/dest/sequencer/automine/automine_factory.js +84 -0
  57. package/dest/sequencer/automine/automine_sequencer.d.ts +151 -0
  58. package/dest/sequencer/automine/automine_sequencer.d.ts.map +1 -0
  59. package/dest/sequencer/automine/automine_sequencer.js +509 -0
  60. package/dest/sequencer/chain_state_overrides.d.ts +61 -0
  61. package/dest/sequencer/chain_state_overrides.d.ts.map +1 -0
  62. package/dest/sequencer/chain_state_overrides.js +98 -0
  63. package/dest/sequencer/checkpoint_proposal_job.d.ts +150 -0
  64. package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -0
  65. package/dest/sequencer/checkpoint_proposal_job.js +1792 -0
  66. package/dest/sequencer/checkpoint_proposal_job_metrics.d.ts +34 -0
  67. package/dest/sequencer/checkpoint_proposal_job_metrics.d.ts.map +1 -0
  68. package/dest/sequencer/checkpoint_proposal_job_metrics.js +72 -0
  69. package/dest/sequencer/checkpoint_voter.d.ts +34 -0
  70. package/dest/sequencer/checkpoint_voter.d.ts.map +1 -0
  71. package/dest/sequencer/checkpoint_voter.js +106 -0
  72. package/dest/sequencer/config.d.ts +7 -1
  73. package/dest/sequencer/config.d.ts.map +1 -1
  74. package/dest/sequencer/errors.d.ts +11 -0
  75. package/dest/sequencer/errors.d.ts.map +1 -0
  76. package/dest/sequencer/errors.js +15 -0
  77. package/dest/sequencer/events.d.ts +92 -0
  78. package/dest/sequencer/events.d.ts.map +1 -0
  79. package/dest/sequencer/events.js +1 -0
  80. package/dest/sequencer/index.d.ts +6 -2
  81. package/dest/sequencer/index.d.ts.map +1 -1
  82. package/dest/sequencer/index.js +5 -1
  83. package/dest/sequencer/metrics.d.ts +64 -13
  84. package/dest/sequencer/metrics.d.ts.map +1 -1
  85. package/dest/sequencer/metrics.js +309 -68
  86. package/dest/sequencer/sequencer.d.ts +205 -135
  87. package/dest/sequencer/sequencer.d.ts.map +1 -1
  88. package/dest/sequencer/sequencer.js +1208 -523
  89. package/dest/sequencer/timetable.d.ts +85 -25
  90. package/dest/sequencer/timetable.d.ts.map +1 -1
  91. package/dest/sequencer/timetable.js +177 -60
  92. package/dest/sequencer/types.d.ts +3 -0
  93. package/dest/sequencer/types.d.ts.map +1 -0
  94. package/dest/sequencer/types.js +1 -0
  95. package/dest/sequencer/utils.d.ts +20 -38
  96. package/dest/sequencer/utils.d.ts.map +1 -1
  97. package/dest/sequencer/utils.js +12 -47
  98. package/dest/test/index.d.ts +9 -3
  99. package/dest/test/index.d.ts.map +1 -1
  100. package/dest/test/index.js +0 -4
  101. package/dest/test/mock_checkpoint_builder.d.ts +95 -0
  102. package/dest/test/mock_checkpoint_builder.d.ts.map +1 -0
  103. package/dest/test/mock_checkpoint_builder.js +231 -0
  104. package/dest/test/utils.d.ts +53 -0
  105. package/dest/test/utils.d.ts.map +1 -0
  106. package/dest/test/utils.js +105 -0
  107. package/package.json +46 -45
  108. package/src/client/sequencer-client.ts +158 -103
  109. package/src/config.ts +201 -99
  110. package/src/global_variable_builder/README.md +44 -0
  111. package/src/global_variable_builder/fee_predictor.ts +172 -0
  112. package/src/global_variable_builder/fee_provider.ts +75 -0
  113. package/src/global_variable_builder/global_builder.ts +68 -76
  114. package/src/global_variable_builder/index.ts +3 -1
  115. package/src/index.ts +10 -3
  116. package/src/publisher/config.ts +184 -59
  117. package/src/publisher/index.ts +7 -0
  118. package/src/publisher/l1_tx_failed_store/factory.ts +32 -0
  119. package/src/publisher/l1_tx_failed_store/failed_tx_store.ts +57 -0
  120. package/src/publisher/l1_tx_failed_store/file_store_failed_tx_store.ts +46 -0
  121. package/src/publisher/l1_tx_failed_store/index.ts +3 -0
  122. package/src/publisher/sequencer-bundle-simulator.ts +254 -0
  123. package/src/publisher/sequencer-publisher-factory.ts +121 -0
  124. package/src/publisher/sequencer-publisher-metrics.ts +33 -63
  125. package/src/publisher/sequencer-publisher.ts +1101 -350
  126. package/src/sequencer/README.md +243 -0
  127. package/src/sequencer/automine/README.md +46 -0
  128. package/src/sequencer/automine/automine_factory.ts +145 -0
  129. package/src/sequencer/automine/automine_sequencer.ts +595 -0
  130. package/src/sequencer/chain_state_overrides.ts +162 -0
  131. package/src/sequencer/checkpoint_proposal_job.ts +1632 -0
  132. package/src/sequencer/checkpoint_proposal_job_metrics.ts +128 -0
  133. package/src/sequencer/checkpoint_voter.ts +119 -0
  134. package/src/sequencer/config.ts +8 -0
  135. package/src/sequencer/errors.ts +21 -0
  136. package/src/sequencer/events.ts +76 -0
  137. package/src/sequencer/index.ts +5 -1
  138. package/src/sequencer/metrics.ts +397 -75
  139. package/src/sequencer/sequencer.ts +1013 -579
  140. package/src/sequencer/timetable.ts +225 -60
  141. package/src/sequencer/types.ts +6 -0
  142. package/src/sequencer/utils.ts +28 -60
  143. package/src/test/index.ts +11 -5
  144. package/src/test/mock_checkpoint_builder.ts +323 -0
  145. package/src/test/utils.ts +185 -0
  146. package/dest/sequencer/allowed.d.ts +0 -3
  147. package/dest/sequencer/allowed.d.ts.map +0 -1
  148. package/dest/sequencer/allowed.js +0 -27
  149. package/dest/slasher/factory.d.ts +0 -7
  150. package/dest/slasher/factory.d.ts.map +0 -1
  151. package/dest/slasher/factory.js +0 -8
  152. package/dest/slasher/index.d.ts +0 -3
  153. package/dest/slasher/index.d.ts.map +0 -1
  154. package/dest/slasher/index.js +0 -2
  155. package/dest/slasher/slasher_client.d.ts +0 -75
  156. package/dest/slasher/slasher_client.d.ts.map +0 -1
  157. package/dest/slasher/slasher_client.js +0 -132
  158. package/dest/tx_validator/archive_cache.d.ts +0 -14
  159. package/dest/tx_validator/archive_cache.d.ts.map +0 -1
  160. package/dest/tx_validator/archive_cache.js +0 -22
  161. package/dest/tx_validator/gas_validator.d.ts +0 -14
  162. package/dest/tx_validator/gas_validator.d.ts.map +0 -1
  163. package/dest/tx_validator/gas_validator.js +0 -78
  164. package/dest/tx_validator/nullifier_cache.d.ts +0 -16
  165. package/dest/tx_validator/nullifier_cache.d.ts.map +0 -1
  166. package/dest/tx_validator/nullifier_cache.js +0 -24
  167. package/dest/tx_validator/phases_validator.d.ts +0 -12
  168. package/dest/tx_validator/phases_validator.d.ts.map +0 -1
  169. package/dest/tx_validator/phases_validator.js +0 -80
  170. package/dest/tx_validator/test_utils.d.ts +0 -23
  171. package/dest/tx_validator/test_utils.d.ts.map +0 -1
  172. package/dest/tx_validator/test_utils.js +0 -26
  173. package/dest/tx_validator/tx_validator_factory.d.ts +0 -18
  174. package/dest/tx_validator/tx_validator_factory.d.ts.map +0 -1
  175. package/dest/tx_validator/tx_validator_factory.js +0 -50
  176. package/src/sequencer/allowed.ts +0 -36
  177. package/src/slasher/factory.ts +0 -15
  178. package/src/slasher/index.ts +0 -2
  179. package/src/slasher/slasher_client.ts +0 -193
  180. package/src/tx_validator/archive_cache.ts +0 -28
  181. package/src/tx_validator/gas_validator.ts +0 -101
  182. package/src/tx_validator/nullifier_cache.ts +0 -30
  183. package/src/tx_validator/phases_validator.ts +0 -98
  184. package/src/tx_validator/test_utils.ts +0 -48
  185. package/src/tx_validator/tx_validator_factory.ts +0 -120
@@ -1,87 +1,193 @@
1
- import { createLogger } from '@aztec/aztec.js';
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
 
11
+ import { SequencerTooSlowError } from './errors.js';
3
12
  import type { SequencerMetrics } from './metrics.js';
4
13
  import { SequencerState } from './utils.js';
5
14
 
6
15
  export class SequencerTimetable {
7
- /** How late into the slot can we be to start working */
8
- public readonly initialTime = 3;
16
+ private readonly checkpointTiming: CheckpointTiming;
9
17
 
10
- /** How long it takes to get ready to start building */
11
- public readonly blockPrepareTime = 1;
18
+ /**
19
+ * How late into the slot can we be to start working. Computed as the total time needed for assembling and publishing a block,
20
+ * assuming an execution time equal to `minExecutionTime`, subtracted from the slot duration. This means that, if the proposer
21
+ * starts building at this time, and all times hold, it will have at least `minExecutionTime` to execute txs for the block.
22
+ */
23
+ public readonly initializeDeadline: number;
12
24
 
13
- /** How long it takes to for proposals and attestations to travel across the p2p layer (one-way) */
14
- public readonly attestationPropagationTime = 2;
25
+ /**
26
+ * Fixed time offset (in seconds) when the first sub-slot starts, used as baseline for all block deadlines.
27
+ * This is an estimate of how long initialization (sync + proposer check) typically takes.
28
+ * If actual initialization takes longer/shorter, blocks just get less/more time accordingly.
29
+ */
30
+ public readonly initializationOffset: number;
15
31
 
16
- /** How much time we spend validating and processing a block after building it, and assembling the proposal to send to attestors */
17
- public readonly blockValidationTime = 1;
32
+ /**
33
+ * Total time needed to finalize and publish a checkpoint, including:
34
+ * - Assembling the checkpoint
35
+ * - Round-trip p2p propagation for the checkpoint proposal and its corresponding attestations
36
+ * - Publishing to L1
37
+ */
38
+ public readonly checkpointFinalizationTime: number;
18
39
 
19
40
  /**
20
41
  * How long it takes to get a published block into L1. L1 builders typically accept txs up to 4 seconds into their slot,
21
42
  * but we'll timeout sooner to give it more time to propagate (remember we also have blobs!). Still, when working in anvil,
22
43
  * we can just post in the very last second of the L1 slot and still expect the tx to be accepted.
23
44
  */
24
- public readonly l1PublishingTime;
45
+ public readonly l1PublishingTime: number;
46
+
47
+ /**
48
+ * What's the minimum time we want to leave available for execution and reexecution (used to derive init deadline)
49
+ * Defaults to half of the block duration if set, otherwise a constant.
50
+ */
51
+ public readonly minExecutionTime: number = MIN_EXECUTION_TIME;
52
+
53
+ /** How long it takes to get ready to start building */
54
+ public readonly checkpointInitializationTime: number = CHECKPOINT_INITIALIZATION_TIME;
55
+
56
+ /** How long it takes to for proposals and attestations to travel across the p2p layer (one-way) */
57
+ public readonly p2pPropagationTime: number;
58
+
59
+ /** How much time we spend assembling a checkpoint after building the last block */
60
+ public readonly checkpointAssembleTime: number = CHECKPOINT_ASSEMBLE_TIME;
61
+
62
+ /** Ethereum slot duration in seconds */
63
+ public readonly ethereumSlotDuration: number;
64
+
65
+ /** Aztec slot duration in seconds (must be multiple of ethereum slot duration) */
66
+ public readonly aztecSlotDuration: number;
67
+
68
+ /** Whether assertTimeLeft will throw if not enough time. */
69
+ public readonly enforce: boolean;
70
+
71
+ /** Duration per block when building multiple blocks per slot (undefined = single block per slot) */
72
+ public readonly blockDuration: number | undefined;
73
+
74
+ /** Maximum number of blocks that can be built in this slot configuration */
75
+ public readonly maxNumberOfBlocks: number;
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;
25
82
 
26
83
  constructor(
27
- private readonly ethereumSlotDuration: number,
28
- private readonly aztecSlotDuration: number,
29
- private readonly maxL1TxInclusionTimeIntoSlot: number,
30
- private readonly enforce: boolean = true,
84
+ opts: {
85
+ ethereumSlotDuration: number;
86
+ aztecSlotDuration: number;
87
+ l1PublishingTime: number;
88
+ p2pPropagationTime?: number;
89
+ blockDurationMs?: number;
90
+ enforce: boolean;
91
+ },
31
92
  private readonly metrics?: SequencerMetrics,
32
- private readonly log = createLogger('sequencer:timetable'),
93
+ private readonly log?: Logger,
33
94
  ) {
34
- this.l1PublishingTime = this.ethereumSlotDuration - this.maxL1TxInclusionTimeIntoSlot;
95
+ this.ethereumSlotDuration = opts.ethereumSlotDuration;
96
+ this.aztecSlotDuration = opts.aztecSlotDuration;
97
+ this.l1PublishingTime = opts.l1PublishingTime;
98
+ this.blockDuration = opts.blockDurationMs ? opts.blockDurationMs / 1000 : undefined;
99
+ this.enforce = opts.enforce;
100
+
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
+ });
108
+
109
+ this.p2pPropagationTime = this.checkpointTiming.p2pPropagationTime;
110
+ this.checkpointAssembleTime = this.checkpointTiming.checkpointAssembleTime;
111
+ this.checkpointInitializationTime = this.checkpointTiming.checkpointInitializationTime;
112
+ this.minExecutionTime = this.checkpointTiming.minExecutionTime;
113
+
114
+ // Calculate initialization offset - estimate of time needed for sync + proposer check
115
+ // This is the baseline for all sub-slot deadlines
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;
121
+
122
+ this.log?.info(
123
+ `Sequencer timetable initialized with ${this.maxNumberOfBlocks} blocks per slot (${this.enforce ? 'enforced' : 'not enforced'})`,
124
+ {
125
+ ethereumSlotDuration: this.ethereumSlotDuration,
126
+ aztecSlotDuration: this.aztecSlotDuration,
127
+ l1PublishingTime: this.l1PublishingTime,
128
+ minExecutionTime: this.minExecutionTime,
129
+ blockPrepareTime: this.checkpointInitializationTime,
130
+ p2pPropagationTime: this.p2pPropagationTime,
131
+ blockAssembleTime: this.checkpointAssembleTime,
132
+ initializeDeadline: this.initializeDeadline,
133
+ enforce: this.enforce,
134
+ pipeliningAttestationGracePeriod: this.pipeliningAttestationGracePeriod,
135
+ minWorkToDo: this.checkpointTiming.minimumBuildSlotWork,
136
+ blockDuration: this.blockDuration,
137
+ maxNumberOfBlocks: this.maxNumberOfBlocks,
138
+ },
139
+ );
140
+
141
+ if (this.initializeDeadline <= 0) {
142
+ throw new Error(
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}).`,
144
+ );
145
+ }
35
146
  }
36
147
 
37
- private get afterBlockBuildingTimeNeededWithoutReexec() {
38
- return this.blockValidationTime + this.attestationPropagationTime * 2 + this.l1PublishingTime;
148
+ public getCheckpointAssemblyDeadline(): number {
149
+ return this.checkpointTiming.checkpointAssemblyDeadline;
39
150
  }
40
151
 
41
- public getBlockProposalExecTimeEnd(secondsIntoSlot: number): number {
42
- // We are N seconds into the slot. We need to account for `afterBlockBuildingTimeNeededWithoutReexec` seconds,
43
- // send then split the remaining time between the re-execution and the block building.
44
- const maxAllowed = this.aztecSlotDuration - this.afterBlockBuildingTimeNeededWithoutReexec;
45
- const available = maxAllowed - secondsIntoSlot;
46
- const executionTimeEnd = secondsIntoSlot + available / 2;
47
- this.log.debug(`Block proposal execution time deadline is ${executionTimeEnd}`, {
48
- secondsIntoSlot,
49
- maxAllowed,
50
- available,
51
- executionTimeEnd,
52
- });
53
- return executionTimeEnd;
152
+ public getCheckpointAttestationDeadline(): number {
153
+ return this.checkpointTiming.checkpointAttestationDeadline;
54
154
  }
55
155
 
56
- private get afterBlockReexecTimeNeeded() {
57
- return this.attestationPropagationTime + this.l1PublishingTime;
156
+ public getCheckpointAttestationStartDeadline(): number {
157
+ return this.checkpointTiming.checkpointAttestationStartDeadline;
58
158
  }
59
159
 
60
- public getValidatorReexecTimeEnd(secondsIntoSlot: number): number {
61
- // We need to leave for `afterBlockReexecTimeNeeded` seconds available.
62
- const validationTimeEnd = this.aztecSlotDuration - this.afterBlockReexecTimeNeeded;
63
- this.log.debug(`Validator re-execution time deadline is ${validationTimeEnd}`, {
64
- secondsIntoSlot,
65
- validationTimeEnd,
66
- });
67
- return validationTimeEnd;
160
+ public getCheckpointPublishingDeadline(): number {
161
+ return this.checkpointTiming.checkpointPublishingDeadline;
68
162
  }
69
163
 
164
+ public getMaxAllowedTime(
165
+ state: Extract<SequencerState, SequencerState.STOPPED | SequencerState.IDLE | SequencerState.SYNCHRONIZING>,
166
+ ): undefined;
167
+ public getMaxAllowedTime(
168
+ state: Exclude<SequencerState, SequencerState.STOPPED | SequencerState.IDLE | SequencerState.SYNCHRONIZING>,
169
+ ): number;
170
+ public getMaxAllowedTime(state: SequencerState): number | undefined;
70
171
  public getMaxAllowedTime(state: SequencerState): number | undefined {
71
172
  switch (state) {
72
173
  case SequencerState.STOPPED:
174
+ case SequencerState.STOPPING:
73
175
  case SequencerState.IDLE:
74
176
  case SequencerState.SYNCHRONIZING:
75
- case SequencerState.PROPOSER_CHECK:
76
177
  return; // We don't really care about times for this states
77
- case SequencerState.INITIALIZING_PROPOSAL:
78
- return this.initialTime;
178
+ case SequencerState.PROPOSER_CHECK:
179
+ case SequencerState.INITIALIZING_CHECKPOINT:
180
+ return this.initializeDeadline;
181
+ case SequencerState.WAITING_FOR_TXS:
79
182
  case SequencerState.CREATING_BLOCK:
80
- return this.initialTime + this.blockPrepareTime;
183
+ case SequencerState.WAITING_UNTIL_NEXT_BLOCK:
184
+ return this.initializeDeadline + this.checkpointInitializationTime;
185
+ case SequencerState.ASSEMBLING_CHECKPOINT:
186
+ return this.getCheckpointAssemblyDeadline();
81
187
  case SequencerState.COLLECTING_ATTESTATIONS:
82
- return this.aztecSlotDuration - this.l1PublishingTime - 2 * this.attestationPropagationTime;
83
- case SequencerState.PUBLISHING_BLOCK:
84
- return this.aztecSlotDuration - this.l1PublishingTime;
188
+ return this.getCheckpointAttestationStartDeadline();
189
+ case SequencerState.PUBLISHING_CHECKPOINT:
190
+ return this.getCheckpointPublishingDeadline();
85
191
  default: {
86
192
  const _exhaustiveCheck: never = state;
87
193
  throw new Error(`Unexpected state: ${state}`);
@@ -105,19 +211,78 @@ export class SequencerTimetable {
105
211
  }
106
212
 
107
213
  this.metrics?.recordStateTransitionBufferMs(Math.floor(bufferSeconds * 1000), newState);
108
- this.log.trace(`Enough time to transition to ${newState}`, { maxAllowedTime, secondsIntoSlot });
214
+ this.log?.trace(`Enough time to transition to ${newState}`, { maxAllowedTime, secondsIntoSlot });
109
215
  }
110
- }
111
216
 
112
- export class SequencerTooSlowError extends Error {
113
- constructor(
114
- public readonly proposedState: SequencerState,
115
- public readonly maxAllowedTime: number,
116
- public readonly currentTime: number,
117
- ) {
118
- super(
119
- `Too far into slot for ${proposedState} (time into slot ${currentTime}s greater than ${maxAllowedTime}s allowance)`,
120
- );
121
- this.name = 'SequencerTooSlowError';
217
+ /**
218
+ * Determines if we can start building the next block and returns its deadline.
219
+ *
220
+ * The timetable divides the slot into fixed sub-slots. This method finds the next
221
+ * available sub-slot that has enough time remaining to build a block.
222
+ *
223
+ * @param secondsIntoSlot - Current time (seconds into the slot)
224
+ * @returns Object with canStart flag, deadline, and whether this is the last block
225
+ */
226
+ public canStartNextBlock(
227
+ secondsIntoSlot: number,
228
+ ):
229
+ | { canStart: true; deadline: undefined; isLastBlock: true }
230
+ | { canStart: false; deadline: undefined; isLastBlock: false }
231
+ | { canStart: boolean; deadline: number; isLastBlock: boolean } {
232
+ // When timetable enforcement is disabled, always allow starting,
233
+ // and build a single block with no deadline. This is here just to
234
+ // satisfy a subset of e2e tests and the sandbox that assume that the
235
+ // sequencer is permanently mining every tx sent.
236
+ if (!this.enforce) {
237
+ return { canStart: true, deadline: undefined, isLastBlock: true };
238
+ }
239
+
240
+ // If no block duration is set, then we're in single-block mode, which
241
+ // is handled for backwards compatibility towards another subset of e2e tests.
242
+ if (this.blockDuration === undefined) {
243
+ // In single block mode, execution and re-execution happen sequentially, so we need to
244
+ // split the available time between them. After building, we need time for attestations and L1.
245
+ const maxAllowed = this.aztecSlotDuration - this.checkpointFinalizationTime;
246
+ const available = (maxAllowed - secondsIntoSlot) / 2; // Split remaining time: half for execution, half for re-execution
247
+ const canStart = available >= this.minExecutionTime;
248
+ const deadline = secondsIntoSlot + available;
249
+
250
+ this.log?.verbose(
251
+ `${canStart ? 'Can' : 'Cannot'} start single-block checkpoint at ${secondsIntoSlot}s into slot`,
252
+ { secondsIntoSlot, maxAllowed, available, deadline },
253
+ );
254
+ return { canStart, deadline, isLastBlock: true };
255
+ }
256
+
257
+ // Otherwise, we're in multi-block-per-slot mode, the default when running in production
258
+ // Find the next available sub-slot that has enough time remaining
259
+ for (let subSlot = 1; subSlot <= this.maxNumberOfBlocks; subSlot++) {
260
+ // Calculate end for this sub-slot
261
+ const deadline = this.initializationOffset + subSlot * this.blockDuration;
262
+
263
+ // Check if we have enough time to build a block with this deadline
264
+ const timeUntilDeadline = deadline - secondsIntoSlot;
265
+
266
+ if (timeUntilDeadline >= this.minExecutionTime) {
267
+ // Found an available sub-slot! Is this the last one?
268
+ const isLastBlock = subSlot === this.maxNumberOfBlocks;
269
+
270
+ this.log?.verbose(
271
+ `Can start ${isLastBlock ? 'last block' : 'block'} in sub-slot ${subSlot} with deadline ${deadline}s`,
272
+ { secondsIntoSlot, deadline, timeUntilDeadline, subSlot, maxBlocks: this.maxNumberOfBlocks },
273
+ );
274
+
275
+ return { canStart: true, deadline, isLastBlock };
276
+ }
277
+ }
278
+
279
+ // No sub-slots available with enough time
280
+ this.log?.verbose(`No time left to start any more blocks`, {
281
+ secondsIntoSlot,
282
+ maxBlocks: this.maxNumberOfBlocks,
283
+ initializationOffset: this.initializationOffset,
284
+ });
285
+
286
+ return { canStart: false, deadline: undefined, isLastBlock: false };
122
287
  }
123
288
  }
@@ -0,0 +1,6 @@
1
+ import type { L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
2
+
3
+ export type SequencerRollupConstants = Pick<
4
+ L1RollupConstants,
5
+ 'ethereumSlotDuration' | 'l1GenesisTime' | 'slotDuration' | 'rollupManaLimit' | 'epochDuration'
6
+ >;
@@ -1,74 +1,42 @@
1
- import type { EthAddress } from '@aztec/foundation/eth-address';
2
- import { Signature } from '@aztec/foundation/eth-signature';
3
- import type { BlockAttestation } from '@aztec/stdlib/p2p';
4
-
5
1
  export enum SequencerState {
6
- /**
7
- * Sequencer is stopped and not processing any txs from the pool.
8
- */
2
+ /** Sequencer is stopped and not processing any txs from the pool. */
9
3
  STOPPED = 'STOPPED',
10
- /**
11
- * Sequencer is awaiting the next call to work().
12
- */
4
+ /** Sequencer is being stopped. Will move to STOPPED shortly. */
5
+ STOPPING = 'STOPPING',
6
+ /** Sequencer is awaiting the next call to work(). */
13
7
  IDLE = 'IDLE',
14
- /**
15
- * Synchronizing with the L2 chain.
16
- */
8
+ /** Synchronizing with the L2 chain. */
17
9
  SYNCHRONIZING = 'SYNCHRONIZING',
18
- /**
19
- * Checking if we are the proposer for the current slot.
20
- */
10
+ /** Checking if we are the proposer for the current slot. */
21
11
  PROPOSER_CHECK = 'PROPOSER_CHECK',
22
- /**
23
- * Initializing the block proposal. Will move to CREATING_BLOCK if there are valid txs to include, or back to SYNCHRONIZING otherwise.
24
- */
25
- INITIALIZING_PROPOSAL = 'INITIALIZING_PROPOSAL',
26
- /**
27
- * Creating a new L2 block. Includes processing public function calls and running rollup circuits. Will move to PUBLISHING_CONTRACT_DATA.
28
- */
12
+ /** Initializing the checkpoint proposal. */
13
+ INITIALIZING_CHECKPOINT = 'INITIALIZING_CHECKPOINT',
14
+ /** Waiting for transactions to arrive in the pool. */
15
+ WAITING_FOR_TXS = 'WAITING_FOR_TXS',
16
+ /** Creating a new L2 block. Includes processing public function calls. */
29
17
  CREATING_BLOCK = 'CREATING_BLOCK',
30
- /**
31
- * Collecting attestations from its peers. Will move to PUBLISHING_BLOCK.
32
- */
18
+ /** Waiting until the next block can be created. */
19
+ WAITING_UNTIL_NEXT_BLOCK = 'WAITING_UNTIL_NEXT_BLOCK',
20
+ /** Assembling and broadcasting the checkpoint. */
21
+ ASSEMBLING_CHECKPOINT = 'ASSEMBLING_CHECKPOINT',
22
+ /** Collecting attestations from its peers. */
33
23
  COLLECTING_ATTESTATIONS = 'COLLECTING_ATTESTATIONS',
34
- /**
35
- * Sending the tx to L1 with the L2 block data and awaiting it to be mined. Will move to SYNCHRONIZING.
36
- */
37
- PUBLISHING_BLOCK = 'PUBLISHING_BLOCK',
24
+ /** Sending the tx to L1 with the L2 checkpoint data and awaiting it to be mined.. */
25
+ PUBLISHING_CHECKPOINT = 'PUBLISHING_CHECKPOINT',
38
26
  }
39
27
 
28
+ export type SequencerStateWithSlot =
29
+ | SequencerState.INITIALIZING_CHECKPOINT
30
+ | SequencerState.WAITING_FOR_TXS
31
+ | SequencerState.CREATING_BLOCK
32
+ | SequencerState.WAITING_UNTIL_NEXT_BLOCK
33
+ | SequencerState.COLLECTING_ATTESTATIONS
34
+ | SequencerState.PUBLISHING_CHECKPOINT
35
+ | SequencerState.PROPOSER_CHECK
36
+ | SequencerState.ASSEMBLING_CHECKPOINT;
37
+
40
38
  export type SequencerStateCallback = () => SequencerState;
41
39
 
42
40
  export function sequencerStateToNumber(state: SequencerState): number {
43
41
  return Object.values(SequencerState).indexOf(state);
44
42
  }
45
-
46
- /** Order Attestations
47
- *
48
- * Returns attestation signatures in the order of a series of provided ethereum addresses
49
- * The rollup smart contract expects attestations to appear in the order of the committee
50
- *
51
- * @todo: perform this logic within the memory attestation store instead?
52
- */
53
- export async function orderAttestations(
54
- attestations: BlockAttestation[],
55
- orderAddresses: EthAddress[],
56
- ): Promise<Signature[]> {
57
- // Create a map of sender addresses to BlockAttestations
58
- const attestationMap = new Map<string, BlockAttestation>();
59
-
60
- for (const attestation of attestations) {
61
- const sender = await attestation.getSender();
62
- if (sender) {
63
- attestationMap.set(sender.toString(), attestation);
64
- }
65
- }
66
-
67
- // Create the ordered array based on the orderAddresses, else return an empty signature
68
- const orderedAttestations = orderAddresses.map(address => {
69
- const addressString = address.toString();
70
- return attestationMap.get(addressString)?.signature || Signature.empty();
71
- });
72
-
73
- return orderedAttestations;
74
- }
package/src/test/index.ts CHANGED
@@ -1,20 +1,26 @@
1
+ import type { L1TxUtils } from '@aztec/ethereum/l1-tx-utils';
2
+ import type { PublisherManager } from '@aztec/ethereum/publisher-manager';
1
3
  import type { PublicProcessorFactory } from '@aztec/simulator/server';
4
+ import type { FullNodeCheckpointsBuilder, ValidatorClient } from '@aztec/validator-client';
2
5
 
3
6
  import { SequencerClient } from '../client/sequencer-client.js';
4
- import type { SequencerPublisher } from '../publisher/sequencer-publisher.js';
7
+ import type { SequencerPublisherFactory } from '../publisher/sequencer-publisher-factory.js';
5
8
  import { Sequencer } from '../sequencer/sequencer.js';
6
9
  import type { SequencerTimetable } from '../sequencer/timetable.js';
7
10
 
8
11
  class TestSequencer_ extends Sequencer {
9
- public override publicProcessorFactory!: PublicProcessorFactory;
10
- public override timetable!: SequencerTimetable;
11
- public override publisher!: SequencerPublisher;
12
+ declare public publicProcessorFactory: PublicProcessorFactory;
13
+ declare public timetable: SequencerTimetable;
14
+ declare public publisherFactory: SequencerPublisherFactory;
15
+ declare public validatorClient: ValidatorClient;
16
+ declare public checkpointsBuilder: FullNodeCheckpointsBuilder;
12
17
  }
13
18
 
14
19
  export type TestSequencer = TestSequencer_;
15
20
 
16
21
  class TestSequencerClient_ extends SequencerClient {
17
- public override sequencer!: TestSequencer;
22
+ declare public sequencer: TestSequencer;
23
+ declare public publisherManager: PublisherManager<L1TxUtils>;
18
24
  }
19
25
 
20
26
  export type TestSequencerClient = TestSequencerClient_;