@aztec/ethereum 0.0.1-commit.b655e406 → 0.0.1-commit.b9865e97
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/account.d.ts +1 -1
- package/dest/chain.d.ts +1 -1
- package/dest/client.d.ts +25 -3
- package/dest/client.d.ts.map +1 -1
- package/dest/client.js +60 -4
- package/dest/config.d.ts +29 -73
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +70 -387
- package/dest/constants.d.ts +1 -1
- 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/empire_base.d.ts +7 -5
- package/dest/contracts/empire_base.d.ts.map +1 -1
- package/dest/contracts/empire_base.js +1 -1
- package/dest/contracts/errors.d.ts +1 -1
- package/dest/contracts/errors.d.ts.map +1 -1
- 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/fee_juice.d.ts +1 -1
- package/dest/contracts/fee_juice.d.ts.map +1 -1
- package/dest/contracts/governance.d.ts +113 -36
- package/dest/contracts/governance.d.ts.map +1 -1
- package/dest/contracts/governance.js +207 -16
- package/dest/contracts/governance_proposer.d.ts +38 -4
- package/dest/contracts/governance_proposer.d.ts.map +1 -1
- package/dest/contracts/governance_proposer.js +455 -12
- package/dest/contracts/gse.d.ts +1 -1
- package/dest/contracts/gse.d.ts.map +1 -1
- package/dest/contracts/inbox.d.ts +24 -3
- 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 +64 -0
- package/dest/contracts/outbox.d.ts.map +1 -0
- package/dest/contracts/outbox.js +113 -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 +5432 -131
- package/dest/contracts/rollup.d.ts.map +1 -1
- package/dest/contracts/rollup.js +1114 -231
- package/dest/contracts/slasher_contract.d.ts +1 -1
- package/dest/contracts/slasher_contract.d.ts.map +1 -1
- package/dest/contracts/{tally_slashing_proposer.d.ts → slashing_proposer.d.ts} +11 -10
- package/dest/contracts/slashing_proposer.d.ts.map +1 -0
- package/dest/contracts/{tally_slashing_proposer.js → slashing_proposer.js} +21 -16
- package/dest/contracts/utils.d.ts +1 -1
- package/dest/deploy_aztec_l1_contracts.d.ts +257 -0
- package/dest/deploy_aztec_l1_contracts.d.ts.map +1 -0
- package/dest/deploy_aztec_l1_contracts.js +410 -0
- package/dest/deploy_l1_contract.d.ts +68 -0
- package/dest/deploy_l1_contract.d.ts.map +1 -0
- package/dest/deploy_l1_contract.js +312 -0
- package/dest/eth-signer/eth-signer.d.ts +1 -1
- package/dest/eth-signer/index.d.ts +1 -1
- package/dest/forwarder_proxy.d.ts +32 -0
- package/dest/forwarder_proxy.d.ts.map +1 -0
- package/dest/forwarder_proxy.js +93 -0
- 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 +19816 -16730
- 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 +99 -80
- package/dest/l1_reader.d.ts +7 -5
- package/dest/l1_reader.d.ts.map +1 -1
- package/dest/l1_reader.js +15 -7
- package/dest/l1_tx_utils/config.d.ts +11 -5
- package/dest/l1_tx_utils/config.d.ts.map +1 -1
- package/dest/l1_tx_utils/config.js +43 -7
- package/dest/l1_tx_utils/constants.d.ts +8 -2
- package/dest/l1_tx_utils/constants.d.ts.map +1 -1
- package/dest/l1_tx_utils/constants.js +27 -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 +10 -0
- package/dest/l1_tx_utils/fee-strategies/index.d.ts.map +1 -0
- package/dest/l1_tx_utils/fee-strategies/index.js +12 -0
- package/dest/l1_tx_utils/fee-strategies/p75_competitive.d.ts +8 -0
- package/dest/l1_tx_utils/fee-strategies/p75_competitive.d.ts.map +1 -0
- package/dest/l1_tx_utils/fee-strategies/p75_competitive.js +129 -0
- package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.d.ts +23 -0
- package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.d.ts.map +1 -0
- package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.js +191 -0
- package/dest/l1_tx_utils/fee-strategies/types.d.ts +51 -0
- package/dest/l1_tx_utils/fee-strategies/types.d.ts.map +1 -0
- package/dest/l1_tx_utils/fee-strategies/types.js +3 -0
- package/dest/l1_tx_utils/forwarder_l1_tx_utils.d.ts +41 -0
- package/dest/l1_tx_utils/forwarder_l1_tx_utils.d.ts.map +1 -0
- package/dest/l1_tx_utils/forwarder_l1_tx_utils.js +42 -0
- package/dest/l1_tx_utils/index-blobs.d.ts +3 -0
- package/dest/l1_tx_utils/index-blobs.d.ts.map +1 -0
- package/dest/l1_tx_utils/index-blobs.js +2 -0
- package/dest/l1_tx_utils/index.d.ts +4 -1
- package/dest/l1_tx_utils/index.d.ts.map +1 -1
- package/dest/l1_tx_utils/index.js +3 -0
- package/dest/l1_tx_utils/interfaces.d.ts +2 -2
- package/dest/l1_tx_utils/interfaces.d.ts.map +1 -1
- package/dest/l1_tx_utils/l1_fee_analyzer.d.ts +233 -0
- package/dest/l1_tx_utils/l1_fee_analyzer.d.ts.map +1 -0
- package/dest/l1_tx_utils/l1_fee_analyzer.js +506 -0
- package/dest/l1_tx_utils/l1_tx_utils.d.ts +26 -8
- package/dest/l1_tx_utils/l1_tx_utils.d.ts.map +1 -1
- package/dest/l1_tx_utils/l1_tx_utils.js +118 -70
- package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts +19 -30
- package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts.map +1 -1
- package/dest/l1_tx_utils/readonly_l1_tx_utils.js +65 -168
- package/dest/l1_tx_utils/signer.d.ts +1 -1
- 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 +70 -39
- package/dest/l1_tx_utils/types.d.ts +1 -1
- package/dest/l1_tx_utils/types.d.ts.map +1 -1
- package/dest/l1_tx_utils/utils.d.ts +1 -1
- package/dest/l1_types.d.ts +1 -1
- 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 +78 -9
- package/dest/test/chain_monitor.d.ts +48 -25
- package/dest/test/chain_monitor.d.ts.map +1 -1
- package/dest/test/chain_monitor.js +71 -38
- package/dest/test/eth_cheat_codes.d.ts +22 -6
- package/dest/test/eth_cheat_codes.d.ts.map +1 -1
- package/dest/test/eth_cheat_codes.js +28 -7
- package/dest/test/eth_cheat_codes_with_state.d.ts +1 -1
- package/dest/test/eth_cheat_codes_with_state.d.ts.map +1 -1
- 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 +46 -14
- package/dest/test/rollup_cheat_codes.d.ts.map +1 -1
- package/dest/test/rollup_cheat_codes.js +118 -42
- package/dest/test/start_anvil.d.ts +25 -2
- package/dest/test/start_anvil.d.ts.map +1 -1
- package/dest/test/start_anvil.js +143 -28
- package/dest/test/upgrade_utils.d.ts +1 -1
- package/dest/test/upgrade_utils.js +2 -2
- package/dest/types.d.ts +57 -2
- package/dest/types.d.ts.map +1 -1
- package/dest/utils.d.ts +24 -4
- package/dest/utils.d.ts.map +1 -1
- package/dest/utils.js +112 -16
- package/dest/zkPassportVerifierAddress.d.ts +1 -1
- package/package.json +35 -17
- package/src/client.ts +66 -2
- package/src/config.ts +91 -469
- package/src/contracts/README.md +157 -0
- package/src/contracts/chain_state_override.ts +200 -0
- package/src/contracts/empire_base.ts +6 -5
- 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 +74 -7
- package/src/contracts/inbox.ts +64 -4
- 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 +132 -0
- package/src/contracts/registry.ts +31 -1
- package/src/contracts/rollup.ts +819 -192
- package/src/contracts/{tally_slashing_proposer.ts → slashing_proposer.ts} +26 -21
- package/src/deploy_aztec_l1_contracts.ts +646 -0
- package/src/deploy_l1_contract.ts +362 -0
- package/src/forwarder_proxy.ts +108 -0
- package/src/generated/l1-contracts-defaults.ts +32 -0
- package/src/l1_artifacts.ts +12 -35
- package/src/l1_contract_addresses.ts +120 -92
- package/src/l1_reader.ts +25 -10
- package/src/l1_tx_utils/config.ts +52 -11
- package/src/l1_tx_utils/constants.ts +13 -2
- package/src/l1_tx_utils/factory.ts +31 -31
- package/src/l1_tx_utils/fee-strategies/index.ts +22 -0
- package/src/l1_tx_utils/fee-strategies/p75_competitive.ts +163 -0
- package/src/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.ts +245 -0
- package/src/l1_tx_utils/fee-strategies/types.ts +56 -0
- package/src/l1_tx_utils/forwarder_l1_tx_utils.ts +108 -0
- package/src/l1_tx_utils/index-blobs.ts +2 -0
- package/src/l1_tx_utils/index.ts +3 -0
- package/src/l1_tx_utils/interfaces.ts +1 -1
- package/src/l1_tx_utils/l1_fee_analyzer.ts +803 -0
- package/src/l1_tx_utils/l1_tx_utils.ts +123 -52
- package/src/l1_tx_utils/readonly_l1_tx_utils.ts +79 -214
- package/src/{test → l1_tx_utils}/tx_delayer.ts +97 -58
- package/src/publisher_manager.ts +107 -10
- package/src/queries.ts +87 -10
- package/src/test/chain_monitor.ts +115 -51
- package/src/test/eth_cheat_codes.ts +25 -7
- package/src/test/index.ts +0 -2
- package/src/test/rollup_cheat_codes.ts +123 -45
- package/src/test/start_anvil.ts +179 -27
- package/src/test/upgrade_utils.ts +2 -2
- package/src/types.ts +62 -0
- package/src/utils.ts +128 -19
- package/dest/contracts/empire_slashing_proposer.d.ts +0 -65
- package/dest/contracts/empire_slashing_proposer.d.ts.map +0 -1
- package/dest/contracts/empire_slashing_proposer.js +0 -194
- package/dest/contracts/tally_slashing_proposer.d.ts.map +0 -1
- package/dest/deploy_l1_contracts.d.ts +0 -226
- package/dest/deploy_l1_contracts.d.ts.map +0 -1
- package/dest/deploy_l1_contracts.js +0 -1473
- package/dest/index.d.ts +0 -18
- package/dest/index.d.ts.map +0 -1
- package/dest/index.js +0 -17
- 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 -259
- package/src/deploy_l1_contracts.ts +0 -1849
- package/src/index.ts +0 -17
- 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
|
}
|
|
@@ -130,12 +166,32 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
130
166
|
return;
|
|
131
167
|
}
|
|
132
168
|
|
|
133
|
-
//
|
|
134
|
-
|
|
135
|
-
|
|
169
|
+
// Clean up excess states if we have more than MAX_L1_TX_STATES
|
|
170
|
+
if (loadedStates.length > MAX_L1_TX_STATES) {
|
|
171
|
+
this.logger.warn(
|
|
172
|
+
`Found ${loadedStates.length} tx states for account ${account}, pruning to most recent ${MAX_L1_TX_STATES}`,
|
|
173
|
+
);
|
|
174
|
+
|
|
175
|
+
// Keep only the most recent MAX_L1_TX_STATES
|
|
176
|
+
const statesToKeep = loadedStates.slice(-MAX_L1_TX_STATES);
|
|
177
|
+
const statesToDelete = loadedStates.slice(0, -MAX_L1_TX_STATES);
|
|
178
|
+
|
|
179
|
+
// Batch delete old states in a transaction for efficiency
|
|
180
|
+
const idsToDelete = statesToDelete.map(s => s.id);
|
|
181
|
+
await this.store.deleteState(account, ...idsToDelete);
|
|
182
|
+
|
|
183
|
+
this.txs = statesToKeep;
|
|
184
|
+
this.logger.info(
|
|
185
|
+
`Cleaned up ${statesToDelete.length} old tx states, kept ${statesToKeep.length} for account ${account}`,
|
|
186
|
+
);
|
|
187
|
+
} else {
|
|
188
|
+
// Convert loaded states (which have id) to the txs format
|
|
189
|
+
this.txs = loadedStates;
|
|
190
|
+
this.logger.info(`Rehydrated ${loadedStates.length} tx states for account ${account}`);
|
|
191
|
+
}
|
|
136
192
|
|
|
137
193
|
// Find all pending states and resume monitoring
|
|
138
|
-
const pendingStates =
|
|
194
|
+
const pendingStates = this.txs.filter(state => !TerminalTxUtilsState.includes(state.status));
|
|
139
195
|
if (pendingStates.length === 0) {
|
|
140
196
|
return;
|
|
141
197
|
}
|
|
@@ -165,6 +221,19 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
165
221
|
return await this.signTransaction(txRequest as TransactionSerializable);
|
|
166
222
|
}
|
|
167
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
|
+
|
|
168
237
|
/**
|
|
169
238
|
* Sends a transaction with gas estimation and pricing
|
|
170
239
|
* @param request - The transaction request (to, data, value)
|
|
@@ -177,17 +246,18 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
177
246
|
blobInputs?: L1BlobInputs,
|
|
178
247
|
stateChange: TxUtilsState = TxUtilsState.SENT,
|
|
179
248
|
): Promise<{ txHash: Hex; state: L1TxState }> {
|
|
180
|
-
if (this.interrupted) {
|
|
181
|
-
throw new InterruptError(`Transaction sending is interrupted`);
|
|
182
|
-
}
|
|
183
|
-
|
|
184
249
|
try {
|
|
185
250
|
const gasConfig = merge(this.config, gasConfigOverrides);
|
|
186
251
|
const account = this.getSenderAddress().toString();
|
|
187
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
|
+
|
|
188
258
|
let gasLimit: bigint;
|
|
189
259
|
if (this.debugMaxGasLimit) {
|
|
190
|
-
gasLimit =
|
|
260
|
+
gasLimit = MAX_L1_TX_LIMIT;
|
|
191
261
|
} else if (gasConfig.gasLimit) {
|
|
192
262
|
gasLimit = gasConfig.gasLimit;
|
|
193
263
|
} else {
|
|
@@ -197,34 +267,34 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
197
267
|
|
|
198
268
|
const gasPrice = await this.getGasPrice(gasConfig, !!blobInputs);
|
|
199
269
|
|
|
200
|
-
|
|
201
|
-
throw new InterruptError(`Transaction sending is interrupted`);
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
const nonce = await this.nonceManager.consume({
|
|
205
|
-
client: this.client,
|
|
206
|
-
address: account,
|
|
207
|
-
chainId: this.client.chain.id,
|
|
208
|
-
});
|
|
270
|
+
const now = await this.checkInterruptedOrTimedOut(gasConfig);
|
|
209
271
|
|
|
210
|
-
|
|
211
|
-
|
|
272
|
+
let txHash: Hex;
|
|
273
|
+
let nonce: number;
|
|
274
|
+
let baseState: Pick<L1TxState, 'request' | 'gasLimit' | 'blobInputs' | 'gasPrice' | 'nonce'>;
|
|
212
275
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
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();
|
|
218
292
|
}
|
|
219
293
|
|
|
220
|
-
// Send the new tx
|
|
221
|
-
const signedRequest = await this.prepareSignedTransaction(txData);
|
|
222
|
-
const txHash = await this.client.sendRawTransaction({ serializedTransaction: signedRequest });
|
|
223
|
-
|
|
224
294
|
// Create the new state for monitoring
|
|
225
295
|
const l1TxState: L1TxState = {
|
|
226
296
|
...baseState,
|
|
227
|
-
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,
|
|
228
298
|
txHashes: [txHash],
|
|
229
299
|
cancelTxHashes: [],
|
|
230
300
|
status: TxUtilsState.IDLE,
|
|
@@ -263,7 +333,7 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
263
333
|
return { txHash, state: l1TxState };
|
|
264
334
|
} catch (err: any) {
|
|
265
335
|
const viemError = formatViemError(err, request.abi);
|
|
266
|
-
this.logger.error(`Failed to send L1 transaction`, viemError, {
|
|
336
|
+
this.logger.error(`Failed to send L1 transaction: ${viemError.message}`, viemError, {
|
|
267
337
|
request: pick(request, 'to', 'value'),
|
|
268
338
|
});
|
|
269
339
|
throw viemError;
|
|
@@ -403,7 +473,6 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
403
473
|
{ nonce, account, pendingNonce, timePassed },
|
|
404
474
|
);
|
|
405
475
|
await this.updateState(state, TxUtilsState.NOT_MINED);
|
|
406
|
-
this.nonceManager.reset({ address: account, chainId: this.client.chain.id });
|
|
407
476
|
throw new DroppedTransactionError(nonce, account);
|
|
408
477
|
}
|
|
409
478
|
|
|
@@ -495,12 +564,7 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
495
564
|
|
|
496
565
|
// Oh no, the transaction has timed out!
|
|
497
566
|
if (isCancelTx || !gasConfig.cancelTxOnTimeout) {
|
|
498
|
-
// If this was already a cancellation tx, or we are configured to not cancel txs, we just mark it as NOT_MINED
|
|
499
|
-
// and reset the nonce manager, so the next tx that comes along can reuse the nonce if/when this tx gets dropped.
|
|
500
|
-
// This is the nastiest scenario for us, since the new tx could acquire the next nonce, but then this tx is dropped,
|
|
501
|
-
// and the new tx would never get mined. Eventually, the new tx would also drop.
|
|
502
567
|
await this.updateState(state, TxUtilsState.NOT_MINED);
|
|
503
|
-
this.nonceManager.reset({ address: account, chainId: this.client.chain.id });
|
|
504
568
|
} else {
|
|
505
569
|
// Otherwise we fire the cancellation without awaiting to avoid blocking the caller,
|
|
506
570
|
// and monitor it in the background so we can speed it up as needed.
|
|
@@ -611,12 +675,12 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
611
675
|
from: request.from ?? this.getSenderAddress().toString(),
|
|
612
676
|
maxFeePerGas: gasPrice.maxFeePerGas,
|
|
613
677
|
maxPriorityFeePerGas: gasPrice.maxPriorityFeePerGas,
|
|
614
|
-
gas: request.gas ??
|
|
678
|
+
gas: request.gas ?? MAX_L1_TX_LIMIT,
|
|
615
679
|
};
|
|
616
680
|
|
|
617
681
|
if (!request.gas && !gasConfig.ignoreBlockGasLimit) {
|
|
618
|
-
//
|
|
619
|
-
blockOverrides.gasLimit =
|
|
682
|
+
// MAX_L1_TX_LIMIT is set as call.gas, ensure block gasLimit is sufficient
|
|
683
|
+
blockOverrides.gasLimit = MAX_L1_TX_LIMIT;
|
|
620
684
|
}
|
|
621
685
|
|
|
622
686
|
return this._simulate(call, blockOverrides, stateOverrides, gasConfig, abi);
|
|
@@ -639,7 +703,6 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
639
703
|
{ nonce, account },
|
|
640
704
|
);
|
|
641
705
|
await this.updateState(state, TxUtilsState.NOT_MINED);
|
|
642
|
-
this.nonceManager.reset({ address: account, chainId: this.client.chain.id });
|
|
643
706
|
return;
|
|
644
707
|
}
|
|
645
708
|
|
|
@@ -651,7 +714,6 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
651
714
|
{ nonce, account, currentNonce },
|
|
652
715
|
);
|
|
653
716
|
await this.updateState(state, TxUtilsState.NOT_MINED);
|
|
654
|
-
this.nonceManager.reset({ address: account, chainId: this.client.chain.id });
|
|
655
717
|
return;
|
|
656
718
|
}
|
|
657
719
|
|
|
@@ -711,8 +773,17 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
711
773
|
return Number(timestamp) * 1000;
|
|
712
774
|
}
|
|
713
775
|
|
|
714
|
-
/** Makes empty blob inputs for the cancellation tx.
|
|
715
|
-
protected makeEmptyBlobInputs(
|
|
716
|
-
|
|
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);
|
|
717
788
|
}
|
|
718
789
|
}
|