@aztec/node-lib 3.0.0-nightly.20251004 → 3.0.0-nightly.20251007
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.
- package/dest/factories/index.d.ts +2 -0
- package/dest/factories/index.d.ts.map +1 -0
- package/dest/factories/index.js +1 -0
- package/dest/factories/l1_tx_utils.d.ts +53 -0
- package/dest/factories/l1_tx_utils.d.ts.map +1 -0
- package/dest/factories/l1_tx_utils.js +50 -0
- package/dest/metrics/index.d.ts +2 -0
- package/dest/metrics/index.d.ts.map +1 -0
- package/dest/metrics/index.js +1 -0
- package/dest/metrics/l1_tx_metrics.d.ts +29 -0
- package/dest/metrics/l1_tx_metrics.d.ts.map +1 -0
- package/dest/metrics/l1_tx_metrics.js +138 -0
- package/dest/stores/index.d.ts +2 -0
- package/dest/stores/index.d.ts.map +1 -0
- package/dest/stores/index.js +1 -0
- package/dest/stores/l1_tx_store.d.ts +89 -0
- package/dest/stores/l1_tx_store.d.ts.map +1 -0
- package/dest/stores/l1_tx_store.js +264 -0
- package/package.json +24 -20
- package/src/factories/index.ts +1 -0
- package/src/factories/l1_tx_utils.ts +122 -0
- package/src/metrics/index.ts +1 -0
- package/src/metrics/l1_tx_metrics.ts +169 -0
- package/src/stores/index.ts +1 -0
- package/src/stores/l1_tx_store.ts +387 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/factories/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './l1_tx_utils.js';
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { EthSigner, ExtendedViemWalletClient, L1TxUtilsConfig, ViemClient } from '@aztec/ethereum';
|
|
2
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
3
|
+
import type { DateProvider } from '@aztec/foundation/timer';
|
|
4
|
+
import type { DataStoreConfig } from '@aztec/kv-store/config';
|
|
5
|
+
import type { TelemetryClient } from '@aztec/telemetry-client';
|
|
6
|
+
import type { L1TxScope } from '../metrics/l1_tx_metrics.js';
|
|
7
|
+
/**
|
|
8
|
+
* Creates L1TxUtils with blobs from multiple Viem wallets, sharing store and metrics.
|
|
9
|
+
*/
|
|
10
|
+
export declare function createL1TxUtilsWithBlobsFromViemWallet(clients: ExtendedViemWalletClient[], config: DataStoreConfig & Partial<L1TxUtilsConfig> & {
|
|
11
|
+
debugMaxGasLimit?: boolean;
|
|
12
|
+
scope?: L1TxScope;
|
|
13
|
+
}, deps: {
|
|
14
|
+
telemetry: TelemetryClient;
|
|
15
|
+
logger?: ReturnType<typeof createLogger>;
|
|
16
|
+
dateProvider?: DateProvider;
|
|
17
|
+
}): Promise<import("@aztec/ethereum/l1-tx-utils-with-blobs").L1TxUtilsWithBlobs[]>;
|
|
18
|
+
/**
|
|
19
|
+
* Creates L1TxUtils with blobs from multiple EthSigners, sharing store and metrics.
|
|
20
|
+
*/
|
|
21
|
+
export declare function createL1TxUtilsWithBlobsFromEthSigner(client: ViemClient, signers: EthSigner[], config: DataStoreConfig & Partial<L1TxUtilsConfig> & {
|
|
22
|
+
debugMaxGasLimit?: boolean;
|
|
23
|
+
scope?: L1TxScope;
|
|
24
|
+
}, deps: {
|
|
25
|
+
telemetry: TelemetryClient;
|
|
26
|
+
logger?: ReturnType<typeof createLogger>;
|
|
27
|
+
dateProvider?: DateProvider;
|
|
28
|
+
}): Promise<import("@aztec/ethereum/l1-tx-utils-with-blobs").L1TxUtilsWithBlobs[]>;
|
|
29
|
+
/**
|
|
30
|
+
* Creates L1TxUtils (without blobs) from multiple Viem wallets, sharing store and metrics.
|
|
31
|
+
*/
|
|
32
|
+
export declare function createL1TxUtilsFromViemWalletWithStore(clients: ExtendedViemWalletClient[], config: DataStoreConfig & Partial<L1TxUtilsConfig> & {
|
|
33
|
+
debugMaxGasLimit?: boolean;
|
|
34
|
+
scope?: L1TxScope;
|
|
35
|
+
}, deps: {
|
|
36
|
+
telemetry: TelemetryClient;
|
|
37
|
+
logger?: ReturnType<typeof createLogger>;
|
|
38
|
+
dateProvider?: DateProvider;
|
|
39
|
+
scope?: L1TxScope;
|
|
40
|
+
}): Promise<import("@aztec/ethereum").L1TxUtils[]>;
|
|
41
|
+
/**
|
|
42
|
+
* Creates L1TxUtils (without blobs) from multiple EthSigners, sharing store and metrics.
|
|
43
|
+
*/
|
|
44
|
+
export declare function createL1TxUtilsFromEthSignerWithStore(client: ViemClient, signers: EthSigner[], config: DataStoreConfig & Partial<L1TxUtilsConfig> & {
|
|
45
|
+
debugMaxGasLimit?: boolean;
|
|
46
|
+
scope?: L1TxScope;
|
|
47
|
+
}, deps: {
|
|
48
|
+
telemetry: TelemetryClient;
|
|
49
|
+
logger?: ReturnType<typeof createLogger>;
|
|
50
|
+
dateProvider?: DateProvider;
|
|
51
|
+
scope?: L1TxScope;
|
|
52
|
+
}): Promise<import("@aztec/ethereum").L1TxUtils[]>;
|
|
53
|
+
//# sourceMappingURL=l1_tx_utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"l1_tx_utils.d.ts","sourceRoot":"","sources":["../../src/factories/l1_tx_utils.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,wBAAwB,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAMxG,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAE9D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAE/D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AA+B7D;;GAEG;AACH,wBAAsB,sCAAsC,CAC1D,OAAO,EAAE,wBAAwB,EAAE,EACnC,MAAM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AAE,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAAC,KAAK,CAAC,EAAE,SAAS,CAAA;CAAE,EACtG,IAAI,EAAE;IACJ,SAAS,EAAE,eAAe,CAAC;IAC3B,MAAM,CAAC,EAAE,UAAU,CAAC,OAAO,YAAY,CAAC,CAAC;IACzC,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,KAAK,CAAC,EAAE,SAAS,CAAC;CACnB,kDAKF"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { createL1TxUtilsFromEthSigner as createL1TxUtilsFromEthSignerBase, createL1TxUtilsFromViemWallet as createL1TxUtilsFromViemWalletBase } from '@aztec/ethereum';
|
|
2
|
+
import { createL1TxUtilsWithBlobsFromEthSigner as createL1TxUtilsWithBlobsFromEthSignerBase, createL1TxUtilsWithBlobsFromViemWallet as createL1TxUtilsWithBlobsFromViemWalletBase } from '@aztec/ethereum/l1-tx-utils-with-blobs';
|
|
3
|
+
import { omit } from '@aztec/foundation/collection';
|
|
4
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
5
|
+
import { createStore } from '@aztec/kv-store/lmdb-v2';
|
|
6
|
+
import { L1TxMetrics } from '../metrics/l1_tx_metrics.js';
|
|
7
|
+
import { L1TxStore } from '../stores/l1_tx_store.js';
|
|
8
|
+
const L1_TX_STORE_NAME = 'l1-tx-utils';
|
|
9
|
+
/**
|
|
10
|
+
* Creates shared dependencies (logger, store, metrics) for L1TxUtils instances.
|
|
11
|
+
*/ async function createSharedDeps(config, deps) {
|
|
12
|
+
const logger = deps.logger ?? createLogger('l1-tx-utils');
|
|
13
|
+
// Note that we do NOT bind them to the rollup address, since we still need to
|
|
14
|
+
// monitor and cancel txs for previous rollups to free up our nonces.
|
|
15
|
+
const noRollupConfig = omit(config, 'l1Contracts');
|
|
16
|
+
const kvStore = await createStore(L1_TX_STORE_NAME, L1TxStore.SCHEMA_VERSION, noRollupConfig, logger);
|
|
17
|
+
const store = new L1TxStore(kvStore, logger);
|
|
18
|
+
const meter = deps.telemetry.getMeter('L1TxUtils');
|
|
19
|
+
const metrics = new L1TxMetrics(meter, config.scope ?? 'other', logger);
|
|
20
|
+
return {
|
|
21
|
+
logger,
|
|
22
|
+
store,
|
|
23
|
+
metrics,
|
|
24
|
+
dateProvider: deps.dateProvider
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Creates L1TxUtils with blobs from multiple Viem wallets, sharing store and metrics.
|
|
29
|
+
*/ export async function createL1TxUtilsWithBlobsFromViemWallet(clients, config, deps) {
|
|
30
|
+
const sharedDeps = await createSharedDeps(config, deps);
|
|
31
|
+
return clients.map((client)=>createL1TxUtilsWithBlobsFromViemWalletBase(client, sharedDeps, config, config.debugMaxGasLimit));
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Creates L1TxUtils with blobs from multiple EthSigners, sharing store and metrics.
|
|
35
|
+
*/ export async function createL1TxUtilsWithBlobsFromEthSigner(client, signers, config, deps) {
|
|
36
|
+
const sharedDeps = await createSharedDeps(config, deps);
|
|
37
|
+
return signers.map((signer)=>createL1TxUtilsWithBlobsFromEthSignerBase(client, signer, sharedDeps, config, config.debugMaxGasLimit));
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Creates L1TxUtils (without blobs) from multiple Viem wallets, sharing store and metrics.
|
|
41
|
+
*/ export async function createL1TxUtilsFromViemWalletWithStore(clients, config, deps) {
|
|
42
|
+
const sharedDeps = await createSharedDeps(config, deps);
|
|
43
|
+
return clients.map((client)=>createL1TxUtilsFromViemWalletBase(client, sharedDeps, config));
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Creates L1TxUtils (without blobs) from multiple EthSigners, sharing store and metrics.
|
|
47
|
+
*/ export async function createL1TxUtilsFromEthSignerWithStore(client, signers, config, deps) {
|
|
48
|
+
const sharedDeps = await createSharedDeps(config, deps);
|
|
49
|
+
return signers.map((signer)=>createL1TxUtilsFromEthSignerBase(client, signer, sharedDeps, config));
|
|
50
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/metrics/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './l1_tx_metrics.js';
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { IL1TxMetrics, L1TxState } from '@aztec/ethereum';
|
|
2
|
+
import { type Meter } from '@aztec/telemetry-client';
|
|
3
|
+
export type L1TxScope = 'sequencer' | 'prover' | 'other';
|
|
4
|
+
/**
|
|
5
|
+
* Metrics for L1 transaction utils tracking tx lifecycle and gas costs.
|
|
6
|
+
*/
|
|
7
|
+
export declare class L1TxMetrics implements IL1TxMetrics {
|
|
8
|
+
private meter;
|
|
9
|
+
private scope;
|
|
10
|
+
private logger;
|
|
11
|
+
private txMinedDuration;
|
|
12
|
+
private txAttemptsUntilMined;
|
|
13
|
+
private txMinedCount;
|
|
14
|
+
private txRevertedCount;
|
|
15
|
+
private txCancelledCount;
|
|
16
|
+
private txNotMinedCount;
|
|
17
|
+
private maxPriorityFeeHistogram;
|
|
18
|
+
private maxFeeHistogram;
|
|
19
|
+
private blobFeeHistogram;
|
|
20
|
+
constructor(meter: Meter, scope?: L1TxScope, logger?: import("@aztec/foundation/log").Logger);
|
|
21
|
+
/**
|
|
22
|
+
* Records metrics when a transaction is mined.
|
|
23
|
+
* @param state - The L1 transaction state
|
|
24
|
+
* @param l1Timestamp - The current L1 timestamp
|
|
25
|
+
*/
|
|
26
|
+
recordMinedTx(state: L1TxState, l1Timestamp: Date): void;
|
|
27
|
+
recordDroppedTx(state: L1TxState): void;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=l1_tx_metrics.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"l1_tx_metrics.d.ts","sourceRoot":"","sources":["../../src/metrics/l1_tx_metrics.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAG/D,OAAO,EAGL,KAAK,KAAK,EAIX,MAAM,yBAAyB,CAAC;AAEjC,MAAM,MAAM,SAAS,GAAG,WAAW,GAAG,QAAQ,GAAG,OAAO,CAAC;AAEzD;;GAEG;AACH,qBAAa,WAAY,YAAW,YAAY;IAmB5C,OAAO,CAAC,KAAK;IACb,OAAO,CAAC,KAAK;IACb,OAAO,CAAC,MAAM;IAnBhB,OAAO,CAAC,eAAe,CAAY;IAGnC,OAAO,CAAC,oBAAoB,CAAY;IAGxC,OAAO,CAAC,YAAY,CAAgB;IACpC,OAAO,CAAC,eAAe,CAAgB;IACvC,OAAO,CAAC,gBAAgB,CAAgB;IACxC,OAAO,CAAC,eAAe,CAAgB;IAGvC,OAAO,CAAC,uBAAuB,CAAY;IAC3C,OAAO,CAAC,eAAe,CAAY;IACnC,OAAO,CAAC,gBAAgB,CAAY;gBAG1B,KAAK,EAAE,KAAK,EACZ,KAAK,GAAE,SAAmB,EAC1B,MAAM,yCAAsC;IAqDtD;;;;OAIG;IACI,aAAa,CAAC,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,IAAI,GAAG,IAAI;IAsDxD,eAAe,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI;CAkB/C"}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { TxUtilsState } from '@aztec/ethereum';
|
|
2
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
3
|
+
import { Attributes, Metrics, ValueType } from '@aztec/telemetry-client';
|
|
4
|
+
/**
|
|
5
|
+
* Metrics for L1 transaction utils tracking tx lifecycle and gas costs.
|
|
6
|
+
*/ export class L1TxMetrics {
|
|
7
|
+
meter;
|
|
8
|
+
scope;
|
|
9
|
+
logger;
|
|
10
|
+
// Time until tx is mined
|
|
11
|
+
txMinedDuration;
|
|
12
|
+
// Number of attempts until mined
|
|
13
|
+
txAttemptsUntilMined;
|
|
14
|
+
// Counters for end states
|
|
15
|
+
txMinedCount;
|
|
16
|
+
txRevertedCount;
|
|
17
|
+
txCancelledCount;
|
|
18
|
+
txNotMinedCount;
|
|
19
|
+
// Gas price histograms (at end state, in wei)
|
|
20
|
+
maxPriorityFeeHistogram;
|
|
21
|
+
maxFeeHistogram;
|
|
22
|
+
blobFeeHistogram;
|
|
23
|
+
constructor(meter, scope = 'other', logger = createLogger('l1-tx-utils:metrics')){
|
|
24
|
+
this.meter = meter;
|
|
25
|
+
this.scope = scope;
|
|
26
|
+
this.logger = logger;
|
|
27
|
+
this.txMinedDuration = this.meter.createHistogram(Metrics.L1_TX_MINED_DURATION, {
|
|
28
|
+
description: 'Time from initial tx send until mined',
|
|
29
|
+
unit: 's',
|
|
30
|
+
valueType: ValueType.INT
|
|
31
|
+
});
|
|
32
|
+
this.txAttemptsUntilMined = this.meter.createHistogram(Metrics.L1_TX_ATTEMPTS_UNTIL_MINED, {
|
|
33
|
+
description: 'Number of tx attempts (including speed-ups) until mined',
|
|
34
|
+
unit: 'attempts',
|
|
35
|
+
valueType: ValueType.INT
|
|
36
|
+
});
|
|
37
|
+
this.txMinedCount = this.meter.createUpDownCounter(Metrics.L1_TX_MINED_COUNT, {
|
|
38
|
+
description: 'Count of transactions successfully mined',
|
|
39
|
+
valueType: ValueType.INT
|
|
40
|
+
});
|
|
41
|
+
this.txRevertedCount = this.meter.createUpDownCounter(Metrics.L1_TX_REVERTED_COUNT, {
|
|
42
|
+
description: 'Count of transactions that reverted',
|
|
43
|
+
valueType: ValueType.INT
|
|
44
|
+
});
|
|
45
|
+
this.txCancelledCount = this.meter.createUpDownCounter(Metrics.L1_TX_CANCELLED_COUNT, {
|
|
46
|
+
description: 'Count of transactions cancelled',
|
|
47
|
+
valueType: ValueType.INT
|
|
48
|
+
});
|
|
49
|
+
this.txNotMinedCount = this.meter.createUpDownCounter(Metrics.L1_TX_NOT_MINED_COUNT, {
|
|
50
|
+
description: 'Count of transactions not mined (timed out)',
|
|
51
|
+
valueType: ValueType.INT
|
|
52
|
+
});
|
|
53
|
+
this.maxPriorityFeeHistogram = this.meter.createHistogram(Metrics.L1_TX_MAX_PRIORITY_FEE, {
|
|
54
|
+
description: 'Max priority fee per gas at tx end state (in wei)',
|
|
55
|
+
unit: 'wei',
|
|
56
|
+
valueType: ValueType.INT
|
|
57
|
+
});
|
|
58
|
+
this.maxFeeHistogram = this.meter.createHistogram(Metrics.L1_TX_MAX_FEE, {
|
|
59
|
+
description: 'Max fee per gas at tx end state (in wei)',
|
|
60
|
+
unit: 'wei',
|
|
61
|
+
valueType: ValueType.INT
|
|
62
|
+
});
|
|
63
|
+
this.blobFeeHistogram = this.meter.createHistogram(Metrics.L1_TX_BLOB_FEE, {
|
|
64
|
+
description: 'Max fee per blob gas at tx end state (in wei)',
|
|
65
|
+
unit: 'wei',
|
|
66
|
+
valueType: ValueType.INT
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Records metrics when a transaction is mined.
|
|
71
|
+
* @param state - The L1 transaction state
|
|
72
|
+
* @param l1Timestamp - The current L1 timestamp
|
|
73
|
+
*/ recordMinedTx(state, l1Timestamp) {
|
|
74
|
+
if (state.status !== TxUtilsState.MINED) {
|
|
75
|
+
this.logger.warn(`Attempted to record mined tx metrics for a tx not in MINED state (state: ${TxUtilsState[state.status]})`, {
|
|
76
|
+
scope: this.scope,
|
|
77
|
+
nonce: state.nonce
|
|
78
|
+
});
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
const attributes = {
|
|
82
|
+
[Attributes.L1_TX_SCOPE]: this.scope
|
|
83
|
+
};
|
|
84
|
+
const isCancelTx = state.cancelTxHashes.length > 0;
|
|
85
|
+
const isReverted = state.receipt?.status === 'reverted';
|
|
86
|
+
if (isCancelTx) {
|
|
87
|
+
this.txCancelledCount.add(1, attributes);
|
|
88
|
+
} else if (isReverted) {
|
|
89
|
+
this.txRevertedCount.add(1, attributes);
|
|
90
|
+
} else {
|
|
91
|
+
this.txMinedCount.add(1, attributes);
|
|
92
|
+
}
|
|
93
|
+
// Record time to mine using provided L1 timestamp
|
|
94
|
+
const duration = Math.floor((l1Timestamp.getTime() - state.sentAtL1Ts.getTime()) / 1000);
|
|
95
|
+
this.txMinedDuration.record(duration, attributes);
|
|
96
|
+
// Record number of attempts until mined
|
|
97
|
+
const attempts = isCancelTx ? state.cancelTxHashes.length : state.txHashes.length;
|
|
98
|
+
this.txAttemptsUntilMined.record(attempts, attributes);
|
|
99
|
+
// Record gas prices at end state (in wei as integers)
|
|
100
|
+
const maxPriorityFeeWei = Number(state.gasPrice.maxPriorityFeePerGas);
|
|
101
|
+
const maxFeeWei = Number(state.gasPrice.maxFeePerGas);
|
|
102
|
+
const blobFeeWei = state.gasPrice.maxFeePerBlobGas ? Number(state.gasPrice.maxFeePerBlobGas) : undefined;
|
|
103
|
+
this.maxPriorityFeeHistogram.record(maxPriorityFeeWei, attributes);
|
|
104
|
+
this.maxFeeHistogram.record(maxFeeWei, attributes);
|
|
105
|
+
// Record blob fee if present (in wei as integer)
|
|
106
|
+
if (blobFeeWei !== undefined) {
|
|
107
|
+
this.blobFeeHistogram.record(blobFeeWei, attributes);
|
|
108
|
+
}
|
|
109
|
+
this.logger.debug(`Recorded tx end state metrics`, {
|
|
110
|
+
status: TxUtilsState[state.status],
|
|
111
|
+
nonce: state.nonce,
|
|
112
|
+
isCancelTx,
|
|
113
|
+
isReverted,
|
|
114
|
+
scope: this.scope,
|
|
115
|
+
maxPriorityFeeWei,
|
|
116
|
+
maxFeeWei,
|
|
117
|
+
blobFeeWei
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
recordDroppedTx(state) {
|
|
121
|
+
if (state.status !== TxUtilsState.NOT_MINED) {
|
|
122
|
+
this.logger.warn(`Attempted to record dropped tx metrics for a tx not in NOT_MINED state (state: ${TxUtilsState[state.status]})`, {
|
|
123
|
+
scope: this.scope,
|
|
124
|
+
nonce: state.nonce
|
|
125
|
+
});
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
const attributes = {
|
|
129
|
+
[Attributes.L1_TX_SCOPE]: this.scope
|
|
130
|
+
};
|
|
131
|
+
this.txNotMinedCount.add(1, attributes);
|
|
132
|
+
this.logger.debug(`Recorded tx dropped metrics`, {
|
|
133
|
+
status: TxUtilsState[state.status],
|
|
134
|
+
nonce: state.nonce,
|
|
135
|
+
scope: this.scope
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/stores/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './l1_tx_store.js';
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import type { IL1TxStore, L1BlobInputs, L1TxState } from '@aztec/ethereum';
|
|
2
|
+
import type { Logger } from '@aztec/foundation/log';
|
|
3
|
+
import type { AztecAsyncKVStore } from '@aztec/kv-store';
|
|
4
|
+
/**
|
|
5
|
+
* Store for persisting L1 transaction states across all L1TxUtils instances.
|
|
6
|
+
* Each state is stored individually with a unique ID, and blobs are stored separately.
|
|
7
|
+
* @remarks This class lives in this package instead of `ethereum` because it depends on `kv-store`.
|
|
8
|
+
*/
|
|
9
|
+
export declare class L1TxStore implements IL1TxStore {
|
|
10
|
+
private readonly store;
|
|
11
|
+
private readonly log;
|
|
12
|
+
static readonly SCHEMA_VERSION = 2;
|
|
13
|
+
private readonly states;
|
|
14
|
+
private readonly blobs;
|
|
15
|
+
private readonly stateIdCounter;
|
|
16
|
+
constructor(store: AztecAsyncKVStore, log?: Logger);
|
|
17
|
+
/**
|
|
18
|
+
* Gets the next available state ID for an account.
|
|
19
|
+
*/
|
|
20
|
+
consumeNextStateId(account: string): Promise<number>;
|
|
21
|
+
/**
|
|
22
|
+
* Creates a storage key for state/blob data.
|
|
23
|
+
*/
|
|
24
|
+
private makeKey;
|
|
25
|
+
/**
|
|
26
|
+
* Saves a single transaction state for a specific account.
|
|
27
|
+
* Blobs are not stored here, use saveBlobs instead.
|
|
28
|
+
* @param account - The sender account address
|
|
29
|
+
* @param state - Transaction state to save
|
|
30
|
+
*/
|
|
31
|
+
saveState(account: string, state: L1TxState): Promise<L1TxState>;
|
|
32
|
+
/**
|
|
33
|
+
* Saves blobs for a given state.
|
|
34
|
+
* @param account - The sender account address
|
|
35
|
+
* @param stateId - The state ID
|
|
36
|
+
* @param blobInputs - Blob inputs to save
|
|
37
|
+
*/
|
|
38
|
+
saveBlobs(account: string, stateId: number, blobInputs: L1BlobInputs | undefined): Promise<void>;
|
|
39
|
+
/**
|
|
40
|
+
* Loads all transaction states for a specific account.
|
|
41
|
+
* @param account - The sender account address
|
|
42
|
+
* @returns Array of transaction states with their IDs
|
|
43
|
+
*/
|
|
44
|
+
loadStates(account: string): Promise<L1TxState[]>;
|
|
45
|
+
/**
|
|
46
|
+
* Loads a single state by ID.
|
|
47
|
+
* @param account - The sender account address
|
|
48
|
+
* @param stateId - The state ID
|
|
49
|
+
* @returns The transaction state or undefined if not found
|
|
50
|
+
*/
|
|
51
|
+
loadState(account: string, stateId: number): Promise<L1TxState | undefined>;
|
|
52
|
+
/**
|
|
53
|
+
* Deletes a specific state and its associated blobs.
|
|
54
|
+
* @param account - The sender account address
|
|
55
|
+
* @param stateId - The state ID to delete
|
|
56
|
+
*/
|
|
57
|
+
deleteState(account: string, stateId: number): Promise<void>;
|
|
58
|
+
/**
|
|
59
|
+
* Clears all transaction states for a specific account.
|
|
60
|
+
* @param account - The sender account address
|
|
61
|
+
*/
|
|
62
|
+
clearStates(account: string): Promise<void>;
|
|
63
|
+
/**
|
|
64
|
+
* Gets all accounts that have stored states.
|
|
65
|
+
* @returns Array of account addresses
|
|
66
|
+
*/
|
|
67
|
+
getAllAccounts(): Promise<string[]>;
|
|
68
|
+
/**
|
|
69
|
+
* Closes the store.
|
|
70
|
+
*/
|
|
71
|
+
close(): Promise<void>;
|
|
72
|
+
/**
|
|
73
|
+
* Serializes an L1TxState for storage.
|
|
74
|
+
*/
|
|
75
|
+
private serializeState;
|
|
76
|
+
/**
|
|
77
|
+
* Deserializes a stored state back to L1TxState.
|
|
78
|
+
*/
|
|
79
|
+
private deserializeState;
|
|
80
|
+
/**
|
|
81
|
+
* Serializes blob inputs for separate storage.
|
|
82
|
+
*/
|
|
83
|
+
private serializeBlobInputs;
|
|
84
|
+
/**
|
|
85
|
+
* Deserializes blob inputs from storage, combining blob data with metadata.
|
|
86
|
+
*/
|
|
87
|
+
private deserializeBlobInputs;
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=l1_tx_store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"l1_tx_store.d.ts","sourceRoot":"","sources":["../../src/stores/l1_tx_store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAc,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEvF,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAEpD,OAAO,KAAK,EAAE,iBAAiB,EAAiB,MAAM,iBAAiB,CAAC;AA2ExE;;;;GAIG;AACH,qBAAa,SAAU,YAAW,UAAU;IAQxC,OAAO,CAAC,QAAQ,CAAC,KAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,GAAG;IARtB,gBAAuB,cAAc,KAAK;IAE1C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAgC;IACvD,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAgC;IACtD,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAgC;gBAG5C,KAAK,EAAE,iBAAiB,EACxB,GAAG,GAAE,MAA0C;IAOlE;;OAEG;IACI,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAS3D;;OAEG;IACH,OAAO,CAAC,OAAO;IAIf;;;;;OAK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