@aztec/ethereum 5.0.0-rc.1 → 5.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/config.d.ts +10 -1
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +24 -0
- package/dest/contracts/rollup.d.ts +165 -8
- package/dest/contracts/rollup.d.ts.map +1 -1
- package/dest/deploy_aztec_l1_contracts.d.ts +2 -2
- package/dest/deploy_aztec_l1_contracts.d.ts.map +1 -1
- package/dest/deploy_aztec_l1_contracts.js +2 -0
- package/dest/generated/l1-contracts-defaults.d.ts +1 -1
- package/dest/generated/l1-contracts-defaults.js +1 -1
- package/dest/l1_artifacts.d.ts +1219 -77
- package/dest/l1_artifacts.d.ts.map +1 -1
- package/dest/l1_tx_utils/config.js +3 -3
- package/dest/l1_tx_utils/l1_tx_utils.d.ts +1 -1
- package/dest/l1_tx_utils/l1_tx_utils.d.ts.map +1 -1
- package/dest/l1_tx_utils/l1_tx_utils.js +57 -15
- package/dest/publisher_manager.d.ts +18 -6
- package/dest/publisher_manager.d.ts.map +1 -1
- package/dest/publisher_manager.js +44 -7
- 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 +33 -2
- package/dest/test/chain_monitor.d.ts.map +1 -1
- package/dest/test/chain_monitor.js +71 -6
- package/dest/test/eth_cheat_codes.d.ts +20 -3
- package/dest/test/eth_cheat_codes.d.ts.map +1 -1
- package/dest/test/eth_cheat_codes.js +50 -40
- package/dest/test/index.d.ts +2 -1
- package/dest/test/index.d.ts.map +1 -1
- package/dest/test/index.js +1 -0
- package/dest/test/rollup_cheat_codes.d.ts +30 -1
- package/dest/test/rollup_cheat_codes.d.ts.map +1 -1
- package/dest/test/rollup_cheat_codes.js +27 -0
- package/package.json +5 -5
- package/src/config.ts +35 -0
- package/src/contracts/rollup.ts +2 -1
- package/src/deploy_aztec_l1_contracts.ts +2 -1
- package/src/generated/l1-contracts-defaults.ts +1 -1
- package/src/l1_tx_utils/config.ts +3 -3
- package/src/l1_tx_utils/l1_tx_utils.ts +52 -18
- package/src/publisher_manager.ts +54 -18
- package/src/test/blob_kzg_warmup.ts +65 -0
- package/src/test/chain_monitor.ts +88 -5
- package/src/test/eth_cheat_codes.ts +47 -43
- package/src/test/index.ts +1 -0
- package/src/test/rollup_cheat_codes.ts +51 -0
|
@@ -206,6 +206,22 @@ export class EthCheatCodes {
|
|
|
206
206
|
}
|
|
207
207
|
}
|
|
208
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
|
+
|
|
209
225
|
/**
|
|
210
226
|
* Set the automine status of the underlying anvil chain
|
|
211
227
|
* @param automine - The automine status to set
|
|
@@ -478,58 +494,46 @@ export class EthCheatCodes {
|
|
|
478
494
|
}
|
|
479
495
|
|
|
480
496
|
/**
|
|
481
|
-
* Mines
|
|
482
|
-
*
|
|
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".
|
|
483
508
|
*/
|
|
484
509
|
public async mineEmptyBlock(blockCount: number = 1): Promise<void> {
|
|
485
510
|
await this.execWithPausedAnvil(async () => {
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
const rawTxs: Hex[] = [];
|
|
493
|
-
for (const tx of txs) {
|
|
494
|
-
try {
|
|
495
|
-
const rawTx = await this.doRpcCall('debug_getRawTransaction', [tx.hash]);
|
|
496
|
-
if (rawTx) {
|
|
497
|
-
rawTxs.push(rawTx);
|
|
498
|
-
this.logger.debug(`Got raw tx for ${tx.hash}`);
|
|
499
|
-
} else {
|
|
500
|
-
this.logger.warn(`No raw tx found for ${tx.hash}`);
|
|
501
|
-
}
|
|
502
|
-
} catch {
|
|
503
|
-
this.logger.warn(`Failed to get raw transaction for ${tx.hash}`);
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
this.logger.debug(`Retrieved ${rawTxs.length} raw transactions`);
|
|
508
|
-
|
|
509
|
-
// Drop all transactions from the mempool
|
|
510
|
-
await this.doRpcCall('anvil_dropAllTransactions', []);
|
|
511
|
-
|
|
512
|
-
// Mine an empty block
|
|
513
|
-
await this.doMine(blockCount);
|
|
514
|
-
|
|
515
|
-
// Re-add the transactions to the pool
|
|
516
|
-
for (const rawTx of rawTxs) {
|
|
517
|
-
try {
|
|
518
|
-
const txHash = await this.doRpcCall('eth_sendRawTransaction', [rawTx]);
|
|
519
|
-
this.logger.debug(`Re-added transaction ${txHash}`);
|
|
520
|
-
} catch (err) {
|
|
521
|
-
this.logger.warn(`Failed to re-add transaction: ${err}`);
|
|
522
|
-
}
|
|
523
|
-
}
|
|
524
|
-
|
|
525
|
-
if (rawTxs.length !== txs.length) {
|
|
526
|
-
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);
|
|
527
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, []]);
|
|
528
521
|
});
|
|
529
522
|
|
|
530
523
|
this.logger.warn(`Mined ${blockCount} empty L1 ${pluralize('block', blockCount)}`);
|
|
531
524
|
}
|
|
532
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
|
+
|
|
533
537
|
public async execWithPausedAnvil<T>(fn: () => Promise<T>): Promise<T> {
|
|
534
538
|
const [blockInterval, wasAutoMining] = await Promise.all([this.getIntervalMining(), this.isAutoMining()]);
|
|
535
539
|
try {
|
package/src/test/index.ts
CHANGED
|
@@ -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
|
|
|
@@ -244,6 +245,56 @@ export class RollupCheatCodes {
|
|
|
244
245
|
});
|
|
245
246
|
}
|
|
246
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
|
+
|
|
247
298
|
/**
|
|
248
299
|
* Overrides the inProgress field of the Inbox contract state
|
|
249
300
|
* @param howMuch - How many checkpoints to move it forward
|