@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
|
@@ -2,17 +2,18 @@ import { maxBigint } from '@aztec/foundation/bigint';
|
|
|
2
2
|
import { merge, pick } from '@aztec/foundation/collection';
|
|
3
3
|
import { InterruptError, TimeoutError } from '@aztec/foundation/error';
|
|
4
4
|
import { createLogger } from '@aztec/foundation/log';
|
|
5
|
+
import { Semaphore } from '@aztec/foundation/queue';
|
|
5
6
|
import { retryUntil } from '@aztec/foundation/retry';
|
|
6
7
|
import { sleep } from '@aztec/foundation/sleep';
|
|
7
8
|
import { DateProvider } from '@aztec/foundation/timer';
|
|
8
9
|
import { RollupAbi } from '@aztec/l1-artifacts/RollupAbi';
|
|
9
10
|
import pickBy from 'lodash.pickby';
|
|
10
|
-
import {
|
|
11
|
-
import { jsonRpc } from 'viem/nonce';
|
|
11
|
+
import { formatGwei, serializeTransaction } from 'viem';
|
|
12
12
|
import { formatViemError } from '../utils.js';
|
|
13
13
|
import { l1TxUtilsConfigMappings } from './config.js';
|
|
14
|
-
import {
|
|
14
|
+
import { MAX_L1_TX_LIMIT } from './constants.js';
|
|
15
15
|
import { ReadOnlyL1TxUtils } from './readonly_l1_tx_utils.js';
|
|
16
|
+
import { createDelayer, wrapClientWithDelayer } from './tx_delayer.js';
|
|
16
17
|
import { DroppedTransactionError, TerminalTxUtilsState, TxUtilsState, UnknownMinedTxError } from './types.js';
|
|
17
18
|
const MAX_L1_TX_STATES = 32;
|
|
18
19
|
export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
@@ -21,13 +22,28 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
21
22
|
signer;
|
|
22
23
|
store;
|
|
23
24
|
metrics;
|
|
24
|
-
nonceManager;
|
|
25
25
|
txs;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
26
|
+
/** Last nonce successfully sent to the chain. Used as a lower bound when a fallback RPC node returns a stale count. */ lastSentNonce;
|
|
27
|
+
/** Mutex to prevent concurrent sendTransaction calls from racing on the same nonce. */ sendMutex;
|
|
28
|
+
/** Tx delayer for testing. Only set when enableDelayer config is true. */ delayer;
|
|
29
|
+
/** KZG instance for blob operations. */ kzg;
|
|
30
|
+
constructor(client, address, signer, logger = createLogger('ethereum:publisher'), dateProvider = new DateProvider(), config, debugMaxGasLimit = false, store, metrics, kzg, delayer){
|
|
31
|
+
super(client, logger, dateProvider, config, debugMaxGasLimit), this.client = client, this.address = address, this.signer = signer, this.store = store, this.metrics = metrics, this.txs = [], this.sendMutex = new Semaphore(1);
|
|
32
|
+
this.kzg = kzg;
|
|
33
|
+
// Set up delayer: use provided one or create new
|
|
34
|
+
if (config?.enableDelayer && config?.ethereumSlotDuration) {
|
|
35
|
+
this.delayer = delayer ?? this.createDelayer({
|
|
36
|
+
ethereumSlotDuration: config.ethereumSlotDuration
|
|
37
|
+
}, logger.getBindings());
|
|
38
|
+
this.client = wrapClientWithDelayer(this.client, this.delayer);
|
|
39
|
+
if (config.txDelayerMaxInclusionTimeIntoSlot !== undefined) {
|
|
40
|
+
this.delayer.setMaxInclusionTimeIntoSlot(config.txDelayerMaxInclusionTimeIntoSlot);
|
|
41
|
+
}
|
|
42
|
+
} else if (delayer) {
|
|
43
|
+
// Delayer provided but enableDelayer not set — just store it without wrapping
|
|
44
|
+
logger.warn('Delayer provided but enableDelayer config is not set; delayer will not be used');
|
|
45
|
+
this.delayer = delayer;
|
|
46
|
+
}
|
|
31
47
|
}
|
|
32
48
|
get state() {
|
|
33
49
|
return this.txs.at(-1)?.status ?? TxUtilsState.IDLE;
|
|
@@ -46,6 +62,11 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
46
62
|
this.metrics?.recordMinedTx(l1TxState, new Date(l1Timestamp));
|
|
47
63
|
} else if (newState === TxUtilsState.NOT_MINED) {
|
|
48
64
|
this.metrics?.recordDroppedTx(l1TxState);
|
|
65
|
+
// The tx was dropped: the chain nonce reverted to l1TxState.nonce, so our lower bound is
|
|
66
|
+
// no longer valid. Clear it so the next send fetches the real nonce from the chain.
|
|
67
|
+
if (this.lastSentNonce === l1TxState.nonce) {
|
|
68
|
+
this.lastSentNonce = undefined;
|
|
69
|
+
}
|
|
49
70
|
}
|
|
50
71
|
// Update state in the store
|
|
51
72
|
await this.store?.saveState(sender, l1TxState).catch((err)=>this.logger.error('Failed to persist L1 tx state', err));
|
|
@@ -54,6 +75,12 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
54
75
|
this.config = merge(this.config, newConfig);
|
|
55
76
|
this.logger.info('Updated L1TxUtils config', pickBy(newConfig, (_, key)=>key in l1TxUtilsConfigMappings));
|
|
56
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* Clears the cached `lastSentNonce` so the next `sendTransaction` call fetches the real
|
|
80
|
+
* nonce from the chain. Call this after an L1 reorg to prevent stale nonce references.
|
|
81
|
+
*/ resetNonce() {
|
|
82
|
+
this.lastSentNonce = undefined;
|
|
83
|
+
}
|
|
57
84
|
getSenderAddress() {
|
|
58
85
|
return this.address;
|
|
59
86
|
}
|
|
@@ -120,21 +147,32 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
120
147
|
const txRequest = await this.client.prepareTransactionRequest(txData);
|
|
121
148
|
return await this.signTransaction(txRequest);
|
|
122
149
|
}
|
|
150
|
+
async checkInterruptedOrTimedOut(gasConfig) {
|
|
151
|
+
if (this.interrupted) {
|
|
152
|
+
throw new InterruptError(`Transaction sending is interrupted`);
|
|
153
|
+
}
|
|
154
|
+
const now = new Date(await this.getL1Timestamp());
|
|
155
|
+
if (gasConfig.txTimeoutAt && now > gasConfig.txTimeoutAt) {
|
|
156
|
+
throw new TimeoutError(`Transaction timed out before sending (now ${now.toISOString()} > timeoutAt ${gasConfig.txTimeoutAt.toISOString()})`);
|
|
157
|
+
}
|
|
158
|
+
return now;
|
|
159
|
+
}
|
|
123
160
|
/**
|
|
124
161
|
* Sends a transaction with gas estimation and pricing
|
|
125
162
|
* @param request - The transaction request (to, data, value)
|
|
126
163
|
* @param gasConfig - Optional gas configuration
|
|
127
164
|
* @returns The transaction hash and parameters used
|
|
128
165
|
*/ async sendTransaction(request, gasConfigOverrides, blobInputs, stateChange = TxUtilsState.SENT) {
|
|
129
|
-
if (this.interrupted) {
|
|
130
|
-
throw new InterruptError(`Transaction sending is interrupted`);
|
|
131
|
-
}
|
|
132
166
|
try {
|
|
133
167
|
const gasConfig = merge(this.config, gasConfigOverrides);
|
|
134
168
|
const account = this.getSenderAddress().toString();
|
|
169
|
+
// Fail fast before doing any work (gas estimation, balance check) if we've been interrupted
|
|
170
|
+
// or if the caller's deadline has already passed. The same check is repeated after gas
|
|
171
|
+
// estimation in case it took long enough to push us past the deadline.
|
|
172
|
+
await this.checkInterruptedOrTimedOut(gasConfig);
|
|
135
173
|
let gasLimit;
|
|
136
174
|
if (this.debugMaxGasLimit) {
|
|
137
|
-
gasLimit =
|
|
175
|
+
gasLimit = MAX_L1_TX_LIMIT;
|
|
138
176
|
} else if (gasConfig.gasLimit) {
|
|
139
177
|
gasLimit = gasConfig.gasLimit;
|
|
140
178
|
} else {
|
|
@@ -145,37 +183,41 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
145
183
|
...request
|
|
146
184
|
});
|
|
147
185
|
const gasPrice = await this.getGasPrice(gasConfig, !!blobInputs);
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
186
|
+
const now = await this.checkInterruptedOrTimedOut(gasConfig);
|
|
187
|
+
let txHash;
|
|
188
|
+
let nonce;
|
|
189
|
+
let baseState;
|
|
190
|
+
await this.sendMutex.acquire();
|
|
191
|
+
try {
|
|
192
|
+
const chainNonce = await this.client.getTransactionCount({
|
|
193
|
+
address: account,
|
|
194
|
+
blockTag: 'pending'
|
|
195
|
+
});
|
|
196
|
+
// If a fallback RPC node returns a stale count (lower than what we last sent), use our
|
|
197
|
+
// local lower bound to avoid sending a duplicate of an already-pending transaction.
|
|
198
|
+
nonce = this.lastSentNonce !== undefined && chainNonce <= this.lastSentNonce ? this.lastSentNonce + 1 : chainNonce;
|
|
199
|
+
baseState = {
|
|
200
|
+
request,
|
|
201
|
+
gasLimit,
|
|
202
|
+
blobInputs,
|
|
203
|
+
gasPrice,
|
|
204
|
+
nonce
|
|
205
|
+
};
|
|
206
|
+
const txData = this.makeTxData(baseState, {
|
|
207
|
+
isCancelTx: false
|
|
208
|
+
});
|
|
209
|
+
const signedRequest = await this.prepareSignedTransaction(txData);
|
|
210
|
+
txHash = await this.client.sendRawTransaction({
|
|
211
|
+
serializedTransaction: signedRequest
|
|
212
|
+
});
|
|
213
|
+
this.lastSentNonce = nonce;
|
|
214
|
+
} finally{
|
|
215
|
+
this.sendMutex.release();
|
|
169
216
|
}
|
|
170
|
-
// Send the new tx
|
|
171
|
-
const signedRequest = await this.prepareSignedTransaction(txData);
|
|
172
|
-
const txHash = await this.client.sendRawTransaction({
|
|
173
|
-
serializedTransaction: signedRequest
|
|
174
|
-
});
|
|
175
217
|
// Create the new state for monitoring
|
|
176
218
|
const l1TxState = {
|
|
177
219
|
...baseState,
|
|
178
|
-
id: await this.store?.consumeNextStateId(account) ?? Math.max(...this.txs.map((tx)=>tx.id),
|
|
220
|
+
id: await this.store?.consumeNextStateId(account) ?? Math.max(...this.txs.map((tx)=>tx.id), -1) + 1,
|
|
179
221
|
txHashes: [
|
|
180
222
|
txHash
|
|
181
223
|
],
|
|
@@ -217,7 +259,7 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
217
259
|
};
|
|
218
260
|
} catch (err) {
|
|
219
261
|
const viemError = formatViemError(err, request.abi);
|
|
220
|
-
this.logger.error(`Failed to send L1 transaction`, viemError, {
|
|
262
|
+
this.logger.error(`Failed to send L1 transaction: ${viemError.message}`, viemError, {
|
|
221
263
|
request: pick(request, 'to', 'value')
|
|
222
264
|
});
|
|
223
265
|
throw viemError;
|
|
@@ -346,10 +388,6 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
346
388
|
timePassed
|
|
347
389
|
});
|
|
348
390
|
await this.updateState(state, TxUtilsState.NOT_MINED);
|
|
349
|
-
this.nonceManager.reset({
|
|
350
|
-
address: account,
|
|
351
|
-
chainId: this.client.chain.id
|
|
352
|
-
});
|
|
353
391
|
throw new DroppedTransactionError(nonce, account);
|
|
354
392
|
}
|
|
355
393
|
// Break if the tx has timed out (ie expired)
|
|
@@ -421,15 +459,7 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
421
459
|
}
|
|
422
460
|
// Oh no, the transaction has timed out!
|
|
423
461
|
if (isCancelTx || !gasConfig.cancelTxOnTimeout) {
|
|
424
|
-
// If this was already a cancellation tx, or we are configured to not cancel txs, we just mark it as NOT_MINED
|
|
425
|
-
// and reset the nonce manager, so the next tx that comes along can reuse the nonce if/when this tx gets dropped.
|
|
426
|
-
// This is the nastiest scenario for us, since the new tx could acquire the next nonce, but then this tx is dropped,
|
|
427
|
-
// and the new tx would never get mined. Eventually, the new tx would also drop.
|
|
428
462
|
await this.updateState(state, TxUtilsState.NOT_MINED);
|
|
429
|
-
this.nonceManager.reset({
|
|
430
|
-
address: account,
|
|
431
|
-
chainId: this.client.chain.id
|
|
432
|
-
});
|
|
433
463
|
} else {
|
|
434
464
|
// Otherwise we fire the cancellation without awaiting to avoid blocking the caller,
|
|
435
465
|
// and monitor it in the background so we can speed it up as needed.
|
|
@@ -522,11 +552,11 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
522
552
|
from: request.from ?? this.getSenderAddress().toString(),
|
|
523
553
|
maxFeePerGas: gasPrice.maxFeePerGas,
|
|
524
554
|
maxPriorityFeePerGas: gasPrice.maxPriorityFeePerGas,
|
|
525
|
-
gas: request.gas ??
|
|
555
|
+
gas: request.gas ?? MAX_L1_TX_LIMIT
|
|
526
556
|
};
|
|
527
557
|
if (!request.gas && !gasConfig.ignoreBlockGasLimit) {
|
|
528
|
-
//
|
|
529
|
-
blockOverrides.gasLimit =
|
|
558
|
+
// MAX_L1_TX_LIMIT is set as call.gas, ensure block gasLimit is sufficient
|
|
559
|
+
blockOverrides.gasLimit = MAX_L1_TX_LIMIT;
|
|
530
560
|
}
|
|
531
561
|
return this._simulate(call, blockOverrides, stateOverrides, gasConfig, abi);
|
|
532
562
|
}
|
|
@@ -545,10 +575,6 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
545
575
|
account
|
|
546
576
|
});
|
|
547
577
|
await this.updateState(state, TxUtilsState.NOT_MINED);
|
|
548
|
-
this.nonceManager.reset({
|
|
549
|
-
address: account,
|
|
550
|
-
chainId: this.client.chain.id
|
|
551
|
-
});
|
|
552
578
|
return;
|
|
553
579
|
}
|
|
554
580
|
// Check if the original tx is still pending
|
|
@@ -563,10 +589,6 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
563
589
|
currentNonce
|
|
564
590
|
});
|
|
565
591
|
await this.updateState(state, TxUtilsState.NOT_MINED);
|
|
566
|
-
this.nonceManager.reset({
|
|
567
|
-
address: account,
|
|
568
|
-
chainId: this.client.chain.id
|
|
569
|
-
});
|
|
570
592
|
return;
|
|
571
593
|
}
|
|
572
594
|
// Get gas price with higher priority fee for cancellation
|
|
@@ -617,7 +639,20 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
617
639
|
});
|
|
618
640
|
return Number(timestamp) * 1000;
|
|
619
641
|
}
|
|
620
|
-
/** Makes empty blob inputs for the cancellation tx.
|
|
621
|
-
|
|
642
|
+
/** Makes empty blob inputs for the cancellation tx. */ makeEmptyBlobInputs(maxFeePerBlobGas) {
|
|
643
|
+
if (!this.kzg) {
|
|
644
|
+
throw new Error('Cannot make empty blob inputs for cancellation without kzg');
|
|
645
|
+
}
|
|
646
|
+
const blobData = new Uint8Array(131072).fill(0);
|
|
647
|
+
return {
|
|
648
|
+
blobs: [
|
|
649
|
+
blobData
|
|
650
|
+
],
|
|
651
|
+
kzg: this.kzg,
|
|
652
|
+
maxFeePerBlobGas
|
|
653
|
+
};
|
|
654
|
+
}
|
|
655
|
+
/** Creates a new delayer instance. */ createDelayer(opts, bindings) {
|
|
656
|
+
return createDelayer(this.dateProvider, opts, bindings);
|
|
622
657
|
}
|
|
623
658
|
}
|
|
@@ -79,9 +79,5 @@ export declare class ReadOnlyL1TxUtils {
|
|
|
79
79
|
result: `0x${string}`;
|
|
80
80
|
}>;
|
|
81
81
|
bumpGasLimit(gasLimit: bigint, _gasConfig?: L1TxUtilsConfig): bigint;
|
|
82
|
-
/**
|
|
83
|
-
* Helper function to retry RPC calls twice
|
|
84
|
-
*/
|
|
85
|
-
private tryTwice;
|
|
86
82
|
}
|
|
87
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
83
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicmVhZG9ubHlfbDFfdHhfdXRpbHMuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9sMV90eF91dGlscy9yZWFkb25seV9sMV90eF91dGlscy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFDQSxPQUFPLEtBQUssRUFBRSxVQUFVLEVBQUUsTUFBTSwrQkFBK0IsQ0FBQztBQUNoRSxPQUFPLEVBQUUsS0FBSyxNQUFNLEVBQWdCLE1BQU0sdUJBQXVCLENBQUM7QUFFbEUsT0FBTyxFQUFFLFlBQVksRUFBRSxNQUFNLHlCQUF5QixDQUFDO0FBSXZELE9BQU8sRUFDTCxLQUFLLEdBQUcsRUFDUixLQUFLL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7 @@ import { RollupAbi } from '@aztec/l1-artifacts/RollupAbi';
|
|
|
5
5
|
import pickBy from 'lodash.pickby';
|
|
6
6
|
import { MethodNotFoundRpcError, MethodNotSupportedRpcError, decodeErrorResult, formatGwei, getContractError, hexToBytes } from 'viem';
|
|
7
7
|
import { defaultL1TxUtilsConfig, l1TxUtilsConfigMappings } from './config.js';
|
|
8
|
-
import { BLOCK_TIME_MS,
|
|
8
|
+
import { BLOCK_TIME_MS, MAX_L1_TX_LIMIT, MIN_BLOB_REPLACEMENT_BUMP_PERCENTAGE, MIN_REPLACEMENT_BUMP_PERCENTAGE, WEI_CONST } from './constants.js';
|
|
9
9
|
import { P75AllTxsPriorityFeeStrategy } from './fee-strategies/index.js';
|
|
10
10
|
import { getCalldataGasUsage, tryGetCustomErrorNameContractFunction } from './utils.js';
|
|
11
11
|
// Change this to the current strategy we want to use
|
|
@@ -46,52 +46,20 @@ export class ReadOnlyL1TxUtils {
|
|
|
46
46
|
* Gets the current gas price with bounds checking
|
|
47
47
|
*/ async getGasPrice(gasConfigOverrides, isBlobTx = false, attempt = 0, previousGasPrice) {
|
|
48
48
|
const gasConfig = merge(this.config, gasConfigOverrides);
|
|
49
|
-
//
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
//
|
|
59
|
-
|
|
60
|
-
isBlobTx
|
|
61
|
-
});
|
|
62
|
-
const strategyPromiseKeys = [];
|
|
63
|
-
const strategyPromisesArr = [];
|
|
64
|
-
for (const [key, promise] of Object.entries(strategyPromises)){
|
|
65
|
-
strategyPromiseKeys.push(key);
|
|
66
|
-
strategyPromisesArr.push(this.tryTwice(()=>promise, `Getting strategy data for ${key}`));
|
|
67
|
-
}
|
|
68
|
-
const [latestBlockResult, blobBaseFeeResult, ...strategyResults] = await Promise.allSettled([
|
|
69
|
-
latestBlockPromise,
|
|
70
|
-
blobBaseFeePromise ?? Promise.resolve(0n),
|
|
71
|
-
...strategyPromisesArr
|
|
72
|
-
]);
|
|
73
|
-
// Extract results
|
|
74
|
-
const baseFee = latestBlockResult.status === 'fulfilled' && typeof latestBlockResult.value === 'object' && latestBlockResult.value.baseFeePerGas ? latestBlockResult.value.baseFeePerGas : 0n;
|
|
75
|
-
// Get blob base fee if available
|
|
76
|
-
let blobBaseFee = 0n;
|
|
77
|
-
if (isBlobTx && blobBaseFeeResult.status === 'fulfilled' && typeof blobBaseFeeResult.value === 'bigint') {
|
|
78
|
-
blobBaseFee = blobBaseFeeResult.value;
|
|
79
|
-
} else if (isBlobTx) {
|
|
49
|
+
// Execute strategy - it handles all RPC calls internally and returns everything we need
|
|
50
|
+
const strategyResult = await retry(()=>CurrentStrategy.execute(this.client, {
|
|
51
|
+
gasConfig,
|
|
52
|
+
isBlobTx,
|
|
53
|
+
logger: this.logger
|
|
54
|
+
}), 'Executing priority fee strategy', makeBackoff(times(2, ()=>0)), this.logger, true);
|
|
55
|
+
const { latestBlock, blobBaseFee, priorityFee: strategyPriorityFee } = strategyResult;
|
|
56
|
+
// Extract base fee from latest block
|
|
57
|
+
const baseFee = latestBlock.baseFeePerGas ?? 0n;
|
|
58
|
+
// Handle blob base fee
|
|
59
|
+
if (isBlobTx && blobBaseFee === undefined) {
|
|
80
60
|
this.logger?.warn('Failed to get L1 blob base fee', attempt);
|
|
81
61
|
}
|
|
82
|
-
let priorityFee;
|
|
83
|
-
// Get competitive priority fee using strategy
|
|
84
|
-
// Reconstruct the results object with the same keys as the promises
|
|
85
|
-
const resultsObject = {};
|
|
86
|
-
strategyPromiseKeys.forEach((key, index)=>{
|
|
87
|
-
resultsObject[key] = strategyResults[index];
|
|
88
|
-
});
|
|
89
|
-
const result = CurrentStrategy.calculate(resultsObject, {
|
|
90
|
-
gasConfig,
|
|
91
|
-
isBlobTx,
|
|
92
|
-
logger: this.logger
|
|
93
|
-
});
|
|
94
|
-
priorityFee = result.priorityFee;
|
|
62
|
+
let priorityFee = strategyPriorityFee;
|
|
95
63
|
// Apply minimum priority fee floor if configured
|
|
96
64
|
if (gasConfig.minimumPriorityFeePerGas) {
|
|
97
65
|
const minimumPriorityFee = BigInt(Math.trunc(gasConfig.minimumPriorityFeePerGas * Number(WEI_CONST)));
|
|
@@ -105,14 +73,15 @@ export class ReadOnlyL1TxUtils {
|
|
|
105
73
|
}
|
|
106
74
|
}
|
|
107
75
|
let maxFeePerGas = baseFee;
|
|
108
|
-
let maxFeePerBlobGas = blobBaseFee;
|
|
76
|
+
let maxFeePerBlobGas = blobBaseFee ?? 0n;
|
|
109
77
|
// Bump base fee so it's valid for next blocks if it stalls
|
|
110
78
|
const numBlocks = Math.ceil(gasConfig.stallTimeMs / BLOCK_TIME_MS);
|
|
111
79
|
for(let i = 0; i < numBlocks; i++){
|
|
112
80
|
// each block can go up 12.5% from previous baseFee
|
|
113
|
-
|
|
81
|
+
// ceil, (a+b-1)/b, to avoid truncation at small values (e.g. 1 wei blob base fee)
|
|
82
|
+
maxFeePerGas = (maxFeePerGas * (1_000n + 125n) + 999n) / 1_000n;
|
|
114
83
|
// same for blob gas fee
|
|
115
|
-
maxFeePerBlobGas = maxFeePerBlobGas * (1_000n + 125n) / 1_000n;
|
|
84
|
+
maxFeePerBlobGas = (maxFeePerBlobGas * (1_000n + 125n) + 999n) / 1_000n;
|
|
116
85
|
}
|
|
117
86
|
if (attempt > 0) {
|
|
118
87
|
const configBump = gasConfig.priorityFeeRetryBumpPercentage ?? defaultL1TxUtilsConfig.priorityFeeRetryBumpPercentage;
|
|
@@ -175,7 +144,7 @@ export class ReadOnlyL1TxUtils {
|
|
|
175
144
|
baseFee: formatGwei(baseFee),
|
|
176
145
|
maxFeePerGas: formatGwei(maxFeePerGas),
|
|
177
146
|
maxPriorityFeePerGas: formatGwei(maxPriorityFeePerGas),
|
|
178
|
-
blobBaseFee: formatGwei(blobBaseFee),
|
|
147
|
+
blobBaseFee: formatGwei(blobBaseFee ?? 0n),
|
|
179
148
|
maxFeePerBlobGas: formatGwei(maxFeePerBlobGas)
|
|
180
149
|
});
|
|
181
150
|
return {
|
|
@@ -195,14 +164,17 @@ export class ReadOnlyL1TxUtils {
|
|
|
195
164
|
};
|
|
196
165
|
let initialEstimate = 0n;
|
|
197
166
|
if (_blobInputs) {
|
|
198
|
-
// @note requests with blobs also require maxFeePerBlobGas to be set
|
|
167
|
+
// @note requests with blobs also require maxFeePerBlobGas to be set.
|
|
168
|
+
// Use 2x buffer for maxFeePerBlobGas to avoid stale fees and to pass EIP-4844 validation (even if it is a gas estimation call).
|
|
169
|
+
// 1. maxFeePerBlobGas >= blobBaseFee
|
|
170
|
+
// 2. account balance >= gas * maxFeePerGas + maxFeePerBlobGas * blobCount + value
|
|
199
171
|
const gasPrice = await this.getGasPrice(gasConfig, true, 0);
|
|
200
172
|
initialEstimate = await this.client.estimateGas({
|
|
201
173
|
account,
|
|
202
174
|
...request,
|
|
203
175
|
..._blobInputs,
|
|
204
|
-
maxFeePerBlobGas: gasPrice.maxFeePerBlobGas,
|
|
205
|
-
gas:
|
|
176
|
+
maxFeePerBlobGas: gasPrice.maxFeePerBlobGas * 2n,
|
|
177
|
+
gas: MAX_L1_TX_LIMIT,
|
|
206
178
|
blockTag: 'latest'
|
|
207
179
|
});
|
|
208
180
|
this.logger?.trace(`Estimated gas for blob tx: ${initialEstimate}`);
|
|
@@ -210,7 +182,7 @@ export class ReadOnlyL1TxUtils {
|
|
|
210
182
|
initialEstimate = await this.client.estimateGas({
|
|
211
183
|
account,
|
|
212
184
|
...request,
|
|
213
|
-
gas:
|
|
185
|
+
gas: MAX_L1_TX_LIMIT,
|
|
214
186
|
blockTag: 'latest'
|
|
215
187
|
});
|
|
216
188
|
this.logger?.trace(`Estimated gas for non-blob tx: ${initialEstimate}`);
|
|
@@ -352,9 +324,4 @@ export class ReadOnlyL1TxUtils {
|
|
|
352
324
|
});
|
|
353
325
|
return bumpedGasLimit;
|
|
354
326
|
}
|
|
355
|
-
/**
|
|
356
|
-
* Helper function to retry RPC calls twice
|
|
357
|
-
*/ tryTwice(fn, description) {
|
|
358
|
-
return retry(fn, description, makeBackoff(times(2, ()=>0)), this.logger, true);
|
|
359
|
-
}
|
|
360
327
|
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { type Logger, type LoggerBindings } from '@aztec/foundation/log';
|
|
2
|
+
import type { DateProvider } from '@aztec/foundation/timer';
|
|
3
|
+
import { type Client, type Hex } from 'viem';
|
|
4
|
+
import type { ViemClient } from '../types.js';
|
|
5
|
+
export declare function waitUntilBlock<T extends Client>(client: T, blockNumber: number | bigint, logger?: Logger, timeout?: number): Promise<boolean>;
|
|
6
|
+
export declare function waitUntilL1Timestamp<T extends Client>(client: T, timestamp: number | bigint, logger?: Logger, timeout?: number): Promise<boolean>;
|
|
7
|
+
/** Manages tx delaying for testing, intercepting sendRawTransaction calls to delay or cancel them. */
|
|
8
|
+
export declare class Delayer {
|
|
9
|
+
dateProvider: DateProvider;
|
|
10
|
+
private logger;
|
|
11
|
+
maxInclusionTimeIntoSlot: number | undefined;
|
|
12
|
+
ethereumSlotDuration: bigint;
|
|
13
|
+
nextWait: {
|
|
14
|
+
l1Timestamp: bigint;
|
|
15
|
+
timeoutSeconds?: number;
|
|
16
|
+
} | {
|
|
17
|
+
l1BlockNumber: bigint;
|
|
18
|
+
timeoutSeconds?: number;
|
|
19
|
+
} | {
|
|
20
|
+
indefinitely: true;
|
|
21
|
+
} | undefined;
|
|
22
|
+
sentTxHashes: Hex[];
|
|
23
|
+
cancelledTxs: Hex[];
|
|
24
|
+
constructor(dateProvider: DateProvider, opts: {
|
|
25
|
+
ethereumSlotDuration: bigint | number;
|
|
26
|
+
}, bindings: LoggerBindings);
|
|
27
|
+
/** Returns the logger instance used by this delayer. */
|
|
28
|
+
getLogger(): Logger;
|
|
29
|
+
/** Returns the hashes of all effectively sent txs. */
|
|
30
|
+
getSentTxHashes(): `0x${string}`[];
|
|
31
|
+
/** Returns the raw hex for all cancelled txs. */
|
|
32
|
+
getCancelledTxs(): Hex[];
|
|
33
|
+
/** Delays the next tx to be sent so it lands on the given L1 block number. */
|
|
34
|
+
pauseNextTxUntilBlock(l1BlockNumber: number | bigint, timeoutSeconds?: number): void;
|
|
35
|
+
/** Delays the next tx to be sent so it lands on the given timestamp. */
|
|
36
|
+
pauseNextTxUntilTimestamp(l1Timestamp: number | bigint, timeoutSeconds?: number): void;
|
|
37
|
+
/** Delays the next tx to be sent indefinitely. */
|
|
38
|
+
cancelNextTx(): void;
|
|
39
|
+
/**
|
|
40
|
+
* Sets max inclusion time into slot. If more than this many seconds have passed
|
|
41
|
+
* since the last L1 block was mined, then any tx will not be mined in the current
|
|
42
|
+
* L1 slot but will be deferred for the next one.
|
|
43
|
+
*/
|
|
44
|
+
setMaxInclusionTimeIntoSlot(seconds: number | undefined): void;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Creates a new Delayer instance. Exposed so callers can create a single shared delayer
|
|
48
|
+
* and pass it to multiple `wrapClientWithDelayer` calls.
|
|
49
|
+
*/
|
|
50
|
+
export declare function createDelayer(dateProvider: DateProvider, opts: {
|
|
51
|
+
ethereumSlotDuration: bigint | number;
|
|
52
|
+
}, bindings: LoggerBindings): Delayer;
|
|
53
|
+
/**
|
|
54
|
+
* Wraps a viem client with tx delaying logic. Returns the wrapped client.
|
|
55
|
+
* The delayer intercepts sendRawTransaction calls and delays them based on the delayer's state.
|
|
56
|
+
*/
|
|
57
|
+
export declare function wrapClientWithDelayer<T extends ViemClient>(client: T, delayer: Delayer): T;
|
|
58
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHhfZGVsYXllci5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL2wxX3R4X3V0aWxzL3R4X2RlbGF5ZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQ0EsT0FBTyxFQUFFLEtBQUssTUFBTSxFQUFFLEtBQU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