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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (185) hide show
  1. package/README.md +281 -21
  2. package/dest/client/index.d.ts +1 -1
  3. package/dest/client/sequencer-client.d.ts +43 -33
  4. package/dest/client/sequencer-client.d.ts.map +1 -1
  5. package/dest/client/sequencer-client.js +117 -62
  6. package/dest/config.d.ts +38 -17
  7. package/dest/config.d.ts.map +1 -1
  8. package/dest/config.js +172 -85
  9. package/dest/global_variable_builder/fee_predictor.d.ts +37 -0
  10. package/dest/global_variable_builder/fee_predictor.d.ts.map +1 -0
  11. package/dest/global_variable_builder/fee_predictor.js +128 -0
  12. package/dest/global_variable_builder/fee_provider.d.ts +21 -0
  13. package/dest/global_variable_builder/fee_provider.d.ts.map +1 -0
  14. package/dest/global_variable_builder/fee_provider.js +58 -0
  15. package/dest/global_variable_builder/global_builder.d.ts +26 -17
  16. package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
  17. package/dest/global_variable_builder/global_builder.js +45 -61
  18. package/dest/global_variable_builder/index.d.ts +4 -2
  19. package/dest/global_variable_builder/index.d.ts.map +1 -1
  20. package/dest/global_variable_builder/index.js +2 -0
  21. package/dest/index.d.ts +2 -4
  22. package/dest/index.d.ts.map +1 -1
  23. package/dest/index.js +1 -3
  24. package/dest/publisher/config.d.ts +60 -27
  25. package/dest/publisher/config.d.ts.map +1 -1
  26. package/dest/publisher/config.js +124 -32
  27. package/dest/publisher/index.d.ts +4 -1
  28. package/dest/publisher/index.d.ts.map +1 -1
  29. package/dest/publisher/index.js +3 -0
  30. package/dest/publisher/l1_tx_failed_store/factory.d.ts +11 -0
  31. package/dest/publisher/l1_tx_failed_store/factory.d.ts.map +1 -0
  32. package/dest/publisher/l1_tx_failed_store/factory.js +22 -0
  33. package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts +58 -0
  34. package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts.map +1 -0
  35. package/dest/publisher/l1_tx_failed_store/failed_tx_store.js +1 -0
  36. package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts +15 -0
  37. package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts.map +1 -0
  38. package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.js +34 -0
  39. package/dest/publisher/l1_tx_failed_store/index.d.ts +4 -0
  40. package/dest/publisher/l1_tx_failed_store/index.d.ts.map +1 -0
  41. package/dest/publisher/l1_tx_failed_store/index.js +2 -0
  42. package/dest/publisher/sequencer-bundle-simulator.d.ts +96 -0
  43. package/dest/publisher/sequencer-bundle-simulator.d.ts.map +1 -0
  44. package/dest/publisher/sequencer-bundle-simulator.js +198 -0
  45. package/dest/publisher/sequencer-publisher-factory.d.ts +50 -0
  46. package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -0
  47. package/dest/publisher/sequencer-publisher-factory.js +75 -0
  48. package/dest/publisher/sequencer-publisher-metrics.d.ts +5 -4
  49. package/dest/publisher/sequencer-publisher-metrics.d.ts.map +1 -1
  50. package/dest/publisher/sequencer-publisher-metrics.js +34 -62
  51. package/dest/publisher/sequencer-publisher.d.ts +170 -97
  52. package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
  53. package/dest/publisher/sequencer-publisher.js +1255 -276
  54. package/dest/sequencer/automine/automine_factory.d.ts +54 -0
  55. package/dest/sequencer/automine/automine_factory.d.ts.map +1 -0
  56. package/dest/sequencer/automine/automine_factory.js +84 -0
  57. package/dest/sequencer/automine/automine_sequencer.d.ts +151 -0
  58. package/dest/sequencer/automine/automine_sequencer.d.ts.map +1 -0
  59. package/dest/sequencer/automine/automine_sequencer.js +509 -0
  60. package/dest/sequencer/chain_state_overrides.d.ts +61 -0
  61. package/dest/sequencer/chain_state_overrides.d.ts.map +1 -0
  62. package/dest/sequencer/chain_state_overrides.js +98 -0
  63. package/dest/sequencer/checkpoint_proposal_job.d.ts +150 -0
  64. package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -0
  65. package/dest/sequencer/checkpoint_proposal_job.js +1792 -0
  66. package/dest/sequencer/checkpoint_proposal_job_metrics.d.ts +34 -0
  67. package/dest/sequencer/checkpoint_proposal_job_metrics.d.ts.map +1 -0
  68. package/dest/sequencer/checkpoint_proposal_job_metrics.js +72 -0
  69. package/dest/sequencer/checkpoint_voter.d.ts +34 -0
  70. package/dest/sequencer/checkpoint_voter.d.ts.map +1 -0
  71. package/dest/sequencer/checkpoint_voter.js +106 -0
  72. package/dest/sequencer/config.d.ts +7 -1
  73. package/dest/sequencer/config.d.ts.map +1 -1
  74. package/dest/sequencer/errors.d.ts +11 -0
  75. package/dest/sequencer/errors.d.ts.map +1 -0
  76. package/dest/sequencer/errors.js +15 -0
  77. package/dest/sequencer/events.d.ts +92 -0
  78. package/dest/sequencer/events.d.ts.map +1 -0
  79. package/dest/sequencer/events.js +1 -0
  80. package/dest/sequencer/index.d.ts +6 -2
  81. package/dest/sequencer/index.d.ts.map +1 -1
  82. package/dest/sequencer/index.js +5 -1
  83. package/dest/sequencer/metrics.d.ts +64 -13
  84. package/dest/sequencer/metrics.d.ts.map +1 -1
  85. package/dest/sequencer/metrics.js +309 -68
  86. package/dest/sequencer/sequencer.d.ts +205 -135
  87. package/dest/sequencer/sequencer.d.ts.map +1 -1
  88. package/dest/sequencer/sequencer.js +1208 -523
  89. package/dest/sequencer/timetable.d.ts +85 -25
  90. package/dest/sequencer/timetable.d.ts.map +1 -1
  91. package/dest/sequencer/timetable.js +177 -60
  92. package/dest/sequencer/types.d.ts +3 -0
  93. package/dest/sequencer/types.d.ts.map +1 -0
  94. package/dest/sequencer/types.js +1 -0
  95. package/dest/sequencer/utils.d.ts +20 -38
  96. package/dest/sequencer/utils.d.ts.map +1 -1
  97. package/dest/sequencer/utils.js +12 -47
  98. package/dest/test/index.d.ts +9 -3
  99. package/dest/test/index.d.ts.map +1 -1
  100. package/dest/test/index.js +0 -4
  101. package/dest/test/mock_checkpoint_builder.d.ts +95 -0
  102. package/dest/test/mock_checkpoint_builder.d.ts.map +1 -0
  103. package/dest/test/mock_checkpoint_builder.js +231 -0
  104. package/dest/test/utils.d.ts +53 -0
  105. package/dest/test/utils.d.ts.map +1 -0
  106. package/dest/test/utils.js +105 -0
  107. package/package.json +46 -45
  108. package/src/client/sequencer-client.ts +158 -103
  109. package/src/config.ts +201 -99
  110. package/src/global_variable_builder/README.md +44 -0
  111. package/src/global_variable_builder/fee_predictor.ts +172 -0
  112. package/src/global_variable_builder/fee_provider.ts +75 -0
  113. package/src/global_variable_builder/global_builder.ts +68 -76
  114. package/src/global_variable_builder/index.ts +3 -1
  115. package/src/index.ts +10 -3
  116. package/src/publisher/config.ts +184 -59
  117. package/src/publisher/index.ts +7 -0
  118. package/src/publisher/l1_tx_failed_store/factory.ts +32 -0
  119. package/src/publisher/l1_tx_failed_store/failed_tx_store.ts +57 -0
  120. package/src/publisher/l1_tx_failed_store/file_store_failed_tx_store.ts +46 -0
  121. package/src/publisher/l1_tx_failed_store/index.ts +3 -0
  122. package/src/publisher/sequencer-bundle-simulator.ts +254 -0
  123. package/src/publisher/sequencer-publisher-factory.ts +121 -0
  124. package/src/publisher/sequencer-publisher-metrics.ts +33 -63
  125. package/src/publisher/sequencer-publisher.ts +1101 -350
  126. package/src/sequencer/README.md +243 -0
  127. package/src/sequencer/automine/README.md +46 -0
  128. package/src/sequencer/automine/automine_factory.ts +145 -0
  129. package/src/sequencer/automine/automine_sequencer.ts +595 -0
  130. package/src/sequencer/chain_state_overrides.ts +162 -0
  131. package/src/sequencer/checkpoint_proposal_job.ts +1632 -0
  132. package/src/sequencer/checkpoint_proposal_job_metrics.ts +128 -0
  133. package/src/sequencer/checkpoint_voter.ts +119 -0
  134. package/src/sequencer/config.ts +8 -0
  135. package/src/sequencer/errors.ts +21 -0
  136. package/src/sequencer/events.ts +76 -0
  137. package/src/sequencer/index.ts +5 -1
  138. package/src/sequencer/metrics.ts +397 -75
  139. package/src/sequencer/sequencer.ts +1013 -579
  140. package/src/sequencer/timetable.ts +225 -60
  141. package/src/sequencer/types.ts +6 -0
  142. package/src/sequencer/utils.ts +28 -60
  143. package/src/test/index.ts +11 -5
  144. package/src/test/mock_checkpoint_builder.ts +323 -0
  145. package/src/test/utils.ts +185 -0
  146. package/dest/sequencer/allowed.d.ts +0 -3
  147. package/dest/sequencer/allowed.d.ts.map +0 -1
  148. package/dest/sequencer/allowed.js +0 -27
  149. package/dest/slasher/factory.d.ts +0 -7
  150. package/dest/slasher/factory.d.ts.map +0 -1
  151. package/dest/slasher/factory.js +0 -8
  152. package/dest/slasher/index.d.ts +0 -3
  153. package/dest/slasher/index.d.ts.map +0 -1
  154. package/dest/slasher/index.js +0 -2
  155. package/dest/slasher/slasher_client.d.ts +0 -75
  156. package/dest/slasher/slasher_client.d.ts.map +0 -1
  157. package/dest/slasher/slasher_client.js +0 -132
  158. package/dest/tx_validator/archive_cache.d.ts +0 -14
  159. package/dest/tx_validator/archive_cache.d.ts.map +0 -1
  160. package/dest/tx_validator/archive_cache.js +0 -22
  161. package/dest/tx_validator/gas_validator.d.ts +0 -14
  162. package/dest/tx_validator/gas_validator.d.ts.map +0 -1
  163. package/dest/tx_validator/gas_validator.js +0 -78
  164. package/dest/tx_validator/nullifier_cache.d.ts +0 -16
  165. package/dest/tx_validator/nullifier_cache.d.ts.map +0 -1
  166. package/dest/tx_validator/nullifier_cache.js +0 -24
  167. package/dest/tx_validator/phases_validator.d.ts +0 -12
  168. package/dest/tx_validator/phases_validator.d.ts.map +0 -1
  169. package/dest/tx_validator/phases_validator.js +0 -80
  170. package/dest/tx_validator/test_utils.d.ts +0 -23
  171. package/dest/tx_validator/test_utils.d.ts.map +0 -1
  172. package/dest/tx_validator/test_utils.js +0 -26
  173. package/dest/tx_validator/tx_validator_factory.d.ts +0 -18
  174. package/dest/tx_validator/tx_validator_factory.d.ts.map +0 -1
  175. package/dest/tx_validator/tx_validator_factory.js +0 -50
  176. package/src/sequencer/allowed.ts +0 -36
  177. package/src/slasher/factory.ts +0 -15
  178. package/src/slasher/index.ts +0 -2
  179. package/src/slasher/slasher_client.ts +0 -193
  180. package/src/tx_validator/archive_cache.ts +0 -28
  181. package/src/tx_validator/gas_validator.ts +0 -101
  182. package/src/tx_validator/nullifier_cache.ts +0 -30
  183. package/src/tx_validator/phases_validator.ts +0 -98
  184. package/src/tx_validator/test_utils.ts +0 -48
  185. package/src/tx_validator/tx_validator_factory.ts +0 -120
@@ -1,43 +1,43 @@
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
- ForwarderContract,
5
- GovernanceProposerContract,
6
- RollupContract,
7
- SlashingProposerContract,
8
- createEthereumChain,
9
- createL1Clients,
10
- isAnvilTestChain,
11
- } from '@aztec/ethereum';
12
- 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';
13
9
  import { EthAddress } from '@aztec/foundation/eth-address';
14
10
  import { createLogger } from '@aztec/foundation/log';
15
11
  import type { DateProvider } from '@aztec/foundation/timer';
12
+ import type { KeystoreManager } from '@aztec/node-keystore';
16
13
  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';
14
+ import type { SlasherClientInterface } from '@aztec/slasher';
15
+ import type { L2BlockSink, L2BlockSource, ProposedCheckpointSink } from '@aztec/stdlib/block';
16
+ import type { ValidatorClientFullConfig, WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
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
- import type { SequencerClientConfig } from '../config.js';
28
- import { GlobalVariableBuilder } from '../global_variable_builder/index.js';
29
- import { SequencerPublisher } from '../publisher/index.js';
21
+ import { type SequencerClientConfig, getPublisherConfigFromSequencerConfig } from '../config.js';
22
+ import type { GlobalVariableBuilder } from '../global_variable_builder/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<L1TxUtils>,
32
+ protected sequencer: Sequencer,
33
+ protected checkpointsBuilder: FullNodeCheckpointsBuilder,
34
+ protected validatorClient?: ValidatorClient,
35
+ private l1Metrics?: L1Metrics,
36
+ private delayer_?: Delayer,
37
+ ) {}
38
38
 
39
39
  /**
40
- * Initializes and starts a new instance.
40
+ * Initializes a new instance.
41
41
  * @param config - Configuration for the sequencer, publisher, and L1 tx sender.
42
42
  * @param p2pClient - P2P client that provides the txs to be sequenced.
43
43
  * @param validatorClient - Validator client performs attestation duties when rotating proposers.
@@ -46,25 +46,27 @@ export class SequencerClient {
46
46
  * @param l2BlockSource - Provides information about the previously published blocks.
47
47
  * @param l1ToL2MessageSource - Provides access to L1 to L2 messages.
48
48
  * @param prover - An instance of a block prover
49
- * @param simulationProvider - An instance of a simulation provider
50
49
  * @returns A new running instance.
51
50
  */
52
51
  public static async new(
53
52
  config: SequencerClientConfig,
54
53
  deps: {
55
- validatorClient: ValidatorClient | undefined; // allowed to be undefined while we migrate
54
+ validatorClient: ValidatorClient;
56
55
  p2pClient: P2P;
57
56
  worldStateSynchronizer: WorldStateSynchronizer;
58
- slasherClient: SlasherClient;
59
- contractDataSource: ContractDataSource;
60
- l2BlockSource: L2BlockSource;
57
+ slasherClient: SlasherClientInterface | undefined;
58
+ checkpointsBuilder: FullNodeCheckpointsBuilder;
59
+ l2BlockSource: L2BlockSource & L2BlockSink & ProposedCheckpointSink;
61
60
  l1ToL2MessageSource: L1ToL2MessageSource;
62
61
  telemetry: TelemetryClient;
63
- publisher?: SequencerPublisher;
64
- blobSinkClient?: BlobSinkClientInterface;
62
+ publisherFactory?: SequencerPublisherFactory;
63
+ blobClient: BlobClientInterface;
65
64
  dateProvider: DateProvider;
66
65
  epochCache?: EpochCache;
67
- l1TxUtils?: L1TxUtilsWithBlobs;
66
+ l1TxUtils: L1TxUtils[];
67
+ funderL1TxUtils?: L1TxUtils;
68
+ nodeKeyStore: KeystoreManager;
69
+ globalVariableBuilder: GlobalVariableBuilder;
68
70
  },
69
71
  ) {
70
72
  const {
@@ -72,118 +74,127 @@ export class SequencerClient {
72
74
  p2pClient,
73
75
  worldStateSynchronizer,
74
76
  slasherClient,
75
- contractDataSource,
77
+ checkpointsBuilder,
76
78
  l2BlockSource,
77
79
  l1ToL2MessageSource,
78
80
  telemetry: telemetryClient,
79
81
  } = 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);
85
- const rollupContract = new RollupContract(publicClient, config.l1Contracts.rollupAddress.toString());
86
- const [l1GenesisTime, slotDuration] = await Promise.all([
82
+ const { l1RpcUrls: rpcUrls, l1ChainId: chainId } = config;
83
+ const log = createLogger('sequencer');
84
+ const publicClient = getPublicClient(config);
85
+ const l1TxUtils = deps.l1TxUtils;
86
+ const l1Metrics = new L1Metrics(
87
+ telemetryClient.getMeter('L1PublisherMetrics'),
88
+ publicClient,
89
+ l1TxUtils.map(x => x.getSenderAddress()),
90
+ );
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([
87
97
  rollupContract.getL1GenesisTime(),
88
98
  rollupContract.getSlotDuration(),
99
+ rollupContract.getManaLimit().then(Number),
89
100
  ] 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
101
 
105
102
  const governanceProposerContract = new GovernanceProposerContract(
106
103
  publicClient,
107
- config.l1Contracts.governanceProposerAddress.toString(),
104
+ config.governanceProposerAddress.toString(),
108
105
  );
109
- const slashingProposerAddress = await rollupContract.getSlashingProposerAddress();
110
- const slashingProposerContract = new SlashingProposerContract(publicClient, slashingProposerAddress.toString());
111
106
  const epochCache =
112
107
  deps.epochCache ??
113
108
  (await EpochCache.create(
114
- config.l1Contracts.rollupAddress,
109
+ config.rollupAddress,
115
110
  {
116
111
  l1RpcUrls: rpcUrls,
117
112
  l1ChainId: chainId,
118
113
  viemPollingIntervalMS: config.viemPollingIntervalMS,
119
- aztecSlotDuration: config.aztecSlotDuration,
120
114
  ethereumSlotDuration: config.ethereumSlotDuration,
121
- aztecEpochDuration: config.aztecEpochDuration,
122
115
  },
123
116
  { dateProvider: deps.dateProvider },
124
117
  ));
125
118
 
126
- const publisher =
127
- deps.publisher ??
128
- new SequencerPublisher(config, {
129
- l1TxUtils,
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
+ rollupContract,
127
+ dateProvider: deps.dateProvider,
128
+ publisherManager,
129
+ nodeKeyStore: NodeKeystoreAdapter.fromKeyStoreManager(deps.nodeKeyStore),
130
+ logger: log,
137
131
  });
138
- const globalsBuilder = new GlobalVariableBuilder(config);
139
-
140
- const publicProcessorFactory = new PublicProcessorFactory(contractDataSource, deps.dateProvider, telemetryClient);
141
132
 
142
133
  const ethereumSlotDuration = config.ethereumSlotDuration;
143
134
 
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.
135
+ const globalsBuilder = deps.globalVariableBuilder;
136
+
137
+ // When running in anvil, assume we can post a tx up until one second before the end of an L1 slot.
138
+ // Otherwise, we need the full L1 slot duration for publishing to ensure inclusion.
147
139
  // 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.
140
+ // reduce the publishing time allowance. However, we prefer being conservative.
149
141
  // 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;
142
+ const l1PublishingTimeBasedOnChain = isAnvilTestChain(config.l1ChainId) ? 1 : ethereumSlotDuration;
143
+ const l1PublishingTime = config.l1PublishingTime ?? l1PublishingTimeBasedOnChain;
144
+
145
+ const { maxL2BlockGas, maxDABlockGas, maxTxsPerBlock } = capPerBlockLimits(config, rollupManaLimit, log);
152
146
 
153
147
  const l1Constants = {
154
148
  l1GenesisTime,
155
149
  slotDuration: Number(slotDuration),
156
150
  ethereumSlotDuration,
151
+ rollupManaLimit,
152
+ epochDuration: config.aztecEpochDuration,
157
153
  };
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, maxDABlockGas, maxTxsPerBlock },
174
170
  telemetryClient,
171
+ log,
175
172
  );
176
- await validatorClient?.start();
177
- await sequencer.start();
178
- return new SequencerClient(sequencer);
173
+
174
+ sequencer.init();
175
+
176
+ // Extract the shared delayer from the first L1TxUtils instance (all instances share the same delayer)
177
+ const delayer = l1TxUtils[0]?.delayer;
178
+
179
+ return new SequencerClient(publisherManager, sequencer, checkpointsBuilder, validatorClient, l1Metrics, delayer);
179
180
  }
180
181
 
181
182
  /**
182
- * Updates sequencer config.
183
+ * Updates sequencer and validator client config.
183
184
  * @param config - New parameters.
184
185
  */
185
- public updateSequencerConfig(config: SequencerConfig) {
186
- return this.sequencer.updateConfig(config);
186
+ public updateConfig(config: SequencerConfig & Partial<ValidatorClientFullConfig>) {
187
+ this.sequencer.updateConfig(config);
188
+ this.checkpointsBuilder.updateConfig(config);
189
+ this.validatorClient?.updateConfig(config);
190
+ }
191
+
192
+ /** Starts the sequencer. */
193
+ public async start() {
194
+ await this.validatorClient?.start();
195
+ this.sequencer.start();
196
+ this.l1Metrics?.start();
197
+ await this.publisherManager.start();
187
198
  }
188
199
 
189
200
  /**
@@ -191,29 +202,73 @@ export class SequencerClient {
191
202
  */
192
203
  public async stop() {
193
204
  await this.sequencer.stop();
205
+ await this.validatorClient?.stop();
206
+ await this.publisherManager.stop();
207
+ this.l1Metrics?.stop();
194
208
  }
195
209
 
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();
210
+ /** Triggers an immediate run of the sequencer, bypassing the polling interval. */
211
+ public trigger() {
212
+ return this.sequencer.trigger();
199
213
  }
200
214
 
201
- /**
202
- * Restarts the sequencer after being stopped.
203
- */
204
- public restart() {
205
- this.sequencer.restart();
215
+ public getSequencer(): Sequencer {
216
+ return this.sequencer;
206
217
  }
207
218
 
208
- get coinbase(): EthAddress {
209
- return this.sequencer.coinbase;
219
+ /** Updates the publisher factory's node keystore adapter after a keystore reload. */
220
+ public updatePublisherNodeKeyStore(adapter: NodeKeystoreAdapter): void {
221
+ this.sequencer.updatePublisherNodeKeyStore(adapter);
210
222
  }
211
223
 
212
- get feeRecipient(): AztecAddress {
213
- return this.sequencer.feeRecipient;
224
+ /** Returns the shared tx delayer for sequencer L1 txs, if enabled. Test-only. */
225
+ getDelayer(): Delayer | undefined {
226
+ return this.delayer_;
214
227
  }
215
228
 
216
- get forwarderAddress(): EthAddress {
217
- return this.sequencer.getForwarderAddress();
229
+ get validatorAddresses(): EthAddress[] | undefined {
230
+ return this.sequencer.getValidatorAddresses();
218
231
  }
232
+
233
+ get maxL2BlockGas(): number | undefined {
234
+ return this.sequencer.maxL2BlockGas;
235
+ }
236
+ }
237
+
238
+ /**
239
+ * Caps operator-provided per-block limits at checkpoint-level limits.
240
+ * Returns undefined for any limit the operator didn't set — the checkpoint builder handles redistribution.
241
+ */
242
+ function capPerBlockLimits(
243
+ config: SequencerClientConfig,
244
+ rollupManaLimit: number,
245
+ log: ReturnType<typeof createLogger>,
246
+ ): { maxL2BlockGas: number | undefined; maxDABlockGas: number | undefined; maxTxsPerBlock: number | undefined } {
247
+ let maxL2BlockGas = config.maxL2BlockGas;
248
+ if (maxL2BlockGas !== undefined && maxL2BlockGas > rollupManaLimit) {
249
+ log.warn(`Provided MAX_L2_BLOCK_GAS ${maxL2BlockGas} exceeds rollup mana limit ${rollupManaLimit} (capping)`);
250
+ maxL2BlockGas = rollupManaLimit;
251
+ }
252
+
253
+ let maxDABlockGas = config.maxDABlockGas;
254
+ if (maxDABlockGas !== undefined && maxDABlockGas > MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT) {
255
+ log.warn(
256
+ `Provided MAX_DA_BLOCK_GAS ${maxDABlockGas} exceeds DA checkpoint limit ${MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT} (capping)`,
257
+ );
258
+ maxDABlockGas = MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT;
259
+ }
260
+
261
+ let maxTxsPerBlock = config.maxTxsPerBlock;
262
+ if (
263
+ maxTxsPerBlock !== undefined &&
264
+ config.maxTxsPerCheckpoint !== undefined &&
265
+ maxTxsPerBlock > config.maxTxsPerCheckpoint
266
+ ) {
267
+ log.warn(
268
+ `Provided MAX_TX_PER_BLOCK ${maxTxsPerBlock} exceeds MAX_TX_PER_CHECKPOINT ${config.maxTxsPerCheckpoint} (capping)`,
269
+ );
270
+ maxTxsPerBlock = config.maxTxsPerCheckpoint;
271
+ }
272
+
273
+ return { maxL2BlockGas, maxDABlockGas, maxTxsPerBlock };
219
274
  }