@aztec/node-lib 0.0.1-commit.03f7ef2
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/README.md +3 -0
- package/dest/actions/build-snapshot-metadata.d.ts +5 -0
- package/dest/actions/build-snapshot-metadata.d.ts.map +1 -0
- package/dest/actions/build-snapshot-metadata.js +19 -0
- package/dest/actions/create-backups.d.ts +6 -0
- package/dest/actions/create-backups.d.ts.map +1 -0
- package/dest/actions/create-backups.js +32 -0
- package/dest/actions/index.d.ts +5 -0
- package/dest/actions/index.d.ts.map +1 -0
- package/dest/actions/index.js +4 -0
- package/dest/actions/snapshot-sync.d.ts +27 -0
- package/dest/actions/snapshot-sync.d.ts.map +1 -0
- package/dest/actions/snapshot-sync.js +236 -0
- package/dest/actions/upload-snapshot.d.ts +12 -0
- package/dest/actions/upload-snapshot.d.ts.map +1 -0
- package/dest/actions/upload-snapshot.js +38 -0
- package/dest/config/index.d.ts +23 -0
- package/dest/config/index.d.ts.map +1 -0
- package/dest/config/index.js +51 -0
- 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 +79 -0
- package/dest/factories/l1_tx_utils.d.ts.map +1 -0
- package/dest/factories/l1_tx_utils.js +90 -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 +272 -0
- package/package.json +102 -0
- package/src/actions/build-snapshot-metadata.ts +29 -0
- package/src/actions/create-backups.ts +41 -0
- package/src/actions/index.ts +4 -0
- package/src/actions/snapshot-sync.ts +277 -0
- package/src/actions/upload-snapshot.ts +50 -0
- package/src/config/index.ts +79 -0
- package/src/factories/index.ts +1 -0
- package/src/factories/l1_tx_utils.ts +212 -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 +396 -0
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { createL1TxUtilsFromEthSigner as createL1TxUtilsFromEthSignerBase, createL1TxUtilsFromViemWallet as createL1TxUtilsFromViemWalletBase } from '@aztec/ethereum/l1-tx-utils';
|
|
2
|
+
import { createForwarderL1TxUtilsFromEthSigner as createForwarderL1TxUtilsFromEthSignerBase, createForwarderL1TxUtilsFromViemWallet as createForwarderL1TxUtilsFromViemWalletBase, 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. Removes duplicates
|
|
35
|
+
*/ export async function createL1TxUtilsWithBlobsFromEthSigner(client, signers, config, deps) {
|
|
36
|
+
const sharedDeps = await createSharedDeps(config, deps);
|
|
37
|
+
// Deduplicate signers by address to avoid creating multiple L1TxUtils instances
|
|
38
|
+
// for the same publisher address (e.g., when multiple attesters share the same publisher key)
|
|
39
|
+
const signersByAddress = new Map();
|
|
40
|
+
for (const signer of signers){
|
|
41
|
+
const addressKey = signer.address.toString().toLowerCase();
|
|
42
|
+
if (!signersByAddress.has(addressKey)) {
|
|
43
|
+
signersByAddress.set(addressKey, signer);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
const uniqueSigners = Array.from(signersByAddress.values());
|
|
47
|
+
if (uniqueSigners.length < signers.length) {
|
|
48
|
+
sharedDeps.logger.info(`Deduplicated ${signers.length} signers to ${uniqueSigners.length} unique publisher addresses`);
|
|
49
|
+
}
|
|
50
|
+
return uniqueSigners.map((signer)=>createL1TxUtilsWithBlobsFromEthSignerBase(client, signer, sharedDeps, config, config.debugMaxGasLimit));
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Creates L1TxUtils (without blobs) from multiple Viem wallets, sharing store and metrics.
|
|
54
|
+
*/ export async function createL1TxUtilsFromViemWalletWithStore(clients, config, deps) {
|
|
55
|
+
const sharedDeps = await createSharedDeps(config, deps);
|
|
56
|
+
return clients.map((client)=>createL1TxUtilsFromViemWalletBase(client, sharedDeps, config));
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Creates L1TxUtils (without blobs) from multiple EthSigners, sharing store and metrics. Removes duplicates.
|
|
60
|
+
*/ export async function createL1TxUtilsFromEthSignerWithStore(client, signers, config, deps) {
|
|
61
|
+
const sharedDeps = await createSharedDeps(config, deps);
|
|
62
|
+
// Deduplicate signers by address to avoid creating multiple L1TxUtils instances
|
|
63
|
+
// for the same publisher address (e.g., when multiple attesters share the same publisher key)
|
|
64
|
+
const signersByAddress = new Map();
|
|
65
|
+
for (const signer of signers){
|
|
66
|
+
const addressKey = signer.address.toString().toLowerCase();
|
|
67
|
+
if (!signersByAddress.has(addressKey)) {
|
|
68
|
+
signersByAddress.set(addressKey, signer);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
const uniqueSigners = Array.from(signersByAddress.values());
|
|
72
|
+
if (uniqueSigners.length < signers.length) {
|
|
73
|
+
sharedDeps.logger.info(`Deduplicated ${signers.length} signers to ${uniqueSigners.length} unique publisher addresses`);
|
|
74
|
+
}
|
|
75
|
+
return uniqueSigners.map((signer)=>createL1TxUtilsFromEthSignerBase(client, signer, sharedDeps, config));
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Creates ForwarderL1TxUtils from multiple Viem wallets, sharing store and metrics.
|
|
79
|
+
* This wraps all transactions through a forwarder contract for testing purposes.
|
|
80
|
+
*/ export async function createForwarderL1TxUtilsFromViemWallet(clients, forwarderAddress, config, deps) {
|
|
81
|
+
const sharedDeps = await createSharedDeps(config, deps);
|
|
82
|
+
return clients.map((client)=>createForwarderL1TxUtilsFromViemWalletBase(client, forwarderAddress, sharedDeps, config, config.debugMaxGasLimit));
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Creates ForwarderL1TxUtils from multiple EthSigners, sharing store and metrics.
|
|
86
|
+
* This wraps all transactions through a forwarder contract for testing purposes.
|
|
87
|
+
*/ export async function createForwarderL1TxUtilsFromEthSigner(client, signers, forwarderAddress, config, deps) {
|
|
88
|
+
const sharedDeps = await createSharedDeps(config, deps);
|
|
89
|
+
return signers.map((signer)=>createForwarderL1TxUtilsFromEthSignerBase(client, signer, forwarderAddress, sharedDeps, config, config.debugMaxGasLimit));
|
|
90
|
+
}
|
|
@@ -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/l1-tx-utils';
|
|
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=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibDFfdHhfbWV0cmljcy5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL21ldHJpY3MvbDFfdHhfbWV0cmljcy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssRUFBRSxZQUFZLEVBQUUsU0FBUyxFQUFFLE1BQU0sNkJBQTZCLENBQUM7QUFHM0UsT0FBTyxFQUdMLEtBQUssS0FBSyxFQUlYLE1BQU0seUJBQXlCLENBQUM7QUFFakMsTUFBTSxNQUFNLFNBQVMsR0FBRyxXQUFXLEdBQUcsUUFBUSxHQUFHLE9BQU8sQ0FBQztBQUV6RDs7R0FFRztBQUNILHFCQUFhLFdBQVksWUFBVyxZQUFZO0lBbUI1QyxPQUFPLENBQUMsS0FBSztJQUNiLE9BQU8sQ0FBQyxLQUFLO0lBQ2IsT0FBTyxDQUFDLE1BQU07SUFuQmhCLE9BQU8sQ0FBQyxlQUFlLENBQVk7SUFHbkMsT0FBTyxDQUFDLG9CQUFvQixDQUFZO0lBR3hDLE9BQU8sQ0FBQyxZQUFZLENBQWdCO0lBQ3BDLE9BQU8sQ0FBQyxlQUFlLENBQWdCO0lBQ3ZDLE9BQU8sQ0FBQyxnQkFBZ0IsQ0FBZ0I7SUFDeEMsT0FBTyxDQUFDLGVBQWUs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,KAAK,GAAE,SAAmB,EAC1B,MAAM,yCAAsC,EAmDrD;IAED;;;;OAIG;IACI,aAAa,CAAC,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,IAAI,GAAG,IAAI,CAoD9D;IAEM,eAAe,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI,CAiB7C;CACF"}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { TxUtilsState } from '@aztec/ethereum/l1-tx-utils';
|
|
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/l1-tx-utils';
|
|
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: number;
|
|
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, ...stateIds: 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=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibDFfdHhfc3RvcmUuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9zdG9yZXMvbDFfdHhfc3RvcmUudHMiXSwibmFtZ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G,OAAO,CAAC,IAAI,CAAC,CAWvD;IAED;;;OAGG;IACU,cAAc,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CAS/C;IAED;;OAEG;IACU,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAGlC;IAED;;OAEG;IACH,OAAO,CAAC,cAAc;IAkCtB;;OAEG;IACH,OAAO,CAAC,gBAAgB;IA2CxB;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAO3B;;OAEG;IACH,OAAO,CAAC,qBAAqB;CAY9B"}
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
import { jsonStringify } from '@aztec/foundation/json-rpc';
|
|
2
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
3
|
+
/**
|
|
4
|
+
* Store for persisting L1 transaction states across all L1TxUtils instances.
|
|
5
|
+
* Each state is stored individually with a unique ID, and blobs are stored separately.
|
|
6
|
+
* @remarks This class lives in this package instead of `ethereum` because it depends on `kv-store`.
|
|
7
|
+
*/ export class L1TxStore {
|
|
8
|
+
store;
|
|
9
|
+
log;
|
|
10
|
+
static SCHEMA_VERSION = 2;
|
|
11
|
+
states;
|
|
12
|
+
blobs;
|
|
13
|
+
stateIdCounter;
|
|
14
|
+
constructor(store, log = createLogger('l1-tx-utils:store')){
|
|
15
|
+
this.store = store;
|
|
16
|
+
this.log = log;
|
|
17
|
+
this.states = store.openMap('l1_tx_states');
|
|
18
|
+
this.blobs = store.openMap('l1_tx_blobs');
|
|
19
|
+
this.stateIdCounter = store.openMap('l1_tx_state_id_counter');
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Gets the next available state ID for an account.
|
|
23
|
+
*/ consumeNextStateId(account) {
|
|
24
|
+
return this.store.transactionAsync(async ()=>{
|
|
25
|
+
const currentId = await this.stateIdCounter.getAsync(account) ?? 0;
|
|
26
|
+
const nextId = currentId + 1;
|
|
27
|
+
await this.stateIdCounter.set(account, nextId);
|
|
28
|
+
return nextId;
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Creates a storage key for state/blob data.
|
|
33
|
+
*/ makeKey(account, stateId) {
|
|
34
|
+
return `${account}-${stateId.toString().padStart(10, '0')}`;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Saves a single transaction state for a specific account.
|
|
38
|
+
* Blobs are not stored here, use saveBlobs instead.
|
|
39
|
+
* @param account - The sender account address
|
|
40
|
+
* @param state - Transaction state to save
|
|
41
|
+
*/ async saveState(account, state) {
|
|
42
|
+
const key = this.makeKey(account, state.id);
|
|
43
|
+
const serializable = this.serializeState(state);
|
|
44
|
+
await this.states.set(key, jsonStringify(serializable));
|
|
45
|
+
this.log.debug(`Saved tx state ${state.id} for account ${account} with nonce ${state.nonce}`);
|
|
46
|
+
return state;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Saves blobs for a given state.
|
|
50
|
+
* @param account - The sender account address
|
|
51
|
+
* @param stateId - The state ID
|
|
52
|
+
* @param blobInputs - Blob inputs to save
|
|
53
|
+
*/ async saveBlobs(account, stateId, blobInputs) {
|
|
54
|
+
if (!blobInputs) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
const key = this.makeKey(account, stateId);
|
|
58
|
+
const blobData = this.serializeBlobInputs(blobInputs);
|
|
59
|
+
await this.blobs.set(key, jsonStringify(blobData));
|
|
60
|
+
this.log.debug(`Saved blobs for state ${stateId} of account ${account}`);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Loads all transaction states for a specific account.
|
|
64
|
+
* @param account - The sender account address
|
|
65
|
+
* @returns Array of transaction states with their IDs
|
|
66
|
+
*/ async loadStates(account) {
|
|
67
|
+
const states = [];
|
|
68
|
+
const prefix = `${account}-`;
|
|
69
|
+
for await (const [key, stateJson] of this.states.entriesAsync({
|
|
70
|
+
start: prefix,
|
|
71
|
+
end: `${prefix}Z`
|
|
72
|
+
})){
|
|
73
|
+
const [keyAccount, stateIdStr] = key.split('-');
|
|
74
|
+
if (keyAccount !== account) {
|
|
75
|
+
throw new Error(`Mismatched account in key: expected ${account} but got ${keyAccount}`);
|
|
76
|
+
}
|
|
77
|
+
const stateId = parseInt(stateIdStr, 10);
|
|
78
|
+
try {
|
|
79
|
+
const serialized = JSON.parse(stateJson);
|
|
80
|
+
// Load blobs if they exist
|
|
81
|
+
let blobInputs;
|
|
82
|
+
if (serialized.hasBlobInputs) {
|
|
83
|
+
const blobJson = await this.blobs.getAsync(key);
|
|
84
|
+
if (blobJson) {
|
|
85
|
+
blobInputs = this.deserializeBlobInputs(JSON.parse(blobJson), serialized.blobMetadata);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
const state = this.deserializeState(serialized, blobInputs);
|
|
89
|
+
states.push({
|
|
90
|
+
...state,
|
|
91
|
+
id: stateId
|
|
92
|
+
});
|
|
93
|
+
} catch (err) {
|
|
94
|
+
this.log.error(`Failed to deserialize state ${key}`, err);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
// Sort by ID
|
|
98
|
+
states.sort((a, b)=>a.id - b.id);
|
|
99
|
+
this.log.debug(`Loaded ${states.length} tx states for account ${account}`);
|
|
100
|
+
return states;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Loads a single state by ID.
|
|
104
|
+
* @param account - The sender account address
|
|
105
|
+
* @param stateId - The state ID
|
|
106
|
+
* @returns The transaction state or undefined if not found
|
|
107
|
+
*/ async loadState(account, stateId) {
|
|
108
|
+
const key = this.makeKey(account, stateId);
|
|
109
|
+
const stateJson = await this.states.getAsync(key);
|
|
110
|
+
if (!stateJson) {
|
|
111
|
+
return undefined;
|
|
112
|
+
}
|
|
113
|
+
try {
|
|
114
|
+
const serialized = JSON.parse(stateJson);
|
|
115
|
+
// Load blobs if they exist
|
|
116
|
+
let blobInputs;
|
|
117
|
+
if (serialized.hasBlobInputs) {
|
|
118
|
+
const blobJson = await this.blobs.getAsync(key);
|
|
119
|
+
if (blobJson) {
|
|
120
|
+
blobInputs = this.deserializeBlobInputs(JSON.parse(blobJson), serialized.blobMetadata);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
const state = this.deserializeState(serialized, blobInputs);
|
|
124
|
+
return {
|
|
125
|
+
...state,
|
|
126
|
+
id: stateId
|
|
127
|
+
};
|
|
128
|
+
} catch (err) {
|
|
129
|
+
this.log.error(`Failed to deserialize state ${key}`, err);
|
|
130
|
+
return undefined;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Deletes a specific state and its associated blobs.
|
|
135
|
+
* @param account - The sender account address
|
|
136
|
+
* @param stateId - The state ID to delete
|
|
137
|
+
*/ async deleteState(account, ...stateIds) {
|
|
138
|
+
if (stateIds.length === 0) {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
await this.store.transactionAsync(async ()=>{
|
|
142
|
+
for (const stateId of stateIds){
|
|
143
|
+
const key = this.makeKey(account, stateId);
|
|
144
|
+
await this.states.delete(key);
|
|
145
|
+
await this.blobs.delete(key);
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Clears all transaction states for a specific account.
|
|
151
|
+
* @param account - The sender account address
|
|
152
|
+
*/ async clearStates(account) {
|
|
153
|
+
await this.store.transactionAsync(async ()=>{
|
|
154
|
+
const states = await this.loadStates(account);
|
|
155
|
+
for (const state of states){
|
|
156
|
+
await this.deleteState(account, state.id);
|
|
157
|
+
}
|
|
158
|
+
await this.stateIdCounter.delete(account);
|
|
159
|
+
this.log.info(`Cleared all tx states for account ${account}`);
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Gets all accounts that have stored states.
|
|
164
|
+
* @returns Array of account addresses
|
|
165
|
+
*/ async getAllAccounts() {
|
|
166
|
+
const accounts = new Set();
|
|
167
|
+
for await (const [key] of this.states.entriesAsync()){
|
|
168
|
+
const account = key.substring(0, key.lastIndexOf('-'));
|
|
169
|
+
accounts.add(account);
|
|
170
|
+
}
|
|
171
|
+
return Array.from(accounts);
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Closes the store.
|
|
175
|
+
*/ async close() {
|
|
176
|
+
await this.store.close();
|
|
177
|
+
this.log.info('Closed L1 tx state store');
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Serializes an L1TxState for storage.
|
|
181
|
+
*/ serializeState(state) {
|
|
182
|
+
const txConfigOverrides = {
|
|
183
|
+
...state.txConfigOverrides,
|
|
184
|
+
gasLimit: state.txConfigOverrides.gasLimit?.toString(),
|
|
185
|
+
txTimeoutAt: state.txConfigOverrides.txTimeoutAt?.getTime()
|
|
186
|
+
};
|
|
187
|
+
return {
|
|
188
|
+
id: state.id,
|
|
189
|
+
txHashes: state.txHashes,
|
|
190
|
+
cancelTxHashes: state.cancelTxHashes,
|
|
191
|
+
gasLimit: state.gasLimit.toString(),
|
|
192
|
+
gasPrice: {
|
|
193
|
+
maxFeePerGas: state.gasPrice.maxFeePerGas.toString(),
|
|
194
|
+
maxPriorityFeePerGas: state.gasPrice.maxPriorityFeePerGas.toString(),
|
|
195
|
+
maxFeePerBlobGas: state.gasPrice.maxFeePerBlobGas?.toString()
|
|
196
|
+
},
|
|
197
|
+
txConfigOverrides,
|
|
198
|
+
request: {
|
|
199
|
+
...state.request,
|
|
200
|
+
value: state.request.value?.toString()
|
|
201
|
+
},
|
|
202
|
+
status: state.status,
|
|
203
|
+
nonce: state.nonce,
|
|
204
|
+
sentAt: state.sentAtL1Ts.getTime(),
|
|
205
|
+
lastSentAt: state.lastSentAtL1Ts.getTime(),
|
|
206
|
+
receipt: state.receipt,
|
|
207
|
+
hasBlobInputs: state.blobInputs !== undefined,
|
|
208
|
+
blobMetadata: state.blobInputs?.maxFeePerBlobGas ? {
|
|
209
|
+
maxFeePerBlobGas: state.blobInputs.maxFeePerBlobGas.toString()
|
|
210
|
+
} : undefined
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Deserializes a stored state back to L1TxState.
|
|
215
|
+
*/ deserializeState(stored, blobInputs) {
|
|
216
|
+
const txConfigOverrides = {
|
|
217
|
+
...stored.txConfigOverrides,
|
|
218
|
+
gasLimit: stored.txConfigOverrides.gasLimit !== undefined ? BigInt(stored.txConfigOverrides.gasLimit) : undefined,
|
|
219
|
+
txTimeoutAt: stored.txConfigOverrides.txTimeoutAt !== undefined ? new Date(stored.txConfigOverrides.txTimeoutAt) : undefined
|
|
220
|
+
};
|
|
221
|
+
const receipt = stored.receipt ? {
|
|
222
|
+
...stored.receipt,
|
|
223
|
+
blockNumber: BigInt(stored.receipt.blockNumber),
|
|
224
|
+
cumulativeGasUsed: BigInt(stored.receipt.cumulativeGasUsed),
|
|
225
|
+
effectiveGasPrice: BigInt(stored.receipt.effectiveGasPrice),
|
|
226
|
+
gasUsed: BigInt(stored.receipt.gasUsed)
|
|
227
|
+
} : undefined;
|
|
228
|
+
return {
|
|
229
|
+
id: stored.id,
|
|
230
|
+
txHashes: stored.txHashes,
|
|
231
|
+
cancelTxHashes: stored.cancelTxHashes,
|
|
232
|
+
gasLimit: BigInt(stored.gasLimit),
|
|
233
|
+
gasPrice: {
|
|
234
|
+
maxFeePerGas: BigInt(stored.gasPrice.maxFeePerGas),
|
|
235
|
+
maxPriorityFeePerGas: BigInt(stored.gasPrice.maxPriorityFeePerGas),
|
|
236
|
+
maxFeePerBlobGas: stored.gasPrice.maxFeePerBlobGas ? BigInt(stored.gasPrice.maxFeePerBlobGas) : undefined
|
|
237
|
+
},
|
|
238
|
+
txConfigOverrides,
|
|
239
|
+
request: {
|
|
240
|
+
to: stored.request.to,
|
|
241
|
+
data: stored.request.data,
|
|
242
|
+
value: stored.request.value ? BigInt(stored.request.value) : undefined
|
|
243
|
+
},
|
|
244
|
+
status: stored.status,
|
|
245
|
+
nonce: stored.nonce,
|
|
246
|
+
sentAtL1Ts: new Date(stored.sentAt),
|
|
247
|
+
lastSentAtL1Ts: new Date(stored.lastSentAt),
|
|
248
|
+
receipt,
|
|
249
|
+
blobInputs
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Serializes blob inputs for separate storage.
|
|
254
|
+
*/ serializeBlobInputs(blobInputs) {
|
|
255
|
+
return {
|
|
256
|
+
blobs: blobInputs.blobs.map((b)=>Buffer.from(b).toString('base64')),
|
|
257
|
+
kzg: jsonStringify(blobInputs.kzg)
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Deserializes blob inputs from storage, combining blob data with metadata.
|
|
262
|
+
*/ deserializeBlobInputs(stored, metadata) {
|
|
263
|
+
const blobInputs = {
|
|
264
|
+
blobs: stored.blobs.map((b)=>new Uint8Array(Buffer.from(b, 'base64'))),
|
|
265
|
+
kzg: JSON.parse(stored.kzg)
|
|
266
|
+
};
|
|
267
|
+
if (metadata?.maxFeePerBlobGas) {
|
|
268
|
+
blobInputs.maxFeePerBlobGas = BigInt(metadata.maxFeePerBlobGas);
|
|
269
|
+
}
|
|
270
|
+
return blobInputs;
|
|
271
|
+
}
|
|
272
|
+
}
|