@aztec/ethereum 0.0.1-commit.03f7ef2 → 0.0.1-commit.04d373f
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 +16 -2
- package/dest/client.d.ts.map +1 -1
- package/dest/client.js +27 -7
- package/dest/config.d.ts +24 -32
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +63 -62
- 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 +6 -5
- package/dest/contracts/fee_asset_handler.d.ts.map +1 -1
- package/dest/contracts/fee_asset_handler.js +11 -9
- 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 +110 -33
- package/dest/contracts/governance.d.ts.map +1 -1
- package/dest/contracts/governance.js +207 -16
- 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 +438 -10
- package/dest/contracts/inbox.d.ts +22 -1
- package/dest/contracts/inbox.d.ts.map +1 -1
- package/dest/contracts/inbox.js +42 -2
- package/dest/contracts/index.d.ts +6 -3
- package/dest/contracts/index.d.ts.map +1 -1
- package/dest/contracts/index.js +5 -2
- package/dest/contracts/log.d.ts +13 -0
- package/dest/contracts/log.d.ts.map +1 -0
- package/dest/contracts/log.js +1 -0
- 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 +58 -0
- package/dest/contracts/outbox.d.ts.map +1 -0
- package/dest/contracts/outbox.js +109 -0
- 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 +5409 -115
- package/dest/contracts/rollup.d.ts.map +1 -1
- package/dest/contracts/rollup.js +1027 -189
- 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 +20 -9
- package/dest/deploy_aztec_l1_contracts.d.ts.map +1 -1
- package/dest/deploy_aztec_l1_contracts.js +113 -37
- package/dest/deploy_l1_contract.js +3 -3
- package/dest/generated/l1-contracts-defaults.d.ts +30 -0
- package/dest/generated/l1-contracts-defaults.d.ts.map +1 -0
- package/dest/generated/l1-contracts-defaults.js +30 -0
- package/dest/l1_artifacts.d.ts +18360 -16454
- 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 +14 -1
- 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/index.d.ts +3 -2
- package/dest/l1_tx_utils/fee-strategies/index.d.ts.map +1 -1
- package/dest/l1_tx_utils/fee-strategies/index.js +2 -1
- package/dest/l1_tx_utils/fee-strategies/p75_competitive.d.ts +2 -12
- package/dest/l1_tx_utils/fee-strategies/p75_competitive.d.ts.map +1 -1
- package/dest/l1_tx_utils/fee-strategies/p75_competitive.js +36 -18
- package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.d.ts +2 -11
- package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.d.ts.map +1 -1
- package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.js +37 -19
- package/dest/l1_tx_utils/fee-strategies/types.d.ts +14 -27
- package/dest/l1_tx_utils/fee-strategies/types.d.ts.map +1 -1
- package/dest/l1_tx_utils/fee-strategies/types.js +0 -21
- 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_fee_analyzer.d.ts +2 -2
- package/dest/l1_tx_utils/l1_fee_analyzer.d.ts.map +1 -1
- package/dest/l1_tx_utils/l1_fee_analyzer.js +3 -3
- 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 +101 -66
- package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts +1 -5
- package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts.map +1 -1
- package/dest/l1_tx_utils/readonly_l1_tx_utils.js +25 -58
- 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 +21 -6
- package/dest/publisher_manager.d.ts.map +1 -1
- package/dest/publisher_manager.js +81 -7
- package/dest/queries.d.ts +14 -3
- package/dest/queries.d.ts.map +1 -1
- package/dest/queries.js +74 -7
- package/dest/test/chain_monitor.d.ts +23 -3
- package/dest/test/chain_monitor.d.ts.map +1 -1
- package/dest/test/chain_monitor.js +39 -4
- package/dest/test/eth_cheat_codes.d.ts +24 -4
- package/dest/test/eth_cheat_codes.d.ts.map +1 -1
- package/dest/test/eth_cheat_codes.js +17 -4
- package/dest/test/index.d.ts +1 -3
- package/dest/test/index.d.ts.map +1 -1
- package/dest/test/index.js +0 -2
- package/dest/test/rollup_cheat_codes.d.ts +34 -3
- package/dest/test/rollup_cheat_codes.d.ts.map +1 -1
- package/dest/test/rollup_cheat_codes.js +75 -6
- 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 +9 -1
- package/dest/utils.d.ts.map +1 -1
- package/dest/utils.js +81 -12
- package/package.json +9 -10
- package/src/client.ts +28 -2
- package/src/config.ts +81 -63
- package/src/contracts/README.md +157 -0
- package/src/contracts/chain_state_override.ts +200 -0
- package/src/contracts/fee_asset_handler.ts +10 -7
- package/src/contracts/fee_asset_price_oracle.ts +285 -0
- package/src/contracts/governance.ts +279 -13
- package/src/contracts/governance_proposer.ts +58 -2
- package/src/contracts/inbox.ts +62 -2
- package/src/contracts/index.ts +5 -2
- package/src/contracts/log.ts +13 -0
- package/src/contracts/multicall.ts +243 -102
- package/src/contracts/outbox.ts +128 -0
- package/src/contracts/registry.ts +31 -1
- package/src/contracts/rollup.ts +728 -148
- package/src/contracts/{tally_slashing_proposer.ts → slashing_proposer.ts} +16 -14
- package/src/deploy_aztec_l1_contracts.ts +137 -47
- package/src/deploy_l1_contract.ts +3 -3
- package/src/generated/l1-contracts-defaults.ts +32 -0
- 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 +20 -0
- 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/index.ts +1 -1
- package/src/l1_tx_utils/fee-strategies/p75_competitive.ts +46 -42
- package/src/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.ts +49 -45
- package/src/l1_tx_utils/fee-strategies/types.ts +14 -46
- 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_fee_analyzer.ts +2 -3
- package/src/l1_tx_utils/l1_tx_utils.ts +99 -48
- package/src/l1_tx_utils/readonly_l1_tx_utils.ts +31 -66
- package/src/{test → l1_tx_utils}/tx_delayer.ts +93 -56
- package/src/publisher_manager.ts +107 -10
- package/src/queries.ts +81 -7
- package/src/test/chain_monitor.ts +66 -4
- package/src/test/eth_cheat_codes.ts +16 -4
- package/src/test/index.ts +0 -2
- package/src/test/rollup_cheat_codes.ts +82 -6
- package/src/test/start_anvil.ts +177 -29
- package/src/test/upgrade_utils.ts +2 -2
- package/src/utils.ts +88 -14
- 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,8 +1,10 @@
|
|
|
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 { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
|
|
7
|
+
import { Semaphore } from '@aztec/foundation/queue';
|
|
6
8
|
import { retryUntil } from '@aztec/foundation/retry';
|
|
7
9
|
import { sleep } from '@aztec/foundation/sleep';
|
|
8
10
|
import { DateProvider } from '@aztec/foundation/timer';
|
|
@@ -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,
|
|
@@ -45,8 +45,15 @@ import {
|
|
|
45
45
|
const MAX_L1_TX_STATES = 32;
|
|
46
46
|
|
|
47
47
|
export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
48
|
-
protected nonceManager: NonceManager;
|
|
49
48
|
protected txs: L1TxState[] = [];
|
|
49
|
+
/** Last nonce successfully sent to the chain. Used as a lower bound when a fallback RPC node returns a stale count. */
|
|
50
|
+
private lastSentNonce: number | undefined;
|
|
51
|
+
/** Mutex to prevent concurrent sendTransaction calls from racing on the same nonce. */
|
|
52
|
+
private readonly sendMutex = new Semaphore(1);
|
|
53
|
+
/** Tx delayer for testing. Only set when enableDelayer config is true. */
|
|
54
|
+
public delayer?: Delayer;
|
|
55
|
+
/** KZG instance for blob operations. */
|
|
56
|
+
protected kzg?: BlobKzgInstance;
|
|
50
57
|
|
|
51
58
|
constructor(
|
|
52
59
|
public override client: ViemClient,
|
|
@@ -58,9 +65,25 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
58
65
|
debugMaxGasLimit: boolean = false,
|
|
59
66
|
protected store?: IL1TxStore,
|
|
60
67
|
protected metrics?: IL1TxMetrics,
|
|
68
|
+
kzg?: BlobKzgInstance,
|
|
69
|
+
delayer?: Delayer,
|
|
61
70
|
) {
|
|
62
71
|
super(client, logger, dateProvider, config, debugMaxGasLimit);
|
|
63
|
-
this.
|
|
72
|
+
this.kzg = kzg;
|
|
73
|
+
|
|
74
|
+
// Set up delayer: use provided one or create new
|
|
75
|
+
if (config?.enableDelayer && config?.ethereumSlotDuration) {
|
|
76
|
+
this.delayer =
|
|
77
|
+
delayer ?? this.createDelayer({ ethereumSlotDuration: config.ethereumSlotDuration }, logger.getBindings());
|
|
78
|
+
this.client = wrapClientWithDelayer(this.client, this.delayer);
|
|
79
|
+
if (config.txDelayerMaxInclusionTimeIntoSlot !== undefined) {
|
|
80
|
+
this.delayer.setMaxInclusionTimeIntoSlot(config.txDelayerMaxInclusionTimeIntoSlot);
|
|
81
|
+
}
|
|
82
|
+
} else if (delayer) {
|
|
83
|
+
// Delayer provided but enableDelayer not set — just store it without wrapping
|
|
84
|
+
logger.warn('Delayer provided but enableDelayer config is not set; delayer will not be used');
|
|
85
|
+
this.delayer = delayer;
|
|
86
|
+
}
|
|
64
87
|
}
|
|
65
88
|
|
|
66
89
|
public get state() {
|
|
@@ -87,6 +110,11 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
87
110
|
this.metrics?.recordMinedTx(l1TxState, new Date(l1Timestamp));
|
|
88
111
|
} else if (newState === TxUtilsState.NOT_MINED) {
|
|
89
112
|
this.metrics?.recordDroppedTx(l1TxState);
|
|
113
|
+
// The tx was dropped: the chain nonce reverted to l1TxState.nonce, so our lower bound is
|
|
114
|
+
// no longer valid. Clear it so the next send fetches the real nonce from the chain.
|
|
115
|
+
if (this.lastSentNonce === l1TxState.nonce) {
|
|
116
|
+
this.lastSentNonce = undefined;
|
|
117
|
+
}
|
|
90
118
|
}
|
|
91
119
|
|
|
92
120
|
// Update state in the store
|
|
@@ -103,6 +131,14 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
103
131
|
);
|
|
104
132
|
}
|
|
105
133
|
|
|
134
|
+
/**
|
|
135
|
+
* Clears the cached `lastSentNonce` so the next `sendTransaction` call fetches the real
|
|
136
|
+
* nonce from the chain. Call this after an L1 reorg to prevent stale nonce references.
|
|
137
|
+
*/
|
|
138
|
+
public resetNonce(): void {
|
|
139
|
+
this.lastSentNonce = undefined;
|
|
140
|
+
}
|
|
141
|
+
|
|
106
142
|
public getSenderAddress() {
|
|
107
143
|
return this.address;
|
|
108
144
|
}
|
|
@@ -185,6 +221,19 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
185
221
|
return await this.signTransaction(txRequest as TransactionSerializable);
|
|
186
222
|
}
|
|
187
223
|
|
|
224
|
+
private async checkInterruptedOrTimedOut(gasConfig: Pick<L1TxConfig, 'txTimeoutAt'>): Promise<Date> {
|
|
225
|
+
if (this.interrupted) {
|
|
226
|
+
throw new InterruptError(`Transaction sending is interrupted`);
|
|
227
|
+
}
|
|
228
|
+
const now = new Date(await this.getL1Timestamp());
|
|
229
|
+
if (gasConfig.txTimeoutAt && now > gasConfig.txTimeoutAt) {
|
|
230
|
+
throw new TimeoutError(
|
|
231
|
+
`Transaction timed out before sending (now ${now.toISOString()} > timeoutAt ${gasConfig.txTimeoutAt.toISOString()})`,
|
|
232
|
+
);
|
|
233
|
+
}
|
|
234
|
+
return now;
|
|
235
|
+
}
|
|
236
|
+
|
|
188
237
|
/**
|
|
189
238
|
* Sends a transaction with gas estimation and pricing
|
|
190
239
|
* @param request - The transaction request (to, data, value)
|
|
@@ -197,17 +246,18 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
197
246
|
blobInputs?: L1BlobInputs,
|
|
198
247
|
stateChange: TxUtilsState = TxUtilsState.SENT,
|
|
199
248
|
): Promise<{ txHash: Hex; state: L1TxState }> {
|
|
200
|
-
if (this.interrupted) {
|
|
201
|
-
throw new InterruptError(`Transaction sending is interrupted`);
|
|
202
|
-
}
|
|
203
|
-
|
|
204
249
|
try {
|
|
205
250
|
const gasConfig = merge(this.config, gasConfigOverrides);
|
|
206
251
|
const account = this.getSenderAddress().toString();
|
|
207
252
|
|
|
253
|
+
// Fail fast before doing any work (gas estimation, balance check) if we've been interrupted
|
|
254
|
+
// or if the caller's deadline has already passed. The same check is repeated after gas
|
|
255
|
+
// estimation in case it took long enough to push us past the deadline.
|
|
256
|
+
await this.checkInterruptedOrTimedOut(gasConfig);
|
|
257
|
+
|
|
208
258
|
let gasLimit: bigint;
|
|
209
259
|
if (this.debugMaxGasLimit) {
|
|
210
|
-
gasLimit =
|
|
260
|
+
gasLimit = MAX_L1_TX_LIMIT;
|
|
211
261
|
} else if (gasConfig.gasLimit) {
|
|
212
262
|
gasLimit = gasConfig.gasLimit;
|
|
213
263
|
} else {
|
|
@@ -217,34 +267,34 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
217
267
|
|
|
218
268
|
const gasPrice = await this.getGasPrice(gasConfig, !!blobInputs);
|
|
219
269
|
|
|
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
|
-
});
|
|
270
|
+
const now = await this.checkInterruptedOrTimedOut(gasConfig);
|
|
229
271
|
|
|
230
|
-
|
|
231
|
-
|
|
272
|
+
let txHash: Hex;
|
|
273
|
+
let nonce: number;
|
|
274
|
+
let baseState: Pick<L1TxState, 'request' | 'gasLimit' | 'blobInputs' | 'gasPrice' | 'nonce'>;
|
|
232
275
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
276
|
+
await this.sendMutex.acquire();
|
|
277
|
+
try {
|
|
278
|
+
const chainNonce = await this.client.getTransactionCount({ address: account, blockTag: 'pending' });
|
|
279
|
+
// If a fallback RPC node returns a stale count (lower than what we last sent), use our
|
|
280
|
+
// local lower bound to avoid sending a duplicate of an already-pending transaction.
|
|
281
|
+
nonce =
|
|
282
|
+
this.lastSentNonce !== undefined && chainNonce <= this.lastSentNonce ? this.lastSentNonce + 1 : chainNonce;
|
|
283
|
+
|
|
284
|
+
baseState = { request, gasLimit, blobInputs, gasPrice, nonce };
|
|
285
|
+
const txData = this.makeTxData(baseState, { isCancelTx: false });
|
|
286
|
+
|
|
287
|
+
const signedRequest = await this.prepareSignedTransaction(txData);
|
|
288
|
+
txHash = await this.client.sendRawTransaction({ serializedTransaction: signedRequest });
|
|
289
|
+
this.lastSentNonce = nonce;
|
|
290
|
+
} finally {
|
|
291
|
+
this.sendMutex.release();
|
|
238
292
|
}
|
|
239
293
|
|
|
240
|
-
// Send the new tx
|
|
241
|
-
const signedRequest = await this.prepareSignedTransaction(txData);
|
|
242
|
-
const txHash = await this.client.sendRawTransaction({ serializedTransaction: signedRequest });
|
|
243
|
-
|
|
244
294
|
// Create the new state for monitoring
|
|
245
295
|
const l1TxState: L1TxState = {
|
|
246
296
|
...baseState,
|
|
247
|
-
id: (await this.store?.consumeNextStateId(account)) ?? Math.max(...this.txs.map(tx => tx.id),
|
|
297
|
+
id: (await this.store?.consumeNextStateId(account)) ?? Math.max(...this.txs.map(tx => tx.id), -1) + 1,
|
|
248
298
|
txHashes: [txHash],
|
|
249
299
|
cancelTxHashes: [],
|
|
250
300
|
status: TxUtilsState.IDLE,
|
|
@@ -283,7 +333,7 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
283
333
|
return { txHash, state: l1TxState };
|
|
284
334
|
} catch (err: any) {
|
|
285
335
|
const viemError = formatViemError(err, request.abi);
|
|
286
|
-
this.logger.error(`Failed to send L1 transaction`, viemError, {
|
|
336
|
+
this.logger.error(`Failed to send L1 transaction: ${viemError.message}`, viemError, {
|
|
287
337
|
request: pick(request, 'to', 'value'),
|
|
288
338
|
});
|
|
289
339
|
throw viemError;
|
|
@@ -423,7 +473,6 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
423
473
|
{ nonce, account, pendingNonce, timePassed },
|
|
424
474
|
);
|
|
425
475
|
await this.updateState(state, TxUtilsState.NOT_MINED);
|
|
426
|
-
this.nonceManager.reset({ address: account, chainId: this.client.chain.id });
|
|
427
476
|
throw new DroppedTransactionError(nonce, account);
|
|
428
477
|
}
|
|
429
478
|
|
|
@@ -515,12 +564,7 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
515
564
|
|
|
516
565
|
// Oh no, the transaction has timed out!
|
|
517
566
|
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
567
|
await this.updateState(state, TxUtilsState.NOT_MINED);
|
|
523
|
-
this.nonceManager.reset({ address: account, chainId: this.client.chain.id });
|
|
524
568
|
} else {
|
|
525
569
|
// Otherwise we fire the cancellation without awaiting to avoid blocking the caller,
|
|
526
570
|
// and monitor it in the background so we can speed it up as needed.
|
|
@@ -631,12 +675,12 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
631
675
|
from: request.from ?? this.getSenderAddress().toString(),
|
|
632
676
|
maxFeePerGas: gasPrice.maxFeePerGas,
|
|
633
677
|
maxPriorityFeePerGas: gasPrice.maxPriorityFeePerGas,
|
|
634
|
-
gas: request.gas ??
|
|
678
|
+
gas: request.gas ?? MAX_L1_TX_LIMIT,
|
|
635
679
|
};
|
|
636
680
|
|
|
637
681
|
if (!request.gas && !gasConfig.ignoreBlockGasLimit) {
|
|
638
|
-
//
|
|
639
|
-
blockOverrides.gasLimit =
|
|
682
|
+
// MAX_L1_TX_LIMIT is set as call.gas, ensure block gasLimit is sufficient
|
|
683
|
+
blockOverrides.gasLimit = MAX_L1_TX_LIMIT;
|
|
640
684
|
}
|
|
641
685
|
|
|
642
686
|
return this._simulate(call, blockOverrides, stateOverrides, gasConfig, abi);
|
|
@@ -659,7 +703,6 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
659
703
|
{ nonce, account },
|
|
660
704
|
);
|
|
661
705
|
await this.updateState(state, TxUtilsState.NOT_MINED);
|
|
662
|
-
this.nonceManager.reset({ address: account, chainId: this.client.chain.id });
|
|
663
706
|
return;
|
|
664
707
|
}
|
|
665
708
|
|
|
@@ -671,7 +714,6 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
671
714
|
{ nonce, account, currentNonce },
|
|
672
715
|
);
|
|
673
716
|
await this.updateState(state, TxUtilsState.NOT_MINED);
|
|
674
|
-
this.nonceManager.reset({ address: account, chainId: this.client.chain.id });
|
|
675
717
|
return;
|
|
676
718
|
}
|
|
677
719
|
|
|
@@ -731,8 +773,17 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
731
773
|
return Number(timestamp) * 1000;
|
|
732
774
|
}
|
|
733
775
|
|
|
734
|
-
/** Makes empty blob inputs for the cancellation tx.
|
|
735
|
-
protected makeEmptyBlobInputs(
|
|
736
|
-
|
|
776
|
+
/** Makes empty blob inputs for the cancellation tx. */
|
|
777
|
+
protected makeEmptyBlobInputs(maxFeePerBlobGas: bigint): Required<L1BlobInputs> {
|
|
778
|
+
if (!this.kzg) {
|
|
779
|
+
throw new Error('Cannot make empty blob inputs for cancellation without kzg');
|
|
780
|
+
}
|
|
781
|
+
const blobData = new Uint8Array(131072).fill(0);
|
|
782
|
+
return { blobs: [blobData], kzg: this.kzg, maxFeePerBlobGas };
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
/** Creates a new delayer instance. */
|
|
786
|
+
protected createDelayer(opts: { ethereumSlotDuration: bigint | number }, bindings: LoggerBindings): Delayer {
|
|
787
|
+
return createDelayer(this.dateProvider, opts, bindings);
|
|
737
788
|
}
|
|
738
789
|
}
|
|
@@ -27,7 +27,7 @@ import type { ViemClient } from '../types.js';
|
|
|
27
27
|
import { type L1TxUtilsConfig, defaultL1TxUtilsConfig, l1TxUtilsConfigMappings } from './config.js';
|
|
28
28
|
import {
|
|
29
29
|
BLOCK_TIME_MS,
|
|
30
|
-
|
|
30
|
+
MAX_L1_TX_LIMIT,
|
|
31
31
|
MIN_BLOB_REPLACEMENT_BUMP_PERCENTAGE,
|
|
32
32
|
MIN_REPLACEMENT_BUMP_PERCENTAGE,
|
|
33
33
|
WEI_CONST,
|
|
@@ -84,63 +84,31 @@ export class ReadOnlyL1TxUtils {
|
|
|
84
84
|
): Promise<GasPrice> {
|
|
85
85
|
const gasConfig = merge(this.config, gasConfigOverrides);
|
|
86
86
|
|
|
87
|
-
//
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
87
|
+
// Execute strategy - it handles all RPC calls internally and returns everything we need
|
|
88
|
+
const strategyResult = await retry(
|
|
89
|
+
() =>
|
|
90
|
+
CurrentStrategy.execute(this.client, {
|
|
91
|
+
gasConfig,
|
|
92
|
+
isBlobTx,
|
|
93
|
+
logger: this.logger,
|
|
94
|
+
}),
|
|
95
|
+
'Executing priority fee strategy',
|
|
96
|
+
makeBackoff(times(2, () => 0)),
|
|
97
|
+
this.logger,
|
|
98
|
+
true,
|
|
92
99
|
);
|
|
93
100
|
|
|
94
|
-
|
|
95
|
-
if (isBlobTx) {
|
|
96
|
-
blobBaseFeePromise = this.tryTwice(() => this.client.getBlobBaseFee(), 'Getting blob base fee');
|
|
97
|
-
}
|
|
101
|
+
const { latestBlock, blobBaseFee, priorityFee: strategyPriorityFee } = strategyResult;
|
|
98
102
|
|
|
99
|
-
//
|
|
100
|
-
const
|
|
101
|
-
const strategyPromiseKeys = [];
|
|
102
|
-
const strategyPromisesArr = [];
|
|
103
|
-
for (const [key, promise] of Object.entries(strategyPromises)) {
|
|
104
|
-
strategyPromiseKeys.push(key);
|
|
105
|
-
strategyPromisesArr.push(this.tryTwice(() => promise, `Getting strategy data for ${key}`));
|
|
106
|
-
}
|
|
103
|
+
// Extract base fee from latest block
|
|
104
|
+
const baseFee = latestBlock.baseFeePerGas ?? 0n;
|
|
107
105
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
blobBaseFeePromise ?? Promise.resolve(0n),
|
|
111
|
-
...strategyPromisesArr,
|
|
112
|
-
]);
|
|
113
|
-
|
|
114
|
-
// Extract results
|
|
115
|
-
const baseFee =
|
|
116
|
-
latestBlockResult.status === 'fulfilled' &&
|
|
117
|
-
typeof latestBlockResult.value === 'object' &&
|
|
118
|
-
latestBlockResult.value.baseFeePerGas
|
|
119
|
-
? latestBlockResult.value.baseFeePerGas
|
|
120
|
-
: 0n;
|
|
121
|
-
|
|
122
|
-
// Get blob base fee if available
|
|
123
|
-
let blobBaseFee = 0n;
|
|
124
|
-
if (isBlobTx && blobBaseFeeResult.status === 'fulfilled' && typeof blobBaseFeeResult.value === 'bigint') {
|
|
125
|
-
blobBaseFee = blobBaseFeeResult.value;
|
|
126
|
-
} else if (isBlobTx) {
|
|
106
|
+
// Handle blob base fee
|
|
107
|
+
if (isBlobTx && blobBaseFee === undefined) {
|
|
127
108
|
this.logger?.warn('Failed to get L1 blob base fee', attempt);
|
|
128
109
|
}
|
|
129
110
|
|
|
130
|
-
let priorityFee
|
|
131
|
-
// Get competitive priority fee using strategy
|
|
132
|
-
// Reconstruct the results object with the same keys as the promises
|
|
133
|
-
const resultsObject: Record<string, PromiseSettledResult<unknown>> = {};
|
|
134
|
-
strategyPromiseKeys.forEach((key, index) => {
|
|
135
|
-
resultsObject[key] = strategyResults[index];
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
const result = CurrentStrategy.calculate(resultsObject as any, {
|
|
139
|
-
gasConfig,
|
|
140
|
-
isBlobTx,
|
|
141
|
-
logger: this.logger,
|
|
142
|
-
});
|
|
143
|
-
priorityFee = result.priorityFee;
|
|
111
|
+
let priorityFee = strategyPriorityFee;
|
|
144
112
|
|
|
145
113
|
// Apply minimum priority fee floor if configured
|
|
146
114
|
if (gasConfig.minimumPriorityFeePerGas) {
|
|
@@ -156,15 +124,16 @@ export class ReadOnlyL1TxUtils {
|
|
|
156
124
|
}
|
|
157
125
|
let maxFeePerGas = baseFee;
|
|
158
126
|
|
|
159
|
-
let maxFeePerBlobGas = blobBaseFee;
|
|
127
|
+
let maxFeePerBlobGas = blobBaseFee ?? 0n;
|
|
160
128
|
|
|
161
129
|
// Bump base fee so it's valid for next blocks if it stalls
|
|
162
130
|
const numBlocks = Math.ceil(gasConfig.stallTimeMs! / BLOCK_TIME_MS);
|
|
163
131
|
for (let i = 0; i < numBlocks; i++) {
|
|
164
132
|
// each block can go up 12.5% from previous baseFee
|
|
165
|
-
|
|
133
|
+
// ceil, (a+b-1)/b, to avoid truncation at small values (e.g. 1 wei blob base fee)
|
|
134
|
+
maxFeePerGas = (maxFeePerGas * (1_000n + 125n) + 999n) / 1_000n;
|
|
166
135
|
// same for blob gas fee
|
|
167
|
-
maxFeePerBlobGas = (maxFeePerBlobGas * (1_000n + 125n)) / 1_000n;
|
|
136
|
+
maxFeePerBlobGas = (maxFeePerBlobGas * (1_000n + 125n) + 999n) / 1_000n;
|
|
168
137
|
}
|
|
169
138
|
|
|
170
139
|
if (attempt > 0) {
|
|
@@ -250,7 +219,7 @@ export class ReadOnlyL1TxUtils {
|
|
|
250
219
|
baseFee: formatGwei(baseFee),
|
|
251
220
|
maxFeePerGas: formatGwei(maxFeePerGas),
|
|
252
221
|
maxPriorityFeePerGas: formatGwei(maxPriorityFeePerGas),
|
|
253
|
-
blobBaseFee: formatGwei(blobBaseFee),
|
|
222
|
+
blobBaseFee: formatGwei(blobBaseFee ?? 0n),
|
|
254
223
|
maxFeePerBlobGas: formatGwei(maxFeePerBlobGas),
|
|
255
224
|
},
|
|
256
225
|
);
|
|
@@ -274,14 +243,17 @@ export class ReadOnlyL1TxUtils {
|
|
|
274
243
|
const gasConfig = { ...this.config, ..._gasConfig };
|
|
275
244
|
let initialEstimate = 0n;
|
|
276
245
|
if (_blobInputs) {
|
|
277
|
-
// @note requests with blobs also require maxFeePerBlobGas to be set
|
|
246
|
+
// @note requests with blobs also require maxFeePerBlobGas to be set.
|
|
247
|
+
// Use 2x buffer for maxFeePerBlobGas to avoid stale fees and to pass EIP-4844 validation (even if it is a gas estimation call).
|
|
248
|
+
// 1. maxFeePerBlobGas >= blobBaseFee
|
|
249
|
+
// 2. account balance >= gas * maxFeePerGas + maxFeePerBlobGas * blobCount + value
|
|
278
250
|
const gasPrice = await this.getGasPrice(gasConfig, true, 0);
|
|
279
251
|
initialEstimate = await this.client.estimateGas({
|
|
280
252
|
account,
|
|
281
253
|
...request,
|
|
282
254
|
..._blobInputs,
|
|
283
|
-
maxFeePerBlobGas: gasPrice.maxFeePerBlobGas
|
|
284
|
-
gas:
|
|
255
|
+
maxFeePerBlobGas: gasPrice.maxFeePerBlobGas! * 2n,
|
|
256
|
+
gas: MAX_L1_TX_LIMIT,
|
|
285
257
|
blockTag: 'latest',
|
|
286
258
|
});
|
|
287
259
|
|
|
@@ -290,7 +262,7 @@ export class ReadOnlyL1TxUtils {
|
|
|
290
262
|
initialEstimate = await this.client.estimateGas({
|
|
291
263
|
account,
|
|
292
264
|
...request,
|
|
293
|
-
gas:
|
|
265
|
+
gas: MAX_L1_TX_LIMIT,
|
|
294
266
|
blockTag: 'latest',
|
|
295
267
|
});
|
|
296
268
|
this.logger?.trace(`Estimated gas for non-blob tx: ${initialEstimate}`);
|
|
@@ -448,11 +420,4 @@ export class ReadOnlyL1TxUtils {
|
|
|
448
420
|
});
|
|
449
421
|
return bumpedGasLimit;
|
|
450
422
|
}
|
|
451
|
-
|
|
452
|
-
/**
|
|
453
|
-
* Helper function to retry RPC calls twice
|
|
454
|
-
*/
|
|
455
|
-
private tryTwice<T>(fn: () => Promise<T>, description: string): Promise<T> {
|
|
456
|
-
return retry<T>(fn, description, makeBackoff(times(2, () => 0)), this.logger, true);
|
|
457
|
-
}
|
|
458
423
|
}
|