@aztec/node-lib 0.0.1-commit.5daedc8 → 0.0.1-commit.6201a7b05

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,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
  /**