@aztec/sequencer-client 0.0.0-test.1 → 0.0.1-commit.03f7ef2

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 (141) hide show
  1. package/dest/client/index.d.ts +1 -1
  2. package/dest/client/sequencer-client.d.ts +30 -29
  3. package/dest/client/sequencer-client.d.ts.map +1 -1
  4. package/dest/client/sequencer-client.js +82 -60
  5. package/dest/config.d.ts +15 -16
  6. package/dest/config.d.ts.map +1 -1
  7. package/dest/config.js +113 -70
  8. package/dest/global_variable_builder/global_builder.d.ts +25 -14
  9. package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
  10. package/dest/global_variable_builder/global_builder.js +60 -42
  11. package/dest/global_variable_builder/index.d.ts +1 -1
  12. package/dest/index.d.ts +2 -3
  13. package/dest/index.d.ts.map +1 -1
  14. package/dest/index.js +1 -2
  15. package/dest/publisher/config.d.ts +15 -12
  16. package/dest/publisher/config.d.ts.map +1 -1
  17. package/dest/publisher/config.js +32 -19
  18. package/dest/publisher/index.d.ts +3 -1
  19. package/dest/publisher/index.d.ts.map +1 -1
  20. package/dest/publisher/index.js +3 -0
  21. package/dest/publisher/sequencer-publisher-factory.d.ts +44 -0
  22. package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -0
  23. package/dest/publisher/sequencer-publisher-factory.js +51 -0
  24. package/dest/publisher/sequencer-publisher-metrics.d.ts +5 -4
  25. package/dest/publisher/sequencer-publisher-metrics.d.ts.map +1 -1
  26. package/dest/publisher/sequencer-publisher-metrics.js +37 -2
  27. package/dest/publisher/sequencer-publisher.d.ts +132 -86
  28. package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
  29. package/dest/publisher/sequencer-publisher.js +755 -248
  30. package/dest/sequencer/block_builder.d.ts +26 -0
  31. package/dest/sequencer/block_builder.d.ts.map +1 -0
  32. package/dest/sequencer/block_builder.js +129 -0
  33. package/dest/sequencer/checkpoint_builder.d.ts +63 -0
  34. package/dest/sequencer/checkpoint_builder.d.ts.map +1 -0
  35. package/dest/sequencer/checkpoint_builder.js +131 -0
  36. package/dest/sequencer/checkpoint_proposal_job.d.ts +74 -0
  37. package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -0
  38. package/dest/sequencer/checkpoint_proposal_job.js +640 -0
  39. package/dest/sequencer/checkpoint_voter.d.ts +34 -0
  40. package/dest/sequencer/checkpoint_voter.d.ts.map +1 -0
  41. package/dest/sequencer/checkpoint_voter.js +85 -0
  42. package/dest/sequencer/config.d.ts +7 -1
  43. package/dest/sequencer/config.d.ts.map +1 -1
  44. package/dest/sequencer/errors.d.ts +11 -0
  45. package/dest/sequencer/errors.d.ts.map +1 -0
  46. package/dest/sequencer/errors.js +15 -0
  47. package/dest/sequencer/events.d.ts +46 -0
  48. package/dest/sequencer/events.d.ts.map +1 -0
  49. package/dest/sequencer/events.js +1 -0
  50. package/dest/sequencer/index.d.ts +6 -2
  51. package/dest/sequencer/index.d.ts.map +1 -1
  52. package/dest/sequencer/index.js +5 -1
  53. package/dest/sequencer/metrics.d.ts +48 -12
  54. package/dest/sequencer/metrics.d.ts.map +1 -1
  55. package/dest/sequencer/metrics.js +274 -48
  56. package/dest/sequencer/sequencer.d.ts +132 -135
  57. package/dest/sequencer/sequencer.d.ts.map +1 -1
  58. package/dest/sequencer/sequencer.js +519 -521
  59. package/dest/sequencer/timetable.d.ts +76 -24
  60. package/dest/sequencer/timetable.d.ts.map +1 -1
  61. package/dest/sequencer/timetable.js +177 -61
  62. package/dest/sequencer/types.d.ts +3 -0
  63. package/dest/sequencer/types.d.ts.map +1 -0
  64. package/dest/sequencer/types.js +1 -0
  65. package/dest/sequencer/utils.d.ts +20 -38
  66. package/dest/sequencer/utils.d.ts.map +1 -1
  67. package/dest/sequencer/utils.js +12 -47
  68. package/dest/test/index.d.ts +10 -1
  69. package/dest/test/index.d.ts.map +1 -1
  70. package/dest/test/index.js +0 -4
  71. package/dest/test/mock_checkpoint_builder.d.ts +83 -0
  72. package/dest/test/mock_checkpoint_builder.d.ts.map +1 -0
  73. package/dest/test/mock_checkpoint_builder.js +179 -0
  74. package/dest/test/utils.d.ts +49 -0
  75. package/dest/test/utils.d.ts.map +1 -0
  76. package/dest/test/utils.js +94 -0
  77. package/dest/tx_validator/nullifier_cache.d.ts +1 -3
  78. package/dest/tx_validator/nullifier_cache.d.ts.map +1 -1
  79. package/dest/tx_validator/tx_validator_factory.d.ts +11 -11
  80. package/dest/tx_validator/tx_validator_factory.d.ts.map +1 -1
  81. package/dest/tx_validator/tx_validator_factory.js +28 -25
  82. package/package.json +45 -45
  83. package/src/client/sequencer-client.ts +105 -105
  84. package/src/config.ts +126 -81
  85. package/src/global_variable_builder/global_builder.ts +82 -53
  86. package/src/index.ts +8 -2
  87. package/src/publisher/config.ts +45 -32
  88. package/src/publisher/index.ts +4 -0
  89. package/src/publisher/sequencer-publisher-factory.ts +92 -0
  90. package/src/publisher/sequencer-publisher-metrics.ts +26 -4
  91. package/src/publisher/sequencer-publisher.ts +955 -293
  92. package/src/sequencer/README.md +531 -0
  93. package/src/sequencer/block_builder.ts +217 -0
  94. package/src/sequencer/checkpoint_builder.ts +217 -0
  95. package/src/sequencer/checkpoint_proposal_job.ts +703 -0
  96. package/src/sequencer/checkpoint_voter.ts +105 -0
  97. package/src/sequencer/config.ts +8 -0
  98. package/src/sequencer/errors.ts +21 -0
  99. package/src/sequencer/events.ts +27 -0
  100. package/src/sequencer/index.ts +5 -1
  101. package/src/sequencer/metrics.ts +355 -50
  102. package/src/sequencer/sequencer.ts +631 -594
  103. package/src/sequencer/timetable.ts +221 -62
  104. package/src/sequencer/types.ts +6 -0
  105. package/src/sequencer/utils.ts +28 -60
  106. package/src/test/index.ts +13 -4
  107. package/src/test/mock_checkpoint_builder.ts +247 -0
  108. package/src/test/utils.ts +137 -0
  109. package/src/tx_validator/tx_validator_factory.ts +46 -33
  110. package/dest/sequencer/allowed.d.ts +0 -3
  111. package/dest/sequencer/allowed.d.ts.map +0 -1
  112. package/dest/sequencer/allowed.js +0 -27
  113. package/dest/slasher/factory.d.ts +0 -7
  114. package/dest/slasher/factory.d.ts.map +0 -1
  115. package/dest/slasher/factory.js +0 -8
  116. package/dest/slasher/index.d.ts +0 -3
  117. package/dest/slasher/index.d.ts.map +0 -1
  118. package/dest/slasher/index.js +0 -2
  119. package/dest/slasher/slasher_client.d.ts +0 -75
  120. package/dest/slasher/slasher_client.d.ts.map +0 -1
  121. package/dest/slasher/slasher_client.js +0 -132
  122. package/dest/tx_validator/archive_cache.d.ts +0 -14
  123. package/dest/tx_validator/archive_cache.d.ts.map +0 -1
  124. package/dest/tx_validator/archive_cache.js +0 -22
  125. package/dest/tx_validator/gas_validator.d.ts +0 -14
  126. package/dest/tx_validator/gas_validator.d.ts.map +0 -1
  127. package/dest/tx_validator/gas_validator.js +0 -78
  128. package/dest/tx_validator/phases_validator.d.ts +0 -12
  129. package/dest/tx_validator/phases_validator.d.ts.map +0 -1
  130. package/dest/tx_validator/phases_validator.js +0 -80
  131. package/dest/tx_validator/test_utils.d.ts +0 -23
  132. package/dest/tx_validator/test_utils.d.ts.map +0 -1
  133. package/dest/tx_validator/test_utils.js +0 -26
  134. package/src/sequencer/allowed.ts +0 -36
  135. package/src/slasher/factory.ts +0 -15
  136. package/src/slasher/index.ts +0 -2
  137. package/src/slasher/slasher_client.ts +0 -193
  138. package/src/tx_validator/archive_cache.ts +0 -28
  139. package/src/tx_validator/gas_validator.ts +0 -101
  140. package/src/tx_validator/phases_validator.ts +0 -98
  141. package/src/tx_validator/test_utils.ts +0 -48
package/src/config.ts CHANGED
@@ -1,9 +1,5 @@
1
- import {
2
- type L1ContractsConfig,
3
- type L1ReaderConfig,
4
- l1ContractsConfigMappings,
5
- l1ReaderConfigMappings,
6
- } from '@aztec/ethereum';
1
+ import { type L1ContractsConfig, l1ContractsConfigMappings } from '@aztec/ethereum/config';
2
+ import { type L1ReaderConfig, l1ReaderConfigMappings } from '@aztec/ethereum/l1-reader';
7
3
  import {
8
4
  type ConfigMappingsType,
9
5
  booleanConfigHelper,
@@ -12,10 +8,12 @@ import {
12
8
  pickConfigMappings,
13
9
  } from '@aztec/foundation/config';
14
10
  import { EthAddress } from '@aztec/foundation/eth-address';
15
- import { Fr } from '@aztec/foundation/fields';
16
- import { FunctionSelector } from '@aztec/stdlib/abi';
11
+ import { type KeyStoreConfig, keyStoreConfigMappings } from '@aztec/node-keystore/config';
12
+ import { type P2PConfig, p2pConfigMappings } from '@aztec/p2p/config';
17
13
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
18
- import { type AllowedElement, type ChainConfig, type SequencerConfig, chainConfigMappings } from '@aztec/stdlib/config';
14
+ import { type ChainConfig, type SequencerConfig, chainConfigMappings } from '@aztec/stdlib/config';
15
+ import type { ResolvedSequencerConfig } from '@aztec/stdlib/interfaces/server';
16
+ import { type ValidatorClientConfig, validatorClientConfigMappings } from '@aztec/validator-client/config';
19
17
 
20
18
  import {
21
19
  type PublisherConfig,
@@ -27,41 +25,80 @@ import {
27
25
  export * from './publisher/config.js';
28
26
  export type { SequencerConfig };
29
27
 
28
+ export const DEFAULT_ATTESTATION_PROPAGATION_TIME = 2;
29
+
30
+ /**
31
+ * Default values for SequencerConfig.
32
+ * Centralized location for all sequencer configuration defaults.
33
+ */
34
+ export const DefaultSequencerConfig: ResolvedSequencerConfig = {
35
+ sequencerPollingIntervalMS: 500,
36
+ maxTxsPerBlock: 32,
37
+ minTxsPerBlock: 1,
38
+ buildCheckpointIfEmpty: false,
39
+ publishTxsWithProposals: false,
40
+ maxL2BlockGas: 10e9,
41
+ maxDABlockGas: 10e9,
42
+ maxBlockSizeInBytes: 1024 * 1024,
43
+ enforceTimeTable: true,
44
+ attestationPropagationTime: DEFAULT_ATTESTATION_PROPAGATION_TIME,
45
+ secondsBeforeInvalidatingBlockAsCommitteeMember: 144, // 12 L1 blocks
46
+ secondsBeforeInvalidatingBlockAsNonCommitteeMember: 432, // 36 L1 blocks
47
+ skipCollectingAttestations: false,
48
+ skipInvalidateBlockAsProposer: false,
49
+ broadcastInvalidBlockProposal: false,
50
+ injectFakeAttestation: false,
51
+ fishermanMode: false,
52
+ shuffleAttestationOrdering: false,
53
+ };
54
+
30
55
  /**
31
56
  * Configuration settings for the SequencerClient.
32
57
  */
33
58
  export type SequencerClientConfig = PublisherConfig &
59
+ KeyStoreConfig &
60
+ ValidatorClientConfig &
34
61
  TxSenderConfig &
35
62
  SequencerConfig &
36
63
  L1ReaderConfig &
37
64
  ChainConfig &
65
+ Pick<P2PConfig, 'txPublicSetupAllowList'> &
38
66
  Pick<L1ContractsConfig, 'ethereumSlotDuration' | 'aztecSlotDuration' | 'aztecEpochDuration'>;
39
67
 
40
68
  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),
69
+ sequencerPollingIntervalMS: {
70
+ env: 'SEQ_POLLING_INTERVAL_MS',
71
+ description: 'The number of ms to wait between polling for checking to build on the next slot.',
72
+ ...numberConfigHelper(DefaultSequencerConfig.sequencerPollingIntervalMS),
45
73
  },
46
74
  maxTxsPerBlock: {
47
75
  env: 'SEQ_MAX_TX_PER_BLOCK',
48
76
  description: 'The maximum number of txs to include in a block.',
49
- ...numberConfigHelper(32),
77
+ ...numberConfigHelper(DefaultSequencerConfig.maxTxsPerBlock),
50
78
  },
51
79
  minTxsPerBlock: {
52
80
  env: 'SEQ_MIN_TX_PER_BLOCK',
53
81
  description: 'The minimum number of txs to include in a block.',
54
- ...numberConfigHelper(1),
82
+ ...numberConfigHelper(DefaultSequencerConfig.minTxsPerBlock),
83
+ },
84
+ minValidTxsPerBlock: {
85
+ description:
86
+ 'The minimum number of valid txs (after execution) to include in a block. If not set, falls back to minTxsPerBlock.',
87
+ },
88
+ publishTxsWithProposals: {
89
+ env: 'SEQ_PUBLISH_TXS_WITH_PROPOSALS',
90
+ description: 'Whether to publish txs with proposals.',
91
+ ...booleanConfigHelper(DefaultSequencerConfig.publishTxsWithProposals),
55
92
  },
56
93
  maxL2BlockGas: {
57
94
  env: 'SEQ_MAX_L2_BLOCK_GAS',
58
95
  description: 'The maximum L2 block gas.',
59
- ...numberConfigHelper(10e9),
96
+ ...numberConfigHelper(DefaultSequencerConfig.maxL2BlockGas),
60
97
  },
61
98
  maxDABlockGas: {
62
99
  env: 'SEQ_MAX_DA_BLOCK_GAS',
63
100
  description: 'The maximum DA block gas.',
64
- ...numberConfigHelper(10e9),
101
+ ...numberConfigHelper(DefaultSequencerConfig.maxDABlockGas),
65
102
  },
66
103
  coinbase: {
67
104
  env: 'COINBASE',
@@ -81,39 +118,97 @@ export const sequencerConfigMappings: ConfigMappingsType<SequencerConfig> = {
81
118
  env: 'ACVM_BINARY_PATH',
82
119
  description: 'The path to the ACVM binary',
83
120
  },
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
121
  maxBlockSizeInBytes: {
92
122
  env: 'SEQ_MAX_BLOCK_SIZE_IN_BYTES',
93
123
  description: 'Max block size',
94
- ...numberConfigHelper(1024 * 1024),
124
+ ...numberConfigHelper(DefaultSequencerConfig.maxBlockSizeInBytes),
95
125
  },
96
126
  enforceTimeTable: {
97
127
  env: 'SEQ_ENFORCE_TIME_TABLE',
98
128
  description: 'Whether to enforce the time table when building blocks',
99
- ...booleanConfigHelper(),
100
- defaultValue: false,
129
+ ...booleanConfigHelper(DefaultSequencerConfig.enforceTimeTable),
101
130
  },
102
131
  governanceProposerPayload: {
103
132
  env: 'GOVERNANCE_PROPOSER_PAYLOAD_ADDRESS',
104
133
  description: 'The address of the payload for the governanceProposer',
105
134
  parseEnv: (val: string) => EthAddress.fromString(val),
106
- defaultValue: EthAddress.ZERO,
107
135
  },
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.',
136
+ l1PublishingTime: {
137
+ env: 'SEQ_L1_PUBLISHING_TIME_ALLOWANCE_IN_SLOT',
138
+ description: 'How much time (in seconds) we allow in the slot for publishing the L1 tx (defaults to 1 L1 slot).',
111
139
  parseEnv: (val: string) => (val ? parseInt(val, 10) : undefined),
112
140
  },
141
+ attestationPropagationTime: {
142
+ env: 'SEQ_ATTESTATION_PROPAGATION_TIME',
143
+ description: 'How many seconds it takes for proposals and attestations to travel across the p2p layer (one-way)',
144
+ ...numberConfigHelper(DefaultSequencerConfig.attestationPropagationTime),
145
+ },
146
+ fakeProcessingDelayPerTxMs: {
147
+ description: 'Used for testing to introduce a fake delay after processing each tx',
148
+ },
149
+ fakeThrowAfterProcessingTxCount: {
150
+ description: 'Used for testing to throw an error after processing N txs',
151
+ },
152
+ secondsBeforeInvalidatingBlockAsCommitteeMember: {
153
+ env: 'SEQ_SECONDS_BEFORE_INVALIDATING_BLOCK_AS_COMMITTEE_MEMBER',
154
+ description:
155
+ 'How many seconds to wait before trying to invalidate a block from the pending chain as a committee member (zero to never invalidate).' +
156
+ ' The next proposer is expected to invalidate, so the committee acts as a fallback.',
157
+ ...numberConfigHelper(DefaultSequencerConfig.secondsBeforeInvalidatingBlockAsCommitteeMember),
158
+ },
159
+ secondsBeforeInvalidatingBlockAsNonCommitteeMember: {
160
+ env: 'SEQ_SECONDS_BEFORE_INVALIDATING_BLOCK_AS_NON_COMMITTEE_MEMBER',
161
+ description:
162
+ 'How many seconds to wait before trying to invalidate a block from the pending chain as a non-committee member (zero to never invalidate).' +
163
+ ' The next proposer is expected to invalidate, then the committee, so other sequencers act as a fallback.',
164
+ ...numberConfigHelper(DefaultSequencerConfig.secondsBeforeInvalidatingBlockAsNonCommitteeMember),
165
+ },
166
+ skipCollectingAttestations: {
167
+ description:
168
+ 'Whether to skip collecting attestations from validators and only use self-attestations (for testing only)',
169
+ ...booleanConfigHelper(DefaultSequencerConfig.skipCollectingAttestations),
170
+ },
171
+ skipInvalidateBlockAsProposer: {
172
+ description: 'Do not invalidate the previous block if invalid when we are the proposer (for testing only)',
173
+ ...booleanConfigHelper(DefaultSequencerConfig.skipInvalidateBlockAsProposer),
174
+ },
175
+ broadcastInvalidBlockProposal: {
176
+ description: 'Broadcast invalid block proposals with corrupted state (for testing only)',
177
+ ...booleanConfigHelper(DefaultSequencerConfig.broadcastInvalidBlockProposal),
178
+ },
179
+ injectFakeAttestation: {
180
+ description: 'Inject a fake attestation (for testing only)',
181
+ ...booleanConfigHelper(DefaultSequencerConfig.injectFakeAttestation),
182
+ },
183
+ fishermanMode: {
184
+ env: 'FISHERMAN_MODE',
185
+ description:
186
+ 'Whether to run in fisherman mode: builds blocks on every slot for validation without publishing to L1',
187
+ ...booleanConfigHelper(DefaultSequencerConfig.fishermanMode),
188
+ },
189
+ shuffleAttestationOrdering: {
190
+ description: 'Shuffle attestation ordering to create invalid ordering (for testing only)',
191
+ ...booleanConfigHelper(DefaultSequencerConfig.shuffleAttestationOrdering),
192
+ },
193
+ blockDurationMs: {
194
+ env: 'SEQ_BLOCK_DURATION_MS',
195
+ description:
196
+ 'Duration per block in milliseconds when building multiple blocks per slot. ' +
197
+ 'If undefined (default), builds a single block per slot using the full slot duration.',
198
+ parseEnv: (val: string) => (val ? parseInt(val, 10) : undefined),
199
+ },
200
+ buildCheckpointIfEmpty: {
201
+ env: 'SEQ_BUILD_CHECKPOINT_IF_EMPTY',
202
+ description: 'Have sequencer build and publish an empty checkpoint if there are no txs',
203
+ ...booleanConfigHelper(DefaultSequencerConfig.buildCheckpointIfEmpty),
204
+ },
205
+ ...pickConfigMappings(p2pConfigMappings, ['txPublicSetupAllowList']),
113
206
  };
114
207
 
115
208
  export const sequencerClientConfigMappings: ConfigMappingsType<SequencerClientConfig> = {
209
+ ...validatorClientConfigMappings,
116
210
  ...sequencerConfigMappings,
211
+ ...keyStoreConfigMappings,
117
212
  ...l1ReaderConfigMappings,
118
213
  ...getTxSenderConfigMappings('SEQ'),
119
214
  ...getPublisherConfigMappings('SEQ'),
@@ -127,53 +222,3 @@ export const sequencerClientConfigMappings: ConfigMappingsType<SequencerClientCo
127
222
  export function getConfigEnvVars(): SequencerClientConfig {
128
223
  return getConfigFromMappings<SequencerClientConfig>(sequencerClientConfigMappings);
129
224
  }
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,98 @@
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 type { L1ContractsConfig } from '@aztec/ethereum/config';
3
+ import { RollupContract } from '@aztec/ethereum/contracts';
4
+ import type { L1ReaderConfig } from '@aztec/ethereum/l1-reader';
5
+ import type { ViemPublicClient } from '@aztec/ethereum/types';
6
+ import { BlockNumber, SlotNumber } from '@aztec/foundation/branded-types';
7
+ import { Fr } from '@aztec/foundation/curves/bn254';
7
8
  import type { EthAddress } from '@aztec/foundation/eth-address';
8
- import { Fr } from '@aztec/foundation/fields';
9
9
  import { createLogger } from '@aztec/foundation/log';
10
- import { RollupAbi } from '@aztec/l1-artifacts';
11
10
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
11
+ import { type L1RollupConstants, getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
12
12
  import { GasFees } from '@aztec/stdlib/gas';
13
- import type { GlobalVariableBuilder as GlobalVariableBuilderInterface } from '@aztec/stdlib/tx';
13
+ import type {
14
+ CheckpointGlobalVariables,
15
+ GlobalVariableBuilder as GlobalVariableBuilderInterface,
16
+ } from '@aztec/stdlib/tx';
14
17
  import { GlobalVariables } from '@aztec/stdlib/tx';
15
18
 
16
- import { type GetContractReturnType, createPublicClient, fallback, getAddress, getContract, http } from 'viem';
19
+ import { createPublicClient, fallback, http } from 'viem';
17
20
 
18
21
  /**
19
22
  * Simple global variables builder.
20
23
  */
21
24
  export class GlobalVariableBuilder implements GlobalVariableBuilderInterface {
22
25
  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'>) {
26
+ private currentBaseFees: Promise<GasFees> = Promise.resolve(new GasFees(0, 0));
27
+ private currentL1BlockNumber: bigint | undefined = undefined;
28
+
29
+ private readonly rollupContract: RollupContract;
30
+ private readonly publicClient: ViemPublicClient;
31
+ private readonly ethereumSlotDuration: number;
32
+ private readonly aztecSlotDuration: number;
33
+ private readonly l1GenesisTime: bigint;
34
+
35
+ private chainId: Fr;
36
+ private version: Fr;
37
+
38
+ constructor(
39
+ config: L1ReaderConfig &
40
+ Pick<L1ContractsConfig, 'ethereumSlotDuration'> &
41
+ Pick<L1RollupConstants, 'slotDuration' | 'l1GenesisTime'> & { rollupVersion: bigint },
42
+ ) {
29
43
  const { l1RpcUrls, l1ChainId: chainId, l1Contracts } = config;
30
44
 
31
45
  const chain = createEthereumChain(l1RpcUrls, chainId);
32
46
 
47
+ this.version = new Fr(config.rollupVersion);
48
+ this.chainId = new Fr(chainId);
49
+
33
50
  this.ethereumSlotDuration = config.ethereumSlotDuration;
51
+ this.aztecSlotDuration = config.slotDuration;
52
+ this.l1GenesisTime = config.l1GenesisTime;
34
53
 
35
54
  this.publicClient = createPublicClient({
36
55
  chain: chain.chainInfo,
37
- transport: fallback(chain.rpcUrls.map(url => http(url))),
56
+ transport: fallback(chain.rpcUrls.map(url => http(url, { batch: false }))),
38
57
  pollingInterval: config.viemPollingIntervalMS,
39
58
  });
40
59
 
41
- this.rollupContract = getContract({
42
- address: getAddress(l1Contracts.rollupAddress.toString()),
43
- abi: RollupAbi,
44
- client: this.publicClient,
45
- });
60
+ this.rollupContract = new RollupContract(this.publicClient, l1Contracts.rollupAddress);
46
61
  }
47
62
 
48
63
  /**
49
64
  * 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
+ * @returns Base fees for the next block
51
66
  */
52
- public async getCurrentBaseFees(): Promise<GasFees> {
67
+ private async computeCurrentBaseFees(): Promise<GasFees> {
53
68
  // Since this might be called in the middle of a slot where a block might have been published,
54
69
  // we need to fetch the last block written, and estimate the earliest timestamp for the next block.
55
70
  // The timestamp of that last block will act as a lower bound for the next block.
56
71
 
57
- const lastBlock = await this.rollupContract.read.getBlock([await this.rollupContract.read.getPendingBlockNumber()]);
58
- const earliestTimestamp = await this.rollupContract.read.getTimestampForSlot([lastBlock.slotNumber + 1n]);
72
+ const lastBlock = await this.rollupContract.getPendingCheckpoint();
73
+ const earliestTimestamp = await this.rollupContract.getTimestampForSlot(
74
+ SlotNumber.fromBigInt(lastBlock.slotNumber + 1n),
75
+ );
59
76
  const nextEthTimestamp = BigInt((await this.publicClient.getBlock()).timestamp + BigInt(this.ethereumSlotDuration));
60
77
  const timestamp = earliestTimestamp > nextEthTimestamp ? earliestTimestamp : nextEthTimestamp;
61
78
 
62
- return new GasFees(Fr.ZERO, new Fr(await this.rollupContract.read.getManaBaseFeeAt([timestamp, true])));
79
+ return new GasFees(0, await this.rollupContract.getManaBaseFeeAt(timestamp, true));
80
+ }
81
+
82
+ public async getCurrentBaseFees(): Promise<GasFees> {
83
+ // Get the current block number
84
+ const blockNumber = await this.publicClient.getBlockNumber();
85
+
86
+ // If the L1 block number has changed then chain a new promise to get the current base fees
87
+ if (this.currentL1BlockNumber === undefined || blockNumber > this.currentL1BlockNumber) {
88
+ this.currentL1BlockNumber = blockNumber;
89
+ this.currentBaseFees = this.currentBaseFees.then(() => this.computeCurrentBaseFees());
90
+ }
91
+ return this.currentBaseFees;
63
92
  }
64
93
 
65
94
  /**
66
- * Simple builder of global variables that use the minimum time possible.
95
+ * Simple builder of global variables.
67
96
  * @param blockNumber - The block number to build global variables for.
68
97
  * @param coinbase - The address to receive block reward.
69
98
  * @param feeRecipient - The address to receive fees.
@@ -71,38 +100,38 @@ export class GlobalVariableBuilder implements GlobalVariableBuilderInterface {
71
100
  * @returns The global variables for the given block number.
72
101
  */
73
102
  public async buildGlobalVariables(
74
- blockNumber: Fr,
103
+ blockNumber: BlockNumber,
75
104
  coinbase: EthAddress,
76
105
  feeRecipient: AztecAddress,
77
- slotNumber?: bigint,
106
+ maybeSlot?: SlotNumber,
78
107
  ): 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
- }
108
+ const slot: SlotNumber =
109
+ maybeSlot ??
110
+ (await this.rollupContract.getSlotAt(
111
+ BigInt((await this.publicClient.getBlock()).timestamp + BigInt(this.ethereumSlotDuration)),
112
+ ));
113
+
114
+ const checkpointGlobalVariables = await this.buildCheckpointGlobalVariables(coinbase, feeRecipient, slot);
115
+ return GlobalVariables.from({ blockNumber, ...checkpointGlobalVariables });
116
+ }
86
117
 
87
- const timestamp = await this.rollupContract.read.getTimestampForSlot([slotNumber]);
118
+ /** Builds global variables that are constant throughout a checkpoint. */
119
+ public async buildCheckpointGlobalVariables(
120
+ coinbase: EthAddress,
121
+ feeRecipient: AztecAddress,
122
+ slotNumber: SlotNumber,
123
+ ): Promise<CheckpointGlobalVariables & { timestamp: bigint }> {
124
+ const { chainId, version } = this;
88
125
 
89
- const slotFr = new Fr(slotNumber);
90
- const timestampFr = new Fr(timestamp);
126
+ const timestamp = getTimestampForSlot(slotNumber, {
127
+ slotDuration: this.aztecSlotDuration,
128
+ l1GenesisTime: this.l1GenesisTime,
129
+ });
91
130
 
92
131
  // 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])));
94
-
95
- const globalVariables = new GlobalVariables(
96
- chainId,
97
- version,
98
- blockNumber,
99
- slotFr,
100
- timestampFr,
101
- coinbase,
102
- feeRecipient,
103
- gasFees,
104
- );
132
+ // TODO(palla/mbps): Can we use a cached value here?
133
+ const gasFees = new GasFees(0, await this.rollupContract.getManaBaseFeeAt(timestamp, true));
105
134
 
106
- return globalVariables;
135
+ return { chainId, version, slotNumber, timestamp, coinbase, feeRecipient, gasFees };
107
136
  }
108
137
  }
package/src/index.ts CHANGED
@@ -1,9 +1,15 @@
1
1
  export * from './client/index.js';
2
2
  export * from './config.js';
3
3
  export * from './publisher/index.js';
4
+ export {
5
+ FullNodeBlockBuilder as BlockBuilder,
6
+ FullNodeCheckpointsBuilder as CheckpointsBuilder,
7
+ CheckpointBuilder,
8
+ Sequencer,
9
+ SequencerState,
10
+ type SequencerEvents,
11
+ } from './sequencer/index.js';
4
12
  export * from './tx_validator/tx_validator_factory.js';
5
- export * from './slasher/index.js';
6
- export { Sequencer, SequencerState, getDefaultAllowedSetupFunctions } from './sequencer/index.js';
7
13
 
8
14
  // Used by the node to simulate public parts of transactions. Should these be moved to a shared library?
9
15
  // ISSUE(#9832)
@@ -1,12 +1,12 @@
1
- import { type BlobSinkConfig, blobSinkConfigMapping } from '@aztec/blob-sink/client';
1
+ import { type BlobClientConfig, blobClientConfigMapping } from '@aztec/blob-client/client/config';
2
+ import { type L1ReaderConfig, l1ReaderConfigMappings } from '@aztec/ethereum/l1-reader';
3
+ import { type L1TxUtilsConfig, l1TxUtilsConfigMappings } from '@aztec/ethereum/l1-tx-utils/config';
2
4
  import {
3
- type L1ReaderConfig,
4
- type L1TxUtilsConfig,
5
- NULL_KEY,
6
- l1ReaderConfigMappings,
7
- l1TxUtilsConfigMappings,
8
- } from '@aztec/ethereum';
9
- import { type ConfigMappingsType, getConfigFromMappings } from '@aztec/foundation/config';
5
+ type ConfigMappingsType,
6
+ SecretValue,
7
+ booleanConfigHelper,
8
+ getConfigFromMappings,
9
+ } from '@aztec/foundation/config';
10
10
  import { EthAddress } from '@aztec/foundation/eth-address';
11
11
 
12
12
  /**
@@ -16,40 +16,43 @@ export type TxSenderConfig = L1ReaderConfig & {
16
16
  /**
17
17
  * The private key to be used by the publisher.
18
18
  */
19
- publisherPrivateKey: `0x${string}`;
19
+ publisherPrivateKeys?: SecretValue<`0x${string}`>[];
20
20
 
21
21
  /**
22
- * The address of the custom forwarder contract.
22
+ * Publisher addresses to be used with a remote signer
23
23
  */
24
- customForwarderContractAddress: EthAddress;
24
+ publisherAddresses?: EthAddress[];
25
25
  };
26
26
 
27
27
  /**
28
28
  * Configuration of the L1Publisher.
29
29
  */
30
30
  export type PublisherConfig = L1TxUtilsConfig &
31
- BlobSinkConfig & {
32
- /**
33
- * The interval to wait between publish retries.
34
- */
35
- l1PublishRetryIntervalMS: number;
31
+ BlobClientConfig & {
32
+ /** True to use publishers in invalid states (timed out, cancelled, etc) if no other is available */
33
+ publisherAllowInvalidStates?: boolean;
34
+ /** Whether to run in fisherman mode: builds blocks on every slot for validation without publishing to L1 */
35
+ fishermanMode?: boolean;
36
+ /** Address of the forwarder contract to wrap all L1 transactions through (for testing purposes only) */
37
+ publisherForwarderAddress?: EthAddress;
36
38
  };
37
39
 
38
40
  export const getTxSenderConfigMappings: (
39
41
  scope: 'PROVER' | 'SEQ',
40
42
  ) => ConfigMappingsType<Omit<TxSenderConfig, 'l1Contracts'>> = (scope: 'PROVER' | 'SEQ') => ({
41
43
  ...l1ReaderConfigMappings,
42
- customForwarderContractAddress: {
43
- env: `CUSTOM_FORWARDER_CONTRACT_ADDRESS`,
44
- parseEnv: (val: string) => EthAddress.fromString(val),
45
- description: 'The address of the custom forwarder contract.',
46
- defaultValue: EthAddress.ZERO,
44
+ publisherPrivateKeys: {
45
+ env: scope === 'PROVER' ? `PROVER_PUBLISHER_PRIVATE_KEYS` : `SEQ_PUBLISHER_PRIVATE_KEYS`,
46
+ description: 'The private keys to be used by the publisher.',
47
+ parseEnv: (val: string) => val.split(',').map(key => new SecretValue(`0x${key.replace('0x', '')}`)),
48
+ defaultValue: [],
49
+ fallback: [scope === 'PROVER' ? `PROVER_PUBLISHER_PRIVATE_KEY` : `SEQ_PUBLISHER_PRIVATE_KEY`],
47
50
  },
48
- publisherPrivateKey: {
49
- env: scope === 'PROVER' ? `PROVER_PUBLISHER_PRIVATE_KEY` : `SEQ_PUBLISHER_PRIVATE_KEY`,
50
- description: 'The private key to be used by the publisher.',
51
- parseEnv: (val: string) => (val ? `0x${val.replace('0x', '')}` : NULL_KEY),
52
- defaultValue: NULL_KEY,
51
+ publisherAddresses: {
52
+ env: scope === 'PROVER' ? `PROVER_PUBLISHER_ADDRESSES` : `SEQ_PUBLISHER_ADDRESSES`,
53
+ description: 'The addresses of the publishers to use with remote signers',
54
+ parseEnv: (val: string) => val.split(',').map(address => EthAddress.fromString(address)),
55
+ defaultValue: [],
53
56
  },
54
57
  });
55
58
 
@@ -60,14 +63,24 @@ export function getTxSenderConfigFromEnv(scope: 'PROVER' | 'SEQ'): Omit<TxSender
60
63
  export const getPublisherConfigMappings: (
61
64
  scope: 'PROVER' | 'SEQ',
62
65
  ) => ConfigMappingsType<PublisherConfig & L1TxUtilsConfig> = scope => ({
63
- l1PublishRetryIntervalMS: {
64
- env: scope === `PROVER` ? `PROVER_PUBLISH_RETRY_INTERVAL_MS` : `SEQ_PUBLISH_RETRY_INTERVAL_MS`,
65
- parseEnv: (val: string) => +val,
66
- defaultValue: 1000,
67
- description: 'The interval to wait between publish retries.',
66
+ publisherAllowInvalidStates: {
67
+ description: 'True to use publishers in invalid states (timed out, cancelled, etc) if no other is available',
68
+ env: scope === `PROVER` ? `PROVER_PUBLISHER_ALLOW_INVALID_STATES` : `SEQ_PUBLISHER_ALLOW_INVALID_STATES`,
69
+ ...booleanConfigHelper(true),
70
+ },
71
+ fishermanMode: {
72
+ env: 'FISHERMAN_MODE',
73
+ description:
74
+ 'Whether to run in fisherman mode: builds blocks on every slot for validation without publishing to L1',
75
+ ...booleanConfigHelper(false),
76
+ },
77
+ publisherForwarderAddress: {
78
+ env: scope === `PROVER` ? `PROVER_PUBLISHER_FORWARDER_ADDRESS` : `SEQ_PUBLISHER_FORWARDER_ADDRESS`,
79
+ description: 'Address of the forwarder contract to wrap all L1 transactions through (for testing purposes only)',
80
+ parseEnv: (val: string) => (val ? EthAddress.fromString(val) : undefined),
68
81
  },
69
82
  ...l1TxUtilsConfigMappings,
70
- ...blobSinkConfigMapping,
83
+ ...blobClientConfigMapping,
71
84
  });
72
85
 
73
86
  export function getPublisherConfigFromEnv(scope: 'PROVER' | 'SEQ'): PublisherConfig {
@@ -1 +1,5 @@
1
1
  export { SequencerPublisher } from './sequencer-publisher.js';
2
+ export { SequencerPublisherFactory } from './sequencer-publisher-factory.js';
3
+
4
+ // Used for tests
5
+ export { SequencerPublisherMetrics } from './sequencer-publisher-metrics.js';