@aztec/node-lib 4.0.0-nightly.20250907 → 4.0.0-nightly.20260108

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.
Files changed (37) hide show
  1. package/dest/actions/build-snapshot-metadata.d.ts +1 -1
  2. package/dest/actions/create-backups.d.ts +1 -1
  3. package/dest/actions/index.d.ts +1 -1
  4. package/dest/actions/snapshot-sync.d.ts +4 -3
  5. package/dest/actions/snapshot-sync.d.ts.map +1 -1
  6. package/dest/actions/snapshot-sync.js +91 -56
  7. package/dest/actions/upload-snapshot.d.ts +1 -1
  8. package/dest/config/index.d.ts +7 -3
  9. package/dest/config/index.d.ts.map +1 -1
  10. package/dest/config/index.js +18 -3
  11. package/dest/factories/index.d.ts +2 -0
  12. package/dest/factories/index.d.ts.map +1 -0
  13. package/dest/factories/index.js +1 -0
  14. package/dest/factories/l1_tx_utils.d.ts +79 -0
  15. package/dest/factories/l1_tx_utils.d.ts.map +1 -0
  16. package/dest/factories/l1_tx_utils.js +90 -0
  17. package/dest/metrics/index.d.ts +2 -0
  18. package/dest/metrics/index.d.ts.map +1 -0
  19. package/dest/metrics/index.js +1 -0
  20. package/dest/metrics/l1_tx_metrics.d.ts +29 -0
  21. package/dest/metrics/l1_tx_metrics.d.ts.map +1 -0
  22. package/dest/metrics/l1_tx_metrics.js +138 -0
  23. package/dest/stores/index.d.ts +2 -0
  24. package/dest/stores/index.d.ts.map +1 -0
  25. package/dest/stores/index.js +1 -0
  26. package/dest/stores/l1_tx_store.d.ts +89 -0
  27. package/dest/stores/l1_tx_store.d.ts.map +1 -0
  28. package/dest/stores/l1_tx_store.js +272 -0
  29. package/package.json +30 -23
  30. package/src/actions/snapshot-sync.ts +103 -64
  31. package/src/config/index.ts +27 -5
  32. package/src/factories/index.ts +1 -0
  33. package/src/factories/l1_tx_utils.ts +212 -0
  34. package/src/metrics/index.ts +1 -0
  35. package/src/metrics/l1_tx_metrics.ts +169 -0
  36. package/src/stores/index.ts +1 -0
  37. package/src/stores/l1_tx_store.ts +396 -0
@@ -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,2 @@
1
+ export * from './l1_tx_store.js';
2
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9zdG9yZXMvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsY0FBYyxrQkFBa0IsQ0FBQyJ9
@@ -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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibDFfdHhfc3RvcmUuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9zdG9yZXMvbDFfdHhfc3RvcmUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxLQUFLLEVBQUUsVUFBVSxFQUFFLFlBQVksRUFBYyxTQUFTLEVBQUUsTUFBTSw2QkFBNkIsQ0FBQztBQUVuRyxPQUFPLEtBQUssRUFBRSxNQUFNLEVBQUUsTUFBTSx1QkFBdUIsQ0FBQztBQUVwRCxPQUFPLEtBQUssRUFBRSxpQkFBaUIsRUFBaUIsTUFBTSxpQkFBaUIsQ0FBQztBQTJFeEU7Ozs7R0FJRztBQUNILHFCQUFhLFNBQVUsWUFBVyxVQU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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
+ }
package/package.json CHANGED
@@ -1,17 +1,20 @@
1
1
  {
2
2
  "name": "@aztec/node-lib",
3
- "version": "4.0.0-nightly.20250907",
3
+ "version": "4.0.0-nightly.20260108",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  "./actions": "./dest/actions/index.js",
7
- "./config": "./dest/config/index.js"
7
+ "./config": "./dest/config/index.js",
8
+ "./factories": "./dest/factories/index.js",
9
+ "./metrics": "./dest/metrics/index.js",
10
+ "./stores": "./dest/stores/index.js"
8
11
  },
9
12
  "inherits": [
10
13
  "../package.common.json"
11
14
  ],
12
15
  "scripts": {
13
- "build": "yarn clean && tsc -b",
14
- "build:dev": "tsc -b --watch",
16
+ "build": "yarn clean && ../scripts/tsc.sh",
17
+ "build:dev": "../scripts/tsc.sh --watch",
15
18
  "clean": "rm -rf ./dest .tsbuildinfo",
16
19
  "bb": "node --no-warnings ./dest/bb/index.js",
17
20
  "test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}"
@@ -54,34 +57,38 @@
54
57
  ]
55
58
  },
56
59
  "dependencies": {
57
- "@aztec/archiver": "4.0.0-nightly.20250907",
58
- "@aztec/bb-prover": "4.0.0-nightly.20250907",
59
- "@aztec/blob-sink": "4.0.0-nightly.20250907",
60
- "@aztec/constants": "4.0.0-nightly.20250907",
61
- "@aztec/epoch-cache": "4.0.0-nightly.20250907",
62
- "@aztec/ethereum": "4.0.0-nightly.20250907",
63
- "@aztec/foundation": "4.0.0-nightly.20250907",
64
- "@aztec/kv-store": "4.0.0-nightly.20250907",
65
- "@aztec/merkle-tree": "4.0.0-nightly.20250907",
66
- "@aztec/p2p": "4.0.0-nightly.20250907",
67
- "@aztec/protocol-contracts": "4.0.0-nightly.20250907",
68
- "@aztec/prover-client": "4.0.0-nightly.20250907",
69
- "@aztec/sequencer-client": "4.0.0-nightly.20250907",
70
- "@aztec/simulator": "4.0.0-nightly.20250907",
71
- "@aztec/stdlib": "4.0.0-nightly.20250907",
72
- "@aztec/telemetry-client": "4.0.0-nightly.20250907",
73
- "@aztec/validator-client": "4.0.0-nightly.20250907",
74
- "@aztec/world-state": "4.0.0-nightly.20250907",
60
+ "@aztec/archiver": "4.0.0-nightly.20260108",
61
+ "@aztec/bb-prover": "4.0.0-nightly.20260108",
62
+ "@aztec/blob-client": "4.0.0-nightly.20260108",
63
+ "@aztec/constants": "4.0.0-nightly.20260108",
64
+ "@aztec/epoch-cache": "4.0.0-nightly.20260108",
65
+ "@aztec/ethereum": "4.0.0-nightly.20260108",
66
+ "@aztec/foundation": "4.0.0-nightly.20260108",
67
+ "@aztec/kv-store": "4.0.0-nightly.20260108",
68
+ "@aztec/merkle-tree": "4.0.0-nightly.20260108",
69
+ "@aztec/p2p": "4.0.0-nightly.20260108",
70
+ "@aztec/protocol-contracts": "4.0.0-nightly.20260108",
71
+ "@aztec/prover-client": "4.0.0-nightly.20260108",
72
+ "@aztec/sequencer-client": "4.0.0-nightly.20260108",
73
+ "@aztec/simulator": "4.0.0-nightly.20260108",
74
+ "@aztec/stdlib": "4.0.0-nightly.20260108",
75
+ "@aztec/telemetry-client": "4.0.0-nightly.20260108",
76
+ "@aztec/validator-client": "4.0.0-nightly.20260108",
77
+ "@aztec/world-state": "4.0.0-nightly.20260108",
75
78
  "tslib": "^2.4.0"
76
79
  },
77
80
  "devDependencies": {
81
+ "@aztec/blob-lib": "4.0.0-nightly.20260108",
82
+ "@aztec/node-keystore": "4.0.0-nightly.20260108",
78
83
  "@jest/globals": "^30.0.0",
79
84
  "@types/jest": "^30.0.0",
80
85
  "@types/node": "^22.15.17",
86
+ "@typescript/native-preview": "7.0.0-dev.20251126.1",
81
87
  "jest": "^30.0.0",
82
88
  "jest-mock-extended": "^4.0.0",
83
89
  "ts-node": "^10.9.1",
84
- "typescript": "^5.3.3"
90
+ "typescript": "^5.3.3",
91
+ "viem": "npm:@aztec/viem@2.38.2"
85
92
  },
86
93
  "files": [
87
94
  "dest",