@aztec/sequencer-client 0.0.0-test.1 → 0.0.1-commit.1142ef1

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 (139) hide show
  1. package/dest/client/index.d.ts +1 -1
  2. package/dest/client/sequencer-client.d.ts +31 -31
  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 +120 -70
  8. package/dest/global_variable_builder/global_builder.d.ts +26 -15
  9. package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
  10. package/dest/global_variable_builder/global_builder.js +62 -44
  11. package/dest/global_variable_builder/index.d.ts +1 -1
  12. package/dest/index.d.ts +2 -4
  13. package/dest/index.d.ts.map +1 -1
  14. package/dest/index.js +1 -3
  15. package/dest/publisher/config.d.ts +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 +26 -62
  27. package/dest/publisher/sequencer-publisher.d.ts +134 -87
  28. package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
  29. package/dest/publisher/sequencer-publisher.js +1146 -249
  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_proposal_job.d.ts +77 -0
  34. package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -0
  35. package/dest/sequencer/checkpoint_proposal_job.js +1089 -0
  36. package/dest/sequencer/checkpoint_voter.d.ts +34 -0
  37. package/dest/sequencer/checkpoint_voter.d.ts.map +1 -0
  38. package/dest/sequencer/checkpoint_voter.js +85 -0
  39. package/dest/sequencer/config.d.ts +7 -1
  40. package/dest/sequencer/config.d.ts.map +1 -1
  41. package/dest/sequencer/errors.d.ts +11 -0
  42. package/dest/sequencer/errors.d.ts.map +1 -0
  43. package/dest/sequencer/errors.js +15 -0
  44. package/dest/sequencer/events.d.ts +46 -0
  45. package/dest/sequencer/events.d.ts.map +1 -0
  46. package/dest/sequencer/events.js +1 -0
  47. package/dest/sequencer/index.d.ts +5 -2
  48. package/dest/sequencer/index.d.ts.map +1 -1
  49. package/dest/sequencer/index.js +4 -1
  50. package/dest/sequencer/metrics.d.ts +48 -12
  51. package/dest/sequencer/metrics.d.ts.map +1 -1
  52. package/dest/sequencer/metrics.js +204 -69
  53. package/dest/sequencer/sequencer.d.ts +136 -137
  54. package/dest/sequencer/sequencer.d.ts.map +1 -1
  55. package/dest/sequencer/sequencer.js +913 -527
  56. package/dest/sequencer/timetable.d.ts +76 -24
  57. package/dest/sequencer/timetable.d.ts.map +1 -1
  58. package/dest/sequencer/timetable.js +177 -61
  59. package/dest/sequencer/types.d.ts +3 -0
  60. package/dest/sequencer/types.d.ts.map +1 -0
  61. package/dest/sequencer/types.js +1 -0
  62. package/dest/sequencer/utils.d.ts +20 -38
  63. package/dest/sequencer/utils.d.ts.map +1 -1
  64. package/dest/sequencer/utils.js +12 -47
  65. package/dest/test/index.d.ts +9 -1
  66. package/dest/test/index.d.ts.map +1 -1
  67. package/dest/test/index.js +0 -4
  68. package/dest/test/mock_checkpoint_builder.d.ts +91 -0
  69. package/dest/test/mock_checkpoint_builder.d.ts.map +1 -0
  70. package/dest/test/mock_checkpoint_builder.js +202 -0
  71. package/dest/test/utils.d.ts +53 -0
  72. package/dest/test/utils.d.ts.map +1 -0
  73. package/dest/test/utils.js +103 -0
  74. package/package.json +45 -45
  75. package/src/client/sequencer-client.ts +106 -107
  76. package/src/config.ts +133 -81
  77. package/src/global_variable_builder/global_builder.ts +84 -55
  78. package/src/index.ts +6 -3
  79. package/src/publisher/config.ts +45 -32
  80. package/src/publisher/index.ts +4 -0
  81. package/src/publisher/sequencer-publisher-factory.ts +92 -0
  82. package/src/publisher/sequencer-publisher-metrics.ts +30 -64
  83. package/src/publisher/sequencer-publisher.ts +967 -295
  84. package/src/sequencer/README.md +531 -0
  85. package/src/sequencer/block_builder.ts +216 -0
  86. package/src/sequencer/checkpoint_proposal_job.ts +742 -0
  87. package/src/sequencer/checkpoint_voter.ts +105 -0
  88. package/src/sequencer/config.ts +8 -0
  89. package/src/sequencer/errors.ts +21 -0
  90. package/src/sequencer/events.ts +27 -0
  91. package/src/sequencer/index.ts +4 -1
  92. package/src/sequencer/metrics.ts +269 -72
  93. package/src/sequencer/sequencer.ts +640 -592
  94. package/src/sequencer/timetable.ts +221 -62
  95. package/src/sequencer/types.ts +6 -0
  96. package/src/sequencer/utils.ts +28 -60
  97. package/src/test/index.ts +12 -4
  98. package/src/test/mock_checkpoint_builder.ts +279 -0
  99. package/src/test/utils.ts +157 -0
  100. package/dest/sequencer/allowed.d.ts +0 -3
  101. package/dest/sequencer/allowed.d.ts.map +0 -1
  102. package/dest/sequencer/allowed.js +0 -27
  103. package/dest/slasher/factory.d.ts +0 -7
  104. package/dest/slasher/factory.d.ts.map +0 -1
  105. package/dest/slasher/factory.js +0 -8
  106. package/dest/slasher/index.d.ts +0 -3
  107. package/dest/slasher/index.d.ts.map +0 -1
  108. package/dest/slasher/index.js +0 -2
  109. package/dest/slasher/slasher_client.d.ts +0 -75
  110. package/dest/slasher/slasher_client.d.ts.map +0 -1
  111. package/dest/slasher/slasher_client.js +0 -132
  112. package/dest/tx_validator/archive_cache.d.ts +0 -14
  113. package/dest/tx_validator/archive_cache.d.ts.map +0 -1
  114. package/dest/tx_validator/archive_cache.js +0 -22
  115. package/dest/tx_validator/gas_validator.d.ts +0 -14
  116. package/dest/tx_validator/gas_validator.d.ts.map +0 -1
  117. package/dest/tx_validator/gas_validator.js +0 -78
  118. package/dest/tx_validator/nullifier_cache.d.ts +0 -16
  119. package/dest/tx_validator/nullifier_cache.d.ts.map +0 -1
  120. package/dest/tx_validator/nullifier_cache.js +0 -24
  121. package/dest/tx_validator/phases_validator.d.ts +0 -12
  122. package/dest/tx_validator/phases_validator.d.ts.map +0 -1
  123. package/dest/tx_validator/phases_validator.js +0 -80
  124. package/dest/tx_validator/test_utils.d.ts +0 -23
  125. package/dest/tx_validator/test_utils.d.ts.map +0 -1
  126. package/dest/tx_validator/test_utils.js +0 -26
  127. package/dest/tx_validator/tx_validator_factory.d.ts +0 -18
  128. package/dest/tx_validator/tx_validator_factory.d.ts.map +0 -1
  129. package/dest/tx_validator/tx_validator_factory.js +0 -50
  130. package/src/sequencer/allowed.ts +0 -36
  131. package/src/slasher/factory.ts +0 -15
  132. package/src/slasher/index.ts +0 -2
  133. package/src/slasher/slasher_client.ts +0 -193
  134. package/src/tx_validator/archive_cache.ts +0 -28
  135. package/src/tx_validator/gas_validator.ts +0 -101
  136. package/src/tx_validator/nullifier_cache.ts +0 -30
  137. package/src/tx_validator/phases_validator.ts +0 -98
  138. package/src/tx_validator/test_utils.ts +0 -48
  139. package/src/tx_validator/tx_validator_factory.ts +0 -120
@@ -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 currentMinFees: 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
- * 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
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
51
66
  */
52
- public async getCurrentBaseFees(): Promise<GasFees> {
67
+ private async computeCurrentMinFees(): 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(BigInt(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.getManaMinFeeAt(timestamp, true));
80
+ }
81
+
82
+ public async getCurrentMinFees(): 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 min fees
87
+ if (this.currentL1BlockNumber === undefined || blockNumber > this.currentL1BlockNumber) {
88
+ this.currentL1BlockNumber = blockNumber;
89
+ this.currentMinFees = this.currentMinFees.then(() => this.computeCurrentMinFees());
90
+ }
91
+ return this.currentMinFees;
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
- }
86
-
87
- const timestamp = await this.rollupContract.read.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
+ }
88
117
 
89
- const slotFr = new Fr(slotNumber);
90
- const timestampFr = new Fr(timestamp);
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;
91
125
 
92
- // We can skip much of the logic in getCurrentBaseFees since it we already check that we are not within a slot elsewhere.
93
- const gasFees = new GasFees(Fr.ZERO, new Fr(await this.rollupContract.read.getManaBaseFeeAt([timestamp, true])));
126
+ const timestamp = getTimestampForSlot(slotNumber, {
127
+ slotDuration: this.aztecSlotDuration,
128
+ l1GenesisTime: this.l1GenesisTime,
129
+ });
94
130
 
95
- const globalVariables = new GlobalVariables(
96
- chainId,
97
- version,
98
- blockNumber,
99
- slotFr,
100
- timestampFr,
101
- coinbase,
102
- feeRecipient,
103
- gasFees,
104
- );
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));
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,12 @@
1
1
  export * from './client/index.js';
2
2
  export * from './config.js';
3
3
  export * from './publisher/index.js';
4
- export * from './tx_validator/tx_validator_factory.js';
5
- export * from './slasher/index.js';
6
- export { Sequencer, SequencerState, getDefaultAllowedSetupFunctions } from './sequencer/index.js';
4
+ export {
5
+ FullNodeBlockBuilder as BlockBuilder,
6
+ Sequencer,
7
+ SequencerState,
8
+ type SequencerEvents,
9
+ } from './sequencer/index.js';
7
10
 
8
11
  // Used by the node to simulate public parts of transactions. Should these be moved to a shared library?
9
12
  // 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';
@@ -0,0 +1,92 @@
1
+ import { EthAddress } from '@aztec/aztec.js/addresses';
2
+ import { type Logger, createLogger } from '@aztec/aztec.js/log';
3
+ import type { BlobClientInterface } from '@aztec/blob-client/client';
4
+ import type { EpochCache } from '@aztec/epoch-cache';
5
+ import type { GovernanceProposerContract, RollupContract } from '@aztec/ethereum/contracts';
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';
9
+ import type { DateProvider } from '@aztec/foundation/timer';
10
+ import type { SlashFactoryContract } from '@aztec/stdlib/l1-contracts';
11
+ import type { TelemetryClient } from '@aztec/telemetry-client';
12
+ import { NodeKeystoreAdapter } from '@aztec/validator-client';
13
+
14
+ import type { SequencerClientConfig } from '../config.js';
15
+ import { SequencerPublisherMetrics } from './sequencer-publisher-metrics.js';
16
+ import { type Action, SequencerPublisher } from './sequencer-publisher.js';
17
+
18
+ export type AttestorPublisherPair = {
19
+ attestorAddress: EthAddress;
20
+ publisher: SequencerPublisher;
21
+ };
22
+
23
+ export class SequencerPublisherFactory {
24
+ private publisherMetrics: SequencerPublisherMetrics;
25
+
26
+ /** Stores the last slot in which every action was carried out by a publisher */
27
+ private lastActions: Partial<Record<Action, SlotNumber>> = {};
28
+
29
+ private logger: Logger;
30
+
31
+ constructor(
32
+ private sequencerConfig: SequencerClientConfig,
33
+ private deps: {
34
+ telemetry: TelemetryClient;
35
+ publisherManager: PublisherManager<L1TxUtilsWithBlobs>;
36
+ blobClient: BlobClientInterface;
37
+ dateProvider: DateProvider;
38
+ epochCache: EpochCache;
39
+ rollupContract: RollupContract;
40
+ governanceProposerContract: GovernanceProposerContract;
41
+ slashFactoryContract: SlashFactoryContract;
42
+ nodeKeyStore: NodeKeystoreAdapter;
43
+ logger?: Logger;
44
+ },
45
+ ) {
46
+ this.publisherMetrics = new SequencerPublisherMetrics(deps.telemetry, 'SequencerPublisher');
47
+ this.logger = deps.logger ?? createLogger('sequencer');
48
+ }
49
+ /**
50
+ * Creates a new SequencerPublisher instance.
51
+ * @param _validatorAddress - The address of the validator that will be using the publisher.
52
+ * @returns A new SequencerPublisher instance.
53
+ */
54
+ public async create(validatorAddress?: EthAddress): Promise<AttestorPublisherPair> {
55
+ // If we have been given an attestor address we must only allow publishers permitted for that attestor
56
+
57
+ const allowedPublishers = !validatorAddress ? [] : this.deps.nodeKeyStore.getPublisherAddresses(validatorAddress);
58
+ const filter: PublisherFilter<L1TxUtilsWithBlobs> = !validatorAddress
59
+ ? () => true
60
+ : (utils: L1TxUtilsWithBlobs) => {
61
+ const publisherAddress = utils.getSenderAddress();
62
+ return allowedPublishers.some(allowedPublisher => allowedPublisher.equals(publisherAddress));
63
+ };
64
+
65
+ const l1Publisher = await this.deps.publisherManager.getAvailablePublisher(filter);
66
+ const attestorAddress =
67
+ validatorAddress ?? this.deps.nodeKeyStore.getAttestorForPublisher(l1Publisher.getSenderAddress());
68
+
69
+ const rollup = this.deps.rollupContract;
70
+ const slashingProposerContract = await rollup.getSlashingProposer();
71
+
72
+ const publisher = new SequencerPublisher(this.sequencerConfig, {
73
+ l1TxUtils: l1Publisher,
74
+ telemetry: this.deps.telemetry,
75
+ blobClient: this.deps.blobClient,
76
+ rollupContract: this.deps.rollupContract,
77
+ epochCache: this.deps.epochCache,
78
+ governanceProposerContract: this.deps.governanceProposerContract,
79
+ slashingProposerContract,
80
+ slashFactoryContract: this.deps.slashFactoryContract,
81
+ dateProvider: this.deps.dateProvider,
82
+ metrics: this.publisherMetrics,
83
+ lastActions: this.lastActions,
84
+ log: this.logger.createChild('publisher'),
85
+ });
86
+
87
+ return {
88
+ attestorAddress,
89
+ publisher,
90
+ };
91
+ }
92
+ }
@@ -1,5 +1,5 @@
1
- import { createLogger } from '@aztec/aztec.js';
2
- import type { L1PublishBlockStats, L1PublishStats } from '@aztec/stdlib/stats';
1
+ import { createLogger } from '@aztec/aztec.js/log';
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';
@@ -24,6 +23,7 @@ export class SequencerPublisherMetrics {
24
23
  private txCalldataGas: Histogram;
25
24
  private txBlobDataGasUsed: Histogram;
26
25
  private txBlobDataGasCost: Histogram;
26
+ private txTotalFee: Histogram;
27
27
 
28
28
  private readonly blobCountHistogram: Histogram;
29
29
  private readonly blobInclusionBlocksHistogram: Histogram;
@@ -39,77 +39,33 @@ export class SequencerPublisherMetrics {
39
39
  ) {
40
40
  const meter = client.getMeter(name);
41
41
 
42
- this.gasPrice = meter.createHistogram(Metrics.L1_PUBLISHER_GAS_PRICE, {
43
- description: 'The gas price used for transactions',
44
- unit: 'gwei',
45
- valueType: ValueType.DOUBLE,
46
- });
42
+ this.gasPrice = meter.createHistogram(Metrics.L1_PUBLISHER_GAS_PRICE);
47
43
 
48
- this.txCount = meter.createUpDownCounter(Metrics.L1_PUBLISHER_TX_COUNT, {
49
- description: 'The number of transactions processed',
50
- });
44
+ this.txCount = meter.createUpDownCounter(Metrics.L1_PUBLISHER_TX_COUNT);
51
45
 
52
- this.txDuration = meter.createHistogram(Metrics.L1_PUBLISHER_TX_DURATION, {
53
- description: 'The duration of transaction processing',
54
- unit: 'ms',
55
- valueType: ValueType.INT,
56
- });
46
+ this.txDuration = meter.createHistogram(Metrics.L1_PUBLISHER_TX_DURATION);
57
47
 
58
- this.txGas = meter.createHistogram(Metrics.L1_PUBLISHER_TX_GAS, {
59
- description: 'The gas consumed by transactions',
60
- unit: 'gas',
61
- valueType: ValueType.INT,
62
- });
48
+ this.txGas = meter.createHistogram(Metrics.L1_PUBLISHER_TX_GAS);
63
49
 
64
- this.txCalldataSize = meter.createHistogram(Metrics.L1_PUBLISHER_TX_CALLDATA_SIZE, {
65
- description: 'The size of the calldata in transactions',
66
- unit: 'By',
67
- valueType: ValueType.INT,
68
- });
50
+ this.txCalldataSize = meter.createHistogram(Metrics.L1_PUBLISHER_TX_CALLDATA_SIZE);
69
51
 
70
- this.txCalldataGas = meter.createHistogram(Metrics.L1_PUBLISHER_TX_CALLDATA_GAS, {
71
- description: 'The gas consumed by the calldata in transactions',
72
- unit: 'gas',
73
- valueType: ValueType.INT,
74
- });
52
+ this.txCalldataGas = meter.createHistogram(Metrics.L1_PUBLISHER_TX_CALLDATA_GAS);
75
53
 
76
- this.txBlobDataGasUsed = meter.createHistogram(Metrics.L1_PUBLISHER_TX_BLOBDATA_GAS_USED, {
77
- description: 'The amount of blob gas used in transactions',
78
- unit: 'gas',
79
- valueType: ValueType.INT,
80
- });
54
+ this.txBlobDataGasUsed = meter.createHistogram(Metrics.L1_PUBLISHER_TX_BLOBDATA_GAS_USED);
81
55
 
82
- this.txBlobDataGasCost = meter.createHistogram(Metrics.L1_PUBLISHER_TX_BLOBDATA_GAS_COST, {
83
- description: 'The gas cost of blobs in transactions',
84
- unit: 'gwei',
85
- valueType: ValueType.INT,
86
- });
56
+ this.txBlobDataGasCost = meter.createHistogram(Metrics.L1_PUBLISHER_TX_BLOBDATA_GAS_COST);
87
57
 
88
- this.blobCountHistogram = meter.createHistogram(Metrics.L1_PUBLISHER_BLOB_COUNT, {
89
- description: 'Number of blobs in L1 transactions',
90
- unit: 'blobs',
91
- valueType: ValueType.INT,
92
- });
58
+ this.blobCountHistogram = meter.createHistogram(Metrics.L1_PUBLISHER_BLOB_COUNT);
93
59
 
94
- this.blobInclusionBlocksHistogram = meter.createHistogram(Metrics.L1_PUBLISHER_BLOB_INCLUSION_BLOCKS, {
95
- description: 'Number of L1 blocks between blob tx submission and inclusion',
96
- unit: 'blocks',
97
- valueType: ValueType.INT,
98
- });
60
+ this.blobInclusionBlocksHistogram = meter.createHistogram(Metrics.L1_PUBLISHER_BLOB_INCLUSION_BLOCKS);
99
61
 
100
- this.blobTxSuccessCounter = meter.createUpDownCounter(Metrics.L1_PUBLISHER_BLOB_TX_SUCCESS, {
101
- description: 'Number of successful L1 transactions with blobs',
102
- });
62
+ this.blobTxSuccessCounter = meter.createUpDownCounter(Metrics.L1_PUBLISHER_BLOB_TX_SUCCESS);
103
63
 
104
- this.blobTxFailureCounter = meter.createUpDownCounter(Metrics.L1_PUBLISHER_BLOB_TX_FAILURE, {
105
- description: 'Number of failed L1 transactions with blobs',
106
- });
64
+ this.blobTxFailureCounter = meter.createUpDownCounter(Metrics.L1_PUBLISHER_BLOB_TX_FAILURE);
107
65
 
108
- this.senderBalance = meter.createGauge(Metrics.L1_PUBLISHER_BALANCE, {
109
- unit: 'eth',
110
- description: 'The balance of the sender address',
111
- valueType: ValueType.DOUBLE,
112
- });
66
+ this.txTotalFee = meter.createHistogram(Metrics.L1_PUBLISHER_TX_TOTAL_FEE);
67
+
68
+ this.senderBalance = meter.createGauge(Metrics.L1_PUBLISHER_BALANCE);
113
69
  }
114
70
 
115
71
  recordFailedTx(txType: L1TxType) {
@@ -123,7 +79,7 @@ export class SequencerPublisherMetrics {
123
79
  }
124
80
  }
125
81
 
126
- recordProcessBlockTx(durationMs: number, stats: L1PublishBlockStats) {
82
+ recordProcessBlockTx(durationMs: number, stats: L1PublishCheckpointStats) {
127
83
  this.recordTx('process', durationMs, stats);
128
84
 
129
85
  if (stats.blobCount && stats.blobCount > 0) {
@@ -169,7 +125,17 @@ export class SequencerPublisherMetrics {
169
125
 
170
126
  try {
171
127
  this.gasPrice.record(parseInt(formatEther(stats.gasPrice, 'gwei'), 10));
172
- } catch (e) {
128
+ } catch {
129
+ // ignore
130
+ }
131
+
132
+ const executionFee = stats.gasUsed * stats.gasPrice;
133
+ const blobFee = stats.blobGasUsed * stats.blobDataGas;
134
+ const totalFee = executionFee + blobFee;
135
+
136
+ try {
137
+ this.txTotalFee.record(parseFloat(formatEther(totalFee)));
138
+ } catch {
173
139
  // ignore
174
140
  }
175
141
  }