@aztec/sequencer-client 0.0.0-test.1 → 0.0.1-commit.0b941701

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 (135) hide show
  1. package/dest/client/index.d.ts +1 -1
  2. package/dest/client/sequencer-client.d.ts +31 -31
  3. package/dest/client/sequencer-client.d.ts.map +1 -1
  4. package/dest/client/sequencer-client.js +82 -60
  5. package/dest/config.d.ts +15 -16
  6. package/dest/config.d.ts.map +1 -1
  7. package/dest/config.js +118 -70
  8. package/dest/global_variable_builder/global_builder.d.ts +26 -15
  9. package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
  10. package/dest/global_variable_builder/global_builder.js +62 -44
  11. package/dest/global_variable_builder/index.d.ts +1 -1
  12. package/dest/index.d.ts +2 -4
  13. package/dest/index.d.ts.map +1 -1
  14. package/dest/index.js +1 -3
  15. package/dest/publisher/config.d.ts +15 -12
  16. package/dest/publisher/config.d.ts.map +1 -1
  17. package/dest/publisher/config.js +32 -19
  18. package/dest/publisher/index.d.ts +3 -1
  19. package/dest/publisher/index.d.ts.map +1 -1
  20. package/dest/publisher/index.js +3 -0
  21. package/dest/publisher/sequencer-publisher-factory.d.ts +44 -0
  22. package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -0
  23. package/dest/publisher/sequencer-publisher-factory.js +51 -0
  24. package/dest/publisher/sequencer-publisher-metrics.d.ts +5 -4
  25. package/dest/publisher/sequencer-publisher-metrics.d.ts.map +1 -1
  26. package/dest/publisher/sequencer-publisher-metrics.js +26 -62
  27. package/dest/publisher/sequencer-publisher.d.ts +134 -87
  28. package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
  29. package/dest/publisher/sequencer-publisher.js +1146 -249
  30. package/dest/sequencer/checkpoint_proposal_job.d.ts +79 -0
  31. package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -0
  32. package/dest/sequencer/checkpoint_proposal_job.js +1165 -0
  33. package/dest/sequencer/checkpoint_voter.d.ts +35 -0
  34. package/dest/sequencer/checkpoint_voter.d.ts.map +1 -0
  35. package/dest/sequencer/checkpoint_voter.js +109 -0
  36. package/dest/sequencer/config.d.ts +7 -1
  37. package/dest/sequencer/config.d.ts.map +1 -1
  38. package/dest/sequencer/errors.d.ts +11 -0
  39. package/dest/sequencer/errors.d.ts.map +1 -0
  40. package/dest/sequencer/errors.js +15 -0
  41. package/dest/sequencer/events.d.ts +46 -0
  42. package/dest/sequencer/events.d.ts.map +1 -0
  43. package/dest/sequencer/events.js +1 -0
  44. package/dest/sequencer/index.d.ts +4 -2
  45. package/dest/sequencer/index.d.ts.map +1 -1
  46. package/dest/sequencer/index.js +3 -1
  47. package/dest/sequencer/metrics.d.ts +48 -12
  48. package/dest/sequencer/metrics.d.ts.map +1 -1
  49. package/dest/sequencer/metrics.js +204 -69
  50. package/dest/sequencer/sequencer.d.ts +144 -137
  51. package/dest/sequencer/sequencer.d.ts.map +1 -1
  52. package/dest/sequencer/sequencer.js +967 -525
  53. package/dest/sequencer/timetable.d.ts +76 -24
  54. package/dest/sequencer/timetable.d.ts.map +1 -1
  55. package/dest/sequencer/timetable.js +177 -61
  56. package/dest/sequencer/types.d.ts +3 -0
  57. package/dest/sequencer/types.d.ts.map +1 -0
  58. package/dest/sequencer/types.js +1 -0
  59. package/dest/sequencer/utils.d.ts +20 -38
  60. package/dest/sequencer/utils.d.ts.map +1 -1
  61. package/dest/sequencer/utils.js +12 -47
  62. package/dest/test/index.d.ts +9 -1
  63. package/dest/test/index.d.ts.map +1 -1
  64. package/dest/test/index.js +0 -4
  65. package/dest/test/mock_checkpoint_builder.d.ts +95 -0
  66. package/dest/test/mock_checkpoint_builder.d.ts.map +1 -0
  67. package/dest/test/mock_checkpoint_builder.js +222 -0
  68. package/dest/test/utils.d.ts +53 -0
  69. package/dest/test/utils.d.ts.map +1 -0
  70. package/dest/test/utils.js +103 -0
  71. package/package.json +47 -45
  72. package/src/client/sequencer-client.ts +106 -107
  73. package/src/config.ts +131 -81
  74. package/src/global_variable_builder/global_builder.ts +84 -55
  75. package/src/index.ts +1 -3
  76. package/src/publisher/config.ts +45 -32
  77. package/src/publisher/index.ts +4 -0
  78. package/src/publisher/sequencer-publisher-factory.ts +92 -0
  79. package/src/publisher/sequencer-publisher-metrics.ts +30 -64
  80. package/src/publisher/sequencer-publisher.ts +967 -295
  81. package/src/sequencer/README.md +531 -0
  82. package/src/sequencer/checkpoint_proposal_job.ts +845 -0
  83. package/src/sequencer/checkpoint_voter.ts +130 -0
  84. package/src/sequencer/config.ts +8 -0
  85. package/src/sequencer/errors.ts +21 -0
  86. package/src/sequencer/events.ts +27 -0
  87. package/src/sequencer/index.ts +3 -1
  88. package/src/sequencer/metrics.ts +269 -72
  89. package/src/sequencer/sequencer.ts +708 -588
  90. package/src/sequencer/timetable.ts +221 -62
  91. package/src/sequencer/types.ts +6 -0
  92. package/src/sequencer/utils.ts +28 -60
  93. package/src/test/index.ts +12 -4
  94. package/src/test/mock_checkpoint_builder.ts +311 -0
  95. package/src/test/utils.ts +164 -0
  96. package/dest/sequencer/allowed.d.ts +0 -3
  97. package/dest/sequencer/allowed.d.ts.map +0 -1
  98. package/dest/sequencer/allowed.js +0 -27
  99. package/dest/slasher/factory.d.ts +0 -7
  100. package/dest/slasher/factory.d.ts.map +0 -1
  101. package/dest/slasher/factory.js +0 -8
  102. package/dest/slasher/index.d.ts +0 -3
  103. package/dest/slasher/index.d.ts.map +0 -1
  104. package/dest/slasher/index.js +0 -2
  105. package/dest/slasher/slasher_client.d.ts +0 -75
  106. package/dest/slasher/slasher_client.d.ts.map +0 -1
  107. package/dest/slasher/slasher_client.js +0 -132
  108. package/dest/tx_validator/archive_cache.d.ts +0 -14
  109. package/dest/tx_validator/archive_cache.d.ts.map +0 -1
  110. package/dest/tx_validator/archive_cache.js +0 -22
  111. package/dest/tx_validator/gas_validator.d.ts +0 -14
  112. package/dest/tx_validator/gas_validator.d.ts.map +0 -1
  113. package/dest/tx_validator/gas_validator.js +0 -78
  114. package/dest/tx_validator/nullifier_cache.d.ts +0 -16
  115. package/dest/tx_validator/nullifier_cache.d.ts.map +0 -1
  116. package/dest/tx_validator/nullifier_cache.js +0 -24
  117. package/dest/tx_validator/phases_validator.d.ts +0 -12
  118. package/dest/tx_validator/phases_validator.d.ts.map +0 -1
  119. package/dest/tx_validator/phases_validator.js +0 -80
  120. package/dest/tx_validator/test_utils.d.ts +0 -23
  121. package/dest/tx_validator/test_utils.d.ts.map +0 -1
  122. package/dest/tx_validator/test_utils.js +0 -26
  123. package/dest/tx_validator/tx_validator_factory.d.ts +0 -18
  124. package/dest/tx_validator/tx_validator_factory.d.ts.map +0 -1
  125. package/dest/tx_validator/tx_validator_factory.js +0 -50
  126. package/src/sequencer/allowed.ts +0 -36
  127. package/src/slasher/factory.ts +0 -15
  128. package/src/slasher/index.ts +0 -2
  129. package/src/slasher/slasher_client.ts +0 -193
  130. package/src/tx_validator/archive_cache.ts +0 -28
  131. package/src/tx_validator/gas_validator.ts +0 -101
  132. package/src/tx_validator/nullifier_cache.ts +0 -30
  133. package/src/tx_validator/phases_validator.ts +0 -98
  134. package/src/tx_validator/test_utils.ts +0 -48
  135. package/src/tx_validator/tx_validator_factory.ts +0 -120
@@ -1,43 +1,42 @@
1
- import type { BlobSinkClientInterface } from '@aztec/blob-sink/client';
1
+ import type { BlobClientInterface } from '@aztec/blob-client/client';
2
2
  import { EpochCache } from '@aztec/epoch-cache';
3
- import {
4
- ForwarderContract,
5
- GovernanceProposerContract,
6
- RollupContract,
7
- SlashingProposerContract,
8
- createEthereumChain,
9
- createL1Clients,
10
- isAnvilTestChain,
11
- } from '@aztec/ethereum';
3
+ import { isAnvilTestChain } from '@aztec/ethereum/chain';
4
+ import { getPublicClient } from '@aztec/ethereum/client';
5
+ import { GovernanceProposerContract, RollupContract } from '@aztec/ethereum/contracts';
12
6
  import { L1TxUtilsWithBlobs } from '@aztec/ethereum/l1-tx-utils-with-blobs';
7
+ import { PublisherManager } from '@aztec/ethereum/publisher-manager';
13
8
  import { EthAddress } from '@aztec/foundation/eth-address';
14
9
  import { createLogger } from '@aztec/foundation/log';
15
10
  import type { DateProvider } from '@aztec/foundation/timer';
11
+ import type { KeystoreManager } from '@aztec/node-keystore';
16
12
  import type { P2P } from '@aztec/p2p';
17
- import { LightweightBlockBuilderFactory } from '@aztec/prover-client/block-builder';
18
- import { PublicProcessorFactory } from '@aztec/simulator/server';
19
- import type { AztecAddress } from '@aztec/stdlib/aztec-address';
20
- import type { L2BlockSource } from '@aztec/stdlib/block';
21
- import type { ContractDataSource } from '@aztec/stdlib/contract';
22
- import type { WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
13
+ import type { SlasherClientInterface } from '@aztec/slasher';
14
+ import type { L2BlockSink, L2BlockSource } from '@aztec/stdlib/block';
15
+ import type { ValidatorClientFullConfig, WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
16
+ import { SlashFactoryContract } from '@aztec/stdlib/l1-contracts';
23
17
  import type { L1ToL2MessageSource } from '@aztec/stdlib/messaging';
24
- import type { TelemetryClient } from '@aztec/telemetry-client';
25
- import type { ValidatorClient } from '@aztec/validator-client';
18
+ import { L1Metrics, type TelemetryClient } from '@aztec/telemetry-client';
19
+ import { FullNodeCheckpointsBuilder, NodeKeystoreAdapter, type ValidatorClient } from '@aztec/validator-client';
26
20
 
27
21
  import type { SequencerClientConfig } from '../config.js';
28
22
  import { GlobalVariableBuilder } from '../global_variable_builder/index.js';
29
- import { SequencerPublisher } from '../publisher/index.js';
23
+ import { SequencerPublisherFactory } from '../publisher/sequencer-publisher-factory.js';
30
24
  import { Sequencer, type SequencerConfig } from '../sequencer/index.js';
31
- import type { SlasherClient } from '../slasher/index.js';
32
25
 
33
26
  /**
34
27
  * Encapsulates the full sequencer and publisher.
35
28
  */
36
29
  export class SequencerClient {
37
- constructor(protected sequencer: Sequencer) {}
30
+ constructor(
31
+ protected publisherManager: PublisherManager<L1TxUtilsWithBlobs>,
32
+ protected sequencer: Sequencer,
33
+ protected checkpointsBuilder: FullNodeCheckpointsBuilder,
34
+ protected validatorClient?: ValidatorClient,
35
+ private l1Metrics?: L1Metrics,
36
+ ) {}
38
37
 
39
38
  /**
40
- * Initializes and starts a new instance.
39
+ * Initializes a new instance.
41
40
  * @param config - Configuration for the sequencer, publisher, and L1 tx sender.
42
41
  * @param p2pClient - P2P client that provides the txs to be sequenced.
43
42
  * @param validatorClient - Validator client performs attestation duties when rotating proposers.
@@ -46,25 +45,25 @@ export class SequencerClient {
46
45
  * @param l2BlockSource - Provides information about the previously published blocks.
47
46
  * @param l1ToL2MessageSource - Provides access to L1 to L2 messages.
48
47
  * @param prover - An instance of a block prover
49
- * @param simulationProvider - An instance of a simulation provider
50
48
  * @returns A new running instance.
51
49
  */
52
50
  public static async new(
53
51
  config: SequencerClientConfig,
54
52
  deps: {
55
- validatorClient: ValidatorClient | undefined; // allowed to be undefined while we migrate
53
+ validatorClient: ValidatorClient;
56
54
  p2pClient: P2P;
57
55
  worldStateSynchronizer: WorldStateSynchronizer;
58
- slasherClient: SlasherClient;
59
- contractDataSource: ContractDataSource;
60
- l2BlockSource: L2BlockSource;
56
+ slasherClient: SlasherClientInterface | undefined;
57
+ checkpointsBuilder: FullNodeCheckpointsBuilder;
58
+ l2BlockSource: L2BlockSource & L2BlockSink;
61
59
  l1ToL2MessageSource: L1ToL2MessageSource;
62
60
  telemetry: TelemetryClient;
63
- publisher?: SequencerPublisher;
64
- blobSinkClient?: BlobSinkClientInterface;
61
+ publisherFactory?: SequencerPublisherFactory;
62
+ blobClient: BlobClientInterface;
65
63
  dateProvider: DateProvider;
66
64
  epochCache?: EpochCache;
67
- l1TxUtils?: L1TxUtilsWithBlobs;
65
+ l1TxUtils: L1TxUtilsWithBlobs[];
66
+ nodeKeyStore: KeystoreManager;
68
67
  },
69
68
  ) {
70
69
  const {
@@ -72,42 +71,33 @@ export class SequencerClient {
72
71
  p2pClient,
73
72
  worldStateSynchronizer,
74
73
  slasherClient,
75
- contractDataSource,
74
+ checkpointsBuilder,
76
75
  l2BlockSource,
77
76
  l1ToL2MessageSource,
78
77
  telemetry: telemetryClient,
79
78
  } = deps;
80
- const { l1RpcUrls: rpcUrls, l1ChainId: chainId, publisherPrivateKey } = config;
81
- const chain = createEthereumChain(rpcUrls, chainId);
82
- const log = createLogger('sequencer-client');
83
- const { publicClient, walletClient } = createL1Clients(rpcUrls, publisherPrivateKey, chain.chainInfo);
84
- const l1TxUtils = deps.l1TxUtils ?? new L1TxUtilsWithBlobs(publicClient, walletClient, log, config);
79
+ const { l1RpcUrls: rpcUrls, l1ChainId: chainId } = config;
80
+ const log = createLogger('sequencer');
81
+ const publicClient = getPublicClient(config);
82
+ const l1TxUtils = deps.l1TxUtils;
83
+ const l1Metrics = new L1Metrics(
84
+ telemetryClient.getMeter('L1PublisherMetrics'),
85
+ publicClient,
86
+ l1TxUtils.map(x => x.getSenderAddress()),
87
+ );
88
+ const publisherManager = new PublisherManager(l1TxUtils, config);
85
89
  const rollupContract = new RollupContract(publicClient, config.l1Contracts.rollupAddress.toString());
86
- const [l1GenesisTime, slotDuration] = await Promise.all([
90
+ const [l1GenesisTime, slotDuration, rollupVersion, rollupManaLimit] = await Promise.all([
87
91
  rollupContract.getL1GenesisTime(),
88
92
  rollupContract.getSlotDuration(),
93
+ rollupContract.getVersion(),
94
+ rollupContract.getManaLimit().then(Number),
89
95
  ] as const);
90
- const forwarderContract =
91
- config.customForwarderContractAddress && config.customForwarderContractAddress !== EthAddress.ZERO
92
- ? new ForwarderContract(
93
- publicClient,
94
- config.customForwarderContractAddress.toString(),
95
- config.l1Contracts.rollupAddress.toString(),
96
- )
97
- : await ForwarderContract.create(
98
- walletClient.account.address,
99
- walletClient,
100
- publicClient,
101
- log,
102
- config.l1Contracts.rollupAddress.toString(),
103
- );
104
96
 
105
97
  const governanceProposerContract = new GovernanceProposerContract(
106
98
  publicClient,
107
99
  config.l1Contracts.governanceProposerAddress.toString(),
108
100
  );
109
- const slashingProposerAddress = await rollupContract.getSlashingProposerAddress();
110
- const slashingProposerContract = new SlashingProposerContract(publicClient, slashingProposerAddress.toString());
111
101
  const epochCache =
112
102
  deps.epochCache ??
113
103
  (await EpochCache.create(
@@ -116,74 +106,92 @@ export class SequencerClient {
116
106
  l1RpcUrls: rpcUrls,
117
107
  l1ChainId: chainId,
118
108
  viemPollingIntervalMS: config.viemPollingIntervalMS,
119
- aztecSlotDuration: config.aztecSlotDuration,
120
109
  ethereumSlotDuration: config.ethereumSlotDuration,
121
- aztecEpochDuration: config.aztecEpochDuration,
122
110
  },
123
111
  { dateProvider: deps.dateProvider },
124
112
  ));
125
113
 
126
- const publisher =
127
- deps.publisher ??
128
- new SequencerPublisher(config, {
129
- l1TxUtils,
114
+ const slashFactoryContract = new SlashFactoryContract(
115
+ publicClient,
116
+ config.l1Contracts.slashFactoryAddress?.toString() ?? EthAddress.ZERO.toString(),
117
+ );
118
+
119
+ const publisherFactory =
120
+ deps.publisherFactory ??
121
+ new SequencerPublisherFactory(config, {
130
122
  telemetry: telemetryClient,
131
- blobSinkClient: deps.blobSinkClient,
132
- rollupContract,
123
+ blobClient: deps.blobClient,
133
124
  epochCache,
134
- forwarderContract,
135
125
  governanceProposerContract,
136
- slashingProposerContract,
126
+ slashFactoryContract,
127
+ rollupContract,
128
+ dateProvider: deps.dateProvider,
129
+ publisherManager,
130
+ nodeKeyStore: NodeKeystoreAdapter.fromKeyStoreManager(deps.nodeKeyStore),
131
+ logger: log,
137
132
  });
138
- const globalsBuilder = new GlobalVariableBuilder(config);
139
-
140
- const publicProcessorFactory = new PublicProcessorFactory(contractDataSource, deps.dateProvider, telemetryClient);
141
133
 
142
134
  const ethereumSlotDuration = config.ethereumSlotDuration;
135
+ const l1Constants = { l1GenesisTime, slotDuration: Number(slotDuration), ethereumSlotDuration };
136
+
137
+ const globalsBuilder = new GlobalVariableBuilder({ ...config, ...l1Constants, rollupVersion });
143
138
 
144
- // When running in anvil, assume we can post a tx up until the very last second of an L1 slot.
145
- // Otherwise, assume we must have broadcasted the tx before the slot started (we use a default
146
- // maxL1TxInclusionTimeIntoSlot of zero) to get the tx into that L1 slot.
139
+ let sequencerManaLimit = config.maxL2BlockGas ?? rollupManaLimit;
140
+ if (sequencerManaLimit > rollupManaLimit) {
141
+ log.warn(
142
+ `Provided maxL2BlockGas ${sequencerManaLimit} is greater than the max allowed by L1. Setting limit to ${rollupManaLimit}.`,
143
+ );
144
+ sequencerManaLimit = rollupManaLimit;
145
+ }
146
+
147
+ // When running in anvil, assume we can post a tx up until one second before the end of an L1 slot.
148
+ // Otherwise, we need the full L1 slot duration for publishing to ensure inclusion.
147
149
  // In theory, the L1 slot has an initial 4s phase where the block is propagated, so we could
148
- // make it with a propagation time into slot equal to 4s. However, we prefer being conservative.
150
+ // reduce the publishing time allowance. However, we prefer being conservative.
149
151
  // See https://www.blocknative.com/blog/anatomy-of-a-slot#7 for more info.
150
- const maxL1TxInclusionTimeIntoSlot =
151
- config.maxL1TxInclusionTimeIntoSlot ?? isAnvilTestChain(config.l1ChainId) ? ethereumSlotDuration : 0;
152
-
153
- const l1Constants = {
154
- l1GenesisTime,
155
- slotDuration: Number(slotDuration),
156
- ethereumSlotDuration,
157
- };
152
+ const l1PublishingTimeBasedOnChain = isAnvilTestChain(config.l1ChainId) ? 1 : ethereumSlotDuration;
153
+ const l1PublishingTime = config.l1PublishingTime ?? l1PublishingTimeBasedOnChain;
158
154
 
159
155
  const sequencer = new Sequencer(
160
- publisher,
156
+ publisherFactory,
161
157
  validatorClient,
162
158
  globalsBuilder,
163
159
  p2pClient,
164
160
  worldStateSynchronizer,
165
161
  slasherClient,
166
- new LightweightBlockBuilderFactory(telemetryClient),
167
162
  l2BlockSource,
168
163
  l1ToL2MessageSource,
169
- publicProcessorFactory,
170
- contractDataSource,
164
+ checkpointsBuilder,
171
165
  l1Constants,
172
166
  deps.dateProvider,
173
- { ...config, maxL1TxInclusionTimeIntoSlot },
167
+ epochCache,
168
+ rollupContract,
169
+ { ...config, l1PublishingTime, maxL2BlockGas: sequencerManaLimit },
174
170
  telemetryClient,
171
+ log,
175
172
  );
176
- await validatorClient?.start();
177
- await sequencer.start();
178
- return new SequencerClient(sequencer);
173
+
174
+ await sequencer.init();
175
+
176
+ return new SequencerClient(publisherManager, sequencer, checkpointsBuilder, validatorClient, l1Metrics);
179
177
  }
180
178
 
181
179
  /**
182
- * Updates sequencer config.
180
+ * Updates sequencer and validator client config.
183
181
  * @param config - New parameters.
184
182
  */
185
- public updateSequencerConfig(config: SequencerConfig) {
186
- return this.sequencer.updateConfig(config);
183
+ public updateConfig(config: SequencerConfig & Partial<ValidatorClientFullConfig>) {
184
+ this.sequencer.updateConfig(config);
185
+ this.checkpointsBuilder.updateConfig(config);
186
+ this.validatorClient?.updateConfig(config);
187
+ }
188
+
189
+ /** Starts the sequencer. */
190
+ public async start() {
191
+ await this.validatorClient?.start();
192
+ this.sequencer.start();
193
+ this.l1Metrics?.start();
194
+ await this.publisherManager.loadState();
187
195
  }
188
196
 
189
197
  /**
@@ -191,29 +199,20 @@ export class SequencerClient {
191
199
  */
192
200
  public async stop() {
193
201
  await this.sequencer.stop();
202
+ await this.validatorClient?.stop();
203
+ this.publisherManager.interrupt();
204
+ this.l1Metrics?.stop();
194
205
  }
195
206
 
196
- /** Forces the sequencer to bypass all time and tx count checks for the next block and build anyway. */
197
- public flush() {
198
- this.sequencer.flush();
199
- }
200
-
201
- /**
202
- * Restarts the sequencer after being stopped.
203
- */
204
- public restart() {
205
- this.sequencer.restart();
206
- }
207
-
208
- get coinbase(): EthAddress {
209
- return this.sequencer.coinbase;
207
+ public getSequencer(): Sequencer {
208
+ return this.sequencer;
210
209
  }
211
210
 
212
- get feeRecipient(): AztecAddress {
213
- return this.sequencer.feeRecipient;
211
+ get validatorAddresses(): EthAddress[] | undefined {
212
+ return this.sequencer.getValidatorAddresses();
214
213
  }
215
214
 
216
- get forwarderAddress(): EthAddress {
217
- return this.sequencer.getForwarderAddress();
215
+ get maxL2BlockGas(): number | undefined {
216
+ return this.sequencer.maxL2BlockGas;
218
217
  }
219
218
  }
package/src/config.ts CHANGED
@@ -1,9 +1,5 @@
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,
@@ -12,10 +8,12 @@ import {
12
8
  pickConfigMappings,
13
9
  } from '@aztec/foundation/config';
14
10
  import { EthAddress } from '@aztec/foundation/eth-address';
15
- import { Fr } from '@aztec/foundation/fields';
16
- import { FunctionSelector } from '@aztec/stdlib/abi';
11
+ import { type KeyStoreConfig, keyStoreConfigMappings } from '@aztec/node-keystore/config';
12
+ import { type P2PConfig, p2pConfigMappings } from '@aztec/p2p/config';
17
13
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
18
- import { type AllowedElement, type ChainConfig, type SequencerConfig, chainConfigMappings } from '@aztec/stdlib/config';
14
+ import { type ChainConfig, type SequencerConfig, chainConfigMappings } from '@aztec/stdlib/config';
15
+ import type { ResolvedSequencerConfig } from '@aztec/stdlib/interfaces/server';
16
+ import { type ValidatorClientConfig, validatorClientConfigMappings } from '@aztec/validator-client/config';
19
17
 
20
18
  import {
21
19
  type PublisherConfig,
@@ -27,41 +25,81 @@ import {
27
25
  export * from './publisher/config.js';
28
26
  export type { SequencerConfig };
29
27
 
28
+ export const DEFAULT_ATTESTATION_PROPAGATION_TIME = 2;
29
+
30
+ /**
31
+ * Default values for SequencerConfig.
32
+ * Centralized location for all sequencer configuration defaults.
33
+ */
34
+ export const DefaultSequencerConfig: ResolvedSequencerConfig = {
35
+ sequencerPollingIntervalMS: 500,
36
+ maxTxsPerBlock: 32,
37
+ minTxsPerBlock: 1,
38
+ buildCheckpointIfEmpty: false,
39
+ publishTxsWithProposals: false,
40
+ maxL2BlockGas: 10e9,
41
+ maxDABlockGas: 10e9,
42
+ maxBlockSizeInBytes: 1024 * 1024,
43
+ enforceTimeTable: true,
44
+ attestationPropagationTime: DEFAULT_ATTESTATION_PROPAGATION_TIME,
45
+ secondsBeforeInvalidatingBlockAsCommitteeMember: 144, // 12 L1 blocks
46
+ secondsBeforeInvalidatingBlockAsNonCommitteeMember: 432, // 36 L1 blocks
47
+ skipCollectingAttestations: false,
48
+ skipInvalidateBlockAsProposer: false,
49
+ broadcastInvalidBlockProposal: false,
50
+ injectFakeAttestation: false,
51
+ fishermanMode: false,
52
+ shuffleAttestationOrdering: false,
53
+ skipPushProposedBlocksToArchiver: false,
54
+ };
55
+
30
56
  /**
31
57
  * Configuration settings for the SequencerClient.
32
58
  */
33
59
  export type SequencerClientConfig = PublisherConfig &
60
+ KeyStoreConfig &
61
+ ValidatorClientConfig &
34
62
  TxSenderConfig &
35
63
  SequencerConfig &
36
64
  L1ReaderConfig &
37
65
  ChainConfig &
66
+ Pick<P2PConfig, 'txPublicSetupAllowList'> &
38
67
  Pick<L1ContractsConfig, 'ethereumSlotDuration' | 'aztecSlotDuration' | 'aztecEpochDuration'>;
39
68
 
40
69
  export const sequencerConfigMappings: ConfigMappingsType<SequencerConfig> = {
41
- transactionPollingIntervalMS: {
42
- env: 'SEQ_TX_POLLING_INTERVAL_MS',
43
- description: 'The number of ms to wait between polling for pending txs.',
44
- ...numberConfigHelper(500),
70
+ sequencerPollingIntervalMS: {
71
+ env: 'SEQ_POLLING_INTERVAL_MS',
72
+ description: 'The number of ms to wait between polling for checking to build on the next slot.',
73
+ ...numberConfigHelper(DefaultSequencerConfig.sequencerPollingIntervalMS),
45
74
  },
46
75
  maxTxsPerBlock: {
47
76
  env: 'SEQ_MAX_TX_PER_BLOCK',
48
77
  description: 'The maximum number of txs to include in a block.',
49
- ...numberConfigHelper(32),
78
+ ...numberConfigHelper(DefaultSequencerConfig.maxTxsPerBlock),
50
79
  },
51
80
  minTxsPerBlock: {
52
81
  env: 'SEQ_MIN_TX_PER_BLOCK',
53
82
  description: 'The minimum number of txs to include in a block.',
54
- ...numberConfigHelper(1),
83
+ ...numberConfigHelper(DefaultSequencerConfig.minTxsPerBlock),
84
+ },
85
+ minValidTxsPerBlock: {
86
+ description:
87
+ 'The minimum number of valid txs (after execution) to include in a block. If not set, falls back to minTxsPerBlock.',
88
+ },
89
+ publishTxsWithProposals: {
90
+ env: 'SEQ_PUBLISH_TXS_WITH_PROPOSALS',
91
+ description: 'Whether to publish txs with proposals.',
92
+ ...booleanConfigHelper(DefaultSequencerConfig.publishTxsWithProposals),
55
93
  },
56
94
  maxL2BlockGas: {
57
95
  env: 'SEQ_MAX_L2_BLOCK_GAS',
58
96
  description: 'The maximum L2 block gas.',
59
- ...numberConfigHelper(10e9),
97
+ ...numberConfigHelper(DefaultSequencerConfig.maxL2BlockGas),
60
98
  },
61
99
  maxDABlockGas: {
62
100
  env: 'SEQ_MAX_DA_BLOCK_GAS',
63
101
  description: 'The maximum DA block gas.',
64
- ...numberConfigHelper(10e9),
102
+ ...numberConfigHelper(DefaultSequencerConfig.maxDABlockGas),
65
103
  },
66
104
  coinbase: {
67
105
  env: 'COINBASE',
@@ -81,39 +119,101 @@ export const sequencerConfigMappings: ConfigMappingsType<SequencerConfig> = {
81
119
  env: 'ACVM_BINARY_PATH',
82
120
  description: 'The path to the ACVM binary',
83
121
  },
84
- allowedInSetup: {
85
- env: 'SEQ_ALLOWED_SETUP_FN',
86
- parseEnv: (val: string) => parseSequencerAllowList(val),
87
- description: 'The list of functions calls allowed to run in setup',
88
- printDefault: () =>
89
- 'AuthRegistry, FeeJuice.increase_public_balance, Token.increase_public_balance, FPC.prepare_fee',
90
- },
91
122
  maxBlockSizeInBytes: {
92
123
  env: 'SEQ_MAX_BLOCK_SIZE_IN_BYTES',
93
124
  description: 'Max block size',
94
- ...numberConfigHelper(1024 * 1024),
125
+ ...numberConfigHelper(DefaultSequencerConfig.maxBlockSizeInBytes),
95
126
  },
96
127
  enforceTimeTable: {
97
128
  env: 'SEQ_ENFORCE_TIME_TABLE',
98
129
  description: 'Whether to enforce the time table when building blocks',
99
- ...booleanConfigHelper(),
100
- defaultValue: false,
130
+ ...booleanConfigHelper(DefaultSequencerConfig.enforceTimeTable),
101
131
  },
102
132
  governanceProposerPayload: {
103
133
  env: 'GOVERNANCE_PROPOSER_PAYLOAD_ADDRESS',
104
134
  description: 'The address of the payload for the governanceProposer',
105
135
  parseEnv: (val: string) => EthAddress.fromString(val),
106
- defaultValue: EthAddress.ZERO,
107
136
  },
108
- maxL1TxInclusionTimeIntoSlot: {
109
- env: 'SEQ_MAX_L1_TX_INCLUSION_TIME_INTO_SLOT',
110
- description: 'How many seconds into an L1 slot we can still send a tx and get it mined.',
137
+ l1PublishingTime: {
138
+ env: 'SEQ_L1_PUBLISHING_TIME_ALLOWANCE_IN_SLOT',
139
+ description: 'How much time (in seconds) we allow in the slot for publishing the L1 tx (defaults to 1 L1 slot).',
140
+ parseEnv: (val: string) => (val ? parseInt(val, 10) : undefined),
141
+ },
142
+ attestationPropagationTime: {
143
+ env: 'SEQ_ATTESTATION_PROPAGATION_TIME',
144
+ description: 'How many seconds it takes for proposals and attestations to travel across the p2p layer (one-way)',
145
+ ...numberConfigHelper(DefaultSequencerConfig.attestationPropagationTime),
146
+ },
147
+ fakeProcessingDelayPerTxMs: {
148
+ description: 'Used for testing to introduce a fake delay after processing each tx',
149
+ },
150
+ fakeThrowAfterProcessingTxCount: {
151
+ description: 'Used for testing to throw an error after processing N txs',
152
+ },
153
+ secondsBeforeInvalidatingBlockAsCommitteeMember: {
154
+ env: 'SEQ_SECONDS_BEFORE_INVALIDATING_BLOCK_AS_COMMITTEE_MEMBER',
155
+ description:
156
+ 'How many seconds to wait before trying to invalidate a block from the pending chain as a committee member (zero to never invalidate).' +
157
+ ' The next proposer is expected to invalidate, so the committee acts as a fallback.',
158
+ ...numberConfigHelper(DefaultSequencerConfig.secondsBeforeInvalidatingBlockAsCommitteeMember),
159
+ },
160
+ secondsBeforeInvalidatingBlockAsNonCommitteeMember: {
161
+ env: 'SEQ_SECONDS_BEFORE_INVALIDATING_BLOCK_AS_NON_COMMITTEE_MEMBER',
162
+ description:
163
+ 'How many seconds to wait before trying to invalidate a block from the pending chain as a non-committee member (zero to never invalidate).' +
164
+ ' The next proposer is expected to invalidate, then the committee, so other sequencers act as a fallback.',
165
+ ...numberConfigHelper(DefaultSequencerConfig.secondsBeforeInvalidatingBlockAsNonCommitteeMember),
166
+ },
167
+ skipCollectingAttestations: {
168
+ description:
169
+ 'Whether to skip collecting attestations from validators and only use self-attestations (for testing only)',
170
+ ...booleanConfigHelper(DefaultSequencerConfig.skipCollectingAttestations),
171
+ },
172
+ skipInvalidateBlockAsProposer: {
173
+ description: 'Do not invalidate the previous block if invalid when we are the proposer (for testing only)',
174
+ ...booleanConfigHelper(DefaultSequencerConfig.skipInvalidateBlockAsProposer),
175
+ },
176
+ broadcastInvalidBlockProposal: {
177
+ description: 'Broadcast invalid block proposals with corrupted state (for testing only)',
178
+ ...booleanConfigHelper(DefaultSequencerConfig.broadcastInvalidBlockProposal),
179
+ },
180
+ injectFakeAttestation: {
181
+ description: 'Inject a fake attestation (for testing only)',
182
+ ...booleanConfigHelper(DefaultSequencerConfig.injectFakeAttestation),
183
+ },
184
+ fishermanMode: {
185
+ env: 'FISHERMAN_MODE',
186
+ description:
187
+ 'Whether to run in fisherman mode: builds blocks on every slot for validation without publishing to L1',
188
+ ...booleanConfigHelper(DefaultSequencerConfig.fishermanMode),
189
+ },
190
+ shuffleAttestationOrdering: {
191
+ description: 'Shuffle attestation ordering to create invalid ordering (for testing only)',
192
+ ...booleanConfigHelper(DefaultSequencerConfig.shuffleAttestationOrdering),
193
+ },
194
+ blockDurationMs: {
195
+ env: 'SEQ_BLOCK_DURATION_MS',
196
+ description:
197
+ 'Duration per block in milliseconds when building multiple blocks per slot. ' +
198
+ 'If undefined (default), builds a single block per slot using the full slot duration.',
111
199
  parseEnv: (val: string) => (val ? parseInt(val, 10) : undefined),
112
200
  },
201
+ buildCheckpointIfEmpty: {
202
+ env: 'SEQ_BUILD_CHECKPOINT_IF_EMPTY',
203
+ description: 'Have sequencer build and publish an empty checkpoint if there are no txs',
204
+ ...booleanConfigHelper(DefaultSequencerConfig.buildCheckpointIfEmpty),
205
+ },
206
+ skipPushProposedBlocksToArchiver: {
207
+ description: 'Skip pushing proposed blocks to archiver (default: true)',
208
+ ...booleanConfigHelper(DefaultSequencerConfig.skipPushProposedBlocksToArchiver),
209
+ },
210
+ ...pickConfigMappings(p2pConfigMappings, ['txPublicSetupAllowList']),
113
211
  };
114
212
 
115
213
  export const sequencerClientConfigMappings: ConfigMappingsType<SequencerClientConfig> = {
214
+ ...validatorClientConfigMappings,
116
215
  ...sequencerConfigMappings,
216
+ ...keyStoreConfigMappings,
117
217
  ...l1ReaderConfigMappings,
118
218
  ...getTxSenderConfigMappings('SEQ'),
119
219
  ...getPublisherConfigMappings('SEQ'),
@@ -127,53 +227,3 @@ export const sequencerClientConfigMappings: ConfigMappingsType<SequencerClientCo
127
227
  export function getConfigEnvVars(): SequencerClientConfig {
128
228
  return getConfigFromMappings<SequencerClientConfig>(sequencerClientConfigMappings);
129
229
  }
130
-
131
- /**
132
- * Parses a string to a list of allowed elements.
133
- * Each encoded is expected to be of one of the following formats
134
- * `I:${address}`
135
- * `I:${address}:${selector}`
136
- * `C:${classId}`
137
- * `C:${classId}:${selector}`
138
- *
139
- * @param value The string to parse
140
- * @returns A list of allowed elements
141
- */
142
- export function parseSequencerAllowList(value: string): AllowedElement[] {
143
- const entries: AllowedElement[] = [];
144
-
145
- if (!value) {
146
- return entries;
147
- }
148
-
149
- for (const val of value.split(',')) {
150
- const [typeString, identifierString, selectorString] = val.split(':');
151
- const selector = selectorString !== undefined ? FunctionSelector.fromString(selectorString) : undefined;
152
-
153
- if (typeString === 'I') {
154
- if (selector) {
155
- entries.push({
156
- address: AztecAddress.fromString(identifierString),
157
- selector,
158
- });
159
- } else {
160
- entries.push({
161
- address: AztecAddress.fromString(identifierString),
162
- });
163
- }
164
- } else if (typeString === 'C') {
165
- if (selector) {
166
- entries.push({
167
- classId: Fr.fromHexString(identifierString),
168
- selector,
169
- });
170
- } else {
171
- entries.push({
172
- classId: Fr.fromHexString(identifierString),
173
- });
174
- }
175
- }
176
- }
177
-
178
- return entries;
179
- }