@aztec/ethereum 0.0.1-commit.2ed92850 → 0.0.1-commit.3100065
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/client.d.ts +25 -3
- package/dest/client.d.ts.map +1 -1
- package/dest/client.js +60 -8
- package/dest/config.d.ts +17 -6
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +39 -11
- package/dest/contracts/chain_state_override.d.ts +78 -0
- package/dest/contracts/chain_state_override.d.ts.map +1 -0
- package/dest/contracts/chain_state_override.js +137 -0
- package/dest/contracts/fee_asset_handler.d.ts +1 -1
- package/dest/contracts/fee_asset_handler.d.ts.map +1 -1
- package/dest/contracts/fee_asset_handler.js +2 -0
- package/dest/contracts/fee_asset_price_oracle.d.ts +105 -0
- package/dest/contracts/fee_asset_price_oracle.d.ts.map +1 -0
- package/dest/contracts/fee_asset_price_oracle.js +656 -0
- package/dest/contracts/governance.d.ts +108 -33
- package/dest/contracts/governance.d.ts.map +1 -1
- package/dest/contracts/governance.js +198 -15
- package/dest/contracts/governance_proposer.d.ts +33 -1
- package/dest/contracts/governance_proposer.d.ts.map +1 -1
- package/dest/contracts/governance_proposer.js +57 -3
- package/dest/contracts/gse.d.ts +4 -2
- package/dest/contracts/gse.d.ts.map +1 -1
- package/dest/contracts/gse.js +2 -2
- package/dest/contracts/inbox.d.ts +3 -3
- package/dest/contracts/inbox.d.ts.map +1 -1
- package/dest/contracts/inbox.js +12 -7
- package/dest/contracts/index.d.ts +4 -3
- package/dest/contracts/index.d.ts.map +1 -1
- package/dest/contracts/index.js +3 -2
- package/dest/contracts/multicall.d.ts +127 -12
- package/dest/contracts/multicall.d.ts.map +1 -1
- package/dest/contracts/multicall.js +201 -93
- package/dest/contracts/outbox.d.ts +27 -4
- package/dest/contracts/outbox.d.ts.map +1 -1
- package/dest/contracts/outbox.js +34 -7
- package/dest/contracts/registry.d.ts +3 -1
- package/dest/contracts/registry.d.ts.map +1 -1
- package/dest/contracts/registry.js +30 -1
- package/dest/contracts/rollup.d.ts +5420 -31
- package/dest/contracts/rollup.d.ts.map +1 -1
- package/dest/contracts/rollup.js +406 -75
- package/dest/contracts/{tally_slashing_proposer.d.ts → slashing_proposer.d.ts} +3 -4
- package/dest/contracts/slashing_proposer.d.ts.map +1 -0
- package/dest/contracts/{tally_slashing_proposer.js → slashing_proposer.js} +18 -13
- package/dest/deploy_aztec_l1_contracts.d.ts +5 -9
- package/dest/deploy_aztec_l1_contracts.d.ts.map +1 -1
- package/dest/deploy_aztec_l1_contracts.js +41 -26
- package/dest/deploy_l1_contract.js +3 -3
- package/dest/generated/l1-contracts-defaults.d.ts +3 -3
- package/dest/generated/l1-contracts-defaults.js +3 -3
- package/dest/l1_artifacts.d.ts +15524 -15847
- package/dest/l1_artifacts.d.ts.map +1 -1
- package/dest/l1_artifacts.js +9 -24
- package/dest/l1_contract_addresses.d.ts +61 -65
- package/dest/l1_contract_addresses.d.ts.map +1 -1
- package/dest/l1_contract_addresses.js +101 -82
- package/dest/l1_reader.d.ts +5 -5
- package/dest/l1_reader.d.ts.map +1 -1
- package/dest/l1_reader.js +9 -7
- package/dest/l1_tx_utils/config.d.ts +7 -1
- package/dest/l1_tx_utils/config.d.ts.map +1 -1
- package/dest/l1_tx_utils/config.js +17 -4
- package/dest/l1_tx_utils/constants.d.ts +1 -1
- package/dest/l1_tx_utils/constants.js +2 -2
- package/dest/l1_tx_utils/factory.d.ts +18 -10
- package/dest/l1_tx_utils/factory.d.ts.map +1 -1
- package/dest/l1_tx_utils/factory.js +17 -7
- package/dest/l1_tx_utils/fee-strategies/p75_competitive.js +1 -1
- package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.js +1 -1
- package/dest/l1_tx_utils/forwarder_l1_tx_utils.d.ts +15 -15
- package/dest/l1_tx_utils/forwarder_l1_tx_utils.d.ts.map +1 -1
- package/dest/l1_tx_utils/forwarder_l1_tx_utils.js +9 -15
- package/dest/l1_tx_utils/index-blobs.d.ts +3 -3
- package/dest/l1_tx_utils/index-blobs.d.ts.map +1 -1
- package/dest/l1_tx_utils/index-blobs.js +2 -2
- package/dest/l1_tx_utils/index.d.ts +2 -1
- package/dest/l1_tx_utils/index.d.ts.map +1 -1
- package/dest/l1_tx_utils/index.js +1 -0
- package/dest/l1_tx_utils/l1_tx_utils.d.ts +26 -7
- package/dest/l1_tx_utils/l1_tx_utils.d.ts.map +1 -1
- package/dest/l1_tx_utils/l1_tx_utils.js +158 -81
- package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts +1 -1
- package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts.map +1 -1
- package/dest/l1_tx_utils/readonly_l1_tx_utils.js +13 -8
- package/dest/l1_tx_utils/tx_delayer.d.ts +58 -0
- package/dest/l1_tx_utils/tx_delayer.d.ts.map +1 -0
- package/dest/{test → l1_tx_utils}/tx_delayer.js +67 -37
- package/dest/publisher_manager.d.ts +34 -7
- package/dest/publisher_manager.d.ts.map +1 -1
- package/dest/publisher_manager.js +119 -8
- package/dest/queries.d.ts +13 -2
- package/dest/queries.d.ts.map +1 -1
- package/dest/queries.js +62 -3
- package/dest/test/blob_kzg_warmup.d.ts +19 -0
- package/dest/test/blob_kzg_warmup.d.ts.map +1 -0
- package/dest/test/blob_kzg_warmup.js +64 -0
- package/dest/test/chain_monitor.d.ts +55 -4
- package/dest/test/chain_monitor.d.ts.map +1 -1
- package/dest/test/chain_monitor.js +104 -3
- package/dest/test/eth_cheat_codes.d.ts +31 -6
- package/dest/test/eth_cheat_codes.d.ts.map +1 -1
- package/dest/test/eth_cheat_codes.js +67 -44
- package/dest/test/index.d.ts +2 -3
- package/dest/test/index.d.ts.map +1 -1
- package/dest/test/index.js +1 -2
- package/dest/test/rollup_cheat_codes.d.ts +62 -3
- package/dest/test/rollup_cheat_codes.d.ts.map +1 -1
- package/dest/test/rollup_cheat_codes.js +95 -7
- package/dest/test/start_anvil.d.ts +23 -3
- package/dest/test/start_anvil.d.ts.map +1 -1
- package/dest/test/start_anvil.js +143 -29
- package/dest/test/upgrade_utils.js +2 -2
- package/dest/utils.d.ts +10 -2
- package/dest/utils.d.ts.map +1 -1
- package/dest/utils.js +105 -24
- package/package.json +6 -8
- package/src/client.ts +66 -2
- package/src/config.ts +59 -15
- package/src/contracts/chain_state_override.ts +200 -0
- package/src/contracts/fee_asset_handler.ts +2 -0
- package/src/contracts/fee_asset_price_oracle.ts +285 -0
- package/src/contracts/governance.ts +271 -12
- package/src/contracts/governance_proposer.ts +58 -2
- package/src/contracts/gse.ts +7 -2
- package/src/contracts/inbox.ts +13 -5
- package/src/contracts/index.ts +3 -2
- package/src/contracts/multicall.ts +243 -102
- package/src/contracts/outbox.ts +42 -8
- package/src/contracts/registry.ts +31 -1
- package/src/contracts/rollup.ts +457 -78
- package/src/contracts/{tally_slashing_proposer.ts → slashing_proposer.ts} +16 -14
- package/src/deploy_aztec_l1_contracts.ts +63 -35
- package/src/deploy_l1_contract.ts +3 -3
- package/src/generated/l1-contracts-defaults.ts +3 -3
- package/src/l1_artifacts.ts +12 -35
- package/src/l1_contract_addresses.ts +120 -94
- package/src/l1_reader.ts +17 -10
- package/src/l1_tx_utils/config.ts +23 -3
- package/src/l1_tx_utils/constants.ts +2 -2
- package/src/l1_tx_utils/factory.ts +31 -31
- package/src/l1_tx_utils/fee-strategies/p75_competitive.ts +1 -1
- package/src/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.ts +1 -1
- package/src/l1_tx_utils/forwarder_l1_tx_utils.ts +43 -54
- package/src/l1_tx_utils/index-blobs.ts +2 -2
- package/src/l1_tx_utils/index.ts +1 -0
- package/src/l1_tx_utils/l1_tx_utils.ts +151 -66
- package/src/l1_tx_utils/readonly_l1_tx_utils.ts +13 -8
- package/src/{test → l1_tx_utils}/tx_delayer.ts +93 -56
- package/src/publisher_manager.ts +145 -12
- package/src/queries.ts +70 -4
- package/src/test/blob_kzg_warmup.ts +65 -0
- package/src/test/chain_monitor.ts +148 -3
- package/src/test/eth_cheat_codes.ts +63 -47
- package/src/test/index.ts +1 -2
- package/src/test/rollup_cheat_codes.ts +124 -6
- package/src/test/start_anvil.ts +177 -29
- package/src/test/upgrade_utils.ts +2 -2
- package/src/utils.ts +109 -29
- package/dest/contracts/empire_slashing_proposer.d.ts +0 -67
- package/dest/contracts/empire_slashing_proposer.d.ts.map +0 -1
- package/dest/contracts/empire_slashing_proposer.js +0 -209
- package/dest/contracts/tally_slashing_proposer.d.ts.map +0 -1
- package/dest/l1_tx_utils/l1_tx_utils_with_blobs.d.ts +0 -26
- package/dest/l1_tx_utils/l1_tx_utils_with_blobs.d.ts.map +0 -1
- package/dest/l1_tx_utils/l1_tx_utils_with_blobs.js +0 -26
- package/dest/test/delayed_tx_utils.d.ts +0 -13
- package/dest/test/delayed_tx_utils.d.ts.map +0 -1
- package/dest/test/delayed_tx_utils.js +0 -28
- package/dest/test/tx_delayer.d.ts +0 -36
- package/dest/test/tx_delayer.d.ts.map +0 -1
- package/src/contracts/empire_slashing_proposer.ts +0 -270
- package/src/l1_tx_utils/l1_tx_utils_with_blobs.ts +0 -77
- package/src/test/delayed_tx_utils.ts +0 -52
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import type { BlobKzgInstance } from '@aztec/blob-lib/types';
|
|
1
2
|
import { maxBigint } from '@aztec/foundation/bigint';
|
|
2
3
|
import { merge, pick } from '@aztec/foundation/collection';
|
|
3
4
|
import { InterruptError, TimeoutError } from '@aztec/foundation/error';
|
|
4
5
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
5
|
-
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
6
|
-
import {
|
|
6
|
+
import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
|
|
7
|
+
import { Semaphore } from '@aztec/foundation/queue';
|
|
8
|
+
import { makeBackoff, retry, retryUntil } from '@aztec/foundation/retry';
|
|
7
9
|
import { sleep } from '@aztec/foundation/sleep';
|
|
8
10
|
import { DateProvider } from '@aztec/foundation/timer';
|
|
9
11
|
import { RollupAbi } from '@aztec/l1-artifacts/RollupAbi';
|
|
@@ -13,23 +15,21 @@ import {
|
|
|
13
15
|
type Abi,
|
|
14
16
|
type BlockOverrides,
|
|
15
17
|
type Hex,
|
|
16
|
-
type NonceManager,
|
|
17
18
|
type PrepareTransactionRequestRequest,
|
|
18
19
|
type StateOverride,
|
|
19
20
|
type TransactionReceipt,
|
|
20
21
|
type TransactionSerializable,
|
|
21
|
-
createNonceManager,
|
|
22
22
|
formatGwei,
|
|
23
23
|
serializeTransaction,
|
|
24
24
|
} from 'viem';
|
|
25
|
-
import { jsonRpc } from 'viem/nonce';
|
|
26
25
|
|
|
27
26
|
import type { ViemClient } from '../types.js';
|
|
28
27
|
import { formatViemError } from '../utils.js';
|
|
29
28
|
import { type L1TxUtilsConfig, l1TxUtilsConfigMappings } from './config.js';
|
|
30
|
-
import {
|
|
29
|
+
import { MAX_L1_TX_LIMIT } from './constants.js';
|
|
31
30
|
import type { IL1TxMetrics, IL1TxStore } from './interfaces.js';
|
|
32
31
|
import { ReadOnlyL1TxUtils } from './readonly_l1_tx_utils.js';
|
|
32
|
+
import { Delayer, createDelayer, wrapClientWithDelayer } from './tx_delayer.js';
|
|
33
33
|
import {
|
|
34
34
|
DroppedTransactionError,
|
|
35
35
|
type L1BlobInputs,
|
|
@@ -44,9 +44,21 @@ import {
|
|
|
44
44
|
|
|
45
45
|
const MAX_L1_TX_STATES = 32;
|
|
46
46
|
|
|
47
|
+
// Backoff (in seconds) for retrying the read-only RPC calls that prepare a tx cancellation. A
|
|
48
|
+
// cancellation is fired in the background after a tx times out and is important (it frees the stuck
|
|
49
|
+
// nonce), so a transient RPC failure while reading the pending nonce or gas price must not abandon it.
|
|
50
|
+
const CANCELLATION_PREP_RETRY_BACKOFF_S = [1, 2, 4, 8];
|
|
51
|
+
|
|
47
52
|
export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
48
|
-
protected nonceManager: NonceManager;
|
|
49
53
|
protected txs: L1TxState[] = [];
|
|
54
|
+
/** Last nonce successfully sent to the chain. Used as a lower bound when a fallback RPC node returns a stale count. */
|
|
55
|
+
private lastSentNonce: number | undefined;
|
|
56
|
+
/** Mutex to prevent concurrent sendTransaction calls from racing on the same nonce. */
|
|
57
|
+
private readonly sendMutex = new Semaphore(1);
|
|
58
|
+
/** Tx delayer for testing. Only set when enableDelayer config is true. */
|
|
59
|
+
public delayer?: Delayer;
|
|
60
|
+
/** KZG instance for blob operations. */
|
|
61
|
+
protected kzg?: BlobKzgInstance;
|
|
50
62
|
|
|
51
63
|
constructor(
|
|
52
64
|
public override client: ViemClient,
|
|
@@ -58,9 +70,25 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
58
70
|
debugMaxGasLimit: boolean = false,
|
|
59
71
|
protected store?: IL1TxStore,
|
|
60
72
|
protected metrics?: IL1TxMetrics,
|
|
73
|
+
kzg?: BlobKzgInstance,
|
|
74
|
+
delayer?: Delayer,
|
|
61
75
|
) {
|
|
62
76
|
super(client, logger, dateProvider, config, debugMaxGasLimit);
|
|
63
|
-
this.
|
|
77
|
+
this.kzg = kzg;
|
|
78
|
+
|
|
79
|
+
// Set up delayer: use provided one or create new
|
|
80
|
+
if (config?.enableDelayer && config?.ethereumSlotDuration) {
|
|
81
|
+
this.delayer =
|
|
82
|
+
delayer ?? this.createDelayer({ ethereumSlotDuration: config.ethereumSlotDuration }, logger.getBindings());
|
|
83
|
+
this.client = wrapClientWithDelayer(this.client, this.delayer);
|
|
84
|
+
if (config.txDelayerMaxInclusionTimeIntoSlot !== undefined) {
|
|
85
|
+
this.delayer.setMaxInclusionTimeIntoSlot(config.txDelayerMaxInclusionTimeIntoSlot);
|
|
86
|
+
}
|
|
87
|
+
} else if (delayer) {
|
|
88
|
+
// Delayer provided but enableDelayer not set — just store it without wrapping
|
|
89
|
+
logger.warn('Delayer provided but enableDelayer config is not set; delayer will not be used');
|
|
90
|
+
this.delayer = delayer;
|
|
91
|
+
}
|
|
64
92
|
}
|
|
65
93
|
|
|
66
94
|
public get state() {
|
|
@@ -87,6 +115,11 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
87
115
|
this.metrics?.recordMinedTx(l1TxState, new Date(l1Timestamp));
|
|
88
116
|
} else if (newState === TxUtilsState.NOT_MINED) {
|
|
89
117
|
this.metrics?.recordDroppedTx(l1TxState);
|
|
118
|
+
// The tx was dropped: the chain nonce reverted to l1TxState.nonce, so our lower bound is
|
|
119
|
+
// no longer valid. Clear it so the next send fetches the real nonce from the chain.
|
|
120
|
+
if (this.lastSentNonce === l1TxState.nonce) {
|
|
121
|
+
this.lastSentNonce = undefined;
|
|
122
|
+
}
|
|
90
123
|
}
|
|
91
124
|
|
|
92
125
|
// Update state in the store
|
|
@@ -103,6 +136,14 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
103
136
|
);
|
|
104
137
|
}
|
|
105
138
|
|
|
139
|
+
/**
|
|
140
|
+
* Clears the cached `lastSentNonce` so the next `sendTransaction` call fetches the real
|
|
141
|
+
* nonce from the chain. Call this after an L1 reorg to prevent stale nonce references.
|
|
142
|
+
*/
|
|
143
|
+
public resetNonce(): void {
|
|
144
|
+
this.lastSentNonce = undefined;
|
|
145
|
+
}
|
|
146
|
+
|
|
106
147
|
public getSenderAddress() {
|
|
107
148
|
return this.address;
|
|
108
149
|
}
|
|
@@ -185,6 +226,19 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
185
226
|
return await this.signTransaction(txRequest as TransactionSerializable);
|
|
186
227
|
}
|
|
187
228
|
|
|
229
|
+
private async checkInterruptedOrTimedOut(gasConfig: Pick<L1TxConfig, 'txTimeoutAt'>): Promise<Date> {
|
|
230
|
+
if (this.interrupted) {
|
|
231
|
+
throw new InterruptError(`Transaction sending is interrupted`);
|
|
232
|
+
}
|
|
233
|
+
const now = new Date(await this.getL1Timestamp());
|
|
234
|
+
if (gasConfig.txTimeoutAt && now > gasConfig.txTimeoutAt) {
|
|
235
|
+
throw new TimeoutError(
|
|
236
|
+
`Transaction timed out before sending (now ${now.toISOString()} > timeoutAt ${gasConfig.txTimeoutAt.toISOString()})`,
|
|
237
|
+
);
|
|
238
|
+
}
|
|
239
|
+
return now;
|
|
240
|
+
}
|
|
241
|
+
|
|
188
242
|
/**
|
|
189
243
|
* Sends a transaction with gas estimation and pricing
|
|
190
244
|
* @param request - The transaction request (to, data, value)
|
|
@@ -197,17 +251,18 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
197
251
|
blobInputs?: L1BlobInputs,
|
|
198
252
|
stateChange: TxUtilsState = TxUtilsState.SENT,
|
|
199
253
|
): Promise<{ txHash: Hex; state: L1TxState }> {
|
|
200
|
-
if (this.interrupted) {
|
|
201
|
-
throw new InterruptError(`Transaction sending is interrupted`);
|
|
202
|
-
}
|
|
203
|
-
|
|
204
254
|
try {
|
|
205
255
|
const gasConfig = merge(this.config, gasConfigOverrides);
|
|
206
256
|
const account = this.getSenderAddress().toString();
|
|
207
257
|
|
|
258
|
+
// Fail fast before doing any work (gas estimation, balance check) if we've been interrupted
|
|
259
|
+
// or if the caller's deadline has already passed. The same check is repeated after gas
|
|
260
|
+
// estimation in case it took long enough to push us past the deadline.
|
|
261
|
+
await this.checkInterruptedOrTimedOut(gasConfig);
|
|
262
|
+
|
|
208
263
|
let gasLimit: bigint;
|
|
209
264
|
if (this.debugMaxGasLimit) {
|
|
210
|
-
gasLimit =
|
|
265
|
+
gasLimit = MAX_L1_TX_LIMIT;
|
|
211
266
|
} else if (gasConfig.gasLimit) {
|
|
212
267
|
gasLimit = gasConfig.gasLimit;
|
|
213
268
|
} else {
|
|
@@ -217,34 +272,34 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
217
272
|
|
|
218
273
|
const gasPrice = await this.getGasPrice(gasConfig, !!blobInputs);
|
|
219
274
|
|
|
220
|
-
|
|
221
|
-
throw new InterruptError(`Transaction sending is interrupted`);
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
const nonce = await this.nonceManager.consume({
|
|
225
|
-
client: this.client,
|
|
226
|
-
address: account,
|
|
227
|
-
chainId: this.client.chain.id,
|
|
228
|
-
});
|
|
275
|
+
const now = await this.checkInterruptedOrTimedOut(gasConfig);
|
|
229
276
|
|
|
230
|
-
|
|
231
|
-
|
|
277
|
+
let txHash: Hex;
|
|
278
|
+
let nonce: number;
|
|
279
|
+
let baseState: Pick<L1TxState, 'request' | 'gasLimit' | 'blobInputs' | 'gasPrice' | 'nonce'>;
|
|
232
280
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
281
|
+
await this.sendMutex.acquire();
|
|
282
|
+
try {
|
|
283
|
+
const chainNonce = await this.client.getTransactionCount({ address: account, blockTag: 'pending' });
|
|
284
|
+
// If a fallback RPC node returns a stale count (lower than what we last sent), use our
|
|
285
|
+
// local lower bound to avoid sending a duplicate of an already-pending transaction.
|
|
286
|
+
nonce =
|
|
287
|
+
this.lastSentNonce !== undefined && chainNonce <= this.lastSentNonce ? this.lastSentNonce + 1 : chainNonce;
|
|
288
|
+
|
|
289
|
+
baseState = { request, gasLimit, blobInputs, gasPrice, nonce };
|
|
290
|
+
const txData = this.makeTxData(baseState, { isCancelTx: false });
|
|
291
|
+
|
|
292
|
+
const signedRequest = await this.prepareSignedTransaction(txData);
|
|
293
|
+
txHash = await this.client.sendRawTransaction({ serializedTransaction: signedRequest });
|
|
294
|
+
this.lastSentNonce = nonce;
|
|
295
|
+
} finally {
|
|
296
|
+
this.sendMutex.release();
|
|
238
297
|
}
|
|
239
298
|
|
|
240
|
-
// Send the new tx
|
|
241
|
-
const signedRequest = await this.prepareSignedTransaction(txData);
|
|
242
|
-
const txHash = await this.client.sendRawTransaction({ serializedTransaction: signedRequest });
|
|
243
|
-
|
|
244
299
|
// Create the new state for monitoring
|
|
245
300
|
const l1TxState: L1TxState = {
|
|
246
301
|
...baseState,
|
|
247
|
-
id: (await this.store?.consumeNextStateId(account)) ?? Math.max(...this.txs.map(tx => tx.id),
|
|
302
|
+
id: (await this.store?.consumeNextStateId(account)) ?? Math.max(...this.txs.map(tx => tx.id), -1) + 1,
|
|
248
303
|
txHashes: [txHash],
|
|
249
304
|
cancelTxHashes: [],
|
|
250
305
|
status: TxUtilsState.IDLE,
|
|
@@ -283,7 +338,7 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
283
338
|
return { txHash, state: l1TxState };
|
|
284
339
|
} catch (err: any) {
|
|
285
340
|
const viemError = formatViemError(err, request.abi);
|
|
286
|
-
this.logger.error(`Failed to send L1 transaction`, viemError, {
|
|
341
|
+
this.logger.error(`Failed to send L1 transaction: ${viemError.message}`, viemError, {
|
|
287
342
|
request: pick(request, 'to', 'value'),
|
|
288
343
|
});
|
|
289
344
|
throw viemError;
|
|
@@ -381,10 +436,23 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
381
436
|
|
|
382
437
|
const initialTxHash = txHashes[0];
|
|
383
438
|
let currentTxHash = txHashes.at(-1)!;
|
|
384
|
-
let l1Timestamp
|
|
439
|
+
let l1Timestamp = 0;
|
|
385
440
|
|
|
386
441
|
while (true) {
|
|
387
|
-
|
|
442
|
+
try {
|
|
443
|
+
l1Timestamp = await this.getL1Timestamp();
|
|
444
|
+
} catch (err) {
|
|
445
|
+
// A transient RPC failure here must not abort monitoring with a rejection: callers that
|
|
446
|
+
// fire this loop in the background would surface it as an unhandled rejection (e.g. when a
|
|
447
|
+
// test tears down its L1 node while a monitor iteration is in flight). Exit quietly if we
|
|
448
|
+
// are shutting down, otherwise retry on the next interval.
|
|
449
|
+
if (this.interrupted) {
|
|
450
|
+
break;
|
|
451
|
+
}
|
|
452
|
+
this.logger.error(`Error fetching L1 timestamp while monitoring tx ${currentTxHash}`, err, { nonce, account });
|
|
453
|
+
await sleep(gasConfig.checkIntervalMs!);
|
|
454
|
+
continue;
|
|
455
|
+
}
|
|
388
456
|
|
|
389
457
|
try {
|
|
390
458
|
const timePassed = l1Timestamp - state.lastSentAtL1Ts.getTime();
|
|
@@ -423,7 +491,6 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
423
491
|
{ nonce, account, pendingNonce, timePassed },
|
|
424
492
|
);
|
|
425
493
|
await this.updateState(state, TxUtilsState.NOT_MINED);
|
|
426
|
-
this.nonceManager.reset({ address: account, chainId: this.client.chain.id });
|
|
427
494
|
throw new DroppedTransactionError(nonce, account);
|
|
428
495
|
}
|
|
429
496
|
|
|
@@ -515,12 +582,7 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
515
582
|
|
|
516
583
|
// Oh no, the transaction has timed out!
|
|
517
584
|
if (isCancelTx || !gasConfig.cancelTxOnTimeout) {
|
|
518
|
-
// If this was already a cancellation tx, or we are configured to not cancel txs, we just mark it as NOT_MINED
|
|
519
|
-
// and reset the nonce manager, so the next tx that comes along can reuse the nonce if/when this tx gets dropped.
|
|
520
|
-
// This is the nastiest scenario for us, since the new tx could acquire the next nonce, but then this tx is dropped,
|
|
521
|
-
// and the new tx would never get mined. Eventually, the new tx would also drop.
|
|
522
585
|
await this.updateState(state, TxUtilsState.NOT_MINED);
|
|
523
|
-
this.nonceManager.reset({ address: account, chainId: this.client.chain.id });
|
|
524
586
|
} else {
|
|
525
587
|
// Otherwise we fire the cancellation without awaiting to avoid blocking the caller,
|
|
526
588
|
// and monitor it in the background so we can speed it up as needed.
|
|
@@ -631,12 +693,12 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
631
693
|
from: request.from ?? this.getSenderAddress().toString(),
|
|
632
694
|
maxFeePerGas: gasPrice.maxFeePerGas,
|
|
633
695
|
maxPriorityFeePerGas: gasPrice.maxPriorityFeePerGas,
|
|
634
|
-
gas: request.gas ??
|
|
696
|
+
gas: request.gas ?? MAX_L1_TX_LIMIT,
|
|
635
697
|
};
|
|
636
698
|
|
|
637
699
|
if (!request.gas && !gasConfig.ignoreBlockGasLimit) {
|
|
638
|
-
//
|
|
639
|
-
blockOverrides.gasLimit =
|
|
700
|
+
// MAX_L1_TX_LIMIT is set as call.gas, ensure block gasLimit is sufficient
|
|
701
|
+
blockOverrides.gasLimit = MAX_L1_TX_LIMIT;
|
|
640
702
|
}
|
|
641
703
|
|
|
642
704
|
return this._simulate(call, blockOverrides, stateOverrides, gasConfig, abi);
|
|
@@ -659,34 +721,48 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
659
721
|
{ nonce, account },
|
|
660
722
|
);
|
|
661
723
|
await this.updateState(state, TxUtilsState.NOT_MINED);
|
|
662
|
-
this.nonceManager.reset({ address: account, chainId: this.client.chain.id });
|
|
663
724
|
return;
|
|
664
725
|
}
|
|
665
726
|
|
|
666
|
-
//
|
|
667
|
-
|
|
668
|
-
|
|
727
|
+
// Resolve the pending nonce and cancellation gas price up front. These are read-only RPC calls, so
|
|
728
|
+
// they are safe to retry; a transient RPC failure here must not permanently abandon the cancellation
|
|
729
|
+
// (which would leave the nonce stuck and the tx state stranded short of CANCELLED). We retry with a
|
|
730
|
+
// real backoff before giving up, unlike getGasPrice's tight internal retry which can be exhausted by
|
|
731
|
+
// a brief node hiccup. The retried block performs no state-changing send, so retrying cannot
|
|
732
|
+
// double-send the cancellation tx.
|
|
733
|
+
const { currentNonce, cancelGasPrice } = await retry(
|
|
734
|
+
async () => {
|
|
735
|
+
const currentNonce = await this.client.getTransactionCount({ address: account, blockTag: 'pending' });
|
|
736
|
+
if (currentNonce >= nonce) {
|
|
737
|
+
// Get gas price with higher priority fee for cancellation
|
|
738
|
+
const cancelGasPrice = await this.getGasPrice(
|
|
739
|
+
{
|
|
740
|
+
...this.config,
|
|
741
|
+
// Use high bump for cancellation to ensure it replaces the original tx
|
|
742
|
+
priorityFeeRetryBumpPercentage: 150, // 150% bump should be enough to replace any tx
|
|
743
|
+
},
|
|
744
|
+
isBlobTx,
|
|
745
|
+
state.txHashes.length,
|
|
746
|
+
previousGasPrice,
|
|
747
|
+
);
|
|
748
|
+
return { currentNonce, cancelGasPrice };
|
|
749
|
+
}
|
|
750
|
+
return { currentNonce, cancelGasPrice: undefined };
|
|
751
|
+
},
|
|
752
|
+
`Preparing cancellation for L1 tx from account ${account} with nonce ${nonce}`,
|
|
753
|
+
makeBackoff(CANCELLATION_PREP_RETRY_BACKOFF_S),
|
|
754
|
+
this.logger,
|
|
755
|
+
);
|
|
756
|
+
|
|
757
|
+
if (cancelGasPrice === undefined) {
|
|
669
758
|
this.logger.verbose(
|
|
670
759
|
`Not sending cancellation for L1 tx from account ${account} with nonce ${nonce} as it is dropped`,
|
|
671
760
|
{ nonce, account, currentNonce },
|
|
672
761
|
);
|
|
673
762
|
await this.updateState(state, TxUtilsState.NOT_MINED);
|
|
674
|
-
this.nonceManager.reset({ address: account, chainId: this.client.chain.id });
|
|
675
763
|
return;
|
|
676
764
|
}
|
|
677
765
|
|
|
678
|
-
// Get gas price with higher priority fee for cancellation
|
|
679
|
-
const cancelGasPrice = await this.getGasPrice(
|
|
680
|
-
{
|
|
681
|
-
...this.config,
|
|
682
|
-
// Use high bump for cancellation to ensure it replaces the original tx
|
|
683
|
-
priorityFeeRetryBumpPercentage: 150, // 150% bump should be enough to replace any tx
|
|
684
|
-
},
|
|
685
|
-
isBlobTx,
|
|
686
|
-
state.txHashes.length,
|
|
687
|
-
previousGasPrice,
|
|
688
|
-
);
|
|
689
|
-
|
|
690
766
|
const { maxFeePerGas, maxPriorityFeePerGas, maxFeePerBlobGas } = cancelGasPrice;
|
|
691
767
|
this.logger.verbose(
|
|
692
768
|
`Attempting to cancel L1 ${isBlobTx ? 'blob' : 'vanilla'} transaction from account ${account} with nonce ${nonce} after time out`,
|
|
@@ -731,8 +807,17 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
731
807
|
return Number(timestamp) * 1000;
|
|
732
808
|
}
|
|
733
809
|
|
|
734
|
-
/** Makes empty blob inputs for the cancellation tx.
|
|
735
|
-
protected makeEmptyBlobInputs(
|
|
736
|
-
|
|
810
|
+
/** Makes empty blob inputs for the cancellation tx. */
|
|
811
|
+
protected makeEmptyBlobInputs(maxFeePerBlobGas: bigint): Required<L1BlobInputs> {
|
|
812
|
+
if (!this.kzg) {
|
|
813
|
+
throw new Error('Cannot make empty blob inputs for cancellation without kzg');
|
|
814
|
+
}
|
|
815
|
+
const blobData = new Uint8Array(131072).fill(0);
|
|
816
|
+
return { blobs: [blobData], kzg: this.kzg, maxFeePerBlobGas };
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
/** Creates a new delayer instance. */
|
|
820
|
+
protected createDelayer(opts: { ethereumSlotDuration: bigint | number }, bindings: LoggerBindings): Delayer {
|
|
821
|
+
return createDelayer(this.dateProvider, opts, bindings);
|
|
737
822
|
}
|
|
738
823
|
}
|
|
@@ -3,6 +3,7 @@ import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
|
3
3
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
4
4
|
import { makeBackoff, retry } from '@aztec/foundation/retry';
|
|
5
5
|
import { DateProvider } from '@aztec/foundation/timer';
|
|
6
|
+
import { getErrorCause } from '@aztec/foundation/types';
|
|
6
7
|
import { RollupAbi } from '@aztec/l1-artifacts/RollupAbi';
|
|
7
8
|
|
|
8
9
|
import pickBy from 'lodash.pickby';
|
|
@@ -27,7 +28,7 @@ import type { ViemClient } from '../types.js';
|
|
|
27
28
|
import { type L1TxUtilsConfig, defaultL1TxUtilsConfig, l1TxUtilsConfigMappings } from './config.js';
|
|
28
29
|
import {
|
|
29
30
|
BLOCK_TIME_MS,
|
|
30
|
-
|
|
31
|
+
MAX_L1_TX_LIMIT,
|
|
31
32
|
MIN_BLOB_REPLACEMENT_BUMP_PERCENTAGE,
|
|
32
33
|
MIN_REPLACEMENT_BUMP_PERCENTAGE,
|
|
33
34
|
WEI_CONST,
|
|
@@ -130,9 +131,10 @@ export class ReadOnlyL1TxUtils {
|
|
|
130
131
|
const numBlocks = Math.ceil(gasConfig.stallTimeMs! / BLOCK_TIME_MS);
|
|
131
132
|
for (let i = 0; i < numBlocks; i++) {
|
|
132
133
|
// each block can go up 12.5% from previous baseFee
|
|
133
|
-
|
|
134
|
+
// ceil, (a+b-1)/b, to avoid truncation at small values (e.g. 1 wei blob base fee)
|
|
135
|
+
maxFeePerGas = (maxFeePerGas * (1_000n + 125n) + 999n) / 1_000n;
|
|
134
136
|
// same for blob gas fee
|
|
135
|
-
maxFeePerBlobGas = (maxFeePerBlobGas * (1_000n + 125n)) / 1_000n;
|
|
137
|
+
maxFeePerBlobGas = (maxFeePerBlobGas * (1_000n + 125n) + 999n) / 1_000n;
|
|
136
138
|
}
|
|
137
139
|
|
|
138
140
|
if (attempt > 0) {
|
|
@@ -242,14 +244,17 @@ export class ReadOnlyL1TxUtils {
|
|
|
242
244
|
const gasConfig = { ...this.config, ..._gasConfig };
|
|
243
245
|
let initialEstimate = 0n;
|
|
244
246
|
if (_blobInputs) {
|
|
245
|
-
// @note requests with blobs also require maxFeePerBlobGas to be set
|
|
247
|
+
// @note requests with blobs also require maxFeePerBlobGas to be set.
|
|
248
|
+
// Use 2x buffer for maxFeePerBlobGas to avoid stale fees and to pass EIP-4844 validation (even if it is a gas estimation call).
|
|
249
|
+
// 1. maxFeePerBlobGas >= blobBaseFee
|
|
250
|
+
// 2. account balance >= gas * maxFeePerGas + maxFeePerBlobGas * blobCount + value
|
|
246
251
|
const gasPrice = await this.getGasPrice(gasConfig, true, 0);
|
|
247
252
|
initialEstimate = await this.client.estimateGas({
|
|
248
253
|
account,
|
|
249
254
|
...request,
|
|
250
255
|
..._blobInputs,
|
|
251
|
-
maxFeePerBlobGas: gasPrice.maxFeePerBlobGas
|
|
252
|
-
gas:
|
|
256
|
+
maxFeePerBlobGas: gasPrice.maxFeePerBlobGas! * 2n,
|
|
257
|
+
gas: MAX_L1_TX_LIMIT,
|
|
253
258
|
blockTag: 'latest',
|
|
254
259
|
});
|
|
255
260
|
|
|
@@ -258,7 +263,7 @@ export class ReadOnlyL1TxUtils {
|
|
|
258
263
|
initialEstimate = await this.client.estimateGas({
|
|
259
264
|
account,
|
|
260
265
|
...request,
|
|
261
|
-
gas:
|
|
266
|
+
gas: MAX_L1_TX_LIMIT,
|
|
262
267
|
blockTag: 'latest',
|
|
263
268
|
});
|
|
264
269
|
this.logger?.trace(`Estimated gas for non-blob tx: ${initialEstimate}`);
|
|
@@ -391,7 +396,7 @@ export class ReadOnlyL1TxUtils {
|
|
|
391
396
|
this.logger?.debug(`L1 transaction simulation succeeded`, { ...result[0].calls[0] });
|
|
392
397
|
return { gasUsed: result[0].gasUsed, result: result[0].calls[0].data as `0x${string}` };
|
|
393
398
|
} catch (err) {
|
|
394
|
-
if (err
|
|
399
|
+
if (getErrorCause(err, MethodNotFoundRpcError) || getErrorCause(err, MethodNotSupportedRpcError)) {
|
|
395
400
|
if (gasConfig.fallbackGasEstimate) {
|
|
396
401
|
this.logger?.warn(
|
|
397
402
|
`Node does not support eth_simulateV1 API. Using fallback gas estimate: ${gasConfig.fallbackGasEstimate}`,
|