@aztec-labs/sequencer-client 6.0.0-nightly.20260829

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 (165) hide show
  1. package/README.md +307 -0
  2. package/dest/client/index.d.ts +2 -0
  3. package/dest/client/index.d.ts.map +1 -0
  4. package/dest/client/index.js +1 -0
  5. package/dest/client/sequencer-client.d.ts +94 -0
  6. package/dest/client/sequencer-client.d.ts.map +1 -0
  7. package/dest/client/sequencer-client.js +177 -0
  8. package/dest/config.d.ts +56 -0
  9. package/dest/config.d.ts.map +1 -0
  10. package/dest/config.js +251 -0
  11. package/dest/global_variable_builder/fee_predictor.d.ts +49 -0
  12. package/dest/global_variable_builder/fee_predictor.d.ts.map +1 -0
  13. package/dest/global_variable_builder/fee_predictor.js +127 -0
  14. package/dest/global_variable_builder/fee_provider.d.ts +28 -0
  15. package/dest/global_variable_builder/fee_provider.d.ts.map +1 -0
  16. package/dest/global_variable_builder/fee_provider.js +87 -0
  17. package/dest/global_variable_builder/global_builder.d.ts +28 -0
  18. package/dest/global_variable_builder/global_builder.d.ts.map +1 -0
  19. package/dest/global_variable_builder/global_builder.js +40 -0
  20. package/dest/global_variable_builder/index.d.ts +4 -0
  21. package/dest/global_variable_builder/index.d.ts.map +1 -0
  22. package/dest/global_variable_builder/index.js +3 -0
  23. package/dest/index.d.ts +7 -0
  24. package/dest/index.d.ts.map +1 -0
  25. package/dest/index.js +8 -0
  26. package/dest/publisher/config.d.ts +68 -0
  27. package/dest/publisher/config.d.ts.map +1 -0
  28. package/dest/publisher/config.js +137 -0
  29. package/dest/publisher/index.d.ts +5 -0
  30. package/dest/publisher/index.d.ts.map +1 -0
  31. package/dest/publisher/index.js +4 -0
  32. package/dest/publisher/l1_to_l2_messaging.d.ts +21 -0
  33. package/dest/publisher/l1_to_l2_messaging.d.ts.map +1 -0
  34. package/dest/publisher/l1_to_l2_messaging.js +70 -0
  35. package/dest/publisher/l1_tx_failed_store/factory.d.ts +11 -0
  36. package/dest/publisher/l1_tx_failed_store/factory.d.ts.map +1 -0
  37. package/dest/publisher/l1_tx_failed_store/factory.js +22 -0
  38. package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts +101 -0
  39. package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts.map +1 -0
  40. package/dest/publisher/l1_tx_failed_store/failed_tx_store.js +68 -0
  41. package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts +15 -0
  42. package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts.map +1 -0
  43. package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.js +36 -0
  44. package/dest/publisher/l1_tx_failed_store/index.d.ts +4 -0
  45. package/dest/publisher/l1_tx_failed_store/index.d.ts.map +1 -0
  46. package/dest/publisher/l1_tx_failed_store/index.js +3 -0
  47. package/dest/publisher/sequencer-bundle-simulator.d.ts +96 -0
  48. package/dest/publisher/sequencer-bundle-simulator.d.ts.map +1 -0
  49. package/dest/publisher/sequencer-bundle-simulator.js +198 -0
  50. package/dest/publisher/sequencer-publisher-factory.d.ts +50 -0
  51. package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -0
  52. package/dest/publisher/sequencer-publisher-factory.js +75 -0
  53. package/dest/publisher/sequencer-publisher-metrics.d.ts +26 -0
  54. package/dest/publisher/sequencer-publisher-metrics.d.ts.map +1 -0
  55. package/dest/publisher/sequencer-publisher-metrics.js +101 -0
  56. package/dest/publisher/sequencer-publisher.d.ts +254 -0
  57. package/dest/publisher/sequencer-publisher.d.ts.map +1 -0
  58. package/dest/publisher/sequencer-publisher.js +1784 -0
  59. package/dest/publisher/write_json.d.ts +11 -0
  60. package/dest/publisher/write_json.d.ts.map +1 -0
  61. package/dest/publisher/write_json.js +57 -0
  62. package/dest/sequencer/automine/automine_factory.d.ts +56 -0
  63. package/dest/sequencer/automine/automine_factory.d.ts.map +1 -0
  64. package/dest/sequencer/automine/automine_factory.js +85 -0
  65. package/dest/sequencer/automine/automine_sequencer.d.ts +189 -0
  66. package/dest/sequencer/automine/automine_sequencer.d.ts.map +1 -0
  67. package/dest/sequencer/automine/automine_sequencer.js +732 -0
  68. package/dest/sequencer/automine/index.d.ts +3 -0
  69. package/dest/sequencer/automine/index.d.ts.map +1 -0
  70. package/dest/sequencer/automine/index.js +2 -0
  71. package/dest/sequencer/checkpoint_proposal_job.d.ts +169 -0
  72. package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -0
  73. package/dest/sequencer/checkpoint_proposal_job.js +1961 -0
  74. package/dest/sequencer/checkpoint_proposal_job_metrics.d.ts +34 -0
  75. package/dest/sequencer/checkpoint_proposal_job_metrics.d.ts.map +1 -0
  76. package/dest/sequencer/checkpoint_proposal_job_metrics.js +72 -0
  77. package/dest/sequencer/checkpoint_voter.d.ts +34 -0
  78. package/dest/sequencer/checkpoint_voter.d.ts.map +1 -0
  79. package/dest/sequencer/checkpoint_voter.js +106 -0
  80. package/dest/sequencer/config.d.ts +8 -0
  81. package/dest/sequencer/config.d.ts.map +1 -0
  82. package/dest/sequencer/config.js +1 -0
  83. package/dest/sequencer/errors.d.ts +11 -0
  84. package/dest/sequencer/errors.d.ts.map +1 -0
  85. package/dest/sequencer/errors.js +15 -0
  86. package/dest/sequencer/events.d.ts +103 -0
  87. package/dest/sequencer/events.d.ts.map +1 -0
  88. package/dest/sequencer/events.js +1 -0
  89. package/dest/sequencer/inbox_bucket_selector.d.ts +88 -0
  90. package/dest/sequencer/inbox_bucket_selector.d.ts.map +1 -0
  91. package/dest/sequencer/inbox_bucket_selector.js +80 -0
  92. package/dest/sequencer/index.d.ts +6 -0
  93. package/dest/sequencer/index.d.ts.map +1 -0
  94. package/dest/sequencer/index.js +5 -0
  95. package/dest/sequencer/metrics.d.ts +75 -0
  96. package/dest/sequencer/metrics.d.ts.map +1 -0
  97. package/dest/sequencer/metrics.js +343 -0
  98. package/dest/sequencer/missing_committee.d.ts +72 -0
  99. package/dest/sequencer/missing_committee.d.ts.map +1 -0
  100. package/dest/sequencer/missing_committee.js +139 -0
  101. package/dest/sequencer/requests_tracker.d.ts +22 -0
  102. package/dest/sequencer/requests_tracker.d.ts.map +1 -0
  103. package/dest/sequencer/requests_tracker.js +33 -0
  104. package/dest/sequencer/sequencer.d.ts +326 -0
  105. package/dest/sequencer/sequencer.d.ts.map +1 -0
  106. package/dest/sequencer/sequencer.js +1495 -0
  107. package/dest/sequencer/types.d.ts +3 -0
  108. package/dest/sequencer/types.d.ts.map +1 -0
  109. package/dest/sequencer/types.js +1 -0
  110. package/dest/sequencer/utils.d.ts +30 -0
  111. package/dest/sequencer/utils.d.ts.map +1 -0
  112. package/dest/sequencer/utils.js +18 -0
  113. package/dest/test/index.d.ts +23 -0
  114. package/dest/test/index.d.ts.map +1 -0
  115. package/dest/test/index.js +6 -0
  116. package/dest/test/mock_checkpoint_builder.d.ts +95 -0
  117. package/dest/test/mock_checkpoint_builder.d.ts.map +1 -0
  118. package/dest/test/mock_checkpoint_builder.js +230 -0
  119. package/dest/test/utils.d.ts +67 -0
  120. package/dest/test/utils.d.ts.map +1 -0
  121. package/dest/test/utils.js +121 -0
  122. package/package.json +118 -0
  123. package/src/client/index.ts +1 -0
  124. package/src/client/sequencer-client.ts +281 -0
  125. package/src/config.ts +309 -0
  126. package/src/global_variable_builder/README.md +44 -0
  127. package/src/global_variable_builder/fee_predictor.ts +176 -0
  128. package/src/global_variable_builder/fee_provider.ts +104 -0
  129. package/src/global_variable_builder/global_builder.ts +68 -0
  130. package/src/global_variable_builder/index.ts +3 -0
  131. package/src/index.ts +15 -0
  132. package/src/publisher/config.ts +220 -0
  133. package/src/publisher/index.ts +8 -0
  134. package/src/publisher/l1_to_l2_messaging.ts +85 -0
  135. package/src/publisher/l1_tx_failed_store/factory.ts +32 -0
  136. package/src/publisher/l1_tx_failed_store/failed_tx_store.ts +166 -0
  137. package/src/publisher/l1_tx_failed_store/file_store_failed_tx_store.ts +47 -0
  138. package/src/publisher/l1_tx_failed_store/index.ts +3 -0
  139. package/src/publisher/sequencer-bundle-simulator.ts +253 -0
  140. package/src/publisher/sequencer-publisher-factory.ts +121 -0
  141. package/src/publisher/sequencer-publisher-metrics.ts +145 -0
  142. package/src/publisher/sequencer-publisher.ts +1719 -0
  143. package/src/publisher/write_json.ts +77 -0
  144. package/src/sequencer/README.md +243 -0
  145. package/src/sequencer/automine/README.md +60 -0
  146. package/src/sequencer/automine/automine_factory.ts +156 -0
  147. package/src/sequencer/automine/automine_sequencer.ts +841 -0
  148. package/src/sequencer/automine/index.ts +6 -0
  149. package/src/sequencer/checkpoint_proposal_job.ts +1889 -0
  150. package/src/sequencer/checkpoint_proposal_job_metrics.ts +128 -0
  151. package/src/sequencer/checkpoint_voter.ts +118 -0
  152. package/src/sequencer/config.ts +9 -0
  153. package/src/sequencer/errors.ts +21 -0
  154. package/src/sequencer/events.ts +93 -0
  155. package/src/sequencer/inbox_bucket_selector.ts +160 -0
  156. package/src/sequencer/index.ts +5 -0
  157. package/src/sequencer/metrics.ts +463 -0
  158. package/src/sequencer/missing_committee.ts +192 -0
  159. package/src/sequencer/requests_tracker.ts +43 -0
  160. package/src/sequencer/sequencer.ts +1401 -0
  161. package/src/sequencer/types.ts +6 -0
  162. package/src/sequencer/utils.ts +42 -0
  163. package/src/test/index.ts +26 -0
  164. package/src/test/mock_checkpoint_builder.ts +324 -0
  165. package/src/test/utils.ts +215 -0
package/src/config.ts ADDED
@@ -0,0 +1,309 @@
1
+ import { type L1ContractsConfig, l1ContractsConfigMappings } from '@aztec-labs/ethereum/config';
2
+ import { type L1ReaderConfig, l1ReaderConfigMappings } from '@aztec-labs/ethereum/l1-reader';
3
+ import {
4
+ type ConfigMappingsType,
5
+ booleanConfigHelper,
6
+ floatConfigHelper,
7
+ getConfigFromMappings,
8
+ numberConfigHelper,
9
+ optionalNumberConfigHelper,
10
+ pickConfigMappings,
11
+ } from '@aztec-labs/foundation/config';
12
+ import { EthAddress } from '@aztec-labs/foundation/eth-address';
13
+ import { type KeyStoreConfig, keyStoreConfigMappings } from '@aztec-labs/node-keystore/config';
14
+ import { type P2PConfig, p2pConfigMappings } from '@aztec-labs/p2p/config';
15
+ import { AztecAddress } from '@aztec-labs/stdlib/aztec-address';
16
+ import {
17
+ type ChainConfig,
18
+ DEFAULT_BLOCK_DURATION_MS,
19
+ DEFAULT_MAX_BLOCKS_PER_CHECKPOINT,
20
+ type SequencerConfig,
21
+ chainConfigMappings,
22
+ sharedSequencerConfigMappings,
23
+ } from '@aztec-labs/stdlib/config';
24
+ import { MIN_PER_BLOCK_ALLOCATION_MULTIPLIER, MIN_PER_BLOCK_DA_ALLOCATION_MULTIPLIER } from '@aztec-labs/stdlib/gas';
25
+ import type { ResolvedSequencerConfig } from '@aztec-labs/stdlib/interfaces/server';
26
+ import { DEFAULT_P2P_PROPAGATION_TIME } from '@aztec-labs/stdlib/timetable';
27
+ import { type ValidatorClientConfig, validatorClientConfigMappings } from '@aztec-labs/validator-client/config';
28
+
29
+ import {
30
+ type SequencerPublisherConfig,
31
+ type SequencerTxSenderConfig,
32
+ sequencerPublisherConfigMappings,
33
+ sequencerTxSenderConfigMappings,
34
+ } from './publisher/config.js';
35
+
36
+ export * from './publisher/config.js';
37
+ export type { SequencerConfig };
38
+
39
+ /**
40
+ * Default values for SequencerConfig.
41
+ * Centralized location for all sequencer configuration defaults.
42
+ */
43
+ export const DefaultSequencerConfig = {
44
+ sequencerPollingIntervalMS: 500,
45
+ minTxsPerBlock: 1,
46
+ buildCheckpointIfEmpty: false,
47
+ publishTxsWithProposals: false,
48
+ perBlockAllocationMultiplier: MIN_PER_BLOCK_ALLOCATION_MULTIPLIER,
49
+ perBlockDAAllocationMultiplier: MIN_PER_BLOCK_DA_ALLOCATION_MULTIPLIER,
50
+ redistributeCheckpointBudget: true,
51
+ blockDurationMs: DEFAULT_BLOCK_DURATION_MS,
52
+ l1PublishingTime: 12,
53
+ checkpointProposalSyncGraceSeconds: 2 * (DEFAULT_BLOCK_DURATION_MS / 1000),
54
+ attestationPropagationTime: DEFAULT_P2P_PROPAGATION_TIME,
55
+ secondsBeforeInvalidatingBlockAsCommitteeMember: 144, // 12 L1 blocks
56
+ secondsBeforeInvalidatingBlockAsNonCommitteeMember: 432, // 36 L1 blocks
57
+ skipCollectingAttestations: false,
58
+ skipInvalidateBlockAsProposer: false,
59
+ skipWaitForValidParentCheckpointOnL1: false,
60
+ broadcastInvalidBlockProposal: false,
61
+ broadcastInvalidCheckpointProposalOnly: false,
62
+ injectFakeAttestation: false,
63
+ injectHighSValueAttestation: false,
64
+ injectUnrecoverableSignatureAttestation: false,
65
+ injectYParityAttestation: false,
66
+ fishermanMode: false,
67
+ governanceProposerForcePayloadVote: false,
68
+ shuffleAttestationOrdering: false,
69
+ skipPushProposedBlocksToArchiver: false,
70
+ skipPublishingCheckpointsPercent: 0,
71
+ maxBlocksPerCheckpoint: DEFAULT_MAX_BLOCKS_PER_CHECKPOINT,
72
+ minPeersToPropose: 1,
73
+ } satisfies ResolvedSequencerConfig;
74
+
75
+ /**
76
+ * Configuration settings for the SequencerClient.
77
+ */
78
+ export type SequencerClientConfig = SequencerPublisherConfig &
79
+ KeyStoreConfig &
80
+ ValidatorClientConfig &
81
+ SequencerTxSenderConfig &
82
+ SequencerConfig &
83
+ L1ReaderConfig &
84
+ ChainConfig &
85
+ Pick<P2PConfig, 'txPublicSetupAllowListExtend'> &
86
+ Pick<L1ContractsConfig, 'ethereumSlotDuration' | 'aztecSlotDuration' | 'aztecEpochDuration'>;
87
+
88
+ export const sequencerConfigMappings: ConfigMappingsType<SequencerConfig> = {
89
+ sequencerPollingIntervalMS: {
90
+ env: 'SEQ_POLLING_INTERVAL_MS',
91
+ description: 'The number of ms to wait between polling for checking to build on the next slot.',
92
+ ...numberConfigHelper(DefaultSequencerConfig.sequencerPollingIntervalMS),
93
+ },
94
+ maxTxsPerCheckpoint: {
95
+ env: 'SEQ_MAX_TX_PER_CHECKPOINT',
96
+ description: 'The maximum number of txs across all blocks in a checkpoint.',
97
+ ...optionalNumberConfigHelper(),
98
+ },
99
+ minTxsPerBlock: {
100
+ env: 'SEQ_MIN_TX_PER_BLOCK',
101
+ description: 'The minimum number of txs to include in a block.',
102
+ ...numberConfigHelper(DefaultSequencerConfig.minTxsPerBlock),
103
+ },
104
+ minValidTxsPerBlock: {
105
+ description:
106
+ 'The minimum number of valid txs (after execution) to include in a block. If not set, falls back to minTxsPerBlock.',
107
+ },
108
+ publishTxsWithProposals: {
109
+ env: 'SEQ_PUBLISH_TXS_WITH_PROPOSALS',
110
+ description: 'Whether to publish txs with proposals.',
111
+ ...booleanConfigHelper(DefaultSequencerConfig.publishTxsWithProposals),
112
+ },
113
+ maxL2BlockGas: {
114
+ env: 'SEQ_MAX_L2_BLOCK_GAS',
115
+ description: 'The maximum L2 block gas.',
116
+ ...optionalNumberConfigHelper(),
117
+ },
118
+ maxDABlockGas: {
119
+ env: 'SEQ_MAX_DA_BLOCK_GAS',
120
+ description: 'The maximum DA block gas.',
121
+ ...optionalNumberConfigHelper(),
122
+ },
123
+ perBlockAllocationMultiplier: {
124
+ env: 'SEQ_PER_BLOCK_ALLOCATION_MULTIPLIER',
125
+ description:
126
+ 'Per-block gas budget multiplier for both L2 and DA gas. Budget per block is (checkpointLimit / maxBlocks) * multiplier.' +
127
+ ' Values greater than one allow early blocks to use more than their even share, relying on checkpoint-level capping for later blocks.',
128
+ ...floatConfigHelper(DefaultSequencerConfig.perBlockAllocationMultiplier),
129
+ },
130
+ perBlockDAAllocationMultiplier: {
131
+ env: 'SEQ_PER_BLOCK_DA_ALLOCATION_MULTIPLIER',
132
+ description:
133
+ 'Per-block budget multiplier applied to DA gas and blob fields in place of perBlockAllocationMultiplier.' +
134
+ ' Defaults higher than the general multiplier so the largest contract class deploy fits a single block.',
135
+ ...floatConfigHelper(DefaultSequencerConfig.perBlockDAAllocationMultiplier),
136
+ },
137
+ redistributeCheckpointBudget: {
138
+ env: 'SEQ_REDISTRIBUTE_CHECKPOINT_BUDGET',
139
+ description:
140
+ 'Redistribute remaining checkpoint budget evenly across remaining blocks instead of allowing a single block to consume the entire remaining budget.',
141
+ ...booleanConfigHelper(DefaultSequencerConfig.redistributeCheckpointBudget),
142
+ },
143
+ coinbase: {
144
+ env: 'COINBASE',
145
+ parseEnv: (val: string) => EthAddress.fromString(val),
146
+ description: 'Recipient of block reward.',
147
+ },
148
+ feeRecipient: {
149
+ env: 'FEE_RECIPIENT',
150
+ parseEnv: (val: string) => AztecAddress.fromStringUnsafe(val),
151
+ description: 'Address to receive fees.',
152
+ },
153
+ acvmWorkingDirectory: {
154
+ env: 'ACVM_WORKING_DIRECTORY',
155
+ description: 'The working directory to use for simulation/proving',
156
+ },
157
+ acvmBinaryPath: {
158
+ env: 'ACVM_BINARY_PATH',
159
+ description: 'The path to the ACVM binary',
160
+ },
161
+ governanceProposerPayload: {
162
+ env: 'GOVERNANCE_PROPOSER_PAYLOAD_ADDRESS',
163
+ description: 'The address of the payload for the governanceProposer',
164
+ parseEnv: (val: string) => EthAddress.fromString(val),
165
+ },
166
+ governanceProposerForcePayloadVote: {
167
+ env: 'GOVERNANCE_PROPOSER_FORCE_PAYLOAD_VOTE',
168
+ description:
169
+ 'Keep signalling the configured governance payload even if a proposal referencing it was already executed.',
170
+ ...booleanConfigHelper(DefaultSequencerConfig.governanceProposerForcePayloadVote),
171
+ },
172
+ l1PublishingTime: {
173
+ env: 'SEQ_L1_PUBLISHING_TIME_ALLOWANCE_IN_SLOT',
174
+ description: 'How much time in seconds to allow in the slot for publishing the L1 transaction.',
175
+ ...numberConfigHelper(DefaultSequencerConfig.l1PublishingTime),
176
+ },
177
+ fakeProcessingDelayPerTxMs: {
178
+ description: 'Used for testing to introduce a fake delay after processing each tx',
179
+ },
180
+ fakeThrowAfterProcessingTxCount: {
181
+ description: 'Used for testing to throw an error after processing N txs',
182
+ },
183
+ secondsBeforeInvalidatingBlockAsCommitteeMember: {
184
+ env: 'SEQ_SECONDS_BEFORE_INVALIDATING_BLOCK_AS_COMMITTEE_MEMBER',
185
+ description:
186
+ 'How many seconds to wait before trying to invalidate a block from the pending chain as a committee member (zero to never invalidate).' +
187
+ ' The next proposer is expected to invalidate, so the committee acts as a fallback.',
188
+ ...numberConfigHelper(DefaultSequencerConfig.secondsBeforeInvalidatingBlockAsCommitteeMember),
189
+ },
190
+ secondsBeforeInvalidatingBlockAsNonCommitteeMember: {
191
+ env: 'SEQ_SECONDS_BEFORE_INVALIDATING_BLOCK_AS_NON_COMMITTEE_MEMBER',
192
+ description:
193
+ 'How many seconds to wait before trying to invalidate a block from the pending chain as a non-committee member (zero to never invalidate).' +
194
+ ' The next proposer is expected to invalidate, then the committee, so other sequencers act as a fallback.',
195
+ ...numberConfigHelper(DefaultSequencerConfig.secondsBeforeInvalidatingBlockAsNonCommitteeMember),
196
+ },
197
+ skipCollectingAttestations: {
198
+ description:
199
+ 'Whether to skip collecting attestations from validators and only use self-attestations (for testing only)',
200
+ ...booleanConfigHelper(DefaultSequencerConfig.skipCollectingAttestations),
201
+ },
202
+ skipInvalidateBlockAsProposer: {
203
+ description: 'Do not invalidate the previous block if invalid when we are the proposer (for testing only)',
204
+ ...booleanConfigHelper(DefaultSequencerConfig.skipInvalidateBlockAsProposer),
205
+ },
206
+ skipWaitForValidParentCheckpointOnL1: {
207
+ description:
208
+ 'Bypass the parent checkpoint validity check before submitting a pipelined checkpoint, ' +
209
+ 'allowing the proposer to publish even when the parent landed on L1 with invalid attestations (for testing only)',
210
+ ...booleanConfigHelper(DefaultSequencerConfig.skipWaitForValidParentCheckpointOnL1),
211
+ },
212
+ broadcastInvalidBlockProposal: {
213
+ description: 'Broadcast invalid block proposals with corrupted state (for testing only)',
214
+ ...booleanConfigHelper(DefaultSequencerConfig.broadcastInvalidBlockProposal),
215
+ },
216
+ invalidBlockProposalIndexWithinCheckpoint: {
217
+ description: 'Broadcast an invalid block proposal only at this indexWithinCheckpoint (for testing only)',
218
+ ...optionalNumberConfigHelper(),
219
+ },
220
+ broadcastInvalidCheckpointProposalOnly: {
221
+ description:
222
+ 'Broadcast invalid checkpoint proposals while keeping the underlying block proposals valid (for testing only). When unset, the checkpoint follows broadcastInvalidBlockProposal.',
223
+ ...booleanConfigHelper(DefaultSequencerConfig.broadcastInvalidCheckpointProposalOnly),
224
+ },
225
+ injectFakeAttestation: {
226
+ description: 'Inject a fake attestation (for testing only)',
227
+ ...booleanConfigHelper(DefaultSequencerConfig.injectFakeAttestation),
228
+ },
229
+ injectHighSValueAttestation: {
230
+ description: 'Inject a malleable attestation with a high-s value (for testing only)',
231
+ ...booleanConfigHelper(DefaultSequencerConfig.injectHighSValueAttestation),
232
+ },
233
+ injectUnrecoverableSignatureAttestation: {
234
+ description: 'Inject an attestation with an unrecoverable signature (for testing only)',
235
+ ...booleanConfigHelper(DefaultSequencerConfig.injectUnrecoverableSignatureAttestation),
236
+ },
237
+ injectYParityAttestation: {
238
+ description: 'Inject a non-proposer attestation slot in yParity form in the packed L1 tuple (for testing only)',
239
+ ...booleanConfigHelper(DefaultSequencerConfig.injectYParityAttestation),
240
+ },
241
+ fishermanMode: {
242
+ env: 'FISHERMAN_MODE',
243
+ description:
244
+ 'Whether to run in fisherman mode: builds blocks on every slot for validation without publishing to L1',
245
+ ...booleanConfigHelper(DefaultSequencerConfig.fishermanMode),
246
+ },
247
+ shuffleAttestationOrdering: {
248
+ description: 'Shuffle attestation ordering to create invalid ordering (for testing only)',
249
+ ...booleanConfigHelper(DefaultSequencerConfig.shuffleAttestationOrdering),
250
+ },
251
+ ...sharedSequencerConfigMappings,
252
+ buildCheckpointIfEmpty: {
253
+ env: 'SEQ_BUILD_CHECKPOINT_IF_EMPTY',
254
+ description: 'Have sequencer build and publish an empty checkpoint if there are no txs',
255
+ ...booleanConfigHelper(DefaultSequencerConfig.buildCheckpointIfEmpty),
256
+ },
257
+ skipPushProposedBlocksToArchiver: {
258
+ description: 'Skip pushing proposed blocks to archiver (test only)',
259
+ ...booleanConfigHelper(DefaultSequencerConfig.skipPushProposedBlocksToArchiver),
260
+ },
261
+ minBlocksForCheckpoint: {
262
+ description: 'Minimum number of blocks required for a checkpoint proposal (test only)',
263
+ },
264
+ skipPublishingCheckpointsPercent: {
265
+ env: 'SEQ_SKIP_CHECKPOINT_PUBLISH_PERCENT',
266
+ description: 'Percent probability (0 - 100) of sequencer skipping checkpoint publishing (testing only)',
267
+ ...numberConfigHelper(DefaultSequencerConfig.skipPublishingCheckpointsPercent),
268
+ },
269
+ skipBroadcastProposals: {
270
+ description: 'Skip broadcasting checkpoint and block proposals via gossipsub when proposer (for testing only)',
271
+ ...booleanConfigHelper(false),
272
+ },
273
+ skipBroadcastCheckpointProposal: {
274
+ description:
275
+ 'Skip broadcasting only the CheckpointProposal via gossipsub when proposer; the held last block is broadcast ' +
276
+ 'standalone instead so peers still receive it as a proposed-but-uncheckpointed tip (for testing only)',
277
+ ...booleanConfigHelper(false),
278
+ },
279
+ pauseProposingForSlots: {
280
+ description:
281
+ 'List of slots for which the sequencer will not produce a proposal (for testing only). Attestation paths are unaffected.',
282
+ },
283
+ minPeersToPropose: {
284
+ env: 'SEQ_MIN_PEERS_TO_PROPOSE',
285
+ description:
286
+ 'Minimum number of connected p2p peers required to build and propose a checkpoint (zero to disable the check).' +
287
+ ' Ignored when p2p is disabled by config.',
288
+ ...numberConfigHelper(DefaultSequencerConfig.minPeersToPropose),
289
+ },
290
+ ...pickConfigMappings(p2pConfigMappings, ['txPublicSetupAllowListExtend']),
291
+ };
292
+
293
+ export const sequencerClientConfigMappings: ConfigMappingsType<SequencerClientConfig> = {
294
+ ...chainConfigMappings,
295
+ ...validatorClientConfigMappings,
296
+ ...sequencerConfigMappings,
297
+ ...keyStoreConfigMappings,
298
+ ...l1ReaderConfigMappings,
299
+ ...sequencerTxSenderConfigMappings,
300
+ ...sequencerPublisherConfigMappings,
301
+ ...pickConfigMappings(l1ContractsConfigMappings, ['ethereumSlotDuration', 'aztecSlotDuration', 'aztecEpochDuration']),
302
+ };
303
+
304
+ /**
305
+ * Creates an instance of SequencerClientConfig out of environment variables using sensible defaults for integration testing if not set.
306
+ */
307
+ export function getConfigEnvVars(): SequencerClientConfig {
308
+ return getConfigFromMappings<SequencerClientConfig>(sequencerClientConfigMappings);
309
+ }
@@ -0,0 +1,44 @@
1
+ # Fee Prediction
2
+
3
+ The `FeePredictor` predicts min fees for upcoming L2 slots based on the current L1
4
+ oracle state and an assumed mana usage pattern.
5
+
6
+ ## Prediction Window
7
+
8
+ The prediction covers `LAG = 2` entries (the next available slot plus 1 more).
9
+ A new oracle update can activate at `startSlot + LAG`, so only the first LAG entries
10
+ are guaranteed stable. Beyond that, L1 fees could change unpredictably.
11
+
12
+ Each entry uses:
13
+
14
+ - The **actual L1 fees** the oracle would return for that slot's timestamp (pre or post,
15
+ depending on whether the slot is before or after `slotOfChange`).
16
+ - A **configurable congestion assumption** (`ManaUsageEstimate`): none (0 mana), target
17
+ (steady state), or limit (worst case, 2x target).
18
+
19
+ The client picks `max(predicted[0..LAG-1])` as their `maxFeesPerGas`.
20
+
21
+ ```
22
+ predicted[0] → fee at next slot (current oracle + current congestion)
23
+ predicted[1] → fee at next slot + 1 (congestion may change based on usage estimate)
24
+ ```
25
+
26
+ ## Why LAG and not LIFETIME?
27
+
28
+ The L1 gas oracle has two timing constants:
29
+
30
+ - **LAG = 2 slots**: when new fees are queued, they activate LAG slots later
31
+ - **LIFETIME = 5 slots**: after an oracle update, the next update is rejected until
32
+ `slotOfChange + (LIFETIME - LAG)` slots have passed
33
+
34
+ If the oracle cooldown has already elapsed (i.e., no recent update), a new update can
35
+ be enqueued at any moment. Its new values would activate LAG slots later. This means
36
+ predictions beyond LAG slots could be invalidated by an oracle update that happens
37
+ right after we query.
38
+
39
+ With a LIFETIME-sized window, we'd give a false sense of coverage: the prediction
40
+ would look like it covers 6 slots, but slots beyond LAG could be wrong if an update
41
+ is enqueued after the prediction is computed.
42
+
43
+ By limiting to LAG entries, we guarantee that all predicted L1 fees are the ones that
44
+ will actually be used — no oracle update can change them within this window.
@@ -0,0 +1,176 @@
1
+ import { type L1FeeData, MAX_FEE_ASSET_PRICE_MODIFIER_BPS, type RollupContract } from '@aztec-labs/ethereum/contracts';
2
+ import { SlotNumber } from '@aztec-labs/foundation/branded-types';
3
+ import { times } from '@aztec-labs/foundation/collection';
4
+ import type { DateProvider } from '@aztec-labs/foundation/timer';
5
+ import { getSlotAtNextL1Block, getTimestampForSlot } from '@aztec-labs/stdlib/epoch-helpers';
6
+ import {
7
+ FEE_ORACLE_LAG,
8
+ GasFees,
9
+ MIN_ETH_PER_FEE_ASSET,
10
+ ManaUsageEstimate,
11
+ computeExcessMana,
12
+ computeManaMinFee,
13
+ } from '@aztec-labs/stdlib/gas';
14
+
15
+ /** Cached rollup state for fee prediction. Refreshed once per L1 block. */
16
+ type FeeOracleState = {
17
+ lastSlot: SlotNumber;
18
+ excessMana: bigint;
19
+ ethPerFeeAsset: bigint;
20
+ manaTarget: bigint;
21
+ manaLimit: bigint;
22
+ provingCostPerManaEth: bigint;
23
+ epochDuration: bigint;
24
+ /** Pre-resolved L1 fees for each slot in the prediction window. */
25
+ l1FeesBySlot: L1FeeData[];
26
+ };
27
+
28
+ /**
29
+ * Predicts min fees for LAG upcoming slots based on the L1 oracle state.
30
+ * A new oracle update can activate at startSlot + LAG, so only the first LAG entries
31
+ * are guaranteed stable.
32
+ */
33
+ export class FeePredictor {
34
+ private cachedState: FeeOracleState | undefined;
35
+
36
+ private readonly slotDuration: number;
37
+ private readonly l1GenesisTime: bigint;
38
+ private readonly ethereumSlotDuration: number;
39
+
40
+ constructor(
41
+ private readonly rollupContract: RollupContract,
42
+ private readonly dateProvider: DateProvider,
43
+ config: { slotDuration: number; l1GenesisTime: bigint; ethereumSlotDuration: number },
44
+ ) {
45
+ this.slotDuration = config.slotDuration;
46
+ this.l1GenesisTime = config.l1GenesisTime;
47
+ this.ethereumSlotDuration = config.ethereumSlotDuration;
48
+ }
49
+
50
+ /** Returns predicted min fees for each slot in the prediction window, from the cached state. */
51
+ getPredictedMinFees(manaUsage: ManaUsageEstimate): GasFees[] {
52
+ const state = this.getState();
53
+ if (state === undefined) {
54
+ throw new Error('FeePredictor.refreshState() must be called before getPredictedMinFees()');
55
+ }
56
+ return this.computePredictions(state, manaUsage);
57
+ }
58
+
59
+ /** Returns whatever rollup state is currently cached, or undefined if refreshState() has never been called. */
60
+ getState(): FeeOracleState | undefined {
61
+ return this.cachedState;
62
+ }
63
+
64
+ /**
65
+ * Fetches and caches rollup state for the given L1 block.
66
+ */
67
+ async refreshState(blockNumber: bigint): Promise<FeeOracleState> {
68
+ const state = await this.fetchState(blockNumber);
69
+ this.cachedState = state;
70
+ return state;
71
+ }
72
+
73
+ private async fetchState(blockNumber: bigint): Promise<FeeOracleState> {
74
+ // Pin all non-constant queries to this L1 block number for a consistent snapshot.
75
+ const opts = { blockNumber };
76
+
77
+ // Cached constants don't need pinning
78
+ const [manaTarget, manaLimit, provingCostPerManaEth, epochDuration] = await Promise.all([
79
+ this.rollupContract.getManaTarget(),
80
+ this.rollupContract.getManaLimit(),
81
+ this.rollupContract.getProvingCostPerMana(),
82
+ this.rollupContract.getEpochDuration(),
83
+ ]);
84
+
85
+ // First, compute the earliest possible nextSlot independently of the checkpoint, so we can
86
+ // evaluate pruneability at the prediction start timestamp instead of the current L1 block time.
87
+ // This avoids an epoch-boundary edge case where the effective parent differs between now and nextSlot.
88
+ const slotConfig = { slotDuration: this.slotDuration, l1GenesisTime: this.l1GenesisTime };
89
+ const currentSlot = await this.rollupContract.getSlotNumber(opts);
90
+
91
+ const slotAtNextL1Block = getSlotAtNextL1Block(BigInt(this.dateProvider.nowInSeconds()), {
92
+ l1GenesisTime: this.l1GenesisTime,
93
+ slotDuration: this.slotDuration,
94
+ ethereumSlotDuration: this.ethereumSlotDuration,
95
+ });
96
+ const preliminaryNextSlot = SlotNumber(Math.max(currentSlot, slotAtNextL1Block));
97
+ const nextSlotTimestamp = getTimestampForSlot(preliminaryNextSlot, slotConfig);
98
+
99
+ // Resolve the effective checkpoint at the prediction start timestamp
100
+ const lastCheckpoint = await this.rollupContract.getEffectivePendingCheckpoint(nextSlotTimestamp, opts);
101
+ const lastSlot = lastCheckpoint.slotNumber;
102
+ // Refine nextSlot: also account for the slot after the last checkpoint
103
+ const nextSlot = SlotNumber(Math.max(SlotNumber.add(lastSlot, 1), preliminaryNextSlot));
104
+ const feeHeader = lastCheckpoint.feeHeader;
105
+
106
+ const slotCount = FEE_ORACLE_LAG;
107
+ const timestamps = times(slotCount, i => getTimestampForSlot(SlotNumber.add(nextSlot, i), slotConfig));
108
+ const l1FeesBySlot = await Promise.all(timestamps.map(ts => this.rollupContract.getL1FeesAt(ts, opts)));
109
+
110
+ return {
111
+ lastSlot,
112
+ excessMana: computeExcessMana(feeHeader.excessMana, feeHeader.manaUsed, manaTarget),
113
+ ethPerFeeAsset: feeHeader.ethPerFeeAsset,
114
+ manaTarget,
115
+ manaLimit,
116
+ provingCostPerManaEth,
117
+ epochDuration: BigInt(epochDuration),
118
+ l1FeesBySlot,
119
+ };
120
+ }
121
+
122
+ /** Computes per-slot fee predictions given cached state and a mana usage assumption. */
123
+ private computePredictions(state: FeeOracleState, manaUsage: ManaUsageEstimate): GasFees[] {
124
+ const assumedManaUsed = this.getAssumedManaUsed(state, manaUsage);
125
+
126
+ const result: GasFees[] = [];
127
+ let { excessMana } = state;
128
+ let { ethPerFeeAsset } = state;
129
+
130
+ // Slot 0: current state (next available slot after last checkpoint)
131
+ result.push(this.computeGasFees(state, excessMana, ethPerFeeAsset, state.l1FeesBySlot[0]));
132
+
133
+ // Slots 1..LAG-1: advance excessMana with the assumed mana usage per checkpoint,
134
+ // and decay ethPerFeeAsset by MAX_FEE_ASSET_PRICE_MODIFIER_BPS per slot for conservative estimates.
135
+ // Lower ethPerFeeAsset means higher fees in fee asset terms.
136
+ for (let i = 1; i < state.l1FeesBySlot.length; i++) {
137
+ excessMana = computeExcessMana(excessMana, assumedManaUsed, state.manaTarget);
138
+ const decayed = (ethPerFeeAsset * (10000n - MAX_FEE_ASSET_PRICE_MODIFIER_BPS)) / 10000n;
139
+ ethPerFeeAsset = decayed < MIN_ETH_PER_FEE_ASSET ? MIN_ETH_PER_FEE_ASSET : decayed;
140
+ result.push(this.computeGasFees(state, excessMana, ethPerFeeAsset, state.l1FeesBySlot[i]));
141
+ }
142
+
143
+ return result;
144
+ }
145
+
146
+ private getAssumedManaUsed(state: FeeOracleState, manaUsage: ManaUsageEstimate): bigint {
147
+ switch (manaUsage) {
148
+ case ManaUsageEstimate.None:
149
+ return 0n;
150
+ case ManaUsageEstimate.Target:
151
+ return state.manaTarget;
152
+ case ManaUsageEstimate.Limit:
153
+ return state.manaLimit;
154
+ }
155
+ }
156
+
157
+ private computeGasFees(
158
+ state: FeeOracleState,
159
+ excessMana: bigint,
160
+ ethPerFeeAsset: bigint,
161
+ l1Fees: L1FeeData,
162
+ ): GasFees {
163
+ return new GasFees(
164
+ 0,
165
+ computeManaMinFee({
166
+ l1BaseFee: l1Fees.baseFee,
167
+ l1BlobFee: l1Fees.blobFee,
168
+ manaTarget: state.manaTarget,
169
+ epochDuration: state.epochDuration,
170
+ provingCostPerManaEth: state.provingCostPerManaEth,
171
+ excessMana,
172
+ ethPerFeeAsset,
173
+ }),
174
+ );
175
+ }
176
+ }
@@ -0,0 +1,104 @@
1
+ import { RollupContract } from '@aztec-labs/ethereum/contracts';
2
+ import type { ViemPublicClient } from '@aztec-labs/ethereum/types';
3
+ import { SlotNumber } from '@aztec-labs/foundation/branded-types';
4
+ import { type Logger, createLogger } from '@aztec-labs/foundation/log';
5
+ import { RunningPromise } from '@aztec-labs/foundation/running-promise';
6
+ import type { DateProvider } from '@aztec-labs/foundation/timer';
7
+ import { getNextL1SlotTimestamp } from '@aztec-labs/stdlib/epoch-helpers';
8
+ import { GasFees, ManaUsageEstimate } from '@aztec-labs/stdlib/gas';
9
+ import type { FeeProvider } from '@aztec-labs/stdlib/tx';
10
+
11
+ import { FeePredictor } from './fee_predictor.js';
12
+ import type { GlobalVariableBuilderConfig } from './global_builder.js';
13
+
14
+ /** Default interval for the background L1 refresh loop, well below L1's block time. */
15
+ const DEFAULT_REFRESH_POLLING_INTERVAL_MS = 1000;
16
+
17
+ /**
18
+ * Provides current and predicted fee information based on on-chain state.
19
+ */
20
+ export class FeeProviderImpl implements FeeProvider {
21
+ private currentMinFees = new GasFees(0, 0);
22
+ private currentL1BlockNumber: bigint | undefined = undefined;
23
+ private refreshLoop: RunningPromise | undefined;
24
+
25
+ private readonly rollupContract: RollupContract;
26
+ private readonly feePredictor: FeePredictor;
27
+ private readonly ethereumSlotDuration: number;
28
+ private readonly l1GenesisTime: bigint;
29
+ private readonly log: Logger = createLogger('sequencer-client:fee-provider');
30
+
31
+ constructor(
32
+ private readonly dateProvider: DateProvider,
33
+ private readonly publicClient: ViemPublicClient,
34
+ config: GlobalVariableBuilderConfig,
35
+ ) {
36
+ this.ethereumSlotDuration = config.ethereumSlotDuration;
37
+ this.l1GenesisTime = config.l1GenesisTime;
38
+
39
+ this.rollupContract = new RollupContract(this.publicClient, config.rollupAddress);
40
+ this.feePredictor = new FeePredictor(this.rollupContract, this.dateProvider, {
41
+ slotDuration: config.slotDuration,
42
+ l1GenesisTime: config.l1GenesisTime,
43
+ ethereumSlotDuration: config.ethereumSlotDuration,
44
+ });
45
+ }
46
+
47
+ public async start(pollingIntervalMs = DEFAULT_REFRESH_POLLING_INTERVAL_MS): Promise<void> {
48
+ await this.refreshFromL1();
49
+ this.refreshLoop = new RunningPromise(() => this.refreshFromL1(), this.log, pollingIntervalMs);
50
+ this.refreshLoop.start();
51
+ }
52
+
53
+ public async stop(): Promise<void> {
54
+ await this.refreshLoop?.stop();
55
+ }
56
+
57
+ /**
58
+ * Checks the current L1 block number and, if it has advanced, refreshes both the current and
59
+ * predicted min fees for that block.
60
+ */
61
+ private async refreshFromL1(): Promise<void> {
62
+ const blockNumber = await this.publicClient.getBlockNumber({ cacheTime: 0 });
63
+ if (this.currentL1BlockNumber !== undefined && blockNumber <= this.currentL1BlockNumber) {
64
+ return;
65
+ }
66
+
67
+ const currentMinFees = await this.computeCurrentMinFees();
68
+ await this.feePredictor.refreshState(blockNumber);
69
+ this.currentMinFees = currentMinFees;
70
+ this.currentL1BlockNumber = blockNumber;
71
+ }
72
+
73
+ /**
74
+ * Computes the "current" min fees, e.g., the price that you currently should pay to get include in the next block
75
+ * @returns Min fees for the next block
76
+ */
77
+ private async computeCurrentMinFees(): Promise<GasFees> {
78
+ // Since this might be called in the middle of a slot where a block might have been published,
79
+ // we need to fetch the last block written, and estimate the earliest timestamp for the next block.
80
+ // The timestamp of that last block will act as a lower bound for the next block.
81
+
82
+ const lastCheckpoint = await this.rollupContract.getPendingCheckpoint();
83
+ const earliestTimestamp = await this.rollupContract.getTimestampForSlot(
84
+ SlotNumber.fromBigInt(BigInt(lastCheckpoint.slotNumber) + 1n),
85
+ );
86
+ const nextEthTimestamp = getNextL1SlotTimestamp(this.dateProvider.nowInSeconds(), {
87
+ l1GenesisTime: this.l1GenesisTime,
88
+ ethereumSlotDuration: this.ethereumSlotDuration,
89
+ });
90
+ const timestamp = earliestTimestamp > nextEthTimestamp ? earliestTimestamp : nextEthTimestamp;
91
+
92
+ return new GasFees(0, await this.rollupContract.getManaMinFeeAt(timestamp, true));
93
+ }
94
+
95
+ public getCurrentMinFees(): Promise<GasFees> {
96
+ return Promise.resolve(this.currentMinFees);
97
+ }
98
+
99
+ public getPredictedMinFees(manaUsage?: ManaUsageEstimate): Promise<GasFees[]> {
100
+ const currentMinFees = this.currentMinFees;
101
+ const predictedMinFees = this.feePredictor.getPredictedMinFees(manaUsage ?? ManaUsageEstimate.Target);
102
+ return Promise.resolve([currentMinFees, ...predictedMinFees]);
103
+ }
104
+ }