@aztec/sequencer-client 0.0.1-commit.a89ec08 → 0.0.1-commit.aa0c64f

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 (125) hide show
  1. package/README.md +281 -21
  2. package/dest/client/sequencer-client.d.ts +19 -5
  3. package/dest/client/sequencer-client.d.ts.map +1 -1
  4. package/dest/client/sequencer-client.js +27 -22
  5. package/dest/config.d.ts +9 -2
  6. package/dest/config.d.ts.map +1 -1
  7. package/dest/config.js +55 -25
  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 +6 -25
  15. package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
  16. package/dest/global_variable_builder/global_builder.js +7 -65
  17. package/dest/global_variable_builder/index.d.ts +3 -1
  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 +23 -3
  21. package/dest/publisher/config.d.ts.map +1 -1
  22. package/dest/publisher/config.js +36 -6
  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 +98 -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 +68 -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 +36 -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 +3 -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 +3 -5
  44. package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -1
  45. package/dest/publisher/sequencer-publisher-factory.js +16 -3
  46. package/dest/publisher/sequencer-publisher.d.ts +105 -66
  47. package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
  48. package/dest/publisher/sequencer-publisher.js +716 -400
  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 +690 -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 +73 -17
  62. package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -1
  63. package/dest/sequencer/checkpoint_proposal_job.js +786 -232
  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/events.d.ts +62 -5
  68. package/dest/sequencer/events.d.ts.map +1 -1
  69. package/dest/sequencer/metrics.d.ts +13 -10
  70. package/dest/sequencer/metrics.d.ts.map +1 -1
  71. package/dest/sequencer/metrics.js +45 -20
  72. package/dest/sequencer/requests_tracker.d.ts +22 -0
  73. package/dest/sequencer/requests_tracker.d.ts.map +1 -0
  74. package/dest/sequencer/requests_tracker.js +33 -0
  75. package/dest/sequencer/sequencer.d.ts +155 -34
  76. package/dest/sequencer/sequencer.d.ts.map +1 -1
  77. package/dest/sequencer/sequencer.js +580 -186
  78. package/dest/sequencer/types.d.ts +2 -2
  79. package/dest/sequencer/types.d.ts.map +1 -1
  80. package/dest/test/index.d.ts +3 -3
  81. package/dest/test/index.d.ts.map +1 -1
  82. package/dest/test/mock_checkpoint_builder.d.ts +1 -1
  83. package/dest/test/mock_checkpoint_builder.d.ts.map +1 -1
  84. package/dest/test/mock_checkpoint_builder.js +0 -2
  85. package/dest/test/utils.d.ts +15 -1
  86. package/dest/test/utils.d.ts.map +1 -1
  87. package/dest/test/utils.js +25 -7
  88. package/package.json +30 -29
  89. package/src/client/sequencer-client.ts +38 -32
  90. package/src/config.ts +64 -22
  91. package/src/global_variable_builder/README.md +44 -0
  92. package/src/global_variable_builder/fee_predictor.ts +182 -0
  93. package/src/global_variable_builder/fee_provider.ts +97 -0
  94. package/src/global_variable_builder/global_builder.ts +12 -80
  95. package/src/global_variable_builder/index.ts +2 -0
  96. package/src/publisher/config.ts +71 -7
  97. package/src/publisher/index.ts +3 -0
  98. package/src/publisher/l1_to_l2_messaging.ts +85 -0
  99. package/src/publisher/l1_tx_failed_store/factory.ts +32 -0
  100. package/src/publisher/l1_tx_failed_store/failed_tx_store.ts +164 -0
  101. package/src/publisher/l1_tx_failed_store/file_store_failed_tx_store.ts +47 -0
  102. package/src/publisher/l1_tx_failed_store/index.ts +3 -0
  103. package/src/publisher/sequencer-bundle-simulator.ts +254 -0
  104. package/src/publisher/sequencer-publisher-factory.ts +18 -6
  105. package/src/publisher/sequencer-publisher.ts +800 -475
  106. package/src/publisher/write_json.ts +78 -0
  107. package/src/sequencer/README.md +162 -450
  108. package/src/sequencer/automine/README.md +60 -0
  109. package/src/sequencer/automine/automine_factory.ts +152 -0
  110. package/src/sequencer/automine/automine_sequencer.ts +796 -0
  111. package/src/sequencer/automine/index.ts +6 -0
  112. package/src/sequencer/checkpoint_proposal_job.ts +922 -246
  113. package/src/sequencer/checkpoint_proposal_job_metrics.ts +128 -0
  114. package/src/sequencer/events.ts +66 -5
  115. package/src/sequencer/metrics.ts +57 -24
  116. package/src/sequencer/requests_tracker.ts +43 -0
  117. package/src/sequencer/sequencer.ts +682 -206
  118. package/src/sequencer/types.ts +1 -1
  119. package/src/test/index.ts +2 -2
  120. package/src/test/mock_checkpoint_builder.ts +0 -2
  121. package/src/test/utils.ts +61 -10
  122. package/dest/sequencer/timetable.d.ts +0 -88
  123. package/dest/sequencer/timetable.d.ts.map +0 -1
  124. package/dest/sequencer/timetable.js +0 -222
  125. package/src/sequencer/timetable.ts +0 -283
@@ -1,23 +1,23 @@
1
- import { RollupContract } from '@aztec/ethereum/contracts';
2
- import type { L1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
1
+ import {
2
+ RollupContract,
3
+ type SimulationOverridesPlan,
4
+ buildSimulationOverridesStateOverride,
5
+ } from '@aztec/ethereum/contracts';
3
6
  import type { ViemPublicClient } from '@aztec/ethereum/types';
4
- import { BlockNumber, SlotNumber } from '@aztec/foundation/branded-types';
7
+ import type { SlotNumber } from '@aztec/foundation/branded-types';
5
8
  import { Fr } from '@aztec/foundation/curves/bn254';
6
9
  import type { EthAddress } from '@aztec/foundation/eth-address';
7
- import { createLogger } from '@aztec/foundation/log';
8
- import type { DateProvider } from '@aztec/foundation/timer';
9
10
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
10
- import { type L1RollupConstants, getNextL1SlotTimestamp, getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
11
+ import { type L1RollupConstants, getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
11
12
  import { GasFees } from '@aztec/stdlib/gas';
12
13
  import type {
13
14
  CheckpointGlobalVariables,
14
15
  GlobalVariableBuilder as GlobalVariableBuilderInterface,
15
16
  } from '@aztec/stdlib/tx';
16
- import { GlobalVariables } from '@aztec/stdlib/tx';
17
17
 
18
18
  /** Configuration for the GlobalVariableBuilder (excludes L1 client config). */
19
19
  export type GlobalVariableBuilderConfig = {
20
- l1Contracts: Pick<L1ContractAddresses, 'rollupAddress'>;
20
+ rollupAddress: EthAddress;
21
21
  ethereumSlotDuration: number;
22
22
  rollupVersion: bigint;
23
23
  } & Pick<L1RollupConstants, 'slotDuration' | 'l1GenesisTime'>;
@@ -26,12 +26,7 @@ export type GlobalVariableBuilderConfig = {
26
26
  * Simple global variables builder.
27
27
  */
28
28
  export class GlobalVariableBuilder implements GlobalVariableBuilderInterface {
29
- private log = createLogger('sequencer:global_variable_builder');
30
- private currentMinFees: Promise<GasFees> = Promise.resolve(new GasFees(0, 0));
31
- private currentL1BlockNumber: bigint | undefined = undefined;
32
-
33
29
  private readonly rollupContract: RollupContract;
34
- private readonly ethereumSlotDuration: number;
35
30
  private readonly aztecSlotDuration: number;
36
31
  private readonly l1GenesisTime: bigint;
37
32
 
@@ -39,79 +34,16 @@ export class GlobalVariableBuilder implements GlobalVariableBuilderInterface {
39
34
  private version: Fr;
40
35
 
41
36
  constructor(
42
- private readonly dateProvider: DateProvider,
43
37
  private readonly publicClient: ViemPublicClient,
44
38
  config: GlobalVariableBuilderConfig,
45
39
  ) {
46
40
  this.version = new Fr(config.rollupVersion);
47
41
  this.chainId = new Fr(this.publicClient.chain!.id);
48
42
 
49
- this.ethereumSlotDuration = config.ethereumSlotDuration;
50
43
  this.aztecSlotDuration = config.slotDuration;
51
44
  this.l1GenesisTime = config.l1GenesisTime;
52
45
 
53
- this.rollupContract = new RollupContract(this.publicClient, config.l1Contracts.rollupAddress);
54
- }
55
-
56
- /**
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
59
- */
60
- private async computeCurrentMinFees(): Promise<GasFees> {
61
- // Since this might be called in the middle of a slot where a block might have been published,
62
- // we need to fetch the last block written, and estimate the earliest timestamp for the next block.
63
- // The timestamp of that last block will act as a lower bound for the next block.
64
-
65
- const lastCheckpoint = await this.rollupContract.getPendingCheckpoint();
66
- const earliestTimestamp = await this.rollupContract.getTimestampForSlot(
67
- SlotNumber.fromBigInt(BigInt(lastCheckpoint.slotNumber) + 1n),
68
- );
69
- const nextEthTimestamp = getNextL1SlotTimestamp(this.dateProvider.nowInSeconds(), {
70
- l1GenesisTime: this.l1GenesisTime,
71
- ethereumSlotDuration: this.ethereumSlotDuration,
72
- });
73
- const timestamp = earliestTimestamp > nextEthTimestamp ? earliestTimestamp : nextEthTimestamp;
74
-
75
- return new GasFees(0, await this.rollupContract.getManaMinFeeAt(timestamp, true));
76
- }
77
-
78
- public async getCurrentMinFees(): Promise<GasFees> {
79
- // Get the current block number
80
- const blockNumber = await this.publicClient.getBlockNumber();
81
-
82
- // If the L1 block number has changed then chain a new promise to get the current min fees
83
- if (this.currentL1BlockNumber === undefined || blockNumber > this.currentL1BlockNumber) {
84
- this.currentL1BlockNumber = blockNumber;
85
- this.currentMinFees = this.currentMinFees.then(() => this.computeCurrentMinFees());
86
- }
87
- return this.currentMinFees;
88
- }
89
-
90
- /**
91
- * Simple builder of global variables.
92
- * @param blockNumber - The block number to build global variables for.
93
- * @param coinbase - The address to receive block reward.
94
- * @param feeRecipient - The address to receive fees.
95
- * @param slotNumber - The slot number to use for the global variables, if undefined it will be calculated.
96
- * @returns The global variables for the given block number.
97
- */
98
- public async buildGlobalVariables(
99
- blockNumber: BlockNumber,
100
- coinbase: EthAddress,
101
- feeRecipient: AztecAddress,
102
- maybeSlot?: SlotNumber,
103
- ): Promise<GlobalVariables> {
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 });
46
+ this.rollupContract = new RollupContract(this.publicClient, config.rollupAddress);
115
47
  }
116
48
 
117
49
  /** Builds global variables that are constant throughout a checkpoint. */
@@ -119,6 +51,7 @@ export class GlobalVariableBuilder implements GlobalVariableBuilderInterface {
119
51
  coinbase: EthAddress,
120
52
  feeRecipient: AztecAddress,
121
53
  slotNumber: SlotNumber,
54
+ simulationOverridesPlan?: SimulationOverridesPlan,
122
55
  ): Promise<CheckpointGlobalVariables> {
123
56
  const { chainId, version } = this;
124
57
 
@@ -127,9 +60,8 @@ export class GlobalVariableBuilder implements GlobalVariableBuilderInterface {
127
60
  l1GenesisTime: this.l1GenesisTime,
128
61
  });
129
62
 
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));
63
+ const stateOverride = await buildSimulationOverridesStateOverride(this.rollupContract, simulationOverridesPlan);
64
+ const gasFees = new GasFees(0, await this.rollupContract.getManaMinFeeAt(timestamp, true, stateOverride));
133
65
 
134
66
  return { chainId, version, slotNumber, timestamp, coinbase, feeRecipient, gasFees };
135
67
  }
@@ -1 +1,3 @@
1
+ export { FeeProviderImpl } from './fee_provider.js';
1
2
  export { GlobalVariableBuilder, type GlobalVariableBuilderConfig } from './global_builder.js';
3
+ export { FeePredictor } from './fee_predictor.js';
@@ -1,9 +1,16 @@
1
1
  import { type BlobClientConfig, blobClientConfigMapping } from '@aztec/blob-client/client/config';
2
2
  import { type L1ReaderConfig, l1ReaderConfigMappings } from '@aztec/ethereum/l1-reader';
3
3
  import { type L1TxUtilsConfig, l1TxUtilsConfigMappings } from '@aztec/ethereum/l1-tx-utils/config';
4
- import { type ConfigMappingsType, SecretValue, booleanConfigHelper } from '@aztec/foundation/config';
4
+ import {
5
+ type ConfigMappingsType,
6
+ SecretValue,
7
+ booleanConfigHelper,
8
+ numberConfigHelper,
9
+ } from '@aztec/foundation/config';
5
10
  import { EthAddress } from '@aztec/foundation/eth-address';
6
11
 
12
+ import { parseEther } from 'viem';
13
+
7
14
  /** Configuration of the transaction publisher. */
8
15
  export type TxSenderConfig = L1ReaderConfig & {
9
16
  /** The private key to be used by the publisher. */
@@ -48,13 +55,39 @@ export type PublisherConfig = L1TxUtilsConfig &
48
55
  fishermanMode?: boolean;
49
56
  /** Address of the forwarder contract to wrap all L1 transactions through (for testing purposes only) */
50
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;
51
64
  };
52
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
+
53
82
  export type ProverPublisherConfig = L1TxUtilsConfig &
54
83
  BlobClientConfig & {
55
84
  fishermanMode?: boolean;
56
85
  proverPublisherAllowInvalidStates?: boolean;
57
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;
58
91
  };
59
92
 
60
93
  export type SequencerPublisherConfig = L1TxUtilsConfig &
@@ -62,6 +95,16 @@ export type SequencerPublisherConfig = L1TxUtilsConfig &
62
95
  fishermanMode?: boolean;
63
96
  sequencerPublisherAllowInvalidStates?: boolean;
64
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;
65
108
  };
66
109
 
67
110
  export function getPublisherConfigFromProverConfig(config: ProverPublisherConfig): PublisherConfig {
@@ -77,15 +120,17 @@ export function getPublisherConfigFromSequencerConfig(config: SequencerPublisher
77
120
  ...config,
78
121
  publisherAllowInvalidStates: config.sequencerPublisherAllowInvalidStates,
79
122
  publisherForwarderAddress: config.sequencerPublisherForwarderAddress,
123
+ l1TxFailedStore: config.l1TxFailedStore,
80
124
  };
81
125
  }
82
126
 
83
- export const proverTxSenderConfigMappings: ConfigMappingsType<Omit<ProverTxSenderConfig, 'l1Contracts'>> = {
127
+ export const proverTxSenderConfigMappings: ConfigMappingsType<ProverTxSenderConfig> = {
84
128
  ...l1ReaderConfigMappings,
85
129
  proverPublisherPrivateKeys: {
86
130
  env: `PROVER_PUBLISHER_PRIVATE_KEYS`,
87
131
  description: 'The private keys to be used by the prover publisher.',
88
- parseEnv: (val: string) => val.split(',').map(key => new SecretValue(`0x${key.replace('0x', '')}`)),
132
+ parseEnv: (val: string) =>
133
+ val.split(',').map(key => new SecretValue(`0x${key.replace('0x', '')}` as `0x${string}`)),
89
134
  defaultValue: [],
90
135
  fallback: [`PROVER_PUBLISHER_PRIVATE_KEY`],
91
136
  },
@@ -97,12 +142,13 @@ export const proverTxSenderConfigMappings: ConfigMappingsType<Omit<ProverTxSende
97
142
  },
98
143
  };
99
144
 
100
- export const sequencerTxSenderConfigMappings: ConfigMappingsType<Omit<SequencerTxSenderConfig, 'l1Contracts'>> = {
145
+ export const sequencerTxSenderConfigMappings: ConfigMappingsType<SequencerTxSenderConfig> = {
101
146
  ...l1ReaderConfigMappings,
102
147
  sequencerPublisherPrivateKeys: {
103
148
  env: `SEQ_PUBLISHER_PRIVATE_KEYS`,
104
149
  description: 'The private keys to be used by the sequencer publisher.',
105
- parseEnv: (val: string) => val.split(',').map(key => new SecretValue(`0x${key.replace('0x', '')}`)),
150
+ parseEnv: (val: string) =>
151
+ val.split(',').map(key => new SecretValue(`0x${key.replace('0x', '')}` as `0x${string}`)),
106
152
  defaultValue: [],
107
153
  fallback: [`SEQ_PUBLISHER_PRIVATE_KEY`],
108
154
  },
@@ -131,8 +177,25 @@ export const sequencerPublisherConfigMappings: ConfigMappingsType<SequencerPubli
131
177
  sequencerPublisherForwarderAddress: {
132
178
  env: `SEQ_PUBLISHER_FORWARDER_ADDRESS`,
133
179
  description: 'Address of the forwarder contract to wrap all L1 transactions through (for testing purposes only)',
134
- 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',
135
197
  },
198
+ ...publisherFundingConfigMappings,
136
199
  };
137
200
 
138
201
  export const proverPublisherConfigMappings: ConfigMappingsType<ProverPublisherConfig & L1TxUtilsConfig> = {
@@ -152,6 +215,7 @@ export const proverPublisherConfigMappings: ConfigMappingsType<ProverPublisherCo
152
215
  proverPublisherForwarderAddress: {
153
216
  env: `PROVER_PUBLISHER_FORWARDER_ADDRESS`,
154
217
  description: 'Address of the forwarder contract to wrap all L1 transactions through (for testing purposes only)',
155
- parseEnv: (val: string) => (val ? EthAddress.fromString(val) : undefined),
218
+ parseEnv: (val: string) => EthAddress.fromString(val),
156
219
  },
220
+ ...publisherFundingConfigMappings,
157
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,164 @@
1
+ import type { WindowBlockFees } from '@aztec/ethereum/l1-fee-analysis';
2
+ import type { GasPrice } from '@aztec/ethereum/l1-tx-utils';
3
+ import type { Branded } from '@aztec/foundation/branded-types';
4
+ import { type ZodFor, schemas } from '@aztec/foundation/schemas';
5
+
6
+ import type { Hex } from 'viem';
7
+ import { z } from 'zod';
8
+
9
+ /** URI pointing to a stored failed L1 transaction. */
10
+ export type FailedL1TxUri = Branded<string, 'FailedL1TxUri'>;
11
+
12
+ /**
13
+ * A failed L1 transaction captured for debugging and replay. Serialized with jsonStringify (bigints
14
+ * become decimal strings on disk) and parsed back via FailedL1TxSchema.
15
+ */
16
+ export type FailedL1Tx = {
17
+ /** Tx hash (for reverts) or keccak256(request.data) (for simulation/send failures). */
18
+ id: Hex;
19
+ /** Unix timestamp (ms) when failure occurred. */
20
+ timestamp: number;
21
+ /** How the failure occurred. */
22
+ failureType: 'simulation' | 'revert' | 'send-error' | 'timeout';
23
+ /** The actual L1 transaction for replay (multicall-encoded for bundled txs). */
24
+ request: {
25
+ to: Hex;
26
+ data: Hex;
27
+ value?: bigint;
28
+ };
29
+ /** Raw blob data as hex for replay. */
30
+ blobData?: Hex[];
31
+ /** L1 block number at time of failure (simulation target or receipt block). */
32
+ l1BlockNumber: bigint;
33
+ /** Receipt info (present only for on-chain reverts). */
34
+ receipt?: {
35
+ transactionHash: Hex;
36
+ blockNumber: bigint;
37
+ gasUsed: bigint;
38
+ status: 'reverted';
39
+ };
40
+ /** Error information. */
41
+ error: {
42
+ message: string;
43
+ /** Decoded error name (e.g., 'Rollup__InvalidProposer'). */
44
+ name?: string;
45
+ };
46
+ /** Context metadata. */
47
+ context: {
48
+ /** Actions involved (e.g., ['propose', 'governance-signal']). */
49
+ actions: string[];
50
+ /** Individual request data for each action (metadata, not used for replay). */
51
+ requests?: Array<{ action: string; to: Hex; data: Hex }>;
52
+ checkpointNumber?: number;
53
+ slot?: number;
54
+ sender: Hex;
55
+ };
56
+ /** Gas pricing info at time of failure for underpricing diagnosis. */
57
+ gasInfo?: {
58
+ /** Gas prices the tx was sent with (present for revert/send-error/timeout, not simulation). */
59
+ sentGasPrice?: GasPrice;
60
+ /** Gas limit used or estimated. */
61
+ gasLimit?: bigint;
62
+ /** Nonce used for the sent tx. */
63
+ nonce?: number;
64
+ /**
65
+ * For timeouts: the escalating gas prices used across the initial send and each speed-up retry,
66
+ * in order. Compare against windowBlocks[].minIncludedPriorityFee to see if any attempt cleared the bar.
67
+ */
68
+ sentGasPriceLadder?: GasPrice[];
69
+ /** Number of send attempts (initial send + speed-ups). */
70
+ attempts?: number;
71
+ /**
72
+ * Per-block fee data for the L1 blocks the tx could have been included in (the target L2 slot's
73
+ * inclusion window), in chronological order. Compare sentGasPrice against these to see whether
74
+ * the tx was underpriced for each block it competed for. May be a partial or empty list if the
75
+ * window was not yet mined when the failure was recorded (e.g. an early send failure).
76
+ */
77
+ windowBlocks?: WindowBlockFees[];
78
+ };
79
+ /** Timing info relative to the L2 slot. */
80
+ timing?: {
81
+ /** The target L2 slot this tx was for. */
82
+ targetL2Slot?: number;
83
+ /** Unix timestamp (seconds) when the target slot ends. */
84
+ slotDeadlineTimestampS?: bigint;
85
+ /** Milliseconds remaining until the slot deadline. Negative = past deadline. */
86
+ msUntilSlotDeadline?: number;
87
+ };
88
+ };
89
+
90
+ const hexSchema = schemas.HexStringWith0x;
91
+
92
+ const gasPriceSchema = z.object({
93
+ maxFeePerGas: schemas.BigInt,
94
+ maxPriorityFeePerGas: schemas.BigInt,
95
+ maxFeePerBlobGas: schemas.BigInt.optional(),
96
+ }) satisfies ZodFor<GasPrice>;
97
+
98
+ const windowBlockFeesSchema = z.object({
99
+ blockNumber: schemas.BigInt,
100
+ timestamp: schemas.BigInt,
101
+ baseFeePerGas: schemas.BigInt,
102
+ p75PriorityFee: schemas.BigInt,
103
+ minIncludedPriorityFee: schemas.BigInt,
104
+ blockBlobsFull: z.boolean(),
105
+ includedBlobCount: z.number(),
106
+ }) satisfies ZodFor<WindowBlockFees>;
107
+
108
+ /** Parses a stored failed-tx record, coercing the on-disk decimal strings back to bigints. */
109
+ export const FailedL1TxSchema: ZodFor<FailedL1Tx> = z.object({
110
+ id: hexSchema,
111
+ timestamp: z.number(),
112
+ failureType: z.enum(['simulation', 'revert', 'send-error', 'timeout']),
113
+ request: z.object({
114
+ to: hexSchema,
115
+ data: hexSchema,
116
+ value: schemas.BigInt.optional(),
117
+ }),
118
+ blobData: z.array(hexSchema).optional(),
119
+ l1BlockNumber: schemas.BigInt,
120
+ receipt: z
121
+ .object({
122
+ transactionHash: hexSchema,
123
+ blockNumber: schemas.BigInt,
124
+ gasUsed: schemas.BigInt,
125
+ status: z.literal('reverted'),
126
+ })
127
+ .optional(),
128
+ error: z.object({
129
+ message: z.string(),
130
+ name: z.string().optional(),
131
+ }),
132
+ context: z.object({
133
+ actions: z.array(z.string()),
134
+ requests: z.array(z.object({ action: z.string(), to: hexSchema, data: hexSchema })).optional(),
135
+ checkpointNumber: z.number().optional(),
136
+ slot: z.number().optional(),
137
+ sender: hexSchema,
138
+ }),
139
+ gasInfo: z
140
+ .object({
141
+ sentGasPrice: gasPriceSchema.optional(),
142
+ gasLimit: schemas.BigInt.optional(),
143
+ nonce: z.number().optional(),
144
+ sentGasPriceLadder: z.array(gasPriceSchema).optional(),
145
+ attempts: z.number().optional(),
146
+ windowBlocks: z.array(windowBlockFeesSchema).optional(),
147
+ })
148
+ .optional(),
149
+ timing: z
150
+ .object({
151
+ targetL2Slot: z.number().optional(),
152
+ slotDeadlineTimestampS: schemas.BigInt.optional(),
153
+ msUntilSlotDeadline: z.number().optional(),
154
+ })
155
+ .optional(),
156
+ });
157
+
158
+ /** Store for failed L1 transactions for debugging purposes. */
159
+ export interface L1TxFailedStore {
160
+ /** Saves a failed transaction and returns its URI. */
161
+ saveFailedTx(tx: FailedL1Tx): Promise<FailedL1TxUri>;
162
+ /** Retrieves a failed transaction by its URI. */
163
+ getFailedTx(uri: FailedL1TxUri): Promise<FailedL1Tx>;
164
+ }
@@ -0,0 +1,47 @@
1
+ import { jsonParseWithSchema, jsonStringify } from '@aztec/foundation/json-rpc';
2
+ import { type Logger, createLogger } from '@aztec/foundation/log';
3
+ import type { FileStore } from '@aztec/stdlib/file-store';
4
+
5
+ import { type FailedL1Tx, FailedL1TxSchema, type FailedL1TxUri, type L1TxFailedStore } from './failed_tx_store.js';
6
+
7
+ /**
8
+ * L1TxFailedStore implementation using the FileStore abstraction.
9
+ * Supports any backend that FileStore supports (GCS, S3, R2, local filesystem).
10
+ */
11
+ export class FileStoreL1TxFailedStore implements L1TxFailedStore {
12
+ private readonly log: Logger;
13
+
14
+ constructor(
15
+ private readonly fileStore: FileStore,
16
+ logger?: Logger,
17
+ ) {
18
+ this.log = logger ?? createLogger('sequencer:l1-tx-failed-store');
19
+ }
20
+
21
+ public async saveFailedTx(tx: FailedL1Tx): Promise<FailedL1TxUri> {
22
+ const prefix = tx.receipt ? 'tx' : 'data';
23
+ const path = `${tx.failureType}/${prefix}-${tx.id}.json`;
24
+ const json = jsonStringify(tx, true);
25
+
26
+ const uri = await this.fileStore.save(path, Buffer.from(json), {
27
+ metadata: {
28
+ 'content-type': 'application/json',
29
+ actions: tx.context.actions.join(','),
30
+ 'failure-type': tx.failureType,
31
+ },
32
+ });
33
+
34
+ this.log.info(`Saved failed L1 tx to ${uri}`, {
35
+ id: tx.id,
36
+ failureType: tx.failureType,
37
+ actions: tx.context.actions.join(','),
38
+ });
39
+
40
+ return uri as FailedL1TxUri;
41
+ }
42
+
43
+ public async getFailedTx(uri: FailedL1TxUri): Promise<FailedL1Tx> {
44
+ const data = await this.fileStore.read(uri);
45
+ return jsonParseWithSchema(data.toString(), FailedL1TxSchema);
46
+ }
47
+ }
@@ -0,0 +1,3 @@
1
+ export { type FailedL1Tx, FailedL1TxSchema, 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';