@aztec/node-lib 0.0.1-commit.03f7ef2 → 0.0.1-commit.04d373f

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.
@@ -1,21 +1,15 @@
1
+ import type { BlobKzgInstance } from '@aztec/blob-lib/types';
1
2
  import type { EthSigner } from '@aztec/ethereum/eth-signer';
2
- import {
3
- createL1TxUtilsFromEthSigner as createL1TxUtilsFromEthSignerBase,
4
- createL1TxUtilsFromViemWallet as createL1TxUtilsFromViemWalletBase,
5
- } from '@aztec/ethereum/l1-tx-utils';
3
+ import { createDelayer, createL1TxUtils as createL1TxUtilsBase } from '@aztec/ethereum/l1-tx-utils';
6
4
  import type { L1TxUtilsConfig } from '@aztec/ethereum/l1-tx-utils';
7
- import {
8
- createForwarderL1TxUtilsFromEthSigner as createForwarderL1TxUtilsFromEthSignerBase,
9
- createForwarderL1TxUtilsFromViemWallet as createForwarderL1TxUtilsFromViemWalletBase,
10
- createL1TxUtilsWithBlobsFromEthSigner as createL1TxUtilsWithBlobsFromEthSignerBase,
11
- createL1TxUtilsWithBlobsFromViemWallet as createL1TxUtilsWithBlobsFromViemWalletBase,
12
- } from '@aztec/ethereum/l1-tx-utils-with-blobs';
5
+ import { createForwarderL1TxUtils as createForwarderL1TxUtilsBase } from '@aztec/ethereum/l1-tx-utils-with-blobs';
13
6
  import type { ExtendedViemWalletClient, ViemClient } from '@aztec/ethereum/types';
14
7
  import { omit } from '@aztec/foundation/collection';
8
+ import type { EthAddress } from '@aztec/foundation/eth-address';
15
9
  import { createLogger } from '@aztec/foundation/log';
16
10
  import type { DateProvider } from '@aztec/foundation/timer';
17
- import type { DataStoreConfig } from '@aztec/kv-store/config';
18
11
  import { createStore } from '@aztec/kv-store/lmdb-v2';
12
+ import type { DataStoreConfig } from '@aztec/stdlib/kv-store';
19
13
  import type { TelemetryClient } from '@aztec/telemetry-client';
20
14
 
21
15
  import type { L1TxScope } from '../metrics/l1_tx_metrics.js';
@@ -25,117 +19,70 @@ import { L1TxStore } from '../stores/l1_tx_store.js';
25
19
  const L1_TX_STORE_NAME = 'l1-tx-utils';
26
20
 
27
21
  /**
28
- * Creates shared dependencies (logger, store, metrics) for L1TxUtils instances.
22
+ * Creates shared dependencies (logger, store, metrics, delayer) for L1TxUtils instances.
23
+ * When enableDelayer is set in config, a single shared delayer is created and passed to all instances.
29
24
  */
30
25
  async function createSharedDeps(
31
- config: DataStoreConfig & { scope?: L1TxScope },
26
+ config: DataStoreConfig & Partial<L1TxUtilsConfig> & { scope?: L1TxScope },
32
27
  deps: {
33
28
  telemetry: TelemetryClient;
34
29
  logger?: ReturnType<typeof createLogger>;
35
- dateProvider?: DateProvider;
30
+ dateProvider: DateProvider;
36
31
  },
37
32
  ) {
38
33
  const logger = deps.logger ?? createLogger('l1-tx-utils');
39
34
 
40
35
  // Note that we do NOT bind them to the rollup address, since we still need to
41
36
  // monitor and cancel txs for previous rollups to free up our nonces.
42
- const noRollupConfig = omit(config, 'l1Contracts');
43
- const kvStore = await createStore(L1_TX_STORE_NAME, L1TxStore.SCHEMA_VERSION, noRollupConfig, logger);
37
+ const noRollupConfig = omit(config, 'rollupAddress');
38
+ const kvStore = await createStore(L1_TX_STORE_NAME, L1TxStore.SCHEMA_VERSION, noRollupConfig, logger.getBindings());
44
39
  const store = new L1TxStore(kvStore, logger);
45
40
 
46
41
  const meter = deps.telemetry.getMeter('L1TxUtils');
47
42
  const metrics = new L1TxMetrics(meter, config.scope ?? 'other', logger);
48
43
 
49
- return { logger, store, metrics, dateProvider: deps.dateProvider };
50
- }
51
-
52
- /**
53
- * Creates L1TxUtils with blobs from multiple Viem wallets, sharing store and metrics.
54
- */
55
- export async function createL1TxUtilsWithBlobsFromViemWallet(
56
- clients: ExtendedViemWalletClient[],
57
- config: DataStoreConfig & Partial<L1TxUtilsConfig> & { debugMaxGasLimit?: boolean; scope?: L1TxScope },
58
- deps: {
59
- telemetry: TelemetryClient;
60
- logger?: ReturnType<typeof createLogger>;
61
- dateProvider?: DateProvider;
62
- },
63
- ) {
64
- const sharedDeps = await createSharedDeps(config, deps);
44
+ // Create a single shared delayer for all L1TxUtils instances in this group
45
+ const delayer =
46
+ config.enableDelayer && config.ethereumSlotDuration !== undefined
47
+ ? createDelayer(deps.dateProvider, { ethereumSlotDuration: config.ethereumSlotDuration }, logger.getBindings())
48
+ : undefined;
65
49
 
66
- return clients.map(client =>
67
- createL1TxUtilsWithBlobsFromViemWalletBase(client, sharedDeps, config, config.debugMaxGasLimit),
68
- );
69
- }
70
-
71
- /**
72
- * Creates L1TxUtils with blobs from multiple EthSigners, sharing store and metrics. Removes duplicates
73
- */
74
- export async function createL1TxUtilsWithBlobsFromEthSigner(
75
- client: ViemClient,
76
- signers: EthSigner[],
77
- config: DataStoreConfig & Partial<L1TxUtilsConfig> & { debugMaxGasLimit?: boolean; scope?: L1TxScope },
78
- deps: {
79
- telemetry: TelemetryClient;
80
- logger?: ReturnType<typeof createLogger>;
81
- dateProvider?: DateProvider;
82
- },
83
- ) {
84
- const sharedDeps = await createSharedDeps(config, deps);
85
-
86
- // Deduplicate signers by address to avoid creating multiple L1TxUtils instances
87
- // for the same publisher address (e.g., when multiple attesters share the same publisher key)
88
- const signersByAddress = new Map<string, EthSigner>();
89
- for (const signer of signers) {
90
- const addressKey = signer.address.toString().toLowerCase();
91
- if (!signersByAddress.has(addressKey)) {
92
- signersByAddress.set(addressKey, signer);
93
- }
94
- }
95
-
96
- const uniqueSigners = Array.from(signersByAddress.values());
97
-
98
- if (uniqueSigners.length < signers.length) {
99
- sharedDeps.logger.info(
100
- `Deduplicated ${signers.length} signers to ${uniqueSigners.length} unique publisher addresses`,
101
- );
102
- }
103
-
104
- return uniqueSigners.map(signer =>
105
- createL1TxUtilsWithBlobsFromEthSignerBase(client, signer, sharedDeps, config, config.debugMaxGasLimit),
106
- );
50
+ return { logger, store, metrics, dateProvider: deps.dateProvider, delayer };
107
51
  }
108
52
 
109
53
  /**
110
- * Creates L1TxUtils (without blobs) from multiple Viem wallets, sharing store and metrics.
54
+ * Creates L1TxUtils from multiple Viem wallet clients, sharing store, metrics, and delayer.
55
+ * When kzg is provided in deps, blob support is enabled.
111
56
  */
112
- export async function createL1TxUtilsFromViemWalletWithStore(
57
+ export async function createL1TxUtilsFromWallets(
113
58
  clients: ExtendedViemWalletClient[],
114
59
  config: DataStoreConfig & Partial<L1TxUtilsConfig> & { debugMaxGasLimit?: boolean; scope?: L1TxScope },
115
60
  deps: {
116
61
  telemetry: TelemetryClient;
117
62
  logger?: ReturnType<typeof createLogger>;
118
- dateProvider?: DateProvider;
119
- scope?: L1TxScope;
63
+ dateProvider: DateProvider;
64
+ kzg?: BlobKzgInstance;
120
65
  },
121
66
  ) {
122
67
  const sharedDeps = await createSharedDeps(config, deps);
123
68
 
124
- return clients.map(client => createL1TxUtilsFromViemWalletBase(client, sharedDeps, config));
69
+ return clients.map(client => createL1TxUtilsBase(client, { ...sharedDeps, kzg: deps.kzg }, config));
125
70
  }
126
71
 
127
72
  /**
128
- * Creates L1TxUtils (without blobs) from multiple EthSigners, sharing store and metrics. Removes duplicates.
73
+ * Creates L1TxUtils from multiple EthSigners, sharing store, metrics, and delayer.
74
+ * When kzg is provided in deps, blob support is enabled.
75
+ * Deduplicates signers by address to avoid creating multiple instances for the same publisher.
129
76
  */
130
- export async function createL1TxUtilsFromEthSignerWithStore(
77
+ export async function createL1TxUtilsFromSigners(
131
78
  client: ViemClient,
132
79
  signers: EthSigner[],
133
80
  config: DataStoreConfig & Partial<L1TxUtilsConfig> & { debugMaxGasLimit?: boolean; scope?: L1TxScope },
134
81
  deps: {
135
82
  telemetry: TelemetryClient;
136
83
  logger?: ReturnType<typeof createLogger>;
137
- dateProvider?: DateProvider;
138
- scope?: L1TxScope;
84
+ dateProvider: DateProvider;
85
+ kzg?: BlobKzgInstance;
139
86
  },
140
87
  ) {
141
88
  const sharedDeps = await createSharedDeps(config, deps);
@@ -158,55 +105,52 @@ export async function createL1TxUtilsFromEthSignerWithStore(
158
105
  );
159
106
  }
160
107
 
161
- return uniqueSigners.map(signer => createL1TxUtilsFromEthSignerBase(client, signer, sharedDeps, config));
108
+ return uniqueSigners.map(signer => createL1TxUtilsBase({ client, signer }, { ...sharedDeps, kzg: deps.kzg }, config));
162
109
  }
163
110
 
164
111
  /**
165
- * Creates ForwarderL1TxUtils from multiple Viem wallets, sharing store and metrics.
166
- * This wraps all transactions through a forwarder contract for testing purposes.
112
+ * Creates ForwarderL1TxUtils from multiple Viem wallet clients, sharing store, metrics, and delayer.
113
+ * Wraps all transactions through a forwarder contract for testing purposes.
114
+ * When kzg is provided in deps, blob support is enabled.
167
115
  */
168
- export async function createForwarderL1TxUtilsFromViemWallet(
116
+ export async function createForwarderL1TxUtilsFromWallets(
169
117
  clients: ExtendedViemWalletClient[],
170
- forwarderAddress: import('@aztec/foundation/eth-address').EthAddress,
118
+ forwarderAddress: EthAddress,
171
119
  config: DataStoreConfig & Partial<L1TxUtilsConfig> & { debugMaxGasLimit?: boolean; scope?: L1TxScope },
172
120
  deps: {
173
121
  telemetry: TelemetryClient;
174
122
  logger?: ReturnType<typeof createLogger>;
175
- dateProvider?: DateProvider;
123
+ dateProvider: DateProvider;
124
+ kzg?: BlobKzgInstance;
176
125
  },
177
126
  ) {
178
127
  const sharedDeps = await createSharedDeps(config, deps);
179
128
 
180
129
  return clients.map(client =>
181
- createForwarderL1TxUtilsFromViemWalletBase(client, forwarderAddress, sharedDeps, config, config.debugMaxGasLimit),
130
+ createForwarderL1TxUtilsBase(client, forwarderAddress, { ...sharedDeps, kzg: deps.kzg }, config),
182
131
  );
183
132
  }
184
133
 
185
134
  /**
186
- * Creates ForwarderL1TxUtils from multiple EthSigners, sharing store and metrics.
187
- * This wraps all transactions through a forwarder contract for testing purposes.
135
+ * Creates ForwarderL1TxUtils from multiple EthSigners, sharing store, metrics, and delayer.
136
+ * Wraps all transactions through a forwarder contract for testing purposes.
137
+ * When kzg is provided in deps, blob support is enabled.
188
138
  */
189
- export async function createForwarderL1TxUtilsFromEthSigner(
139
+ export async function createForwarderL1TxUtilsFromSigners(
190
140
  client: ViemClient,
191
141
  signers: EthSigner[],
192
- forwarderAddress: import('@aztec/foundation/eth-address').EthAddress,
142
+ forwarderAddress: EthAddress,
193
143
  config: DataStoreConfig & Partial<L1TxUtilsConfig> & { debugMaxGasLimit?: boolean; scope?: L1TxScope },
194
144
  deps: {
195
145
  telemetry: TelemetryClient;
196
146
  logger?: ReturnType<typeof createLogger>;
197
- dateProvider?: DateProvider;
147
+ dateProvider: DateProvider;
148
+ kzg?: BlobKzgInstance;
198
149
  },
199
150
  ) {
200
151
  const sharedDeps = await createSharedDeps(config, deps);
201
152
 
202
153
  return signers.map(signer =>
203
- createForwarderL1TxUtilsFromEthSignerBase(
204
- client,
205
- signer,
206
- forwarderAddress,
207
- sharedDeps,
208
- config,
209
- config.debugMaxGasLimit,
210
- ),
154
+ createForwarderL1TxUtilsBase({ client, signer }, forwarderAddress, { ...sharedDeps, kzg: deps.kzg }, config),
211
155
  );
212
156
  }
@@ -7,7 +7,7 @@ import {
7
7
  type Meter,
8
8
  Metrics,
9
9
  type UpDownCounter,
10
- ValueType,
10
+ createUpDownCounterWithDefault,
11
11
  } from '@aztec/telemetry-client';
12
12
 
13
13
  export type L1TxScope = 'sequencer' | 'prover' | 'other';
@@ -38,55 +38,24 @@ export class L1TxMetrics implements IL1TxMetrics {
38
38
  private scope: L1TxScope = 'other',
39
39
  private logger = createLogger('l1-tx-utils:metrics'),
40
40
  ) {
41
- this.txMinedDuration = this.meter.createHistogram(Metrics.L1_TX_MINED_DURATION, {
42
- description: 'Time from initial tx send until mined',
43
- unit: 's',
44
- valueType: ValueType.INT,
45
- });
41
+ this.txMinedDuration = this.meter.createHistogram(Metrics.L1_TX_MINED_DURATION);
46
42
 
47
- this.txAttemptsUntilMined = this.meter.createHistogram(Metrics.L1_TX_ATTEMPTS_UNTIL_MINED, {
48
- description: 'Number of tx attempts (including speed-ups) until mined',
49
- unit: 'attempts',
50
- valueType: ValueType.INT,
51
- });
43
+ this.txAttemptsUntilMined = this.meter.createHistogram(Metrics.L1_TX_ATTEMPTS_UNTIL_MINED);
52
44
 
53
- this.txMinedCount = this.meter.createUpDownCounter(Metrics.L1_TX_MINED_COUNT, {
54
- description: 'Count of transactions successfully mined',
55
- valueType: ValueType.INT,
56
- });
45
+ const scopeAttributes = [{ [Attributes.L1_TX_SCOPE]: this.scope }];
46
+ this.txMinedCount = createUpDownCounterWithDefault(this.meter, Metrics.L1_TX_MINED_COUNT, scopeAttributes);
57
47
 
58
- this.txRevertedCount = this.meter.createUpDownCounter(Metrics.L1_TX_REVERTED_COUNT, {
59
- description: 'Count of transactions that reverted',
60
- valueType: ValueType.INT,
61
- });
48
+ this.txRevertedCount = createUpDownCounterWithDefault(this.meter, Metrics.L1_TX_REVERTED_COUNT, scopeAttributes);
62
49
 
63
- this.txCancelledCount = this.meter.createUpDownCounter(Metrics.L1_TX_CANCELLED_COUNT, {
64
- description: 'Count of transactions cancelled',
65
- valueType: ValueType.INT,
66
- });
50
+ this.txCancelledCount = createUpDownCounterWithDefault(this.meter, Metrics.L1_TX_CANCELLED_COUNT, scopeAttributes);
67
51
 
68
- this.txNotMinedCount = this.meter.createUpDownCounter(Metrics.L1_TX_NOT_MINED_COUNT, {
69
- description: 'Count of transactions not mined (timed out)',
70
- valueType: ValueType.INT,
71
- });
52
+ this.txNotMinedCount = createUpDownCounterWithDefault(this.meter, Metrics.L1_TX_NOT_MINED_COUNT, scopeAttributes);
72
53
 
73
- this.maxPriorityFeeHistogram = this.meter.createHistogram(Metrics.L1_TX_MAX_PRIORITY_FEE, {
74
- description: 'Max priority fee per gas at tx end state (in wei)',
75
- unit: 'wei',
76
- valueType: ValueType.INT,
77
- });
54
+ this.maxPriorityFeeHistogram = this.meter.createHistogram(Metrics.L1_TX_MAX_PRIORITY_FEE);
78
55
 
79
- this.maxFeeHistogram = this.meter.createHistogram(Metrics.L1_TX_MAX_FEE, {
80
- description: 'Max fee per gas at tx end state (in wei)',
81
- unit: 'wei',
82
- valueType: ValueType.INT,
83
- });
56
+ this.maxFeeHistogram = this.meter.createHistogram(Metrics.L1_TX_MAX_FEE);
84
57
 
85
- this.blobFeeHistogram = this.meter.createHistogram(Metrics.L1_TX_BLOB_FEE, {
86
- description: 'Max fee per blob gas at tx end state (in wei)',
87
- unit: 'wei',
88
- valueType: ValueType.INT,
89
- });
58
+ this.blobFeeHistogram = this.meter.createHistogram(Metrics.L1_TX_BLOB_FEE);
90
59
  }
91
60
 
92
61
  /**
@@ -123,17 +92,19 @@ export class L1TxMetrics implements IL1TxMetrics {
123
92
  const attempts = isCancelTx ? state.cancelTxHashes.length : state.txHashes.length;
124
93
  this.txAttemptsUntilMined.record(attempts, attributes);
125
94
 
126
- // Record gas prices at end state (in wei as integers)
127
- const maxPriorityFeeWei = Number(state.gasPrice.maxPriorityFeePerGas);
128
- const maxFeeWei = Number(state.gasPrice.maxFeePerGas);
129
- const blobFeeWei = state.gasPrice.maxFeePerBlobGas ? Number(state.gasPrice.maxFeePerBlobGas) : undefined;
95
+ // Record gas prices at end state, converted from wei to gwei to match metric unit definitions
96
+ const weiToGwei = 1e9;
97
+ const maxPriorityFeeGwei = Number(state.gasPrice.maxPriorityFeePerGas) / weiToGwei;
98
+ const maxFeeGwei = Number(state.gasPrice.maxFeePerGas) / weiToGwei;
99
+ const blobFeeGwei = state.gasPrice.maxFeePerBlobGas
100
+ ? Number(state.gasPrice.maxFeePerBlobGas) / weiToGwei
101
+ : undefined;
130
102
 
131
- this.maxPriorityFeeHistogram.record(maxPriorityFeeWei, attributes);
132
- this.maxFeeHistogram.record(maxFeeWei, attributes);
103
+ this.maxPriorityFeeHistogram.record(maxPriorityFeeGwei, attributes);
104
+ this.maxFeeHistogram.record(maxFeeGwei, attributes);
133
105
 
134
- // Record blob fee if present (in wei as integer)
135
- if (blobFeeWei !== undefined) {
136
- this.blobFeeHistogram.record(blobFeeWei, attributes);
106
+ if (blobFeeGwei !== undefined) {
107
+ this.blobFeeHistogram.record(blobFeeGwei, attributes);
137
108
  }
138
109
 
139
110
  this.logger.debug(`Recorded tx end state metrics`, {
@@ -142,9 +113,9 @@ export class L1TxMetrics implements IL1TxMetrics {
142
113
  isCancelTx,
143
114
  isReverted,
144
115
  scope: this.scope,
145
- maxPriorityFeeWei,
146
- maxFeeWei,
147
- blobFeeWei,
116
+ maxPriorityFeeGwei,
117
+ maxFeeGwei,
118
+ blobFeeGwei,
148
119
  });
149
120
  }
150
121