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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (145) hide show
  1. package/README.md +282 -21
  2. package/dest/client/sequencer-client.d.ts +20 -11
  3. package/dest/client/sequencer-client.d.ts.map +1 -1
  4. package/dest/client/sequencer-client.js +67 -33
  5. package/dest/config.d.ts +29 -7
  6. package/dest/config.d.ts.map +1 -1
  7. package/dest/config.js +82 -37
  8. package/dest/global_variable_builder/fee_predictor.d.ts +37 -0
  9. package/dest/global_variable_builder/fee_predictor.d.ts.map +1 -0
  10. package/dest/global_variable_builder/fee_predictor.js +128 -0
  11. package/dest/global_variable_builder/fee_provider.d.ts +21 -0
  12. package/dest/global_variable_builder/fee_provider.d.ts.map +1 -0
  13. package/dest/global_variable_builder/fee_provider.js +58 -0
  14. package/dest/global_variable_builder/global_builder.d.ts +14 -16
  15. package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
  16. package/dest/global_variable_builder/global_builder.js +16 -50
  17. package/dest/global_variable_builder/index.d.ts +4 -2
  18. package/dest/global_variable_builder/index.d.ts.map +1 -1
  19. package/dest/global_variable_builder/index.js +2 -0
  20. package/dest/index.d.ts +2 -3
  21. package/dest/index.d.ts.map +1 -1
  22. package/dest/index.js +1 -2
  23. package/dest/publisher/config.d.ts +47 -17
  24. package/dest/publisher/config.d.ts.map +1 -1
  25. package/dest/publisher/config.js +121 -42
  26. package/dest/publisher/index.d.ts +2 -1
  27. package/dest/publisher/index.d.ts.map +1 -1
  28. package/dest/publisher/l1_tx_failed_store/factory.d.ts +11 -0
  29. package/dest/publisher/l1_tx_failed_store/factory.d.ts.map +1 -0
  30. package/dest/publisher/l1_tx_failed_store/factory.js +22 -0
  31. package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts +58 -0
  32. package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts.map +1 -0
  33. package/dest/publisher/l1_tx_failed_store/failed_tx_store.js +1 -0
  34. package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts +15 -0
  35. package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts.map +1 -0
  36. package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.js +34 -0
  37. package/dest/publisher/l1_tx_failed_store/index.d.ts +4 -0
  38. package/dest/publisher/l1_tx_failed_store/index.d.ts.map +1 -0
  39. package/dest/publisher/l1_tx_failed_store/index.js +2 -0
  40. package/dest/publisher/sequencer-bundle-simulator.d.ts +96 -0
  41. package/dest/publisher/sequencer-bundle-simulator.d.ts.map +1 -0
  42. package/dest/publisher/sequencer-bundle-simulator.js +198 -0
  43. package/dest/publisher/sequencer-publisher-factory.d.ts +12 -6
  44. package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -1
  45. package/dest/publisher/sequencer-publisher-factory.js +27 -3
  46. package/dest/publisher/sequencer-publisher-metrics.d.ts +1 -1
  47. package/dest/publisher/sequencer-publisher-metrics.d.ts.map +1 -1
  48. package/dest/publisher/sequencer-publisher-metrics.js +23 -86
  49. package/dest/publisher/sequencer-publisher.d.ts +108 -81
  50. package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
  51. package/dest/publisher/sequencer-publisher.js +876 -403
  52. package/dest/sequencer/automine/automine_factory.d.ts +54 -0
  53. package/dest/sequencer/automine/automine_factory.d.ts.map +1 -0
  54. package/dest/sequencer/automine/automine_factory.js +84 -0
  55. package/dest/sequencer/automine/automine_sequencer.d.ts +151 -0
  56. package/dest/sequencer/automine/automine_sequencer.d.ts.map +1 -0
  57. package/dest/sequencer/automine/automine_sequencer.js +506 -0
  58. package/dest/sequencer/chain_state_overrides.d.ts +61 -0
  59. package/dest/sequencer/chain_state_overrides.d.ts.map +1 -0
  60. package/dest/sequencer/chain_state_overrides.js +98 -0
  61. package/dest/sequencer/checkpoint_proposal_job.d.ts +87 -16
  62. package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -1
  63. package/dest/sequencer/checkpoint_proposal_job.js +1331 -203
  64. package/dest/sequencer/checkpoint_proposal_job_metrics.d.ts +34 -0
  65. package/dest/sequencer/checkpoint_proposal_job_metrics.d.ts.map +1 -0
  66. package/dest/sequencer/checkpoint_proposal_job_metrics.js +72 -0
  67. package/dest/sequencer/checkpoint_voter.d.ts +3 -3
  68. package/dest/sequencer/checkpoint_voter.d.ts.map +1 -1
  69. package/dest/sequencer/checkpoint_voter.js +34 -13
  70. package/dest/sequencer/events.d.ts +47 -2
  71. package/dest/sequencer/events.d.ts.map +1 -1
  72. package/dest/sequencer/index.d.ts +3 -3
  73. package/dest/sequencer/index.d.ts.map +1 -1
  74. package/dest/sequencer/index.js +2 -2
  75. package/dest/sequencer/metrics.d.ts +23 -8
  76. package/dest/sequencer/metrics.d.ts.map +1 -1
  77. package/dest/sequencer/metrics.js +158 -143
  78. package/dest/sequencer/sequencer.d.ts +92 -29
  79. package/dest/sequencer/sequencer.d.ts.map +1 -1
  80. package/dest/sequencer/sequencer.js +818 -157
  81. package/dest/sequencer/timetable.d.ts +17 -6
  82. package/dest/sequencer/timetable.d.ts.map +1 -1
  83. package/dest/sequencer/timetable.js +51 -46
  84. package/dest/sequencer/types.d.ts +2 -2
  85. package/dest/sequencer/types.d.ts.map +1 -1
  86. package/dest/test/index.d.ts +4 -7
  87. package/dest/test/index.d.ts.map +1 -1
  88. package/dest/test/mock_checkpoint_builder.d.ts +29 -17
  89. package/dest/test/mock_checkpoint_builder.d.ts.map +1 -1
  90. package/dest/test/mock_checkpoint_builder.js +86 -34
  91. package/dest/test/utils.d.ts +13 -9
  92. package/dest/test/utils.d.ts.map +1 -1
  93. package/dest/test/utils.js +31 -20
  94. package/package.json +29 -28
  95. package/src/client/sequencer-client.ts +94 -38
  96. package/src/config.ts +107 -46
  97. package/src/global_variable_builder/README.md +44 -0
  98. package/src/global_variable_builder/fee_predictor.ts +172 -0
  99. package/src/global_variable_builder/fee_provider.ts +75 -0
  100. package/src/global_variable_builder/global_builder.ts +26 -63
  101. package/src/global_variable_builder/index.ts +3 -1
  102. package/src/index.ts +5 -4
  103. package/src/publisher/config.ts +157 -45
  104. package/src/publisher/index.ts +3 -0
  105. package/src/publisher/l1_tx_failed_store/factory.ts +32 -0
  106. package/src/publisher/l1_tx_failed_store/failed_tx_store.ts +57 -0
  107. package/src/publisher/l1_tx_failed_store/file_store_failed_tx_store.ts +46 -0
  108. package/src/publisher/l1_tx_failed_store/index.ts +3 -0
  109. package/src/publisher/sequencer-bundle-simulator.ts +254 -0
  110. package/src/publisher/sequencer-publisher-factory.ts +39 -10
  111. package/src/publisher/sequencer-publisher-metrics.ts +17 -69
  112. package/src/publisher/sequencer-publisher.ts +611 -521
  113. package/src/sequencer/README.md +152 -450
  114. package/src/sequencer/automine/README.md +46 -0
  115. package/src/sequencer/automine/automine_factory.ts +145 -0
  116. package/src/sequencer/automine/automine_sequencer.ts +592 -0
  117. package/src/sequencer/chain_state_overrides.ts +162 -0
  118. package/src/sequencer/checkpoint_proposal_job.ts +1138 -230
  119. package/src/sequencer/checkpoint_proposal_job_metrics.ts +128 -0
  120. package/src/sequencer/checkpoint_voter.ts +31 -17
  121. package/src/sequencer/events.ts +50 -2
  122. package/src/sequencer/index.ts +2 -2
  123. package/src/sequencer/metrics.ts +168 -151
  124. package/src/sequencer/sequencer.ts +535 -162
  125. package/src/sequencer/timetable.ts +70 -57
  126. package/src/sequencer/types.ts +1 -1
  127. package/src/test/index.ts +3 -6
  128. package/src/test/mock_checkpoint_builder.ts +149 -73
  129. package/src/test/utils.ts +78 -30
  130. package/dest/sequencer/block_builder.d.ts +0 -26
  131. package/dest/sequencer/block_builder.d.ts.map +0 -1
  132. package/dest/sequencer/block_builder.js +0 -129
  133. package/dest/sequencer/checkpoint_builder.d.ts +0 -63
  134. package/dest/sequencer/checkpoint_builder.d.ts.map +0 -1
  135. package/dest/sequencer/checkpoint_builder.js +0 -131
  136. package/dest/tx_validator/nullifier_cache.d.ts +0 -14
  137. package/dest/tx_validator/nullifier_cache.d.ts.map +0 -1
  138. package/dest/tx_validator/nullifier_cache.js +0 -24
  139. package/dest/tx_validator/tx_validator_factory.d.ts +0 -18
  140. package/dest/tx_validator/tx_validator_factory.d.ts.map +0 -1
  141. package/dest/tx_validator/tx_validator_factory.js +0 -53
  142. package/src/sequencer/block_builder.ts +0 -217
  143. package/src/sequencer/checkpoint_builder.ts +0 -217
  144. package/src/tx_validator/nullifier_cache.ts +0 -30
  145. package/src/tx_validator/tx_validator_factory.ts +0 -133
@@ -1,9 +1,10 @@
1
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
4
  import { isAnvilTestChain } from '@aztec/ethereum/chain';
4
5
  import { getPublicClient } from '@aztec/ethereum/client';
5
6
  import { GovernanceProposerContract, RollupContract } from '@aztec/ethereum/contracts';
6
- import { L1TxUtilsWithBlobs } from '@aztec/ethereum/l1-tx-utils-with-blobs';
7
+ import { type Delayer, L1TxUtils } from '@aztec/ethereum/l1-tx-utils';
7
8
  import { PublisherManager } from '@aztec/ethereum/publisher-manager';
8
9
  import { EthAddress } from '@aztec/foundation/eth-address';
9
10
  import { createLogger } from '@aztec/foundation/log';
@@ -11,17 +12,15 @@ import type { DateProvider } from '@aztec/foundation/timer';
11
12
  import type { KeystoreManager } from '@aztec/node-keystore';
12
13
  import type { P2P } from '@aztec/p2p';
13
14
  import type { SlasherClientInterface } from '@aztec/slasher';
14
- import type { L2BlockSource } from '@aztec/stdlib/block';
15
+ import type { L2BlockSink, L2BlockSource, ProposedCheckpointSink } from '@aztec/stdlib/block';
15
16
  import type { ValidatorClientFullConfig, WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
16
- import { SlashFactoryContract } from '@aztec/stdlib/l1-contracts';
17
17
  import type { L1ToL2MessageSource } from '@aztec/stdlib/messaging';
18
18
  import { L1Metrics, type TelemetryClient } from '@aztec/telemetry-client';
19
- import { NodeKeystoreAdapter, type ValidatorClient } from '@aztec/validator-client';
19
+ import { FullNodeCheckpointsBuilder, NodeKeystoreAdapter, type ValidatorClient } from '@aztec/validator-client';
20
20
 
21
- import type { SequencerClientConfig } from '../config.js';
22
- 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';
23
23
  import { SequencerPublisherFactory } from '../publisher/sequencer-publisher-factory.js';
24
- import { FullNodeCheckpointsBuilder } from '../sequencer/checkpoint_builder.js';
25
24
  import { Sequencer, type SequencerConfig } from '../sequencer/index.js';
26
25
 
27
26
  /**
@@ -29,11 +28,12 @@ import { Sequencer, type SequencerConfig } from '../sequencer/index.js';
29
28
  */
30
29
  export class SequencerClient {
31
30
  constructor(
32
- protected publisherManager: PublisherManager<L1TxUtilsWithBlobs>,
31
+ protected publisherManager: PublisherManager<L1TxUtils>,
33
32
  protected sequencer: Sequencer,
34
33
  protected checkpointsBuilder: FullNodeCheckpointsBuilder,
35
34
  protected validatorClient?: ValidatorClient,
36
35
  private l1Metrics?: L1Metrics,
36
+ private delayer_?: Delayer,
37
37
  ) {}
38
38
 
39
39
  /**
@@ -56,15 +56,17 @@ export class SequencerClient {
56
56
  worldStateSynchronizer: WorldStateSynchronizer;
57
57
  slasherClient: SlasherClientInterface | undefined;
58
58
  checkpointsBuilder: FullNodeCheckpointsBuilder;
59
- l2BlockSource: L2BlockSource;
59
+ l2BlockSource: L2BlockSource & L2BlockSink & ProposedCheckpointSink;
60
60
  l1ToL2MessageSource: L1ToL2MessageSource;
61
61
  telemetry: TelemetryClient;
62
62
  publisherFactory?: SequencerPublisherFactory;
63
- blobClient?: BlobClientInterface;
63
+ blobClient: BlobClientInterface;
64
64
  dateProvider: DateProvider;
65
65
  epochCache?: EpochCache;
66
- l1TxUtils: L1TxUtilsWithBlobs[];
66
+ l1TxUtils: L1TxUtils[];
67
+ funderL1TxUtils?: L1TxUtils;
67
68
  nodeKeyStore: KeystoreManager;
69
+ globalVariableBuilder: GlobalVariableBuilder;
68
70
  },
69
71
  ) {
70
72
  const {
@@ -86,37 +88,35 @@ export class SequencerClient {
86
88
  publicClient,
87
89
  l1TxUtils.map(x => x.getSenderAddress()),
88
90
  );
89
- const publisherManager = new PublisherManager(l1TxUtils, config);
90
- const rollupContract = new RollupContract(publicClient, config.l1Contracts.rollupAddress.toString());
91
- const [l1GenesisTime, slotDuration, rollupVersion, rollupManaLimit] = await Promise.all([
91
+ const publisherManager = new PublisherManager(l1TxUtils, getPublisherConfigFromSequencerConfig(config), {
92
+ bindings: log.getBindings(),
93
+ funder: deps.funderL1TxUtils,
94
+ });
95
+ const rollupContract = new RollupContract(publicClient, config.rollupAddress.toString());
96
+ const [l1GenesisTime, slotDuration, rollupManaLimit] = await Promise.all([
92
97
  rollupContract.getL1GenesisTime(),
93
98
  rollupContract.getSlotDuration(),
94
- rollupContract.getVersion(),
95
99
  rollupContract.getManaLimit().then(Number),
96
100
  ] as const);
97
101
 
98
102
  const governanceProposerContract = new GovernanceProposerContract(
99
103
  publicClient,
100
- config.l1Contracts.governanceProposerAddress.toString(),
104
+ config.governanceProposerAddress.toString(),
101
105
  );
102
106
  const epochCache =
103
107
  deps.epochCache ??
104
108
  (await EpochCache.create(
105
- config.l1Contracts.rollupAddress,
109
+ config.rollupAddress,
106
110
  {
107
111
  l1RpcUrls: rpcUrls,
108
112
  l1ChainId: chainId,
109
113
  viemPollingIntervalMS: config.viemPollingIntervalMS,
110
114
  ethereumSlotDuration: config.ethereumSlotDuration,
115
+ enableProposerPipelining: config.enableProposerPipelining,
111
116
  },
112
117
  { dateProvider: deps.dateProvider },
113
118
  ));
114
119
 
115
- const slashFactoryContract = new SlashFactoryContract(
116
- publicClient,
117
- config.l1Contracts.slashFactoryAddress?.toString() ?? EthAddress.ZERO.toString(),
118
- );
119
-
120
120
  const publisherFactory =
121
121
  deps.publisherFactory ??
122
122
  new SequencerPublisherFactory(config, {
@@ -124,7 +124,6 @@ export class SequencerClient {
124
124
  blobClient: deps.blobClient,
125
125
  epochCache,
126
126
  governanceProposerContract,
127
- slashFactoryContract,
128
127
  rollupContract,
129
128
  dateProvider: deps.dateProvider,
130
129
  publisherManager,
@@ -133,17 +132,8 @@ export class SequencerClient {
133
132
  });
134
133
 
135
134
  const ethereumSlotDuration = config.ethereumSlotDuration;
136
- const l1Constants = { l1GenesisTime, slotDuration: Number(slotDuration), ethereumSlotDuration };
137
-
138
- const globalsBuilder = new GlobalVariableBuilder({ ...config, ...l1Constants, rollupVersion });
139
135
 
140
- let sequencerManaLimit = config.maxL2BlockGas ?? rollupManaLimit;
141
- if (sequencerManaLimit > rollupManaLimit) {
142
- log.warn(
143
- `Provided maxL2BlockGas ${sequencerManaLimit} is greater than the max allowed by L1. Setting limit to ${rollupManaLimit}.`,
144
- );
145
- sequencerManaLimit = rollupManaLimit;
146
- }
136
+ const globalsBuilder = deps.globalVariableBuilder;
147
137
 
148
138
  // When running in anvil, assume we can post a tx up until one second before the end of an L1 slot.
149
139
  // Otherwise, we need the full L1 slot duration for publishing to ensure inclusion.
@@ -153,6 +143,16 @@ export class SequencerClient {
153
143
  const l1PublishingTimeBasedOnChain = isAnvilTestChain(config.l1ChainId) ? 1 : ethereumSlotDuration;
154
144
  const l1PublishingTime = config.l1PublishingTime ?? l1PublishingTimeBasedOnChain;
155
145
 
146
+ const { maxL2BlockGas, maxDABlockGas, maxTxsPerBlock } = capPerBlockLimits(config, rollupManaLimit, log);
147
+
148
+ const l1Constants = {
149
+ l1GenesisTime,
150
+ slotDuration: Number(slotDuration),
151
+ ethereumSlotDuration,
152
+ rollupManaLimit,
153
+ epochDuration: config.aztecEpochDuration,
154
+ };
155
+
156
156
  const sequencer = new Sequencer(
157
157
  publisherFactory,
158
158
  validatorClient,
@@ -167,14 +167,17 @@ export class SequencerClient {
167
167
  deps.dateProvider,
168
168
  epochCache,
169
169
  rollupContract,
170
- { ...config, l1PublishingTime, maxL2BlockGas: sequencerManaLimit },
170
+ { ...config, l1PublishingTime, maxL2BlockGas, maxDABlockGas, maxTxsPerBlock },
171
171
  telemetryClient,
172
172
  log,
173
173
  );
174
174
 
175
- await sequencer.init();
175
+ sequencer.init();
176
+
177
+ // Extract the shared delayer from the first L1TxUtils instance (all instances share the same delayer)
178
+ const delayer = l1TxUtils[0]?.delayer;
176
179
 
177
- return new SequencerClient(publisherManager, sequencer, checkpointsBuilder, validatorClient, l1Metrics);
180
+ return new SequencerClient(publisherManager, sequencer, checkpointsBuilder, validatorClient, l1Metrics, delayer);
178
181
  }
179
182
 
180
183
  /**
@@ -192,7 +195,7 @@ export class SequencerClient {
192
195
  await this.validatorClient?.start();
193
196
  this.sequencer.start();
194
197
  this.l1Metrics?.start();
195
- await this.publisherManager.loadState();
198
+ await this.publisherManager.start();
196
199
  }
197
200
 
198
201
  /**
@@ -201,14 +204,29 @@ export class SequencerClient {
201
204
  public async stop() {
202
205
  await this.sequencer.stop();
203
206
  await this.validatorClient?.stop();
204
- this.publisherManager.interrupt();
207
+ await this.publisherManager.stop();
205
208
  this.l1Metrics?.stop();
206
209
  }
207
210
 
211
+ /** Triggers an immediate run of the sequencer, bypassing the polling interval. */
212
+ public trigger() {
213
+ return this.sequencer.trigger();
214
+ }
215
+
208
216
  public getSequencer(): Sequencer {
209
217
  return this.sequencer;
210
218
  }
211
219
 
220
+ /** Updates the publisher factory's node keystore adapter after a keystore reload. */
221
+ public updatePublisherNodeKeyStore(adapter: NodeKeystoreAdapter): void {
222
+ this.sequencer.updatePublisherNodeKeyStore(adapter);
223
+ }
224
+
225
+ /** Returns the shared tx delayer for sequencer L1 txs, if enabled. Test-only. */
226
+ getDelayer(): Delayer | undefined {
227
+ return this.delayer_;
228
+ }
229
+
212
230
  get validatorAddresses(): EthAddress[] | undefined {
213
231
  return this.sequencer.getValidatorAddresses();
214
232
  }
@@ -217,3 +235,41 @@ export class SequencerClient {
217
235
  return this.sequencer.maxL2BlockGas;
218
236
  }
219
237
  }
238
+
239
+ /**
240
+ * Caps operator-provided per-block limits at checkpoint-level limits.
241
+ * Returns undefined for any limit the operator didn't set — the checkpoint builder handles redistribution.
242
+ */
243
+ function capPerBlockLimits(
244
+ config: SequencerClientConfig,
245
+ rollupManaLimit: number,
246
+ log: ReturnType<typeof createLogger>,
247
+ ): { maxL2BlockGas: number | undefined; maxDABlockGas: number | undefined; maxTxsPerBlock: number | undefined } {
248
+ let maxL2BlockGas = config.maxL2BlockGas;
249
+ if (maxL2BlockGas !== undefined && maxL2BlockGas > rollupManaLimit) {
250
+ log.warn(`Provided MAX_L2_BLOCK_GAS ${maxL2BlockGas} exceeds rollup mana limit ${rollupManaLimit} (capping)`);
251
+ maxL2BlockGas = rollupManaLimit;
252
+ }
253
+
254
+ let maxDABlockGas = config.maxDABlockGas;
255
+ if (maxDABlockGas !== undefined && maxDABlockGas > MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT) {
256
+ log.warn(
257
+ `Provided MAX_DA_BLOCK_GAS ${maxDABlockGas} exceeds DA checkpoint limit ${MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT} (capping)`,
258
+ );
259
+ maxDABlockGas = MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT;
260
+ }
261
+
262
+ let maxTxsPerBlock = config.maxTxsPerBlock;
263
+ if (
264
+ maxTxsPerBlock !== undefined &&
265
+ config.maxTxsPerCheckpoint !== undefined &&
266
+ maxTxsPerBlock > config.maxTxsPerCheckpoint
267
+ ) {
268
+ log.warn(
269
+ `Provided MAX_TX_PER_BLOCK ${maxTxsPerBlock} exceeds MAX_TX_PER_CHECKPOINT ${config.maxTxsPerCheckpoint} (capping)`,
270
+ );
271
+ maxTxsPerBlock = config.maxTxsPerCheckpoint;
272
+ }
273
+
274
+ return { maxL2BlockGas, maxDABlockGas, maxTxsPerBlock };
275
+ }
package/src/config.ts CHANGED
@@ -5,64 +5,78 @@ import {
5
5
  booleanConfigHelper,
6
6
  getConfigFromMappings,
7
7
  numberConfigHelper,
8
+ optionalNumberConfigHelper,
8
9
  pickConfigMappings,
9
10
  } from '@aztec/foundation/config';
10
11
  import { EthAddress } from '@aztec/foundation/eth-address';
11
12
  import { type KeyStoreConfig, keyStoreConfigMappings } from '@aztec/node-keystore/config';
12
13
  import { type P2PConfig, p2pConfigMappings } from '@aztec/p2p/config';
13
14
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
14
- import { type ChainConfig, type SequencerConfig, chainConfigMappings } from '@aztec/stdlib/config';
15
+ import {
16
+ type ChainConfig,
17
+ DEFAULT_MAX_BLOCKS_PER_CHECKPOINT,
18
+ type PipelineConfig,
19
+ type SequencerConfig,
20
+ chainConfigMappings,
21
+ pipelineConfigMappings,
22
+ sharedSequencerConfigMappings,
23
+ } from '@aztec/stdlib/config';
15
24
  import type { ResolvedSequencerConfig } from '@aztec/stdlib/interfaces/server';
25
+ import { DEFAULT_P2P_PROPAGATION_TIME } from '@aztec/stdlib/timetable';
16
26
  import { type ValidatorClientConfig, validatorClientConfigMappings } from '@aztec/validator-client/config';
17
27
 
18
28
  import {
19
- type PublisherConfig,
20
- type TxSenderConfig,
21
- getPublisherConfigMappings,
22
- getTxSenderConfigMappings,
29
+ type SequencerPublisherConfig,
30
+ type SequencerTxSenderConfig,
31
+ sequencerPublisherConfigMappings,
32
+ sequencerTxSenderConfigMappings,
23
33
  } from './publisher/config.js';
24
34
 
25
35
  export * from './publisher/config.js';
26
36
  export type { SequencerConfig };
27
37
 
28
- export const DEFAULT_ATTESTATION_PROPAGATION_TIME = 2;
29
-
30
38
  /**
31
39
  * Default values for SequencerConfig.
32
40
  * Centralized location for all sequencer configuration defaults.
33
41
  */
34
- export const DefaultSequencerConfig: ResolvedSequencerConfig = {
42
+ export const DefaultSequencerConfig = {
35
43
  sequencerPollingIntervalMS: 500,
36
- maxTxsPerBlock: 32,
37
44
  minTxsPerBlock: 1,
38
45
  buildCheckpointIfEmpty: false,
39
46
  publishTxsWithProposals: false,
40
- maxL2BlockGas: 10e9,
41
- maxDABlockGas: 10e9,
42
- maxBlockSizeInBytes: 1024 * 1024,
47
+ perBlockAllocationMultiplier: 1.2,
48
+ redistributeCheckpointBudget: true,
43
49
  enforceTimeTable: true,
44
- attestationPropagationTime: DEFAULT_ATTESTATION_PROPAGATION_TIME,
50
+ attestationPropagationTime: DEFAULT_P2P_PROPAGATION_TIME,
45
51
  secondsBeforeInvalidatingBlockAsCommitteeMember: 144, // 12 L1 blocks
46
52
  secondsBeforeInvalidatingBlockAsNonCommitteeMember: 432, // 36 L1 blocks
47
53
  skipCollectingAttestations: false,
48
54
  skipInvalidateBlockAsProposer: false,
55
+ skipWaitForValidParentCheckpointOnL1: false,
49
56
  broadcastInvalidBlockProposal: false,
57
+ broadcastInvalidCheckpointProposalOnly: false,
50
58
  injectFakeAttestation: false,
59
+ injectHighSValueAttestation: false,
60
+ injectUnrecoverableSignatureAttestation: false,
51
61
  fishermanMode: false,
52
62
  shuffleAttestationOrdering: false,
53
- };
63
+ skipPushProposedBlocksToArchiver: false,
64
+ skipPublishingCheckpointsPercent: 0,
65
+ maxBlocksPerCheckpoint: DEFAULT_MAX_BLOCKS_PER_CHECKPOINT,
66
+ } satisfies ResolvedSequencerConfig;
54
67
 
55
68
  /**
56
69
  * Configuration settings for the SequencerClient.
57
70
  */
58
- export type SequencerClientConfig = PublisherConfig &
71
+ export type SequencerClientConfig = SequencerPublisherConfig &
59
72
  KeyStoreConfig &
60
73
  ValidatorClientConfig &
61
- TxSenderConfig &
74
+ SequencerTxSenderConfig &
62
75
  SequencerConfig &
63
76
  L1ReaderConfig &
64
77
  ChainConfig &
65
- Pick<P2PConfig, 'txPublicSetupAllowList'> &
78
+ PipelineConfig &
79
+ Pick<P2PConfig, 'txPublicSetupAllowListExtend'> &
66
80
  Pick<L1ContractsConfig, 'ethereumSlotDuration' | 'aztecSlotDuration' | 'aztecEpochDuration'>;
67
81
 
68
82
  export const sequencerConfigMappings: ConfigMappingsType<SequencerConfig> = {
@@ -71,10 +85,10 @@ export const sequencerConfigMappings: ConfigMappingsType<SequencerConfig> = {
71
85
  description: 'The number of ms to wait between polling for checking to build on the next slot.',
72
86
  ...numberConfigHelper(DefaultSequencerConfig.sequencerPollingIntervalMS),
73
87
  },
74
- maxTxsPerBlock: {
75
- env: 'SEQ_MAX_TX_PER_BLOCK',
76
- description: 'The maximum number of txs to include in a block.',
77
- ...numberConfigHelper(DefaultSequencerConfig.maxTxsPerBlock),
88
+ maxTxsPerCheckpoint: {
89
+ env: 'SEQ_MAX_TX_PER_CHECKPOINT',
90
+ description: 'The maximum number of txs across all blocks in a checkpoint.',
91
+ ...optionalNumberConfigHelper(),
78
92
  },
79
93
  minTxsPerBlock: {
80
94
  env: 'SEQ_MIN_TX_PER_BLOCK',
@@ -93,16 +107,29 @@ export const sequencerConfigMappings: ConfigMappingsType<SequencerConfig> = {
93
107
  maxL2BlockGas: {
94
108
  env: 'SEQ_MAX_L2_BLOCK_GAS',
95
109
  description: 'The maximum L2 block gas.',
96
- ...numberConfigHelper(DefaultSequencerConfig.maxL2BlockGas),
110
+ ...optionalNumberConfigHelper(),
97
111
  },
98
112
  maxDABlockGas: {
99
113
  env: 'SEQ_MAX_DA_BLOCK_GAS',
100
114
  description: 'The maximum DA block gas.',
101
- ...numberConfigHelper(DefaultSequencerConfig.maxDABlockGas),
115
+ ...optionalNumberConfigHelper(),
116
+ },
117
+ perBlockAllocationMultiplier: {
118
+ env: 'SEQ_PER_BLOCK_ALLOCATION_MULTIPLIER',
119
+ description:
120
+ 'Per-block gas budget multiplier for both L2 and DA gas. Budget per block is (checkpointLimit / maxBlocks) * multiplier.' +
121
+ ' Values greater than one allow early blocks to use more than their even share, relying on checkpoint-level capping for later blocks.',
122
+ ...numberConfigHelper(DefaultSequencerConfig.perBlockAllocationMultiplier),
123
+ },
124
+ redistributeCheckpointBudget: {
125
+ env: 'SEQ_REDISTRIBUTE_CHECKPOINT_BUDGET',
126
+ description:
127
+ 'Redistribute remaining checkpoint budget evenly across remaining blocks instead of allowing a single block to consume the entire remaining budget.',
128
+ ...booleanConfigHelper(DefaultSequencerConfig.redistributeCheckpointBudget),
102
129
  },
103
130
  coinbase: {
104
131
  env: 'COINBASE',
105
- parseEnv: (val: string) => (val ? EthAddress.fromString(val) : undefined),
132
+ parseEnv: (val: string) => EthAddress.fromString(val),
106
133
  description: 'Recipient of block reward.',
107
134
  },
108
135
  feeRecipient: {
@@ -118,11 +145,6 @@ export const sequencerConfigMappings: ConfigMappingsType<SequencerConfig> = {
118
145
  env: 'ACVM_BINARY_PATH',
119
146
  description: 'The path to the ACVM binary',
120
147
  },
121
- maxBlockSizeInBytes: {
122
- env: 'SEQ_MAX_BLOCK_SIZE_IN_BYTES',
123
- description: 'Max block size',
124
- ...numberConfigHelper(DefaultSequencerConfig.maxBlockSizeInBytes),
125
- },
126
148
  enforceTimeTable: {
127
149
  env: 'SEQ_ENFORCE_TIME_TABLE',
128
150
  description: 'Whether to enforce the time table when building blocks',
@@ -136,12 +158,7 @@ export const sequencerConfigMappings: ConfigMappingsType<SequencerConfig> = {
136
158
  l1PublishingTime: {
137
159
  env: 'SEQ_L1_PUBLISHING_TIME_ALLOWANCE_IN_SLOT',
138
160
  description: 'How much time (in seconds) we allow in the slot for publishing the L1 tx (defaults to 1 L1 slot).',
139
- parseEnv: (val: string) => (val ? parseInt(val, 10) : undefined),
140
- },
141
- attestationPropagationTime: {
142
- env: 'SEQ_ATTESTATION_PROPAGATION_TIME',
143
- description: 'How many seconds it takes for proposals and attestations to travel across the p2p layer (one-way)',
144
- ...numberConfigHelper(DefaultSequencerConfig.attestationPropagationTime),
161
+ ...optionalNumberConfigHelper(),
145
162
  },
146
163
  fakeProcessingDelayPerTxMs: {
147
164
  description: 'Used for testing to introduce a fake delay after processing each tx',
@@ -172,14 +189,37 @@ export const sequencerConfigMappings: ConfigMappingsType<SequencerConfig> = {
172
189
  description: 'Do not invalidate the previous block if invalid when we are the proposer (for testing only)',
173
190
  ...booleanConfigHelper(DefaultSequencerConfig.skipInvalidateBlockAsProposer),
174
191
  },
192
+ skipWaitForValidParentCheckpointOnL1: {
193
+ description:
194
+ 'Bypass the parent checkpoint validity check before submitting a pipelined checkpoint, ' +
195
+ 'allowing the proposer to publish even when the parent landed on L1 with invalid attestations (for testing only)',
196
+ ...booleanConfigHelper(DefaultSequencerConfig.skipWaitForValidParentCheckpointOnL1),
197
+ },
175
198
  broadcastInvalidBlockProposal: {
176
199
  description: 'Broadcast invalid block proposals with corrupted state (for testing only)',
177
200
  ...booleanConfigHelper(DefaultSequencerConfig.broadcastInvalidBlockProposal),
178
201
  },
202
+ invalidBlockProposalIndexWithinCheckpoint: {
203
+ description: 'Broadcast an invalid block proposal only at this indexWithinCheckpoint (for testing only)',
204
+ ...optionalNumberConfigHelper(),
205
+ },
206
+ broadcastInvalidCheckpointProposalOnly: {
207
+ description:
208
+ 'Broadcast invalid checkpoint proposals while keeping the underlying block proposals valid (for testing only). When unset, the checkpoint follows broadcastInvalidBlockProposal.',
209
+ ...booleanConfigHelper(DefaultSequencerConfig.broadcastInvalidCheckpointProposalOnly),
210
+ },
179
211
  injectFakeAttestation: {
180
212
  description: 'Inject a fake attestation (for testing only)',
181
213
  ...booleanConfigHelper(DefaultSequencerConfig.injectFakeAttestation),
182
214
  },
215
+ injectHighSValueAttestation: {
216
+ description: 'Inject a malleable attestation with a high-s value (for testing only)',
217
+ ...booleanConfigHelper(DefaultSequencerConfig.injectHighSValueAttestation),
218
+ },
219
+ injectUnrecoverableSignatureAttestation: {
220
+ description: 'Inject an attestation with an unrecoverable signature (for testing only)',
221
+ ...booleanConfigHelper(DefaultSequencerConfig.injectUnrecoverableSignatureAttestation),
222
+ },
183
223
  fishermanMode: {
184
224
  env: 'FISHERMAN_MODE',
185
225
  description:
@@ -190,29 +230,50 @@ export const sequencerConfigMappings: ConfigMappingsType<SequencerConfig> = {
190
230
  description: 'Shuffle attestation ordering to create invalid ordering (for testing only)',
191
231
  ...booleanConfigHelper(DefaultSequencerConfig.shuffleAttestationOrdering),
192
232
  },
193
- blockDurationMs: {
194
- env: 'SEQ_BLOCK_DURATION_MS',
195
- description:
196
- 'Duration per block in milliseconds when building multiple blocks per slot. ' +
197
- 'If undefined (default), builds a single block per slot using the full slot duration.',
198
- parseEnv: (val: string) => (val ? parseInt(val, 10) : undefined),
199
- },
233
+ ...sharedSequencerConfigMappings,
200
234
  buildCheckpointIfEmpty: {
201
235
  env: 'SEQ_BUILD_CHECKPOINT_IF_EMPTY',
202
236
  description: 'Have sequencer build and publish an empty checkpoint if there are no txs',
203
237
  ...booleanConfigHelper(DefaultSequencerConfig.buildCheckpointIfEmpty),
204
238
  },
205
- ...pickConfigMappings(p2pConfigMappings, ['txPublicSetupAllowList']),
239
+ skipPushProposedBlocksToArchiver: {
240
+ description: 'Skip pushing proposed blocks to archiver (default: true)',
241
+ ...booleanConfigHelper(DefaultSequencerConfig.skipPushProposedBlocksToArchiver),
242
+ },
243
+ minBlocksForCheckpoint: {
244
+ description: 'Minimum number of blocks required for a checkpoint proposal (test only)',
245
+ },
246
+ skipPublishingCheckpointsPercent: {
247
+ env: 'SEQ_SKIP_CHECKPOINT_PUBLISH_PERCENT',
248
+ description: 'Percent probability (0 - 100) of sequencer skipping checkpoint publishing (testing only)',
249
+ ...numberConfigHelper(DefaultSequencerConfig.skipPublishingCheckpointsPercent),
250
+ },
251
+ skipBroadcastProposals: {
252
+ description: 'Skip broadcasting checkpoint and block proposals via gossipsub when proposer (for testing only)',
253
+ ...booleanConfigHelper(false),
254
+ },
255
+ skipBroadcastCheckpointProposal: {
256
+ description:
257
+ 'Skip broadcasting only the CheckpointProposal via gossipsub when proposer; the held last block is broadcast ' +
258
+ 'standalone instead so peers still receive it as a proposed-but-uncheckpointed tip (for testing only)',
259
+ ...booleanConfigHelper(false),
260
+ },
261
+ pauseProposingForSlots: {
262
+ description:
263
+ 'List of slots for which the sequencer will not produce a proposal (for testing only). Attestation paths are unaffected.',
264
+ },
265
+ ...pickConfigMappings(p2pConfigMappings, ['txPublicSetupAllowListExtend']),
206
266
  };
207
267
 
208
268
  export const sequencerClientConfigMappings: ConfigMappingsType<SequencerClientConfig> = {
269
+ ...chainConfigMappings,
209
270
  ...validatorClientConfigMappings,
210
271
  ...sequencerConfigMappings,
211
272
  ...keyStoreConfigMappings,
212
273
  ...l1ReaderConfigMappings,
213
- ...getTxSenderConfigMappings('SEQ'),
214
- ...getPublisherConfigMappings('SEQ'),
215
- ...chainConfigMappings,
274
+ ...sequencerTxSenderConfigMappings,
275
+ ...sequencerPublisherConfigMappings,
276
+ ...pipelineConfigMappings,
216
277
  ...pickConfigMappings(l1ContractsConfigMappings, ['ethereumSlotDuration', 'aztecSlotDuration', 'aztecEpochDuration']),
217
278
  };
218
279
 
@@ -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.