@aztec/sequencer-client 0.0.0-test.0 → 0.0.1-commit.001888fc

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 (151) hide show
  1. package/dest/client/index.d.ts +1 -1
  2. package/dest/client/sequencer-client.d.ts +50 -33
  3. package/dest/client/sequencer-client.d.ts.map +1 -1
  4. package/dest/client/sequencer-client.js +164 -57
  5. package/dest/config.d.ts +35 -17
  6. package/dest/config.d.ts.map +1 -1
  7. package/dest/config.js +150 -81
  8. package/dest/global_variable_builder/global_builder.d.ts +24 -15
  9. package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
  10. package/dest/global_variable_builder/global_builder.js +63 -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 +48 -27
  16. package/dest/publisher/config.d.ts.map +1 -1
  17. package/dest/publisher/config.js +109 -32
  18. package/dest/publisher/index.d.ts +4 -1
  19. package/dest/publisher/index.d.ts.map +1 -1
  20. package/dest/publisher/index.js +3 -0
  21. package/dest/publisher/l1_tx_failed_store/factory.d.ts +11 -0
  22. package/dest/publisher/l1_tx_failed_store/factory.d.ts.map +1 -0
  23. package/dest/publisher/l1_tx_failed_store/factory.js +22 -0
  24. package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts +59 -0
  25. package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts.map +1 -0
  26. package/dest/publisher/l1_tx_failed_store/failed_tx_store.js +1 -0
  27. package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts +15 -0
  28. package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts.map +1 -0
  29. package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.js +34 -0
  30. package/dest/publisher/l1_tx_failed_store/index.d.ts +4 -0
  31. package/dest/publisher/l1_tx_failed_store/index.d.ts.map +1 -0
  32. package/dest/publisher/l1_tx_failed_store/index.js +2 -0
  33. package/dest/publisher/sequencer-publisher-factory.d.ts +52 -0
  34. package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -0
  35. package/dest/publisher/sequencer-publisher-factory.js +76 -0
  36. package/dest/publisher/sequencer-publisher-metrics.d.ts +5 -4
  37. package/dest/publisher/sequencer-publisher-metrics.d.ts.map +1 -1
  38. package/dest/publisher/sequencer-publisher-metrics.js +34 -62
  39. package/dest/publisher/sequencer-publisher.d.ts +158 -93
  40. package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
  41. package/dest/publisher/sequencer-publisher.js +1452 -255
  42. package/dest/sequencer/checkpoint_proposal_job.d.ts +100 -0
  43. package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -0
  44. package/dest/sequencer/checkpoint_proposal_job.js +1240 -0
  45. package/dest/sequencer/checkpoint_voter.d.ts +35 -0
  46. package/dest/sequencer/checkpoint_voter.d.ts.map +1 -0
  47. package/dest/sequencer/checkpoint_voter.js +109 -0
  48. package/dest/sequencer/config.d.ts +7 -1
  49. package/dest/sequencer/config.d.ts.map +1 -1
  50. package/dest/sequencer/errors.d.ts +11 -0
  51. package/dest/sequencer/errors.d.ts.map +1 -0
  52. package/dest/sequencer/errors.js +15 -0
  53. package/dest/sequencer/events.d.ts +46 -0
  54. package/dest/sequencer/events.d.ts.map +1 -0
  55. package/dest/sequencer/events.js +1 -0
  56. package/dest/sequencer/index.d.ts +4 -2
  57. package/dest/sequencer/index.d.ts.map +1 -1
  58. package/dest/sequencer/index.js +3 -1
  59. package/dest/sequencer/metrics.d.ts +60 -12
  60. package/dest/sequencer/metrics.d.ts.map +1 -1
  61. package/dest/sequencer/metrics.js +283 -67
  62. package/dest/sequencer/sequencer.d.ts +157 -135
  63. package/dest/sequencer/sequencer.d.ts.map +1 -1
  64. package/dest/sequencer/sequencer.js +966 -523
  65. package/dest/sequencer/timetable.d.ts +75 -25
  66. package/dest/sequencer/timetable.d.ts.map +1 -1
  67. package/dest/sequencer/timetable.js +174 -62
  68. package/dest/sequencer/types.d.ts +3 -0
  69. package/dest/sequencer/types.d.ts.map +1 -0
  70. package/dest/sequencer/types.js +1 -0
  71. package/dest/sequencer/utils.d.ts +20 -38
  72. package/dest/sequencer/utils.d.ts.map +1 -1
  73. package/dest/sequencer/utils.js +12 -47
  74. package/dest/test/index.d.ts +9 -3
  75. package/dest/test/index.d.ts.map +1 -1
  76. package/dest/test/index.js +0 -4
  77. package/dest/test/mock_checkpoint_builder.d.ts +99 -0
  78. package/dest/test/mock_checkpoint_builder.d.ts.map +1 -0
  79. package/dest/test/mock_checkpoint_builder.js +231 -0
  80. package/dest/test/utils.d.ts +53 -0
  81. package/dest/test/utils.d.ts.map +1 -0
  82. package/dest/test/utils.js +104 -0
  83. package/package.json +46 -45
  84. package/src/client/sequencer-client.ts +220 -104
  85. package/src/config.ts +172 -96
  86. package/src/global_variable_builder/global_builder.ts +85 -55
  87. package/src/index.ts +1 -3
  88. package/src/publisher/config.ts +150 -59
  89. package/src/publisher/index.ts +7 -0
  90. package/src/publisher/l1_tx_failed_store/factory.ts +32 -0
  91. package/src/publisher/l1_tx_failed_store/failed_tx_store.ts +55 -0
  92. package/src/publisher/l1_tx_failed_store/file_store_failed_tx_store.ts +46 -0
  93. package/src/publisher/l1_tx_failed_store/index.ts +3 -0
  94. package/src/publisher/sequencer-publisher-factory.ts +124 -0
  95. package/src/publisher/sequencer-publisher-metrics.ts +33 -63
  96. package/src/publisher/sequencer-publisher.ts +1266 -311
  97. package/src/sequencer/README.md +531 -0
  98. package/src/sequencer/checkpoint_proposal_job.ts +967 -0
  99. package/src/sequencer/checkpoint_voter.ts +130 -0
  100. package/src/sequencer/config.ts +8 -0
  101. package/src/sequencer/errors.ts +21 -0
  102. package/src/sequencer/events.ts +27 -0
  103. package/src/sequencer/index.ts +3 -1
  104. package/src/sequencer/metrics.ts +362 -73
  105. package/src/sequencer/sequencer.ts +712 -586
  106. package/src/sequencer/timetable.ts +224 -64
  107. package/src/sequencer/types.ts +6 -0
  108. package/src/sequencer/utils.ts +28 -60
  109. package/src/test/index.ts +11 -5
  110. package/src/test/mock_checkpoint_builder.ts +323 -0
  111. package/src/test/utils.ts +167 -0
  112. package/dest/sequencer/allowed.d.ts +0 -3
  113. package/dest/sequencer/allowed.d.ts.map +0 -1
  114. package/dest/sequencer/allowed.js +0 -27
  115. package/dest/slasher/factory.d.ts +0 -7
  116. package/dest/slasher/factory.d.ts.map +0 -1
  117. package/dest/slasher/factory.js +0 -8
  118. package/dest/slasher/index.d.ts +0 -3
  119. package/dest/slasher/index.d.ts.map +0 -1
  120. package/dest/slasher/index.js +0 -2
  121. package/dest/slasher/slasher_client.d.ts +0 -75
  122. package/dest/slasher/slasher_client.d.ts.map +0 -1
  123. package/dest/slasher/slasher_client.js +0 -132
  124. package/dest/tx_validator/archive_cache.d.ts +0 -14
  125. package/dest/tx_validator/archive_cache.d.ts.map +0 -1
  126. package/dest/tx_validator/archive_cache.js +0 -22
  127. package/dest/tx_validator/gas_validator.d.ts +0 -14
  128. package/dest/tx_validator/gas_validator.d.ts.map +0 -1
  129. package/dest/tx_validator/gas_validator.js +0 -78
  130. package/dest/tx_validator/nullifier_cache.d.ts +0 -16
  131. package/dest/tx_validator/nullifier_cache.d.ts.map +0 -1
  132. package/dest/tx_validator/nullifier_cache.js +0 -24
  133. package/dest/tx_validator/phases_validator.d.ts +0 -12
  134. package/dest/tx_validator/phases_validator.d.ts.map +0 -1
  135. package/dest/tx_validator/phases_validator.js +0 -80
  136. package/dest/tx_validator/test_utils.d.ts +0 -23
  137. package/dest/tx_validator/test_utils.d.ts.map +0 -1
  138. package/dest/tx_validator/test_utils.js +0 -26
  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 -50
  142. package/src/sequencer/allowed.ts +0 -36
  143. package/src/slasher/factory.ts +0 -15
  144. package/src/slasher/index.ts +0 -2
  145. package/src/slasher/slasher_client.ts +0 -193
  146. package/src/tx_validator/archive_cache.ts +0 -28
  147. package/src/tx_validator/gas_validator.ts +0 -101
  148. package/src/tx_validator/nullifier_cache.ts +0 -30
  149. package/src/tx_validator/phases_validator.ts +0 -98
  150. package/src/tx_validator/test_utils.ts +0 -48
  151. package/src/tx_validator/tx_validator_factory.ts +0 -120
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,56 +8,119 @@ 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 {
15
+ type ChainConfig,
16
+ type SequencerConfig,
17
+ chainConfigMappings,
18
+ sharedSequencerConfigMappings,
19
+ } from '@aztec/stdlib/config';
20
+ import type { ResolvedSequencerConfig } from '@aztec/stdlib/interfaces/server';
21
+ import { DEFAULT_P2P_PROPAGATION_TIME } from '@aztec/stdlib/timetable';
22
+ import { type ValidatorClientConfig, validatorClientConfigMappings } from '@aztec/validator-client/config';
19
23
 
20
24
  import {
21
- type PublisherConfig,
22
- type TxSenderConfig,
23
- getPublisherConfigMappings,
24
- getTxSenderConfigMappings,
25
+ type SequencerPublisherConfig,
26
+ type SequencerTxSenderConfig,
27
+ sequencerPublisherConfigMappings,
28
+ sequencerTxSenderConfigMappings,
25
29
  } from './publisher/config.js';
26
30
 
27
31
  export * from './publisher/config.js';
28
32
  export type { SequencerConfig };
29
33
 
34
+ /**
35
+ * Default values for SequencerConfig.
36
+ * Centralized location for all sequencer configuration defaults.
37
+ */
38
+ export const DefaultSequencerConfig = {
39
+ sequencerPollingIntervalMS: 500,
40
+ minTxsPerBlock: 1,
41
+ buildCheckpointIfEmpty: false,
42
+ publishTxsWithProposals: false,
43
+ perBlockAllocationMultiplier: 1.2,
44
+ redistributeCheckpointBudget: true,
45
+ enforceTimeTable: true,
46
+ attestationPropagationTime: DEFAULT_P2P_PROPAGATION_TIME,
47
+ secondsBeforeInvalidatingBlockAsCommitteeMember: 144, // 12 L1 blocks
48
+ secondsBeforeInvalidatingBlockAsNonCommitteeMember: 432, // 36 L1 blocks
49
+ skipCollectingAttestations: false,
50
+ skipInvalidateBlockAsProposer: false,
51
+ broadcastInvalidBlockProposal: false,
52
+ injectFakeAttestation: false,
53
+ injectHighSValueAttestation: false,
54
+ injectUnrecoverableSignatureAttestation: false,
55
+ fishermanMode: false,
56
+ shuffleAttestationOrdering: false,
57
+ skipPushProposedBlocksToArchiver: false,
58
+ skipPublishingCheckpointsPercent: 0,
59
+ } satisfies ResolvedSequencerConfig;
60
+
30
61
  /**
31
62
  * Configuration settings for the SequencerClient.
32
63
  */
33
- export type SequencerClientConfig = PublisherConfig &
34
- TxSenderConfig &
64
+ export type SequencerClientConfig = SequencerPublisherConfig &
65
+ KeyStoreConfig &
66
+ ValidatorClientConfig &
67
+ SequencerTxSenderConfig &
35
68
  SequencerConfig &
36
69
  L1ReaderConfig &
37
70
  ChainConfig &
71
+ Pick<P2PConfig, 'txPublicSetupAllowListExtend'> &
38
72
  Pick<L1ContractsConfig, 'ethereumSlotDuration' | 'aztecSlotDuration' | 'aztecEpochDuration'>;
39
73
 
40
74
  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),
75
+ sequencerPollingIntervalMS: {
76
+ env: 'SEQ_POLLING_INTERVAL_MS',
77
+ description: 'The number of ms to wait between polling for checking to build on the next slot.',
78
+ ...numberConfigHelper(DefaultSequencerConfig.sequencerPollingIntervalMS),
45
79
  },
46
- maxTxsPerBlock: {
47
- env: 'SEQ_MAX_TX_PER_BLOCK',
48
- description: 'The maximum number of txs to include in a block.',
49
- ...numberConfigHelper(32),
80
+ maxTxsPerCheckpoint: {
81
+ env: 'SEQ_MAX_TX_PER_CHECKPOINT',
82
+ description: 'The maximum number of txs across all blocks in a checkpoint.',
83
+ parseEnv: (val: string) => (val ? parseInt(val, 10) : undefined),
50
84
  },
51
85
  minTxsPerBlock: {
52
86
  env: 'SEQ_MIN_TX_PER_BLOCK',
53
87
  description: 'The minimum number of txs to include in a block.',
54
- ...numberConfigHelper(1),
88
+ ...numberConfigHelper(DefaultSequencerConfig.minTxsPerBlock),
89
+ },
90
+ minValidTxsPerBlock: {
91
+ description:
92
+ 'The minimum number of valid txs (after execution) to include in a block. If not set, falls back to minTxsPerBlock.',
93
+ },
94
+ publishTxsWithProposals: {
95
+ env: 'SEQ_PUBLISH_TXS_WITH_PROPOSALS',
96
+ description: 'Whether to publish txs with proposals.',
97
+ ...booleanConfigHelper(DefaultSequencerConfig.publishTxsWithProposals),
55
98
  },
56
99
  maxL2BlockGas: {
57
100
  env: 'SEQ_MAX_L2_BLOCK_GAS',
58
101
  description: 'The maximum L2 block gas.',
59
- ...numberConfigHelper(10e9),
102
+ parseEnv: (val: string) => (val ? parseInt(val, 10) : undefined),
60
103
  },
61
104
  maxDABlockGas: {
62
105
  env: 'SEQ_MAX_DA_BLOCK_GAS',
63
106
  description: 'The maximum DA block gas.',
64
- ...numberConfigHelper(10e9),
107
+ parseEnv: (val: string) => (val ? parseInt(val, 10) : undefined),
108
+ },
109
+ perBlockAllocationMultiplier: {
110
+ env: 'SEQ_PER_BLOCK_ALLOCATION_MULTIPLIER',
111
+ description:
112
+ 'Per-block gas budget multiplier for both L2 and DA gas. Budget per block is (checkpointLimit / maxBlocks) * multiplier.' +
113
+ ' Values greater than one allow early blocks to use more than their even share, relying on checkpoint-level capping for later blocks.',
114
+ ...numberConfigHelper(DefaultSequencerConfig.perBlockAllocationMultiplier),
115
+ },
116
+ redistributeCheckpointBudget: {
117
+ env: 'SEQ_REDISTRIBUTE_CHECKPOINT_BUDGET',
118
+ description:
119
+ 'Redistribute remaining checkpoint budget evenly across remaining blocks instead of allowing a single block to consume the entire remaining budget.',
120
+ ...booleanConfigHelper(DefaultSequencerConfig.redistributeCheckpointBudget),
121
+ },
122
+ maxBlocksPerCheckpoint: {
123
+ description: 'Computed max number of blocks per checkpoint from timetable.',
65
124
  },
66
125
  coinbase: {
67
126
  env: 'COINBASE',
@@ -81,42 +140,109 @@ export const sequencerConfigMappings: ConfigMappingsType<SequencerConfig> = {
81
140
  env: 'ACVM_BINARY_PATH',
82
141
  description: 'The path to the ACVM binary',
83
142
  },
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
- maxBlockSizeInBytes: {
92
- env: 'SEQ_MAX_BLOCK_SIZE_IN_BYTES',
93
- description: 'Max block size',
94
- ...numberConfigHelper(1024 * 1024),
95
- },
96
143
  enforceTimeTable: {
97
144
  env: 'SEQ_ENFORCE_TIME_TABLE',
98
145
  description: 'Whether to enforce the time table when building blocks',
99
- ...booleanConfigHelper(),
100
- defaultValue: false,
146
+ ...booleanConfigHelper(DefaultSequencerConfig.enforceTimeTable),
101
147
  },
102
148
  governanceProposerPayload: {
103
149
  env: 'GOVERNANCE_PROPOSER_PAYLOAD_ADDRESS',
104
150
  description: 'The address of the payload for the governanceProposer',
105
151
  parseEnv: (val: string) => EthAddress.fromString(val),
106
- defaultValue: EthAddress.ZERO,
107
152
  },
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.',
153
+ l1PublishingTime: {
154
+ env: 'SEQ_L1_PUBLISHING_TIME_ALLOWANCE_IN_SLOT',
155
+ description: 'How much time (in seconds) we allow in the slot for publishing the L1 tx (defaults to 1 L1 slot).',
111
156
  parseEnv: (val: string) => (val ? parseInt(val, 10) : undefined),
112
157
  },
158
+ attestationPropagationTime: {
159
+ env: 'SEQ_ATTESTATION_PROPAGATION_TIME',
160
+ description: 'How many seconds it takes for proposals and attestations to travel across the p2p layer (one-way)',
161
+ ...numberConfigHelper(DefaultSequencerConfig.attestationPropagationTime),
162
+ },
163
+ fakeProcessingDelayPerTxMs: {
164
+ description: 'Used for testing to introduce a fake delay after processing each tx',
165
+ },
166
+ fakeThrowAfterProcessingTxCount: {
167
+ description: 'Used for testing to throw an error after processing N txs',
168
+ },
169
+ secondsBeforeInvalidatingBlockAsCommitteeMember: {
170
+ env: 'SEQ_SECONDS_BEFORE_INVALIDATING_BLOCK_AS_COMMITTEE_MEMBER',
171
+ description:
172
+ 'How many seconds to wait before trying to invalidate a block from the pending chain as a committee member (zero to never invalidate).' +
173
+ ' The next proposer is expected to invalidate, so the committee acts as a fallback.',
174
+ ...numberConfigHelper(DefaultSequencerConfig.secondsBeforeInvalidatingBlockAsCommitteeMember),
175
+ },
176
+ secondsBeforeInvalidatingBlockAsNonCommitteeMember: {
177
+ env: 'SEQ_SECONDS_BEFORE_INVALIDATING_BLOCK_AS_NON_COMMITTEE_MEMBER',
178
+ description:
179
+ 'How many seconds to wait before trying to invalidate a block from the pending chain as a non-committee member (zero to never invalidate).' +
180
+ ' The next proposer is expected to invalidate, then the committee, so other sequencers act as a fallback.',
181
+ ...numberConfigHelper(DefaultSequencerConfig.secondsBeforeInvalidatingBlockAsNonCommitteeMember),
182
+ },
183
+ skipCollectingAttestations: {
184
+ description:
185
+ 'Whether to skip collecting attestations from validators and only use self-attestations (for testing only)',
186
+ ...booleanConfigHelper(DefaultSequencerConfig.skipCollectingAttestations),
187
+ },
188
+ skipInvalidateBlockAsProposer: {
189
+ description: 'Do not invalidate the previous block if invalid when we are the proposer (for testing only)',
190
+ ...booleanConfigHelper(DefaultSequencerConfig.skipInvalidateBlockAsProposer),
191
+ },
192
+ broadcastInvalidBlockProposal: {
193
+ description: 'Broadcast invalid block proposals with corrupted state (for testing only)',
194
+ ...booleanConfigHelper(DefaultSequencerConfig.broadcastInvalidBlockProposal),
195
+ },
196
+ injectFakeAttestation: {
197
+ description: 'Inject a fake attestation (for testing only)',
198
+ ...booleanConfigHelper(DefaultSequencerConfig.injectFakeAttestation),
199
+ },
200
+ injectHighSValueAttestation: {
201
+ description: 'Inject a malleable attestation with a high-s value (for testing only)',
202
+ ...booleanConfigHelper(DefaultSequencerConfig.injectHighSValueAttestation),
203
+ },
204
+ injectUnrecoverableSignatureAttestation: {
205
+ description: 'Inject an attestation with an unrecoverable signature (for testing only)',
206
+ ...booleanConfigHelper(DefaultSequencerConfig.injectUnrecoverableSignatureAttestation),
207
+ },
208
+ fishermanMode: {
209
+ env: 'FISHERMAN_MODE',
210
+ description:
211
+ 'Whether to run in fisherman mode: builds blocks on every slot for validation without publishing to L1',
212
+ ...booleanConfigHelper(DefaultSequencerConfig.fishermanMode),
213
+ },
214
+ shuffleAttestationOrdering: {
215
+ description: 'Shuffle attestation ordering to create invalid ordering (for testing only)',
216
+ ...booleanConfigHelper(DefaultSequencerConfig.shuffleAttestationOrdering),
217
+ },
218
+ ...sharedSequencerConfigMappings,
219
+ buildCheckpointIfEmpty: {
220
+ env: 'SEQ_BUILD_CHECKPOINT_IF_EMPTY',
221
+ description: 'Have sequencer build and publish an empty checkpoint if there are no txs',
222
+ ...booleanConfigHelper(DefaultSequencerConfig.buildCheckpointIfEmpty),
223
+ },
224
+ skipPushProposedBlocksToArchiver: {
225
+ description: 'Skip pushing proposed blocks to archiver (default: true)',
226
+ ...booleanConfigHelper(DefaultSequencerConfig.skipPushProposedBlocksToArchiver),
227
+ },
228
+ minBlocksForCheckpoint: {
229
+ description: 'Minimum number of blocks required for a checkpoint proposal (test only)',
230
+ },
231
+ skipPublishingCheckpointsPercent: {
232
+ env: 'SEQ_SKIP_CHECKPOINT_PUBLISH_PERCENT',
233
+ description: 'Percent probability (0 - 100) of sequencer skipping checkpoint publishing (testing only)',
234
+ ...numberConfigHelper(DefaultSequencerConfig.skipPublishingCheckpointsPercent),
235
+ },
236
+ ...pickConfigMappings(p2pConfigMappings, ['txPublicSetupAllowListExtend']),
113
237
  };
114
238
 
115
239
  export const sequencerClientConfigMappings: ConfigMappingsType<SequencerClientConfig> = {
240
+ ...validatorClientConfigMappings,
116
241
  ...sequencerConfigMappings,
242
+ ...keyStoreConfigMappings,
117
243
  ...l1ReaderConfigMappings,
118
- ...getTxSenderConfigMappings('SEQ'),
119
- ...getPublisherConfigMappings('SEQ'),
244
+ ...sequencerTxSenderConfigMappings,
245
+ ...sequencerPublisherConfigMappings,
120
246
  ...chainConfigMappings,
121
247
  ...pickConfigMappings(l1ContractsConfigMappings, ['ethereumSlotDuration', 'aztecSlotDuration', 'aztecEpochDuration']),
122
248
  };
@@ -127,53 +253,3 @@ export const sequencerClientConfigMappings: ConfigMappingsType<SequencerClientCo
127
253
  export function getConfigEnvVars(): SequencerClientConfig {
128
254
  return getConfigFromMappings<SequencerClientConfig>(sequencerClientConfigMappings);
129
255
  }
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
- }
@@ -1,69 +1,99 @@
1
- import {
2
- type L1ContractsConfig,
3
- type L1ReaderConfig,
4
- type ViemPublicClient,
5
- createEthereumChain,
6
- } from '@aztec/ethereum';
1
+ import { createEthereumChain } from '@aztec/ethereum/chain';
2
+ import { makeL1HttpTransport } from '@aztec/ethereum/client';
3
+ import type { L1ContractsConfig } from '@aztec/ethereum/config';
4
+ import { RollupContract } from '@aztec/ethereum/contracts';
5
+ import type { L1ReaderConfig } from '@aztec/ethereum/l1-reader';
6
+ import type { ViemPublicClient } from '@aztec/ethereum/types';
7
+ import { BlockNumber, SlotNumber } from '@aztec/foundation/branded-types';
8
+ import { Fr } from '@aztec/foundation/curves/bn254';
7
9
  import type { EthAddress } from '@aztec/foundation/eth-address';
8
- import { Fr } from '@aztec/foundation/fields';
9
10
  import { createLogger } from '@aztec/foundation/log';
10
- import { RollupAbi } from '@aztec/l1-artifacts';
11
11
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
12
+ import { type L1RollupConstants, getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
12
13
  import { GasFees } from '@aztec/stdlib/gas';
13
- import type { GlobalVariableBuilder as GlobalVariableBuilderInterface } from '@aztec/stdlib/tx';
14
+ import type {
15
+ CheckpointGlobalVariables,
16
+ GlobalVariableBuilder as GlobalVariableBuilderInterface,
17
+ } from '@aztec/stdlib/tx';
14
18
  import { GlobalVariables } from '@aztec/stdlib/tx';
15
19
 
16
- import { type GetContractReturnType, createPublicClient, fallback, getAddress, getContract, http } from 'viem';
20
+ import { createPublicClient } from 'viem';
17
21
 
18
22
  /**
19
23
  * Simple global variables builder.
20
24
  */
21
25
  export class GlobalVariableBuilder implements GlobalVariableBuilderInterface {
22
26
  private log = createLogger('sequencer:global_variable_builder');
23
-
24
- private rollupContract: GetContractReturnType<typeof RollupAbi, ViemPublicClient>;
25
- private publicClient: ViemPublicClient;
26
- private ethereumSlotDuration: number;
27
-
28
- constructor(config: L1ReaderConfig & Pick<L1ContractsConfig, 'ethereumSlotDuration'>) {
27
+ private currentMinFees: Promise<GasFees> = Promise.resolve(new GasFees(0, 0));
28
+ private currentL1BlockNumber: bigint | undefined = undefined;
29
+
30
+ private readonly rollupContract: RollupContract;
31
+ private readonly publicClient: ViemPublicClient;
32
+ private readonly ethereumSlotDuration: number;
33
+ private readonly aztecSlotDuration: number;
34
+ private readonly l1GenesisTime: bigint;
35
+
36
+ private chainId: Fr;
37
+ private version: Fr;
38
+
39
+ constructor(
40
+ config: L1ReaderConfig &
41
+ Pick<L1ContractsConfig, 'ethereumSlotDuration'> &
42
+ Pick<L1RollupConstants, 'slotDuration' | 'l1GenesisTime'> & { rollupVersion: bigint },
43
+ ) {
29
44
  const { l1RpcUrls, l1ChainId: chainId, l1Contracts } = config;
30
45
 
31
46
  const chain = createEthereumChain(l1RpcUrls, chainId);
32
47
 
48
+ this.version = new Fr(config.rollupVersion);
49
+ this.chainId = new Fr(chainId);
50
+
33
51
  this.ethereumSlotDuration = config.ethereumSlotDuration;
52
+ this.aztecSlotDuration = config.slotDuration;
53
+ this.l1GenesisTime = config.l1GenesisTime;
34
54
 
35
55
  this.publicClient = createPublicClient({
36
56
  chain: chain.chainInfo,
37
- transport: fallback(chain.rpcUrls.map(url => http(url))),
57
+ transport: makeL1HttpTransport(chain.rpcUrls, { timeout: config.l1HttpTimeoutMS }),
38
58
  pollingInterval: config.viemPollingIntervalMS,
39
59
  });
40
60
 
41
- this.rollupContract = getContract({
42
- address: getAddress(l1Contracts.rollupAddress.toString()),
43
- abi: RollupAbi,
44
- client: this.publicClient,
45
- });
61
+ this.rollupContract = new RollupContract(this.publicClient, l1Contracts.rollupAddress);
46
62
  }
47
63
 
48
64
  /**
49
- * Computes the "current" base fees, e.g., the price that you currently should pay to get include in the next block
50
- * @returns Base fees for the expected next block
65
+ * Computes the "current" min fees, e.g., the price that you currently should pay to get include in the next block
66
+ * @returns Min fees for the next block
51
67
  */
52
- public async getCurrentBaseFees(): Promise<GasFees> {
68
+ private async computeCurrentMinFees(): Promise<GasFees> {
53
69
  // Since this might be called in the middle of a slot where a block might have been published,
54
70
  // we need to fetch the last block written, and estimate the earliest timestamp for the next block.
55
71
  // The timestamp of that last block will act as a lower bound for the next block.
56
72
 
57
- const lastBlock = await this.rollupContract.read.getBlock([await this.rollupContract.read.getPendingBlockNumber()]);
58
- const earliestTimestamp = await this.rollupContract.read.getTimestampForSlot([lastBlock.slotNumber + 1n]);
73
+ const lastCheckpoint = await this.rollupContract.getPendingCheckpoint();
74
+ const earliestTimestamp = await this.rollupContract.getTimestampForSlot(
75
+ SlotNumber.fromBigInt(BigInt(lastCheckpoint.slotNumber) + 1n),
76
+ );
59
77
  const nextEthTimestamp = BigInt((await this.publicClient.getBlock()).timestamp + BigInt(this.ethereumSlotDuration));
60
78
  const timestamp = earliestTimestamp > nextEthTimestamp ? earliestTimestamp : nextEthTimestamp;
61
79
 
62
- return new GasFees(Fr.ZERO, new Fr(await this.rollupContract.read.getManaBaseFeeAt([timestamp, true])));
80
+ return new GasFees(0, await this.rollupContract.getManaMinFeeAt(timestamp, true));
81
+ }
82
+
83
+ public async getCurrentMinFees(): Promise<GasFees> {
84
+ // Get the current block number
85
+ const blockNumber = await this.publicClient.getBlockNumber();
86
+
87
+ // If the L1 block number has changed then chain a new promise to get the current min fees
88
+ if (this.currentL1BlockNumber === undefined || blockNumber > this.currentL1BlockNumber) {
89
+ this.currentL1BlockNumber = blockNumber;
90
+ this.currentMinFees = this.currentMinFees.then(() => this.computeCurrentMinFees());
91
+ }
92
+ return this.currentMinFees;
63
93
  }
64
94
 
65
95
  /**
66
- * Simple builder of global variables that use the minimum time possible.
96
+ * Simple builder of global variables.
67
97
  * @param blockNumber - The block number to build global variables for.
68
98
  * @param coinbase - The address to receive block reward.
69
99
  * @param feeRecipient - The address to receive fees.
@@ -71,38 +101,38 @@ export class GlobalVariableBuilder implements GlobalVariableBuilderInterface {
71
101
  * @returns The global variables for the given block number.
72
102
  */
73
103
  public async buildGlobalVariables(
74
- blockNumber: Fr,
104
+ blockNumber: BlockNumber,
75
105
  coinbase: EthAddress,
76
106
  feeRecipient: AztecAddress,
77
- slotNumber?: bigint,
107
+ maybeSlot?: SlotNumber,
78
108
  ): Promise<GlobalVariables> {
79
- const version = new Fr(await this.rollupContract.read.getVersion());
80
- const chainId = new Fr(this.publicClient.chain.id);
81
-
82
- if (slotNumber === undefined) {
83
- const ts = BigInt((await this.publicClient.getBlock()).timestamp + BigInt(this.ethereumSlotDuration));
84
- slotNumber = await this.rollupContract.read.getSlotAt([ts]);
85
- }
86
-
87
- const timestamp = await this.rollupContract.read.getTimestampForSlot([slotNumber]);
109
+ const slot: SlotNumber =
110
+ maybeSlot ??
111
+ (await this.rollupContract.getSlotAt(
112
+ BigInt((await this.publicClient.getBlock()).timestamp + BigInt(this.ethereumSlotDuration)),
113
+ ));
114
+
115
+ const checkpointGlobalVariables = await this.buildCheckpointGlobalVariables(coinbase, feeRecipient, slot);
116
+ return GlobalVariables.from({ blockNumber, ...checkpointGlobalVariables });
117
+ }
88
118
 
89
- const slotFr = new Fr(slotNumber);
90
- const timestampFr = new Fr(timestamp);
119
+ /** Builds global variables that are constant throughout a checkpoint. */
120
+ public async buildCheckpointGlobalVariables(
121
+ coinbase: EthAddress,
122
+ feeRecipient: AztecAddress,
123
+ slotNumber: SlotNumber,
124
+ ): Promise<CheckpointGlobalVariables> {
125
+ const { chainId, version } = this;
91
126
 
92
- // We can skip much of the logic in getCurrentBaseFees since it we already check that we are not within a slot elsewhere.
93
- const gasFees = new GasFees(Fr.ZERO, new Fr(await this.rollupContract.read.getManaBaseFeeAt([timestamp, true])));
127
+ const timestamp = getTimestampForSlot(slotNumber, {
128
+ slotDuration: this.aztecSlotDuration,
129
+ l1GenesisTime: this.l1GenesisTime,
130
+ });
94
131
 
95
- const globalVariables = new GlobalVariables(
96
- chainId,
97
- version,
98
- blockNumber,
99
- slotFr,
100
- timestampFr,
101
- coinbase,
102
- feeRecipient,
103
- gasFees,
104
- );
132
+ // We can skip much of the logic in getCurrentMinFees since it we already check that we are not within a slot elsewhere.
133
+ // TODO(palla/mbps): Can we use a cached value here?
134
+ const gasFees = new GasFees(0, await this.rollupContract.getManaMinFeeAt(timestamp, true));
105
135
 
106
- return globalVariables;
136
+ return { chainId, version, slotNumber, timestamp, coinbase, feeRecipient, gasFees };
107
137
  }
108
138
  }
package/src/index.ts CHANGED
@@ -1,9 +1,7 @@
1
1
  export * from './client/index.js';
2
2
  export * from './config.js';
3
3
  export * from './publisher/index.js';
4
- export * from './tx_validator/tx_validator_factory.js';
5
- export * from './slasher/index.js';
6
- export { Sequencer, SequencerState, getDefaultAllowedSetupFunctions } from './sequencer/index.js';
4
+ export { Sequencer, SequencerState, type SequencerEvents } from './sequencer/index.js';
7
5
 
8
6
  // Used by the node to simulate public parts of transactions. Should these be moved to a shared library?
9
7
  // ISSUE(#9832)