@aztec/node-lib 0.0.1-commit.d3ec352c → 0.0.1-commit.d58ff9d0

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,17 +1,15 @@
1
- import {
2
- createL1TxUtilsFromEthSigner as createL1TxUtilsFromEthSignerBase,
3
- createL1TxUtilsFromViemWallet as createL1TxUtilsFromViemWalletBase,
4
- } from '@aztec/ethereum';
5
- import type { EthSigner, ExtendedViemWalletClient, L1TxUtilsConfig, ViemClient } from '@aztec/ethereum';
6
- import {
7
- createL1TxUtilsWithBlobsFromEthSigner as createL1TxUtilsWithBlobsFromEthSignerBase,
8
- createL1TxUtilsWithBlobsFromViemWallet as createL1TxUtilsWithBlobsFromViemWalletBase,
9
- } from '@aztec/ethereum/l1-tx-utils-with-blobs';
1
+ import type { BlobKzgInstance } from '@aztec/blob-lib/types';
2
+ import type { EthSigner } from '@aztec/ethereum/eth-signer';
3
+ import { createDelayer, createL1TxUtils as createL1TxUtilsBase } from '@aztec/ethereum/l1-tx-utils';
4
+ import type { L1TxUtilsConfig } from '@aztec/ethereum/l1-tx-utils';
5
+ import { createForwarderL1TxUtils as createForwarderL1TxUtilsBase } from '@aztec/ethereum/l1-tx-utils-with-blobs';
6
+ import type { ExtendedViemWalletClient, ViemClient } from '@aztec/ethereum/types';
10
7
  import { omit } from '@aztec/foundation/collection';
8
+ import type { EthAddress } from '@aztec/foundation/eth-address';
11
9
  import { createLogger } from '@aztec/foundation/log';
12
10
  import type { DateProvider } from '@aztec/foundation/timer';
13
- import type { DataStoreConfig } from '@aztec/kv-store/config';
14
11
  import { createStore } from '@aztec/kv-store/lmdb-v2';
12
+ import type { DataStoreConfig } from '@aztec/stdlib/kv-store';
15
13
  import type { TelemetryClient } from '@aztec/telemetry-client';
16
14
 
17
15
  import type { L1TxScope } from '../metrics/l1_tx_metrics.js';
@@ -21,102 +19,138 @@ import { L1TxStore } from '../stores/l1_tx_store.js';
21
19
  const L1_TX_STORE_NAME = 'l1-tx-utils';
22
20
 
23
21
  /**
24
- * 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.
25
24
  */
26
25
  async function createSharedDeps(
27
- config: DataStoreConfig & { scope?: L1TxScope },
26
+ config: DataStoreConfig & Partial<L1TxUtilsConfig> & { scope?: L1TxScope },
28
27
  deps: {
29
28
  telemetry: TelemetryClient;
30
29
  logger?: ReturnType<typeof createLogger>;
31
- dateProvider?: DateProvider;
30
+ dateProvider: DateProvider;
32
31
  },
33
32
  ) {
34
33
  const logger = deps.logger ?? createLogger('l1-tx-utils');
35
34
 
36
35
  // Note that we do NOT bind them to the rollup address, since we still need to
37
36
  // monitor and cancel txs for previous rollups to free up our nonces.
38
- const noRollupConfig = omit(config, 'l1Contracts');
39
- 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());
40
39
  const store = new L1TxStore(kvStore, logger);
41
40
 
42
41
  const meter = deps.telemetry.getMeter('L1TxUtils');
43
42
  const metrics = new L1TxMetrics(meter, config.scope ?? 'other', logger);
44
43
 
45
- return { logger, store, metrics, dateProvider: deps.dateProvider };
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;
49
+
50
+ return { logger, store, metrics, dateProvider: deps.dateProvider, delayer };
46
51
  }
47
52
 
48
53
  /**
49
- * Creates L1TxUtils with 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.
50
56
  */
51
- export async function createL1TxUtilsWithBlobsFromViemWallet(
57
+ export async function createL1TxUtilsFromWallets(
52
58
  clients: ExtendedViemWalletClient[],
53
59
  config: DataStoreConfig & Partial<L1TxUtilsConfig> & { debugMaxGasLimit?: boolean; scope?: L1TxScope },
54
60
  deps: {
55
61
  telemetry: TelemetryClient;
56
62
  logger?: ReturnType<typeof createLogger>;
57
- dateProvider?: DateProvider;
63
+ dateProvider: DateProvider;
64
+ kzg?: BlobKzgInstance;
58
65
  },
59
66
  ) {
60
67
  const sharedDeps = await createSharedDeps(config, deps);
61
68
 
62
- return clients.map(client =>
63
- createL1TxUtilsWithBlobsFromViemWalletBase(client, sharedDeps, config, config.debugMaxGasLimit),
64
- );
69
+ return clients.map(client => createL1TxUtilsBase(client, { ...sharedDeps, kzg: deps.kzg }, config));
65
70
  }
66
71
 
67
72
  /**
68
- * Creates L1TxUtils with blobs from multiple EthSigners, sharing store and metrics.
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.
69
76
  */
70
- export async function createL1TxUtilsWithBlobsFromEthSigner(
77
+ export async function createL1TxUtilsFromSigners(
71
78
  client: ViemClient,
72
79
  signers: EthSigner[],
73
80
  config: DataStoreConfig & Partial<L1TxUtilsConfig> & { debugMaxGasLimit?: boolean; scope?: L1TxScope },
74
81
  deps: {
75
82
  telemetry: TelemetryClient;
76
83
  logger?: ReturnType<typeof createLogger>;
77
- dateProvider?: DateProvider;
84
+ dateProvider: DateProvider;
85
+ kzg?: BlobKzgInstance;
78
86
  },
79
87
  ) {
80
88
  const sharedDeps = await createSharedDeps(config, deps);
81
89
 
82
- return signers.map(signer =>
83
- createL1TxUtilsWithBlobsFromEthSignerBase(client, signer, sharedDeps, config, config.debugMaxGasLimit),
84
- );
90
+ // Deduplicate signers by address to avoid creating multiple L1TxUtils instances
91
+ // for the same publisher address (e.g., when multiple attesters share the same publisher key)
92
+ const signersByAddress = new Map<string, EthSigner>();
93
+ for (const signer of signers) {
94
+ const addressKey = signer.address.toString().toLowerCase();
95
+ if (!signersByAddress.has(addressKey)) {
96
+ signersByAddress.set(addressKey, signer);
97
+ }
98
+ }
99
+
100
+ const uniqueSigners = Array.from(signersByAddress.values());
101
+
102
+ if (uniqueSigners.length < signers.length) {
103
+ sharedDeps.logger.info(
104
+ `Deduplicated ${signers.length} signers to ${uniqueSigners.length} unique publisher addresses`,
105
+ );
106
+ }
107
+
108
+ return uniqueSigners.map(signer => createL1TxUtilsBase({ client, signer }, { ...sharedDeps, kzg: deps.kzg }, config));
85
109
  }
86
110
 
87
111
  /**
88
- * Creates L1TxUtils (without blobs) from multiple Viem wallets, sharing store and metrics.
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.
89
115
  */
90
- export async function createL1TxUtilsFromViemWalletWithStore(
116
+ export async function createForwarderL1TxUtilsFromWallets(
91
117
  clients: ExtendedViemWalletClient[],
118
+ forwarderAddress: EthAddress,
92
119
  config: DataStoreConfig & Partial<L1TxUtilsConfig> & { debugMaxGasLimit?: boolean; scope?: L1TxScope },
93
120
  deps: {
94
121
  telemetry: TelemetryClient;
95
122
  logger?: ReturnType<typeof createLogger>;
96
- dateProvider?: DateProvider;
97
- scope?: L1TxScope;
123
+ dateProvider: DateProvider;
124
+ kzg?: BlobKzgInstance;
98
125
  },
99
126
  ) {
100
127
  const sharedDeps = await createSharedDeps(config, deps);
101
128
 
102
- return clients.map(client => createL1TxUtilsFromViemWalletBase(client, sharedDeps, config));
129
+ return clients.map(client =>
130
+ createForwarderL1TxUtilsBase(client, forwarderAddress, { ...sharedDeps, kzg: deps.kzg }, config),
131
+ );
103
132
  }
104
133
 
105
134
  /**
106
- * Creates L1TxUtils (without blobs) from multiple EthSigners, sharing store and metrics.
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.
107
138
  */
108
- export async function createL1TxUtilsFromEthSignerWithStore(
139
+ export async function createForwarderL1TxUtilsFromSigners(
109
140
  client: ViemClient,
110
141
  signers: EthSigner[],
142
+ forwarderAddress: EthAddress,
111
143
  config: DataStoreConfig & Partial<L1TxUtilsConfig> & { debugMaxGasLimit?: boolean; scope?: L1TxScope },
112
144
  deps: {
113
145
  telemetry: TelemetryClient;
114
146
  logger?: ReturnType<typeof createLogger>;
115
- dateProvider?: DateProvider;
116
- scope?: L1TxScope;
147
+ dateProvider: DateProvider;
148
+ kzg?: BlobKzgInstance;
117
149
  },
118
150
  ) {
119
151
  const sharedDeps = await createSharedDeps(config, deps);
120
152
 
121
- return signers.map(signer => createL1TxUtilsFromEthSignerBase(client, signer, sharedDeps, config));
153
+ return signers.map(signer =>
154
+ createForwarderL1TxUtilsBase({ client, signer }, forwarderAddress, { ...sharedDeps, kzg: deps.kzg }, config),
155
+ );
122
156
  }
@@ -1,5 +1,5 @@
1
- import type { IL1TxMetrics, L1TxState } from '@aztec/ethereum';
2
- import { TxUtilsState } from '@aztec/ethereum';
1
+ import type { IL1TxMetrics, L1TxState } from '@aztec/ethereum/l1-tx-utils';
2
+ import { TxUtilsState } from '@aztec/ethereum/l1-tx-utils';
3
3
  import { createLogger } from '@aztec/foundation/log';
4
4
  import {
5
5
  Attributes,
@@ -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
 
@@ -1,4 +1,4 @@
1
- import type { IL1TxStore, L1BlobInputs, L1TxConfig, L1TxState } from '@aztec/ethereum';
1
+ import type { IL1TxStore, L1BlobInputs, L1TxConfig, L1TxState } from '@aztec/ethereum/l1-tx-utils';
2
2
  import { jsonStringify } from '@aztec/foundation/json-rpc';
3
3
  import type { Logger } from '@aztec/foundation/log';
4
4
  import { createLogger } from '@aztec/foundation/log';
@@ -231,11 +231,18 @@ export class L1TxStore implements IL1TxStore {
231
231
  * @param account - The sender account address
232
232
  * @param stateId - The state ID to delete
233
233
  */
234
- public async deleteState(account: string, stateId: number): Promise<void> {
235
- const key = this.makeKey(account, stateId);
236
- await this.states.delete(key);
237
- await this.blobs.delete(key);
238
- this.log.debug(`Deleted state ${stateId} for account ${account}`);
234
+ public async deleteState(account: string, ...stateIds: number[]): Promise<void> {
235
+ if (stateIds.length === 0) {
236
+ return;
237
+ }
238
+
239
+ await this.store.transactionAsync(async () => {
240
+ for (const stateId of stateIds) {
241
+ const key = this.makeKey(account, stateId);
242
+ await this.states.delete(key);
243
+ await this.blobs.delete(key);
244
+ }
245
+ });
239
246
  }
240
247
 
241
248
  /**
@@ -243,14 +250,16 @@ export class L1TxStore implements IL1TxStore {
243
250
  * @param account - The sender account address
244
251
  */
245
252
  public async clearStates(account: string): Promise<void> {
246
- const states = await this.loadStates(account);
253
+ await this.store.transactionAsync(async () => {
254
+ const states = await this.loadStates(account);
247
255
 
248
- for (const state of states) {
249
- await this.deleteState(account, state.id);
250
- }
256
+ for (const state of states) {
257
+ await this.deleteState(account, state.id);
258
+ }
251
259
 
252
- await this.stateIdCounter.delete(account);
253
- this.log.info(`Cleared all tx states for account ${account}`);
260
+ await this.stateIdCounter.delete(account);
261
+ this.log.info(`Cleared all tx states for account ${account}`);
262
+ });
254
263
  }
255
264
 
256
265
  /**