@aztec/ethereum 0.0.1-commit.b655e406 → 0.0.1-commit.b8a057fa
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 +48 -73
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +120 -386
- 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 +4 -2
- package/dest/contracts/gse.d.ts.map +1 -1
- package/dest/contracts/gse.js +2 -2
- 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 +130 -13
- package/dest/contracts/multicall.d.ts.map +1 -1
- package/dest/contracts/multicall.js +203 -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 +5591 -131
- package/dest/contracts/rollup.d.ts.map +1 -1
- package/dest/contracts/rollup.js +1125 -232
- 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 +267 -0
- package/dest/deploy_aztec_l1_contracts.d.ts.map +1 -0
- package/dest/deploy_aztec_l1_contracts.js +417 -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/l1_artifacts.d.ts +21007 -16779
- 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 +46 -10
- 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 +252 -0
- package/dest/l1_tx_utils/l1_fee_analyzer.d.ts.map +1 -0
- package/dest/l1_tx_utils/l1_fee_analyzer.js +568 -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 +202 -92
- 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 +27 -1
- package/dest/l1_tx_utils/types.d.ts.map +1 -1
- package/dest/l1_tx_utils/types.js +10 -0
- package/dest/l1_tx_utils/utils.d.ts +1 -1
- package/dest/l1_types.d.ts +1 -1
- package/dest/publisher_manager.d.ts +34 -7
- package/dest/publisher_manager.d.ts.map +1 -1
- package/dest/publisher_manager.js +119 -8
- package/dest/queries.d.ts +14 -3
- package/dest/queries.d.ts.map +1 -1
- package/dest/queries.js +84 -9
- 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 +80 -26
- package/dest/test/chain_monitor.d.ts.map +1 -1
- package/dest/test/chain_monitor.js +137 -39
- package/dest/test/eth_cheat_codes.d.ts +47 -8
- package/dest/test/eth_cheat_codes.d.ts.map +1 -1
- package/dest/test/eth_cheat_codes.js +100 -44
- 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 +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 +75 -14
- package/dest/test/rollup_cheat_codes.d.ts.map +1 -1
- package/dest/test/rollup_cheat_codes.js +145 -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 +34 -17
- package/src/client.ts +66 -2
- package/src/config.ts +162 -470
- 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/gse.ts +7 -2
- 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 +247 -103
- package/src/contracts/outbox.ts +132 -0
- package/src/contracts/registry.ts +31 -1
- package/src/contracts/rollup.ts +830 -194
- package/src/contracts/{tally_slashing_proposer.ts → slashing_proposer.ts} +26 -21
- package/src/deploy_aztec_l1_contracts.ts +652 -0
- package/src/deploy_l1_contract.ts +362 -0
- package/src/forwarder_proxy.ts +108 -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 +55 -14
- 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 +875 -0
- package/src/l1_tx_utils/l1_tx_utils.ts +194 -72
- 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/l1_tx_utils/types.ts +32 -0
- package/src/publisher_manager.ts +145 -12
- package/src/queries.ts +93 -10
- package/src/test/blob_kzg_warmup.ts +65 -0
- package/src/test/chain_monitor.ts +198 -51
- package/src/test/eth_cheat_codes.ts +91 -48
- package/src/test/index.ts +1 -2
- package/src/test/rollup_cheat_codes.ts +174 -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
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { getBytesPerBlob, getBytesPerCommitment, getKzg } from '@aztec/blob-lib';
|
|
2
|
+
import type { Logger } from '@aztec/foundation/log';
|
|
3
|
+
|
|
4
|
+
import type { ExtendedViemWalletClient } from '../types.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Warms both KZG trusted setups in parallel for tests against a local anvil:
|
|
8
|
+
* - anvil's own setup, loaded lazily when it first validates a blob sidecar in `eth_sendRawTransaction`
|
|
9
|
+
* - our `@crate-crypto/node-eth-kzg` singleton (`getKzg()`, a ~2.2s synchronous precomp build)
|
|
10
|
+
*
|
|
11
|
+
* Without this, the first checkpoint publish pays both serially (~4.4s). The recipe does all RPC round
|
|
12
|
+
* trips up front, fires a single bare raw send carrying a fake (garbage) blob sidecar that anvil rejects
|
|
13
|
+
* after loading its trusted setup, yields once to flush the socket write, then synchronously builds our
|
|
14
|
+
* own precomp tables while anvil warms in parallel. The fake tx is rejected at admission, so it never
|
|
15
|
+
* enters the pool, mines no block, and burns no nonce — sending it from the passed client is harmless.
|
|
16
|
+
*
|
|
17
|
+
* Best-effort: any failure is debug-logged and swallowed, leaving lazy init as the fallback. Never throws.
|
|
18
|
+
*
|
|
19
|
+
* @param l1Client - The L1 client whose account sends the (rejected) warm-up blob tx.
|
|
20
|
+
*/
|
|
21
|
+
export async function warmBlobKzg(l1Client: ExtendedViemWalletClient, logger?: Logger): Promise<void> {
|
|
22
|
+
try {
|
|
23
|
+
// A pure-JS fake kzg: returns deterministic garbage of the correct lengths (commitment and proof are
|
|
24
|
+
// both 48 bytes). It makes viem build a syntactically valid sidecar without initializing any native
|
|
25
|
+
// module, so anvil loads its trusted setup to validate the (invalid) proof and then rejects the tx.
|
|
26
|
+
const fakeKzg = {
|
|
27
|
+
blobToKzgCommitment: () => {
|
|
28
|
+
const commitment = new Uint8Array(getBytesPerCommitment());
|
|
29
|
+
commitment.fill(0xab);
|
|
30
|
+
commitment[0] = 0xc0;
|
|
31
|
+
return commitment;
|
|
32
|
+
},
|
|
33
|
+
computeBlobKzgProof: () => {
|
|
34
|
+
const proof = new Uint8Array(getBytesPerCommitment());
|
|
35
|
+
proof.fill(0xcd);
|
|
36
|
+
proof[0] = 0xc0;
|
|
37
|
+
return proof;
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
// All RPC round trips (nonce, fees, gas) happen here, so only a single socket write remains to flush.
|
|
42
|
+
const prepared = await l1Client.prepareTransactionRequest({
|
|
43
|
+
blobs: [new Uint8Array(getBytesPerBlob())],
|
|
44
|
+
kzg: fakeKzg,
|
|
45
|
+
to: '0x0000000000000000000000000000000000000000',
|
|
46
|
+
value: 0n,
|
|
47
|
+
maxFeePerBlobGas: 1_000_000_000_000n,
|
|
48
|
+
});
|
|
49
|
+
const serialized = await l1Client.signTransaction(prepared);
|
|
50
|
+
|
|
51
|
+
// Fire the raw send without awaiting and swallow the expected rejection.
|
|
52
|
+
const sent = l1Client.request({ method: 'eth_sendRawTransaction', params: [serialized] }).catch(() => {});
|
|
53
|
+
|
|
54
|
+
// Flush the single socket write so anvil receives the tx and starts loading its trusted setup in its
|
|
55
|
+
// own process before we block the event loop below.
|
|
56
|
+
await new Promise(resolve => setImmediate(resolve));
|
|
57
|
+
|
|
58
|
+
// Synchronously build our precomp tables (~2.2s, event-loop-blocking); anvil warms in parallel.
|
|
59
|
+
getKzg();
|
|
60
|
+
|
|
61
|
+
await sent;
|
|
62
|
+
} catch (err) {
|
|
63
|
+
logger?.debug('Failed to warm blob KZG; falling back to lazy init', { err });
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { ManaMinFeeComponents, RollupContract } from '@aztec/ethereum/contracts';
|
|
2
|
+
import { InboxContract } from '@aztec/ethereum/contracts';
|
|
3
|
+
import { CheckpointNumber, EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
2
4
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
3
5
|
import { createLogger } from '@aztec/foundation/log';
|
|
4
6
|
import { promiseWithResolvers } from '@aztec/foundation/promise';
|
|
@@ -8,18 +10,46 @@ import { EventEmitter } from 'events';
|
|
|
8
10
|
|
|
9
11
|
import type { ViemClient } from '../types.js';
|
|
10
12
|
|
|
13
|
+
/** L2 fee data reported by the chain monitor. */
|
|
14
|
+
export type L2FeeData = ManaMinFeeComponents & {
|
|
15
|
+
/** Total minimum fee per mana in Fee Juice (sum of sequencerCost + proverCost + congestionCost). */
|
|
16
|
+
minFeePerMana: bigint;
|
|
17
|
+
/** L1 base fee observed by the oracle. */
|
|
18
|
+
l1BaseFee: bigint;
|
|
19
|
+
/** L1 blob fee observed by the oracle. */
|
|
20
|
+
l1BlobFee: bigint;
|
|
21
|
+
/** ETH per fee asset exchange rate (1e12 precision). */
|
|
22
|
+
ethPerFeeAsset: bigint;
|
|
23
|
+
/** Mana target per checkpoint. */
|
|
24
|
+
manaTarget: bigint;
|
|
25
|
+
};
|
|
26
|
+
|
|
11
27
|
export type ChainMonitorEventMap = {
|
|
12
28
|
'l1-block': [{ l1BlockNumber: number; timestamp: bigint }];
|
|
13
|
-
|
|
14
|
-
|
|
29
|
+
checkpoint: [
|
|
30
|
+
{ checkpointNumber: CheckpointNumber; l1BlockNumber: number; l2SlotNumber: SlotNumber; timestamp: bigint },
|
|
31
|
+
];
|
|
32
|
+
'checkpoint-proven': [{ provenCheckpointNumber: CheckpointNumber; l1BlockNumber: number; timestamp: bigint }];
|
|
15
33
|
'l2-messages': [{ totalL2Messages: number; l1BlockNumber: number }];
|
|
16
|
-
'l2-epoch': [{ l2EpochNumber:
|
|
17
|
-
'l2-slot': [{ l2SlotNumber:
|
|
34
|
+
'l2-epoch': [{ l2EpochNumber: EpochNumber; timestamp: bigint; committee: EthAddress[] | undefined }];
|
|
35
|
+
'l2-slot': [{ l2SlotNumber: SlotNumber; timestamp: bigint }];
|
|
36
|
+
'l2-fees': [L2FeeData];
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/** Options for tuning what the {@link ChainMonitor} polls on each new L1 block. */
|
|
40
|
+
export type ChainMonitorOptions = {
|
|
41
|
+
/**
|
|
42
|
+
* Whether to fetch L2 fee/oracle data (5 extra rollup reads per new L1 block) and emit `l2-fees`.
|
|
43
|
+
* Defaults to `true`. Set to `false` for tests that only care about slot/checkpoint/proven state to
|
|
44
|
+
* avoid the extra round-trips.
|
|
45
|
+
*/
|
|
46
|
+
includeFeeData?: boolean;
|
|
18
47
|
};
|
|
19
48
|
|
|
20
49
|
/** Utility class that polls the chain on quick intervals and logs new L1 blocks, L2 blocks, and L2 proofs. */
|
|
21
50
|
export class ChainMonitor extends EventEmitter<ChainMonitorEventMap> {
|
|
22
51
|
private readonly l1Client: ViemClient;
|
|
52
|
+
private readonly includeFeeData: boolean;
|
|
23
53
|
private inbox: InboxContract | undefined;
|
|
24
54
|
private handle: NodeJS.Timeout | undefined;
|
|
25
55
|
// eslint-disable-next-line aztec-custom/no-non-primitive-in-collections
|
|
@@ -27,29 +57,33 @@ export class ChainMonitor extends EventEmitter<ChainMonitorEventMap> {
|
|
|
27
57
|
|
|
28
58
|
/** Current L1 block number */
|
|
29
59
|
public l1BlockNumber!: number;
|
|
30
|
-
/** Current
|
|
31
|
-
public
|
|
32
|
-
/** Current
|
|
33
|
-
public
|
|
34
|
-
/** L1 timestamp for the current
|
|
35
|
-
public
|
|
36
|
-
/** L1 timestamp for the proven
|
|
37
|
-
public
|
|
60
|
+
/** Current checkpoint number */
|
|
61
|
+
public checkpointNumber!: CheckpointNumber;
|
|
62
|
+
/** Current proven checkpoint number */
|
|
63
|
+
public provenCheckpointNumber!: CheckpointNumber;
|
|
64
|
+
/** L1 timestamp for the current checkpoint */
|
|
65
|
+
public checkpointTimestamp!: bigint;
|
|
66
|
+
/** L1 timestamp for the proven checkpoint */
|
|
67
|
+
public provenCheckpointTimestamp!: bigint;
|
|
38
68
|
/** Total number of L2 messages pushed into the Inbox */
|
|
39
69
|
public totalL2Messages: number = 0;
|
|
40
70
|
/** Current L2 epoch number */
|
|
41
|
-
public l2EpochNumber!:
|
|
71
|
+
public l2EpochNumber!: EpochNumber;
|
|
42
72
|
/** Current L2 slot number */
|
|
43
|
-
public l2SlotNumber!:
|
|
73
|
+
public l2SlotNumber!: SlotNumber;
|
|
74
|
+
/** Current L2 fee data (components of the minimum fee per mana). */
|
|
75
|
+
public l2FeeData!: L2FeeData;
|
|
44
76
|
|
|
45
77
|
constructor(
|
|
46
78
|
private readonly rollup: RollupContract,
|
|
47
79
|
private readonly dateProvider: DateProvider = new DateProvider(),
|
|
48
80
|
private readonly logger = createLogger('aztecjs:utils:chain_monitor'),
|
|
49
81
|
private readonly intervalMs = 200,
|
|
82
|
+
options: ChainMonitorOptions = {},
|
|
50
83
|
) {
|
|
51
84
|
super();
|
|
52
85
|
this.l1Client = rollup.client;
|
|
86
|
+
this.includeFeeData = options.includeFeeData ?? true;
|
|
53
87
|
}
|
|
54
88
|
|
|
55
89
|
start() {
|
|
@@ -73,7 +107,7 @@ export class ChainMonitor extends EventEmitter<ChainMonitorEventMap> {
|
|
|
73
107
|
}
|
|
74
108
|
}
|
|
75
109
|
|
|
76
|
-
|
|
110
|
+
protected async getInbox() {
|
|
77
111
|
if (!this.inbox) {
|
|
78
112
|
const { inboxAddress } = await this.rollup.getRollupAddresses();
|
|
79
113
|
this.inbox = new InboxContract(this.l1Client, inboxAddress);
|
|
@@ -114,28 +148,28 @@ export class ChainMonitor extends EventEmitter<ChainMonitorEventMap> {
|
|
|
114
148
|
this.emit('l1-block', { l1BlockNumber: newL1BlockNumber, timestamp });
|
|
115
149
|
let msg = `L1 block ${newL1BlockNumber} mined at ${timestampString}`;
|
|
116
150
|
|
|
117
|
-
const
|
|
118
|
-
if (this.
|
|
119
|
-
const epochNumber = await this.rollup.
|
|
120
|
-
msg += ` with new
|
|
121
|
-
this.
|
|
122
|
-
this.
|
|
123
|
-
this.emit('
|
|
124
|
-
|
|
151
|
+
const newCheckpointNumber = await this.rollup.getCheckpointNumber();
|
|
152
|
+
if (this.checkpointNumber !== newCheckpointNumber) {
|
|
153
|
+
const epochNumber = await this.rollup.getEpochNumberForCheckpoint(newCheckpointNumber);
|
|
154
|
+
msg += ` with new checkpoint ${newCheckpointNumber} for epoch ${epochNumber}`;
|
|
155
|
+
this.checkpointNumber = newCheckpointNumber;
|
|
156
|
+
this.checkpointTimestamp = timestamp;
|
|
157
|
+
this.emit('checkpoint', {
|
|
158
|
+
checkpointNumber: newCheckpointNumber,
|
|
125
159
|
l1BlockNumber: newL1BlockNumber,
|
|
126
|
-
l2SlotNumber
|
|
160
|
+
l2SlotNumber,
|
|
127
161
|
timestamp,
|
|
128
162
|
});
|
|
129
163
|
}
|
|
130
164
|
|
|
131
|
-
const
|
|
132
|
-
if (this.
|
|
133
|
-
const epochNumber = await this.rollup.
|
|
134
|
-
msg += ` with proof up to
|
|
135
|
-
this.
|
|
136
|
-
this.
|
|
137
|
-
this.emit('
|
|
138
|
-
|
|
165
|
+
const newProvenCheckpointNumber = await this.rollup.getProvenCheckpointNumber();
|
|
166
|
+
if (this.provenCheckpointNumber !== newProvenCheckpointNumber) {
|
|
167
|
+
const epochNumber = await this.rollup.getEpochNumberForCheckpoint(newProvenCheckpointNumber);
|
|
168
|
+
msg += ` with proof up to checkpoint ${newProvenCheckpointNumber} for epoch ${epochNumber}`;
|
|
169
|
+
this.provenCheckpointNumber = newProvenCheckpointNumber;
|
|
170
|
+
this.provenCheckpointTimestamp = timestamp;
|
|
171
|
+
this.emit('checkpoint-proven', {
|
|
172
|
+
provenCheckpointNumber: newProvenCheckpointNumber,
|
|
139
173
|
l1BlockNumber: newL1BlockNumber,
|
|
140
174
|
timestamp,
|
|
141
175
|
});
|
|
@@ -152,14 +186,23 @@ export class ChainMonitor extends EventEmitter<ChainMonitorEventMap> {
|
|
|
152
186
|
let committee: EthAddress[] | undefined;
|
|
153
187
|
if (l2Epoch !== this.l2EpochNumber) {
|
|
154
188
|
this.l2EpochNumber = l2Epoch;
|
|
155
|
-
committee =
|
|
156
|
-
this.emit('l2-epoch', { l2EpochNumber:
|
|
157
|
-
msg += ` starting new epoch ${this.l2EpochNumber}
|
|
189
|
+
committee = await this.rollup.getCurrentEpochCommittee();
|
|
190
|
+
this.emit('l2-epoch', { l2EpochNumber: l2Epoch, timestamp, committee });
|
|
191
|
+
msg += ` starting new epoch ${this.l2EpochNumber}`;
|
|
158
192
|
}
|
|
159
193
|
|
|
160
194
|
if (l2SlotNumber !== this.l2SlotNumber) {
|
|
161
195
|
this.l2SlotNumber = l2SlotNumber;
|
|
162
|
-
this.emit('l2-slot', { l2SlotNumber
|
|
196
|
+
this.emit('l2-slot', { l2SlotNumber, timestamp });
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
if (this.includeFeeData) {
|
|
200
|
+
const feeData = await this.fetchFeeData(timestamp);
|
|
201
|
+
if (this.hasFeeDataChanged(feeData)) {
|
|
202
|
+
msg += ` with L2 min fee ${feeData.minFeePerMana}`;
|
|
203
|
+
this.l2FeeData = feeData;
|
|
204
|
+
this.emit('l2-fees', feeData);
|
|
205
|
+
}
|
|
163
206
|
}
|
|
164
207
|
|
|
165
208
|
this.logger.info(msg, {
|
|
@@ -168,23 +211,23 @@ export class ChainMonitor extends EventEmitter<ChainMonitorEventMap> {
|
|
|
168
211
|
l1BlockNumber: this.l1BlockNumber,
|
|
169
212
|
l2SlotNumber,
|
|
170
213
|
l2Epoch,
|
|
171
|
-
|
|
172
|
-
|
|
214
|
+
checkpointNumber: this.checkpointNumber,
|
|
215
|
+
provenCheckpointNumber: this.provenCheckpointNumber,
|
|
173
216
|
totalL2Messages: this.totalL2Messages,
|
|
174
217
|
committee,
|
|
218
|
+
...this.l2FeeData,
|
|
175
219
|
});
|
|
176
220
|
|
|
177
221
|
return this;
|
|
178
222
|
}
|
|
179
223
|
|
|
180
|
-
public waitUntilL2Slot(slot:
|
|
181
|
-
|
|
182
|
-
if (this.l2SlotNumber >= targetSlot) {
|
|
224
|
+
public waitUntilL2Slot(slot: SlotNumber): Promise<void> {
|
|
225
|
+
if (this.l2SlotNumber >= slot) {
|
|
183
226
|
return Promise.resolve();
|
|
184
227
|
}
|
|
185
228
|
return new Promise(resolve => {
|
|
186
|
-
const listener = (data: { l2SlotNumber:
|
|
187
|
-
if (data.l2SlotNumber >=
|
|
229
|
+
const listener = (data: { l2SlotNumber: SlotNumber; timestamp: bigint }) => {
|
|
230
|
+
if (data.l2SlotNumber >= slot) {
|
|
188
231
|
this.off('l2-slot', listener);
|
|
189
232
|
resolve();
|
|
190
233
|
}
|
|
@@ -193,6 +236,11 @@ export class ChainMonitor extends EventEmitter<ChainMonitorEventMap> {
|
|
|
193
236
|
});
|
|
194
237
|
}
|
|
195
238
|
|
|
239
|
+
public async waitUntilNextL2Slot(): Promise<void> {
|
|
240
|
+
const targetSlot = SlotNumber.add((await this.run()).l2SlotNumber, 1);
|
|
241
|
+
return this.waitUntilL2Slot(targetSlot);
|
|
242
|
+
}
|
|
243
|
+
|
|
196
244
|
public waitUntilL1Block(block: number | bigint): Promise<void> {
|
|
197
245
|
const targetBlock = typeof block === 'bigint' ? block.valueOf() : block;
|
|
198
246
|
if (this.l1BlockNumber >= targetBlock) {
|
|
@@ -225,19 +273,118 @@ export class ChainMonitor extends EventEmitter<ChainMonitorEventMap> {
|
|
|
225
273
|
});
|
|
226
274
|
}
|
|
227
275
|
|
|
228
|
-
public
|
|
229
|
-
|
|
230
|
-
if (this.l2BlockNumber >= targetBlock) {
|
|
276
|
+
public waitUntilCheckpoint(checkpointNumber: CheckpointNumber): Promise<void> {
|
|
277
|
+
if (this.checkpointNumber >= checkpointNumber) {
|
|
231
278
|
return Promise.resolve();
|
|
232
279
|
}
|
|
233
280
|
return new Promise(resolve => {
|
|
234
|
-
const listener = (data: {
|
|
235
|
-
if (data.
|
|
236
|
-
this.off('
|
|
281
|
+
const listener = (data: { checkpointNumber: CheckpointNumber; timestamp: bigint }) => {
|
|
282
|
+
if (data.checkpointNumber >= checkpointNumber) {
|
|
283
|
+
this.off('checkpoint', listener);
|
|
237
284
|
resolve();
|
|
238
285
|
}
|
|
239
286
|
};
|
|
240
|
-
this.on('
|
|
287
|
+
this.on('checkpoint', listener);
|
|
241
288
|
});
|
|
242
289
|
}
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* Resolves with the first `checkpoint` event whose payload satisfies `match`. Unlike
|
|
293
|
+
* {@link waitUntilCheckpoint} (which waits for a target number), this lets callers wait for an
|
|
294
|
+
* arbitrary checkpoint property (e.g. one published in the first half of its slot). Rejects after
|
|
295
|
+
* `opts.timeout` ms if provided; otherwise waits indefinitely.
|
|
296
|
+
*
|
|
297
|
+
* By default this is purely event-driven and only resolves on the *next* matching checkpoint that
|
|
298
|
+
* arrives after the call. Set `checkCurrentCheckpoint` to also test the current checkpoint first (via
|
|
299
|
+
* a fresh {@link run} snapshot) and short-circuit if it already satisfies `match`. Use it only for
|
|
300
|
+
* latching state predicates (e.g. "checkpoint number has passed N"), where an already-satisfied
|
|
301
|
+
* result is valid and you want to avoid missing an advance that landed before the listener attached.
|
|
302
|
+
* Do NOT set it when the predicate depends on observing the checkpoint live (e.g. one published
|
|
303
|
+
* mid-slot that the caller then times against wall-clock), since it may return a checkpoint whose
|
|
304
|
+
* slot has already elapsed.
|
|
305
|
+
*/
|
|
306
|
+
public async waitForCheckpoint(
|
|
307
|
+
match: (event: ChainMonitorEventMap['checkpoint'][0]) => boolean,
|
|
308
|
+
opts: { timeout?: number; checkCurrentCheckpoint?: boolean } = {},
|
|
309
|
+
): Promise<ChainMonitorEventMap['checkpoint'][0]> {
|
|
310
|
+
if (opts.checkCurrentCheckpoint) {
|
|
311
|
+
await this.run();
|
|
312
|
+
const current: ChainMonitorEventMap['checkpoint'][0] = {
|
|
313
|
+
checkpointNumber: this.checkpointNumber,
|
|
314
|
+
l1BlockNumber: this.l1BlockNumber,
|
|
315
|
+
l2SlotNumber: this.l2SlotNumber,
|
|
316
|
+
timestamp: this.checkpointTimestamp,
|
|
317
|
+
};
|
|
318
|
+
if (match(current)) {
|
|
319
|
+
return current;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
return new Promise((resolve, reject) => {
|
|
323
|
+
let timer: NodeJS.Timeout | undefined;
|
|
324
|
+
const listener = (event: ChainMonitorEventMap['checkpoint'][0]) => {
|
|
325
|
+
if (match(event)) {
|
|
326
|
+
if (timer) {
|
|
327
|
+
clearTimeout(timer);
|
|
328
|
+
}
|
|
329
|
+
this.off('checkpoint', listener);
|
|
330
|
+
resolve(event);
|
|
331
|
+
}
|
|
332
|
+
};
|
|
333
|
+
if (opts.timeout !== undefined) {
|
|
334
|
+
timer = setTimeout(() => {
|
|
335
|
+
this.off('checkpoint', listener);
|
|
336
|
+
reject(new Error(`Timed out after ${opts.timeout}ms waiting for a matching checkpoint`));
|
|
337
|
+
}, opts.timeout);
|
|
338
|
+
}
|
|
339
|
+
this.on('checkpoint', listener);
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/** Resolves once the proven checkpoint number reaches `checkpointNumber`. */
|
|
344
|
+
public waitUntilCheckpointProven(checkpointNumber: CheckpointNumber): Promise<void> {
|
|
345
|
+
if (this.provenCheckpointNumber >= checkpointNumber) {
|
|
346
|
+
return Promise.resolve();
|
|
347
|
+
}
|
|
348
|
+
return new Promise(resolve => {
|
|
349
|
+
const listener = (data: { provenCheckpointNumber: CheckpointNumber; timestamp: bigint }) => {
|
|
350
|
+
if (data.provenCheckpointNumber >= checkpointNumber) {
|
|
351
|
+
this.off('checkpoint-proven', listener);
|
|
352
|
+
resolve();
|
|
353
|
+
}
|
|
354
|
+
};
|
|
355
|
+
this.on('checkpoint-proven', listener);
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
private async fetchFeeData(timestamp: bigint): Promise<L2FeeData> {
|
|
360
|
+
const [components, minFeePerMana, l1Fees, ethPerFeeAsset, manaTarget] = await Promise.all([
|
|
361
|
+
this.rollup.getManaMinFeeComponentsAt(timestamp, true),
|
|
362
|
+
this.rollup.getManaMinFeeAt(timestamp, true),
|
|
363
|
+
this.rollup.getL1FeesAt(timestamp),
|
|
364
|
+
this.rollup.getEthPerFeeAsset(),
|
|
365
|
+
this.rollup.getManaTarget(),
|
|
366
|
+
]);
|
|
367
|
+
return {
|
|
368
|
+
...components,
|
|
369
|
+
minFeePerMana,
|
|
370
|
+
l1BaseFee: l1Fees.baseFee,
|
|
371
|
+
l1BlobFee: l1Fees.blobFee,
|
|
372
|
+
ethPerFeeAsset,
|
|
373
|
+
manaTarget,
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
private hasFeeDataChanged(newData: L2FeeData): boolean {
|
|
378
|
+
if (!this.l2FeeData) {
|
|
379
|
+
return true;
|
|
380
|
+
}
|
|
381
|
+
return (
|
|
382
|
+
this.l2FeeData.sequencerCost !== newData.sequencerCost ||
|
|
383
|
+
this.l2FeeData.proverCost !== newData.proverCost ||
|
|
384
|
+
this.l2FeeData.congestionCost !== newData.congestionCost ||
|
|
385
|
+
this.l2FeeData.l1BaseFee !== newData.l1BaseFee ||
|
|
386
|
+
this.l2FeeData.l1BlobFee !== newData.l1BlobFee ||
|
|
387
|
+
this.l2FeeData.ethPerFeeAsset !== newData.ethPerFeeAsset
|
|
388
|
+
);
|
|
389
|
+
}
|
|
243
390
|
}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { toBigIntBE, toHex } from '@aztec/foundation/bigint-buffer';
|
|
2
|
-
import { keccak256 } from '@aztec/foundation/crypto';
|
|
2
|
+
import { keccak256 } from '@aztec/foundation/crypto/keccak';
|
|
3
3
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
4
4
|
import { jsonStringify } from '@aztec/foundation/json-rpc';
|
|
5
5
|
import { createLogger } from '@aztec/foundation/log';
|
|
6
6
|
import { pluralize } from '@aztec/foundation/string';
|
|
7
7
|
import type { DateProvider, TestDateProvider } from '@aztec/foundation/timer';
|
|
8
8
|
|
|
9
|
-
import { type Hex, type Transaction, createPublicClient, fallback, hexToNumber, http } from 'viem';
|
|
9
|
+
import { type Chain, type Hex, type Transaction, createPublicClient, fallback, hexToNumber, http } from 'viem';
|
|
10
|
+
import { foundry } from 'viem/chains';
|
|
10
11
|
|
|
11
12
|
import type { ViemPublicClient } from '../types.js';
|
|
12
13
|
|
|
@@ -28,9 +29,14 @@ export class EthCheatCodes {
|
|
|
28
29
|
* The logger to use for the eth cheatcodes
|
|
29
30
|
*/
|
|
30
31
|
public logger = createLogger('ethereum:cheat_codes'),
|
|
32
|
+
/**
|
|
33
|
+
* The chain configuration provided to Anvil
|
|
34
|
+
*/
|
|
35
|
+
public chain: Chain = foundry,
|
|
31
36
|
) {
|
|
32
37
|
this.publicClient = createPublicClient({
|
|
33
|
-
transport: fallback(this.rpcUrls.map(url => http(url))),
|
|
38
|
+
transport: fallback(this.rpcUrls.map(url => http(url, { batch: false }))),
|
|
39
|
+
chain: chain,
|
|
34
40
|
});
|
|
35
41
|
}
|
|
36
42
|
|
|
@@ -79,14 +85,26 @@ export class EthCheatCodes {
|
|
|
79
85
|
}
|
|
80
86
|
|
|
81
87
|
/**
|
|
82
|
-
* Get the
|
|
83
|
-
*
|
|
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
|
|
84
92
|
*/
|
|
85
|
-
public async
|
|
93
|
+
public async lastBlockTimestamp(): Promise<number> {
|
|
86
94
|
const res = await this.doRpcCall('eth_getBlockByNumber', ['latest', true]);
|
|
87
95
|
return parseInt(res.timestamp, 16);
|
|
88
96
|
}
|
|
89
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
|
+
|
|
90
108
|
/**
|
|
91
109
|
* Advance the chain by a number of blocks
|
|
92
110
|
* @param numberOfBlocks - The number of blocks to mine
|
|
@@ -188,6 +206,22 @@ export class EthCheatCodes {
|
|
|
188
206
|
}
|
|
189
207
|
}
|
|
190
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
|
+
|
|
191
225
|
/**
|
|
192
226
|
* Set the automine status of the underlying anvil chain
|
|
193
227
|
* @param automine - The automine status to set
|
|
@@ -460,58 +494,67 @@ export class EthCheatCodes {
|
|
|
460
494
|
}
|
|
461
495
|
|
|
462
496
|
/**
|
|
463
|
-
* Mines
|
|
464
|
-
*
|
|
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".
|
|
508
|
+
*
|
|
509
|
+
* The replacement blocks advance L1 time. `anvil_reorg` stamps each replacement as `parent + N*interval`,
|
|
510
|
+
* so on its own it would freeze L1 time at the parent timestamp; callers that measure elapsed L1 time
|
|
511
|
+
* (L1TxUtils stall/timeout detection, `syncDateProvider`-driven slot advancement) rely on it moving
|
|
512
|
+
* forward. We reproduce the wall-clock advance the mine step just made (at least 1s per block) via a
|
|
513
|
+
* temporary block-timestamp interval, then restore any pre-existing interval.
|
|
465
514
|
*/
|
|
466
515
|
public async mineEmptyBlock(blockCount: number = 1): Promise<void> {
|
|
467
516
|
await this.execWithPausedAnvil(async () => {
|
|
468
|
-
|
|
469
|
-
const
|
|
470
|
-
|
|
471
|
-
this
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
if (rawTx) {
|
|
479
|
-
rawTxs.push(rawTx);
|
|
480
|
-
this.logger.debug(`Got raw tx for ${tx.hash}`);
|
|
481
|
-
} else {
|
|
482
|
-
this.logger.warn(`No raw tx found for ${tx.hash}`);
|
|
483
|
-
}
|
|
484
|
-
} catch {
|
|
485
|
-
this.logger.warn(`Failed to get raw transaction for ${tx.hash}`);
|
|
486
|
-
}
|
|
517
|
+
const originalGasLimit = await this.getBlockGasLimit();
|
|
518
|
+
const parentTimestamp = await this.lastBlockTimestamp();
|
|
519
|
+
// anvil has no getter for the block-timestamp interval, but the pending block is stamped
|
|
520
|
+
// `latest + interval`, so this delta is the standing interval (0 when none is set).
|
|
521
|
+
const priorInterval = (await this.nextBlockTimestamp()) - parentTimestamp;
|
|
522
|
+
try {
|
|
523
|
+
await this.setBlockGasLimit(1n);
|
|
524
|
+
await this.doMine(blockCount);
|
|
525
|
+
} finally {
|
|
526
|
+
await this.setBlockGasLimit(originalGasLimit);
|
|
487
527
|
}
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
//
|
|
492
|
-
await this.doRpcCall('
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
const txHash = await this.doRpcCall('eth_sendRawTransaction', [rawTx]);
|
|
501
|
-
this.logger.debug(`Re-added transaction ${txHash}`);
|
|
502
|
-
} catch (err) {
|
|
503
|
-
this.logger.warn(`Failed to re-add transaction: ${err}`);
|
|
528
|
+
const advance = (await this.lastBlockTimestamp()) - parentTimestamp;
|
|
529
|
+
const perBlockInterval = Math.max(1, Math.floor(advance / blockCount));
|
|
530
|
+
// Replace the tiny-gas-limit blocks with empty blocks at the restored gas limit, keeping the same
|
|
531
|
+
// height. The reorged-out blocks held no transactions, so nothing returns to the pool.
|
|
532
|
+
await this.doRpcCall('anvil_setBlockTimestampInterval', [perBlockInterval]);
|
|
533
|
+
try {
|
|
534
|
+
await this.doRpcCall('anvil_reorg', [blockCount, []]);
|
|
535
|
+
} finally {
|
|
536
|
+
if (priorInterval > 0) {
|
|
537
|
+
await this.doRpcCall('anvil_setBlockTimestampInterval', [priorInterval]);
|
|
538
|
+
} else {
|
|
539
|
+
await this.doRpcCall('anvil_removeBlockTimestampInterval', []);
|
|
504
540
|
}
|
|
505
541
|
}
|
|
506
|
-
|
|
507
|
-
if (rawTxs.length !== txs.length) {
|
|
508
|
-
this.logger.warn(`Failed to add all txs back: had ${txs.length} but re-added ${rawTxs.length}`);
|
|
509
|
-
}
|
|
510
542
|
});
|
|
511
543
|
|
|
512
544
|
this.logger.warn(`Mined ${blockCount} empty L1 ${pluralize('block', blockCount)}`);
|
|
513
545
|
}
|
|
514
546
|
|
|
547
|
+
/** Returns the gas limit of the latest mined L1 block. */
|
|
548
|
+
public async getBlockGasLimit(): Promise<bigint> {
|
|
549
|
+
const block = await this.doRpcCall('eth_getBlockByNumber', ['latest', false]);
|
|
550
|
+
return BigInt(block.gasLimit);
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
/** Sets the block gas limit applied to subsequently mined L1 blocks. */
|
|
554
|
+
public async setBlockGasLimit(gasLimit: bigint): Promise<void> {
|
|
555
|
+
await this.doRpcCall('anvil_setBlockGasLimit', [toHex(gasLimit)]);
|
|
556
|
+
}
|
|
557
|
+
|
|
515
558
|
public async execWithPausedAnvil<T>(fn: () => Promise<T>): Promise<T> {
|
|
516
559
|
const [blockInterval, wasAutoMining] = await Promise.all([this.getIntervalMining(), this.isAutoMining()]);
|
|
517
560
|
try {
|
|
@@ -546,7 +589,7 @@ export class EthCheatCodes {
|
|
|
546
589
|
}
|
|
547
590
|
|
|
548
591
|
public async syncDateProvider() {
|
|
549
|
-
const timestamp = await this.
|
|
592
|
+
const timestamp = await this.lastBlockTimestamp();
|
|
550
593
|
if ('setTime' in this.dateProvider) {
|
|
551
594
|
this.dateProvider.setTime(timestamp * 1000);
|
|
552
595
|
}
|
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';
|