@aztec/sequencer-client 0.0.1-commit.b655e406 → 0.0.1-commit.d1f2d6c

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 (101) hide show
  1. package/dest/client/index.d.ts +1 -1
  2. package/dest/client/sequencer-client.d.ts +12 -12
  3. package/dest/client/sequencer-client.d.ts.map +1 -1
  4. package/dest/client/sequencer-client.js +32 -24
  5. package/dest/config.d.ts +12 -5
  6. package/dest/config.d.ts.map +1 -1
  7. package/dest/config.js +80 -28
  8. package/dest/global_variable_builder/global_builder.d.ts +22 -16
  9. package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
  10. package/dest/global_variable_builder/global_builder.js +52 -39
  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 +9 -4
  16. package/dest/publisher/config.d.ts.map +1 -1
  17. package/dest/publisher/config.js +14 -3
  18. package/dest/publisher/index.d.ts +1 -1
  19. package/dest/publisher/sequencer-publisher-factory.d.ts +5 -4
  20. package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -1
  21. package/dest/publisher/sequencer-publisher-factory.js +1 -1
  22. package/dest/publisher/sequencer-publisher-metrics.d.ts +3 -3
  23. package/dest/publisher/sequencer-publisher-metrics.d.ts.map +1 -1
  24. package/dest/publisher/sequencer-publisher-metrics.js +15 -86
  25. package/dest/publisher/sequencer-publisher.d.ts +75 -61
  26. package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
  27. package/dest/publisher/sequencer-publisher.js +661 -158
  28. package/dest/sequencer/checkpoint_proposal_job.d.ts +79 -0
  29. package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -0
  30. package/dest/sequencer/checkpoint_proposal_job.js +1164 -0
  31. package/dest/sequencer/checkpoint_voter.d.ts +35 -0
  32. package/dest/sequencer/checkpoint_voter.d.ts.map +1 -0
  33. package/dest/sequencer/checkpoint_voter.js +109 -0
  34. package/dest/sequencer/config.d.ts +3 -2
  35. package/dest/sequencer/config.d.ts.map +1 -1
  36. package/dest/sequencer/errors.d.ts +1 -1
  37. package/dest/sequencer/errors.d.ts.map +1 -1
  38. package/dest/sequencer/events.d.ts +46 -0
  39. package/dest/sequencer/events.d.ts.map +1 -0
  40. package/dest/sequencer/events.js +1 -0
  41. package/dest/sequencer/index.d.ts +4 -2
  42. package/dest/sequencer/index.d.ts.map +1 -1
  43. package/dest/sequencer/index.js +3 -1
  44. package/dest/sequencer/metrics.d.ts +32 -3
  45. package/dest/sequencer/metrics.d.ts.map +1 -1
  46. package/dest/sequencer/metrics.js +147 -46
  47. package/dest/sequencer/sequencer.d.ts +110 -142
  48. package/dest/sequencer/sequencer.d.ts.map +1 -1
  49. package/dest/sequencer/sequencer.js +716 -504
  50. package/dest/sequencer/timetable.d.ts +54 -14
  51. package/dest/sequencer/timetable.d.ts.map +1 -1
  52. package/dest/sequencer/timetable.js +148 -59
  53. package/dest/sequencer/types.d.ts +3 -0
  54. package/dest/sequencer/types.d.ts.map +1 -0
  55. package/dest/sequencer/types.js +1 -0
  56. package/dest/sequencer/utils.d.ts +14 -8
  57. package/dest/sequencer/utils.d.ts.map +1 -1
  58. package/dest/sequencer/utils.js +7 -4
  59. package/dest/test/index.d.ts +4 -3
  60. package/dest/test/index.d.ts.map +1 -1
  61. package/dest/test/mock_checkpoint_builder.d.ts +92 -0
  62. package/dest/test/mock_checkpoint_builder.d.ts.map +1 -0
  63. package/dest/test/mock_checkpoint_builder.js +208 -0
  64. package/dest/test/utils.d.ts +53 -0
  65. package/dest/test/utils.d.ts.map +1 -0
  66. package/dest/test/utils.js +103 -0
  67. package/package.json +33 -30
  68. package/src/client/sequencer-client.ts +30 -41
  69. package/src/config.ts +86 -32
  70. package/src/global_variable_builder/global_builder.ts +67 -59
  71. package/src/index.ts +1 -7
  72. package/src/publisher/config.ts +20 -9
  73. package/src/publisher/sequencer-publisher-factory.ts +7 -5
  74. package/src/publisher/sequencer-publisher-metrics.ts +16 -72
  75. package/src/publisher/sequencer-publisher.ts +381 -203
  76. package/src/sequencer/README.md +531 -0
  77. package/src/sequencer/checkpoint_proposal_job.ts +843 -0
  78. package/src/sequencer/checkpoint_voter.ts +130 -0
  79. package/src/sequencer/config.ts +2 -1
  80. package/src/sequencer/events.ts +27 -0
  81. package/src/sequencer/index.ts +3 -1
  82. package/src/sequencer/metrics.ts +198 -55
  83. package/src/sequencer/sequencer.ts +465 -696
  84. package/src/sequencer/timetable.ts +173 -79
  85. package/src/sequencer/types.ts +6 -0
  86. package/src/sequencer/utils.ts +18 -9
  87. package/src/test/index.ts +3 -2
  88. package/src/test/mock_checkpoint_builder.ts +295 -0
  89. package/src/test/utils.ts +164 -0
  90. package/dest/sequencer/block_builder.d.ts +0 -27
  91. package/dest/sequencer/block_builder.d.ts.map +0 -1
  92. package/dest/sequencer/block_builder.js +0 -130
  93. package/dest/tx_validator/nullifier_cache.d.ts +0 -14
  94. package/dest/tx_validator/nullifier_cache.d.ts.map +0 -1
  95. package/dest/tx_validator/nullifier_cache.js +0 -24
  96. package/dest/tx_validator/tx_validator_factory.d.ts +0 -17
  97. package/dest/tx_validator/tx_validator_factory.d.ts.map +0 -1
  98. package/dest/tx_validator/tx_validator_factory.js +0 -53
  99. package/src/sequencer/block_builder.ts +0 -218
  100. package/src/tx_validator/nullifier_cache.ts +0 -30
  101. package/src/tx_validator/tx_validator_factory.ts +0 -132
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,11 +8,12 @@ import {
12
8
  pickConfigMappings,
13
9
  } from '@aztec/foundation/config';
14
10
  import { EthAddress } from '@aztec/foundation/eth-address';
15
- import { type KeyStoreConfig, keyStoreConfigMappings } from '@aztec/node-keystore';
16
- import { type P2PConfig, p2pConfigMappings } from '@aztec/p2p';
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
14
  import { type ChainConfig, type SequencerConfig, chainConfigMappings } from '@aztec/stdlib/config';
19
- import { type ValidatorClientConfig, validatorClientConfigMappings } from '@aztec/validator-client';
15
+ import type { ResolvedSequencerConfig } from '@aztec/stdlib/interfaces/server';
16
+ import { type ValidatorClientConfig, validatorClientConfigMappings } from '@aztec/validator-client/config';
20
17
 
21
18
  import {
22
19
  type PublisherConfig,
@@ -30,6 +27,32 @@ export type { SequencerConfig };
30
27
 
31
28
  export const DEFAULT_ATTESTATION_PROPAGATION_TIME = 2;
32
29
 
30
+ /**
31
+ * Default values for SequencerConfig.
32
+ * Centralized location for all sequencer configuration defaults.
33
+ */
34
+ export const DefaultSequencerConfig: ResolvedSequencerConfig = {
35
+ sequencerPollingIntervalMS: 500,
36
+ maxTxsPerBlock: 32,
37
+ minTxsPerBlock: 1,
38
+ buildCheckpointIfEmpty: false,
39
+ publishTxsWithProposals: false,
40
+ maxL2BlockGas: 10e9,
41
+ maxDABlockGas: 10e9,
42
+ maxBlockSizeInBytes: 1024 * 1024,
43
+ enforceTimeTable: true,
44
+ attestationPropagationTime: DEFAULT_ATTESTATION_PROPAGATION_TIME,
45
+ secondsBeforeInvalidatingBlockAsCommitteeMember: 144, // 12 L1 blocks
46
+ secondsBeforeInvalidatingBlockAsNonCommitteeMember: 432, // 36 L1 blocks
47
+ skipCollectingAttestations: false,
48
+ skipInvalidateBlockAsProposer: false,
49
+ broadcastInvalidBlockProposal: false,
50
+ injectFakeAttestation: false,
51
+ fishermanMode: false,
52
+ shuffleAttestationOrdering: false,
53
+ skipPushProposedBlocksToArchiver: false,
54
+ };
55
+
33
56
  /**
34
57
  * Configuration settings for the SequencerClient.
35
58
  */
@@ -44,35 +67,39 @@ export type SequencerClientConfig = PublisherConfig &
44
67
  Pick<L1ContractsConfig, 'ethereumSlotDuration' | 'aztecSlotDuration' | 'aztecEpochDuration'>;
45
68
 
46
69
  export const sequencerConfigMappings: ConfigMappingsType<SequencerConfig> = {
47
- transactionPollingIntervalMS: {
48
- env: 'SEQ_TX_POLLING_INTERVAL_MS',
49
- description: 'The number of ms to wait between polling for pending txs.',
50
- ...numberConfigHelper(500),
70
+ sequencerPollingIntervalMS: {
71
+ env: 'SEQ_POLLING_INTERVAL_MS',
72
+ description: 'The number of ms to wait between polling for checking to build on the next slot.',
73
+ ...numberConfigHelper(DefaultSequencerConfig.sequencerPollingIntervalMS),
51
74
  },
52
75
  maxTxsPerBlock: {
53
76
  env: 'SEQ_MAX_TX_PER_BLOCK',
54
77
  description: 'The maximum number of txs to include in a block.',
55
- ...numberConfigHelper(32),
78
+ ...numberConfigHelper(DefaultSequencerConfig.maxTxsPerBlock),
56
79
  },
57
80
  minTxsPerBlock: {
58
81
  env: 'SEQ_MIN_TX_PER_BLOCK',
59
82
  description: 'The minimum number of txs to include in a block.',
60
- ...numberConfigHelper(1),
83
+ ...numberConfigHelper(DefaultSequencerConfig.minTxsPerBlock),
84
+ },
85
+ minValidTxsPerBlock: {
86
+ description:
87
+ 'The minimum number of valid txs (after execution) to include in a block. If not set, falls back to minTxsPerBlock.',
61
88
  },
62
89
  publishTxsWithProposals: {
63
90
  env: 'SEQ_PUBLISH_TXS_WITH_PROPOSALS',
64
91
  description: 'Whether to publish txs with proposals.',
65
- ...booleanConfigHelper(false),
92
+ ...booleanConfigHelper(DefaultSequencerConfig.publishTxsWithProposals),
66
93
  },
67
94
  maxL2BlockGas: {
68
95
  env: 'SEQ_MAX_L2_BLOCK_GAS',
69
96
  description: 'The maximum L2 block gas.',
70
- ...numberConfigHelper(10e9),
97
+ ...numberConfigHelper(DefaultSequencerConfig.maxL2BlockGas),
71
98
  },
72
99
  maxDABlockGas: {
73
100
  env: 'SEQ_MAX_DA_BLOCK_GAS',
74
101
  description: 'The maximum DA block gas.',
75
- ...numberConfigHelper(10e9),
102
+ ...numberConfigHelper(DefaultSequencerConfig.maxDABlockGas),
76
103
  },
77
104
  coinbase: {
78
105
  env: 'COINBASE',
@@ -95,63 +122,90 @@ export const sequencerConfigMappings: ConfigMappingsType<SequencerConfig> = {
95
122
  maxBlockSizeInBytes: {
96
123
  env: 'SEQ_MAX_BLOCK_SIZE_IN_BYTES',
97
124
  description: 'Max block size',
98
- ...numberConfigHelper(1024 * 1024),
125
+ ...numberConfigHelper(DefaultSequencerConfig.maxBlockSizeInBytes),
99
126
  },
100
127
  enforceTimeTable: {
101
128
  env: 'SEQ_ENFORCE_TIME_TABLE',
102
129
  description: 'Whether to enforce the time table when building blocks',
103
- ...booleanConfigHelper(),
104
- defaultValue: true,
130
+ ...booleanConfigHelper(DefaultSequencerConfig.enforceTimeTable),
105
131
  },
106
132
  governanceProposerPayload: {
107
133
  env: 'GOVERNANCE_PROPOSER_PAYLOAD_ADDRESS',
108
134
  description: 'The address of the payload for the governanceProposer',
109
135
  parseEnv: (val: string) => EthAddress.fromString(val),
110
- defaultValue: EthAddress.ZERO,
111
136
  },
112
- maxL1TxInclusionTimeIntoSlot: {
113
- env: 'SEQ_MAX_L1_TX_INCLUSION_TIME_INTO_SLOT',
114
- description: 'How many seconds into an L1 slot we can still send a tx and get it mined.',
137
+ l1PublishingTime: {
138
+ env: 'SEQ_L1_PUBLISHING_TIME_ALLOWANCE_IN_SLOT',
139
+ description: 'How much time (in seconds) we allow in the slot for publishing the L1 tx (defaults to 1 L1 slot).',
115
140
  parseEnv: (val: string) => (val ? parseInt(val, 10) : undefined),
116
141
  },
117
142
  attestationPropagationTime: {
118
143
  env: 'SEQ_ATTESTATION_PROPAGATION_TIME',
119
144
  description: 'How many seconds it takes for proposals and attestations to travel across the p2p layer (one-way)',
120
- ...numberConfigHelper(DEFAULT_ATTESTATION_PROPAGATION_TIME),
145
+ ...numberConfigHelper(DefaultSequencerConfig.attestationPropagationTime),
121
146
  },
122
147
  fakeProcessingDelayPerTxMs: {
123
148
  description: 'Used for testing to introduce a fake delay after processing each tx',
124
149
  },
150
+ fakeThrowAfterProcessingTxCount: {
151
+ description: 'Used for testing to throw an error after processing N txs',
152
+ },
125
153
  secondsBeforeInvalidatingBlockAsCommitteeMember: {
126
154
  env: 'SEQ_SECONDS_BEFORE_INVALIDATING_BLOCK_AS_COMMITTEE_MEMBER',
127
155
  description:
128
156
  'How many seconds to wait before trying to invalidate a block from the pending chain as a committee member (zero to never invalidate).' +
129
157
  ' The next proposer is expected to invalidate, so the committee acts as a fallback.',
130
- ...numberConfigHelper(144), // 12 L1 blocks
158
+ ...numberConfigHelper(DefaultSequencerConfig.secondsBeforeInvalidatingBlockAsCommitteeMember),
131
159
  },
132
160
  secondsBeforeInvalidatingBlockAsNonCommitteeMember: {
133
161
  env: 'SEQ_SECONDS_BEFORE_INVALIDATING_BLOCK_AS_NON_COMMITTEE_MEMBER',
134
162
  description:
135
163
  'How many seconds to wait before trying to invalidate a block from the pending chain as a non-committee member (zero to never invalidate).' +
136
164
  ' The next proposer is expected to invalidate, then the committee, so other sequencers act as a fallback.',
137
- ...numberConfigHelper(432), // 36 L1 blocks
165
+ ...numberConfigHelper(DefaultSequencerConfig.secondsBeforeInvalidatingBlockAsNonCommitteeMember),
138
166
  },
139
167
  skipCollectingAttestations: {
140
168
  description:
141
169
  'Whether to skip collecting attestations from validators and only use self-attestations (for testing only)',
142
- ...booleanConfigHelper(false),
170
+ ...booleanConfigHelper(DefaultSequencerConfig.skipCollectingAttestations),
143
171
  },
144
172
  skipInvalidateBlockAsProposer: {
145
173
  description: 'Do not invalidate the previous block if invalid when we are the proposer (for testing only)',
146
- ...booleanConfigHelper(false),
174
+ ...booleanConfigHelper(DefaultSequencerConfig.skipInvalidateBlockAsProposer),
147
175
  },
148
176
  broadcastInvalidBlockProposal: {
149
177
  description: 'Broadcast invalid block proposals with corrupted state (for testing only)',
150
- ...booleanConfigHelper(false),
178
+ ...booleanConfigHelper(DefaultSequencerConfig.broadcastInvalidBlockProposal),
151
179
  },
152
180
  injectFakeAttestation: {
153
181
  description: 'Inject a fake attestation (for testing only)',
154
- ...booleanConfigHelper(false),
182
+ ...booleanConfigHelper(DefaultSequencerConfig.injectFakeAttestation),
183
+ },
184
+ fishermanMode: {
185
+ env: 'FISHERMAN_MODE',
186
+ description:
187
+ 'Whether to run in fisherman mode: builds blocks on every slot for validation without publishing to L1',
188
+ ...booleanConfigHelper(DefaultSequencerConfig.fishermanMode),
189
+ },
190
+ shuffleAttestationOrdering: {
191
+ description: 'Shuffle attestation ordering to create invalid ordering (for testing only)',
192
+ ...booleanConfigHelper(DefaultSequencerConfig.shuffleAttestationOrdering),
193
+ },
194
+ blockDurationMs: {
195
+ env: 'SEQ_BLOCK_DURATION_MS',
196
+ description:
197
+ 'Duration per block in milliseconds when building multiple blocks per slot. ' +
198
+ 'If undefined (default), builds a single block per slot using the full slot duration.',
199
+ parseEnv: (val: string) => (val ? parseInt(val, 10) : undefined),
200
+ },
201
+ buildCheckpointIfEmpty: {
202
+ env: 'SEQ_BUILD_CHECKPOINT_IF_EMPTY',
203
+ description: 'Have sequencer build and publish an empty checkpoint if there are no txs',
204
+ ...booleanConfigHelper(DefaultSequencerConfig.buildCheckpointIfEmpty),
205
+ },
206
+ skipPushProposedBlocksToArchiver: {
207
+ description: 'Skip pushing proposed blocks to archiver (default: true)',
208
+ ...booleanConfigHelper(DefaultSequencerConfig.skipPushProposedBlocksToArchiver),
155
209
  },
156
210
  ...pickConfigMappings(p2pConfigMappings, ['txPublicSetupAllowList']),
157
211
  };
@@ -1,16 +1,19 @@
1
- import {
2
- type L1ContractsConfig,
3
- type L1ReaderConfig,
4
- RollupContract,
5
- type ViemPublicClient,
6
- createEthereumChain,
7
- } 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';
8
8
  import type { EthAddress } from '@aztec/foundation/eth-address';
9
- import { Fr } from '@aztec/foundation/fields';
10
9
  import { createLogger } from '@aztec/foundation/log';
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
19
  import { createPublicClient, fallback, http } from 'viem';
@@ -20,26 +23,37 @@ import { createPublicClient, fallback, http } from 'viem';
20
23
  */
21
24
  export class GlobalVariableBuilder implements GlobalVariableBuilderInterface {
22
25
  private log = createLogger('sequencer:global_variable_builder');
23
- private currentBaseFees: Promise<GasFees> = Promise.resolve(new GasFees(0, 0));
26
+ private currentMinFees: Promise<GasFees> = Promise.resolve(new GasFees(0, 0));
24
27
  private currentL1BlockNumber: bigint | undefined = undefined;
25
28
 
26
29
  private readonly rollupContract: RollupContract;
27
30
  private readonly publicClient: ViemPublicClient;
28
31
  private readonly ethereumSlotDuration: number;
32
+ private readonly aztecSlotDuration: number;
33
+ private readonly l1GenesisTime: bigint;
29
34
 
30
- private chainId?: Fr;
31
- private version?: Fr;
35
+ private chainId: Fr;
36
+ private version: Fr;
32
37
 
33
- constructor(config: L1ReaderConfig & Pick<L1ContractsConfig, 'ethereumSlotDuration'>) {
38
+ constructor(
39
+ config: L1ReaderConfig &
40
+ Pick<L1ContractsConfig, 'ethereumSlotDuration'> &
41
+ Pick<L1RollupConstants, 'slotDuration' | 'l1GenesisTime'> & { rollupVersion: bigint },
42
+ ) {
34
43
  const { l1RpcUrls, l1ChainId: chainId, l1Contracts } = config;
35
44
 
36
45
  const chain = createEthereumChain(l1RpcUrls, chainId);
37
46
 
47
+ this.version = new Fr(config.rollupVersion);
48
+ this.chainId = new Fr(chainId);
49
+
38
50
  this.ethereumSlotDuration = config.ethereumSlotDuration;
51
+ this.aztecSlotDuration = config.slotDuration;
52
+ this.l1GenesisTime = config.l1GenesisTime;
39
53
 
40
54
  this.publicClient = createPublicClient({
41
55
  chain: chain.chainInfo,
42
- transport: fallback(chain.rpcUrls.map(url => http(url))),
56
+ transport: fallback(chain.rpcUrls.map(url => http(url, { batch: false }))),
43
57
  pollingInterval: config.viemPollingIntervalMS,
44
58
  });
45
59
 
@@ -47,46 +61,38 @@ export class GlobalVariableBuilder implements GlobalVariableBuilderInterface {
47
61
  }
48
62
 
49
63
  /**
50
- * Computes the "current" base fees, e.g., the price that you currently should pay to get include in the next block
51
- * @returns Base fees for the next block
64
+ * Computes the "current" min fees, e.g., the price that you currently should pay to get include in the next block
65
+ * @returns Min fees for the next block
52
66
  */
53
- private async computeCurrentBaseFees(): Promise<GasFees> {
67
+ private async computeCurrentMinFees(): Promise<GasFees> {
54
68
  // Since this might be called in the middle of a slot where a block might have been published,
55
69
  // we need to fetch the last block written, and estimate the earliest timestamp for the next block.
56
70
  // The timestamp of that last block will act as a lower bound for the next block.
57
71
 
58
- const lastBlock = await this.rollupContract.getBlock(await this.rollupContract.getBlockNumber());
59
- const earliestTimestamp = await this.rollupContract.getTimestampForSlot(lastBlock.slotNumber + 1n);
72
+ const lastCheckpoint = await this.rollupContract.getPendingCheckpoint();
73
+ const earliestTimestamp = await this.rollupContract.getTimestampForSlot(
74
+ SlotNumber.fromBigInt(BigInt(lastCheckpoint.slotNumber) + 1n),
75
+ );
60
76
  const nextEthTimestamp = BigInt((await this.publicClient.getBlock()).timestamp + BigInt(this.ethereumSlotDuration));
61
77
  const timestamp = earliestTimestamp > nextEthTimestamp ? earliestTimestamp : nextEthTimestamp;
62
78
 
63
- return new GasFees(0, await this.rollupContract.getManaBaseFeeAt(timestamp, true));
79
+ return new GasFees(0, await this.rollupContract.getManaMinFeeAt(timestamp, true));
64
80
  }
65
81
 
66
- public async getCurrentBaseFees(): Promise<GasFees> {
82
+ public async getCurrentMinFees(): Promise<GasFees> {
67
83
  // Get the current block number
68
84
  const blockNumber = await this.publicClient.getBlockNumber();
69
85
 
70
- // If the L1 block number has changed then chain a new promise to get the current base fees
86
+ // If the L1 block number has changed then chain a new promise to get the current min fees
71
87
  if (this.currentL1BlockNumber === undefined || blockNumber > this.currentL1BlockNumber) {
72
88
  this.currentL1BlockNumber = blockNumber;
73
- this.currentBaseFees = this.currentBaseFees.then(() => this.computeCurrentBaseFees());
89
+ this.currentMinFees = this.currentMinFees.then(() => this.computeCurrentMinFees());
74
90
  }
75
- return this.currentBaseFees;
76
- }
77
-
78
- public async getGlobalConstantVariables(): Promise<Pick<GlobalVariables, 'chainId' | 'version'>> {
79
- if (!this.chainId) {
80
- this.chainId = new Fr(this.publicClient.chain.id);
81
- }
82
- if (!this.version) {
83
- this.version = new Fr(await this.rollupContract.getVersion());
84
- }
85
- return { chainId: this.chainId, version: this.version };
91
+ return this.currentMinFees;
86
92
  }
87
93
 
88
94
  /**
89
- * Simple builder of global variables that use the minimum time possible.
95
+ * Simple builder of global variables.
90
96
  * @param blockNumber - The block number to build global variables for.
91
97
  * @param coinbase - The address to receive block reward.
92
98
  * @param feeRecipient - The address to receive fees.
@@ -94,36 +100,38 @@ export class GlobalVariableBuilder implements GlobalVariableBuilderInterface {
94
100
  * @returns The global variables for the given block number.
95
101
  */
96
102
  public async buildGlobalVariables(
97
- blockNumber: number,
103
+ blockNumber: BlockNumber,
98
104
  coinbase: EthAddress,
99
105
  feeRecipient: AztecAddress,
100
- slotNumber?: bigint,
106
+ maybeSlot?: SlotNumber,
101
107
  ): Promise<GlobalVariables> {
102
- const { chainId, version } = await this.getGlobalConstantVariables();
103
-
104
- if (slotNumber === undefined) {
105
- const ts = BigInt((await this.publicClient.getBlock()).timestamp + BigInt(this.ethereumSlotDuration));
106
- slotNumber = await this.rollupContract.getSlotAt(ts);
107
- }
108
-
109
- const timestamp = await this.rollupContract.getTimestampForSlot(slotNumber);
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
+ }
110
117
 
111
- const slotFr = new Fr(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;
112
125
 
113
- // We can skip much of the logic in getCurrentBaseFees since it we already check that we are not within a slot elsewhere.
114
- const gasFees = new GasFees(0, await this.rollupContract.getManaBaseFeeAt(timestamp, true));
126
+ const timestamp = getTimestampForSlot(slotNumber, {
127
+ slotDuration: this.aztecSlotDuration,
128
+ l1GenesisTime: this.l1GenesisTime,
129
+ });
115
130
 
116
- const globalVariables = new GlobalVariables(
117
- chainId,
118
- version,
119
- blockNumber,
120
- slotFr,
121
- timestamp,
122
- coinbase,
123
- feeRecipient,
124
- gasFees,
125
- );
131
+ // We can skip much of the logic in getCurrentMinFees since it we already check that we are not within a slot elsewhere.
132
+ // TODO(palla/mbps): Can we use a cached value here?
133
+ const gasFees = new GasFees(0, await this.rollupContract.getManaMinFeeAt(timestamp, true));
126
134
 
127
- return globalVariables;
135
+ return { chainId, version, slotNumber, timestamp, coinbase, feeRecipient, gasFees };
128
136
  }
129
137
  }
package/src/index.ts CHANGED
@@ -1,13 +1,7 @@
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
- Sequencer,
7
- SequencerState,
8
- type SequencerEvents,
9
- } from './sequencer/index.js';
10
- export * from './tx_validator/tx_validator_factory.js';
4
+ export { Sequencer, SequencerState, type SequencerEvents } from './sequencer/index.js';
11
5
 
12
6
  // Used by the node to simulate public parts of transactions. Should these be moved to a shared library?
13
7
  // ISSUE(#9832)
@@ -1,10 +1,6 @@
1
- import { type BlobSinkConfig, blobSinkConfigMapping } from '@aztec/blob-sink/client';
2
- import {
3
- type L1ReaderConfig,
4
- type L1TxUtilsConfig,
5
- l1ReaderConfigMappings,
6
- l1TxUtilsConfigMappings,
7
- } from '@aztec/ethereum';
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';
8
4
  import {
9
5
  type ConfigMappingsType,
10
6
  SecretValue,
@@ -32,9 +28,13 @@ export type TxSenderConfig = L1ReaderConfig & {
32
28
  * Configuration of the L1Publisher.
33
29
  */
34
30
  export type PublisherConfig = L1TxUtilsConfig &
35
- BlobSinkConfig & {
31
+ BlobClientConfig & {
36
32
  /** True to use publishers in invalid states (timed out, cancelled, etc) if no other is available */
37
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;
38
38
  };
39
39
 
40
40
  export const getTxSenderConfigMappings: (
@@ -68,8 +68,19 @@ export const getPublisherConfigMappings: (
68
68
  env: scope === `PROVER` ? `PROVER_PUBLISHER_ALLOW_INVALID_STATES` : `SEQ_PUBLISHER_ALLOW_INVALID_STATES`,
69
69
  ...booleanConfigHelper(true),
70
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),
81
+ },
71
82
  ...l1TxUtilsConfigMappings,
72
- ...blobSinkConfigMapping,
83
+ ...blobClientConfigMapping,
73
84
  });
74
85
 
75
86
  export function getPublisherConfigFromEnv(scope: 'PROVER' | 'SEQ'): PublisherConfig {
@@ -1,9 +1,11 @@
1
1
  import { EthAddress } from '@aztec/aztec.js/addresses';
2
2
  import { type Logger, createLogger } from '@aztec/aztec.js/log';
3
- import type { BlobSinkClientInterface } from '@aztec/blob-sink/client';
3
+ import type { BlobClientInterface } from '@aztec/blob-client/client';
4
4
  import type { EpochCache } from '@aztec/epoch-cache';
5
- import type { GovernanceProposerContract, PublisherFilter, PublisherManager, RollupContract } from '@aztec/ethereum';
5
+ import type { GovernanceProposerContract, RollupContract } from '@aztec/ethereum/contracts';
6
6
  import type { L1TxUtilsWithBlobs } from '@aztec/ethereum/l1-tx-utils-with-blobs';
7
+ import type { PublisherFilter, PublisherManager } from '@aztec/ethereum/publisher-manager';
8
+ import { SlotNumber } from '@aztec/foundation/branded-types';
7
9
  import type { DateProvider } from '@aztec/foundation/timer';
8
10
  import type { SlashFactoryContract } from '@aztec/stdlib/l1-contracts';
9
11
  import type { TelemetryClient } from '@aztec/telemetry-client';
@@ -22,7 +24,7 @@ export class SequencerPublisherFactory {
22
24
  private publisherMetrics: SequencerPublisherMetrics;
23
25
 
24
26
  /** Stores the last slot in which every action was carried out by a publisher */
25
- private lastActions: Partial<Record<Action, bigint>> = {};
27
+ private lastActions: Partial<Record<Action, SlotNumber>> = {};
26
28
 
27
29
  private logger: Logger;
28
30
 
@@ -31,7 +33,7 @@ export class SequencerPublisherFactory {
31
33
  private deps: {
32
34
  telemetry: TelemetryClient;
33
35
  publisherManager: PublisherManager<L1TxUtilsWithBlobs>;
34
- blobSinkClient?: BlobSinkClientInterface;
36
+ blobClient: BlobClientInterface;
35
37
  dateProvider: DateProvider;
36
38
  epochCache: EpochCache;
37
39
  rollupContract: RollupContract;
@@ -70,7 +72,7 @@ export class SequencerPublisherFactory {
70
72
  const publisher = new SequencerPublisher(this.sequencerConfig, {
71
73
  l1TxUtils: l1Publisher,
72
74
  telemetry: this.deps.telemetry,
73
- blobSinkClient: this.deps.blobSinkClient,
75
+ blobClient: this.deps.blobClient,
74
76
  rollupContract: this.deps.rollupContract,
75
77
  epochCache: this.deps.epochCache,
76
78
  governanceProposerContract: this.deps.governanceProposerContract,
@@ -1,5 +1,5 @@
1
1
  import { createLogger } from '@aztec/aztec.js/log';
2
- import type { L1PublishBlockStats, L1PublishStats } from '@aztec/stdlib/stats';
2
+ import type { L1PublishCheckpointStats, L1PublishStats } from '@aztec/stdlib/stats';
3
3
  import {
4
4
  Attributes,
5
5
  type Gauge,
@@ -7,7 +7,6 @@ import {
7
7
  Metrics,
8
8
  type TelemetryClient,
9
9
  type UpDownCounter,
10
- ValueType,
11
10
  } from '@aztec/telemetry-client';
12
11
 
13
12
  import { formatEther } from 'viem/utils';
@@ -40,88 +39,33 @@ export class SequencerPublisherMetrics {
40
39
  ) {
41
40
  const meter = client.getMeter(name);
42
41
 
43
- this.gasPrice = meter.createHistogram(Metrics.L1_PUBLISHER_GAS_PRICE, {
44
- description: 'The gas price used for transactions',
45
- unit: 'gwei',
46
- valueType: ValueType.DOUBLE,
47
- });
42
+ this.gasPrice = meter.createHistogram(Metrics.L1_PUBLISHER_GAS_PRICE);
48
43
 
49
- this.txCount = meter.createUpDownCounter(Metrics.L1_PUBLISHER_TX_COUNT, {
50
- description: 'The number of transactions processed',
51
- });
44
+ this.txCount = meter.createUpDownCounter(Metrics.L1_PUBLISHER_TX_COUNT);
52
45
 
53
- this.txDuration = meter.createHistogram(Metrics.L1_PUBLISHER_TX_DURATION, {
54
- description: 'The duration of transaction processing',
55
- unit: 'ms',
56
- valueType: ValueType.INT,
57
- });
46
+ this.txDuration = meter.createHistogram(Metrics.L1_PUBLISHER_TX_DURATION);
58
47
 
59
- this.txGas = meter.createHistogram(Metrics.L1_PUBLISHER_TX_GAS, {
60
- description: 'The gas consumed by transactions',
61
- unit: 'gas',
62
- valueType: ValueType.INT,
63
- });
48
+ this.txGas = meter.createHistogram(Metrics.L1_PUBLISHER_TX_GAS);
64
49
 
65
- this.txCalldataSize = meter.createHistogram(Metrics.L1_PUBLISHER_TX_CALLDATA_SIZE, {
66
- description: 'The size of the calldata in transactions',
67
- unit: 'By',
68
- valueType: ValueType.INT,
69
- });
50
+ this.txCalldataSize = meter.createHistogram(Metrics.L1_PUBLISHER_TX_CALLDATA_SIZE);
70
51
 
71
- this.txCalldataGas = meter.createHistogram(Metrics.L1_PUBLISHER_TX_CALLDATA_GAS, {
72
- description: 'The gas consumed by the calldata in transactions',
73
- unit: 'gas',
74
- valueType: ValueType.INT,
75
- });
52
+ this.txCalldataGas = meter.createHistogram(Metrics.L1_PUBLISHER_TX_CALLDATA_GAS);
76
53
 
77
- this.txBlobDataGasUsed = meter.createHistogram(Metrics.L1_PUBLISHER_TX_BLOBDATA_GAS_USED, {
78
- description: 'The amount of blob gas used in transactions',
79
- unit: 'gas',
80
- valueType: ValueType.INT,
81
- });
54
+ this.txBlobDataGasUsed = meter.createHistogram(Metrics.L1_PUBLISHER_TX_BLOBDATA_GAS_USED);
82
55
 
83
- this.txBlobDataGasCost = meter.createHistogram(Metrics.L1_PUBLISHER_TX_BLOBDATA_GAS_COST, {
84
- description: 'The gas cost of blobs in transactions',
85
- unit: 'gwei',
86
- valueType: ValueType.INT,
87
- });
56
+ this.txBlobDataGasCost = meter.createHistogram(Metrics.L1_PUBLISHER_TX_BLOBDATA_GAS_COST);
88
57
 
89
- this.blobCountHistogram = meter.createHistogram(Metrics.L1_PUBLISHER_BLOB_COUNT, {
90
- description: 'Number of blobs in L1 transactions',
91
- unit: 'blobs',
92
- valueType: ValueType.INT,
93
- });
58
+ this.blobCountHistogram = meter.createHistogram(Metrics.L1_PUBLISHER_BLOB_COUNT);
94
59
 
95
- this.blobInclusionBlocksHistogram = meter.createHistogram(Metrics.L1_PUBLISHER_BLOB_INCLUSION_BLOCKS, {
96
- description: 'Number of L1 blocks between blob tx submission and inclusion',
97
- unit: 'blocks',
98
- valueType: ValueType.INT,
99
- });
60
+ this.blobInclusionBlocksHistogram = meter.createHistogram(Metrics.L1_PUBLISHER_BLOB_INCLUSION_BLOCKS);
100
61
 
101
- this.blobTxSuccessCounter = meter.createUpDownCounter(Metrics.L1_PUBLISHER_BLOB_TX_SUCCESS, {
102
- description: 'Number of successful L1 transactions with blobs',
103
- });
62
+ this.blobTxSuccessCounter = meter.createUpDownCounter(Metrics.L1_PUBLISHER_BLOB_TX_SUCCESS);
104
63
 
105
- this.blobTxFailureCounter = meter.createUpDownCounter(Metrics.L1_PUBLISHER_BLOB_TX_FAILURE, {
106
- description: 'Number of failed L1 transactions with blobs',
107
- });
64
+ this.blobTxFailureCounter = meter.createUpDownCounter(Metrics.L1_PUBLISHER_BLOB_TX_FAILURE);
108
65
 
109
- this.txTotalFee = meter.createHistogram(Metrics.L1_PUBLISHER_TX_TOTAL_FEE, {
110
- description: 'How much L1 tx costs',
111
- unit: 'eth',
112
- valueType: ValueType.DOUBLE,
113
- advice: {
114
- explicitBucketBoundaries: [
115
- 0.001, 0.002, 0.004, 0.008, 0.01, 0.02, 0.04, 0.08, 0.1, 0.2, 0.4, 0.8, 1, 1.2, 1.4, 1.8, 2,
116
- ],
117
- },
118
- });
66
+ this.txTotalFee = meter.createHistogram(Metrics.L1_PUBLISHER_TX_TOTAL_FEE);
119
67
 
120
- this.senderBalance = meter.createGauge(Metrics.L1_PUBLISHER_BALANCE, {
121
- unit: 'eth',
122
- description: 'The balance of the sender address',
123
- valueType: ValueType.DOUBLE,
124
- });
68
+ this.senderBalance = meter.createGauge(Metrics.L1_PUBLISHER_BALANCE);
125
69
  }
126
70
 
127
71
  recordFailedTx(txType: L1TxType) {
@@ -135,7 +79,7 @@ export class SequencerPublisherMetrics {
135
79
  }
136
80
  }
137
81
 
138
- recordProcessBlockTx(durationMs: number, stats: L1PublishBlockStats) {
82
+ recordProcessBlockTx(durationMs: number, stats: L1PublishCheckpointStats) {
139
83
  this.recordTx('process', durationMs, stats);
140
84
 
141
85
  if (stats.blobCount && stats.blobCount > 0) {