@aztec/ethereum 0.0.1-commit.a072138 → 0.0.1-commit.a5db02d
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/client.d.ts +25 -3
- package/dest/client.d.ts.map +1 -1
- package/dest/client.js +60 -8
- package/dest/config.d.ts +17 -6
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +39 -11
- package/dest/contracts/chain_state_override.d.ts +78 -0
- package/dest/contracts/chain_state_override.d.ts.map +1 -0
- package/dest/contracts/chain_state_override.js +137 -0
- package/dest/contracts/fee_asset_price_oracle.d.ts +105 -0
- package/dest/contracts/fee_asset_price_oracle.d.ts.map +1 -0
- package/dest/contracts/fee_asset_price_oracle.js +656 -0
- package/dest/contracts/governance.d.ts +108 -33
- package/dest/contracts/governance.d.ts.map +1 -1
- package/dest/contracts/governance.js +196 -15
- package/dest/contracts/governance_proposer.d.ts +33 -1
- package/dest/contracts/governance_proposer.d.ts.map +1 -1
- package/dest/contracts/governance_proposer.js +53 -2
- package/dest/contracts/gse.d.ts +4 -2
- package/dest/contracts/gse.d.ts.map +1 -1
- package/dest/contracts/gse.js +2 -2
- package/dest/contracts/inbox.d.ts +3 -3
- package/dest/contracts/inbox.d.ts.map +1 -1
- package/dest/contracts/inbox.js +12 -7
- package/dest/contracts/index.d.ts +4 -3
- package/dest/contracts/index.d.ts.map +1 -1
- package/dest/contracts/index.js +3 -2
- package/dest/contracts/multicall.d.ts +127 -12
- package/dest/contracts/multicall.d.ts.map +1 -1
- package/dest/contracts/multicall.js +201 -94
- package/dest/contracts/outbox.d.ts +27 -4
- package/dest/contracts/outbox.d.ts.map +1 -1
- package/dest/contracts/outbox.js +34 -7
- package/dest/contracts/registry.d.ts +3 -1
- package/dest/contracts/registry.d.ts.map +1 -1
- package/dest/contracts/registry.js +30 -1
- package/dest/contracts/rollup.d.ts +5420 -31
- package/dest/contracts/rollup.d.ts.map +1 -1
- package/dest/contracts/rollup.js +402 -75
- package/dest/contracts/{tally_slashing_proposer.d.ts → slashing_proposer.d.ts} +3 -4
- package/dest/contracts/slashing_proposer.d.ts.map +1 -0
- package/dest/contracts/{tally_slashing_proposer.js → slashing_proposer.js} +13 -15
- package/dest/deploy_aztec_l1_contracts.d.ts +5 -9
- package/dest/deploy_aztec_l1_contracts.d.ts.map +1 -1
- package/dest/deploy_aztec_l1_contracts.js +52 -30
- package/dest/deploy_l1_contract.js +3 -3
- package/dest/foundry_binary.d.ts +13 -0
- package/dest/foundry_binary.d.ts.map +1 -0
- package/dest/foundry_binary.js +52 -0
- package/dest/generated/l1-contracts-defaults.d.ts +3 -3
- package/dest/generated/l1-contracts-defaults.js +3 -3
- package/dest/l1_artifacts.d.ts +15524 -15847
- package/dest/l1_artifacts.d.ts.map +1 -1
- package/dest/l1_artifacts.js +9 -24
- package/dest/l1_contract_addresses.d.ts +61 -65
- package/dest/l1_contract_addresses.d.ts.map +1 -1
- package/dest/l1_contract_addresses.js +101 -82
- package/dest/l1_reader.d.ts +5 -5
- package/dest/l1_reader.d.ts.map +1 -1
- package/dest/l1_reader.js +9 -7
- package/dest/l1_tx_utils/config.d.ts +7 -1
- package/dest/l1_tx_utils/config.d.ts.map +1 -1
- package/dest/l1_tx_utils/config.js +17 -4
- package/dest/l1_tx_utils/factory.d.ts +18 -10
- package/dest/l1_tx_utils/factory.d.ts.map +1 -1
- package/dest/l1_tx_utils/factory.js +17 -7
- package/dest/l1_tx_utils/fee-strategies/p75_competitive.js +1 -1
- package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.js +1 -1
- package/dest/l1_tx_utils/forwarder_l1_tx_utils.d.ts +15 -15
- package/dest/l1_tx_utils/forwarder_l1_tx_utils.d.ts.map +1 -1
- package/dest/l1_tx_utils/forwarder_l1_tx_utils.js +9 -15
- package/dest/l1_tx_utils/index-blobs.d.ts +3 -3
- package/dest/l1_tx_utils/index-blobs.d.ts.map +1 -1
- package/dest/l1_tx_utils/index-blobs.js +2 -2
- package/dest/l1_tx_utils/index.d.ts +2 -1
- package/dest/l1_tx_utils/index.d.ts.map +1 -1
- package/dest/l1_tx_utils/index.js +1 -0
- package/dest/l1_tx_utils/l1_tx_utils.d.ts +26 -7
- package/dest/l1_tx_utils/l1_tx_utils.d.ts.map +1 -1
- package/dest/l1_tx_utils/l1_tx_utils.js +152 -75
- package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts +1 -1
- package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts.map +1 -1
- package/dest/l1_tx_utils/readonly_l1_tx_utils.js +10 -5
- package/dest/l1_tx_utils/tx_delayer.d.ts +58 -0
- package/dest/l1_tx_utils/tx_delayer.d.ts.map +1 -0
- package/dest/{test → l1_tx_utils}/tx_delayer.js +67 -37
- package/dest/publisher_manager.d.ts +34 -8
- package/dest/publisher_manager.d.ts.map +1 -1
- package/dest/publisher_manager.js +119 -8
- package/dest/queries.d.ts +13 -2
- package/dest/queries.d.ts.map +1 -1
- package/dest/queries.js +62 -3
- package/dest/test/blob_kzg_warmup.d.ts +19 -0
- package/dest/test/blob_kzg_warmup.d.ts.map +1 -0
- package/dest/test/blob_kzg_warmup.js +64 -0
- package/dest/test/chain_monitor.d.ts +55 -4
- package/dest/test/chain_monitor.d.ts.map +1 -1
- package/dest/test/chain_monitor.js +104 -3
- package/dest/test/eth_cheat_codes.d.ts +31 -6
- package/dest/test/eth_cheat_codes.d.ts.map +1 -1
- package/dest/test/eth_cheat_codes.js +67 -44
- package/dest/test/index.d.ts +2 -3
- package/dest/test/index.d.ts.map +1 -1
- package/dest/test/index.js +1 -2
- package/dest/test/rollup_cheat_codes.d.ts +60 -3
- package/dest/test/rollup_cheat_codes.d.ts.map +1 -1
- package/dest/test/rollup_cheat_codes.js +86 -7
- package/dest/test/start_anvil.d.ts +23 -3
- package/dest/test/start_anvil.d.ts.map +1 -1
- package/dest/test/start_anvil.js +182 -32
- package/dest/test/upgrade_utils.js +2 -2
- package/dest/utils.d.ts +9 -2
- package/dest/utils.d.ts.map +1 -1
- package/dest/utils.js +59 -24
- package/package.json +6 -8
- package/src/client.ts +66 -2
- package/src/config.ts +59 -15
- package/src/contracts/chain_state_override.ts +200 -0
- package/src/contracts/fee_asset_price_oracle.ts +285 -0
- package/src/contracts/governance.ts +269 -12
- package/src/contracts/governance_proposer.ts +54 -1
- package/src/contracts/gse.ts +7 -2
- package/src/contracts/inbox.ts +13 -5
- package/src/contracts/index.ts +3 -2
- package/src/contracts/multicall.ts +243 -105
- package/src/contracts/outbox.ts +42 -8
- package/src/contracts/registry.ts +31 -1
- package/src/contracts/rollup.ts +453 -78
- package/src/contracts/{tally_slashing_proposer.ts → slashing_proposer.ts} +14 -16
- package/src/deploy_aztec_l1_contracts.ts +79 -39
- package/src/deploy_l1_contract.ts +3 -3
- package/src/foundry_binary.ts +57 -0
- package/src/generated/l1-contracts-defaults.ts +3 -3
- package/src/l1_artifacts.ts +12 -35
- package/src/l1_contract_addresses.ts +120 -94
- package/src/l1_reader.ts +17 -10
- package/src/l1_tx_utils/config.ts +23 -3
- package/src/l1_tx_utils/factory.ts +31 -31
- package/src/l1_tx_utils/fee-strategies/p75_competitive.ts +1 -1
- package/src/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.ts +1 -1
- package/src/l1_tx_utils/forwarder_l1_tx_utils.ts +43 -54
- package/src/l1_tx_utils/index-blobs.ts +2 -2
- package/src/l1_tx_utils/index.ts +1 -0
- package/src/l1_tx_utils/l1_tx_utils.ts +145 -60
- package/src/l1_tx_utils/readonly_l1_tx_utils.ts +10 -5
- package/src/{test → l1_tx_utils}/tx_delayer.ts +93 -56
- package/src/publisher_manager.ts +143 -12
- package/src/queries.ts +70 -4
- package/src/test/blob_kzg_warmup.ts +65 -0
- package/src/test/chain_monitor.ts +148 -3
- package/src/test/eth_cheat_codes.ts +63 -47
- package/src/test/index.ts +1 -2
- package/src/test/rollup_cheat_codes.ts +115 -6
- package/src/test/start_anvil.ts +212 -32
- package/src/test/upgrade_utils.ts +2 -2
- package/src/utils.ts +56 -29
- package/dest/contracts/empire_slashing_proposer.d.ts +0 -67
- package/dest/contracts/empire_slashing_proposer.d.ts.map +0 -1
- package/dest/contracts/empire_slashing_proposer.js +0 -207
- 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 -259
- package/src/l1_tx_utils/l1_tx_utils_with_blobs.ts +0 -77
- package/src/test/delayed_tx_utils.ts +0 -52
|
@@ -85,14 +85,26 @@ export class EthCheatCodes {
|
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
/**
|
|
88
|
-
* Get the
|
|
89
|
-
*
|
|
88
|
+
* Get the timestamp of the latest mined L1 block.
|
|
89
|
+
* Note: this is NOT the current time — it's the discrete timestamp of the last block.
|
|
90
|
+
* Between blocks, the actual chain time advances but no new block reflects it.
|
|
91
|
+
* @returns The latest block timestamp in seconds
|
|
90
92
|
*/
|
|
91
|
-
public async
|
|
93
|
+
public async lastBlockTimestamp(): Promise<number> {
|
|
92
94
|
const res = await this.doRpcCall('eth_getBlockByNumber', ['latest', true]);
|
|
93
95
|
return parseInt(res.timestamp, 16);
|
|
94
96
|
}
|
|
95
97
|
|
|
98
|
+
/**
|
|
99
|
+
* Get the timestamp of the pending L1 block — the block that anvil will mine next.
|
|
100
|
+
* Reflects any prior `setNextBlockTimestamp` call or the configured block interval.
|
|
101
|
+
* @returns The pending block timestamp in seconds.
|
|
102
|
+
*/
|
|
103
|
+
public async nextBlockTimestamp(): Promise<number> {
|
|
104
|
+
const res = await this.doRpcCall('eth_getBlockByNumber', ['pending', false]);
|
|
105
|
+
return parseInt(res.timestamp, 16);
|
|
106
|
+
}
|
|
107
|
+
|
|
96
108
|
/**
|
|
97
109
|
* Advance the chain by a number of blocks
|
|
98
110
|
* @param numberOfBlocks - The number of blocks to mine
|
|
@@ -194,6 +206,22 @@ export class EthCheatCodes {
|
|
|
194
206
|
}
|
|
195
207
|
}
|
|
196
208
|
|
|
209
|
+
/**
|
|
210
|
+
* Starts interval mining from a freshly mined block and syncs the date provider to the block timestamp.
|
|
211
|
+
*/
|
|
212
|
+
public async startIntervalMiningWithFreshBlock(seconds: number): Promise<void> {
|
|
213
|
+
if (seconds <= 0) {
|
|
214
|
+
throw new Error(`Interval mining requires a positive interval, got ${seconds}`);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
await this.setAutomine(false);
|
|
218
|
+
await this.setIntervalMining(0, { silent: true });
|
|
219
|
+
await this.evmMine();
|
|
220
|
+
await this.syncDateProvider();
|
|
221
|
+
await this.setIntervalMining(seconds);
|
|
222
|
+
this.logger.warn(`Started L1 interval mining at ${seconds} seconds from a fresh block`);
|
|
223
|
+
}
|
|
224
|
+
|
|
197
225
|
/**
|
|
198
226
|
* Set the automine status of the underlying anvil chain
|
|
199
227
|
* @param automine - The automine status to set
|
|
@@ -466,58 +494,46 @@ export class EthCheatCodes {
|
|
|
466
494
|
}
|
|
467
495
|
|
|
468
496
|
/**
|
|
469
|
-
* Mines
|
|
470
|
-
*
|
|
497
|
+
* Mines empty blocks while leaving any pending transactions untouched in the mempool.
|
|
498
|
+
*
|
|
499
|
+
* Never manipulates the mempool, so it is immune to the race that dropping and re-adding txs has against a
|
|
500
|
+
* concurrent publisher that is monitoring and re-broadcasting the same in-flight tx (with that approach the
|
|
501
|
+
* in-flight tx could reappear in the pool and be swept into the "empty" block, mining a proposal the caller
|
|
502
|
+
* expected to stay pending). Works in two steps: first the block gas limit is temporarily lowered below the
|
|
503
|
+
* intrinsic cost of any transaction (21000 gas) and the blocks are mined, so no pending tx is includable;
|
|
504
|
+
* then those blocks are reorged out and replaced with empty blocks mined at the restored gas limit. The
|
|
505
|
+
* reorg is needed because anvil applies a new gas limit only to future blocks: without it the just-mined
|
|
506
|
+
* blocks would keep the tiny gas limit, and an `eth_call` against `latest` (whose gas is capped by the
|
|
507
|
+
* block gas limit) would revert with "intrinsic gas too high".
|
|
471
508
|
*/
|
|
472
509
|
public async mineEmptyBlock(blockCount: number = 1): Promise<void> {
|
|
473
510
|
await this.execWithPausedAnvil(async () => {
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
const rawTxs: Hex[] = [];
|
|
481
|
-
for (const tx of txs) {
|
|
482
|
-
try {
|
|
483
|
-
const rawTx = await this.doRpcCall('debug_getRawTransaction', [tx.hash]);
|
|
484
|
-
if (rawTx) {
|
|
485
|
-
rawTxs.push(rawTx);
|
|
486
|
-
this.logger.debug(`Got raw tx for ${tx.hash}`);
|
|
487
|
-
} else {
|
|
488
|
-
this.logger.warn(`No raw tx found for ${tx.hash}`);
|
|
489
|
-
}
|
|
490
|
-
} catch {
|
|
491
|
-
this.logger.warn(`Failed to get raw transaction for ${tx.hash}`);
|
|
492
|
-
}
|
|
493
|
-
}
|
|
494
|
-
|
|
495
|
-
this.logger.debug(`Retrieved ${rawTxs.length} raw transactions`);
|
|
496
|
-
|
|
497
|
-
// Drop all transactions from the mempool
|
|
498
|
-
await this.doRpcCall('anvil_dropAllTransactions', []);
|
|
499
|
-
|
|
500
|
-
// Mine an empty block
|
|
501
|
-
await this.doMine(blockCount);
|
|
502
|
-
|
|
503
|
-
// Re-add the transactions to the pool
|
|
504
|
-
for (const rawTx of rawTxs) {
|
|
505
|
-
try {
|
|
506
|
-
const txHash = await this.doRpcCall('eth_sendRawTransaction', [rawTx]);
|
|
507
|
-
this.logger.debug(`Re-added transaction ${txHash}`);
|
|
508
|
-
} catch (err) {
|
|
509
|
-
this.logger.warn(`Failed to re-add transaction: ${err}`);
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
|
|
513
|
-
if (rawTxs.length !== txs.length) {
|
|
514
|
-
this.logger.warn(`Failed to add all txs back: had ${txs.length} but re-added ${rawTxs.length}`);
|
|
511
|
+
const originalGasLimit = await this.getBlockGasLimit();
|
|
512
|
+
try {
|
|
513
|
+
await this.setBlockGasLimit(1n);
|
|
514
|
+
await this.doMine(blockCount);
|
|
515
|
+
} finally {
|
|
516
|
+
await this.setBlockGasLimit(originalGasLimit);
|
|
515
517
|
}
|
|
518
|
+
// Replace the tiny-gas-limit blocks with empty blocks at the restored gas limit, keeping the same
|
|
519
|
+
// height and timestamps. The reorged-out blocks held no transactions, so nothing returns to the pool.
|
|
520
|
+
await this.doRpcCall('anvil_reorg', [blockCount, []]);
|
|
516
521
|
});
|
|
517
522
|
|
|
518
523
|
this.logger.warn(`Mined ${blockCount} empty L1 ${pluralize('block', blockCount)}`);
|
|
519
524
|
}
|
|
520
525
|
|
|
526
|
+
/** Returns the gas limit of the latest mined L1 block. */
|
|
527
|
+
public async getBlockGasLimit(): Promise<bigint> {
|
|
528
|
+
const block = await this.doRpcCall('eth_getBlockByNumber', ['latest', false]);
|
|
529
|
+
return BigInt(block.gasLimit);
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
/** Sets the block gas limit applied to subsequently mined L1 blocks. */
|
|
533
|
+
public async setBlockGasLimit(gasLimit: bigint): Promise<void> {
|
|
534
|
+
await this.doRpcCall('anvil_setBlockGasLimit', [toHex(gasLimit)]);
|
|
535
|
+
}
|
|
536
|
+
|
|
521
537
|
public async execWithPausedAnvil<T>(fn: () => Promise<T>): Promise<T> {
|
|
522
538
|
const [blockInterval, wasAutoMining] = await Promise.all([this.getIntervalMining(), this.isAutoMining()]);
|
|
523
539
|
try {
|
|
@@ -552,7 +568,7 @@ export class EthCheatCodes {
|
|
|
552
568
|
}
|
|
553
569
|
|
|
554
570
|
public async syncDateProvider() {
|
|
555
|
-
const timestamp = await this.
|
|
571
|
+
const timestamp = await this.lastBlockTimestamp();
|
|
556
572
|
if ('setTime' in this.dateProvider) {
|
|
557
573
|
this.dateProvider.setTime(timestamp * 1000);
|
|
558
574
|
}
|
package/src/test/index.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
export * from './
|
|
1
|
+
export * from './blob_kzg_warmup.js';
|
|
2
2
|
export * from './eth_cheat_codes.js';
|
|
3
3
|
export * from './eth_cheat_codes_with_state.js';
|
|
4
4
|
export * from './start_anvil.js';
|
|
5
|
-
export * from './tx_delayer.js';
|
|
6
5
|
export * from './upgrade_utils.js';
|
|
7
6
|
export * from './chain_monitor.js';
|
|
8
7
|
export * from './rollup_cheat_codes.js';
|
|
@@ -4,6 +4,7 @@ import type { ViemPublicClient } from '@aztec/ethereum/types';
|
|
|
4
4
|
import { CheckpointNumber, EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
5
5
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
6
6
|
import { createLogger } from '@aztec/foundation/log';
|
|
7
|
+
import { retryUntil } from '@aztec/foundation/retry';
|
|
7
8
|
import type { DateProvider } from '@aztec/foundation/timer';
|
|
8
9
|
import { RollupAbi } from '@aztec/l1-artifacts/RollupAbi';
|
|
9
10
|
|
|
@@ -15,6 +16,7 @@ import {
|
|
|
15
16
|
getContract,
|
|
16
17
|
hexToBigInt,
|
|
17
18
|
http,
|
|
19
|
+
keccak256,
|
|
18
20
|
} from 'viem';
|
|
19
21
|
|
|
20
22
|
import { EthCheatCodes } from './eth_cheat_codes.js';
|
|
@@ -53,7 +55,17 @@ export class RollupCheatCodes {
|
|
|
53
55
|
/** Returns the current slot */
|
|
54
56
|
public async getSlot(): Promise<SlotNumber> {
|
|
55
57
|
const ts = BigInt((await this.client.getBlock()).timestamp);
|
|
56
|
-
return
|
|
58
|
+
return this.getSlotAt(ts);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Returns the slot number at a given timestamp. */
|
|
62
|
+
public async getSlotAt(timestamp: bigint): Promise<SlotNumber> {
|
|
63
|
+
return SlotNumber.fromBigInt(await this.rollup.read.getSlotAt([timestamp]));
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Returns the timestamp for the start of a given slot. */
|
|
67
|
+
public async getTimestampForSlot(slot: SlotNumber): Promise<bigint> {
|
|
68
|
+
return await this.rollup.read.getTimestampForSlot([BigInt(slot)]);
|
|
57
69
|
}
|
|
58
70
|
|
|
59
71
|
/** Returns the number of seconds until the start of the given slot based on L1 block timestamp. */
|
|
@@ -168,6 +180,21 @@ export class RollupCheatCodes {
|
|
|
168
180
|
return [timestamp, nextSlot];
|
|
169
181
|
}
|
|
170
182
|
|
|
183
|
+
/**
|
|
184
|
+
* Warps L1 time to the start of an explicit absolute slot. Unlike `advanceSlots(N)` which is
|
|
185
|
+
* relative to the current L1 timestamp at call time and therefore races with real-time
|
|
186
|
+
* progression between query and warp, this lands at the slot regardless of latency.
|
|
187
|
+
*
|
|
188
|
+
* Throws if the requested slot is in the past relative to current L1 time (anvil cannot
|
|
189
|
+
* rewind).
|
|
190
|
+
*/
|
|
191
|
+
public async advanceToSlot(slot: SlotNumber) {
|
|
192
|
+
const timestamp = await this.rollup.read.getTimestampForSlot([BigInt(slot)]);
|
|
193
|
+
await this.ethCheatCodes.warp(Number(timestamp), { silent: true, resetBlockInterval: true });
|
|
194
|
+
this.logger.warn(`Advanced to slot ${slot}`, { timestamp });
|
|
195
|
+
return timestamp;
|
|
196
|
+
}
|
|
197
|
+
|
|
171
198
|
/**
|
|
172
199
|
* Warps time in L1 equivalent to however many slots.
|
|
173
200
|
* @param howMany - The number of slots to advance.
|
|
@@ -218,6 +245,56 @@ export class RollupCheatCodes {
|
|
|
218
245
|
});
|
|
219
246
|
}
|
|
220
247
|
|
|
248
|
+
/**
|
|
249
|
+
* Polls the rollup until its current epoch reaches `epoch`. Unlike {@link advanceToEpoch} this does
|
|
250
|
+
* not warp the L1 clock; it only waits for the chain to reach `epoch` through external activity.
|
|
251
|
+
*/
|
|
252
|
+
public async waitForEpoch(epoch: EpochNumber, opts: { timeout?: number; interval?: number } = {}): Promise<void> {
|
|
253
|
+
await retryUntil(
|
|
254
|
+
async () => (await this.getEpoch()) >= epoch || undefined,
|
|
255
|
+
`rollup epoch >= ${epoch}`,
|
|
256
|
+
opts.timeout ?? 60,
|
|
257
|
+
opts.interval ?? 1,
|
|
258
|
+
);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Polls the rollup until its current slot reaches `slot`. Unlike {@link advanceToSlot} this does not
|
|
263
|
+
* warp the L1 clock; it only waits for the chain to reach `slot` through external activity.
|
|
264
|
+
*/
|
|
265
|
+
public async waitForSlot(slot: SlotNumber, opts: { timeout?: number; interval?: number } = {}): Promise<void> {
|
|
266
|
+
await retryUntil(
|
|
267
|
+
async () => (await this.getSlot()) >= slot || undefined,
|
|
268
|
+
`rollup slot >= ${slot}`,
|
|
269
|
+
opts.timeout ?? 60,
|
|
270
|
+
opts.interval ?? 1,
|
|
271
|
+
);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Polls the rollup until its pending checkpoint settles below `checkpoint` on a freshly mined, non-zero
|
|
276
|
+
* checkpoint, and returns that new pending checkpoint number. Reads the L1 rollup contract directly
|
|
277
|
+
* rather than a node, since a rollback lands on L1 first.
|
|
278
|
+
*
|
|
279
|
+
* A prune can momentarily drop the pending checkpoint to 0 before the post-deadline propose mines its
|
|
280
|
+
* replacement, so a caller detecting a rollback wants the new lower checkpoint, not that transient
|
|
281
|
+
* empty state — hence the non-zero guard.
|
|
282
|
+
*/
|
|
283
|
+
public async waitForCheckpointBelow(
|
|
284
|
+
checkpoint: CheckpointNumber,
|
|
285
|
+
opts: { timeout?: number; interval?: number } = {},
|
|
286
|
+
): Promise<CheckpointNumber> {
|
|
287
|
+
return await retryUntil(
|
|
288
|
+
async () => {
|
|
289
|
+
const { pending } = await this.getTips();
|
|
290
|
+
return pending > 0 && pending < checkpoint ? pending : undefined;
|
|
291
|
+
},
|
|
292
|
+
`rollup checkpoint in (0, ${checkpoint})`,
|
|
293
|
+
opts.timeout ?? 60,
|
|
294
|
+
opts.interval ?? 1,
|
|
295
|
+
);
|
|
296
|
+
}
|
|
297
|
+
|
|
221
298
|
/**
|
|
222
299
|
* Overrides the inProgress field of the Inbox contract state
|
|
223
300
|
* @param howMuch - How many checkpoints to move it forward
|
|
@@ -259,12 +336,14 @@ export class RollupCheatCodes {
|
|
|
259
336
|
});
|
|
260
337
|
}
|
|
261
338
|
|
|
262
|
-
public insertOutbox(epoch: EpochNumber, outHash: bigint) {
|
|
339
|
+
public insertOutbox(epoch: EpochNumber, numCheckpointsInEpoch: number, outHash: bigint) {
|
|
263
340
|
return this.ethCheatCodes.execWithPausedAnvil(async () => {
|
|
264
341
|
const outboxAddress = await this.rollup.read.getOutbox();
|
|
265
|
-
const epochRootSlot = OutboxContract.getEpochRootStorageSlot(epoch);
|
|
342
|
+
const epochRootSlot = OutboxContract.getEpochRootStorageSlot(epoch, numCheckpointsInEpoch);
|
|
266
343
|
await this.ethCheatCodes.store(EthAddress.fromString(outboxAddress), epochRootSlot, outHash);
|
|
267
|
-
this.logger.warn(
|
|
344
|
+
this.logger.warn(
|
|
345
|
+
`Advanced outbox to epoch ${epoch} numCheckpointsInEpoch ${numCheckpointsInEpoch} with out hash ${outHash}`,
|
|
346
|
+
);
|
|
268
347
|
});
|
|
269
348
|
}
|
|
270
349
|
|
|
@@ -313,7 +392,8 @@ export class RollupCheatCodes {
|
|
|
313
392
|
}
|
|
314
393
|
|
|
315
394
|
/**
|
|
316
|
-
* Directly updates proving cost per mana.
|
|
395
|
+
* Directly updates proving cost per mana. Throws if the on-chain tx reverts
|
|
396
|
+
* (e.g. rate-limit cooldown, step cap, or floor) instead of silently succeeding.
|
|
317
397
|
* @param ethValue - The new proving cost per mana in ETH
|
|
318
398
|
*/
|
|
319
399
|
public async setProvingCostPerMana(ethValue: bigint) {
|
|
@@ -323,8 +403,37 @@ export class RollupCheatCodes {
|
|
|
323
403
|
chain: this.client.chain,
|
|
324
404
|
gasLimit: 1000000n,
|
|
325
405
|
});
|
|
326
|
-
await this.client.waitForTransactionReceipt({ hash });
|
|
406
|
+
const receipt = await this.client.waitForTransactionReceipt({ hash });
|
|
407
|
+
if (receipt.status !== 'success') {
|
|
408
|
+
throw new Error(
|
|
409
|
+
`setProvingCostPerMana(${ethValue}) reverted on L1 (tx ${hash}). ` +
|
|
410
|
+
`Likely FeeLib rate-limit (30-day cooldown or 1.5x step cap); ` +
|
|
411
|
+
`use clearProvingCostCooldown() between successive updates.`,
|
|
412
|
+
);
|
|
413
|
+
}
|
|
327
414
|
this.logger.warn(`Updated proving cost per mana to ${ethValue}`);
|
|
328
415
|
});
|
|
329
416
|
}
|
|
417
|
+
|
|
418
|
+
/**
|
|
419
|
+
* Resets the 30-day proving-cost update cooldown enforced by FeeLib.updateProvingCostPerMana
|
|
420
|
+
* by zeroing `FeeStore.provingCostLastUpdate` directly in contract storage. Use between
|
|
421
|
+
* successive setProvingCostPerMana / bumpProvingCostPerMana calls so the later update can
|
|
422
|
+
* land instead of reverting. Does not touch L1 time, so PXE/tx-expiration state stays intact.
|
|
423
|
+
*
|
|
424
|
+
* @note This is tightly coupled to the `FeeStore` layout in
|
|
425
|
+
* l1-contracts/src/core/libraries/rollup/FeeLib.sol:
|
|
426
|
+
* slot + 0: CompressedFeeConfig config (uint256)
|
|
427
|
+
* slot + 1: L1GasOracleValues l1GasOracleValues (14+14+4 bytes, packed)
|
|
428
|
+
* slot + 2: uint64 provingCostLastUpdate (only member — zeroing the slot is safe)
|
|
429
|
+
* If the struct layout changes, update the offset below.
|
|
430
|
+
*/
|
|
431
|
+
public async clearProvingCostCooldown() {
|
|
432
|
+
const feeStoreBaseSlot = hexToBigInt(keccak256(Buffer.from('aztec.fee.storage', 'utf-8')));
|
|
433
|
+
const provingCostLastUpdateSlot = feeStoreBaseSlot + 2n;
|
|
434
|
+
await this.ethCheatCodes.store(EthAddress.fromString(this.rollup.address), provingCostLastUpdateSlot, 0n, {
|
|
435
|
+
silent: true,
|
|
436
|
+
});
|
|
437
|
+
this.logger.warn(`Cleared proving-cost update cooldown`);
|
|
438
|
+
}
|
|
330
439
|
}
|
package/src/test/start_anvil.ts
CHANGED
|
@@ -1,9 +1,42 @@
|
|
|
1
1
|
import { createLogger } from '@aztec/foundation/log';
|
|
2
2
|
import { makeBackoff, retry } from '@aztec/foundation/retry';
|
|
3
|
-
import {
|
|
3
|
+
import type { TestDateProvider } from '@aztec/foundation/timer';
|
|
4
4
|
|
|
5
|
-
import { type
|
|
6
|
-
|
|
5
|
+
import { type ChildProcess, spawn } from 'child_process';
|
|
6
|
+
|
|
7
|
+
import { resolveFoundryBinary } from '../foundry_binary.js';
|
|
8
|
+
|
|
9
|
+
/** Minimal interface matching the @viem/anvil Anvil shape used by callers. */
|
|
10
|
+
export interface Anvil {
|
|
11
|
+
readonly port: number;
|
|
12
|
+
readonly host: string;
|
|
13
|
+
readonly status: 'listening' | 'idle';
|
|
14
|
+
stop(): Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// Watchdog wrapper: instead of spawning anvil directly, we spawn a small bash supervisor that runs
|
|
18
|
+
// anvil as a background child and polls its own parent (this node process). If the parent dies for
|
|
19
|
+
// ANY reason — including SIGKILL / crash / OOM, where node's own exit handlers never run — the poll
|
|
20
|
+
// loop ends and the EXIT trap reaps anvil. The script is inlined (rather than shipped as a `.sh`) so
|
|
21
|
+
// it works from the published npm tarball too, and the resolved anvil binary is passed via
|
|
22
|
+
// `$ANVIL_BIN` so it works without `anvil` on PATH.
|
|
23
|
+
//
|
|
24
|
+
// `$@` is the anvil argv; `bash -c <script> bash <...args>` puts the args in `$@` and `$0` = 'bash'.
|
|
25
|
+
//
|
|
26
|
+
// The EXIT trap reaps anvil; INT/TERM just `exit` (which fires the EXIT trap) so a signal terminates
|
|
27
|
+
// the supervisor promptly instead of being swallowed — a trapped TERM does NOT terminate the shell,
|
|
28
|
+
// so trapping the kill directly on TERM would leave the poll loop running and the caller's teardown
|
|
29
|
+
// hanging until its SIGKILL escalation. `sleep & wait` makes the poll interruptible, so INT/TERM are
|
|
30
|
+
// handled immediately rather than after the current `sleep` returns.
|
|
31
|
+
const ANVIL_WATCHDOG = `
|
|
32
|
+
set -u
|
|
33
|
+
parent=$PPID
|
|
34
|
+
"$ANVIL_BIN" "$@" &
|
|
35
|
+
anvil_pid=$!
|
|
36
|
+
trap 'kill "$anvil_pid" 2>/dev/null' EXIT
|
|
37
|
+
trap 'exit 0' INT TERM
|
|
38
|
+
while kill -0 "$parent" 2>/dev/null; do sleep 1 & wait $!; done
|
|
39
|
+
`;
|
|
7
40
|
|
|
8
41
|
/**
|
|
9
42
|
* Ensures there's a running Anvil instance and returns the RPC URL.
|
|
@@ -16,56 +49,203 @@ export async function startAnvil(
|
|
|
16
49
|
captureMethodCalls?: boolean;
|
|
17
50
|
accounts?: number;
|
|
18
51
|
chainId?: number;
|
|
19
|
-
/** The hardfork to use
|
|
52
|
+
/** The hardfork to use (e.g. 'cancun', 'latest'). */
|
|
20
53
|
hardfork?: string;
|
|
54
|
+
/**
|
|
55
|
+
* Number of slots per epoch used by anvil to compute the 'finalized' and 'safe' block tags.
|
|
56
|
+
* Anvil reports `finalized = latest - slotsInAnEpoch * 2`.
|
|
57
|
+
* Defaults to 1 so the finalized block advances immediately, making tests that check
|
|
58
|
+
* L1-finality-based logic work without needing hundreds of mined blocks.
|
|
59
|
+
*/
|
|
60
|
+
slotsInAnEpoch?: number;
|
|
61
|
+
/**
|
|
62
|
+
* If provided, the date provider will be synced to anvil's block time on every mined block.
|
|
63
|
+
* This keeps the dateProvider in lockstep with anvil's chain time, avoiding drift between
|
|
64
|
+
* the wall clock and the L1 chain when computing L1 slot timestamps.
|
|
65
|
+
*/
|
|
66
|
+
dateProvider?: TestDateProvider;
|
|
21
67
|
} = {},
|
|
22
68
|
): Promise<{ anvil: Anvil; methodCalls?: string[]; rpcUrl: string; stop: () => Promise<void> }> {
|
|
23
|
-
const anvilBinary =
|
|
69
|
+
const anvilBinary = resolveFoundryBinary('anvil');
|
|
24
70
|
const logger = opts.log ? createLogger('ethereum:anvil') : undefined;
|
|
25
71
|
const methodCalls = opts.captureMethodCalls ? ([] as string[]) : undefined;
|
|
26
72
|
|
|
27
|
-
let
|
|
73
|
+
let detectedPort: number | undefined;
|
|
28
74
|
|
|
29
|
-
// Start anvil.
|
|
30
|
-
// We go via a wrapper script to ensure if the parent dies, anvil dies.
|
|
31
75
|
const anvil = await retry(
|
|
32
76
|
async () => {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
77
|
+
// `--port 0` lets anvil bind an OS-assigned ephemeral port; the actual port is read back from
|
|
78
|
+
// its "Listening on host:port" stdout below, so independent suites can spawn their own anvil
|
|
79
|
+
// in parallel without fighting over a fixed port.
|
|
80
|
+
const port = opts.port ?? (process.env.ANVIL_PORT ? parseInt(process.env.ANVIL_PORT) : 8545);
|
|
81
|
+
const args: string[] = [
|
|
82
|
+
'--host',
|
|
83
|
+
'127.0.0.1',
|
|
84
|
+
'--port',
|
|
85
|
+
String(port),
|
|
86
|
+
'--accounts',
|
|
87
|
+
String(opts.accounts ?? 20),
|
|
88
|
+
'--gas-limit',
|
|
89
|
+
String(45_000_000),
|
|
90
|
+
'--chain-id',
|
|
91
|
+
String(opts.chainId ?? 31337),
|
|
92
|
+
];
|
|
93
|
+
if (opts.l1BlockTime !== undefined) {
|
|
94
|
+
args.push('--block-time', String(opts.l1BlockTime));
|
|
95
|
+
}
|
|
96
|
+
if (opts.hardfork !== undefined) {
|
|
97
|
+
args.push('--hardfork', opts.hardfork);
|
|
98
|
+
}
|
|
99
|
+
args.push('--slots-in-an-epoch', String(opts.slotsInAnEpoch ?? 1));
|
|
100
|
+
|
|
101
|
+
// Spawn the watchdog (see ANVIL_WATCHDOG). It launches anvil with these args and reaps it if we
|
|
102
|
+
// die; `$0` is 'bash' and `$@` is the anvil argv.
|
|
103
|
+
const child = spawn('bash', ['-c', ANVIL_WATCHDOG, 'bash', ...args], {
|
|
104
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
105
|
+
env: { ...process.env, ANVIL_BIN: anvilBinary, RAYON_NUM_THREADS: '1' },
|
|
42
106
|
});
|
|
43
107
|
|
|
44
|
-
//
|
|
45
|
-
|
|
46
|
-
|
|
108
|
+
// Wait for "Listening on" or an early exit.
|
|
109
|
+
await new Promise<void>((resolve, reject) => {
|
|
110
|
+
let stderr = '';
|
|
111
|
+
|
|
112
|
+
const onStdout = (data: Buffer) => {
|
|
113
|
+
const text = data.toString();
|
|
114
|
+
logger?.debug(text.trim());
|
|
115
|
+
methodCalls?.push(...(text.match(/eth_[^\s]+/g) || []));
|
|
47
116
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
117
|
+
if (detectedPort === undefined && text.includes('Listening on')) {
|
|
118
|
+
const match = text.match(/Listening on ([^:]+):(\d+)/);
|
|
119
|
+
if (match) {
|
|
120
|
+
detectedPort = parseInt(match[2]);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
if (detectedPort !== undefined) {
|
|
124
|
+
child.stdout?.removeListener('data', onStdout);
|
|
125
|
+
child.stderr?.removeListener('data', onStderr);
|
|
126
|
+
child.removeListener('close', onClose);
|
|
127
|
+
resolve();
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
const onStderr = (data: Buffer) => {
|
|
132
|
+
stderr += data.toString();
|
|
133
|
+
logger?.debug(data.toString().trim());
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
const onClose = (code: number | null) => {
|
|
137
|
+
child.stdout?.removeListener('data', onStdout);
|
|
138
|
+
child.stderr?.removeListener('data', onStderr);
|
|
139
|
+
reject(new Error(`Anvil exited with code ${code} before listening. stderr: ${stderr}`));
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
child.stdout?.on('data', onStdout);
|
|
143
|
+
child.stderr?.on('data', onStderr);
|
|
144
|
+
child.once('close', onClose);
|
|
52
145
|
});
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
146
|
+
|
|
147
|
+
// Continue piping for logging, method-call capture, and/or dateProvider sync after startup.
|
|
148
|
+
if (logger || opts.captureMethodCalls || opts.dateProvider) {
|
|
149
|
+
child.stdout?.on('data', (data: Buffer) => {
|
|
150
|
+
const text = data.toString();
|
|
151
|
+
logger?.debug(text.trim());
|
|
152
|
+
methodCalls?.push(...(text.match(/eth_[^\s]+/g) || []));
|
|
153
|
+
if (opts.dateProvider) {
|
|
154
|
+
syncDateProviderFromAnvilOutput(text, opts.dateProvider);
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
child.stderr?.on('data', (data: Buffer) => {
|
|
158
|
+
logger?.debug(data.toString().trim());
|
|
159
|
+
});
|
|
160
|
+
} else {
|
|
161
|
+
// Consume streams so the child process doesn't block on full pipe buffers.
|
|
162
|
+
child.stdout?.resume();
|
|
163
|
+
child.stderr?.resume();
|
|
56
164
|
}
|
|
57
165
|
|
|
58
|
-
return
|
|
166
|
+
return child;
|
|
59
167
|
},
|
|
60
168
|
'Start anvil',
|
|
61
169
|
makeBackoff([5, 5, 5]),
|
|
62
170
|
);
|
|
63
171
|
|
|
64
|
-
if (!
|
|
172
|
+
if (!detectedPort) {
|
|
65
173
|
throw new Error('Failed to start anvil');
|
|
66
174
|
}
|
|
67
175
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
176
|
+
const port = detectedPort;
|
|
177
|
+
let status: 'listening' | 'idle' = 'listening';
|
|
178
|
+
|
|
179
|
+
anvil.once('close', () => {
|
|
180
|
+
status = 'idle';
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
const stop = async () => {
|
|
184
|
+
if (status === 'idle') {
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
await killChild(anvil);
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
const anvilObj: Anvil = {
|
|
191
|
+
port,
|
|
192
|
+
host: '127.0.0.1',
|
|
193
|
+
get status() {
|
|
194
|
+
return status;
|
|
195
|
+
},
|
|
196
|
+
stop,
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
return { anvil: anvilObj, methodCalls, stop, rpcUrl: `http://127.0.0.1:${port}` };
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/** Extracts block time from anvil stdout and syncs the dateProvider. */
|
|
203
|
+
function syncDateProviderFromAnvilOutput(text: string, dateProvider: TestDateProvider): void {
|
|
204
|
+
// Anvil logs mined blocks as:
|
|
205
|
+
// Block Time: "Fri, 20 Mar 2026 02:10:46 +0000"
|
|
206
|
+
const match = text.match(/Block Time:\s*"([^"]+)"/);
|
|
207
|
+
if (match) {
|
|
208
|
+
const blockTimeMs = new Date(match[1]).getTime();
|
|
209
|
+
if (!isNaN(blockTimeMs)) {
|
|
210
|
+
dateProvider.setTime(blockTimeMs);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Send SIGTERM to the watchdog, wait up to 5 s, then SIGKILL. The watchdog's trap forwards the
|
|
217
|
+
* signal to anvil, so terminating it tears down anvil too. All timers are always cleared.
|
|
218
|
+
*/
|
|
219
|
+
function killChild(child: ChildProcess): Promise<void> {
|
|
220
|
+
return new Promise<void>(resolve => {
|
|
221
|
+
if (child.exitCode !== null || child.killed) {
|
|
222
|
+
child.stdout?.destroy();
|
|
223
|
+
child.stderr?.destroy();
|
|
224
|
+
resolve();
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
let killTimer: NodeJS.Timeout | undefined;
|
|
229
|
+
|
|
230
|
+
const onClose = () => {
|
|
231
|
+
if (killTimer !== undefined) {
|
|
232
|
+
clearTimeout(killTimer);
|
|
233
|
+
}
|
|
234
|
+
// Destroy stdio streams so their PipeWrap handles don't keep the event loop alive.
|
|
235
|
+
child.stdout?.destroy();
|
|
236
|
+
child.stderr?.destroy();
|
|
237
|
+
resolve();
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
child.once('close', onClose);
|
|
241
|
+
child.kill('SIGTERM');
|
|
242
|
+
|
|
243
|
+
killTimer = setTimeout(() => {
|
|
244
|
+
killTimer = undefined;
|
|
245
|
+
child.kill('SIGKILL');
|
|
246
|
+
}, 5000);
|
|
247
|
+
|
|
248
|
+
// Ensure the timer does not prevent Node from exiting.
|
|
249
|
+
killTimer.unref();
|
|
250
|
+
});
|
|
71
251
|
}
|
|
@@ -7,7 +7,7 @@ import { type GetContractReturnType, type PrivateKeyAccount, getContract } from
|
|
|
7
7
|
|
|
8
8
|
import { extractProposalIdFromLogs } from '../contracts/governance.js';
|
|
9
9
|
import type { L1ContractAddresses } from '../l1_contract_addresses.js';
|
|
10
|
-
import {
|
|
10
|
+
import { createL1TxUtils } from '../l1_tx_utils/index.js';
|
|
11
11
|
import type { ExtendedViemWalletClient, ViemPublicClient } from '../types.js';
|
|
12
12
|
import { EthCheatCodes } from './eth_cheat_codes.js';
|
|
13
13
|
|
|
@@ -22,7 +22,7 @@ export async function executeGovernanceProposal(
|
|
|
22
22
|
) {
|
|
23
23
|
const proposal = await governance.read.getProposal([proposalId]);
|
|
24
24
|
|
|
25
|
-
const l1TxUtils =
|
|
25
|
+
const l1TxUtils = createL1TxUtils(l1Client);
|
|
26
26
|
|
|
27
27
|
const waitL1Block = async () => {
|
|
28
28
|
await l1TxUtils.sendAndMonitorTransaction({
|