@aztec/sequencer-client 0.0.0-test.0 → 0.0.1-commit.001888fc

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 (151) hide show
  1. package/dest/client/index.d.ts +1 -1
  2. package/dest/client/sequencer-client.d.ts +50 -33
  3. package/dest/client/sequencer-client.d.ts.map +1 -1
  4. package/dest/client/sequencer-client.js +164 -57
  5. package/dest/config.d.ts +35 -17
  6. package/dest/config.d.ts.map +1 -1
  7. package/dest/config.js +150 -81
  8. package/dest/global_variable_builder/global_builder.d.ts +24 -15
  9. package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
  10. package/dest/global_variable_builder/global_builder.js +63 -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 +48 -27
  16. package/dest/publisher/config.d.ts.map +1 -1
  17. package/dest/publisher/config.js +109 -32
  18. package/dest/publisher/index.d.ts +4 -1
  19. package/dest/publisher/index.d.ts.map +1 -1
  20. package/dest/publisher/index.js +3 -0
  21. package/dest/publisher/l1_tx_failed_store/factory.d.ts +11 -0
  22. package/dest/publisher/l1_tx_failed_store/factory.d.ts.map +1 -0
  23. package/dest/publisher/l1_tx_failed_store/factory.js +22 -0
  24. package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts +59 -0
  25. package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts.map +1 -0
  26. package/dest/publisher/l1_tx_failed_store/failed_tx_store.js +1 -0
  27. package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts +15 -0
  28. package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts.map +1 -0
  29. package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.js +34 -0
  30. package/dest/publisher/l1_tx_failed_store/index.d.ts +4 -0
  31. package/dest/publisher/l1_tx_failed_store/index.d.ts.map +1 -0
  32. package/dest/publisher/l1_tx_failed_store/index.js +2 -0
  33. package/dest/publisher/sequencer-publisher-factory.d.ts +52 -0
  34. package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -0
  35. package/dest/publisher/sequencer-publisher-factory.js +76 -0
  36. package/dest/publisher/sequencer-publisher-metrics.d.ts +5 -4
  37. package/dest/publisher/sequencer-publisher-metrics.d.ts.map +1 -1
  38. package/dest/publisher/sequencer-publisher-metrics.js +34 -62
  39. package/dest/publisher/sequencer-publisher.d.ts +158 -93
  40. package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
  41. package/dest/publisher/sequencer-publisher.js +1452 -255
  42. package/dest/sequencer/checkpoint_proposal_job.d.ts +100 -0
  43. package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -0
  44. package/dest/sequencer/checkpoint_proposal_job.js +1240 -0
  45. package/dest/sequencer/checkpoint_voter.d.ts +35 -0
  46. package/dest/sequencer/checkpoint_voter.d.ts.map +1 -0
  47. package/dest/sequencer/checkpoint_voter.js +109 -0
  48. package/dest/sequencer/config.d.ts +7 -1
  49. package/dest/sequencer/config.d.ts.map +1 -1
  50. package/dest/sequencer/errors.d.ts +11 -0
  51. package/dest/sequencer/errors.d.ts.map +1 -0
  52. package/dest/sequencer/errors.js +15 -0
  53. package/dest/sequencer/events.d.ts +46 -0
  54. package/dest/sequencer/events.d.ts.map +1 -0
  55. package/dest/sequencer/events.js +1 -0
  56. package/dest/sequencer/index.d.ts +4 -2
  57. package/dest/sequencer/index.d.ts.map +1 -1
  58. package/dest/sequencer/index.js +3 -1
  59. package/dest/sequencer/metrics.d.ts +60 -12
  60. package/dest/sequencer/metrics.d.ts.map +1 -1
  61. package/dest/sequencer/metrics.js +283 -67
  62. package/dest/sequencer/sequencer.d.ts +157 -135
  63. package/dest/sequencer/sequencer.d.ts.map +1 -1
  64. package/dest/sequencer/sequencer.js +966 -523
  65. package/dest/sequencer/timetable.d.ts +75 -25
  66. package/dest/sequencer/timetable.d.ts.map +1 -1
  67. package/dest/sequencer/timetable.js +174 -62
  68. package/dest/sequencer/types.d.ts +3 -0
  69. package/dest/sequencer/types.d.ts.map +1 -0
  70. package/dest/sequencer/types.js +1 -0
  71. package/dest/sequencer/utils.d.ts +20 -38
  72. package/dest/sequencer/utils.d.ts.map +1 -1
  73. package/dest/sequencer/utils.js +12 -47
  74. package/dest/test/index.d.ts +9 -3
  75. package/dest/test/index.d.ts.map +1 -1
  76. package/dest/test/index.js +0 -4
  77. package/dest/test/mock_checkpoint_builder.d.ts +99 -0
  78. package/dest/test/mock_checkpoint_builder.d.ts.map +1 -0
  79. package/dest/test/mock_checkpoint_builder.js +231 -0
  80. package/dest/test/utils.d.ts +53 -0
  81. package/dest/test/utils.d.ts.map +1 -0
  82. package/dest/test/utils.js +104 -0
  83. package/package.json +46 -45
  84. package/src/client/sequencer-client.ts +220 -104
  85. package/src/config.ts +172 -96
  86. package/src/global_variable_builder/global_builder.ts +85 -55
  87. package/src/index.ts +1 -3
  88. package/src/publisher/config.ts +150 -59
  89. package/src/publisher/index.ts +7 -0
  90. package/src/publisher/l1_tx_failed_store/factory.ts +32 -0
  91. package/src/publisher/l1_tx_failed_store/failed_tx_store.ts +55 -0
  92. package/src/publisher/l1_tx_failed_store/file_store_failed_tx_store.ts +46 -0
  93. package/src/publisher/l1_tx_failed_store/index.ts +3 -0
  94. package/src/publisher/sequencer-publisher-factory.ts +124 -0
  95. package/src/publisher/sequencer-publisher-metrics.ts +33 -63
  96. package/src/publisher/sequencer-publisher.ts +1266 -311
  97. package/src/sequencer/README.md +531 -0
  98. package/src/sequencer/checkpoint_proposal_job.ts +967 -0
  99. package/src/sequencer/checkpoint_voter.ts +130 -0
  100. package/src/sequencer/config.ts +8 -0
  101. package/src/sequencer/errors.ts +21 -0
  102. package/src/sequencer/events.ts +27 -0
  103. package/src/sequencer/index.ts +3 -1
  104. package/src/sequencer/metrics.ts +362 -73
  105. package/src/sequencer/sequencer.ts +712 -586
  106. package/src/sequencer/timetable.ts +224 -64
  107. package/src/sequencer/types.ts +6 -0
  108. package/src/sequencer/utils.ts +28 -60
  109. package/src/test/index.ts +11 -5
  110. package/src/test/mock_checkpoint_builder.ts +323 -0
  111. package/src/test/utils.ts +167 -0
  112. package/dest/sequencer/allowed.d.ts +0 -3
  113. package/dest/sequencer/allowed.d.ts.map +0 -1
  114. package/dest/sequencer/allowed.js +0 -27
  115. package/dest/slasher/factory.d.ts +0 -7
  116. package/dest/slasher/factory.d.ts.map +0 -1
  117. package/dest/slasher/factory.js +0 -8
  118. package/dest/slasher/index.d.ts +0 -3
  119. package/dest/slasher/index.d.ts.map +0 -1
  120. package/dest/slasher/index.js +0 -2
  121. package/dest/slasher/slasher_client.d.ts +0 -75
  122. package/dest/slasher/slasher_client.d.ts.map +0 -1
  123. package/dest/slasher/slasher_client.js +0 -132
  124. package/dest/tx_validator/archive_cache.d.ts +0 -14
  125. package/dest/tx_validator/archive_cache.d.ts.map +0 -1
  126. package/dest/tx_validator/archive_cache.js +0 -22
  127. package/dest/tx_validator/gas_validator.d.ts +0 -14
  128. package/dest/tx_validator/gas_validator.d.ts.map +0 -1
  129. package/dest/tx_validator/gas_validator.js +0 -78
  130. package/dest/tx_validator/nullifier_cache.d.ts +0 -16
  131. package/dest/tx_validator/nullifier_cache.d.ts.map +0 -1
  132. package/dest/tx_validator/nullifier_cache.js +0 -24
  133. package/dest/tx_validator/phases_validator.d.ts +0 -12
  134. package/dest/tx_validator/phases_validator.d.ts.map +0 -1
  135. package/dest/tx_validator/phases_validator.js +0 -80
  136. package/dest/tx_validator/test_utils.d.ts +0 -23
  137. package/dest/tx_validator/test_utils.d.ts.map +0 -1
  138. package/dest/tx_validator/test_utils.js +0 -26
  139. package/dest/tx_validator/tx_validator_factory.d.ts +0 -18
  140. package/dest/tx_validator/tx_validator_factory.d.ts.map +0 -1
  141. package/dest/tx_validator/tx_validator_factory.js +0 -50
  142. package/src/sequencer/allowed.ts +0 -36
  143. package/src/slasher/factory.ts +0 -15
  144. package/src/slasher/index.ts +0 -2
  145. package/src/slasher/slasher_client.ts +0 -193
  146. package/src/tx_validator/archive_cache.ts +0 -28
  147. package/src/tx_validator/gas_validator.ts +0 -101
  148. package/src/tx_validator/nullifier_cache.ts +0 -30
  149. package/src/tx_validator/phases_validator.ts +0 -98
  150. package/src/tx_validator/test_utils.ts +0 -48
  151. package/src/tx_validator/tx_validator_factory.ts +0 -120
@@ -1,75 +1,166 @@
1
- import { type BlobSinkConfig, blobSinkConfigMapping } from '@aztec/blob-sink/client';
2
- 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';
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';
4
+ import { type ConfigMappingsType, SecretValue, booleanConfigHelper } from '@aztec/foundation/config';
10
5
  import { EthAddress } from '@aztec/foundation/eth-address';
11
6
 
12
- /**
13
- * The configuration of the rollup transaction publisher.
14
- */
7
+ /** Configuration of the transaction publisher. */
15
8
  export type TxSenderConfig = L1ReaderConfig & {
16
- /**
17
- * The private key to be used by the publisher.
18
- */
19
- publisherPrivateKey: `0x${string}`;
9
+ /** The private key to be used by the publisher. */
10
+ publisherPrivateKeys?: SecretValue<`0x${string}`>[];
20
11
 
21
- /**
22
- * The address of the custom forwarder contract.
23
- */
24
- customForwarderContractAddress: EthAddress;
12
+ /** Publisher addresses to be used with a remote signer */
13
+ publisherAddresses?: EthAddress[];
25
14
  };
26
15
 
27
- /**
28
- * Configuration of the L1Publisher.
29
- */
16
+ export type ProverTxSenderConfig = L1ReaderConfig & {
17
+ proverPublisherPrivateKeys?: SecretValue<`0x${string}`>[];
18
+ proverPublisherAddresses?: EthAddress[];
19
+ };
20
+
21
+ export type SequencerTxSenderConfig = L1ReaderConfig & {
22
+ sequencerPublisherPrivateKeys?: SecretValue<`0x${string}`>[];
23
+ sequencerPublisherAddresses?: EthAddress[];
24
+ };
25
+
26
+ export function getTxSenderConfigFromProverConfig(config: ProverTxSenderConfig): TxSenderConfig {
27
+ return {
28
+ ...config,
29
+ publisherPrivateKeys: config.proverPublisherPrivateKeys,
30
+ publisherAddresses: config.proverPublisherAddresses,
31
+ };
32
+ }
33
+
34
+ export function getTxSenderConfigFromSequencerConfig(config: SequencerTxSenderConfig): TxSenderConfig {
35
+ return {
36
+ ...config,
37
+ publisherPrivateKeys: config.sequencerPublisherPrivateKeys,
38
+ publisherAddresses: config.sequencerPublisherAddresses,
39
+ };
40
+ }
41
+
42
+ /** Configuration of the L1Publisher. */
30
43
  export type PublisherConfig = L1TxUtilsConfig &
31
- BlobSinkConfig & {
32
- /**
33
- * The interval to wait between publish retries.
34
- */
35
- l1PublishRetryIntervalMS: number;
44
+ BlobClientConfig & {
45
+ /** True to use publishers in invalid states (timed out, cancelled, etc) if no other is available */
46
+ publisherAllowInvalidStates?: boolean;
47
+ /** Whether to run in fisherman mode: builds blocks on every slot for validation without publishing to L1 */
48
+ fishermanMode?: boolean;
49
+ /** Address of the forwarder contract to wrap all L1 transactions through (for testing purposes only) */
50
+ publisherForwarderAddress?: EthAddress;
51
+ /** Store for failed L1 transaction inputs (test networks only). Format: gs://bucket/path */
52
+ l1TxFailedStore?: string;
53
+ };
54
+
55
+ export type ProverPublisherConfig = L1TxUtilsConfig &
56
+ BlobClientConfig & {
57
+ fishermanMode?: boolean;
58
+ proverPublisherAllowInvalidStates?: boolean;
59
+ proverPublisherForwarderAddress?: EthAddress;
60
+ };
61
+
62
+ export type SequencerPublisherConfig = L1TxUtilsConfig &
63
+ BlobClientConfig & {
64
+ fishermanMode?: boolean;
65
+ sequencerPublisherAllowInvalidStates?: boolean;
66
+ sequencerPublisherForwarderAddress?: EthAddress;
67
+ /** Store for failed L1 transaction inputs (test networks only). Format: gs://bucket/path */
68
+ l1TxFailedStore?: string;
69
+ };
70
+
71
+ export function getPublisherConfigFromProverConfig(config: ProverPublisherConfig): PublisherConfig {
72
+ return {
73
+ ...config,
74
+ publisherAllowInvalidStates: config.proverPublisherAllowInvalidStates,
75
+ publisherForwarderAddress: config.proverPublisherForwarderAddress,
76
+ };
77
+ }
78
+
79
+ export function getPublisherConfigFromSequencerConfig(config: SequencerPublisherConfig): PublisherConfig {
80
+ return {
81
+ ...config,
82
+ publisherAllowInvalidStates: config.sequencerPublisherAllowInvalidStates,
83
+ publisherForwarderAddress: config.sequencerPublisherForwarderAddress,
84
+ l1TxFailedStore: config.l1TxFailedStore,
36
85
  };
86
+ }
37
87
 
38
- export const getTxSenderConfigMappings: (
39
- scope: 'PROVER' | 'SEQ',
40
- ) => ConfigMappingsType<Omit<TxSenderConfig, 'l1Contracts'>> = (scope: 'PROVER' | 'SEQ') => ({
88
+ export const proverTxSenderConfigMappings: ConfigMappingsType<Omit<ProverTxSenderConfig, 'l1Contracts'>> = {
41
89
  ...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,
90
+ proverPublisherPrivateKeys: {
91
+ env: `PROVER_PUBLISHER_PRIVATE_KEYS`,
92
+ description: 'The private keys to be used by the prover publisher.',
93
+ parseEnv: (val: string) => val.split(',').map(key => new SecretValue(`0x${key.replace('0x', '')}`)),
94
+ defaultValue: [],
95
+ fallback: [`PROVER_PUBLISHER_PRIVATE_KEY`],
47
96
  },
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,
97
+ proverPublisherAddresses: {
98
+ env: `PROVER_PUBLISHER_ADDRESSES`,
99
+ description: 'The addresses of the publishers to use with remote signers',
100
+ parseEnv: (val: string) => val.split(',').map(address => EthAddress.fromString(address)),
101
+ defaultValue: [],
53
102
  },
54
- });
55
-
56
- export function getTxSenderConfigFromEnv(scope: 'PROVER' | 'SEQ'): Omit<TxSenderConfig, 'l1Contracts'> {
57
- return getConfigFromMappings(getTxSenderConfigMappings(scope));
58
- }
103
+ };
59
104
 
60
- export const getPublisherConfigMappings: (
61
- scope: 'PROVER' | 'SEQ',
62
- ) => 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.',
105
+ export const sequencerTxSenderConfigMappings: ConfigMappingsType<Omit<SequencerTxSenderConfig, 'l1Contracts'>> = {
106
+ ...l1ReaderConfigMappings,
107
+ sequencerPublisherPrivateKeys: {
108
+ env: `SEQ_PUBLISHER_PRIVATE_KEYS`,
109
+ description: 'The private keys to be used by the sequencer publisher.',
110
+ parseEnv: (val: string) => val.split(',').map(key => new SecretValue(`0x${key.replace('0x', '')}`)),
111
+ defaultValue: [],
112
+ fallback: [`SEQ_PUBLISHER_PRIVATE_KEY`],
68
113
  },
114
+ sequencerPublisherAddresses: {
115
+ env: `SEQ_PUBLISHER_ADDRESSES`,
116
+ description: 'The addresses of the publishers to use with remote signers',
117
+ parseEnv: (val: string) => val.split(',').map(address => EthAddress.fromString(address)),
118
+ defaultValue: [],
119
+ },
120
+ };
121
+
122
+ export const sequencerPublisherConfigMappings: ConfigMappingsType<SequencerPublisherConfig & L1TxUtilsConfig> = {
69
123
  ...l1TxUtilsConfigMappings,
70
- ...blobSinkConfigMapping,
71
- });
124
+ ...blobClientConfigMapping,
125
+ sequencerPublisherAllowInvalidStates: {
126
+ env: `SEQ_PUBLISHER_ALLOW_INVALID_STATES`,
127
+ description: 'True to use publishers in invalid states (timed out, cancelled, etc) if no other is available',
128
+ ...booleanConfigHelper(true),
129
+ },
130
+ fishermanMode: {
131
+ env: 'FISHERMAN_MODE',
132
+ description:
133
+ 'Whether to run in fisherman mode: builds blocks on every slot for validation without publishing to L1',
134
+ ...booleanConfigHelper(false),
135
+ },
136
+ sequencerPublisherForwarderAddress: {
137
+ env: `SEQ_PUBLISHER_FORWARDER_ADDRESS`,
138
+ description: 'Address of the forwarder contract to wrap all L1 transactions through (for testing purposes only)',
139
+ parseEnv: (val: string) => (val ? EthAddress.fromString(val) : undefined),
140
+ },
141
+ l1TxFailedStore: {
142
+ env: 'L1_TX_FAILED_STORE',
143
+ description: 'Store for failed L1 transaction inputs (test networks only). Format: gs://bucket/path',
144
+ },
145
+ };
72
146
 
73
- export function getPublisherConfigFromEnv(scope: 'PROVER' | 'SEQ'): PublisherConfig {
74
- return getConfigFromMappings(getPublisherConfigMappings(scope));
75
- }
147
+ export const proverPublisherConfigMappings: ConfigMappingsType<ProverPublisherConfig & L1TxUtilsConfig> = {
148
+ ...l1TxUtilsConfigMappings,
149
+ ...blobClientConfigMapping,
150
+ proverPublisherAllowInvalidStates: {
151
+ env: `PROVER_PUBLISHER_ALLOW_INVALID_STATES`,
152
+ description: 'True to use publishers in invalid states (timed out, cancelled, etc) if no other is available',
153
+ ...booleanConfigHelper(true),
154
+ },
155
+ fishermanMode: {
156
+ env: 'FISHERMAN_MODE',
157
+ description:
158
+ 'Whether to run in fisherman mode: builds blocks on every slot for validation without publishing to L1',
159
+ ...booleanConfigHelper(false),
160
+ },
161
+ proverPublisherForwarderAddress: {
162
+ env: `PROVER_PUBLISHER_FORWARDER_ADDRESS`,
163
+ description: 'Address of the forwarder contract to wrap all L1 transactions through (for testing purposes only)',
164
+ parseEnv: (val: string) => (val ? EthAddress.fromString(val) : undefined),
165
+ },
166
+ };
@@ -1 +1,8 @@
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';
6
+
7
+ // Failed L1 tx store (optional, for test networks)
8
+ export { type FailedL1Tx, type FailedL1TxUri, type L1TxFailedStore } from './l1_tx_failed_store/index.js';
@@ -0,0 +1,32 @@
1
+ import { type Logger, createLogger } from '@aztec/foundation/log';
2
+ import { createFileStore } from '@aztec/stdlib/file-store';
3
+
4
+ import type { L1TxFailedStore } from './failed_tx_store.js';
5
+ import { FileStoreL1TxFailedStore } from './file_store_failed_tx_store.js';
6
+
7
+ /**
8
+ * Creates an L1TxFailedStore from a config string.
9
+ * Supports any backend that FileStore supports (GCS, S3, R2, local filesystem).
10
+ * @param config - Config string (e.g., 'gs://bucket/path', 's3://bucket/path', 'file:///path'). If undefined, returns undefined.
11
+ * @param logger - Optional logger.
12
+ * @returns The store instance, or undefined if config is not provided.
13
+ */
14
+ export async function createL1TxFailedStore(
15
+ config: string | undefined,
16
+ logger: Logger = createLogger('sequencer:l1-tx-failed-store'),
17
+ ): Promise<L1TxFailedStore | undefined> {
18
+ if (!config) {
19
+ return undefined;
20
+ }
21
+
22
+ const fileStore = await createFileStore(config, logger);
23
+ if (!fileStore) {
24
+ throw new Error(
25
+ `Failed to create file store from config: '${config}'. ` +
26
+ `Supported formats: 'gs://bucket/path', 's3://bucket/path', 'file:///path'.`,
27
+ );
28
+ }
29
+
30
+ logger.info(`Created L1 tx failed store`, { config });
31
+ return new FileStoreL1TxFailedStore(fileStore, logger);
32
+ }
@@ -0,0 +1,55 @@
1
+ import type { Hex } from 'viem';
2
+
3
+ /** URI pointing to a stored failed L1 transaction. */
4
+ export type FailedL1TxUri = string & { __brand: 'FailedL1TxUri' };
5
+
6
+ /** A failed L1 transaction captured for debugging and replay. */
7
+ export type FailedL1Tx = {
8
+ /** Tx hash (for reverts) or keccak256(request.data) (for simulation/send failures). */
9
+ id: Hex;
10
+ /** Unix timestamp (ms) when failure occurred. */
11
+ timestamp: number;
12
+ /** Whether the failure was during simulation or after sending. */
13
+ failureType: 'simulation' | 'revert' | 'send-error';
14
+ /** The actual L1 transaction for replay (multicall-encoded for bundled txs). */
15
+ request: {
16
+ to: Hex;
17
+ data: Hex;
18
+ value?: string; // bigint as string
19
+ };
20
+ /** Raw blob data as hex for replay. */
21
+ blobData?: Hex[];
22
+ /** L1 block number at time of failure (simulation target or receipt block). */
23
+ l1BlockNumber: string; // bigint as string
24
+ /** Receipt info (present only for on-chain reverts). */
25
+ receipt?: {
26
+ transactionHash: Hex;
27
+ blockNumber: string; // bigint as string
28
+ gasUsed: string; // bigint as string
29
+ status: 'reverted';
30
+ };
31
+ /** Error information. */
32
+ error: {
33
+ message: string;
34
+ /** Decoded error name (e.g., 'Rollup__InvalidProposer'). */
35
+ name?: string;
36
+ };
37
+ /** Context metadata. */
38
+ context: {
39
+ /** Actions involved (e.g., ['propose', 'governance-signal']). */
40
+ actions: string[];
41
+ /** Individual request data for each action (metadata, not used for replay). */
42
+ requests?: Array<{ action: string; to: Hex; data: Hex }>;
43
+ checkpointNumber?: number;
44
+ slot?: number;
45
+ sender: Hex;
46
+ };
47
+ };
48
+
49
+ /** Store for failed L1 transactions for debugging purposes. */
50
+ export interface L1TxFailedStore {
51
+ /** Saves a failed transaction and returns its URI. */
52
+ saveFailedTx(tx: FailedL1Tx): Promise<FailedL1TxUri>;
53
+ /** Retrieves a failed transaction by its URI. */
54
+ getFailedTx(uri: FailedL1TxUri): Promise<FailedL1Tx>;
55
+ }
@@ -0,0 +1,46 @@
1
+ import { type Logger, createLogger } from '@aztec/foundation/log';
2
+ import type { FileStore } from '@aztec/stdlib/file-store';
3
+
4
+ import type { FailedL1Tx, FailedL1TxUri, L1TxFailedStore } from './failed_tx_store.js';
5
+
6
+ /**
7
+ * L1TxFailedStore implementation using the FileStore abstraction.
8
+ * Supports any backend that FileStore supports (GCS, S3, R2, local filesystem).
9
+ */
10
+ export class FileStoreL1TxFailedStore implements L1TxFailedStore {
11
+ private readonly log: Logger;
12
+
13
+ constructor(
14
+ private readonly fileStore: FileStore,
15
+ logger?: Logger,
16
+ ) {
17
+ this.log = logger ?? createLogger('sequencer:l1-tx-failed-store');
18
+ }
19
+
20
+ public async saveFailedTx(tx: FailedL1Tx): Promise<FailedL1TxUri> {
21
+ const prefix = tx.receipt ? 'tx' : 'data';
22
+ const path = `${tx.failureType}/${prefix}-${tx.id}.json`;
23
+ const json = JSON.stringify(tx, null, 2);
24
+
25
+ const uri = await this.fileStore.save(path, Buffer.from(json), {
26
+ metadata: {
27
+ 'content-type': 'application/json',
28
+ actions: tx.context.actions.join(','),
29
+ 'failure-type': tx.failureType,
30
+ },
31
+ });
32
+
33
+ this.log.info(`Saved failed L1 tx to ${uri}`, {
34
+ id: tx.id,
35
+ failureType: tx.failureType,
36
+ actions: tx.context.actions.join(','),
37
+ });
38
+
39
+ return uri as FailedL1TxUri;
40
+ }
41
+
42
+ public async getFailedTx(uri: FailedL1TxUri): Promise<FailedL1Tx> {
43
+ const data = await this.fileStore.read(uri);
44
+ return JSON.parse(data.toString()) as FailedL1Tx;
45
+ }
46
+ }
@@ -0,0 +1,3 @@
1
+ export { type FailedL1Tx, type FailedL1TxUri, type L1TxFailedStore } from './failed_tx_store.js';
2
+ export { createL1TxFailedStore } from './factory.js';
3
+ export { FileStoreL1TxFailedStore } from './file_store_failed_tx_store.js';
@@ -0,0 +1,124 @@
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 { L1TxUtils } from '@aztec/ethereum/l1-tx-utils';
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 nodeKeyStore: NodeKeystoreAdapter;
30
+
31
+ private logger: Logger;
32
+
33
+ constructor(
34
+ private sequencerConfig: SequencerClientConfig,
35
+ private deps: {
36
+ telemetry: TelemetryClient;
37
+ publisherManager: PublisherManager<L1TxUtils>;
38
+ blobClient: BlobClientInterface;
39
+ dateProvider: DateProvider;
40
+ epochCache: EpochCache;
41
+ rollupContract: RollupContract;
42
+ governanceProposerContract: GovernanceProposerContract;
43
+ slashFactoryContract: SlashFactoryContract;
44
+ nodeKeyStore: NodeKeystoreAdapter;
45
+ logger?: Logger;
46
+ },
47
+ ) {
48
+ this.publisherMetrics = new SequencerPublisherMetrics(deps.telemetry, 'SequencerPublisher');
49
+ this.logger = deps.logger ?? createLogger('sequencer');
50
+ this.nodeKeyStore = this.deps.nodeKeyStore;
51
+ }
52
+
53
+ /**
54
+ * Updates the node keystore adapter used for publisher lookups.
55
+ * Called when the keystore is reloaded at runtime to reflect new validator-publisher mappings.
56
+ */
57
+ public updateNodeKeyStore(adapter: NodeKeystoreAdapter): void {
58
+ this.nodeKeyStore = adapter;
59
+ }
60
+
61
+ /**
62
+ * Creates a new SequencerPublisher instance.
63
+ * @param _validatorAddress - The address of the validator that will be using the publisher.
64
+ * @returns A new SequencerPublisher instance.
65
+ */
66
+ public async create(validatorAddress?: EthAddress): Promise<AttestorPublisherPair> {
67
+ // If we have been given an attestor address we must only allow publishers permitted for that attestor
68
+
69
+ const allowedPublishers = !validatorAddress ? [] : this.nodeKeyStore.getPublisherAddresses(validatorAddress);
70
+ const filter: PublisherFilter<L1TxUtils> = !validatorAddress
71
+ ? () => true
72
+ : (utils: L1TxUtils) => {
73
+ const publisherAddress = utils.getSenderAddress();
74
+ return allowedPublishers.some(allowedPublisher => allowedPublisher.equals(publisherAddress));
75
+ };
76
+
77
+ const l1Publisher = await this.deps.publisherManager.getAvailablePublisher(filter);
78
+ const attestorAddress =
79
+ validatorAddress ?? this.nodeKeyStore.getAttestorForPublisher(l1Publisher.getSenderAddress());
80
+
81
+ const rollup = this.deps.rollupContract;
82
+ const slashingProposerContract = await rollup.getSlashingProposer();
83
+
84
+ const getNextPublisher = async (excludeAddresses: EthAddress[]): Promise<L1TxUtils | undefined> => {
85
+ const exclusionFilter: PublisherFilter<L1TxUtils> = (utils: L1TxUtils) => {
86
+ if (excludeAddresses.some(addr => addr.equals(utils.getSenderAddress()))) {
87
+ return false;
88
+ }
89
+ return filter(utils);
90
+ };
91
+ try {
92
+ return await this.deps.publisherManager.getAvailablePublisher(exclusionFilter);
93
+ } catch {
94
+ return undefined;
95
+ }
96
+ };
97
+
98
+ const publisher = new SequencerPublisher(this.sequencerConfig, {
99
+ l1TxUtils: l1Publisher,
100
+ getNextPublisher,
101
+ telemetry: this.deps.telemetry,
102
+ blobClient: this.deps.blobClient,
103
+ rollupContract: this.deps.rollupContract,
104
+ epochCache: this.deps.epochCache,
105
+ governanceProposerContract: this.deps.governanceProposerContract,
106
+ slashingProposerContract,
107
+ slashFactoryContract: this.deps.slashFactoryContract,
108
+ dateProvider: this.deps.dateProvider,
109
+ metrics: this.publisherMetrics,
110
+ lastActions: this.lastActions,
111
+ log: this.logger.createChild('publisher'),
112
+ });
113
+
114
+ return {
115
+ attestorAddress,
116
+ publisher,
117
+ };
118
+ }
119
+
120
+ /** Interrupts all publishers managed by this factory. Used during sequencer shutdown. */
121
+ public interruptAll(): void {
122
+ this.deps.publisherManager.interrupt();
123
+ }
124
+ }
@@ -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,7 @@ import {
7
7
  Metrics,
8
8
  type TelemetryClient,
9
9
  type UpDownCounter,
10
- ValueType,
10
+ createUpDownCounterWithDefault,
11
11
  } from '@aztec/telemetry-client';
12
12
 
13
13
  import { formatEther } from 'viem/utils';
@@ -24,6 +24,7 @@ export class SequencerPublisherMetrics {
24
24
  private txCalldataGas: Histogram;
25
25
  private txBlobDataGasUsed: Histogram;
26
26
  private txBlobDataGasCost: Histogram;
27
+ private txTotalFee: Histogram;
27
28
 
28
29
  private readonly blobCountHistogram: Histogram;
29
30
  private readonly blobInclusionBlocksHistogram: Histogram;
@@ -39,77 +40,36 @@ export class SequencerPublisherMetrics {
39
40
  ) {
40
41
  const meter = client.getMeter(name);
41
42
 
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
- });
43
+ this.gasPrice = meter.createHistogram(Metrics.L1_PUBLISHER_GAS_PRICE);
47
44
 
48
- this.txCount = meter.createUpDownCounter(Metrics.L1_PUBLISHER_TX_COUNT, {
49
- description: 'The number of transactions processed',
45
+ this.txCount = createUpDownCounterWithDefault(meter, Metrics.L1_PUBLISHER_TX_COUNT, {
46
+ [Attributes.L1_TX_TYPE]: ['process'],
47
+ [Attributes.OK]: [true, false],
50
48
  });
51
49
 
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
- });
50
+ this.txDuration = meter.createHistogram(Metrics.L1_PUBLISHER_TX_DURATION);
57
51
 
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
- });
52
+ this.txGas = meter.createHistogram(Metrics.L1_PUBLISHER_TX_GAS);
63
53
 
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
- });
54
+ this.txCalldataSize = meter.createHistogram(Metrics.L1_PUBLISHER_TX_CALLDATA_SIZE);
69
55
 
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
- });
56
+ this.txCalldataGas = meter.createHistogram(Metrics.L1_PUBLISHER_TX_CALLDATA_GAS);
75
57
 
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
- });
58
+ this.txBlobDataGasUsed = meter.createHistogram(Metrics.L1_PUBLISHER_TX_BLOBDATA_GAS_USED);
81
59
 
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
- });
60
+ this.txBlobDataGasCost = meter.createHistogram(Metrics.L1_PUBLISHER_TX_BLOBDATA_GAS_COST);
87
61
 
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
- });
62
+ this.blobCountHistogram = meter.createHistogram(Metrics.L1_PUBLISHER_BLOB_COUNT);
93
63
 
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
- });
64
+ this.blobInclusionBlocksHistogram = meter.createHistogram(Metrics.L1_PUBLISHER_BLOB_INCLUSION_BLOCKS);
99
65
 
100
- this.blobTxSuccessCounter = meter.createUpDownCounter(Metrics.L1_PUBLISHER_BLOB_TX_SUCCESS, {
101
- description: 'Number of successful L1 transactions with blobs',
102
- });
66
+ this.blobTxSuccessCounter = createUpDownCounterWithDefault(meter, Metrics.L1_PUBLISHER_BLOB_TX_SUCCESS);
103
67
 
104
- this.blobTxFailureCounter = meter.createUpDownCounter(Metrics.L1_PUBLISHER_BLOB_TX_FAILURE, {
105
- description: 'Number of failed L1 transactions with blobs',
106
- });
68
+ this.blobTxFailureCounter = createUpDownCounterWithDefault(meter, Metrics.L1_PUBLISHER_BLOB_TX_FAILURE);
107
69
 
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
- });
70
+ this.txTotalFee = meter.createHistogram(Metrics.L1_PUBLISHER_TX_TOTAL_FEE);
71
+
72
+ this.senderBalance = meter.createGauge(Metrics.L1_PUBLISHER_BALANCE);
113
73
  }
114
74
 
115
75
  recordFailedTx(txType: L1TxType) {
@@ -123,7 +83,7 @@ export class SequencerPublisherMetrics {
123
83
  }
124
84
  }
125
85
 
126
- recordProcessBlockTx(durationMs: number, stats: L1PublishBlockStats) {
86
+ recordProcessBlockTx(durationMs: number, stats: L1PublishCheckpointStats) {
127
87
  this.recordTx('process', durationMs, stats);
128
88
 
129
89
  if (stats.blobCount && stats.blobCount > 0) {
@@ -169,7 +129,17 @@ export class SequencerPublisherMetrics {
169
129
 
170
130
  try {
171
131
  this.gasPrice.record(parseInt(formatEther(stats.gasPrice, 'gwei'), 10));
172
- } catch (e) {
132
+ } catch {
133
+ // ignore
134
+ }
135
+
136
+ const executionFee = stats.gasUsed * stats.gasPrice;
137
+ const blobFee = stats.blobGasUsed * stats.blobDataGas;
138
+ const totalFee = executionFee + blobFee;
139
+
140
+ try {
141
+ this.txTotalFee.record(parseFloat(formatEther(totalFee)));
142
+ } catch {
173
143
  // ignore
174
144
  }
175
145
  }