@aztec/sequencer-client 0.0.1-commit.9b94fc1 → 0.0.1-commit.9ee6fcc6

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 (118) hide show
  1. package/dest/client/sequencer-client.d.ts +24 -16
  2. package/dest/client/sequencer-client.d.ts.map +1 -1
  3. package/dest/client/sequencer-client.js +73 -32
  4. package/dest/config.d.ts +35 -9
  5. package/dest/config.d.ts.map +1 -1
  6. package/dest/config.js +106 -44
  7. package/dest/global_variable_builder/global_builder.d.ts +27 -14
  8. package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
  9. package/dest/global_variable_builder/global_builder.js +65 -54
  10. package/dest/global_variable_builder/index.d.ts +2 -2
  11. package/dest/global_variable_builder/index.d.ts.map +1 -1
  12. package/dest/index.d.ts +2 -3
  13. package/dest/index.d.ts.map +1 -1
  14. package/dest/index.js +1 -2
  15. package/dest/publisher/config.d.ts +53 -20
  16. package/dest/publisher/config.d.ts.map +1 -1
  17. package/dest/publisher/config.js +124 -39
  18. package/dest/publisher/index.d.ts +2 -1
  19. package/dest/publisher/index.d.ts.map +1 -1
  20. package/dest/publisher/l1_tx_failed_store/factory.d.ts +11 -0
  21. package/dest/publisher/l1_tx_failed_store/factory.d.ts.map +1 -0
  22. package/dest/publisher/l1_tx_failed_store/factory.js +22 -0
  23. package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts +59 -0
  24. package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts.map +1 -0
  25. package/dest/publisher/l1_tx_failed_store/failed_tx_store.js +1 -0
  26. package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts +15 -0
  27. package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts.map +1 -0
  28. package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.js +34 -0
  29. package/dest/publisher/l1_tx_failed_store/index.d.ts +4 -0
  30. package/dest/publisher/l1_tx_failed_store/index.d.ts.map +1 -0
  31. package/dest/publisher/l1_tx_failed_store/index.js +2 -0
  32. package/dest/publisher/sequencer-publisher-factory.d.ts +15 -6
  33. package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -1
  34. package/dest/publisher/sequencer-publisher-factory.js +28 -3
  35. package/dest/publisher/sequencer-publisher-metrics.d.ts +3 -3
  36. package/dest/publisher/sequencer-publisher-metrics.d.ts.map +1 -1
  37. package/dest/publisher/sequencer-publisher-metrics.js +23 -86
  38. package/dest/publisher/sequencer-publisher.d.ts +79 -49
  39. package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
  40. package/dest/publisher/sequencer-publisher.js +932 -155
  41. package/dest/sequencer/checkpoint_proposal_job.d.ts +108 -0
  42. package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -0
  43. package/dest/sequencer/checkpoint_proposal_job.js +1289 -0
  44. package/dest/sequencer/checkpoint_voter.d.ts +35 -0
  45. package/dest/sequencer/checkpoint_voter.d.ts.map +1 -0
  46. package/dest/sequencer/checkpoint_voter.js +109 -0
  47. package/dest/sequencer/config.d.ts +3 -2
  48. package/dest/sequencer/config.d.ts.map +1 -1
  49. package/dest/sequencer/events.d.ts +47 -0
  50. package/dest/sequencer/events.d.ts.map +1 -0
  51. package/dest/sequencer/events.js +1 -0
  52. package/dest/sequencer/index.d.ts +4 -2
  53. package/dest/sequencer/index.d.ts.map +1 -1
  54. package/dest/sequencer/index.js +3 -1
  55. package/dest/sequencer/metrics.d.ts +42 -6
  56. package/dest/sequencer/metrics.d.ts.map +1 -1
  57. package/dest/sequencer/metrics.js +227 -72
  58. package/dest/sequencer/sequencer.d.ts +125 -134
  59. package/dest/sequencer/sequencer.d.ts.map +1 -1
  60. package/dest/sequencer/sequencer.js +754 -652
  61. package/dest/sequencer/timetable.d.ts +54 -16
  62. package/dest/sequencer/timetable.d.ts.map +1 -1
  63. package/dest/sequencer/timetable.js +147 -62
  64. package/dest/sequencer/types.d.ts +3 -0
  65. package/dest/sequencer/types.d.ts.map +1 -0
  66. package/dest/sequencer/types.js +1 -0
  67. package/dest/sequencer/utils.d.ts +14 -8
  68. package/dest/sequencer/utils.d.ts.map +1 -1
  69. package/dest/sequencer/utils.js +7 -4
  70. package/dest/test/index.d.ts +6 -7
  71. package/dest/test/index.d.ts.map +1 -1
  72. package/dest/test/mock_checkpoint_builder.d.ts +95 -0
  73. package/dest/test/mock_checkpoint_builder.d.ts.map +1 -0
  74. package/dest/test/mock_checkpoint_builder.js +231 -0
  75. package/dest/test/utils.d.ts +53 -0
  76. package/dest/test/utils.d.ts.map +1 -0
  77. package/dest/test/utils.js +104 -0
  78. package/package.json +31 -30
  79. package/src/client/sequencer-client.ts +97 -55
  80. package/src/config.ts +124 -53
  81. package/src/global_variable_builder/global_builder.ts +76 -73
  82. package/src/global_variable_builder/index.ts +1 -1
  83. package/src/index.ts +1 -7
  84. package/src/publisher/config.ts +163 -50
  85. package/src/publisher/index.ts +3 -0
  86. package/src/publisher/l1_tx_failed_store/factory.ts +32 -0
  87. package/src/publisher/l1_tx_failed_store/failed_tx_store.ts +55 -0
  88. package/src/publisher/l1_tx_failed_store/file_store_failed_tx_store.ts +46 -0
  89. package/src/publisher/l1_tx_failed_store/index.ts +3 -0
  90. package/src/publisher/sequencer-publisher-factory.ts +43 -10
  91. package/src/publisher/sequencer-publisher-metrics.ts +19 -71
  92. package/src/publisher/sequencer-publisher.ts +635 -200
  93. package/src/sequencer/README.md +531 -0
  94. package/src/sequencer/checkpoint_proposal_job.ts +1049 -0
  95. package/src/sequencer/checkpoint_voter.ts +130 -0
  96. package/src/sequencer/config.ts +2 -1
  97. package/src/sequencer/events.ts +27 -0
  98. package/src/sequencer/index.ts +3 -1
  99. package/src/sequencer/metrics.ts +282 -82
  100. package/src/sequencer/sequencer.ts +521 -859
  101. package/src/sequencer/timetable.ts +178 -83
  102. package/src/sequencer/types.ts +6 -0
  103. package/src/sequencer/utils.ts +18 -9
  104. package/src/test/index.ts +5 -6
  105. package/src/test/mock_checkpoint_builder.ts +323 -0
  106. package/src/test/utils.ts +167 -0
  107. package/dest/sequencer/block_builder.d.ts +0 -27
  108. package/dest/sequencer/block_builder.d.ts.map +0 -1
  109. package/dest/sequencer/block_builder.js +0 -134
  110. package/dest/tx_validator/nullifier_cache.d.ts +0 -14
  111. package/dest/tx_validator/nullifier_cache.d.ts.map +0 -1
  112. package/dest/tx_validator/nullifier_cache.js +0 -24
  113. package/dest/tx_validator/tx_validator_factory.d.ts +0 -17
  114. package/dest/tx_validator/tx_validator_factory.d.ts.map +0 -1
  115. package/dest/tx_validator/tx_validator_factory.js +0 -53
  116. package/src/sequencer/block_builder.ts +0 -222
  117. package/src/tx_validator/nullifier_cache.ts +0 -30
  118. package/src/tx_validator/tx_validator_factory.ts +0 -132
@@ -1,95 +1,94 @@
1
- import {
2
- type L1ContractsConfig,
3
- type L1ReaderConfig,
4
- RollupContract,
5
- type ViemPublicClient,
6
- createEthereumChain,
7
- } from '@aztec/ethereum';
8
- import { SlotNumber } from '@aztec/foundation/branded-types';
1
+ import { RollupContract } from '@aztec/ethereum/contracts';
2
+ import type { L1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
3
+ import type { ViemPublicClient } from '@aztec/ethereum/types';
4
+ import { BlockNumber, SlotNumber } from '@aztec/foundation/branded-types';
5
+ import { Fr } from '@aztec/foundation/curves/bn254';
9
6
  import type { EthAddress } from '@aztec/foundation/eth-address';
10
- import { Fr } from '@aztec/foundation/fields';
11
7
  import { createLogger } from '@aztec/foundation/log';
8
+ import type { DateProvider } from '@aztec/foundation/timer';
12
9
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
10
+ import { type L1RollupConstants, getNextL1SlotTimestamp, getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
13
11
  import { GasFees } from '@aztec/stdlib/gas';
14
- import type { GlobalVariableBuilder as GlobalVariableBuilderInterface } from '@aztec/stdlib/tx';
12
+ import type {
13
+ CheckpointGlobalVariables,
14
+ GlobalVariableBuilder as GlobalVariableBuilderInterface,
15
+ } from '@aztec/stdlib/tx';
15
16
  import { GlobalVariables } from '@aztec/stdlib/tx';
16
17
 
17
- import { createPublicClient, fallback, http } from 'viem';
18
+ /** Configuration for the GlobalVariableBuilder (excludes L1 client config). */
19
+ export type GlobalVariableBuilderConfig = {
20
+ l1Contracts: Pick<L1ContractAddresses, 'rollupAddress'>;
21
+ ethereumSlotDuration: number;
22
+ rollupVersion: bigint;
23
+ } & Pick<L1RollupConstants, 'slotDuration' | 'l1GenesisTime'>;
18
24
 
19
25
  /**
20
26
  * Simple global variables builder.
21
27
  */
22
28
  export class GlobalVariableBuilder implements GlobalVariableBuilderInterface {
23
29
  private log = createLogger('sequencer:global_variable_builder');
24
- private currentBaseFees: Promise<GasFees> = Promise.resolve(new GasFees(0, 0));
30
+ private currentMinFees: Promise<GasFees> = Promise.resolve(new GasFees(0, 0));
25
31
  private currentL1BlockNumber: bigint | undefined = undefined;
26
32
 
27
33
  private readonly rollupContract: RollupContract;
28
- private readonly publicClient: ViemPublicClient;
29
34
  private readonly ethereumSlotDuration: number;
35
+ private readonly aztecSlotDuration: number;
36
+ private readonly l1GenesisTime: bigint;
30
37
 
31
- private chainId?: Fr;
32
- private version?: Fr;
38
+ private chainId: Fr;
39
+ private version: Fr;
33
40
 
34
- constructor(config: L1ReaderConfig & Pick<L1ContractsConfig, 'ethereumSlotDuration'>) {
35
- const { l1RpcUrls, l1ChainId: chainId, l1Contracts } = config;
36
-
37
- const chain = createEthereumChain(l1RpcUrls, chainId);
41
+ constructor(
42
+ private readonly dateProvider: DateProvider,
43
+ private readonly publicClient: ViemPublicClient,
44
+ config: GlobalVariableBuilderConfig,
45
+ ) {
46
+ this.version = new Fr(config.rollupVersion);
47
+ this.chainId = new Fr(this.publicClient.chain!.id);
38
48
 
39
49
  this.ethereumSlotDuration = config.ethereumSlotDuration;
50
+ this.aztecSlotDuration = config.slotDuration;
51
+ this.l1GenesisTime = config.l1GenesisTime;
40
52
 
41
- this.publicClient = createPublicClient({
42
- chain: chain.chainInfo,
43
- transport: fallback(chain.rpcUrls.map(url => http(url))),
44
- pollingInterval: config.viemPollingIntervalMS,
45
- });
46
-
47
- this.rollupContract = new RollupContract(this.publicClient, l1Contracts.rollupAddress);
53
+ this.rollupContract = new RollupContract(this.publicClient, config.l1Contracts.rollupAddress);
48
54
  }
49
55
 
50
56
  /**
51
- * Computes the "current" base fees, e.g., the price that you currently should pay to get include in the next block
52
- * @returns Base fees for the next block
57
+ * Computes the "current" min fees, e.g., the price that you currently should pay to get include in the next block
58
+ * @returns Min fees for the next block
53
59
  */
54
- private async computeCurrentBaseFees(): Promise<GasFees> {
60
+ private async computeCurrentMinFees(): Promise<GasFees> {
55
61
  // Since this might be called in the middle of a slot where a block might have been published,
56
62
  // we need to fetch the last block written, and estimate the earliest timestamp for the next block.
57
63
  // The timestamp of that last block will act as a lower bound for the next block.
58
64
 
59
- const lastBlock = await this.rollupContract.getCheckpoint(await this.rollupContract.getCheckpointNumber());
65
+ const lastCheckpoint = await this.rollupContract.getPendingCheckpoint();
60
66
  const earliestTimestamp = await this.rollupContract.getTimestampForSlot(
61
- SlotNumber.fromBigInt(lastBlock.slotNumber + 1n),
67
+ SlotNumber.fromBigInt(BigInt(lastCheckpoint.slotNumber) + 1n),
62
68
  );
63
- const nextEthTimestamp = BigInt((await this.publicClient.getBlock()).timestamp + BigInt(this.ethereumSlotDuration));
69
+ const nextEthTimestamp = getNextL1SlotTimestamp(this.dateProvider.nowInSeconds(), {
70
+ l1GenesisTime: this.l1GenesisTime,
71
+ ethereumSlotDuration: this.ethereumSlotDuration,
72
+ });
64
73
  const timestamp = earliestTimestamp > nextEthTimestamp ? earliestTimestamp : nextEthTimestamp;
65
74
 
66
- return new GasFees(0, await this.rollupContract.getManaBaseFeeAt(timestamp, true));
75
+ return new GasFees(0, await this.rollupContract.getManaMinFeeAt(timestamp, true));
67
76
  }
68
77
 
69
- public async getCurrentBaseFees(): Promise<GasFees> {
78
+ public async getCurrentMinFees(): Promise<GasFees> {
70
79
  // Get the current block number
71
80
  const blockNumber = await this.publicClient.getBlockNumber();
72
81
 
73
- // If the L1 block number has changed then chain a new promise to get the current base fees
82
+ // If the L1 block number has changed then chain a new promise to get the current min fees
74
83
  if (this.currentL1BlockNumber === undefined || blockNumber > this.currentL1BlockNumber) {
75
84
  this.currentL1BlockNumber = blockNumber;
76
- this.currentBaseFees = this.currentBaseFees.then(() => this.computeCurrentBaseFees());
77
- }
78
- return this.currentBaseFees;
79
- }
80
-
81
- public async getGlobalConstantVariables(): Promise<Pick<GlobalVariables, 'chainId' | 'version'>> {
82
- if (!this.chainId) {
83
- this.chainId = new Fr(this.publicClient.chain.id);
85
+ this.currentMinFees = this.currentMinFees.then(() => this.computeCurrentMinFees());
84
86
  }
85
- if (!this.version) {
86
- this.version = new Fr(await this.rollupContract.getVersion());
87
- }
88
- return { chainId: this.chainId, version: this.version };
87
+ return this.currentMinFees;
89
88
  }
90
89
 
91
90
  /**
92
- * Simple builder of global variables that use the minimum time possible.
91
+ * Simple builder of global variables.
93
92
  * @param blockNumber - The block number to build global variables for.
94
93
  * @param coinbase - The address to receive block reward.
95
94
  * @param feeRecipient - The address to receive fees.
@@ -97,37 +96,41 @@ export class GlobalVariableBuilder implements GlobalVariableBuilderInterface {
97
96
  * @returns The global variables for the given block number.
98
97
  */
99
98
  public async buildGlobalVariables(
100
- blockNumber: number,
99
+ blockNumber: BlockNumber,
101
100
  coinbase: EthAddress,
102
101
  feeRecipient: AztecAddress,
103
- slotNumber?: SlotNumber,
102
+ maybeSlot?: SlotNumber,
104
103
  ): Promise<GlobalVariables> {
105
- const { chainId, version } = await this.getGlobalConstantVariables();
106
-
107
- let slot: SlotNumber;
108
- if (slotNumber === undefined) {
109
- const ts = BigInt((await this.publicClient.getBlock()).timestamp + BigInt(this.ethereumSlotDuration));
110
- slot = await this.rollupContract.getSlotAt(ts);
111
- } else {
112
- slot = slotNumber;
113
- }
104
+ const slot: SlotNumber =
105
+ maybeSlot ??
106
+ (await this.rollupContract.getSlotAt(
107
+ getNextL1SlotTimestamp(this.dateProvider.nowInSeconds(), {
108
+ l1GenesisTime: this.l1GenesisTime,
109
+ ethereumSlotDuration: this.ethereumSlotDuration,
110
+ }),
111
+ ));
112
+
113
+ const checkpointGlobalVariables = await this.buildCheckpointGlobalVariables(coinbase, feeRecipient, slot);
114
+ return GlobalVariables.from({ blockNumber, ...checkpointGlobalVariables });
115
+ }
114
116
 
115
- const timestamp = await this.rollupContract.getTimestampForSlot(slot);
117
+ /** Builds global variables that are constant throughout a checkpoint. */
118
+ public async buildCheckpointGlobalVariables(
119
+ coinbase: EthAddress,
120
+ feeRecipient: AztecAddress,
121
+ slotNumber: SlotNumber,
122
+ ): Promise<CheckpointGlobalVariables> {
123
+ const { chainId, version } = this;
116
124
 
117
- // We can skip much of the logic in getCurrentBaseFees since it we already check that we are not within a slot elsewhere.
118
- const gasFees = new GasFees(0, await this.rollupContract.getManaBaseFeeAt(timestamp, true));
125
+ const timestamp = getTimestampForSlot(slotNumber, {
126
+ slotDuration: this.aztecSlotDuration,
127
+ l1GenesisTime: this.l1GenesisTime,
128
+ });
119
129
 
120
- const globalVariables = new GlobalVariables(
121
- chainId,
122
- version,
123
- blockNumber,
124
- slot,
125
- timestamp,
126
- coinbase,
127
- feeRecipient,
128
- gasFees,
129
- );
130
+ // We can skip much of the logic in getCurrentMinFees since it we already check that we are not within a slot elsewhere.
131
+ // TODO(palla/mbps): Can we use a cached value here?
132
+ const gasFees = new GasFees(0, await this.rollupContract.getManaMinFeeAt(timestamp, true));
130
133
 
131
- return globalVariables;
134
+ return { chainId, version, slotNumber, timestamp, coinbase, feeRecipient, gasFees };
132
135
  }
133
136
  }
@@ -1 +1 @@
1
- export { GlobalVariableBuilder } from './global_builder.js';
1
+ export { GlobalVariableBuilder, type GlobalVariableBuilderConfig } from './global_builder.js';
package/src/index.ts CHANGED
@@ -1,13 +1,7 @@
1
1
  export * from './client/index.js';
2
2
  export * from './config.js';
3
3
  export * from './publisher/index.js';
4
- export {
5
- FullNodeBlockBuilder as BlockBuilder,
6
- Sequencer,
7
- SequencerState,
8
- type SequencerEvents,
9
- } from './sequencer/index.js';
10
- export * from './tx_validator/tx_validator_factory.js';
4
+ export { Sequencer, SequencerState, type SequencerEvents } from './sequencer/index.js';
11
5
 
12
6
  // Used by the node to simulate public parts of transactions. Should these be moved to a shared library?
13
7
  // ISSUE(#9832)
@@ -1,73 +1,160 @@
1
- import { type BlobSinkConfig, blobSinkConfigMapping } from '@aztec/blob-sink/client';
2
- import {
3
- type L1ReaderConfig,
4
- type L1TxUtilsConfig,
5
- l1ReaderConfigMappings,
6
- l1TxUtilsConfigMappings,
7
- } from '@aztec/ethereum';
8
- import {
9
- type ConfigMappingsType,
10
- SecretValue,
11
- booleanConfigHelper,
12
- getConfigFromMappings,
13
- } 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';
14
5
  import { EthAddress } from '@aztec/foundation/eth-address';
15
6
 
16
- /**
17
- * The configuration of the rollup transaction publisher.
18
- */
7
+ import { parseEther } from 'viem';
8
+
9
+ /** Configuration of the transaction publisher. */
19
10
  export type TxSenderConfig = L1ReaderConfig & {
20
- /**
21
- * The private key to be used by the publisher.
22
- */
11
+ /** The private key to be used by the publisher. */
23
12
  publisherPrivateKeys?: SecretValue<`0x${string}`>[];
24
13
 
25
- /**
26
- * Publisher addresses to be used with a remote signer
27
- */
14
+ /** Publisher addresses to be used with a remote signer */
28
15
  publisherAddresses?: EthAddress[];
29
16
  };
30
17
 
31
- /**
32
- * Configuration of the L1Publisher.
33
- */
18
+ export type ProverTxSenderConfig = L1ReaderConfig & {
19
+ proverPublisherPrivateKeys?: SecretValue<`0x${string}`>[];
20
+ proverPublisherAddresses?: EthAddress[];
21
+ };
22
+
23
+ export type SequencerTxSenderConfig = L1ReaderConfig & {
24
+ sequencerPublisherPrivateKeys?: SecretValue<`0x${string}`>[];
25
+ sequencerPublisherAddresses?: EthAddress[];
26
+ };
27
+
28
+ export function getTxSenderConfigFromProverConfig(config: ProverTxSenderConfig): TxSenderConfig {
29
+ return {
30
+ ...config,
31
+ publisherPrivateKeys: config.proverPublisherPrivateKeys,
32
+ publisherAddresses: config.proverPublisherAddresses,
33
+ };
34
+ }
35
+
36
+ export function getTxSenderConfigFromSequencerConfig(config: SequencerTxSenderConfig): TxSenderConfig {
37
+ return {
38
+ ...config,
39
+ publisherPrivateKeys: config.sequencerPublisherPrivateKeys,
40
+ publisherAddresses: config.sequencerPublisherAddresses,
41
+ };
42
+ }
43
+
44
+ /** Configuration of the L1Publisher. */
34
45
  export type PublisherConfig = L1TxUtilsConfig &
35
- BlobSinkConfig & {
46
+ BlobClientConfig & {
36
47
  /** True to use publishers in invalid states (timed out, cancelled, etc) if no other is available */
37
48
  publisherAllowInvalidStates?: boolean;
38
49
  /** Whether to run in fisherman mode: builds blocks on every slot for validation without publishing to L1 */
39
50
  fishermanMode?: boolean;
51
+ /** Address of the forwarder contract to wrap all L1 transactions through (for testing purposes only) */
52
+ publisherForwarderAddress?: EthAddress;
53
+ /** Store for failed L1 transaction inputs (test networks only). Format: gs://bucket/path */
54
+ l1TxFailedStore?: string;
55
+ /** Min ETH balance below which a publisher gets funded. Undefined = funding disabled. */
56
+ publisherFundingThreshold?: bigint;
57
+ /** Amount of ETH to send when funding a publisher. Undefined = funding disabled. */
58
+ publisherFundingAmount?: bigint;
40
59
  };
41
60
 
42
- export const getTxSenderConfigMappings: (
43
- scope: 'PROVER' | 'SEQ',
44
- ) => ConfigMappingsType<Omit<TxSenderConfig, 'l1Contracts'>> = (scope: 'PROVER' | 'SEQ') => ({
61
+ /** Shared config mappings for publisher funding, used by both sequencer and prover publisher configs. */
62
+ const publisherFundingConfigMappings = {
63
+ publisherFundingThreshold: {
64
+ env: 'PUBLISHER_FUNDING_THRESHOLD' as const,
65
+ description:
66
+ 'Min ETH balance below which a publisher gets funded. Specified in ether (e.g. 0.1). Unset = funding disabled.',
67
+ parseEnv: (val: string) => parseEther(val),
68
+ },
69
+ publisherFundingAmount: {
70
+ env: 'PUBLISHER_FUNDING_AMOUNT' as const,
71
+ description:
72
+ 'Amount of ETH to send when funding a publisher. Specified in ether (e.g. 0.5). Unset = funding disabled.',
73
+ parseEnv: (val: string) => parseEther(val),
74
+ },
75
+ };
76
+
77
+ export type ProverPublisherConfig = L1TxUtilsConfig &
78
+ BlobClientConfig & {
79
+ fishermanMode?: boolean;
80
+ proverPublisherAllowInvalidStates?: boolean;
81
+ proverPublisherForwarderAddress?: EthAddress;
82
+ /** Min ETH balance below which a publisher gets funded. Undefined = funding disabled. */
83
+ publisherFundingThreshold?: bigint;
84
+ /** Amount of ETH to send when funding a publisher. Undefined = funding disabled. */
85
+ publisherFundingAmount?: bigint;
86
+ };
87
+
88
+ export type SequencerPublisherConfig = L1TxUtilsConfig &
89
+ BlobClientConfig & {
90
+ fishermanMode?: boolean;
91
+ sequencerPublisherAllowInvalidStates?: boolean;
92
+ sequencerPublisherForwarderAddress?: EthAddress;
93
+ /** Store for failed L1 transaction inputs (test networks only). Format: gs://bucket/path */
94
+ l1TxFailedStore?: string;
95
+ /** Min ETH balance below which a publisher gets funded. Undefined = funding disabled. */
96
+ publisherFundingThreshold?: bigint;
97
+ /** Amount of ETH to send when funding a publisher. Undefined = funding disabled. */
98
+ publisherFundingAmount?: bigint;
99
+ };
100
+
101
+ export function getPublisherConfigFromProverConfig(config: ProverPublisherConfig): PublisherConfig {
102
+ return {
103
+ ...config,
104
+ publisherAllowInvalidStates: config.proverPublisherAllowInvalidStates,
105
+ publisherForwarderAddress: config.proverPublisherForwarderAddress,
106
+ };
107
+ }
108
+
109
+ export function getPublisherConfigFromSequencerConfig(config: SequencerPublisherConfig): PublisherConfig {
110
+ return {
111
+ ...config,
112
+ publisherAllowInvalidStates: config.sequencerPublisherAllowInvalidStates,
113
+ publisherForwarderAddress: config.sequencerPublisherForwarderAddress,
114
+ l1TxFailedStore: config.l1TxFailedStore,
115
+ };
116
+ }
117
+
118
+ export const proverTxSenderConfigMappings: ConfigMappingsType<Omit<ProverTxSenderConfig, 'l1Contracts'>> = {
45
119
  ...l1ReaderConfigMappings,
46
- publisherPrivateKeys: {
47
- env: scope === 'PROVER' ? `PROVER_PUBLISHER_PRIVATE_KEYS` : `SEQ_PUBLISHER_PRIVATE_KEYS`,
48
- description: 'The private keys to be used by the publisher.',
120
+ proverPublisherPrivateKeys: {
121
+ env: `PROVER_PUBLISHER_PRIVATE_KEYS`,
122
+ description: 'The private keys to be used by the prover publisher.',
49
123
  parseEnv: (val: string) => val.split(',').map(key => new SecretValue(`0x${key.replace('0x', '')}`)),
50
124
  defaultValue: [],
51
- fallback: [scope === 'PROVER' ? `PROVER_PUBLISHER_PRIVATE_KEY` : `SEQ_PUBLISHER_PRIVATE_KEY`],
125
+ fallback: [`PROVER_PUBLISHER_PRIVATE_KEY`],
52
126
  },
53
- publisherAddresses: {
54
- env: scope === 'PROVER' ? `PROVER_PUBLISHER_ADDRESSES` : `SEQ_PUBLISHER_ADDRESSES`,
127
+ proverPublisherAddresses: {
128
+ env: `PROVER_PUBLISHER_ADDRESSES`,
55
129
  description: 'The addresses of the publishers to use with remote signers',
56
130
  parseEnv: (val: string) => val.split(',').map(address => EthAddress.fromString(address)),
57
131
  defaultValue: [],
58
132
  },
59
- });
133
+ };
60
134
 
61
- export function getTxSenderConfigFromEnv(scope: 'PROVER' | 'SEQ'): Omit<TxSenderConfig, 'l1Contracts'> {
62
- return getConfigFromMappings(getTxSenderConfigMappings(scope));
63
- }
135
+ export const sequencerTxSenderConfigMappings: ConfigMappingsType<Omit<SequencerTxSenderConfig, 'l1Contracts'>> = {
136
+ ...l1ReaderConfigMappings,
137
+ sequencerPublisherPrivateKeys: {
138
+ env: `SEQ_PUBLISHER_PRIVATE_KEYS`,
139
+ description: 'The private keys to be used by the sequencer publisher.',
140
+ parseEnv: (val: string) => val.split(',').map(key => new SecretValue(`0x${key.replace('0x', '')}`)),
141
+ defaultValue: [],
142
+ fallback: [`SEQ_PUBLISHER_PRIVATE_KEY`],
143
+ },
144
+ sequencerPublisherAddresses: {
145
+ env: `SEQ_PUBLISHER_ADDRESSES`,
146
+ description: 'The addresses of the publishers to use with remote signers',
147
+ parseEnv: (val: string) => val.split(',').map(address => EthAddress.fromString(address)),
148
+ defaultValue: [],
149
+ },
150
+ };
64
151
 
65
- export const getPublisherConfigMappings: (
66
- scope: 'PROVER' | 'SEQ',
67
- ) => ConfigMappingsType<PublisherConfig & L1TxUtilsConfig> = scope => ({
68
- publisherAllowInvalidStates: {
152
+ export const sequencerPublisherConfigMappings: ConfigMappingsType<SequencerPublisherConfig & L1TxUtilsConfig> = {
153
+ ...l1TxUtilsConfigMappings,
154
+ ...blobClientConfigMapping,
155
+ sequencerPublisherAllowInvalidStates: {
156
+ env: `SEQ_PUBLISHER_ALLOW_INVALID_STATES`,
69
157
  description: 'True to use publishers in invalid states (timed out, cancelled, etc) if no other is available',
70
- env: scope === `PROVER` ? `PROVER_PUBLISHER_ALLOW_INVALID_STATES` : `SEQ_PUBLISHER_ALLOW_INVALID_STATES`,
71
158
  ...booleanConfigHelper(true),
72
159
  },
73
160
  fishermanMode: {
@@ -76,10 +163,36 @@ export const getPublisherConfigMappings: (
76
163
  'Whether to run in fisherman mode: builds blocks on every slot for validation without publishing to L1',
77
164
  ...booleanConfigHelper(false),
78
165
  },
79
- ...l1TxUtilsConfigMappings,
80
- ...blobSinkConfigMapping,
81
- });
166
+ sequencerPublisherForwarderAddress: {
167
+ env: `SEQ_PUBLISHER_FORWARDER_ADDRESS`,
168
+ description: 'Address of the forwarder contract to wrap all L1 transactions through (for testing purposes only)',
169
+ parseEnv: (val: string) => (val ? EthAddress.fromString(val) : undefined),
170
+ },
171
+ l1TxFailedStore: {
172
+ env: 'L1_TX_FAILED_STORE',
173
+ description: 'Store for failed L1 transaction inputs (test networks only). Format: gs://bucket/path',
174
+ },
175
+ ...publisherFundingConfigMappings,
176
+ };
82
177
 
83
- export function getPublisherConfigFromEnv(scope: 'PROVER' | 'SEQ'): PublisherConfig {
84
- return getConfigFromMappings(getPublisherConfigMappings(scope));
85
- }
178
+ export const proverPublisherConfigMappings: ConfigMappingsType<ProverPublisherConfig & L1TxUtilsConfig> = {
179
+ ...l1TxUtilsConfigMappings,
180
+ ...blobClientConfigMapping,
181
+ proverPublisherAllowInvalidStates: {
182
+ env: `PROVER_PUBLISHER_ALLOW_INVALID_STATES`,
183
+ description: 'True to use publishers in invalid states (timed out, cancelled, etc) if no other is available',
184
+ ...booleanConfigHelper(true),
185
+ },
186
+ fishermanMode: {
187
+ env: 'FISHERMAN_MODE',
188
+ description:
189
+ 'Whether to run in fisherman mode: builds blocks on every slot for validation without publishing to L1',
190
+ ...booleanConfigHelper(false),
191
+ },
192
+ proverPublisherForwarderAddress: {
193
+ env: `PROVER_PUBLISHER_FORWARDER_ADDRESS`,
194
+ description: 'Address of the forwarder contract to wrap all L1 transactions through (for testing purposes only)',
195
+ parseEnv: (val: string) => (val ? EthAddress.fromString(val) : undefined),
196
+ },
197
+ ...publisherFundingConfigMappings,
198
+ };
@@ -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,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';