@aztec-labs/ethereum 6.0.0-rc.3 → 6.0.0
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/blob_tx.d.ts +24 -0
- package/dest/blob_tx.d.ts.map +1 -0
- package/dest/blob_tx.js +94 -0
- package/dest/bn254/hash_to_point.d.ts +32 -0
- package/dest/bn254/hash_to_point.d.ts.map +1 -0
- package/dest/bn254/hash_to_point.js +80 -0
- package/dest/bn254/index.d.ts +3 -0
- package/dest/bn254/index.d.ts.map +1 -0
- package/dest/bn254/index.js +2 -0
- package/dest/bn254/proof_of_possession_gas.d.ts +29 -0
- package/dest/bn254/proof_of_possession_gas.d.ts.map +1 -0
- package/dest/bn254/proof_of_possession_gas.js +24 -0
- package/dest/client.d.ts +1 -1
- package/dest/client.d.ts.map +1 -1
- package/dest/client.js +5 -3
- package/dest/contracts/errors.d.ts +10 -3
- package/dest/contracts/errors.d.ts.map +1 -1
- package/dest/contracts/errors.js +10 -4
- package/dest/contracts/inbox.d.ts +1 -1
- package/dest/contracts/inbox.d.ts.map +1 -1
- package/dest/contracts/inbox.js +2 -0
- package/dest/contracts/log.d.ts +7 -1
- package/dest/contracts/log.d.ts.map +1 -1
- package/dest/contracts/log.js +6 -0
- package/dest/contracts/rollup.d.ts +32 -4
- package/dest/contracts/rollup.d.ts.map +1 -1
- package/dest/contracts/rollup.js +63 -7
- package/dest/deploy_aztec_l1_contracts.d.ts +16 -1
- package/dest/deploy_aztec_l1_contracts.d.ts.map +1 -1
- package/dest/deploy_aztec_l1_contracts.js +201 -65
- package/dest/foundry_binary.d.ts +1 -1
- package/dest/foundry_binary.d.ts.map +1 -1
- package/dest/foundry_binary.js +2 -1
- package/dest/l1_tx_utils/amsterdam.d.ts +1 -1
- package/dest/l1_tx_utils/amsterdam.d.ts.map +1 -1
- package/dest/l1_tx_utils/amsterdam.js +4 -1
- package/dest/l1_tx_utils/constants.d.ts +2 -1
- package/dest/l1_tx_utils/constants.d.ts.map +1 -1
- package/dest/l1_tx_utils/constants.js +3 -0
- package/dest/l1_tx_utils/fee-strategies/p75_competitive.d.ts +1 -1
- package/dest/l1_tx_utils/fee-strategies/p75_competitive.d.ts.map +1 -1
- package/dest/l1_tx_utils/fee-strategies/p75_competitive.js +6 -1
- package/dest/l1_tx_utils/index.d.ts +2 -1
- package/dest/l1_tx_utils/index.d.ts.map +1 -1
- package/dest/l1_tx_utils/index.js +1 -0
- package/dest/l1_tx_utils/l1_tx_utils.d.ts +21 -1
- package/dest/l1_tx_utils/l1_tx_utils.d.ts.map +1 -1
- package/dest/l1_tx_utils/l1_tx_utils.js +71 -5
- package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts +8 -1
- package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts.map +1 -1
- package/dest/l1_tx_utils/readonly_l1_tx_utils.js +1 -1
- package/dest/l1_tx_utils/send_cost.d.ts +15 -0
- package/dest/l1_tx_utils/send_cost.d.ts.map +1 -0
- package/dest/l1_tx_utils/send_cost.js +10 -0
- package/dest/l1_tx_utils/signer.d.ts +2 -2
- package/dest/l1_tx_utils/signer.d.ts.map +1 -1
- package/dest/l1_tx_utils/signer.js +2 -2
- package/dest/l1_tx_utils/tx_delayer.d.ts +1 -1
- package/dest/l1_tx_utils/tx_delayer.d.ts.map +1 -1
- package/dest/l1_tx_utils/tx_delayer.js +8 -26
- package/dest/publisher_manager.d.ts +127 -13
- package/dest/publisher_manager.d.ts.map +1 -1
- package/dest/publisher_manager.js +320 -79
- package/dest/test/anvil_hardfork.d.ts +42 -0
- package/dest/test/anvil_hardfork.d.ts.map +1 -0
- package/dest/test/anvil_hardfork.js +107 -0
- package/dest/test/eth_cheat_codes.d.ts +30 -5
- package/dest/test/eth_cheat_codes.d.ts.map +1 -1
- package/dest/test/eth_cheat_codes.js +283 -101
- package/dest/test/index.d.ts +3 -1
- package/dest/test/index.d.ts.map +1 -1
- package/dest/test/index.js +2 -0
- package/dest/test/l1_hardfork.d.ts +43 -0
- package/dest/test/l1_hardfork.d.ts.map +1 -0
- package/dest/test/l1_hardfork.js +51 -0
- package/dest/test/recording_rpc_server.d.ts +1 -1
- package/dest/test/recording_rpc_server.d.ts.map +1 -1
- package/dest/test/recording_rpc_server.js +1 -0
- package/dest/test/rollup_cheat_codes.d.ts +1 -1
- package/dest/test/rollup_cheat_codes.d.ts.map +1 -1
- package/dest/test/rollup_cheat_codes.js +7 -7
- package/dest/test/start_anvil.d.ts +14 -2
- package/dest/test/start_anvil.d.ts.map +1 -1
- package/dest/test/start_anvil.js +28 -11
- package/package.json +13 -11
- package/src/blob_tx.ts +118 -0
- package/src/bn254/hash_to_point.ts +95 -0
- package/src/bn254/index.ts +2 -0
- package/src/bn254/proof_of_possession_gas.ts +54 -0
- package/src/client.ts +6 -3
- package/src/contracts/errors.ts +12 -4
- package/src/contracts/inbox.ts +4 -0
- package/src/contracts/log.ts +12 -0
- package/src/contracts/rollup.ts +63 -6
- package/src/deploy_aztec_l1_contracts.ts +238 -63
- package/src/foundry_binary.ts +2 -1
- package/src/l1_tx_utils/amsterdam.ts +4 -1
- package/src/l1_tx_utils/constants.ts +4 -0
- package/src/l1_tx_utils/fee-strategies/p75_competitive.ts +11 -1
- package/src/l1_tx_utils/index.ts +1 -0
- package/src/l1_tx_utils/l1_tx_utils.ts +72 -5
- package/src/l1_tx_utils/readonly_l1_tx_utils.ts +1 -1
- package/src/l1_tx_utils/send_cost.ts +21 -0
- package/src/l1_tx_utils/signer.ts +3 -2
- package/src/l1_tx_utils/tx_delayer.ts +8 -37
- package/src/publisher_manager.ts +458 -83
- package/src/test/anvil_hardfork.ts +95 -0
- package/src/test/eth_cheat_codes.ts +306 -81
- package/src/test/fixtures/sepolia_blob_tx.json +10 -0
- package/src/test/index.ts +2 -0
- package/src/test/l1_hardfork.ts +71 -0
- package/src/test/recording_rpc_server.ts +1 -0
- package/src/test/rollup_cheat_codes.ts +9 -9
- package/src/test/start_anvil.ts +41 -13
|
@@ -2,6 +2,12 @@ import { EthAddress } from '@aztec-labs/foundation/eth-address';
|
|
|
2
2
|
import type { DateProvider, TestDateProvider } from '@aztec-labs/foundation/timer';
|
|
3
3
|
import { type Chain, type Hex, type Transaction } from 'viem';
|
|
4
4
|
import type { ViemPublicClient } from '../types.js';
|
|
5
|
+
/**
|
|
6
|
+
* Cancels any pending interval-mining resume and forgets the pause state, if they belong to the anvil listening on
|
|
7
|
+
* `port`. Called when that anvil is stopped, so no timer outlives it and the next anvil starts clean. Stopping any other
|
|
8
|
+
* anvil, such as a throwaway one a test starts next to its main one, leaves the state alone.
|
|
9
|
+
*/
|
|
10
|
+
export declare function resetAnvilMiningState(port: number): void;
|
|
5
11
|
/**
|
|
6
12
|
* A class that provides utility functions for interacting with ethereum (L1).
|
|
7
13
|
*/
|
|
@@ -80,6 +86,7 @@ export declare class EthCheatCodes {
|
|
|
80
86
|
* Mines a single block with evm_mine
|
|
81
87
|
*/
|
|
82
88
|
evmMine(): Promise<void>;
|
|
89
|
+
private doEvmMine;
|
|
83
90
|
/**
|
|
84
91
|
* Set the balance of an account
|
|
85
92
|
* @param account - The account to set the balance for
|
|
@@ -98,17 +105,20 @@ export declare class EthCheatCodes {
|
|
|
98
105
|
*/
|
|
99
106
|
setNextBlockBaseFeePerGas(baseFee: bigint | number): Promise<void>;
|
|
100
107
|
/**
|
|
101
|
-
* Get interval mining if set.
|
|
102
|
-
*
|
|
108
|
+
* Get interval mining if set. A pending resume left by {@link execWithPausedAnvil} counts as set, although anvil
|
|
109
|
+
* itself reports interval mining as off until the resume fires.
|
|
103
110
|
*/
|
|
104
111
|
getIntervalMining(): Promise<number | null>;
|
|
112
|
+
private doGetIntervalMining;
|
|
105
113
|
/**
|
|
106
|
-
* Enable interval mining at the given interval (block time)
|
|
114
|
+
* Enable interval mining at the given interval (block time). Replaces any pending resume left by
|
|
115
|
+
* {@link execWithPausedAnvil}.
|
|
107
116
|
* @param seconds - The interval to use between blocks
|
|
108
117
|
*/
|
|
109
118
|
setIntervalMining(seconds: number, opts?: {
|
|
110
119
|
silent?: boolean;
|
|
111
120
|
}): Promise<void>;
|
|
121
|
+
private doSetIntervalMining;
|
|
112
122
|
/**
|
|
113
123
|
* Starts interval mining from a freshly mined block and syncs the date provider to the block timestamp.
|
|
114
124
|
*/
|
|
@@ -120,13 +130,16 @@ export declare class EthCheatCodes {
|
|
|
120
130
|
setAutomine(automine: boolean, opts?: {
|
|
121
131
|
silent?: boolean;
|
|
122
132
|
}): Promise<void>;
|
|
133
|
+
private doSetAutomine;
|
|
123
134
|
/**
|
|
124
135
|
* Drop a transaction from the mempool
|
|
125
136
|
* @param txHash - The transaction hash
|
|
126
137
|
*/
|
|
127
138
|
dropTransaction(txHash: Hex): Promise<void>;
|
|
128
139
|
/**
|
|
129
|
-
* Set the next block timestamp
|
|
140
|
+
* Set the next block timestamp. A resume on the block grid after {@link execWithPausedAnvil} would overwrite it, so
|
|
141
|
+
* interval mining is instead restarted straight away: now if a resume is pending, or when the current pause ends if
|
|
142
|
+
* no block mined during the pause has used the timestamp.
|
|
130
143
|
* @param timestamp - The timestamp to set the next block to
|
|
131
144
|
*/
|
|
132
145
|
setNextBlockTimestamp(timestamp: number | Date): Promise<void>;
|
|
@@ -253,12 +266,24 @@ export declare class EthCheatCodes {
|
|
|
253
266
|
getBlockGasLimit(): Promise<bigint>;
|
|
254
267
|
/** Sets the block gas limit applied to subsequently mined L1 blocks. */
|
|
255
268
|
setBlockGasLimit(gasLimit: bigint): Promise<void>;
|
|
269
|
+
/**
|
|
270
|
+
* Runs `fn` with automine and interval mining off, so no block is mined while it runs. Called while another pause is
|
|
271
|
+
* in progress, it just runs `fn` and leaves the mining mode to that pause.
|
|
272
|
+
*
|
|
273
|
+
* Automine comes back straight away. Interval mining comes back in the background, on the grid the chain was
|
|
274
|
+
* already on (see {@link scheduleResume}), so the caller never waits for an L1 tick.
|
|
275
|
+
*/
|
|
256
276
|
execWithPausedAnvil<T>(fn: () => Promise<T>): Promise<T>;
|
|
257
277
|
syncDateProvider(): Promise<void>;
|
|
278
|
+
private withMiningLock;
|
|
279
|
+
private pauseMining;
|
|
280
|
+
private restoreMining;
|
|
281
|
+
private scheduleResume;
|
|
282
|
+
private resumeOnGrid;
|
|
258
283
|
}
|
|
259
284
|
type TxPoolState = 'pending' | 'queued';
|
|
260
285
|
export type TxPoolTransaction = Transaction & {
|
|
261
286
|
poolState: TxPoolState;
|
|
262
287
|
};
|
|
263
288
|
export {};
|
|
264
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
289
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZXRoX2NoZWF0X2NvZGVzLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvdGVzdC9ldGhfY2hlYXRfY29kZXMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBRUEsT0FBTyxFQUFFLFVBQVUsRUFBRSxNQUFNLG9DQUFvQyxDQUFDO0FBS2hFLE9BQU8sS0FBSyxFQUFFLFlBQVksRUFBRSxnQkFBZ0IsRUFBRSxNQUFNLDhCQUE4QixDQUFDO0FBRW5GLE9BQU8sRUFDTCxLQUFLLEtBQUssRUFDVixLQUFLLEdBQUcsRUFDUixLQUFLLFdBQVcsRUFNakIsTUFBTSxNQUFNLENBQUM7QUFHZCxPQUFPLEtBQUssRUFBRSxnQkFBZ0IsRUFBRSxNQUFNLGFBQWEsQ0FBQztBQXFDcEQ7Ozs7R0FJRztBQUNILHdCQUFnQixxQkFBcUIsQ0FBQyxJQUFJLEVBQUUsTUFBTSxHQUFHLElBQUksQ0FReEQ7QUFZRDs7R0FFRztBQUNILHFCQUFhLGFBQWE7SUFHdEI7O09BRUc7SUFDSSxPQUFPLEVBQUUsTUFBTSxFQUFFO0lBQ3hCOztPQUVHO0lBQ0ksWUFBWSxFQUFFLFlBQVksR0FBRyxnQkFBZ0I7SUFDcEQ7O09BRUc7SUFDSSxNQUFNO0lBQ2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
|
-
{"version":3,"file":"eth_cheat_codes.d.ts","sourceRoot":"","sources":["../../src/test/eth_cheat_codes.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,oCAAoC,CAAC;
|
|
1
|
+
{"version":3,"file":"eth_cheat_codes.d.ts","sourceRoot":"","sources":["../../src/test/eth_cheat_codes.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,oCAAoC,CAAC;AAKhE,OAAO,KAAK,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAEnF,OAAO,EACL,KAAK,KAAK,EACV,KAAK,GAAG,EACR,KAAK,WAAW,EAMjB,MAAM,MAAM,CAAC;AAGd,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAqCpD;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAQxD;AAYD;;GAEG;AACH,qBAAa,aAAa;IAGtB;;OAEG;IACI,OAAO,EAAE,MAAM,EAAE;IACxB;;OAEG;IACI,YAAY,EAAE,YAAY,GAAG,gBAAgB;IACpD;;OAEG;IACI,MAAM;IACb;;OAEG;IACI,KAAK,EAAE,KAAK;IAjBrB,SAAgB,YAAY,EAAE,gBAAgB,CAAC;IAC/C;IACE;;OAEG;IACI,OAAO,EAAE,MAAM,EAAE;IACxB;;OAEG;IACI,YAAY,EAAE,YAAY,GAAG,gBAAgB;IACpD;;OAEG;IACI,MAAM,8CAAuC;IACpD;;OAEG;IACI,KAAK,GAAE,KAAe,EAM9B;IAEM,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,gBAG3C;YAEa,SAAS;IAOvB;;;OAGG;IACU,YAAY,IAAI,OAAO,CAAC,OAAO,CAAC,CAQ5C;IAED;;;OAGG;IACU,WAAW,IAAI,OAAO,CAAC,MAAM,CAAC,CAG1C;IAED;;;OAGG;IACU,OAAO,IAAI,O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7D;IAED;;;;;;OAMG;IACU,mBAAmB,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAiBpE;IAEY,gBAAgB,kBAK5B;YAEa,cAAc;YASd,WAAW;YAmBX,aAAa;YAsCb,cAAc;YA2Bd,YAAY;CAoC3B;AAED,KAAK,WAAW,GAAG,SAAS,GAAG,QAAQ,CAAC;AAOxC,MAAM,MAAM,iBAAiB,GAAG,WAAW,GAAG;IAC5C,SAAS,EAAE,WAAW,CAAC;CACxB,CAAC"}
|
|
@@ -2,9 +2,48 @@ import { toBigIntBE, toHex } from '@aztec-labs/foundation/bigint-buffer';
|
|
|
2
2
|
import { keccak256 } from '@aztec-labs/foundation/crypto/keccak';
|
|
3
3
|
import { jsonStringify } from '@aztec-labs/foundation/json-rpc';
|
|
4
4
|
import { createLogger } from '@aztec-labs/foundation/log';
|
|
5
|
+
import { Semaphore } from '@aztec-labs/foundation/queue';
|
|
5
6
|
import { pluralize } from '@aztec-labs/foundation/string';
|
|
7
|
+
import { Buffer } from 'buffer';
|
|
6
8
|
import { createPublicClient, fallback, hexToNumber, http, numberToHex } from 'viem';
|
|
7
9
|
import { foundry } from 'viem/chains';
|
|
10
|
+
/**
|
|
11
|
+
* Mining state of the test anvil, shared by every {@link EthCheatCodes} instance in the process: e2e builds several over
|
|
12
|
+
* one anvil (the fixture's, `CheatCodes.eth`, each `RollupCheatCodes`), and a pause or pending resume started by one
|
|
13
|
+
* must be visible to the others. Assumes every mining-mode cheat code in the process targets one anvil: other anvils may
|
|
14
|
+
* be started and stopped alongside it, but not paused or switched between mining modes.
|
|
15
|
+
*/ const anvilMining = {
|
|
16
|
+
lock: new Semaphore(1),
|
|
17
|
+
generation: 0
|
|
18
|
+
};
|
|
19
|
+
/** Stops a pending resume and returns the interval it would have restored. */ function takePendingResume() {
|
|
20
|
+
const pending = anvilMining.pendingResume;
|
|
21
|
+
if (!pending) {
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
clearTimeout(pending.timer);
|
|
25
|
+
anvilMining.pendingResume = undefined;
|
|
26
|
+
return pending.interval;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Cancels any pending interval-mining resume and forgets the pause state, if they belong to the anvil listening on
|
|
30
|
+
* `port`. Called when that anvil is stopped, so no timer outlives it and the next anvil starts clean. Stopping any other
|
|
31
|
+
* anvil, such as a throwaway one a test starts next to its main one, leaves the state alone.
|
|
32
|
+
*/ export function resetAnvilMiningState(port) {
|
|
33
|
+
// The owner is kept, so the reset on the anvil's close still clears a timer armed while it was shutting down.
|
|
34
|
+
if (!anvilMining.ownerPorts?.includes(String(port))) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
takePendingResume();
|
|
38
|
+
anvilMining.paused = undefined;
|
|
39
|
+
anvilMining.generation++;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* A tick missed by at most this long, because a pause ended or the resume timer fired that much after it, is still
|
|
43
|
+
* mined straight away with its grid timestamp: the block lands up to this late rather than leaving a gap in the chain.
|
|
44
|
+
* A tick missed by more is skipped, like a missed L1 slot, and mining resumes on the next one.
|
|
45
|
+
*/ const OVERDUE_TICK_GRACE_MS = 1000;
|
|
46
|
+
/** A grid block mined at most this long after its tick restarts anvil's countdown from it; a later one does not. */ const ON_TIME_TOLERANCE_MS = 100;
|
|
8
47
|
/**
|
|
9
48
|
* A class that provides utility functions for interacting with ethereum (L1).
|
|
10
49
|
*/ export class EthCheatCodes {
|
|
@@ -96,7 +135,7 @@ import { foundry } from 'viem/chains';
|
|
|
96
135
|
* Advance the chain by a number of blocks
|
|
97
136
|
* @param numberOfBlocks - The number of blocks to mine
|
|
98
137
|
*/ async mine(numberOfBlocks = 1) {
|
|
99
|
-
await this.doMine(Number(numberOfBlocks));
|
|
138
|
+
await this.withMiningLock(()=>this.doMine(Number(numberOfBlocks)));
|
|
100
139
|
this.logger.warn(`Mined ${numberOfBlocks} L1 blocks`);
|
|
101
140
|
}
|
|
102
141
|
async doMine(numberOfBlocks = 1) {
|
|
@@ -111,9 +150,12 @@ import { foundry } from 'viem/chains';
|
|
|
111
150
|
/**
|
|
112
151
|
* Mines a single block with evm_mine
|
|
113
152
|
*/ async evmMine() {
|
|
153
|
+
await this.withMiningLock(()=>this.doEvmMine());
|
|
154
|
+
this.logger.warn(`Mined 1 L1 block with evm_mine`);
|
|
155
|
+
}
|
|
156
|
+
async doEvmMine() {
|
|
114
157
|
try {
|
|
115
158
|
await this.doRpcCall('evm_mine', []);
|
|
116
|
-
this.logger.warn(`Mined 1 L1 block with evm_mine`);
|
|
117
159
|
} catch (err) {
|
|
118
160
|
throw new Error(`Error mining: ${err}`);
|
|
119
161
|
}
|
|
@@ -167,19 +209,32 @@ import { foundry } from 'viem/chains';
|
|
|
167
209
|
this.logger.warn(`Set L1 next block base fee per gas to ${baseFee}`);
|
|
168
210
|
}
|
|
169
211
|
/**
|
|
170
|
-
* Get interval mining if set.
|
|
171
|
-
*
|
|
172
|
-
*/ getIntervalMining() {
|
|
212
|
+
* Get interval mining if set. A pending resume left by {@link execWithPausedAnvil} counts as set, although anvil
|
|
213
|
+
* itself reports interval mining as off until the resume fires.
|
|
214
|
+
*/ async getIntervalMining() {
|
|
215
|
+
return await this.withMiningLock(async ()=>anvilMining.pendingResume?.interval ?? await this.doGetIntervalMining());
|
|
216
|
+
}
|
|
217
|
+
async doGetIntervalMining() {
|
|
173
218
|
try {
|
|
174
|
-
return this.doRpcCall('anvil_getIntervalMining', []);
|
|
219
|
+
return await this.doRpcCall('anvil_getIntervalMining', []);
|
|
175
220
|
} catch (err) {
|
|
176
221
|
throw new Error(`Error getting interval mining: ${err}`);
|
|
177
222
|
}
|
|
178
223
|
}
|
|
179
224
|
/**
|
|
180
|
-
* Enable interval mining at the given interval (block time)
|
|
225
|
+
* Enable interval mining at the given interval (block time). Replaces any pending resume left by
|
|
226
|
+
* {@link execWithPausedAnvil}.
|
|
181
227
|
* @param seconds - The interval to use between blocks
|
|
182
228
|
*/ async setIntervalMining(seconds, opts = {}) {
|
|
229
|
+
await this.withMiningLock(async ()=>{
|
|
230
|
+
takePendingResume();
|
|
231
|
+
await this.doSetIntervalMining(seconds);
|
|
232
|
+
});
|
|
233
|
+
if (!opts.silent) {
|
|
234
|
+
this.logger.warn(`Set L1 interval mining to ${seconds} seconds`);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
async doSetIntervalMining(seconds) {
|
|
183
238
|
try {
|
|
184
239
|
await this.rpcCall('anvil_setIntervalMining', [
|
|
185
240
|
seconds
|
|
@@ -187,9 +242,6 @@ import { foundry } from 'viem/chains';
|
|
|
187
242
|
} catch (err) {
|
|
188
243
|
throw new Error(`Error setting interval mining: ${err}`);
|
|
189
244
|
}
|
|
190
|
-
if (!opts.silent) {
|
|
191
|
-
this.logger.warn(`Set L1 interval mining to ${seconds} seconds`);
|
|
192
|
-
}
|
|
193
245
|
}
|
|
194
246
|
/**
|
|
195
247
|
* Starts interval mining from a freshly mined block and syncs the date provider to the block timestamp.
|
|
@@ -197,19 +249,26 @@ import { foundry } from 'viem/chains';
|
|
|
197
249
|
if (seconds <= 0) {
|
|
198
250
|
throw new Error(`Interval mining requires a positive interval, got ${seconds}`);
|
|
199
251
|
}
|
|
200
|
-
await this.
|
|
201
|
-
|
|
202
|
-
|
|
252
|
+
await this.withMiningLock(async ()=>{
|
|
253
|
+
takePendingResume();
|
|
254
|
+
await this.doSetAutomine(false);
|
|
255
|
+
await this.doSetIntervalMining(0);
|
|
256
|
+
await this.doEvmMine();
|
|
257
|
+
await this.syncDateProvider();
|
|
258
|
+
await this.doSetIntervalMining(seconds);
|
|
203
259
|
});
|
|
204
|
-
await this.evmMine();
|
|
205
|
-
await this.syncDateProvider();
|
|
206
|
-
await this.setIntervalMining(seconds);
|
|
207
260
|
this.logger.warn(`Started L1 interval mining at ${seconds} seconds from a fresh block`);
|
|
208
261
|
}
|
|
209
262
|
/**
|
|
210
263
|
* Set the automine status of the underlying anvil chain
|
|
211
264
|
* @param automine - The automine status to set
|
|
212
265
|
*/ async setAutomine(automine, opts = {}) {
|
|
266
|
+
await this.withMiningLock(()=>this.doSetAutomine(automine));
|
|
267
|
+
if (!opts.silent) {
|
|
268
|
+
this.logger.warn(`Set L1 automine to ${automine}`);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
async doSetAutomine(automine) {
|
|
213
272
|
try {
|
|
214
273
|
await this.rpcCall('anvil_setAutomine', [
|
|
215
274
|
automine
|
|
@@ -217,9 +276,6 @@ import { foundry } from 'viem/chains';
|
|
|
217
276
|
} catch (err) {
|
|
218
277
|
throw new Error(`Error setting automine: ${err}`);
|
|
219
278
|
}
|
|
220
|
-
if (!opts.silent) {
|
|
221
|
-
this.logger.warn(`Set L1 automine to ${automine}`);
|
|
222
|
-
}
|
|
223
279
|
}
|
|
224
280
|
/**
|
|
225
281
|
* Drop a transaction from the mempool
|
|
@@ -235,16 +291,28 @@ import { foundry } from 'viem/chains';
|
|
|
235
291
|
this.logger.warn(`Dropped transaction ${txHash}`);
|
|
236
292
|
}
|
|
237
293
|
/**
|
|
238
|
-
* Set the next block timestamp
|
|
294
|
+
* Set the next block timestamp. A resume on the block grid after {@link execWithPausedAnvil} would overwrite it, so
|
|
295
|
+
* interval mining is instead restarted straight away: now if a resume is pending, or when the current pause ends if
|
|
296
|
+
* no block mined during the pause has used the timestamp.
|
|
239
297
|
* @param timestamp - The timestamp to set the next block to
|
|
240
298
|
*/ async setNextBlockTimestamp(timestamp) {
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
299
|
+
const seconds = timestamp instanceof Date ? Math.floor(timestamp.getTime() / 1000) : timestamp;
|
|
300
|
+
await this.withMiningLock(async ()=>{
|
|
301
|
+
const pendingInterval = takePendingResume();
|
|
302
|
+
if (pendingInterval !== undefined) {
|
|
303
|
+
await this.doSetIntervalMining(pendingInterval);
|
|
304
|
+
}
|
|
305
|
+
if (anvilMining.paused) {
|
|
306
|
+
anvilMining.paused.nextTimestamp = seconds;
|
|
307
|
+
}
|
|
308
|
+
try {
|
|
309
|
+
await this.rpcCall('evm_setNextBlockTimestamp', [
|
|
310
|
+
seconds
|
|
311
|
+
]);
|
|
312
|
+
} catch (err) {
|
|
313
|
+
throw new Error(`Error setting next block timestamp: ${err.message}`);
|
|
314
|
+
}
|
|
315
|
+
});
|
|
248
316
|
this.logger.warn(`Set L1 next block timestamp to ${timestamp}`);
|
|
249
317
|
}
|
|
250
318
|
/**
|
|
@@ -253,37 +321,36 @@ import { foundry } from 'viem/chains';
|
|
|
253
321
|
* Always updates the injected date provider to follow L1 time.
|
|
254
322
|
* @param timestamp - The timestamp to set the next block to
|
|
255
323
|
*/ async warp(timestamp, opts = {}) {
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
if (
|
|
262
|
-
await this.
|
|
263
|
-
|
|
264
|
-
|
|
324
|
+
await this.withMiningLock(async ()=>{
|
|
325
|
+
let blockInterval = null;
|
|
326
|
+
try {
|
|
327
|
+
// Load current block interval and disable it. A pending resume would put mining back on the grid from
|
|
328
|
+
// before the warp, so take it over: the warp re-phases the grid onto its own timestamp.
|
|
329
|
+
if (opts.resetBlockInterval) {
|
|
330
|
+
blockInterval = takePendingResume() ?? await this.doGetIntervalMining();
|
|
331
|
+
if (blockInterval !== null) {
|
|
332
|
+
await this.doSetIntervalMining(0);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
// Set the timestamp of the next block to be mined
|
|
336
|
+
await this.rpcCall('evm_setNextBlockTimestamp', [
|
|
337
|
+
Number(timestamp)
|
|
338
|
+
]);
|
|
339
|
+
// And mine a block so the timestamp goes into effect now
|
|
340
|
+
await this.doMine();
|
|
341
|
+
// Update the injected date provider so it follows L1 time
|
|
342
|
+
if ('setTime' in this.dateProvider) {
|
|
343
|
+
this.dateProvider.setTime(Number(timestamp) * 1000);
|
|
344
|
+
}
|
|
345
|
+
} catch (err) {
|
|
346
|
+
throw new Error(`Error warping: ${err}`);
|
|
347
|
+
} finally{
|
|
348
|
+
// Restore interval mining so the next block is mined in `blockInterval` seconds from this one
|
|
349
|
+
if (opts.resetBlockInterval && blockInterval !== null && blockInterval > 0) {
|
|
350
|
+
await this.doSetIntervalMining(blockInterval);
|
|
265
351
|
}
|
|
266
352
|
}
|
|
267
|
-
|
|
268
|
-
await this.rpcCall('evm_setNextBlockTimestamp', [
|
|
269
|
-
Number(timestamp)
|
|
270
|
-
]);
|
|
271
|
-
// And mine a block so the timestamp goes into effect now
|
|
272
|
-
await this.doMine();
|
|
273
|
-
// Update the injected date provider so it follows L1 time
|
|
274
|
-
if ('setTime' in this.dateProvider) {
|
|
275
|
-
this.dateProvider.setTime(Number(timestamp) * 1000);
|
|
276
|
-
}
|
|
277
|
-
} catch (err) {
|
|
278
|
-
throw new Error(`Error warping: ${err}`);
|
|
279
|
-
} finally{
|
|
280
|
-
// Restore interval mining so the next block is mined in `blockInterval` seconds from this one
|
|
281
|
-
if (opts.resetBlockInterval && blockInterval !== null && blockInterval > 0) {
|
|
282
|
-
await this.setIntervalMining(blockInterval, {
|
|
283
|
-
silent: true
|
|
284
|
-
});
|
|
285
|
-
}
|
|
286
|
-
}
|
|
353
|
+
});
|
|
287
354
|
if (!opts.silent) {
|
|
288
355
|
this.logger.warn(`Warped L1 timestamp to ${timestamp}`);
|
|
289
356
|
}
|
|
@@ -445,19 +512,19 @@ import { foundry } from 'viem/chains';
|
|
|
445
512
|
*/ async reorgWithReplacement(depth, newBlocks = []) {
|
|
446
513
|
this.logger.verbose(`Preparing L1 reorg with depth ${depth}`);
|
|
447
514
|
try {
|
|
448
|
-
await this.rpcCall('anvil_reorg', [
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
515
|
+
await this.withMiningLock(()=>this.rpcCall('anvil_reorg', [
|
|
516
|
+
depth,
|
|
517
|
+
newBlocks.flatMap((txs, index)=>txs.map((tx)=>[
|
|
518
|
+
typeof tx === 'string' ? tx : {
|
|
519
|
+
value: 0,
|
|
520
|
+
...tx,
|
|
521
|
+
...tx.gas === undefined ? {} : {
|
|
522
|
+
gas: numberToHex(tx.gas)
|
|
523
|
+
}
|
|
524
|
+
},
|
|
525
|
+
index
|
|
526
|
+
]))
|
|
527
|
+
]));
|
|
461
528
|
} catch (err) {
|
|
462
529
|
throw new Error(`Error reorging: ${err}`);
|
|
463
530
|
}
|
|
@@ -549,50 +616,165 @@ import { foundry } from 'viem/chains';
|
|
|
549
616
|
toHex(gasLimit)
|
|
550
617
|
]);
|
|
551
618
|
}
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
}
|
|
563
|
-
if (wasAutoMining) {
|
|
564
|
-
await this.setAutomine(false, {
|
|
565
|
-
silent: true
|
|
566
|
-
});
|
|
619
|
+
/**
|
|
620
|
+
* Runs `fn` with automine and interval mining off, so no block is mined while it runs. Called while another pause is
|
|
621
|
+
* in progress, it just runs `fn` and leaves the mining mode to that pause.
|
|
622
|
+
*
|
|
623
|
+
* Automine comes back straight away. Interval mining comes back in the background, on the grid the chain was
|
|
624
|
+
* already on (see {@link scheduleResume}), so the caller never waits for an L1 tick.
|
|
625
|
+
*/ async execWithPausedAnvil(fn) {
|
|
626
|
+
const ownsPause = await this.withMiningLock(async ()=>{
|
|
627
|
+
if (anvilMining.paused) {
|
|
628
|
+
return false;
|
|
567
629
|
}
|
|
630
|
+
await this.pauseMining();
|
|
631
|
+
return true;
|
|
632
|
+
});
|
|
633
|
+
if (!ownsPause) {
|
|
634
|
+
return await fn();
|
|
635
|
+
}
|
|
636
|
+
try {
|
|
568
637
|
return await fn();
|
|
569
638
|
} finally{
|
|
639
|
+
await this.withMiningLock(()=>this.restoreMining());
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
async syncDateProvider() {
|
|
643
|
+
const timestamp = await this.lastBlockTimestamp();
|
|
644
|
+
if ('setTime' in this.dateProvider) {
|
|
645
|
+
this.dateProvider.setTime(timestamp * 1000);
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
async withMiningLock(fn) {
|
|
649
|
+
await anvilMining.lock.acquire();
|
|
650
|
+
try {
|
|
651
|
+
return await fn();
|
|
652
|
+
} finally{
|
|
653
|
+
anvilMining.lock.release();
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
async pauseMining() {
|
|
657
|
+
// A resume still pending from an earlier pause is taken over: anvil reports interval mining as off meanwhile.
|
|
658
|
+
const interval = takePendingResume() ?? await this.doGetIntervalMining();
|
|
659
|
+
const paused = {
|
|
660
|
+
interval,
|
|
661
|
+
automine: await this.isAutoMining()
|
|
662
|
+
};
|
|
663
|
+
anvilMining.paused = paused;
|
|
664
|
+
anvilMining.ownerPorts = this.rpcUrls.map((url)=>new URL(url).port);
|
|
665
|
+
try {
|
|
666
|
+
if (interval !== null) {
|
|
667
|
+
await this.doSetIntervalMining(0);
|
|
668
|
+
}
|
|
669
|
+
if (paused.automine) {
|
|
670
|
+
await this.doSetAutomine(false);
|
|
671
|
+
}
|
|
672
|
+
} catch (err) {
|
|
673
|
+
await this.restoreMining();
|
|
674
|
+
throw err;
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
async restoreMining() {
|
|
678
|
+
const saved = anvilMining.paused;
|
|
679
|
+
anvilMining.paused = undefined;
|
|
680
|
+
if (saved?.automine) {
|
|
570
681
|
try {
|
|
571
|
-
|
|
572
|
-
if (wasAutoMining) {
|
|
573
|
-
await this.setAutomine(true, {
|
|
574
|
-
silent: true
|
|
575
|
-
});
|
|
576
|
-
}
|
|
682
|
+
await this.doSetAutomine(true);
|
|
577
683
|
} catch (err) {
|
|
578
684
|
this.logger.warn(`Failed to reenable automining: ${err}`);
|
|
579
685
|
}
|
|
686
|
+
}
|
|
687
|
+
if (saved?.interval) {
|
|
580
688
|
try {
|
|
581
|
-
|
|
582
|
-
if (blockInterval !== null) {
|
|
583
|
-
await this.setIntervalMining(blockInterval, {
|
|
584
|
-
silent: true
|
|
585
|
-
});
|
|
586
|
-
}
|
|
689
|
+
await this.scheduleResume(saved.interval, saved.nextTimestamp);
|
|
587
690
|
} catch (err) {
|
|
588
|
-
this.logger.warn(`Failed to
|
|
691
|
+
this.logger.warn(`Failed to schedule interval mining on the block grid, restarting it now: ${err}`);
|
|
692
|
+
try {
|
|
693
|
+
await this.doSetIntervalMining(saved.interval);
|
|
694
|
+
} catch (err) {
|
|
695
|
+
this.logger.warn(`Failed to reenable interval mining: ${err}`);
|
|
696
|
+
}
|
|
589
697
|
}
|
|
590
698
|
}
|
|
591
699
|
}
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
700
|
+
/**
|
|
701
|
+
* Re-enables interval mining so the next block lands on the grid the chain is already on: the first
|
|
702
|
+
* `latest + k * interval` tick the node clock has not yet passed. Anvil restarts its countdown from zero on
|
|
703
|
+
* `anvil_setIntervalMining`, so re-enabling it right after a pause would mine the next block late while still
|
|
704
|
+
* stamping it `latest + interval`, leaving L1 time behind the node clock for good. Instead mining stays off until
|
|
705
|
+
* that tick, when a background timer mines the tick's block and restarts the countdown from it.
|
|
706
|
+
*
|
|
707
|
+
* A tick the pause ran past by up to {@link OVERDUE_TICK_GRACE_MS} is mined straight away; one missed by more is
|
|
708
|
+
* skipped, so the lag stays bounded, at the cost of a gap in the chain like a missed L1 slot. Must be called holding
|
|
709
|
+
* the mining lock.
|
|
710
|
+
*
|
|
711
|
+
* @param nextTimestamp - A next-block timestamp a caller set during the pause. Unless a block has already used it, it
|
|
712
|
+
* is kept: interval mining restarts straight away instead, so the resume does not overwrite it.
|
|
713
|
+
*/ async scheduleResume(interval, nextTimestamp) {
|
|
714
|
+
const generation = anvilMining.generation;
|
|
715
|
+
const latest = await this.lastBlockTimestamp();
|
|
716
|
+
if (anvilMining.generation !== generation) {
|
|
717
|
+
return;
|
|
718
|
+
}
|
|
719
|
+
if (nextTimestamp !== undefined && latest < nextTimestamp) {
|
|
720
|
+
await this.doSetIntervalMining(interval);
|
|
721
|
+
return;
|
|
722
|
+
}
|
|
723
|
+
const nowMs = this.dateProvider.now();
|
|
724
|
+
const ticks = Math.max(1, Math.ceil((nowMs - OVERDUE_TICK_GRACE_MS - latest * 1000) / (interval * 1000)));
|
|
725
|
+
const tick = latest + ticks * interval;
|
|
726
|
+
const delayMs = tick * 1000 - nowMs;
|
|
727
|
+
if (delayMs > interval * 1000) {
|
|
728
|
+
// The chain is ahead of the node clock (say, a warp the date provider could not follow), so no tick is due
|
|
729
|
+
// within an interval: restart the countdown now, as anvil would.
|
|
730
|
+
await this.doSetIntervalMining(interval);
|
|
731
|
+
return;
|
|
732
|
+
}
|
|
733
|
+
const resume = {
|
|
734
|
+
interval,
|
|
735
|
+
timer: setTimeout(()=>void this.resumeOnGrid(resume, latest, tick), Math.max(0, delayMs))
|
|
736
|
+
};
|
|
737
|
+
anvilMining.pendingResume = resume;
|
|
738
|
+
}
|
|
739
|
+
async resumeOnGrid(resume, latest, tick) {
|
|
740
|
+
try {
|
|
741
|
+
await this.withMiningLock(async ()=>{
|
|
742
|
+
if (anvilMining.pendingResume !== resume) {
|
|
743
|
+
return;
|
|
744
|
+
}
|
|
745
|
+
anvilMining.pendingResume = undefined;
|
|
746
|
+
try {
|
|
747
|
+
const chainMoved = await this.lastBlockTimestamp() !== latest;
|
|
748
|
+
const firedMs = this.dateProvider.now();
|
|
749
|
+
if (chainMoved || firedMs - tick * 1000 > OVERDUE_TICK_GRACE_MS) {
|
|
750
|
+
// Blocks were mined or rolled back while mining was off, so the grid may have moved; or the timer ran
|
|
751
|
+
// late (a busy event loop, a wait on the lock), and mining the old tick now would put L1 behind again.
|
|
752
|
+
await this.scheduleResume(resume.interval);
|
|
753
|
+
return;
|
|
754
|
+
}
|
|
755
|
+
await this.doRpcCall('evm_setNextBlockTimestamp', [
|
|
756
|
+
tick
|
|
757
|
+
]);
|
|
758
|
+
await this.doEvmMine();
|
|
759
|
+
if (this.dateProvider.now() - tick * 1000 > ON_TIME_TOLERANCE_MS) {
|
|
760
|
+
// The tick was mined late, so a countdown restarted now would keep every later block that late too: wait
|
|
761
|
+
// for the next tick and restart it there instead.
|
|
762
|
+
await this.scheduleResume(resume.interval);
|
|
763
|
+
return;
|
|
764
|
+
}
|
|
765
|
+
} catch (err) {
|
|
766
|
+
this.logger.warn(`Failed to mine the L1 block due at ${tick}, restarting interval mining off the grid`, {
|
|
767
|
+
err: String(err),
|
|
768
|
+
tick
|
|
769
|
+
});
|
|
770
|
+
}
|
|
771
|
+
await this.doSetIntervalMining(resume.interval);
|
|
772
|
+
});
|
|
773
|
+
} catch (err) {
|
|
774
|
+
this.logger.error(`Failed to resume L1 interval mining`, err, {
|
|
775
|
+
interval: resume.interval,
|
|
776
|
+
tick
|
|
777
|
+
});
|
|
596
778
|
}
|
|
597
779
|
}
|
|
598
780
|
}
|
package/dest/test/index.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
export * from './anvil_hardfork.js';
|
|
1
2
|
export * from './blob_kzg_warmup.js';
|
|
2
3
|
export * from './eth_cheat_codes.js';
|
|
3
4
|
export * from './eth_cheat_codes_with_state.js';
|
|
5
|
+
export * from './l1_hardfork.js';
|
|
4
6
|
export * from './start_anvil.js';
|
|
5
7
|
export * from './upgrade_utils.js';
|
|
6
8
|
export * from './chain_monitor.js';
|
|
7
9
|
export * from './rollup_cheat_codes.js';
|
|
8
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
10
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy90ZXN0L2luZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLGNBQWMscUJBQXFCLENBQUM7QUFDcEMsY0FBYyxzQkFBc0IsQ0FBQztBQUNyQyxjQUFjLHNCQUFzQixDQUFDO0FBQ3JDLGNBQWMsaUNBQWlDLENBQUM7QUFDaEQsY0FBYyxrQkFBa0IsQ0FBQztBQUNqQyxjQUFjLGtCQUFrQixDQUFDO0FBQ2pDLGNBQWMsb0JBQW9CLENBQUM7QUFDbkMsY0FBYyxvQkFBb0IsQ0FBQztBQUNuQyxjQUFjLHlCQUF5QixDQUFDIn0=
|
package/dest/test/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/test/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,iCAAiC,CAAC;AAChD,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,yBAAyB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/test/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,iCAAiC,CAAC;AAChD,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,yBAAyB,CAAC"}
|
package/dest/test/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
export * from './anvil_hardfork.js';
|
|
1
2
|
export * from './blob_kzg_warmup.js';
|
|
2
3
|
export * from './eth_cheat_codes.js';
|
|
3
4
|
export * from './eth_cheat_codes_with_state.js';
|
|
5
|
+
export * from './l1_hardfork.js';
|
|
4
6
|
export * from './start_anvil.js';
|
|
5
7
|
export * from './upgrade_utils.js';
|
|
6
8
|
export * from './chain_monitor.js';
|