@aztec/sequencer-client 0.0.1-commit.f2ce05ee → 0.0.1-commit.f5a9928

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 (133) hide show
  1. package/README.md +283 -21
  2. package/dest/client/sequencer-client.d.ts +34 -11
  3. package/dest/client/sequencer-client.d.ts.map +1 -1
  4. package/dest/client/sequencer-client.js +77 -39
  5. package/dest/config.d.ts +34 -5
  6. package/dest/config.d.ts.map +1 -1
  7. package/dest/config.js +103 -39
  8. package/dest/global_variable_builder/fee_predictor.d.ts +37 -0
  9. package/dest/global_variable_builder/fee_predictor.d.ts.map +1 -0
  10. package/dest/global_variable_builder/fee_predictor.js +138 -0
  11. package/dest/global_variable_builder/fee_provider.d.ts +21 -0
  12. package/dest/global_variable_builder/fee_provider.d.ts.map +1 -0
  13. package/dest/global_variable_builder/fee_provider.js +80 -0
  14. package/dest/global_variable_builder/global_builder.d.ts +13 -28
  15. package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
  16. package/dest/global_variable_builder/global_builder.js +9 -66
  17. package/dest/global_variable_builder/index.d.ts +4 -2
  18. package/dest/global_variable_builder/index.d.ts.map +1 -1
  19. package/dest/global_variable_builder/index.js +2 -0
  20. package/dest/publisher/config.d.ts +51 -17
  21. package/dest/publisher/config.d.ts.map +1 -1
  22. package/dest/publisher/config.js +131 -42
  23. package/dest/publisher/index.d.ts +2 -1
  24. package/dest/publisher/index.d.ts.map +1 -1
  25. package/dest/publisher/l1_to_l2_messaging.d.ts +21 -0
  26. package/dest/publisher/l1_to_l2_messaging.d.ts.map +1 -0
  27. package/dest/publisher/l1_to_l2_messaging.js +70 -0
  28. package/dest/publisher/l1_tx_failed_store/factory.d.ts +11 -0
  29. package/dest/publisher/l1_tx_failed_store/factory.d.ts.map +1 -0
  30. package/dest/publisher/l1_tx_failed_store/factory.js +22 -0
  31. package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts +58 -0
  32. package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts.map +1 -0
  33. package/dest/publisher/l1_tx_failed_store/failed_tx_store.js +1 -0
  34. package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts +15 -0
  35. package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts.map +1 -0
  36. package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.js +34 -0
  37. package/dest/publisher/l1_tx_failed_store/index.d.ts +4 -0
  38. package/dest/publisher/l1_tx_failed_store/index.d.ts.map +1 -0
  39. package/dest/publisher/l1_tx_failed_store/index.js +2 -0
  40. package/dest/publisher/sequencer-bundle-simulator.d.ts +96 -0
  41. package/dest/publisher/sequencer-bundle-simulator.d.ts.map +1 -0
  42. package/dest/publisher/sequencer-bundle-simulator.js +198 -0
  43. package/dest/publisher/sequencer-publisher-factory.d.ts +11 -5
  44. package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -1
  45. package/dest/publisher/sequencer-publisher-factory.js +27 -3
  46. package/dest/publisher/sequencer-publisher.d.ts +112 -71
  47. package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
  48. package/dest/publisher/sequencer-publisher.js +571 -392
  49. package/dest/publisher/write_json.d.ts +11 -0
  50. package/dest/publisher/write_json.d.ts.map +1 -0
  51. package/dest/publisher/write_json.js +57 -0
  52. package/dest/sequencer/automine/automine_factory.d.ts +56 -0
  53. package/dest/sequencer/automine/automine_factory.d.ts.map +1 -0
  54. package/dest/sequencer/automine/automine_factory.js +85 -0
  55. package/dest/sequencer/automine/automine_sequencer.d.ts +189 -0
  56. package/dest/sequencer/automine/automine_sequencer.d.ts.map +1 -0
  57. package/dest/sequencer/automine/automine_sequencer.js +696 -0
  58. package/dest/sequencer/automine/index.d.ts +3 -0
  59. package/dest/sequencer/automine/index.d.ts.map +1 -0
  60. package/dest/sequencer/automine/index.js +2 -0
  61. package/dest/sequencer/checkpoint_proposal_job.d.ts +75 -19
  62. package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -1
  63. package/dest/sequencer/checkpoint_proposal_job.js +886 -264
  64. package/dest/sequencer/checkpoint_proposal_job_metrics.d.ts +34 -0
  65. package/dest/sequencer/checkpoint_proposal_job_metrics.d.ts.map +1 -0
  66. package/dest/sequencer/checkpoint_proposal_job_metrics.js +72 -0
  67. package/dest/sequencer/checkpoint_voter.d.ts +1 -2
  68. package/dest/sequencer/checkpoint_voter.d.ts.map +1 -1
  69. package/dest/sequencer/checkpoint_voter.js +2 -5
  70. package/dest/sequencer/errors.d.ts +1 -8
  71. package/dest/sequencer/errors.d.ts.map +1 -1
  72. package/dest/sequencer/errors.js +0 -9
  73. package/dest/sequencer/events.d.ts +62 -5
  74. package/dest/sequencer/events.d.ts.map +1 -1
  75. package/dest/sequencer/metrics.d.ts +23 -8
  76. package/dest/sequencer/metrics.d.ts.map +1 -1
  77. package/dest/sequencer/metrics.js +117 -21
  78. package/dest/sequencer/requests_tracker.d.ts +22 -0
  79. package/dest/sequencer/requests_tracker.d.ts.map +1 -0
  80. package/dest/sequencer/requests_tracker.js +33 -0
  81. package/dest/sequencer/sequencer.d.ts +181 -44
  82. package/dest/sequencer/sequencer.d.ts.map +1 -1
  83. package/dest/sequencer/sequencer.js +635 -218
  84. package/dest/sequencer/types.d.ts +2 -2
  85. package/dest/sequencer/types.d.ts.map +1 -1
  86. package/dest/test/index.d.ts +5 -7
  87. package/dest/test/index.d.ts.map +1 -1
  88. package/dest/test/mock_checkpoint_builder.d.ts +11 -11
  89. package/dest/test/mock_checkpoint_builder.d.ts.map +1 -1
  90. package/dest/test/mock_checkpoint_builder.js +45 -34
  91. package/dest/test/utils.d.ts +17 -3
  92. package/dest/test/utils.d.ts.map +1 -1
  93. package/dest/test/utils.js +28 -9
  94. package/package.json +28 -28
  95. package/src/client/sequencer-client.ts +110 -47
  96. package/src/config.ts +126 -44
  97. package/src/global_variable_builder/README.md +44 -0
  98. package/src/global_variable_builder/fee_predictor.ts +182 -0
  99. package/src/global_variable_builder/fee_provider.ts +97 -0
  100. package/src/global_variable_builder/global_builder.ts +20 -89
  101. package/src/global_variable_builder/index.ts +3 -1
  102. package/src/publisher/config.ts +173 -40
  103. package/src/publisher/index.ts +3 -0
  104. package/src/publisher/l1_to_l2_messaging.ts +85 -0
  105. package/src/publisher/l1_tx_failed_store/factory.ts +32 -0
  106. package/src/publisher/l1_tx_failed_store/failed_tx_store.ts +57 -0
  107. package/src/publisher/l1_tx_failed_store/file_store_failed_tx_store.ts +46 -0
  108. package/src/publisher/l1_tx_failed_store/index.ts +3 -0
  109. package/src/publisher/sequencer-bundle-simulator.ts +254 -0
  110. package/src/publisher/sequencer-publisher-factory.ts +38 -9
  111. package/src/publisher/sequencer-publisher.ts +667 -484
  112. package/src/publisher/write_json.ts +78 -0
  113. package/src/sequencer/automine/README.md +60 -0
  114. package/src/sequencer/automine/automine_factory.ts +152 -0
  115. package/src/sequencer/automine/automine_sequencer.ts +800 -0
  116. package/src/sequencer/automine/index.ts +6 -0
  117. package/src/sequencer/checkpoint_proposal_job.ts +1073 -290
  118. package/src/sequencer/checkpoint_proposal_job_metrics.ts +128 -0
  119. package/src/sequencer/checkpoint_voter.ts +1 -12
  120. package/src/sequencer/errors.ts +0 -15
  121. package/src/sequencer/events.ts +66 -5
  122. package/src/sequencer/metrics.ts +138 -26
  123. package/src/sequencer/requests_tracker.ts +43 -0
  124. package/src/sequencer/sequencer.ts +745 -243
  125. package/src/sequencer/types.ts +1 -1
  126. package/src/test/index.ts +4 -6
  127. package/src/test/mock_checkpoint_builder.ts +63 -49
  128. package/src/test/utils.ts +64 -10
  129. package/dest/sequencer/timetable.d.ts +0 -87
  130. package/dest/sequencer/timetable.d.ts.map +0 -1
  131. package/dest/sequencer/timetable.js +0 -223
  132. package/src/sequencer/README.md +0 -531
  133. package/src/sequencer/timetable.ts +0 -283
@@ -5,28 +5,48 @@ import {
5
5
  type ConfigMappingsType,
6
6
  SecretValue,
7
7
  booleanConfigHelper,
8
- getConfigFromMappings,
8
+ numberConfigHelper,
9
9
  } from '@aztec/foundation/config';
10
10
  import { EthAddress } from '@aztec/foundation/eth-address';
11
11
 
12
- /**
13
- * The configuration of the rollup transaction publisher.
14
- */
12
+ import { parseEther } from 'viem';
13
+
14
+ /** Configuration of the transaction publisher. */
15
15
  export type TxSenderConfig = L1ReaderConfig & {
16
- /**
17
- * The private key to be used by the publisher.
18
- */
16
+ /** The private key to be used by the publisher. */
19
17
  publisherPrivateKeys?: SecretValue<`0x${string}`>[];
20
18
 
21
- /**
22
- * Publisher addresses to be used with a remote signer
23
- */
19
+ /** Publisher addresses to be used with a remote signer */
24
20
  publisherAddresses?: EthAddress[];
25
21
  };
26
22
 
27
- /**
28
- * Configuration of the L1Publisher.
29
- */
23
+ export type ProverTxSenderConfig = L1ReaderConfig & {
24
+ proverPublisherPrivateKeys?: SecretValue<`0x${string}`>[];
25
+ proverPublisherAddresses?: EthAddress[];
26
+ };
27
+
28
+ export type SequencerTxSenderConfig = L1ReaderConfig & {
29
+ sequencerPublisherPrivateKeys?: SecretValue<`0x${string}`>[];
30
+ sequencerPublisherAddresses?: EthAddress[];
31
+ };
32
+
33
+ export function getTxSenderConfigFromProverConfig(config: ProverTxSenderConfig): TxSenderConfig {
34
+ return {
35
+ ...config,
36
+ publisherPrivateKeys: config.proverPublisherPrivateKeys,
37
+ publisherAddresses: config.proverPublisherAddresses,
38
+ };
39
+ }
40
+
41
+ export function getTxSenderConfigFromSequencerConfig(config: SequencerTxSenderConfig): TxSenderConfig {
42
+ return {
43
+ ...config,
44
+ publisherPrivateKeys: config.sequencerPublisherPrivateKeys,
45
+ publisherAddresses: config.sequencerPublisherAddresses,
46
+ };
47
+ }
48
+
49
+ /** Configuration of the L1Publisher. */
30
50
  export type PublisherConfig = L1TxUtilsConfig &
31
51
  BlobClientConfig & {
32
52
  /** True to use publishers in invalid states (timed out, cancelled, etc) if no other is available */
@@ -35,37 +55,117 @@ export type PublisherConfig = L1TxUtilsConfig &
35
55
  fishermanMode?: boolean;
36
56
  /** Address of the forwarder contract to wrap all L1 transactions through (for testing purposes only) */
37
57
  publisherForwarderAddress?: EthAddress;
58
+ /** Store for failed L1 transaction inputs (test networks only). Format: gs://bucket/path */
59
+ l1TxFailedStore?: string;
60
+ /** Min ETH balance below which a publisher gets funded. Undefined = funding disabled. */
61
+ publisherFundingThreshold?: bigint;
62
+ /** Amount of ETH to send when funding a publisher. Undefined = funding disabled. */
63
+ publisherFundingAmount?: bigint;
64
+ };
65
+
66
+ /** Shared config mappings for publisher funding, used by both sequencer and prover publisher configs. */
67
+ const publisherFundingConfigMappings = {
68
+ publisherFundingThreshold: {
69
+ env: 'PUBLISHER_FUNDING_THRESHOLD' as const,
70
+ description:
71
+ 'Min ETH balance below which a publisher gets funded. Specified in ether (e.g. 0.1). Unset = funding disabled.',
72
+ parseEnv: (val: string) => parseEther(val),
73
+ },
74
+ publisherFundingAmount: {
75
+ env: 'PUBLISHER_FUNDING_AMOUNT' as const,
76
+ description:
77
+ 'Amount of ETH to send when funding a publisher. Specified in ether (e.g. 0.5). Unset = funding disabled.',
78
+ parseEnv: (val: string) => parseEther(val),
79
+ },
80
+ };
81
+
82
+ export type ProverPublisherConfig = L1TxUtilsConfig &
83
+ BlobClientConfig & {
84
+ fishermanMode?: boolean;
85
+ proverPublisherAllowInvalidStates?: boolean;
86
+ proverPublisherForwarderAddress?: EthAddress;
87
+ /** Min ETH balance below which a publisher gets funded. Undefined = funding disabled. */
88
+ publisherFundingThreshold?: bigint;
89
+ /** Amount of ETH to send when funding a publisher. Undefined = funding disabled. */
90
+ publisherFundingAmount?: bigint;
91
+ };
92
+
93
+ export type SequencerPublisherConfig = L1TxUtilsConfig &
94
+ BlobClientConfig & {
95
+ fishermanMode?: boolean;
96
+ sequencerPublisherAllowInvalidStates?: boolean;
97
+ sequencerPublisherForwarderAddress?: EthAddress;
98
+ /** How long to wait for the previous L1 block before sending scheduled publisher txs anyway. */
99
+ sequencerPublisherPreviousL1BlockWaitTimeoutMs: number;
100
+ /** Poll interval while waiting for the previous L1 block before scheduled publisher txs. */
101
+ sequencerPublisherPreviousL1BlockWaitPollIntervalMs: number;
102
+ /** Store for failed L1 transaction inputs (test networks only). Format: gs://bucket/path */
103
+ l1TxFailedStore?: string;
104
+ /** Min ETH balance below which a publisher gets funded. Undefined = funding disabled. */
105
+ publisherFundingThreshold?: bigint;
106
+ /** Amount of ETH to send when funding a publisher. Undefined = funding disabled. */
107
+ publisherFundingAmount?: bigint;
108
+ };
109
+
110
+ export function getPublisherConfigFromProverConfig(config: ProverPublisherConfig): PublisherConfig {
111
+ return {
112
+ ...config,
113
+ publisherAllowInvalidStates: config.proverPublisherAllowInvalidStates,
114
+ publisherForwarderAddress: config.proverPublisherForwarderAddress,
115
+ };
116
+ }
117
+
118
+ export function getPublisherConfigFromSequencerConfig(config: SequencerPublisherConfig): PublisherConfig {
119
+ return {
120
+ ...config,
121
+ publisherAllowInvalidStates: config.sequencerPublisherAllowInvalidStates,
122
+ publisherForwarderAddress: config.sequencerPublisherForwarderAddress,
123
+ l1TxFailedStore: config.l1TxFailedStore,
38
124
  };
125
+ }
39
126
 
40
- export const getTxSenderConfigMappings: (
41
- scope: 'PROVER' | 'SEQ',
42
- ) => ConfigMappingsType<Omit<TxSenderConfig, 'l1Contracts'>> = (scope: 'PROVER' | 'SEQ') => ({
127
+ export const proverTxSenderConfigMappings: ConfigMappingsType<ProverTxSenderConfig> = {
43
128
  ...l1ReaderConfigMappings,
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', '')}`)),
129
+ proverPublisherPrivateKeys: {
130
+ env: `PROVER_PUBLISHER_PRIVATE_KEYS`,
131
+ description: 'The private keys to be used by the prover publisher.',
132
+ parseEnv: (val: string) =>
133
+ val.split(',').map(key => new SecretValue(`0x${key.replace('0x', '')}` as `0x${string}`)),
48
134
  defaultValue: [],
49
- fallback: [scope === 'PROVER' ? `PROVER_PUBLISHER_PRIVATE_KEY` : `SEQ_PUBLISHER_PRIVATE_KEY`],
135
+ fallback: [`PROVER_PUBLISHER_PRIVATE_KEY`],
50
136
  },
51
- publisherAddresses: {
52
- env: scope === 'PROVER' ? `PROVER_PUBLISHER_ADDRESSES` : `SEQ_PUBLISHER_ADDRESSES`,
137
+ proverPublisherAddresses: {
138
+ env: `PROVER_PUBLISHER_ADDRESSES`,
53
139
  description: 'The addresses of the publishers to use with remote signers',
54
140
  parseEnv: (val: string) => val.split(',').map(address => EthAddress.fromString(address)),
55
141
  defaultValue: [],
56
142
  },
57
- });
143
+ };
58
144
 
59
- export function getTxSenderConfigFromEnv(scope: 'PROVER' | 'SEQ'): Omit<TxSenderConfig, 'l1Contracts'> {
60
- return getConfigFromMappings(getTxSenderConfigMappings(scope));
61
- }
145
+ export const sequencerTxSenderConfigMappings: ConfigMappingsType<SequencerTxSenderConfig> = {
146
+ ...l1ReaderConfigMappings,
147
+ sequencerPublisherPrivateKeys: {
148
+ env: `SEQ_PUBLISHER_PRIVATE_KEYS`,
149
+ description: 'The private keys to be used by the sequencer publisher.',
150
+ parseEnv: (val: string) =>
151
+ val.split(',').map(key => new SecretValue(`0x${key.replace('0x', '')}` as `0x${string}`)),
152
+ defaultValue: [],
153
+ fallback: [`SEQ_PUBLISHER_PRIVATE_KEY`],
154
+ },
155
+ sequencerPublisherAddresses: {
156
+ env: `SEQ_PUBLISHER_ADDRESSES`,
157
+ description: 'The addresses of the publishers to use with remote signers',
158
+ parseEnv: (val: string) => val.split(',').map(address => EthAddress.fromString(address)),
159
+ defaultValue: [],
160
+ },
161
+ };
62
162
 
63
- export const getPublisherConfigMappings: (
64
- scope: 'PROVER' | 'SEQ',
65
- ) => ConfigMappingsType<PublisherConfig & L1TxUtilsConfig> = scope => ({
66
- publisherAllowInvalidStates: {
163
+ export const sequencerPublisherConfigMappings: ConfigMappingsType<SequencerPublisherConfig & L1TxUtilsConfig> = {
164
+ ...l1TxUtilsConfigMappings,
165
+ ...blobClientConfigMapping,
166
+ sequencerPublisherAllowInvalidStates: {
167
+ env: `SEQ_PUBLISHER_ALLOW_INVALID_STATES`,
67
168
  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
169
  ...booleanConfigHelper(true),
70
170
  },
71
171
  fishermanMode: {
@@ -74,15 +174,48 @@ export const getPublisherConfigMappings: (
74
174
  'Whether to run in fisherman mode: builds blocks on every slot for validation without publishing to L1',
75
175
  ...booleanConfigHelper(false),
76
176
  },
77
- publisherForwarderAddress: {
78
- env: scope === `PROVER` ? `PROVER_PUBLISHER_FORWARDER_ADDRESS` : `SEQ_PUBLISHER_FORWARDER_ADDRESS`,
177
+ sequencerPublisherForwarderAddress: {
178
+ env: `SEQ_PUBLISHER_FORWARDER_ADDRESS`,
79
179
  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),
180
+ parseEnv: (val: string) => EthAddress.fromString(val),
181
+ },
182
+ sequencerPublisherPreviousL1BlockWaitTimeoutMs: {
183
+ env: `SEQ_PUBLISHER_PREVIOUS_L1_BLOCK_WAIT_TIMEOUT_MS`,
184
+ description:
185
+ 'How long to wait for the previous L1 block before sending scheduled publisher txs anyway, in milliseconds.',
186
+ ...numberConfigHelper(8_000),
187
+ },
188
+ sequencerPublisherPreviousL1BlockWaitPollIntervalMs: {
189
+ env: `SEQ_PUBLISHER_PREVIOUS_L1_BLOCK_WAIT_POLL_INTERVAL_MS`,
190
+ description:
191
+ 'Poll interval while waiting for the previous L1 block before scheduled publisher txs, in milliseconds.',
192
+ ...numberConfigHelper(500),
193
+ },
194
+ l1TxFailedStore: {
195
+ env: 'L1_TX_FAILED_STORE',
196
+ description: 'Store for failed L1 transaction inputs (test networks only). Format: gs://bucket/path',
81
197
  },
198
+ ...publisherFundingConfigMappings,
199
+ };
200
+
201
+ export const proverPublisherConfigMappings: ConfigMappingsType<ProverPublisherConfig & L1TxUtilsConfig> = {
82
202
  ...l1TxUtilsConfigMappings,
83
203
  ...blobClientConfigMapping,
84
- });
85
-
86
- export function getPublisherConfigFromEnv(scope: 'PROVER' | 'SEQ'): PublisherConfig {
87
- return getConfigFromMappings(getPublisherConfigMappings(scope));
88
- }
204
+ proverPublisherAllowInvalidStates: {
205
+ env: `PROVER_PUBLISHER_ALLOW_INVALID_STATES`,
206
+ description: 'True to use publishers in invalid states (timed out, cancelled, etc) if no other is available',
207
+ ...booleanConfigHelper(true),
208
+ },
209
+ fishermanMode: {
210
+ env: 'FISHERMAN_MODE',
211
+ description:
212
+ 'Whether to run in fisherman mode: builds blocks on every slot for validation without publishing to L1',
213
+ ...booleanConfigHelper(false),
214
+ },
215
+ proverPublisherForwarderAddress: {
216
+ env: `PROVER_PUBLISHER_FORWARDER_ADDRESS`,
217
+ description: 'Address of the forwarder contract to wrap all L1 transactions through (for testing purposes only)',
218
+ parseEnv: (val: string) => EthAddress.fromString(val),
219
+ },
220
+ ...publisherFundingConfigMappings,
221
+ };
@@ -3,3 +3,6 @@ export { SequencerPublisherFactory } from './sequencer-publisher-factory.js';
3
3
 
4
4
  // Used for tests
5
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,85 @@
1
+ import { RollupContract } from '@aztec/ethereum/contracts';
2
+ import type { L1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
3
+ import type { ExtendedViemWalletClient } from '@aztec/ethereum/types';
4
+ import { Fr } from '@aztec/foundation/curves/bn254';
5
+ import { tryJsonStringify } from '@aztec/foundation/json-rpc';
6
+ import { createLogger } from '@aztec/foundation/log';
7
+ import { InboxAbi } from '@aztec/l1-artifacts';
8
+ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
9
+
10
+ import { decodeEventLog, getContract } from 'viem';
11
+
12
+ /**
13
+ * Sends an L1-to-L2 message via the Inbox contract and returns its hash and global leaf index.
14
+ * Test helper copied from the end-to-end fixtures so this integration test can live in sequencer-client.
15
+ */
16
+ export async function sendL1ToL2Message(
17
+ message: { recipient: AztecAddress; content: Fr; secretHash: Fr },
18
+ ctx: {
19
+ l1Client: ExtendedViemWalletClient;
20
+ l1ContractAddresses: Pick<L1ContractAddresses, 'inboxAddress' | 'rollupAddress'>;
21
+ },
22
+ ) {
23
+ const logger = createLogger('sequencer-client:l1_to_l2_messaging');
24
+ const inbox = getContract({
25
+ address: ctx.l1ContractAddresses.inboxAddress.toString(),
26
+ abi: InboxAbi,
27
+ client: ctx.l1Client,
28
+ });
29
+
30
+ const { recipient, content, secretHash } = message;
31
+
32
+ const version = await new RollupContract(ctx.l1Client, ctx.l1ContractAddresses.rollupAddress.toString()).getVersion();
33
+
34
+ // We inject the message to Inbox
35
+ const txHash = await inbox.write.sendL2Message(
36
+ [{ actor: recipient.toString(), version: BigInt(version) }, content.toString(), secretHash.toString()],
37
+ {
38
+ gas: 1_000_000n,
39
+ },
40
+ );
41
+ logger.info(`L1 to L2 message sent in tx ${txHash}`);
42
+
43
+ // We check that the message was correctly injected by checking the emitted event
44
+ const txReceipt = await ctx.l1Client.waitForTransactionReceipt({ hash: txHash });
45
+
46
+ if (txReceipt.status !== 'success') {
47
+ throw new Error(`L1 to L2 message failed to be sent in tx ${txHash}. Status: ${txReceipt.status}`);
48
+ }
49
+
50
+ logger.info(`L1 to L2 message receipt retrieved for tx ${txReceipt.transactionHash}`, txReceipt);
51
+
52
+ if (txReceipt.transactionHash !== txHash) {
53
+ throw new Error(`Receipt transaction hash mismatch: ${txReceipt.transactionHash} !== ${txHash}`);
54
+ }
55
+
56
+ // Filter for MessageSent events from the Inbox contract by trying to decode each log
57
+ const messageSentLogs = txReceipt.logs
58
+ .filter(log => log.address.toLowerCase() === ctx.l1ContractAddresses.inboxAddress.toString().toLowerCase())
59
+ .map(log => {
60
+ try {
61
+ const decoded = decodeEventLog({
62
+ abi: InboxAbi,
63
+ data: log.data,
64
+ topics: log.topics,
65
+ });
66
+ return { log, decoded };
67
+ } catch {
68
+ return null; // Not a decodable event from this ABI
69
+ }
70
+ })
71
+ .filter((item): item is { log: any; decoded: any } => item !== null && item.decoded.eventName === 'MessageSent');
72
+
73
+ if (messageSentLogs.length !== 1) {
74
+ throw new Error(
75
+ `Wrong number of MessageSent logs found in ${txHash} transaction (got ${messageSentLogs.length} expected 1)\n${tryJsonStringify(messageSentLogs.map(item => item.log))}`,
76
+ );
77
+ }
78
+
79
+ // We already have the decoded event
80
+ const topics = messageSentLogs[0].decoded;
81
+ const receivedMsgHash = topics.args.hash;
82
+ const receivedGlobalLeafIndex = topics.args.index;
83
+
84
+ return { msgHash: Fr.fromHexString(receivedMsgHash), globalLeafIndex: new Fr(receivedGlobalLeafIndex), txReceipt };
85
+ }
@@ -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,57 @@
1
+ import type { Branded } from '@aztec/foundation/branded-types';
2
+
3
+ import type { Hex } from 'viem';
4
+
5
+ /** URI pointing to a stored failed L1 transaction. */
6
+ export type FailedL1TxUri = Branded<string, 'FailedL1TxUri'>;
7
+
8
+ /** A failed L1 transaction captured for debugging and replay. */
9
+ export type FailedL1Tx = {
10
+ /** Tx hash (for reverts) or keccak256(request.data) (for simulation/send failures). */
11
+ id: Hex;
12
+ /** Unix timestamp (ms) when failure occurred. */
13
+ timestamp: number;
14
+ /** Whether the failure was during simulation or after sending. */
15
+ failureType: 'simulation' | 'revert' | 'send-error';
16
+ /** The actual L1 transaction for replay (multicall-encoded for bundled txs). */
17
+ request: {
18
+ to: Hex;
19
+ data: Hex;
20
+ value?: string; // bigint as string
21
+ };
22
+ /** Raw blob data as hex for replay. */
23
+ blobData?: Hex[];
24
+ /** L1 block number at time of failure (simulation target or receipt block). */
25
+ l1BlockNumber: string; // bigint as string
26
+ /** Receipt info (present only for on-chain reverts). */
27
+ receipt?: {
28
+ transactionHash: Hex;
29
+ blockNumber: string; // bigint as string
30
+ gasUsed: string; // bigint as string
31
+ status: 'reverted';
32
+ };
33
+ /** Error information. */
34
+ error: {
35
+ message: string;
36
+ /** Decoded error name (e.g., 'Rollup__InvalidProposer'). */
37
+ name?: string;
38
+ };
39
+ /** Context metadata. */
40
+ context: {
41
+ /** Actions involved (e.g., ['propose', 'governance-signal']). */
42
+ actions: string[];
43
+ /** Individual request data for each action (metadata, not used for replay). */
44
+ requests?: Array<{ action: string; to: Hex; data: Hex }>;
45
+ checkpointNumber?: number;
46
+ slot?: number;
47
+ sender: Hex;
48
+ };
49
+ };
50
+
51
+ /** Store for failed L1 transactions for debugging purposes. */
52
+ export interface L1TxFailedStore {
53
+ /** Saves a failed transaction and returns its URI. */
54
+ saveFailedTx(tx: FailedL1Tx): Promise<FailedL1TxUri>;
55
+ /** Retrieves a failed transaction by its URI. */
56
+ getFailedTx(uri: FailedL1TxUri): Promise<FailedL1Tx>;
57
+ }
@@ -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';