@aztec/sequencer-client 0.0.1-commit.5daedc8 → 0.0.1-commit.6201a7b05

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 (136) hide show
  1. package/dest/client/sequencer-client.d.ts +26 -16
  2. package/dest/client/sequencer-client.d.ts.map +1 -1
  3. package/dest/client/sequencer-client.js +76 -36
  4. package/dest/config.d.ts +35 -9
  5. package/dest/config.d.ts.map +1 -1
  6. package/dest/config.js +113 -50
  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 +25 -17
  14. package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
  15. package/dest/global_variable_builder/global_builder.js +44 -68
  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/index.d.ts +2 -3
  20. package/dest/index.d.ts.map +1 -1
  21. package/dest/index.js +1 -2
  22. package/dest/publisher/config.d.ts +53 -20
  23. package/dest/publisher/config.d.ts.map +1 -1
  24. package/dest/publisher/config.js +124 -39
  25. package/dest/publisher/index.d.ts +2 -1
  26. package/dest/publisher/index.d.ts.map +1 -1
  27. package/dest/publisher/l1_tx_failed_store/factory.d.ts +11 -0
  28. package/dest/publisher/l1_tx_failed_store/factory.d.ts.map +1 -0
  29. package/dest/publisher/l1_tx_failed_store/factory.js +22 -0
  30. package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts +58 -0
  31. package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts.map +1 -0
  32. package/dest/publisher/l1_tx_failed_store/failed_tx_store.js +1 -0
  33. package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts +15 -0
  34. package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts.map +1 -0
  35. package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.js +34 -0
  36. package/dest/publisher/l1_tx_failed_store/index.d.ts +4 -0
  37. package/dest/publisher/l1_tx_failed_store/index.d.ts.map +1 -0
  38. package/dest/publisher/l1_tx_failed_store/index.js +2 -0
  39. package/dest/publisher/sequencer-publisher-factory.d.ts +15 -8
  40. package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -1
  41. package/dest/publisher/sequencer-publisher-factory.js +28 -4
  42. package/dest/publisher/sequencer-publisher-metrics.d.ts +3 -3
  43. package/dest/publisher/sequencer-publisher-metrics.d.ts.map +1 -1
  44. package/dest/publisher/sequencer-publisher-metrics.js +23 -86
  45. package/dest/publisher/sequencer-publisher.d.ts +114 -80
  46. package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
  47. package/dest/publisher/sequencer-publisher.js +1010 -244
  48. package/dest/sequencer/chain_state_overrides.d.ts +25 -0
  49. package/dest/sequencer/chain_state_overrides.d.ts.map +1 -0
  50. package/dest/sequencer/chain_state_overrides.js +39 -0
  51. package/dest/sequencer/checkpoint_proposal_job.d.ts +138 -0
  52. package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -0
  53. package/dest/sequencer/checkpoint_proposal_job.js +1665 -0
  54. package/dest/sequencer/checkpoint_proposal_job_metrics.d.ts +34 -0
  55. package/dest/sequencer/checkpoint_proposal_job_metrics.d.ts.map +1 -0
  56. package/dest/sequencer/checkpoint_proposal_job_metrics.js +72 -0
  57. package/dest/sequencer/checkpoint_voter.d.ts +34 -0
  58. package/dest/sequencer/checkpoint_voter.d.ts.map +1 -0
  59. package/dest/sequencer/checkpoint_voter.js +106 -0
  60. package/dest/sequencer/config.d.ts +3 -2
  61. package/dest/sequencer/config.d.ts.map +1 -1
  62. package/dest/sequencer/events.d.ts +52 -0
  63. package/dest/sequencer/events.d.ts.map +1 -0
  64. package/dest/sequencer/events.js +1 -0
  65. package/dest/sequencer/index.d.ts +4 -2
  66. package/dest/sequencer/index.d.ts.map +1 -1
  67. package/dest/sequencer/index.js +3 -1
  68. package/dest/sequencer/metrics.d.ts +42 -7
  69. package/dest/sequencer/metrics.d.ts.map +1 -1
  70. package/dest/sequencer/metrics.js +241 -72
  71. package/dest/sequencer/sequencer.d.ts +146 -135
  72. package/dest/sequencer/sequencer.d.ts.map +1 -1
  73. package/dest/sequencer/sequencer.js +841 -661
  74. package/dest/sequencer/timetable.d.ts +67 -16
  75. package/dest/sequencer/timetable.d.ts.map +1 -1
  76. package/dest/sequencer/timetable.js +158 -64
  77. package/dest/sequencer/types.d.ts +3 -0
  78. package/dest/sequencer/types.d.ts.map +1 -0
  79. package/dest/sequencer/types.js +1 -0
  80. package/dest/sequencer/utils.d.ts +14 -8
  81. package/dest/sequencer/utils.d.ts.map +1 -1
  82. package/dest/sequencer/utils.js +7 -4
  83. package/dest/test/index.d.ts +6 -7
  84. package/dest/test/index.d.ts.map +1 -1
  85. package/dest/test/mock_checkpoint_builder.d.ts +95 -0
  86. package/dest/test/mock_checkpoint_builder.d.ts.map +1 -0
  87. package/dest/test/mock_checkpoint_builder.js +231 -0
  88. package/dest/test/utils.d.ts +53 -0
  89. package/dest/test/utils.d.ts.map +1 -0
  90. package/dest/test/utils.js +105 -0
  91. package/package.json +31 -30
  92. package/src/client/sequencer-client.ts +102 -62
  93. package/src/config.ts +132 -59
  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 +64 -96
  98. package/src/global_variable_builder/index.ts +3 -1
  99. package/src/index.ts +1 -7
  100. package/src/publisher/config.ts +166 -51
  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-publisher-factory.ts +43 -13
  107. package/src/publisher/sequencer-publisher-metrics.ts +19 -71
  108. package/src/publisher/sequencer-publisher.ts +763 -325
  109. package/src/sequencer/README.md +600 -0
  110. package/src/sequencer/chain_state_overrides.ts +87 -0
  111. package/src/sequencer/checkpoint_proposal_job.ts +1498 -0
  112. package/src/sequencer/checkpoint_proposal_job_metrics.ts +128 -0
  113. package/src/sequencer/checkpoint_voter.ts +119 -0
  114. package/src/sequencer/config.ts +2 -1
  115. package/src/sequencer/events.ts +32 -0
  116. package/src/sequencer/index.ts +3 -1
  117. package/src/sequencer/metrics.ts +302 -83
  118. package/src/sequencer/sequencer.ts +641 -863
  119. package/src/sequencer/timetable.ts +188 -81
  120. package/src/sequencer/types.ts +6 -0
  121. package/src/sequencer/utils.ts +18 -9
  122. package/src/test/index.ts +5 -6
  123. package/src/test/mock_checkpoint_builder.ts +323 -0
  124. package/src/test/utils.ts +185 -0
  125. package/dest/sequencer/block_builder.d.ts +0 -27
  126. package/dest/sequencer/block_builder.d.ts.map +0 -1
  127. package/dest/sequencer/block_builder.js +0 -134
  128. package/dest/tx_validator/nullifier_cache.d.ts +0 -14
  129. package/dest/tx_validator/nullifier_cache.d.ts.map +0 -1
  130. package/dest/tx_validator/nullifier_cache.js +0 -24
  131. package/dest/tx_validator/tx_validator_factory.d.ts +0 -17
  132. package/dest/tx_validator/tx_validator_factory.d.ts.map +0 -1
  133. package/dest/tx_validator/tx_validator_factory.js +0 -53
  134. package/src/sequencer/block_builder.ts +0 -222
  135. package/src/tx_validator/nullifier_cache.ts +0 -30
  136. package/src/tx_validator/tx_validator_factory.ts +0 -132
@@ -1,32 +1,25 @@
1
- import type { BlobSinkClientInterface } from '@aztec/blob-sink/client';
1
+ import type { BlobClientInterface } from '@aztec/blob-client/client';
2
+ import { MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT } from '@aztec/constants';
2
3
  import { EpochCache } from '@aztec/epoch-cache';
3
- import {
4
- GovernanceProposerContract,
5
- PublisherManager,
6
- RollupContract,
7
- getPublicClient,
8
- isAnvilTestChain,
9
- } from '@aztec/ethereum';
10
- import { L1TxUtilsWithBlobs } from '@aztec/ethereum/l1-tx-utils-with-blobs';
4
+ import { isAnvilTestChain } from '@aztec/ethereum/chain';
5
+ import { getPublicClient } from '@aztec/ethereum/client';
6
+ import { GovernanceProposerContract, RollupContract } from '@aztec/ethereum/contracts';
7
+ import { type Delayer, L1TxUtils } from '@aztec/ethereum/l1-tx-utils';
8
+ import { PublisherManager } from '@aztec/ethereum/publisher-manager';
11
9
  import { EthAddress } from '@aztec/foundation/eth-address';
12
10
  import { createLogger } from '@aztec/foundation/log';
13
11
  import type { DateProvider } from '@aztec/foundation/timer';
14
12
  import type { KeystoreManager } from '@aztec/node-keystore';
15
13
  import type { P2P } from '@aztec/p2p';
16
14
  import type { SlasherClientInterface } from '@aztec/slasher';
17
- import type { L2BlockSource } from '@aztec/stdlib/block';
18
- import type {
19
- IFullNodeBlockBuilder,
20
- ValidatorClientFullConfig,
21
- WorldStateSynchronizer,
22
- } from '@aztec/stdlib/interfaces/server';
23
- import { SlashFactoryContract } from '@aztec/stdlib/l1-contracts';
15
+ import type { L2BlockSink, L2BlockSource } from '@aztec/stdlib/block';
16
+ import type { ValidatorClientFullConfig, WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
24
17
  import type { L1ToL2MessageSource } from '@aztec/stdlib/messaging';
25
18
  import { L1Metrics, type TelemetryClient } from '@aztec/telemetry-client';
26
- import { NodeKeystoreAdapter, type ValidatorClient } from '@aztec/validator-client';
19
+ import { FullNodeCheckpointsBuilder, NodeKeystoreAdapter, type ValidatorClient } from '@aztec/validator-client';
27
20
 
28
- import type { SequencerClientConfig } from '../config.js';
29
- import { GlobalVariableBuilder } from '../global_variable_builder/index.js';
21
+ import { type SequencerClientConfig, getPublisherConfigFromSequencerConfig } from '../config.js';
22
+ import type { GlobalVariableBuilder } from '../global_variable_builder/index.js';
30
23
  import { SequencerPublisherFactory } from '../publisher/sequencer-publisher-factory.js';
31
24
  import { Sequencer, type SequencerConfig } from '../sequencer/index.js';
32
25
 
@@ -35,11 +28,12 @@ import { Sequencer, type SequencerConfig } from '../sequencer/index.js';
35
28
  */
36
29
  export class SequencerClient {
37
30
  constructor(
38
- protected publisherManager: PublisherManager<L1TxUtilsWithBlobs>,
31
+ protected publisherManager: PublisherManager<L1TxUtils>,
39
32
  protected sequencer: Sequencer,
40
- protected blockBuilder: IFullNodeBlockBuilder,
33
+ protected checkpointsBuilder: FullNodeCheckpointsBuilder,
41
34
  protected validatorClient?: ValidatorClient,
42
35
  private l1Metrics?: L1Metrics,
36
+ private delayer_?: Delayer,
43
37
  ) {}
44
38
 
45
39
  /**
@@ -57,20 +51,22 @@ export class SequencerClient {
57
51
  public static async new(
58
52
  config: SequencerClientConfig,
59
53
  deps: {
60
- validatorClient: ValidatorClient | undefined; // allowed to be undefined while we migrate
54
+ validatorClient: ValidatorClient;
61
55
  p2pClient: P2P;
62
56
  worldStateSynchronizer: WorldStateSynchronizer;
63
57
  slasherClient: SlasherClientInterface | undefined;
64
- blockBuilder: IFullNodeBlockBuilder;
65
- l2BlockSource: L2BlockSource;
58
+ checkpointsBuilder: FullNodeCheckpointsBuilder;
59
+ l2BlockSource: L2BlockSource & L2BlockSink;
66
60
  l1ToL2MessageSource: L1ToL2MessageSource;
67
61
  telemetry: TelemetryClient;
68
62
  publisherFactory?: SequencerPublisherFactory;
69
- blobSinkClient?: BlobSinkClientInterface;
63
+ blobClient: BlobClientInterface;
70
64
  dateProvider: DateProvider;
71
65
  epochCache?: EpochCache;
72
- l1TxUtils: L1TxUtilsWithBlobs[];
66
+ l1TxUtils: L1TxUtils[];
67
+ funderL1TxUtils?: L1TxUtils;
73
68
  nodeKeyStore: KeystoreManager;
69
+ globalVariableBuilder: GlobalVariableBuilder;
74
70
  },
75
71
  ) {
76
72
  const {
@@ -78,7 +74,7 @@ export class SequencerClient {
78
74
  p2pClient,
79
75
  worldStateSynchronizer,
80
76
  slasherClient,
81
- blockBuilder,
77
+ checkpointsBuilder,
82
78
  l2BlockSource,
83
79
  l1ToL2MessageSource,
84
80
  telemetry: telemetryClient,
@@ -92,11 +88,15 @@ export class SequencerClient {
92
88
  publicClient,
93
89
  l1TxUtils.map(x => x.getSenderAddress()),
94
90
  );
95
- const publisherManager = new PublisherManager(l1TxUtils, config);
91
+ const publisherManager = new PublisherManager(l1TxUtils, getPublisherConfigFromSequencerConfig(config), {
92
+ bindings: log.getBindings(),
93
+ funder: deps.funderL1TxUtils,
94
+ });
96
95
  const rollupContract = new RollupContract(publicClient, config.l1Contracts.rollupAddress.toString());
97
- const [l1GenesisTime, slotDuration] = await Promise.all([
96
+ const [l1GenesisTime, slotDuration, rollupManaLimit] = await Promise.all([
98
97
  rollupContract.getL1GenesisTime(),
99
98
  rollupContract.getSlotDuration(),
99
+ rollupContract.getManaLimit().then(Number),
100
100
  ] as const);
101
101
 
102
102
  const governanceProposerContract = new GovernanceProposerContract(
@@ -112,56 +112,40 @@ export class SequencerClient {
112
112
  l1ChainId: chainId,
113
113
  viemPollingIntervalMS: config.viemPollingIntervalMS,
114
114
  ethereumSlotDuration: config.ethereumSlotDuration,
115
+ enableProposerPipelining: config.enableProposerPipelining,
115
116
  },
116
117
  { dateProvider: deps.dateProvider },
117
118
  ));
118
119
 
119
- const slashFactoryContract = new SlashFactoryContract(
120
- publicClient,
121
- config.l1Contracts.slashFactoryAddress?.toString() ?? EthAddress.ZERO.toString(),
122
- );
123
-
124
120
  const publisherFactory =
125
121
  deps.publisherFactory ??
126
122
  new SequencerPublisherFactory(config, {
127
123
  telemetry: telemetryClient,
128
- blobSinkClient: deps.blobSinkClient,
124
+ blobClient: deps.blobClient,
129
125
  epochCache,
130
126
  governanceProposerContract,
131
- slashFactoryContract,
132
127
  rollupContract,
133
128
  dateProvider: deps.dateProvider,
134
129
  publisherManager,
135
130
  nodeKeyStore: NodeKeystoreAdapter.fromKeyStoreManager(deps.nodeKeyStore),
136
131
  logger: log,
137
132
  });
138
- const globalsBuilder = new GlobalVariableBuilder(config);
139
133
 
140
134
  const ethereumSlotDuration = config.ethereumSlotDuration;
141
135
 
142
- const rollupManaLimit = Number(await rollupContract.getManaLimit());
143
- let sequencerManaLimit = config.maxL2BlockGas ?? rollupManaLimit;
144
- if (sequencerManaLimit > rollupManaLimit) {
145
- log.warn(
146
- `Provided maxL2BlockGas of ${sequencerManaLimit} is greater than the maximum allowed by the L1 (${rollupManaLimit}), setting limit to ${rollupManaLimit}`,
147
- );
148
- sequencerManaLimit = rollupManaLimit;
149
- }
136
+ const globalsBuilder = deps.globalVariableBuilder;
150
137
 
151
138
  // When running in anvil, assume we can post a tx up until one second before the end of an L1 slot.
152
- // Otherwise, assume we must have broadcasted the tx before the slot started (we use a default
153
- // maxL1TxInclusionTimeIntoSlot of zero) to get the tx into that L1 slot.
139
+ // Otherwise, we need the full L1 slot duration for publishing to ensure inclusion.
154
140
  // In theory, the L1 slot has an initial 4s phase where the block is propagated, so we could
155
- // make it with a propagation time into slot equal to 4s. However, we prefer being conservative.
141
+ // reduce the publishing time allowance. However, we prefer being conservative.
156
142
  // See https://www.blocknative.com/blog/anatomy-of-a-slot#7 for more info.
157
- const maxInclusionBasedOnChain = isAnvilTestChain(config.l1ChainId) ? ethereumSlotDuration - 1 : 0;
158
- const maxL1TxInclusionTimeIntoSlot = config.maxL1TxInclusionTimeIntoSlot ?? maxInclusionBasedOnChain;
143
+ const l1PublishingTimeBasedOnChain = isAnvilTestChain(config.l1ChainId) ? 1 : ethereumSlotDuration;
144
+ const l1PublishingTime = config.l1PublishingTime ?? l1PublishingTimeBasedOnChain;
159
145
 
160
- const l1Constants = {
161
- l1GenesisTime,
162
- slotDuration: Number(slotDuration),
163
- ethereumSlotDuration,
164
- };
146
+ const { maxL2BlockGas, maxDABlockGas, maxTxsPerBlock } = capPerBlockLimits(config, rollupManaLimit, log);
147
+
148
+ const l1Constants = { l1GenesisTime, slotDuration: Number(slotDuration), ethereumSlotDuration, rollupManaLimit };
165
149
 
166
150
  const sequencer = new Sequencer(
167
151
  publisherFactory,
@@ -172,19 +156,22 @@ export class SequencerClient {
172
156
  slasherClient,
173
157
  l2BlockSource,
174
158
  l1ToL2MessageSource,
175
- blockBuilder,
159
+ checkpointsBuilder,
176
160
  l1Constants,
177
161
  deps.dateProvider,
178
162
  epochCache,
179
163
  rollupContract,
180
- { ...config, maxL1TxInclusionTimeIntoSlot, maxL2BlockGas: sequencerManaLimit },
164
+ { ...config, l1PublishingTime, maxL2BlockGas, maxDABlockGas, maxTxsPerBlock },
181
165
  telemetryClient,
182
166
  log,
183
167
  );
184
168
 
185
- await sequencer.init();
169
+ sequencer.init();
170
+
171
+ // Extract the shared delayer from the first L1TxUtils instance (all instances share the same delayer)
172
+ const delayer = l1TxUtils[0]?.delayer;
186
173
 
187
- return new SequencerClient(publisherManager, sequencer, blockBuilder, validatorClient, l1Metrics);
174
+ return new SequencerClient(publisherManager, sequencer, checkpointsBuilder, validatorClient, l1Metrics, delayer);
188
175
  }
189
176
 
190
177
  /**
@@ -193,7 +180,7 @@ export class SequencerClient {
193
180
  */
194
181
  public updateConfig(config: SequencerConfig & Partial<ValidatorClientFullConfig>) {
195
182
  this.sequencer.updateConfig(config);
196
- this.blockBuilder.updateConfig(config);
183
+ this.checkpointsBuilder.updateConfig(config);
197
184
  this.validatorClient?.updateConfig(config);
198
185
  }
199
186
 
@@ -202,7 +189,7 @@ export class SequencerClient {
202
189
  await this.validatorClient?.start();
203
190
  this.sequencer.start();
204
191
  this.l1Metrics?.start();
205
- await this.publisherManager.loadState();
192
+ await this.publisherManager.start();
206
193
  }
207
194
 
208
195
  /**
@@ -211,14 +198,29 @@ export class SequencerClient {
211
198
  public async stop() {
212
199
  await this.sequencer.stop();
213
200
  await this.validatorClient?.stop();
214
- this.publisherManager.interrupt();
201
+ await this.publisherManager.stop();
215
202
  this.l1Metrics?.stop();
216
203
  }
217
204
 
205
+ /** Triggers an immediate run of the sequencer, bypassing the polling interval. */
206
+ public trigger() {
207
+ return this.sequencer.trigger();
208
+ }
209
+
218
210
  public getSequencer(): Sequencer {
219
211
  return this.sequencer;
220
212
  }
221
213
 
214
+ /** Updates the publisher factory's node keystore adapter after a keystore reload. */
215
+ public updatePublisherNodeKeyStore(adapter: NodeKeystoreAdapter): void {
216
+ this.sequencer.updatePublisherNodeKeyStore(adapter);
217
+ }
218
+
219
+ /** Returns the shared tx delayer for sequencer L1 txs, if enabled. Test-only. */
220
+ getDelayer(): Delayer | undefined {
221
+ return this.delayer_;
222
+ }
223
+
222
224
  get validatorAddresses(): EthAddress[] | undefined {
223
225
  return this.sequencer.getValidatorAddresses();
224
226
  }
@@ -227,3 +229,41 @@ export class SequencerClient {
227
229
  return this.sequencer.maxL2BlockGas;
228
230
  }
229
231
  }
232
+
233
+ /**
234
+ * Caps operator-provided per-block limits at checkpoint-level limits.
235
+ * Returns undefined for any limit the operator didn't set — the checkpoint builder handles redistribution.
236
+ */
237
+ function capPerBlockLimits(
238
+ config: SequencerClientConfig,
239
+ rollupManaLimit: number,
240
+ log: ReturnType<typeof createLogger>,
241
+ ): { maxL2BlockGas: number | undefined; maxDABlockGas: number | undefined; maxTxsPerBlock: number | undefined } {
242
+ let maxL2BlockGas = config.maxL2BlockGas;
243
+ if (maxL2BlockGas !== undefined && maxL2BlockGas > rollupManaLimit) {
244
+ log.warn(`Provided MAX_L2_BLOCK_GAS ${maxL2BlockGas} exceeds rollup mana limit ${rollupManaLimit} (capping)`);
245
+ maxL2BlockGas = rollupManaLimit;
246
+ }
247
+
248
+ let maxDABlockGas = config.maxDABlockGas;
249
+ if (maxDABlockGas !== undefined && maxDABlockGas > MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT) {
250
+ log.warn(
251
+ `Provided MAX_DA_BLOCK_GAS ${maxDABlockGas} exceeds DA checkpoint limit ${MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT} (capping)`,
252
+ );
253
+ maxDABlockGas = MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT;
254
+ }
255
+
256
+ let maxTxsPerBlock = config.maxTxsPerBlock;
257
+ if (
258
+ maxTxsPerBlock !== undefined &&
259
+ config.maxTxsPerCheckpoint !== undefined &&
260
+ maxTxsPerBlock > config.maxTxsPerCheckpoint
261
+ ) {
262
+ log.warn(
263
+ `Provided MAX_TX_PER_BLOCK ${maxTxsPerBlock} exceeds MAX_TX_PER_CHECKPOINT ${config.maxTxsPerCheckpoint} (capping)`,
264
+ );
265
+ maxTxsPerBlock = config.maxTxsPerCheckpoint;
266
+ }
267
+
268
+ return { maxL2BlockGas, maxDABlockGas, maxTxsPerBlock };
269
+ }
package/src/config.ts CHANGED
@@ -1,82 +1,131 @@
1
- import {
2
- type L1ContractsConfig,
3
- type L1ReaderConfig,
4
- l1ContractsConfigMappings,
5
- l1ReaderConfigMappings,
6
- } from '@aztec/ethereum';
1
+ import { type L1ContractsConfig, l1ContractsConfigMappings } from '@aztec/ethereum/config';
2
+ import { type L1ReaderConfig, l1ReaderConfigMappings } from '@aztec/ethereum/l1-reader';
7
3
  import {
8
4
  type ConfigMappingsType,
9
5
  booleanConfigHelper,
10
6
  getConfigFromMappings,
11
7
  numberConfigHelper,
8
+ optionalNumberConfigHelper,
12
9
  pickConfigMappings,
13
10
  } from '@aztec/foundation/config';
14
11
  import { EthAddress } from '@aztec/foundation/eth-address';
15
- import { type KeyStoreConfig, keyStoreConfigMappings } from '@aztec/node-keystore';
16
- import { type P2PConfig, p2pConfigMappings } from '@aztec/p2p';
12
+ import { type KeyStoreConfig, keyStoreConfigMappings } from '@aztec/node-keystore/config';
13
+ import { type P2PConfig, p2pConfigMappings } from '@aztec/p2p/config';
17
14
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
18
- import { type ChainConfig, type SequencerConfig, chainConfigMappings } from '@aztec/stdlib/config';
19
- import { type ValidatorClientConfig, validatorClientConfigMappings } from '@aztec/validator-client';
15
+ import {
16
+ type ChainConfig,
17
+ type PipelineConfig,
18
+ type SequencerConfig,
19
+ chainConfigMappings,
20
+ pipelineConfigMappings,
21
+ sharedSequencerConfigMappings,
22
+ } from '@aztec/stdlib/config';
23
+ import type { ResolvedSequencerConfig } from '@aztec/stdlib/interfaces/server';
24
+ import { DEFAULT_P2P_PROPAGATION_TIME } from '@aztec/stdlib/timetable';
25
+ import { type ValidatorClientConfig, validatorClientConfigMappings } from '@aztec/validator-client/config';
20
26
 
21
27
  import {
22
- type PublisherConfig,
23
- type TxSenderConfig,
24
- getPublisherConfigMappings,
25
- getTxSenderConfigMappings,
28
+ type SequencerPublisherConfig,
29
+ type SequencerTxSenderConfig,
30
+ sequencerPublisherConfigMappings,
31
+ sequencerTxSenderConfigMappings,
26
32
  } from './publisher/config.js';
27
33
 
28
34
  export * from './publisher/config.js';
29
35
  export type { SequencerConfig };
30
36
 
31
- export const DEFAULT_ATTESTATION_PROPAGATION_TIME = 2;
37
+ /**
38
+ * Default values for SequencerConfig.
39
+ * Centralized location for all sequencer configuration defaults.
40
+ */
41
+ export const DefaultSequencerConfig = {
42
+ sequencerPollingIntervalMS: 500,
43
+ minTxsPerBlock: 1,
44
+ buildCheckpointIfEmpty: false,
45
+ publishTxsWithProposals: false,
46
+ perBlockAllocationMultiplier: 1.2,
47
+ redistributeCheckpointBudget: true,
48
+ enforceTimeTable: true,
49
+ attestationPropagationTime: DEFAULT_P2P_PROPAGATION_TIME,
50
+ secondsBeforeInvalidatingBlockAsCommitteeMember: 144, // 12 L1 blocks
51
+ secondsBeforeInvalidatingBlockAsNonCommitteeMember: 432, // 36 L1 blocks
52
+ skipCollectingAttestations: false,
53
+ skipInvalidateBlockAsProposer: false,
54
+ broadcastInvalidBlockProposal: false,
55
+ injectFakeAttestation: false,
56
+ injectHighSValueAttestation: false,
57
+ injectUnrecoverableSignatureAttestation: false,
58
+ fishermanMode: false,
59
+ shuffleAttestationOrdering: false,
60
+ skipPushProposedBlocksToArchiver: false,
61
+ skipPublishingCheckpointsPercent: 0,
62
+ } satisfies ResolvedSequencerConfig;
32
63
 
33
64
  /**
34
65
  * Configuration settings for the SequencerClient.
35
66
  */
36
- export type SequencerClientConfig = PublisherConfig &
67
+ export type SequencerClientConfig = SequencerPublisherConfig &
37
68
  KeyStoreConfig &
38
69
  ValidatorClientConfig &
39
- TxSenderConfig &
70
+ SequencerTxSenderConfig &
40
71
  SequencerConfig &
41
72
  L1ReaderConfig &
42
73
  ChainConfig &
43
- Pick<P2PConfig, 'txPublicSetupAllowList'> &
74
+ PipelineConfig &
75
+ Pick<P2PConfig, 'txPublicSetupAllowListExtend'> &
44
76
  Pick<L1ContractsConfig, 'ethereumSlotDuration' | 'aztecSlotDuration' | 'aztecEpochDuration'>;
45
77
 
46
78
  export const sequencerConfigMappings: ConfigMappingsType<SequencerConfig> = {
47
- transactionPollingIntervalMS: {
48
- env: 'SEQ_TX_POLLING_INTERVAL_MS',
49
- description: 'The number of ms to wait between polling for pending txs.',
50
- ...numberConfigHelper(500),
79
+ sequencerPollingIntervalMS: {
80
+ env: 'SEQ_POLLING_INTERVAL_MS',
81
+ description: 'The number of ms to wait between polling for checking to build on the next slot.',
82
+ ...numberConfigHelper(DefaultSequencerConfig.sequencerPollingIntervalMS),
51
83
  },
52
- maxTxsPerBlock: {
53
- env: 'SEQ_MAX_TX_PER_BLOCK',
54
- description: 'The maximum number of txs to include in a block.',
55
- ...numberConfigHelper(32),
84
+ maxTxsPerCheckpoint: {
85
+ env: 'SEQ_MAX_TX_PER_CHECKPOINT',
86
+ description: 'The maximum number of txs across all blocks in a checkpoint.',
87
+ ...optionalNumberConfigHelper(),
56
88
  },
57
89
  minTxsPerBlock: {
58
90
  env: 'SEQ_MIN_TX_PER_BLOCK',
59
91
  description: 'The minimum number of txs to include in a block.',
60
- ...numberConfigHelper(1),
92
+ ...numberConfigHelper(DefaultSequencerConfig.minTxsPerBlock),
93
+ },
94
+ minValidTxsPerBlock: {
95
+ description:
96
+ 'The minimum number of valid txs (after execution) to include in a block. If not set, falls back to minTxsPerBlock.',
61
97
  },
62
98
  publishTxsWithProposals: {
63
99
  env: 'SEQ_PUBLISH_TXS_WITH_PROPOSALS',
64
100
  description: 'Whether to publish txs with proposals.',
65
- ...booleanConfigHelper(false),
101
+ ...booleanConfigHelper(DefaultSequencerConfig.publishTxsWithProposals),
66
102
  },
67
103
  maxL2BlockGas: {
68
104
  env: 'SEQ_MAX_L2_BLOCK_GAS',
69
105
  description: 'The maximum L2 block gas.',
70
- ...numberConfigHelper(10e9),
106
+ ...optionalNumberConfigHelper(),
71
107
  },
72
108
  maxDABlockGas: {
73
109
  env: 'SEQ_MAX_DA_BLOCK_GAS',
74
110
  description: 'The maximum DA block gas.',
75
- ...numberConfigHelper(10e9),
111
+ ...optionalNumberConfigHelper(),
112
+ },
113
+ perBlockAllocationMultiplier: {
114
+ env: 'SEQ_PER_BLOCK_ALLOCATION_MULTIPLIER',
115
+ description:
116
+ 'Per-block gas budget multiplier for both L2 and DA gas. Budget per block is (checkpointLimit / maxBlocks) * multiplier.' +
117
+ ' Values greater than one allow early blocks to use more than their even share, relying on checkpoint-level capping for later blocks.',
118
+ ...numberConfigHelper(DefaultSequencerConfig.perBlockAllocationMultiplier),
119
+ },
120
+ redistributeCheckpointBudget: {
121
+ env: 'SEQ_REDISTRIBUTE_CHECKPOINT_BUDGET',
122
+ description:
123
+ 'Redistribute remaining checkpoint budget evenly across remaining blocks instead of allowing a single block to consume the entire remaining budget.',
124
+ ...booleanConfigHelper(DefaultSequencerConfig.redistributeCheckpointBudget),
76
125
  },
77
126
  coinbase: {
78
127
  env: 'COINBASE',
79
- parseEnv: (val: string) => (val ? EthAddress.fromString(val) : undefined),
128
+ parseEnv: (val: string) => EthAddress.fromString(val),
80
129
  description: 'Recipient of block reward.',
81
130
  },
82
131
  feeRecipient: {
@@ -92,88 +141,112 @@ export const sequencerConfigMappings: ConfigMappingsType<SequencerConfig> = {
92
141
  env: 'ACVM_BINARY_PATH',
93
142
  description: 'The path to the ACVM binary',
94
143
  },
95
- maxBlockSizeInBytes: {
96
- env: 'SEQ_MAX_BLOCK_SIZE_IN_BYTES',
97
- description: 'Max block size',
98
- ...numberConfigHelper(1024 * 1024),
99
- },
100
144
  enforceTimeTable: {
101
145
  env: 'SEQ_ENFORCE_TIME_TABLE',
102
146
  description: 'Whether to enforce the time table when building blocks',
103
- ...booleanConfigHelper(),
104
- defaultValue: true,
147
+ ...booleanConfigHelper(DefaultSequencerConfig.enforceTimeTable),
105
148
  },
106
149
  governanceProposerPayload: {
107
150
  env: 'GOVERNANCE_PROPOSER_PAYLOAD_ADDRESS',
108
151
  description: 'The address of the payload for the governanceProposer',
109
152
  parseEnv: (val: string) => EthAddress.fromString(val),
110
- defaultValue: EthAddress.ZERO,
111
- },
112
- maxL1TxInclusionTimeIntoSlot: {
113
- env: 'SEQ_MAX_L1_TX_INCLUSION_TIME_INTO_SLOT',
114
- description: 'How many seconds into an L1 slot we can still send a tx and get it mined.',
115
- parseEnv: (val: string) => (val ? parseInt(val, 10) : undefined),
116
153
  },
117
- attestationPropagationTime: {
118
- env: 'SEQ_ATTESTATION_PROPAGATION_TIME',
119
- description: 'How many seconds it takes for proposals and attestations to travel across the p2p layer (one-way)',
120
- ...numberConfigHelper(DEFAULT_ATTESTATION_PROPAGATION_TIME),
154
+ l1PublishingTime: {
155
+ env: 'SEQ_L1_PUBLISHING_TIME_ALLOWANCE_IN_SLOT',
156
+ description: 'How much time (in seconds) we allow in the slot for publishing the L1 tx (defaults to 1 L1 slot).',
157
+ ...optionalNumberConfigHelper(),
121
158
  },
122
159
  fakeProcessingDelayPerTxMs: {
123
160
  description: 'Used for testing to introduce a fake delay after processing each tx',
124
161
  },
162
+ fakeThrowAfterProcessingTxCount: {
163
+ description: 'Used for testing to throw an error after processing N txs',
164
+ },
125
165
  secondsBeforeInvalidatingBlockAsCommitteeMember: {
126
166
  env: 'SEQ_SECONDS_BEFORE_INVALIDATING_BLOCK_AS_COMMITTEE_MEMBER',
127
167
  description:
128
168
  'How many seconds to wait before trying to invalidate a block from the pending chain as a committee member (zero to never invalidate).' +
129
169
  ' The next proposer is expected to invalidate, so the committee acts as a fallback.',
130
- ...numberConfigHelper(144), // 12 L1 blocks
170
+ ...numberConfigHelper(DefaultSequencerConfig.secondsBeforeInvalidatingBlockAsCommitteeMember),
131
171
  },
132
172
  secondsBeforeInvalidatingBlockAsNonCommitteeMember: {
133
173
  env: 'SEQ_SECONDS_BEFORE_INVALIDATING_BLOCK_AS_NON_COMMITTEE_MEMBER',
134
174
  description:
135
175
  'How many seconds to wait before trying to invalidate a block from the pending chain as a non-committee member (zero to never invalidate).' +
136
176
  ' The next proposer is expected to invalidate, then the committee, so other sequencers act as a fallback.',
137
- ...numberConfigHelper(432), // 36 L1 blocks
177
+ ...numberConfigHelper(DefaultSequencerConfig.secondsBeforeInvalidatingBlockAsNonCommitteeMember),
138
178
  },
139
179
  skipCollectingAttestations: {
140
180
  description:
141
181
  'Whether to skip collecting attestations from validators and only use self-attestations (for testing only)',
142
- ...booleanConfigHelper(false),
182
+ ...booleanConfigHelper(DefaultSequencerConfig.skipCollectingAttestations),
143
183
  },
144
184
  skipInvalidateBlockAsProposer: {
145
185
  description: 'Do not invalidate the previous block if invalid when we are the proposer (for testing only)',
146
- ...booleanConfigHelper(false),
186
+ ...booleanConfigHelper(DefaultSequencerConfig.skipInvalidateBlockAsProposer),
147
187
  },
148
188
  broadcastInvalidBlockProposal: {
149
189
  description: 'Broadcast invalid block proposals with corrupted state (for testing only)',
150
- ...booleanConfigHelper(false),
190
+ ...booleanConfigHelper(DefaultSequencerConfig.broadcastInvalidBlockProposal),
151
191
  },
152
192
  injectFakeAttestation: {
153
193
  description: 'Inject a fake attestation (for testing only)',
154
- ...booleanConfigHelper(false),
194
+ ...booleanConfigHelper(DefaultSequencerConfig.injectFakeAttestation),
195
+ },
196
+ injectHighSValueAttestation: {
197
+ description: 'Inject a malleable attestation with a high-s value (for testing only)',
198
+ ...booleanConfigHelper(DefaultSequencerConfig.injectHighSValueAttestation),
199
+ },
200
+ injectUnrecoverableSignatureAttestation: {
201
+ description: 'Inject an attestation with an unrecoverable signature (for testing only)',
202
+ ...booleanConfigHelper(DefaultSequencerConfig.injectUnrecoverableSignatureAttestation),
155
203
  },
156
204
  fishermanMode: {
157
205
  env: 'FISHERMAN_MODE',
158
206
  description:
159
207
  'Whether to run in fisherman mode: builds blocks on every slot for validation without publishing to L1',
160
- ...booleanConfigHelper(false),
208
+ ...booleanConfigHelper(DefaultSequencerConfig.fishermanMode),
161
209
  },
162
210
  shuffleAttestationOrdering: {
163
211
  description: 'Shuffle attestation ordering to create invalid ordering (for testing only)',
212
+ ...booleanConfigHelper(DefaultSequencerConfig.shuffleAttestationOrdering),
213
+ },
214
+ ...sharedSequencerConfigMappings,
215
+ buildCheckpointIfEmpty: {
216
+ env: 'SEQ_BUILD_CHECKPOINT_IF_EMPTY',
217
+ description: 'Have sequencer build and publish an empty checkpoint if there are no txs',
218
+ ...booleanConfigHelper(DefaultSequencerConfig.buildCheckpointIfEmpty),
219
+ },
220
+ skipPushProposedBlocksToArchiver: {
221
+ description: 'Skip pushing proposed blocks to archiver (default: true)',
222
+ ...booleanConfigHelper(DefaultSequencerConfig.skipPushProposedBlocksToArchiver),
223
+ },
224
+ minBlocksForCheckpoint: {
225
+ description: 'Minimum number of blocks required for a checkpoint proposal (test only)',
226
+ },
227
+ skipPublishingCheckpointsPercent: {
228
+ env: 'SEQ_SKIP_CHECKPOINT_PUBLISH_PERCENT',
229
+ description: 'Percent probability (0 - 100) of sequencer skipping checkpoint publishing (testing only)',
230
+ ...numberConfigHelper(DefaultSequencerConfig.skipPublishingCheckpointsPercent),
231
+ },
232
+ skipBroadcastProposals: {
233
+ description: 'Skip broadcasting checkpoint and block proposals via gossipsub when proposer (for testing only)',
164
234
  ...booleanConfigHelper(false),
165
235
  },
166
- ...pickConfigMappings(p2pConfigMappings, ['txPublicSetupAllowList']),
236
+ ...pickConfigMappings(p2pConfigMappings, ['txPublicSetupAllowListExtend']),
167
237
  };
168
238
 
169
239
  export const sequencerClientConfigMappings: ConfigMappingsType<SequencerClientConfig> = {
240
+ // chainConfigMappings must come first: its l1Contracts only maps rollupAddress,
241
+ // while l1ReaderConfigMappings (spread later) maps all L1 contract addresses.
242
+ ...chainConfigMappings,
170
243
  ...validatorClientConfigMappings,
171
244
  ...sequencerConfigMappings,
172
245
  ...keyStoreConfigMappings,
173
246
  ...l1ReaderConfigMappings,
174
- ...getTxSenderConfigMappings('SEQ'),
175
- ...getPublisherConfigMappings('SEQ'),
176
- ...chainConfigMappings,
247
+ ...sequencerTxSenderConfigMappings,
248
+ ...sequencerPublisherConfigMappings,
249
+ ...pipelineConfigMappings,
177
250
  ...pickConfigMappings(l1ContractsConfigMappings, ['ethereumSlotDuration', 'aztecSlotDuration', 'aztecEpochDuration']),
178
251
  };
179
252
 
@@ -0,0 +1,44 @@
1
+ # Fee Prediction
2
+
3
+ The `FeePredictor` predicts min fees for upcoming L2 slots based on the current L1
4
+ oracle state and an assumed mana usage pattern.
5
+
6
+ ## Prediction Window
7
+
8
+ The prediction covers `LAG = 2` entries (the next available slot plus 1 more).
9
+ A new oracle update can activate at `startSlot + LAG`, so only the first LAG entries
10
+ are guaranteed stable. Beyond that, L1 fees could change unpredictably.
11
+
12
+ Each entry uses:
13
+
14
+ - The **actual L1 fees** the oracle would return for that slot's timestamp (pre or post,
15
+ depending on whether the slot is before or after `slotOfChange`).
16
+ - A **configurable congestion assumption** (`ManaUsageEstimate`): none (0 mana), target
17
+ (steady state), or limit (worst case, 2x target).
18
+
19
+ The client picks `max(predicted[0..LAG-1])` as their `maxFeesPerGas`.
20
+
21
+ ```
22
+ predicted[0] → fee at next slot (current oracle + current congestion)
23
+ predicted[1] → fee at next slot + 1 (congestion may change based on usage estimate)
24
+ ```
25
+
26
+ ## Why LAG and not LIFETIME?
27
+
28
+ The L1 gas oracle has two timing constants:
29
+
30
+ - **LAG = 2 slots**: when new fees are queued, they activate LAG slots later
31
+ - **LIFETIME = 5 slots**: after an oracle update, the next update is rejected until
32
+ `slotOfChange + (LIFETIME - LAG)` slots have passed
33
+
34
+ If the oracle cooldown has already elapsed (i.e., no recent update), a new update can
35
+ be enqueued at any moment. Its new values would activate LAG slots later. This means
36
+ predictions beyond LAG slots could be invalidated by an oracle update that happens
37
+ right after we query.
38
+
39
+ With a LIFETIME-sized window, we'd give a false sense of coverage: the prediction
40
+ would look like it covers 6 slots, but slots beyond LAG could be wrong if an update
41
+ is enqueued after the prediction is computed.
42
+
43
+ By limiting to LAG entries, we guarantee that all predicted L1 fees are the ones that
44
+ will actually be used — no oracle update can change them within this window.