@aztec/aztec 0.0.1-commit.2f68f620 → 0.0.1-commit.321f6a9
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/bin/index.js +2 -0
- package/dest/cli/aztec_start_action.d.ts +1 -1
- package/dest/cli/aztec_start_action.d.ts.map +1 -1
- package/dest/cli/aztec_start_action.js +6 -27
- package/dest/cli/aztec_start_options.js +1 -1
- package/dest/cli/cmds/compile.d.ts +1 -1
- package/dest/cli/cmds/compile.d.ts.map +1 -1
- package/dest/cli/cmds/compile.js +25 -17
- package/dest/cli/cmds/prover.d.ts +4 -0
- package/dest/cli/cmds/prover.d.ts.map +1 -0
- package/dest/cli/cmds/prover.js +24 -0
- package/dest/cli/cmds/standby.d.ts +28 -2
- package/dest/cli/cmds/standby.d.ts.map +1 -1
- package/dest/cli/cmds/standby.js +45 -2
- package/dest/cli/cmds/start_bot.d.ts +1 -1
- package/dest/cli/cmds/start_bot.d.ts.map +1 -1
- package/dest/cli/cmds/start_bot.js +5 -1
- package/dest/cli/cmds/start_node.d.ts +1 -1
- package/dest/cli/cmds/start_node.d.ts.map +1 -1
- package/dest/cli/cmds/start_node.js +14 -23
- package/dest/cli/cmds/utils/artifacts.d.ts +6 -1
- package/dest/cli/cmds/utils/artifacts.d.ts.map +1 -1
- package/dest/cli/util.d.ts +10 -5
- package/dest/cli/util.d.ts.map +1 -1
- package/dest/cli/util.js +20 -49
- package/dest/examples/token.js +3 -3
- package/dest/local-network/local-network.d.ts +6 -5
- package/dest/local-network/local-network.d.ts.map +1 -1
- package/dest/local-network/local-network.js +33 -76
- package/dest/testing/cheat_codes.d.ts +16 -23
- package/dest/testing/cheat_codes.d.ts.map +1 -1
- package/dest/testing/cheat_codes.js +20 -82
- package/dest/testing/epoch_test_settler.d.ts +2 -2
- package/dest/testing/epoch_test_settler.d.ts.map +1 -1
- package/dest/testing/epoch_test_settler.js +5 -26
- package/dest/testing/index.d.ts +2 -2
- package/dest/testing/index.d.ts.map +1 -1
- package/dest/testing/index.js +1 -1
- package/dest/testing/local-network.d.ts +51 -0
- package/dest/testing/local-network.d.ts.map +1 -0
- package/dest/testing/local-network.js +60 -0
- package/dest/testing/token_allowed_setup.d.ts +9 -4
- package/dest/testing/token_allowed_setup.d.ts.map +1 -1
- package/dest/testing/token_allowed_setup.js +12 -8
- package/package.json +34 -34
- package/scripts/templates/counter/contract/src/main.nr +4 -4
- package/src/bin/index.ts +2 -0
- package/src/cli/aztec_start_action.ts +3 -14
- package/src/cli/aztec_start_options.ts +1 -1
- package/src/cli/cmds/compile.ts +29 -16
- package/src/cli/cmds/prover.ts +42 -0
- package/src/cli/cmds/standby.ts +55 -3
- package/src/cli/cmds/start_bot.ts +6 -1
- package/src/cli/cmds/start_node.ts +17 -23
- package/src/cli/cmds/utils/artifacts.ts +5 -0
- package/src/cli/util.ts +21 -62
- package/src/examples/token.ts +11 -3
- package/src/local-network/local-network.ts +40 -88
- package/src/testing/cheat_codes.ts +19 -103
- package/src/testing/epoch_test_settler.ts +8 -30
- package/src/testing/index.ts +1 -1
- package/src/testing/local-network.ts +97 -0
- package/src/testing/token_allowed_setup.ts +15 -8
- package/dest/testing/anvil_test_watcher.d.ts +0 -54
- package/dest/testing/anvil_test_watcher.d.ts.map +0 -1
- package/dest/testing/anvil_test_watcher.js +0 -235
- package/src/testing/anvil_test_watcher.ts +0 -273
|
@@ -1,132 +1,48 @@
|
|
|
1
1
|
import { EthCheatCodes, RollupCheatCodes } from '@aztec/ethereum/test';
|
|
2
|
-
import { SlotNumber } from '@aztec/foundation/branded-types';
|
|
3
|
-
import { createLogger } from '@aztec/foundation/log';
|
|
4
2
|
import type { DateProvider } from '@aztec/foundation/timer';
|
|
5
|
-
import type { AutomineSequencer } from '@aztec/sequencer-client';
|
|
6
3
|
import type { AztecNode, AztecNodeDebug } from '@aztec/stdlib/interfaces/client';
|
|
7
4
|
|
|
8
5
|
/**
|
|
9
|
-
*
|
|
10
|
-
* @deprecated
|
|
11
|
-
* they became unused (we now have better testing tools). If you are introducing a new functionality to the cheat
|
|
12
|
-
* codes, please consider whether it makes sense to just introduce new utils in your tests instead.
|
|
6
|
+
* Wrapper for Aztec Debug API.
|
|
7
|
+
* @deprecated use the AztecNode debug API directly.
|
|
13
8
|
*/
|
|
14
9
|
export class CheatCodes {
|
|
15
|
-
private logger = createLogger('aztecjs:cheat_codes');
|
|
16
|
-
|
|
17
10
|
constructor(
|
|
18
11
|
/** Cheat codes for L1.*/
|
|
19
12
|
public eth: EthCheatCodes,
|
|
20
13
|
/** Cheat codes for the Aztec Rollup contract on L1. */
|
|
21
14
|
public rollup: RollupCheatCodes,
|
|
22
|
-
/** When wired, redirects time-warps through the AutomineSequencer queue (test-only). */
|
|
23
|
-
private automine?: AutomineSequencer,
|
|
24
15
|
) {}
|
|
25
16
|
|
|
26
|
-
static async create(
|
|
27
|
-
rpcUrls: string[],
|
|
28
|
-
node: AztecNode,
|
|
29
|
-
dateProvider: DateProvider,
|
|
30
|
-
automine?: AutomineSequencer,
|
|
31
|
-
): Promise<CheatCodes> {
|
|
17
|
+
static async create(rpcUrls: string[], node: AztecNode, dateProvider: DateProvider): Promise<CheatCodes> {
|
|
32
18
|
const ethCheatCodes = new EthCheatCodes(rpcUrls, dateProvider);
|
|
33
19
|
const rollupCheatCodes = new RollupCheatCodes(
|
|
34
20
|
ethCheatCodes,
|
|
35
21
|
await node.getNodeInfo().then(n => n.l1ContractAddresses),
|
|
36
22
|
);
|
|
37
|
-
return new CheatCodes(ethCheatCodes, rollupCheatCodes
|
|
23
|
+
return new CheatCodes(ethCheatCodes, rollupCheatCodes);
|
|
38
24
|
}
|
|
39
25
|
|
|
40
26
|
/**
|
|
41
|
-
* Warps the L1 timestamp to
|
|
42
|
-
* the target
|
|
43
|
-
*
|
|
44
|
-
* @param
|
|
45
|
-
* @
|
|
27
|
+
* Warps the L1 timestamp to at least `targetTimestamp` and mines an L2 block advancing the L2 timestamp to at least
|
|
28
|
+
* the target. Forwards to the node's debug API, which serializes the warp through the automine sequencer queue.
|
|
29
|
+
* @param node - The Aztec node whose debug API performs the warp. Must run an automine sequencer.
|
|
30
|
+
* @param targetTimestamp - The target timestamp to warp to (in seconds).
|
|
31
|
+
* @deprecated Call `node.warpL2TimeAtLeastTo(targetTimestamp)` on the node debug API directly.
|
|
46
32
|
*/
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const currentTimestamp = BigInt(await this.eth.lastBlockTimestamp());
|
|
50
|
-
|
|
51
|
-
if (targetBigInt <= currentTimestamp) {
|
|
52
|
-
throw new Error(
|
|
53
|
-
`warpL2TimeAtLeastTo: target timestamp ${targetBigInt} is not in the future (current L1 timestamp is ${currentTimestamp}).`,
|
|
54
|
-
);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// AutomineSequencer owns time control through its serial queue — delegate to keep warps atomic
|
|
58
|
-
// with respect to any in-flight build, and avoid the mineBlock-loop hack below.
|
|
59
|
-
// `warpTo` internally builds an empty L2 checkpoint, which auto-mines exactly one L1 block at
|
|
60
|
-
// the target slot boundary, so no separate `node.mineBlock()` is needed here.
|
|
61
|
-
if (this.automine) {
|
|
62
|
-
await this.automine.warpTo(Number(targetBigInt));
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const currentSlot = await this.rollup.getSlot();
|
|
67
|
-
const targetSlot = await this.rollup.getSlotAt(targetBigInt);
|
|
68
|
-
|
|
69
|
-
let effectiveTimestamp = targetBigInt;
|
|
70
|
-
let effectiveTargetSlot = targetSlot;
|
|
71
|
-
|
|
72
|
-
if (targetSlot <= currentSlot) {
|
|
73
|
-
// Target lands in the same (or earlier) slot — auto-adjust to the next slot's start.
|
|
74
|
-
const nextSlot = SlotNumber(currentSlot + 1);
|
|
75
|
-
const nextSlotTimestamp = await this.rollup.getTimestampForSlot(nextSlot);
|
|
76
|
-
this.logger.warn(
|
|
77
|
-
`warpL2TimeAtLeastTo: target timestamp ${targetBigInt} falls in current slot ${currentSlot}. ` +
|
|
78
|
-
`Auto-adjusting to start of slot ${nextSlot} at timestamp ${nextSlotTimestamp}.`,
|
|
79
|
-
);
|
|
80
|
-
effectiveTimestamp = nextSlotTimestamp;
|
|
81
|
-
effectiveTargetSlot = nextSlot;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
await this.eth.warp(effectiveTimestamp, { resetBlockInterval: true });
|
|
85
|
-
|
|
86
|
-
// The sequencer's polling loop may have a `work()` cycle in flight that captured pre-warp slot/timestamp values
|
|
87
|
-
// just before our warp landed. That cycle would mine an L2 block at the stale slot — the L1 sync prunes such a
|
|
88
|
-
// block from the canonical chain, but it lingers in local world state and the PXE will use it as the anchor for
|
|
89
|
-
// subsequent txs, leading to `expiration_timestamp` values that are already in the past relative to L1. Mine
|
|
90
|
-
// until we observe an L2 block at (or past) the post-warp slot, ensuring the next tx anchors to a fresh block.
|
|
91
|
-
const maxAttempts = 5;
|
|
92
|
-
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
|
93
|
-
await node.mineBlock();
|
|
94
|
-
const blockData = await node.getBlockData('latest');
|
|
95
|
-
const blockSlot = blockData?.header.globalVariables.slotNumber;
|
|
96
|
-
if (blockSlot !== undefined && BigInt(blockSlot) >= BigInt(effectiveTargetSlot)) {
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
this.logger.warn(
|
|
100
|
-
`warpL2TimeAtLeastTo: mined L2 block at slot ${blockSlot}, expected at least ${effectiveTargetSlot}. ` +
|
|
101
|
-
`Retrying mineBlock (attempt ${attempt}/${maxAttempts}).`,
|
|
102
|
-
);
|
|
103
|
-
}
|
|
104
|
-
throw new Error(
|
|
105
|
-
`warpL2TimeAtLeastTo: failed to mine an L2 block at or past slot ${effectiveTargetSlot} after ${maxAttempts} attempts.`,
|
|
106
|
-
);
|
|
33
|
+
warpL2TimeAtLeastTo(node: AztecNode & AztecNodeDebug, targetTimestamp: bigint | number): Promise<void> {
|
|
34
|
+
return node.warpL2TimeAtLeastTo(Number(targetTimestamp));
|
|
107
35
|
}
|
|
108
36
|
|
|
109
37
|
/**
|
|
110
|
-
* Warps the L1 timestamp forward by
|
|
111
|
-
* least by the duration.
|
|
112
|
-
*
|
|
113
|
-
* @param node - The Aztec node
|
|
114
|
-
* @param duration - The duration to advance time by (in seconds)
|
|
38
|
+
* Warps the L1 timestamp forward by at least `duration` seconds and mines an L2 block advancing the L2 timestamp at
|
|
39
|
+
* least by the duration. Forwards to the node's debug API, which serializes the warp through the automine sequencer
|
|
40
|
+
* queue.
|
|
41
|
+
* @param node - The Aztec node whose debug API performs the warp. Must run an automine sequencer.
|
|
42
|
+
* @param duration - The duration to advance time by (in seconds).
|
|
43
|
+
* @deprecated Call `node.warpL2TimeAtLeastBy(duration)` on the node debug API directly.
|
|
115
44
|
*/
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
throw new Error(`warpL2TimeAtLeastBy: duration must be positive, got ${duration} seconds.`);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
// Advance relative to whichever clock leads. A live sequencer mines L2 blocks at slot boundaries that can run
|
|
122
|
-
// ahead of anvil's L1 timestamp, so basing the target on L1 alone would advance the L2 timestamp by less than
|
|
123
|
-
// `duration`. Anchoring to the latest L2 block timestamp when it leads guarantees the post-warp L2 block is at
|
|
124
|
-
// least `duration` ahead of the current one.
|
|
125
|
-
const currentL1Timestamp = BigInt(await this.eth.lastBlockTimestamp());
|
|
126
|
-
const latestBlockData = await node.getBlockData('latest');
|
|
127
|
-
const latestL2Timestamp = latestBlockData ? BigInt(latestBlockData.header.globalVariables.timestamp) : 0n;
|
|
128
|
-
const baseTimestamp = latestL2Timestamp > currentL1Timestamp ? latestL2Timestamp : currentL1Timestamp;
|
|
129
|
-
const targetTimestamp = baseTimestamp + BigInt(duration);
|
|
130
|
-
await this.warpL2TimeAtLeastTo(node, targetTimestamp);
|
|
45
|
+
warpL2TimeAtLeastBy(node: AztecNode & AztecNodeDebug, duration: bigint | number): Promise<void> {
|
|
46
|
+
return node.warpL2TimeAtLeastBy(Number(duration));
|
|
131
47
|
}
|
|
132
48
|
}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { Fr } from '@aztec/aztec.js/fields';
|
|
2
1
|
import { type EthCheatCodes, RollupCheatCodes } from '@aztec/ethereum/test';
|
|
3
|
-
import {
|
|
2
|
+
import type { EpochNumber } from '@aztec/foundation/branded-types';
|
|
4
3
|
import type { Logger } from '@aztec/foundation/log';
|
|
4
|
+
import { settleEpochOutbox } from '@aztec/prover-client/test';
|
|
5
5
|
import { EpochMonitor } from '@aztec/prover-node';
|
|
6
6
|
import type { EthAddress, L2BlockSource } from '@aztec/stdlib/block';
|
|
7
|
-
import { computeEpochOutHash } from '@aztec/stdlib/messaging';
|
|
8
7
|
|
|
9
8
|
export class EpochTestSettler {
|
|
10
9
|
private rollupCheatCodes: RollupCheatCodes;
|
|
@@ -31,33 +30,12 @@ export class EpochTestSettler {
|
|
|
31
30
|
}
|
|
32
31
|
|
|
33
32
|
async handleEpochReadyToProve(epoch: EpochNumber): Promise<boolean> {
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
let previousSlotNumber = SlotNumber.ZERO;
|
|
41
|
-
let checkpointIndex = -1;
|
|
42
|
-
|
|
43
|
-
for (const block of blocks) {
|
|
44
|
-
const slotNumber = block.header.globalVariables.slotNumber;
|
|
45
|
-
if (slotNumber !== previousSlotNumber) {
|
|
46
|
-
checkpointIndex++;
|
|
47
|
-
messagesInEpoch[checkpointIndex] = [];
|
|
48
|
-
previousSlotNumber = slotNumber;
|
|
49
|
-
}
|
|
50
|
-
messagesInEpoch[checkpointIndex].push(block.body.txEffects.map(txEffect => txEffect.l2ToL1Msgs));
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const outHash = computeEpochOutHash(messagesInEpoch);
|
|
54
|
-
if (!outHash.isZero()) {
|
|
55
|
-
await this.rollupCheatCodes.insertOutbox(epoch, messagesInEpoch.length, outHash.toBigInt());
|
|
56
|
-
} else {
|
|
57
|
-
this.log.info(`No L2 to L1 messages in epoch ${epoch}`);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const lastCheckpoint = blocks.at(-1)?.checkpointNumber;
|
|
33
|
+
const lastCheckpoint = await settleEpochOutbox({
|
|
34
|
+
rollupCheatCodes: this.rollupCheatCodes,
|
|
35
|
+
l2BlockSource: this.l2BlockSource,
|
|
36
|
+
epoch,
|
|
37
|
+
log: this.log,
|
|
38
|
+
});
|
|
61
39
|
if (lastCheckpoint !== undefined) {
|
|
62
40
|
await this.rollupCheatCodes.markAsProven(lastCheckpoint);
|
|
63
41
|
} else {
|
package/src/testing/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { AnvilTestWatcher, type AnvilTestWatcherOpts } from './anvil_test_watcher.js';
|
|
2
1
|
export { EthCheatCodes, RollupCheatCodes } from '@aztec/ethereum/test';
|
|
3
2
|
export { CheatCodes } from './cheat_codes.js';
|
|
4
3
|
export { EpochTestSettler } from './epoch_test_settler.js';
|
|
4
|
+
export { setupLocalNetwork, TEST_FEE_PADDING, type LocalNetwork, type LocalNetworkOptions } from './local-network.js';
|
|
5
5
|
export { getTokenAllowedSetupFunctions } from './token_allowed_setup.js';
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import type { AztecNodeService } from '@aztec/aztec-node';
|
|
2
|
+
import type { AztecNodeConfig } from '@aztec/aztec-node/config';
|
|
3
|
+
import type { Fr } from '@aztec/aztec.js/fields';
|
|
4
|
+
import { startAnvil } from '@aztec/ethereum/test';
|
|
5
|
+
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
6
|
+
|
|
7
|
+
import { foundry } from 'viem/chains';
|
|
8
|
+
|
|
9
|
+
import { createLocalNetwork } from '../local-network/local-network.js';
|
|
10
|
+
|
|
11
|
+
/** A running in-process local network: an inline Aztec node backed by its own anvil L1. */
|
|
12
|
+
export interface LocalNetwork extends AsyncDisposable {
|
|
13
|
+
/** Fully-synced Aztec node, ready to serve client requests. */
|
|
14
|
+
node: AztecNodeService;
|
|
15
|
+
/** RPC URL of the spawned anvil instance. */
|
|
16
|
+
l1RpcUrl: string;
|
|
17
|
+
/** Chain id used on L1 (foundry's default 31337). */
|
|
18
|
+
l1ChainId: number;
|
|
19
|
+
/** Stops every process started by the fixture: node and anvil. Also invoked by `await using`. */
|
|
20
|
+
stop: () => Promise<void>;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Options for {@link setupLocalNetwork}. */
|
|
24
|
+
export interface LocalNetworkOptions {
|
|
25
|
+
/**
|
|
26
|
+
* Addresses that should hold fee juice at genesis. Saves each of these the round-trip of bridging
|
|
27
|
+
* + claiming fee juice before they can pay for gas.
|
|
28
|
+
*/
|
|
29
|
+
fundedAddresses?: AztecAddress[];
|
|
30
|
+
/** Override the default per-address genesis fee juice granted to {@link fundedAddresses}. */
|
|
31
|
+
initialAccountFeeJuice?: Fr;
|
|
32
|
+
/** Node config overrides, e.g. `realProofs`, `aztecEpochDuration`, `p2pEnabled`. */
|
|
33
|
+
config?: Partial<AztecNodeConfig>;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Spin up an in-process local network with the given addresses pre-funded.
|
|
38
|
+
*
|
|
39
|
+
* Each call spawns its own anvil on an OS-assigned random port and runs the Aztec node inline via
|
|
40
|
+
* the same {@link createLocalNetwork} codepath that backs `aztec start --local-network` (with the
|
|
41
|
+
* sandbox account/FPC/token setup skipped). Distinct ports let independent suites run in parallel.
|
|
42
|
+
* The caller must `await result.stop()` in its teardown (or hold the result with `await using`).
|
|
43
|
+
*
|
|
44
|
+
* Requires a Foundry toolchain (`anvil`/`forge`), installed via `aztec-up` or `foundryup`. Binaries
|
|
45
|
+
* are located in the standard install directories or on `PATH`; set `$ANVIL_BIN` / `$FORGE_BIN` to
|
|
46
|
+
* pin specific ones.
|
|
47
|
+
*/
|
|
48
|
+
export async function setupLocalNetwork(opts: LocalNetworkOptions = {}): Promise<LocalNetwork> {
|
|
49
|
+
// `--port 0` → anvil binds an ephemeral port that `startAnvil` reads back, so parallel suites
|
|
50
|
+
// never collide on a fixed port.
|
|
51
|
+
const { rpcUrl, stop: stopAnvil } = await startAnvil({ port: 0 });
|
|
52
|
+
|
|
53
|
+
try {
|
|
54
|
+
const { node, stop: stopNode } = await createLocalNetwork(
|
|
55
|
+
{
|
|
56
|
+
...opts.config,
|
|
57
|
+
l1RpcUrls: [rpcUrl],
|
|
58
|
+
testAccounts: false,
|
|
59
|
+
prefundAddresses: (opts.fundedAddresses ?? []).map(a => a.toString()),
|
|
60
|
+
initialAccountFeeJuice: opts.initialAccountFeeJuice,
|
|
61
|
+
},
|
|
62
|
+
() => {},
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
// Stop the node before anvil (its teardown still talks to L1); the finally guarantees anvil is
|
|
66
|
+
// reaped even if node shutdown throws.
|
|
67
|
+
const stop = async () => {
|
|
68
|
+
try {
|
|
69
|
+
await stopNode();
|
|
70
|
+
} finally {
|
|
71
|
+
await stopAnvil();
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
return {
|
|
76
|
+
node,
|
|
77
|
+
l1RpcUrl: rpcUrl,
|
|
78
|
+
l1ChainId: foundry.id,
|
|
79
|
+
stop,
|
|
80
|
+
[Symbol.asyncDispose]: stop,
|
|
81
|
+
};
|
|
82
|
+
} catch (err) {
|
|
83
|
+
await stopAnvil();
|
|
84
|
+
throw err;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Min-fee padding multiplier for test wallets whose txs may mine well after their fee estimate.
|
|
90
|
+
* The automine sequencer builds one block per tx and advances L1 time in big jumps, and proposer
|
|
91
|
+
* pipelining evolves the fee-asset price across the build/publish gap (~20x observed in CI), so the
|
|
92
|
+
* network's congestion base fee can swing sharply between the wallet's fee estimate and the block
|
|
93
|
+
* the tx actually lands in. The default wallet padding isn't enough and trips
|
|
94
|
+
* `maxFeesPerGas.feePerL2Gas must be >= gasFees.feePerL2Gas`. Apply via
|
|
95
|
+
* `wallet.setMinFeePadding(TEST_FEE_PADDING)` on every test wallet that sends txs.
|
|
96
|
+
*/
|
|
97
|
+
export const TEST_FEE_PADDING = 30;
|
|
@@ -1,19 +1,26 @@
|
|
|
1
1
|
import { TokenContractArtifact } from '@aztec/noir-contracts.js/Token';
|
|
2
2
|
import { buildAllowedElement } from '@aztec/p2p/msg_validators';
|
|
3
|
+
import type { ContractArtifact } from '@aztec/stdlib/abi';
|
|
3
4
|
import { getContractClassFromArtifact } from '@aztec/stdlib/contract';
|
|
4
5
|
import type { AllowedElement } from '@aztec/stdlib/interfaces/server';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
|
-
* Returns
|
|
8
|
-
*
|
|
8
|
+
* Returns the allowlist entries needed for FPC-based fee payments, keyed by the contract class of
|
|
9
|
+
* the `artifact` actually deployed as the fee token (defaults to canonical Token). The setup-phase
|
|
10
|
+
* validator matches these entries by class id, so a test deploying the codegen'd TestToken as its
|
|
11
|
+
* fee vehicle must pass `TestTokenContract.artifact` here -- otherwise the FPC fee calls are matched
|
|
12
|
+
* against the wrong class and rejected. Test-only: FPC fee payment with custom tokens won't work on
|
|
13
|
+
* mainnet alpha.
|
|
9
14
|
*/
|
|
10
|
-
export async function getTokenAllowedSetupFunctions(
|
|
11
|
-
|
|
15
|
+
export async function getTokenAllowedSetupFunctions(
|
|
16
|
+
artifact: ContractArtifact = TokenContractArtifact,
|
|
17
|
+
): Promise<AllowedElement[]> {
|
|
18
|
+
const tokenClassId = (await getContractClassFromArtifact(artifact)).id;
|
|
12
19
|
const target = { classId: tokenClassId };
|
|
13
20
|
return Promise.all([
|
|
14
|
-
//
|
|
15
|
-
buildAllowedElement(
|
|
16
|
-
//
|
|
17
|
-
buildAllowedElement(
|
|
21
|
+
// needed for private transfers via FPC (transfer_to_public enqueues this)
|
|
22
|
+
buildAllowedElement(artifact, target, '_increase_public_balance', { onlySelf: true }),
|
|
23
|
+
// needed for public transfers via FPC (fee_entrypoint_public enqueues this)
|
|
24
|
+
buildAllowedElement(artifact, target, 'transfer_in_public'),
|
|
18
25
|
]);
|
|
19
26
|
}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { EthCheatCodes } from '@aztec/ethereum/test';
|
|
2
|
-
import type { ViemClient } from '@aztec/ethereum/types';
|
|
3
|
-
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
4
|
-
import type { TestDateProvider } from '@aztec/foundation/timer';
|
|
5
|
-
export type AnvilTestWatcherOpts = {
|
|
6
|
-
isLocalNetwork?: boolean;
|
|
7
|
-
isMarkingAsProven?: boolean;
|
|
8
|
-
};
|
|
9
|
-
/**
|
|
10
|
-
* Represents a watcher for a rollup contract.
|
|
11
|
-
*
|
|
12
|
-
* It started on a network like anvil where time traveling is allowed, and auto-mine is turned on
|
|
13
|
-
* it will periodically check if the current slot have already been filled, e.g., there was an L2
|
|
14
|
-
* block within the slot. And if so, it will time travel into the next slot.
|
|
15
|
-
*/
|
|
16
|
-
export declare class AnvilTestWatcher {
|
|
17
|
-
private cheatcodes;
|
|
18
|
-
private dateProvider?;
|
|
19
|
-
private isLocalNetwork;
|
|
20
|
-
private isMarkingAsProven;
|
|
21
|
-
private rollup;
|
|
22
|
-
private rollupCheatCodes;
|
|
23
|
-
private l2SlotDuration;
|
|
24
|
-
private filledRunningPromise?;
|
|
25
|
-
private syncDateProviderPromise?;
|
|
26
|
-
private markingAsProvenRunningPromise?;
|
|
27
|
-
private logger;
|
|
28
|
-
private getPendingTxCount?;
|
|
29
|
-
private isSequencerBuilding?;
|
|
30
|
-
private unfilledSlotFirstSeen?;
|
|
31
|
-
private proposedTargetSlot?;
|
|
32
|
-
constructor(cheatcodes: EthCheatCodes, rollupAddress: EthAddress, l1Client: ViemClient, dateProvider?: TestDateProvider | undefined, opts?: AnvilTestWatcherOpts);
|
|
33
|
-
setIsMarkingAsProven(isMarkingAsProven: boolean): void;
|
|
34
|
-
setisLocalNetwork(isLocalNetwork: boolean): void;
|
|
35
|
-
/** Sets a callback to check for pending txs, used to skip unfilled slots faster when txs are waiting. */
|
|
36
|
-
setGetPendingTxCount(fn: () => Promise<number>): void;
|
|
37
|
-
/** Sets a callback to check if the sequencer is actively building, to avoid warping while it works. */
|
|
38
|
-
setIsSequencerBuilding(fn: () => boolean): void;
|
|
39
|
-
/**
|
|
40
|
-
* Records the target slot for which the proposer has built a block destined for L1. Used by
|
|
41
|
-
* the local-network watcher to fast-forward L1 (and the injected date provider) ahead of the
|
|
42
|
-
* pipelined publisher's `sendRequestsAt` sleep so it ends promptly instead of waiting a full
|
|
43
|
-
* wall-clock slot. Only ratchets up — late warps for stale slots are no-ops.
|
|
44
|
-
*/
|
|
45
|
-
setProposedTargetSlot(slot: number): void;
|
|
46
|
-
start(): Promise<void>;
|
|
47
|
-
stop(): Promise<void>;
|
|
48
|
-
trigger(): Promise<void>;
|
|
49
|
-
markAsProven(): Promise<void>;
|
|
50
|
-
syncDateProviderToL1IfBehind(): Promise<void>;
|
|
51
|
-
warpTimeIfNeeded(): Promise<void>;
|
|
52
|
-
private warpToTimestamp;
|
|
53
|
-
}
|
|
54
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYW52aWxfdGVzdF93YXRjaGVyLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvdGVzdGluZy9hbnZpbF90ZXN0X3dhdGNoZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLGFBQWEsRUFBb0IsTUFBTSxzQkFBc0IsQ0FBQztBQUN2RSxPQUFPLEtBQUssRUFBRSxVQUFVLEVBQUUsTUFBTSx1QkFBdUIsQ0FBQztBQUV4RCxPQUFPLEtBQUssRUFBRSxVQUFVLEVBQUUsTUFBTSwrQkFBK0IsQ0FBQztBQUdoRSxPQUFPLEtBQUssRUFBRSxnQkFBZ0IsRUFBRSxNQUFNLHlCQUF5QixDQUFDO0FBS2hFLE1BQU0sTUFBTSxvQkFBb0IsR0FBRztJQUNqQyxjQUFjLENBQUMsRUFBRSxPQUFPLENBQUM7SUFDekIsaUJBQWlCLENBQUMsRUFBRSxPQUFPLENBQUM7Q0FDN0IsQ0FBQztBQUVGOzs7Ozs7R0FNRztBQUNILHFCQUFhLGdCQUFnQjtJQThCekIsT0FBTyxDQUFDLFVBQVU7SUFHbEIsT0FBTyxDQUFDLFlBQVksQ0FBQztJQWhDdkIsT0FBTyxDQUFDLGNBQWMsQ0FBQztJQUN2QixPQUFPLENBQUMsaUJBQWlCLENBQUM7SUFFMUIsT0FBTyxDQUFDLE1BQU0sQ0FBc0Q7SUFDcEUsT0FBTyxDQUFDLGdCQUFnQixDQUFtQjtJQUMzQyxPQUFPLENBQUMsY0FBYyxDQUFVO0lBRWhDLE9BQU8sQ0FBQyxvQkFBb0IsQ0FBQyxDQUFpQjtJQUM5QyxPQUFPLENBQUMsdUJBQXVCLENBQUMsQ0FBaUI7SUFDakQsT0FBTyxDQUFDLDZCQUE2QixDQUFDLENBQWlCO0lBRXZELE9BQU8sQ0FBQyxNQUFNLENBQWlEO0lBRy9ELE9BQU8sQ0FBQyxpQkFBaUIsQ0FBQyxDQUF3QjtJQUdsRCxPQUFPLENBQUMsbUJBQW1CLENBQUMsQ0FBZ0I7SUFHNUMsT0FBTyxDQUFDLHFCQUFxQixDQUFDLENBQXFDO0lBTW5FLE9BQU8sQ0FBQyxrQkFBa0IsQ0FBQyxDQUFTO0lBRXBDLFlBQ1UsVUFBVSxFQUFFLGFBQWEsRUFDakMsYUFBYSxFQUFFLFVBQVUsRUFDekIsUUFBUSxFQUFFLFVBQVUsRUFDWixZQUFZLENBQUMsOEJBQWtCLEVBQ3ZDLElBQUksR0FBRSxvQkFBeUIsRUFnQmhDO0lBRUQsb0JBQW9CLENBQUMsaUJBQWlCLEVBQUUsT0FBTyxRQUc5QztJQUVELGlCQUFpQixDQUFDLGNBQWMsRUFBRSxPQUFPLFFBRXhDO0lBRUQseUdBQXlHO0lBQ3pHLG9CQUFvQixDQUFDLEVBQUUsRUFBRSxNQUFNLE9BQU8sQ0FBQyxNQUFNLENBQUMsUUFFN0M7SUFFRCx1R0FBdUc7SUFDdkcsc0JBQXNCLENBQUMsRUFBRSxFQUFFLE1BQU0sT0FBTyxRQUV2QztJQUVEOzs7OztPQUtHO0lBQ0gscUJBQXFCLENBQUMsSUFBSSxFQUFFLE1BQU0sUUFJakM7SUFFSyxLQUFLLGtCQXlCVjtJQUVLLElBQUksa0JBSVQ7SUFFSyxPQUFPLGtCQUlaO0lBRUssWUFBWSxrQkFLakI7SUFFSyw0QkFBNEIsa0JBc0JqQztJQUVLLGdCQUFnQixrQkEwRXJCO1lBTWEsZUFBZTtDQWdCOUIifQ==
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"anvil_test_watcher.d.ts","sourceRoot":"","sources":["../../src/testing/anvil_test_watcher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAoB,MAAM,sBAAsB,CAAC;AACvE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAExD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAGhE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAKhE,MAAM,MAAM,oBAAoB,GAAG;IACjC,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B,CAAC;AAEF;;;;;;GAMG;AACH,qBAAa,gBAAgB;IA8BzB,OAAO,CAAC,UAAU;IAGlB,OAAO,CAAC,YAAY,CAAC;IAhCvB,OAAO,CAAC,cAAc,CAAC;IACvB,OAAO,CAAC,iBAAiB,CAAC;IAE1B,OAAO,CAAC,MAAM,CAAsD;IACpE,OAAO,CAAC,gBAAgB,CAAmB;IAC3C,OAAO,CAAC,cAAc,CAAU;IAEhC,OAAO,CAAC,oBAAoB,CAAC,CAAiB;IAC9C,OAAO,CAAC,uBAAuB,CAAC,CAAiB;IACjD,OAAO,CAAC,6BAA6B,CAAC,CAAiB;IAEvD,OAAO,CAAC,MAAM,CAAiD;IAG/D,OAAO,CAAC,iBAAiB,CAAC,CAAwB;IAGlD,OAAO,CAAC,mBAAmB,CAAC,CAAgB;IAG5C,OAAO,CAAC,qBAAqB,CAAC,CAAqC;IAMnE,OAAO,CAAC,kBAAkB,CAAC,CAAS;IAEpC,YACU,UAAU,EAAE,aAAa,EACjC,aAAa,EAAE,UAAU,EACzB,QAAQ,EAAE,UAAU,EACZ,YAAY,CAAC,8BAAkB,EACvC,IAAI,GAAE,oBAAyB,EAgBhC;IAED,oBAAoB,CAAC,iBAAiB,EAAE,OAAO,QAG9C;IAED,iBAAiB,CAAC,cAAc,EAAE,OAAO,QAExC;IAED,yGAAyG;IACzG,oBAAoB,CAAC,EAAE,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,QAE7C;IAED,uGAAuG;IACvG,sBAAsB,CAAC,EAAE,EAAE,MAAM,OAAO,QAEvC;IAED;;;;;OAKG;IACH,qBAAqB,CAAC,IAAI,EAAE,MAAM,QAIjC;IAEK,KAAK,kBAyBV;IAEK,IAAI,kBAIT;IAEK,OAAO,kBAIZ;IAEK,YAAY,kBAKjB;IAEK,4BAA4B,kBAsBjC;IAEK,gBAAgB,kBA0ErB;YAMa,eAAe;CAgB9B"}
|
|
@@ -1,235 +0,0 @@
|
|
|
1
|
-
import { RollupCheatCodes } from '@aztec/ethereum/test';
|
|
2
|
-
import { SlotNumber } from '@aztec/foundation/branded-types';
|
|
3
|
-
import { createLogger } from '@aztec/foundation/log';
|
|
4
|
-
import { RunningPromise } from '@aztec/foundation/running-promise';
|
|
5
|
-
import { RollupAbi } from '@aztec/l1-artifacts/RollupAbi';
|
|
6
|
-
import { getAddress, getContract } from 'viem';
|
|
7
|
-
/**
|
|
8
|
-
* Represents a watcher for a rollup contract.
|
|
9
|
-
*
|
|
10
|
-
* It started on a network like anvil where time traveling is allowed, and auto-mine is turned on
|
|
11
|
-
* it will periodically check if the current slot have already been filled, e.g., there was an L2
|
|
12
|
-
* block within the slot. And if so, it will time travel into the next slot.
|
|
13
|
-
*/ export class AnvilTestWatcher {
|
|
14
|
-
cheatcodes;
|
|
15
|
-
dateProvider;
|
|
16
|
-
isLocalNetwork;
|
|
17
|
-
isMarkingAsProven;
|
|
18
|
-
rollup;
|
|
19
|
-
rollupCheatCodes;
|
|
20
|
-
l2SlotDuration;
|
|
21
|
-
filledRunningPromise;
|
|
22
|
-
syncDateProviderPromise;
|
|
23
|
-
markingAsProvenRunningPromise;
|
|
24
|
-
logger;
|
|
25
|
-
// Optional callback to check if there are pending txs in the mempool.
|
|
26
|
-
getPendingTxCount;
|
|
27
|
-
// Optional callback to check if the sequencer is actively building a block.
|
|
28
|
-
isSequencerBuilding;
|
|
29
|
-
// Tracks when we first observed the current unfilled slot with pending txs (real wall time).
|
|
30
|
-
unfilledSlotFirstSeen;
|
|
31
|
-
// Latest target slot for which the proposer has built a block destined for L1 but which has
|
|
32
|
-
// not yet been committed. Set by the proposer-pipelining hook from `block-proposed` events so
|
|
33
|
-
// the watcher can advance L1 (and the injected date provider) to the target slot ahead of the
|
|
34
|
-
// publisher's `sendRequestsAt` sleep, instead of waiting a full wall-clock slot.
|
|
35
|
-
proposedTargetSlot;
|
|
36
|
-
constructor(cheatcodes, rollupAddress, l1Client, dateProvider, opts = {}){
|
|
37
|
-
this.cheatcodes = cheatcodes;
|
|
38
|
-
this.dateProvider = dateProvider;
|
|
39
|
-
this.logger = createLogger(`aztecjs:utils:watcher`);
|
|
40
|
-
this.rollup = getContract({
|
|
41
|
-
address: getAddress(rollupAddress.toString()),
|
|
42
|
-
abi: RollupAbi,
|
|
43
|
-
client: l1Client
|
|
44
|
-
});
|
|
45
|
-
this.rollupCheatCodes = new RollupCheatCodes(this.cheatcodes, {
|
|
46
|
-
rollupAddress
|
|
47
|
-
});
|
|
48
|
-
this.isLocalNetwork = opts.isLocalNetwork ?? false;
|
|
49
|
-
this.isMarkingAsProven = opts.isMarkingAsProven ?? true;
|
|
50
|
-
this.logger.debug(`Watcher created for rollup at ${rollupAddress}`);
|
|
51
|
-
}
|
|
52
|
-
setIsMarkingAsProven(isMarkingAsProven) {
|
|
53
|
-
this.logger.warn(`Watcher is now ${isMarkingAsProven ? 'marking' : 'not marking'} blocks as proven`);
|
|
54
|
-
this.isMarkingAsProven = isMarkingAsProven;
|
|
55
|
-
}
|
|
56
|
-
setisLocalNetwork(isLocalNetwork) {
|
|
57
|
-
this.isLocalNetwork = isLocalNetwork;
|
|
58
|
-
}
|
|
59
|
-
/** Sets a callback to check for pending txs, used to skip unfilled slots faster when txs are waiting. */ setGetPendingTxCount(fn) {
|
|
60
|
-
this.getPendingTxCount = fn;
|
|
61
|
-
}
|
|
62
|
-
/** Sets a callback to check if the sequencer is actively building, to avoid warping while it works. */ setIsSequencerBuilding(fn) {
|
|
63
|
-
this.isSequencerBuilding = fn;
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Records the target slot for which the proposer has built a block destined for L1. Used by
|
|
67
|
-
* the local-network watcher to fast-forward L1 (and the injected date provider) ahead of the
|
|
68
|
-
* pipelined publisher's `sendRequestsAt` sleep so it ends promptly instead of waiting a full
|
|
69
|
-
* wall-clock slot. Only ratchets up — late warps for stale slots are no-ops.
|
|
70
|
-
*/ setProposedTargetSlot(slot) {
|
|
71
|
-
if (this.proposedTargetSlot === undefined || slot > this.proposedTargetSlot) {
|
|
72
|
-
this.proposedTargetSlot = slot;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
async start() {
|
|
76
|
-
if (this.filledRunningPromise) {
|
|
77
|
-
throw new Error('Watcher already watching for filled slot');
|
|
78
|
-
}
|
|
79
|
-
const config = await this.rollupCheatCodes.getConfig();
|
|
80
|
-
this.l2SlotDuration = config.slotDuration;
|
|
81
|
-
// If auto mining is not supported (e.g., we are on a real network), then we
|
|
82
|
-
// will simple do nothing. But if on an anvil or the like, this make sure that
|
|
83
|
-
// the local network and tests don't break because time is frozen and we never get to
|
|
84
|
-
// the next slot.
|
|
85
|
-
const isAutoMining = await this.cheatcodes.isAutoMining();
|
|
86
|
-
if (isAutoMining) {
|
|
87
|
-
this.filledRunningPromise = new RunningPromise(()=>this.warpTimeIfNeeded(), this.logger, 200);
|
|
88
|
-
this.filledRunningPromise.start();
|
|
89
|
-
this.syncDateProviderPromise = new RunningPromise(()=>this.syncDateProviderToL1IfBehind(), this.logger, 200);
|
|
90
|
-
this.syncDateProviderPromise.start();
|
|
91
|
-
this.markingAsProvenRunningPromise = new RunningPromise(()=>this.markAsProven(), this.logger, 200);
|
|
92
|
-
this.markingAsProvenRunningPromise.start();
|
|
93
|
-
this.logger.info(`Watcher started for rollup at ${this.rollup.address}`);
|
|
94
|
-
} else {
|
|
95
|
-
this.logger.info(`Watcher not started because not auto mining`);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
async stop() {
|
|
99
|
-
await this.filledRunningPromise?.stop();
|
|
100
|
-
await this.syncDateProviderPromise?.stop();
|
|
101
|
-
await this.markingAsProvenRunningPromise?.stop();
|
|
102
|
-
}
|
|
103
|
-
async trigger() {
|
|
104
|
-
await this.filledRunningPromise?.trigger();
|
|
105
|
-
await this.syncDateProviderPromise?.trigger();
|
|
106
|
-
await this.markingAsProvenRunningPromise?.trigger();
|
|
107
|
-
}
|
|
108
|
-
async markAsProven() {
|
|
109
|
-
if (!this.isMarkingAsProven) {
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
await this.rollupCheatCodes.markAsProven();
|
|
113
|
-
}
|
|
114
|
-
async syncDateProviderToL1IfBehind() {
|
|
115
|
-
// this doesn't apply to the local network, because we don't have a date provider in the local network
|
|
116
|
-
if (!this.dateProvider) {
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
const l1Time = await this.cheatcodes.lastBlockTimestamp() * 1000;
|
|
120
|
-
const wallTime = this.dateProvider.now();
|
|
121
|
-
if (l1Time > wallTime) {
|
|
122
|
-
this.logger.warn(`L1 is ahead of wall time. Syncing wall time to L1 time`);
|
|
123
|
-
this.dateProvider.setTime(l1Time);
|
|
124
|
-
} else if (l1Time + Number(this.l2SlotDuration) * 1000 < wallTime) {
|
|
125
|
-
// Warp L1 to the slot boundary at-or-before wall time. Rounding to a slot boundary (rather than
|
|
126
|
-
// `ceil(wallTime / 1000)`) keeps this loop's target aligned with `warpTimeIfNeeded`'s
|
|
127
|
-
// `nextSlotTimestamp` target, avoiding a race where the two loops pick timestamps a fraction of
|
|
128
|
-
// a second apart and one of them is then rejected by anvil as non-monotonic.
|
|
129
|
-
const wallSec = Math.floor(wallTime / 1000);
|
|
130
|
-
const targetSlot = await this.rollup.read.getSlotAt([
|
|
131
|
-
BigInt(wallSec)
|
|
132
|
-
]);
|
|
133
|
-
const targetTimestamp = Number(await this.rollup.read.getTimestampForSlot([
|
|
134
|
-
targetSlot
|
|
135
|
-
]));
|
|
136
|
-
this.logger.warn(`L1 is more than 1 L2 slot behind wall time. Warping to slot ${targetSlot} boundary`);
|
|
137
|
-
await this.warpToTimestamp(targetTimestamp);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
async warpTimeIfNeeded() {
|
|
141
|
-
try {
|
|
142
|
-
const currentSlot = SlotNumber.fromBigInt(await this.rollup.read.getCurrentSlot());
|
|
143
|
-
const pendingCheckpointNumber = await this.rollup.read.getPendingCheckpointNumber();
|
|
144
|
-
const checkpointLog = await this.rollup.read.getCheckpoint([
|
|
145
|
-
pendingCheckpointNumber
|
|
146
|
-
]);
|
|
147
|
-
const nextSlot = SlotNumber(currentSlot + 1);
|
|
148
|
-
const nextSlotTimestamp = Number(await this.rollup.read.getTimestampForSlot([
|
|
149
|
-
BigInt(nextSlot)
|
|
150
|
-
]));
|
|
151
|
-
if (BigInt(currentSlot) === checkpointLog.slotNumber) {
|
|
152
|
-
// The current slot has been filled, we should jump to the next slot.
|
|
153
|
-
if (await this.warpToTimestamp(nextSlotTimestamp)) {
|
|
154
|
-
this.logger.info(`Slot ${currentSlot} was filled, jumped to next slot`);
|
|
155
|
-
}
|
|
156
|
-
return;
|
|
157
|
-
}
|
|
158
|
-
// If we are not in local network, we don't need to warp time
|
|
159
|
-
if (!this.isLocalNetwork) {
|
|
160
|
-
return;
|
|
161
|
-
}
|
|
162
|
-
// Pipelined-publish shortcut: if the proposer has built a block destined for a slot
|
|
163
|
-
// beyond the current L1 slot, fast-forward L1 to that slot's timestamp so the publisher's
|
|
164
|
-
// `sendRequestsAt(targetSlot)` sleep ends and the multicall mines inside the target slot.
|
|
165
|
-
// Without this, the publisher waits up to a full real-time slot for wall clock to catch up.
|
|
166
|
-
if (this.proposedTargetSlot !== undefined && this.proposedTargetSlot > currentSlot) {
|
|
167
|
-
const targetSlotTimestamp = Number(await this.rollup.read.getTimestampForSlot([
|
|
168
|
-
BigInt(this.proposedTargetSlot)
|
|
169
|
-
]));
|
|
170
|
-
if (await this.warpToTimestamp(targetSlotTimestamp)) {
|
|
171
|
-
this.logger.info(`Warped L1 to target slot ${this.proposedTargetSlot} for pipelined publish`);
|
|
172
|
-
}
|
|
173
|
-
return;
|
|
174
|
-
}
|
|
175
|
-
// If there are pending txs and the sequencer missed them, warp quickly (after a 2s real-time debounce) so the
|
|
176
|
-
// sequencer can retry in the next slot. Without this, we'd have to wait a full real-time slot duration (~36s) for
|
|
177
|
-
// the dateProvider to catch up to the next slot timestamp. We skip the warp if the sequencer is actively building
|
|
178
|
-
// to avoid invalidating its in-progress work.
|
|
179
|
-
if (this.getPendingTxCount) {
|
|
180
|
-
const pendingTxs = await this.getPendingTxCount();
|
|
181
|
-
if (pendingTxs > 0) {
|
|
182
|
-
if (this.isSequencerBuilding?.()) {
|
|
183
|
-
this.unfilledSlotFirstSeen = undefined;
|
|
184
|
-
return;
|
|
185
|
-
}
|
|
186
|
-
const realNow = Date.now();
|
|
187
|
-
if (!this.unfilledSlotFirstSeen || this.unfilledSlotFirstSeen.slot !== currentSlot) {
|
|
188
|
-
this.unfilledSlotFirstSeen = {
|
|
189
|
-
slot: currentSlot,
|
|
190
|
-
realTime: realNow
|
|
191
|
-
};
|
|
192
|
-
return;
|
|
193
|
-
}
|
|
194
|
-
if (realNow - this.unfilledSlotFirstSeen.realTime > 2000) {
|
|
195
|
-
if (await this.warpToTimestamp(nextSlotTimestamp)) {
|
|
196
|
-
this.logger.info(`Slot ${currentSlot} was missed with pending txs, jumped to next slot`);
|
|
197
|
-
}
|
|
198
|
-
this.unfilledSlotFirstSeen = undefined;
|
|
199
|
-
}
|
|
200
|
-
return;
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
// Fallback: warp when the dateProvider time has passed the next slot timestamp.
|
|
204
|
-
const currentTimestamp = this.dateProvider?.now() ?? Date.now();
|
|
205
|
-
if (currentTimestamp > nextSlotTimestamp * 1000) {
|
|
206
|
-
if (await this.warpToTimestamp(nextSlotTimestamp)) {
|
|
207
|
-
this.logger.info(`Slot ${currentSlot} was missed, jumped to next slot`);
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
} catch {
|
|
211
|
-
this.logger.error('mineIfSlotFilled failed');
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
/**
|
|
215
|
-
* Warps L1 to `timestamp`, unless L1 is already at or past it. Returns true when a warp actually
|
|
216
|
-
* happened, false when skipped or on error. Callers use the return value to gate success logs.
|
|
217
|
-
*/ async warpToTimestamp(timestamp) {
|
|
218
|
-
try {
|
|
219
|
-
// Anvil rejects evm_setNextBlockTimestamp values <= the current block's timestamp. The two
|
|
220
|
-
// watcher loops can race and pick targets a fraction of a second apart; skip here rather than
|
|
221
|
-
// letting the second one error out noisily.
|
|
222
|
-
const lastTimestamp = await this.cheatcodes.lastBlockTimestamp();
|
|
223
|
-
if (timestamp <= lastTimestamp) {
|
|
224
|
-
return false;
|
|
225
|
-
}
|
|
226
|
-
await this.cheatcodes.warp(timestamp, {
|
|
227
|
-
resetBlockInterval: true
|
|
228
|
-
});
|
|
229
|
-
return true;
|
|
230
|
-
} catch (e) {
|
|
231
|
-
this.logger.error(`Failed to warp to timestamp ${timestamp}: ${e}`);
|
|
232
|
-
return false;
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
}
|