@aztec/sequencer-client 0.0.1-commit.d3ec352c → 0.0.1-commit.d431d1c

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 (96) hide show
  1. package/dest/client/sequencer-client.d.ts +12 -12
  2. package/dest/client/sequencer-client.d.ts.map +1 -1
  3. package/dest/client/sequencer-client.js +32 -25
  4. package/dest/config.d.ts +12 -5
  5. package/dest/config.d.ts.map +1 -1
  6. package/dest/config.js +75 -30
  7. package/dest/global_variable_builder/global_builder.d.ts +21 -12
  8. package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
  9. package/dest/global_variable_builder/global_builder.js +51 -41
  10. package/dest/index.d.ts +2 -3
  11. package/dest/index.d.ts.map +1 -1
  12. package/dest/index.js +1 -2
  13. package/dest/publisher/config.d.ts +7 -4
  14. package/dest/publisher/config.d.ts.map +1 -1
  15. package/dest/publisher/config.js +9 -3
  16. package/dest/publisher/sequencer-publisher-factory.d.ts +5 -4
  17. package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -1
  18. package/dest/publisher/sequencer-publisher-factory.js +1 -1
  19. package/dest/publisher/sequencer-publisher-metrics.d.ts +3 -3
  20. package/dest/publisher/sequencer-publisher-metrics.d.ts.map +1 -1
  21. package/dest/publisher/sequencer-publisher-metrics.js +15 -86
  22. package/dest/publisher/sequencer-publisher.d.ts +48 -40
  23. package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
  24. package/dest/publisher/sequencer-publisher.js +564 -114
  25. package/dest/sequencer/checkpoint_proposal_job.d.ts +79 -0
  26. package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -0
  27. package/dest/sequencer/checkpoint_proposal_job.js +1159 -0
  28. package/dest/sequencer/checkpoint_voter.d.ts +35 -0
  29. package/dest/sequencer/checkpoint_voter.d.ts.map +1 -0
  30. package/dest/sequencer/checkpoint_voter.js +109 -0
  31. package/dest/sequencer/config.d.ts +3 -2
  32. package/dest/sequencer/config.d.ts.map +1 -1
  33. package/dest/sequencer/events.d.ts +46 -0
  34. package/dest/sequencer/events.d.ts.map +1 -0
  35. package/dest/sequencer/events.js +1 -0
  36. package/dest/sequencer/index.d.ts +4 -2
  37. package/dest/sequencer/index.d.ts.map +1 -1
  38. package/dest/sequencer/index.js +3 -1
  39. package/dest/sequencer/metrics.d.ts +22 -2
  40. package/dest/sequencer/metrics.d.ts.map +1 -1
  41. package/dest/sequencer/metrics.js +125 -62
  42. package/dest/sequencer/sequencer.d.ts +107 -131
  43. package/dest/sequencer/sequencer.d.ts.map +1 -1
  44. package/dest/sequencer/sequencer.js +690 -602
  45. package/dest/sequencer/timetable.d.ts +54 -14
  46. package/dest/sequencer/timetable.d.ts.map +1 -1
  47. package/dest/sequencer/timetable.js +148 -59
  48. package/dest/sequencer/types.d.ts +3 -0
  49. package/dest/sequencer/types.d.ts.map +1 -0
  50. package/dest/sequencer/types.js +1 -0
  51. package/dest/sequencer/utils.d.ts +14 -8
  52. package/dest/sequencer/utils.d.ts.map +1 -1
  53. package/dest/sequencer/utils.js +7 -4
  54. package/dest/test/index.d.ts +4 -3
  55. package/dest/test/index.d.ts.map +1 -1
  56. package/dest/test/mock_checkpoint_builder.d.ts +92 -0
  57. package/dest/test/mock_checkpoint_builder.d.ts.map +1 -0
  58. package/dest/test/mock_checkpoint_builder.js +208 -0
  59. package/dest/test/utils.d.ts +53 -0
  60. package/dest/test/utils.d.ts.map +1 -0
  61. package/dest/test/utils.js +103 -0
  62. package/package.json +30 -28
  63. package/src/client/sequencer-client.ts +30 -41
  64. package/src/config.ts +80 -34
  65. package/src/global_variable_builder/global_builder.ts +63 -59
  66. package/src/index.ts +1 -7
  67. package/src/publisher/config.ts +12 -9
  68. package/src/publisher/sequencer-publisher-factory.ts +5 -4
  69. package/src/publisher/sequencer-publisher-metrics.ts +16 -72
  70. package/src/publisher/sequencer-publisher.ts +262 -155
  71. package/src/sequencer/README.md +531 -0
  72. package/src/sequencer/checkpoint_proposal_job.ts +841 -0
  73. package/src/sequencer/checkpoint_voter.ts +130 -0
  74. package/src/sequencer/config.ts +2 -1
  75. package/src/sequencer/events.ts +27 -0
  76. package/src/sequencer/index.ts +3 -1
  77. package/src/sequencer/metrics.ts +164 -70
  78. package/src/sequencer/sequencer.ts +430 -804
  79. package/src/sequencer/timetable.ts +173 -79
  80. package/src/sequencer/types.ts +6 -0
  81. package/src/sequencer/utils.ts +18 -9
  82. package/src/test/index.ts +3 -2
  83. package/src/test/mock_checkpoint_builder.ts +295 -0
  84. package/src/test/utils.ts +158 -0
  85. package/dest/sequencer/block_builder.d.ts +0 -28
  86. package/dest/sequencer/block_builder.d.ts.map +0 -1
  87. package/dest/sequencer/block_builder.js +0 -134
  88. package/dest/tx_validator/nullifier_cache.d.ts +0 -14
  89. package/dest/tx_validator/nullifier_cache.d.ts.map +0 -1
  90. package/dest/tx_validator/nullifier_cache.js +0 -24
  91. package/dest/tx_validator/tx_validator_factory.d.ts +0 -18
  92. package/dest/tx_validator/tx_validator_factory.d.ts.map +0 -1
  93. package/dest/tx_validator/tx_validator_factory.js +0 -53
  94. package/src/sequencer/block_builder.ts +0 -222
  95. package/src/tx_validator/nullifier_cache.ts +0 -30
  96. package/src/tx_validator/tx_validator_factory.ts +0 -133
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,33 @@ 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
+ // TODO(palla/mbps): Change default to false once block sync is stable
54
+ skipPushProposedBlocksToArchiver: true,
55
+ };
56
+
33
57
  /**
34
58
  * Configuration settings for the SequencerClient.
35
59
  */
@@ -44,35 +68,39 @@ export type SequencerClientConfig = PublisherConfig &
44
68
  Pick<L1ContractsConfig, 'ethereumSlotDuration' | 'aztecSlotDuration' | 'aztecEpochDuration'>;
45
69
 
46
70
  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),
71
+ sequencerPollingIntervalMS: {
72
+ env: 'SEQ_POLLING_INTERVAL_MS',
73
+ description: 'The number of ms to wait between polling for checking to build on the next slot.',
74
+ ...numberConfigHelper(DefaultSequencerConfig.sequencerPollingIntervalMS),
51
75
  },
52
76
  maxTxsPerBlock: {
53
77
  env: 'SEQ_MAX_TX_PER_BLOCK',
54
78
  description: 'The maximum number of txs to include in a block.',
55
- ...numberConfigHelper(32),
79
+ ...numberConfigHelper(DefaultSequencerConfig.maxTxsPerBlock),
56
80
  },
57
81
  minTxsPerBlock: {
58
82
  env: 'SEQ_MIN_TX_PER_BLOCK',
59
83
  description: 'The minimum number of txs to include in a block.',
60
- ...numberConfigHelper(1),
84
+ ...numberConfigHelper(DefaultSequencerConfig.minTxsPerBlock),
85
+ },
86
+ minValidTxsPerBlock: {
87
+ description:
88
+ 'The minimum number of valid txs (after execution) to include in a block. If not set, falls back to minTxsPerBlock.',
61
89
  },
62
90
  publishTxsWithProposals: {
63
91
  env: 'SEQ_PUBLISH_TXS_WITH_PROPOSALS',
64
92
  description: 'Whether to publish txs with proposals.',
65
- ...booleanConfigHelper(false),
93
+ ...booleanConfigHelper(DefaultSequencerConfig.publishTxsWithProposals),
66
94
  },
67
95
  maxL2BlockGas: {
68
96
  env: 'SEQ_MAX_L2_BLOCK_GAS',
69
97
  description: 'The maximum L2 block gas.',
70
- ...numberConfigHelper(10e9),
98
+ ...numberConfigHelper(DefaultSequencerConfig.maxL2BlockGas),
71
99
  },
72
100
  maxDABlockGas: {
73
101
  env: 'SEQ_MAX_DA_BLOCK_GAS',
74
102
  description: 'The maximum DA block gas.',
75
- ...numberConfigHelper(10e9),
103
+ ...numberConfigHelper(DefaultSequencerConfig.maxDABlockGas),
76
104
  },
77
105
  coinbase: {
78
106
  env: 'COINBASE',
@@ -95,73 +123,91 @@ export const sequencerConfigMappings: ConfigMappingsType<SequencerConfig> = {
95
123
  maxBlockSizeInBytes: {
96
124
  env: 'SEQ_MAX_BLOCK_SIZE_IN_BYTES',
97
125
  description: 'Max block size',
98
- ...numberConfigHelper(1024 * 1024),
126
+ ...numberConfigHelper(DefaultSequencerConfig.maxBlockSizeInBytes),
99
127
  },
100
128
  enforceTimeTable: {
101
129
  env: 'SEQ_ENFORCE_TIME_TABLE',
102
130
  description: 'Whether to enforce the time table when building blocks',
103
- ...booleanConfigHelper(),
104
- defaultValue: true,
131
+ ...booleanConfigHelper(DefaultSequencerConfig.enforceTimeTable),
105
132
  },
106
133
  governanceProposerPayload: {
107
134
  env: 'GOVERNANCE_PROPOSER_PAYLOAD_ADDRESS',
108
135
  description: 'The address of the payload for the governanceProposer',
109
136
  parseEnv: (val: string) => EthAddress.fromString(val),
110
- defaultValue: EthAddress.ZERO,
111
137
  },
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.',
138
+ l1PublishingTime: {
139
+ env: 'SEQ_L1_PUBLISHING_TIME_ALLOWANCE_IN_SLOT',
140
+ description: 'How much time (in seconds) we allow in the slot for publishing the L1 tx (defaults to 1 L1 slot).',
115
141
  parseEnv: (val: string) => (val ? parseInt(val, 10) : undefined),
116
142
  },
117
143
  attestationPropagationTime: {
118
144
  env: 'SEQ_ATTESTATION_PROPAGATION_TIME',
119
145
  description: 'How many seconds it takes for proposals and attestations to travel across the p2p layer (one-way)',
120
- ...numberConfigHelper(DEFAULT_ATTESTATION_PROPAGATION_TIME),
146
+ ...numberConfigHelper(DefaultSequencerConfig.attestationPropagationTime),
121
147
  },
122
148
  fakeProcessingDelayPerTxMs: {
123
149
  description: 'Used for testing to introduce a fake delay after processing each tx',
124
150
  },
151
+ fakeThrowAfterProcessingTxCount: {
152
+ description: 'Used for testing to throw an error after processing N txs',
153
+ },
125
154
  secondsBeforeInvalidatingBlockAsCommitteeMember: {
126
155
  env: 'SEQ_SECONDS_BEFORE_INVALIDATING_BLOCK_AS_COMMITTEE_MEMBER',
127
156
  description:
128
157
  'How many seconds to wait before trying to invalidate a block from the pending chain as a committee member (zero to never invalidate).' +
129
158
  ' The next proposer is expected to invalidate, so the committee acts as a fallback.',
130
- ...numberConfigHelper(144), // 12 L1 blocks
159
+ ...numberConfigHelper(DefaultSequencerConfig.secondsBeforeInvalidatingBlockAsCommitteeMember),
131
160
  },
132
161
  secondsBeforeInvalidatingBlockAsNonCommitteeMember: {
133
162
  env: 'SEQ_SECONDS_BEFORE_INVALIDATING_BLOCK_AS_NON_COMMITTEE_MEMBER',
134
163
  description:
135
164
  '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
165
  ' The next proposer is expected to invalidate, then the committee, so other sequencers act as a fallback.',
137
- ...numberConfigHelper(432), // 36 L1 blocks
166
+ ...numberConfigHelper(DefaultSequencerConfig.secondsBeforeInvalidatingBlockAsNonCommitteeMember),
138
167
  },
139
168
  skipCollectingAttestations: {
140
169
  description:
141
170
  'Whether to skip collecting attestations from validators and only use self-attestations (for testing only)',
142
- ...booleanConfigHelper(false),
171
+ ...booleanConfigHelper(DefaultSequencerConfig.skipCollectingAttestations),
143
172
  },
144
173
  skipInvalidateBlockAsProposer: {
145
174
  description: 'Do not invalidate the previous block if invalid when we are the proposer (for testing only)',
146
- ...booleanConfigHelper(false),
175
+ ...booleanConfigHelper(DefaultSequencerConfig.skipInvalidateBlockAsProposer),
147
176
  },
148
177
  broadcastInvalidBlockProposal: {
149
178
  description: 'Broadcast invalid block proposals with corrupted state (for testing only)',
150
- ...booleanConfigHelper(false),
179
+ ...booleanConfigHelper(DefaultSequencerConfig.broadcastInvalidBlockProposal),
151
180
  },
152
181
  injectFakeAttestation: {
153
182
  description: 'Inject a fake attestation (for testing only)',
154
- ...booleanConfigHelper(false),
183
+ ...booleanConfigHelper(DefaultSequencerConfig.injectFakeAttestation),
155
184
  },
156
185
  fishermanMode: {
157
186
  env: 'FISHERMAN_MODE',
158
187
  description:
159
188
  'Whether to run in fisherman mode: builds blocks on every slot for validation without publishing to L1',
160
- ...booleanConfigHelper(false),
189
+ ...booleanConfigHelper(DefaultSequencerConfig.fishermanMode),
161
190
  },
162
191
  shuffleAttestationOrdering: {
163
192
  description: 'Shuffle attestation ordering to create invalid ordering (for testing only)',
164
- ...booleanConfigHelper(false),
193
+ ...booleanConfigHelper(DefaultSequencerConfig.shuffleAttestationOrdering),
194
+ },
195
+ blockDurationMs: {
196
+ env: 'SEQ_BLOCK_DURATION_MS',
197
+ description:
198
+ 'Duration per block in milliseconds when building multiple blocks per slot. ' +
199
+ 'If undefined (default), builds a single block per slot using the full slot duration.',
200
+ parseEnv: (val: string) => (val ? parseInt(val, 10) : undefined),
201
+ },
202
+ buildCheckpointIfEmpty: {
203
+ env: 'SEQ_BUILD_CHECKPOINT_IF_EMPTY',
204
+ description: 'Have sequencer build and publish an empty checkpoint if there are no txs',
205
+ ...booleanConfigHelper(DefaultSequencerConfig.buildCheckpointIfEmpty),
206
+ },
207
+ // TODO(palla/mbps): Change default to false once block sync is stable
208
+ skipPushProposedBlocksToArchiver: {
209
+ description: 'Skip pushing proposed blocks to archiver (default: true)',
210
+ ...booleanConfigHelper(DefaultSequencerConfig.skipPushProposedBlocksToArchiver),
165
211
  },
166
212
  ...pickConfigMappings(p2pConfigMappings, ['txPublicSetupAllowList']),
167
213
  };
@@ -1,17 +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';
8
6
  import { BlockNumber, SlotNumber } from '@aztec/foundation/branded-types';
7
+ import { Fr } from '@aztec/foundation/curves/bn254';
9
8
  import type { EthAddress } from '@aztec/foundation/eth-address';
10
- import { Fr } from '@aztec/foundation/fields';
11
9
  import { createLogger } from '@aztec/foundation/log';
12
10
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
11
+ import { type L1RollupConstants, getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
13
12
  import { GasFees } from '@aztec/stdlib/gas';
14
- import type { GlobalVariableBuilder as GlobalVariableBuilderInterface } from '@aztec/stdlib/tx';
13
+ import type {
14
+ CheckpointGlobalVariables,
15
+ GlobalVariableBuilder as GlobalVariableBuilderInterface,
16
+ } from '@aztec/stdlib/tx';
15
17
  import { GlobalVariables } from '@aztec/stdlib/tx';
16
18
 
17
19
  import { createPublicClient, fallback, http } from 'viem';
@@ -21,26 +23,37 @@ import { createPublicClient, fallback, http } from 'viem';
21
23
  */
22
24
  export class GlobalVariableBuilder implements GlobalVariableBuilderInterface {
23
25
  private log = createLogger('sequencer:global_variable_builder');
24
- private currentBaseFees: Promise<GasFees> = Promise.resolve(new GasFees(0, 0));
26
+ private currentMinFees: Promise<GasFees> = Promise.resolve(new GasFees(0, 0));
25
27
  private currentL1BlockNumber: bigint | undefined = undefined;
26
28
 
27
29
  private readonly rollupContract: RollupContract;
28
30
  private readonly publicClient: ViemPublicClient;
29
31
  private readonly ethereumSlotDuration: number;
32
+ private readonly aztecSlotDuration: number;
33
+ private readonly l1GenesisTime: bigint;
30
34
 
31
- private chainId?: Fr;
32
- private version?: Fr;
35
+ private chainId: Fr;
36
+ private version: Fr;
33
37
 
34
- constructor(config: L1ReaderConfig & Pick<L1ContractsConfig, 'ethereumSlotDuration'>) {
38
+ constructor(
39
+ config: L1ReaderConfig &
40
+ Pick<L1ContractsConfig, 'ethereumSlotDuration'> &
41
+ Pick<L1RollupConstants, 'slotDuration' | 'l1GenesisTime'> & { rollupVersion: bigint },
42
+ ) {
35
43
  const { l1RpcUrls, l1ChainId: chainId, l1Contracts } = config;
36
44
 
37
45
  const chain = createEthereumChain(l1RpcUrls, chainId);
38
46
 
47
+ this.version = new Fr(config.rollupVersion);
48
+ this.chainId = new Fr(chainId);
49
+
39
50
  this.ethereumSlotDuration = config.ethereumSlotDuration;
51
+ this.aztecSlotDuration = config.slotDuration;
52
+ this.l1GenesisTime = config.l1GenesisTime;
40
53
 
41
54
  this.publicClient = createPublicClient({
42
55
  chain: chain.chainInfo,
43
- transport: fallback(chain.rpcUrls.map(url => http(url))),
56
+ transport: fallback(chain.rpcUrls.map(url => http(url, { batch: false }))),
44
57
  pollingInterval: config.viemPollingIntervalMS,
45
58
  });
46
59
 
@@ -48,48 +61,38 @@ export class GlobalVariableBuilder implements GlobalVariableBuilderInterface {
48
61
  }
49
62
 
50
63
  /**
51
- * Computes the "current" base fees, e.g., the price that you currently should pay to get include in the next block
52
- * @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
53
66
  */
54
- private async computeCurrentBaseFees(): Promise<GasFees> {
67
+ private async computeCurrentMinFees(): Promise<GasFees> {
55
68
  // Since this might be called in the middle of a slot where a block might have been published,
56
69
  // we need to fetch the last block written, and estimate the earliest timestamp for the next block.
57
70
  // The timestamp of that last block will act as a lower bound for the next block.
58
71
 
59
- const lastBlock = await this.rollupContract.getCheckpoint(await this.rollupContract.getCheckpointNumber());
72
+ const lastBlock = await this.rollupContract.getPendingCheckpoint();
60
73
  const earliestTimestamp = await this.rollupContract.getTimestampForSlot(
61
- SlotNumber.fromBigInt(lastBlock.slotNumber + 1n),
74
+ SlotNumber.fromBigInt(BigInt(lastBlock.slotNumber) + 1n),
62
75
  );
63
76
  const nextEthTimestamp = BigInt((await this.publicClient.getBlock()).timestamp + BigInt(this.ethereumSlotDuration));
64
77
  const timestamp = earliestTimestamp > nextEthTimestamp ? earliestTimestamp : nextEthTimestamp;
65
78
 
66
- return new GasFees(0, await this.rollupContract.getManaBaseFeeAt(timestamp, true));
79
+ return new GasFees(0, await this.rollupContract.getManaMinFeeAt(timestamp, true));
67
80
  }
68
81
 
69
- public async getCurrentBaseFees(): Promise<GasFees> {
82
+ public async getCurrentMinFees(): Promise<GasFees> {
70
83
  // Get the current block number
71
84
  const blockNumber = await this.publicClient.getBlockNumber();
72
85
 
73
- // 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
74
87
  if (this.currentL1BlockNumber === undefined || blockNumber > this.currentL1BlockNumber) {
75
88
  this.currentL1BlockNumber = blockNumber;
76
- this.currentBaseFees = this.currentBaseFees.then(() => this.computeCurrentBaseFees());
77
- }
78
- return this.currentBaseFees;
79
- }
80
-
81
- public async getGlobalConstantVariables(): Promise<Pick<GlobalVariables, 'chainId' | 'version'>> {
82
- if (!this.chainId) {
83
- this.chainId = new Fr(this.publicClient.chain.id);
84
- }
85
- if (!this.version) {
86
- this.version = new Fr(await this.rollupContract.getVersion());
89
+ this.currentMinFees = this.currentMinFees.then(() => this.computeCurrentMinFees());
87
90
  }
88
- return { chainId: this.chainId, version: this.version };
91
+ return this.currentMinFees;
89
92
  }
90
93
 
91
94
  /**
92
- * Simple builder of global variables that use the minimum time possible.
95
+ * Simple builder of global variables.
93
96
  * @param blockNumber - The block number to build global variables for.
94
97
  * @param coinbase - The address to receive block reward.
95
98
  * @param feeRecipient - The address to receive fees.
@@ -100,34 +103,35 @@ export class GlobalVariableBuilder implements GlobalVariableBuilderInterface {
100
103
  blockNumber: BlockNumber,
101
104
  coinbase: EthAddress,
102
105
  feeRecipient: AztecAddress,
103
- slotNumber?: SlotNumber,
106
+ maybeSlot?: SlotNumber,
104
107
  ): Promise<GlobalVariables> {
105
- const { chainId, version } = await this.getGlobalConstantVariables();
106
-
107
- let slot: SlotNumber;
108
- if (slotNumber === undefined) {
109
- const ts = BigInt((await this.publicClient.getBlock()).timestamp + BigInt(this.ethereumSlotDuration));
110
- slot = await this.rollupContract.getSlotAt(ts);
111
- } else {
112
- slot = slotNumber;
113
- }
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
+ }
114
117
 
115
- const timestamp = await this.rollupContract.getTimestampForSlot(slot);
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;
116
125
 
117
- // We can skip much of the logic in getCurrentBaseFees since it we already check that we are not within a slot elsewhere.
118
- 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
+ });
119
130
 
120
- const globalVariables = new GlobalVariables(
121
- chainId,
122
- version,
123
- blockNumber,
124
- slot,
125
- timestamp,
126
- coinbase,
127
- feeRecipient,
128
- gasFees,
129
- );
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));
130
134
 
131
- return globalVariables;
135
+ return { chainId, version, slotNumber, timestamp, coinbase, feeRecipient, gasFees };
132
136
  }
133
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,11 +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;
38
34
  /** Whether to run in fisherman mode: builds blocks on every slot for validation without publishing to L1 */
39
35
  fishermanMode?: boolean;
36
+ /** Address of the forwarder contract to wrap all L1 transactions through (for testing purposes only) */
37
+ publisherForwarderAddress?: EthAddress;
40
38
  };
41
39
 
42
40
  export const getTxSenderConfigMappings: (
@@ -76,8 +74,13 @@ export const getPublisherConfigMappings: (
76
74
  'Whether to run in fisherman mode: builds blocks on every slot for validation without publishing to L1',
77
75
  ...booleanConfigHelper(false),
78
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
+ },
79
82
  ...l1TxUtilsConfigMappings,
80
- ...blobSinkConfigMapping,
83
+ ...blobClientConfigMapping,
81
84
  });
82
85
 
83
86
  export function getPublisherConfigFromEnv(scope: 'PROVER' | 'SEQ'): PublisherConfig {
@@ -1,9 +1,10 @@
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';
7
8
  import { SlotNumber } from '@aztec/foundation/branded-types';
8
9
  import type { DateProvider } from '@aztec/foundation/timer';
9
10
  import type { SlashFactoryContract } from '@aztec/stdlib/l1-contracts';
@@ -32,7 +33,7 @@ export class SequencerPublisherFactory {
32
33
  private deps: {
33
34
  telemetry: TelemetryClient;
34
35
  publisherManager: PublisherManager<L1TxUtilsWithBlobs>;
35
- blobSinkClient?: BlobSinkClientInterface;
36
+ blobClient: BlobClientInterface;
36
37
  dateProvider: DateProvider;
37
38
  epochCache: EpochCache;
38
39
  rollupContract: RollupContract;
@@ -71,7 +72,7 @@ export class SequencerPublisherFactory {
71
72
  const publisher = new SequencerPublisher(this.sequencerConfig, {
72
73
  l1TxUtils: l1Publisher,
73
74
  telemetry: this.deps.telemetry,
74
- blobSinkClient: this.deps.blobSinkClient,
75
+ blobClient: this.deps.blobClient,
75
76
  rollupContract: this.deps.rollupContract,
76
77
  epochCache: this.deps.epochCache,
77
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) {