@aztec/aztec 5.0.0-private.20260319 → 5.0.0-rc.1
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 +1 -1
- 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 +16 -24
- package/dest/cli/aztec_start_options.d.ts +2 -2
- package/dest/cli/aztec_start_options.d.ts.map +1 -1
- package/dest/cli/aztec_start_options.js +14 -14
- 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 +8 -8
- package/dest/cli/cmds/profile.d.ts +1 -1
- package/dest/cli/cmds/profile.d.ts.map +1 -1
- package/dest/cli/cmds/profile.js +1 -1
- package/dest/cli/cmds/profile_gates.d.ts +2 -2
- package/dest/cli/cmds/profile_gates.d.ts.map +1 -1
- package/dest/cli/cmds/profile_gates.js +21 -3
- package/dest/cli/cmds/standby.d.ts +3 -5
- package/dest/cli/cmds/standby.d.ts.map +1 -1
- package/dest/cli/cmds/standby.js +3 -3
- 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 +8 -4
- 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 +13 -40
- package/dest/cli/cmds/start_prover_agent.d.ts +1 -1
- package/dest/cli/cmds/start_prover_agent.d.ts.map +1 -1
- package/dest/cli/cmds/start_prover_agent.js +5 -17
- package/dest/cli/cmds/start_prover_broker.d.ts +1 -1
- package/dest/cli/cmds/start_prover_broker.d.ts.map +1 -1
- package/dest/cli/cmds/start_prover_broker.js +11 -8
- package/dest/cli/cmds/start_txe.d.ts +2 -2
- package/dest/cli/cmds/start_txe.d.ts.map +1 -1
- package/dest/cli/cmds/start_txe.js +6 -5
- package/dest/cli/cmds/utils/collect_crate_dirs.d.ts +21 -0
- package/dest/cli/cmds/utils/collect_crate_dirs.d.ts.map +1 -0
- package/dest/cli/cmds/utils/collect_crate_dirs.js +114 -0
- package/dest/cli/cmds/utils/needs_recompile.d.ts +1 -1
- package/dest/cli/cmds/utils/needs_recompile.d.ts.map +1 -1
- package/dest/cli/cmds/utils/needs_recompile.js +9 -53
- package/dest/cli/cmds/utils/warn_if_aztec_version_mismatch.d.ts +4 -0
- package/dest/cli/cmds/utils/warn_if_aztec_version_mismatch.d.ts.map +1 -0
- package/dest/cli/cmds/utils/warn_if_aztec_version_mismatch.js +61 -0
- package/dest/cli/util.js +7 -5
- package/dest/examples/token.js +3 -3
- package/dest/local-network/auth_registry.d.ts +5 -0
- package/dest/local-network/auth_registry.d.ts.map +1 -0
- package/dest/local-network/auth_registry.js +17 -0
- package/dest/local-network/banana_fpc.d.ts +3 -2
- package/dest/local-network/banana_fpc.d.ts.map +1 -1
- package/dest/local-network/banana_fpc.js +11 -7
- package/dest/local-network/local-network.d.ts +6 -29
- package/dest/local-network/local-network.d.ts.map +1 -1
- package/dest/local-network/local-network.js +45 -70
- package/dest/testing/cheat_codes.d.ts +18 -17
- package/dest/testing/cheat_codes.d.ts.map +1 -1
- package/dest/testing/cheat_codes.js +70 -36
- 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 +6 -25
- package/dest/testing/index.d.ts +1 -2
- package/dest/testing/index.d.ts.map +1 -1
- package/dest/testing/index.js +0 -1
- package/package.json +34 -33
- package/scripts/add_crate.sh +11 -60
- package/scripts/aztec.sh +6 -2
- package/scripts/init.sh +5 -5
- package/scripts/new.sh +2 -2
- package/scripts/setup_workspace.sh +3 -2
- package/scripts/templates/blank/contract/Nargo.toml +6 -0
- package/scripts/templates/blank/contract/src/main.nr +10 -0
- package/scripts/templates/blank/test/Nargo.toml +7 -0
- package/scripts/templates/blank/test/src/lib.nr +11 -0
- package/scripts/templates/counter/contract/Nargo.toml +7 -0
- package/scripts/templates/counter/contract/src/main.nr +48 -0
- package/scripts/templates/counter/test/Nargo.toml +7 -0
- package/scripts/templates/counter/test/src/lib.nr +32 -0
- package/src/bin/index.ts +1 -1
- package/src/cli/aztec_start_action.ts +14 -17
- package/src/cli/aztec_start_options.ts +21 -22
- package/src/cli/cmds/compile.ts +10 -9
- package/src/cli/cmds/profile.ts +2 -1
- package/src/cli/cmds/profile_gates.ts +20 -4
- package/src/cli/cmds/standby.ts +4 -4
- package/src/cli/cmds/start_bot.ts +9 -6
- package/src/cli/cmds/start_node.ts +20 -23
- package/src/cli/cmds/start_prover_agent.ts +5 -8
- package/src/cli/cmds/start_prover_broker.ts +10 -11
- package/src/cli/cmds/start_txe.ts +7 -5
- package/src/cli/cmds/utils/collect_crate_dirs.ts +118 -0
- package/src/cli/cmds/utils/needs_recompile.ts +8 -61
- package/src/cli/cmds/utils/warn_if_aztec_version_mismatch.ts +76 -0
- package/src/cli/util.ts +7 -7
- package/src/examples/token.ts +3 -3
- package/src/local-network/auth_registry.ts +19 -0
- package/src/local-network/banana_fpc.ts +12 -8
- package/src/local-network/local-network.ts +49 -80
- package/src/testing/cheat_codes.ts +89 -39
- package/src/testing/epoch_test_settler.ts +8 -31
- package/src/testing/index.ts +0 -1
- package/dest/cli/cmds/start_archiver.d.ts +0 -9
- package/dest/cli/cmds/start_archiver.d.ts.map +0 -1
- package/dest/cli/cmds/start_archiver.js +0 -48
- package/dest/testing/anvil_test_watcher.d.ts +0 -42
- package/dest/testing/anvil_test_watcher.d.ts.map +0 -1
- package/dest/testing/anvil_test_watcher.js +0 -181
- package/src/cli/cmds/start_archiver.ts +0 -50
- package/src/testing/anvil_test_watcher.ts +0 -210
|
@@ -1,42 +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
|
-
/**
|
|
6
|
-
* Represents a watcher for a rollup contract.
|
|
7
|
-
*
|
|
8
|
-
* It started on a network like anvil where time traveling is allowed, and auto-mine is turned on
|
|
9
|
-
* it will periodically check if the current slot have already been filled, e.g., there was an L2
|
|
10
|
-
* block within the slot. And if so, it will time travel into the next slot.
|
|
11
|
-
*/
|
|
12
|
-
export declare class AnvilTestWatcher {
|
|
13
|
-
private cheatcodes;
|
|
14
|
-
private dateProvider?;
|
|
15
|
-
private isLocalNetwork;
|
|
16
|
-
private rollup;
|
|
17
|
-
private rollupCheatCodes;
|
|
18
|
-
private l2SlotDuration;
|
|
19
|
-
private filledRunningPromise?;
|
|
20
|
-
private syncDateProviderPromise?;
|
|
21
|
-
private markingAsProvenRunningPromise?;
|
|
22
|
-
private logger;
|
|
23
|
-
private isMarkingAsProven;
|
|
24
|
-
private getPendingTxCount?;
|
|
25
|
-
private isSequencerBuilding?;
|
|
26
|
-
private unfilledSlotFirstSeen?;
|
|
27
|
-
constructor(cheatcodes: EthCheatCodes, rollupAddress: EthAddress, l1Client: ViemClient, dateProvider?: TestDateProvider | undefined);
|
|
28
|
-
setIsMarkingAsProven(isMarkingAsProven: boolean): void;
|
|
29
|
-
setisLocalNetwork(isLocalNetwork: boolean): void;
|
|
30
|
-
/** Sets a callback to check for pending txs, used to skip unfilled slots faster when txs are waiting. */
|
|
31
|
-
setGetPendingTxCount(fn: () => Promise<number>): void;
|
|
32
|
-
/** Sets a callback to check if the sequencer is actively building, to avoid warping while it works. */
|
|
33
|
-
setIsSequencerBuilding(fn: () => boolean): void;
|
|
34
|
-
start(): Promise<void>;
|
|
35
|
-
stop(): Promise<void>;
|
|
36
|
-
trigger(): Promise<void>;
|
|
37
|
-
markAsProven(): Promise<void>;
|
|
38
|
-
syncDateProviderToL1IfBehind(): Promise<void>;
|
|
39
|
-
warpTimeIfNeeded(): Promise<void>;
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AAC,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;IAE/D,OAAO,CAAC,iBAAiB,CAAQ;IAGjC,OAAO,CAAC,iBAAiB,CAAC,CAAwB;IAGlD,OAAO,CAAC,mBAAmB,CAAC,CAAgB;IAG5C,OAAO,CAAC,qBAAqB,CAAC,CAAqC;IAEnE,YACU,UAAU,EAAE,aAAa,EACjC,aAAa,EAAE,UAAU,EACzB,QAAQ,EAAE,UAAU,EACZ,YAAY,CAAC,8BAAkB,EAaxC;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;IAEK,KAAK,kBAyBV;IAEK,IAAI,kBAIT;IAEK,OAAO,kBAIZ;IAEK,YAAY,kBAKjB;IAEK,4BAA4B,kBAejC;IAEK,gBAAgB,kBAyDrB;YAEa,eAAe;CAO9B"}
|
|
@@ -1,181 +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
|
-
rollup;
|
|
18
|
-
rollupCheatCodes;
|
|
19
|
-
l2SlotDuration;
|
|
20
|
-
filledRunningPromise;
|
|
21
|
-
syncDateProviderPromise;
|
|
22
|
-
markingAsProvenRunningPromise;
|
|
23
|
-
logger;
|
|
24
|
-
isMarkingAsProven;
|
|
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
|
-
constructor(cheatcodes, rollupAddress, l1Client, dateProvider){
|
|
32
|
-
this.cheatcodes = cheatcodes;
|
|
33
|
-
this.dateProvider = dateProvider;
|
|
34
|
-
this.isLocalNetwork = false;
|
|
35
|
-
this.logger = createLogger(`aztecjs:utils:watcher`);
|
|
36
|
-
this.isMarkingAsProven = true;
|
|
37
|
-
this.rollup = getContract({
|
|
38
|
-
address: getAddress(rollupAddress.toString()),
|
|
39
|
-
abi: RollupAbi,
|
|
40
|
-
client: l1Client
|
|
41
|
-
});
|
|
42
|
-
this.rollupCheatCodes = new RollupCheatCodes(this.cheatcodes, {
|
|
43
|
-
rollupAddress
|
|
44
|
-
});
|
|
45
|
-
this.logger.debug(`Watcher created for rollup at ${rollupAddress}`);
|
|
46
|
-
}
|
|
47
|
-
setIsMarkingAsProven(isMarkingAsProven) {
|
|
48
|
-
this.logger.warn(`Watcher is now ${isMarkingAsProven ? 'marking' : 'not marking'} blocks as proven`);
|
|
49
|
-
this.isMarkingAsProven = isMarkingAsProven;
|
|
50
|
-
}
|
|
51
|
-
setisLocalNetwork(isLocalNetwork) {
|
|
52
|
-
this.isLocalNetwork = isLocalNetwork;
|
|
53
|
-
}
|
|
54
|
-
/** Sets a callback to check for pending txs, used to skip unfilled slots faster when txs are waiting. */ setGetPendingTxCount(fn) {
|
|
55
|
-
this.getPendingTxCount = fn;
|
|
56
|
-
}
|
|
57
|
-
/** Sets a callback to check if the sequencer is actively building, to avoid warping while it works. */ setIsSequencerBuilding(fn) {
|
|
58
|
-
this.isSequencerBuilding = fn;
|
|
59
|
-
}
|
|
60
|
-
async start() {
|
|
61
|
-
if (this.filledRunningPromise) {
|
|
62
|
-
throw new Error('Watcher already watching for filled slot');
|
|
63
|
-
}
|
|
64
|
-
const config = await this.rollupCheatCodes.getConfig();
|
|
65
|
-
this.l2SlotDuration = config.slotDuration;
|
|
66
|
-
// If auto mining is not supported (e.g., we are on a real network), then we
|
|
67
|
-
// will simple do nothing. But if on an anvil or the like, this make sure that
|
|
68
|
-
// the local network and tests don't break because time is frozen and we never get to
|
|
69
|
-
// the next slot.
|
|
70
|
-
const isAutoMining = await this.cheatcodes.isAutoMining();
|
|
71
|
-
if (isAutoMining) {
|
|
72
|
-
this.filledRunningPromise = new RunningPromise(()=>this.warpTimeIfNeeded(), this.logger, 200);
|
|
73
|
-
this.filledRunningPromise.start();
|
|
74
|
-
this.syncDateProviderPromise = new RunningPromise(()=>this.syncDateProviderToL1IfBehind(), this.logger, 200);
|
|
75
|
-
this.syncDateProviderPromise.start();
|
|
76
|
-
this.markingAsProvenRunningPromise = new RunningPromise(()=>this.markAsProven(), this.logger, 200);
|
|
77
|
-
this.markingAsProvenRunningPromise.start();
|
|
78
|
-
this.logger.info(`Watcher started for rollup at ${this.rollup.address}`);
|
|
79
|
-
} else {
|
|
80
|
-
this.logger.info(`Watcher not started because not auto mining`);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
async stop() {
|
|
84
|
-
await this.filledRunningPromise?.stop();
|
|
85
|
-
await this.syncDateProviderPromise?.stop();
|
|
86
|
-
await this.markingAsProvenRunningPromise?.stop();
|
|
87
|
-
}
|
|
88
|
-
async trigger() {
|
|
89
|
-
await this.filledRunningPromise?.trigger();
|
|
90
|
-
await this.syncDateProviderPromise?.trigger();
|
|
91
|
-
await this.markingAsProvenRunningPromise?.trigger();
|
|
92
|
-
}
|
|
93
|
-
async markAsProven() {
|
|
94
|
-
if (!this.isMarkingAsProven) {
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
await this.rollupCheatCodes.markAsProven();
|
|
98
|
-
}
|
|
99
|
-
async syncDateProviderToL1IfBehind() {
|
|
100
|
-
// this doesn't apply to the local network, because we don't have a date provider in the local network
|
|
101
|
-
if (!this.dateProvider) {
|
|
102
|
-
return;
|
|
103
|
-
}
|
|
104
|
-
const l1Time = await this.cheatcodes.timestamp() * 1000;
|
|
105
|
-
const wallTime = this.dateProvider.now();
|
|
106
|
-
if (l1Time > wallTime) {
|
|
107
|
-
this.logger.warn(`L1 is ahead of wall time. Syncing wall time to L1 time`);
|
|
108
|
-
this.dateProvider.setTime(l1Time);
|
|
109
|
-
} else if (l1Time + Number(this.l2SlotDuration) * 1000 < wallTime) {
|
|
110
|
-
this.logger.warn(`L1 is more than 1 L2 slot behind wall time. Warping to wall time`);
|
|
111
|
-
await this.cheatcodes.warp(Math.ceil(wallTime / 1000));
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
async warpTimeIfNeeded() {
|
|
115
|
-
try {
|
|
116
|
-
const currentSlot = SlotNumber.fromBigInt(await this.rollup.read.getCurrentSlot());
|
|
117
|
-
const pendingCheckpointNumber = await this.rollup.read.getPendingCheckpointNumber();
|
|
118
|
-
const checkpointLog = await this.rollup.read.getCheckpoint([
|
|
119
|
-
pendingCheckpointNumber
|
|
120
|
-
]);
|
|
121
|
-
const nextSlot = SlotNumber(currentSlot + 1);
|
|
122
|
-
const nextSlotTimestamp = Number(await this.rollup.read.getTimestampForSlot([
|
|
123
|
-
BigInt(nextSlot)
|
|
124
|
-
]));
|
|
125
|
-
if (BigInt(currentSlot) === checkpointLog.slotNumber) {
|
|
126
|
-
// The current slot has been filled, we should jump to the next slot.
|
|
127
|
-
await this.warpToTimestamp(nextSlotTimestamp);
|
|
128
|
-
this.logger.info(`Slot ${currentSlot} was filled, jumped to next slot`);
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
// If we are not in local network, we don't need to warp time
|
|
132
|
-
if (!this.isLocalNetwork) {
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
|
-
// If there are pending txs and the sequencer missed them, warp quickly (after a 2s real-time debounce) so the
|
|
136
|
-
// sequencer can retry in the next slot. Without this, we'd have to wait a full real-time slot duration (~36s) for
|
|
137
|
-
// the dateProvider to catch up to the next slot timestamp. We skip the warp if the sequencer is actively building
|
|
138
|
-
// to avoid invalidating its in-progress work.
|
|
139
|
-
if (this.getPendingTxCount) {
|
|
140
|
-
const pendingTxs = await this.getPendingTxCount();
|
|
141
|
-
if (pendingTxs > 0) {
|
|
142
|
-
if (this.isSequencerBuilding?.()) {
|
|
143
|
-
this.unfilledSlotFirstSeen = undefined;
|
|
144
|
-
return;
|
|
145
|
-
}
|
|
146
|
-
const realNow = Date.now();
|
|
147
|
-
if (!this.unfilledSlotFirstSeen || this.unfilledSlotFirstSeen.slot !== currentSlot) {
|
|
148
|
-
this.unfilledSlotFirstSeen = {
|
|
149
|
-
slot: currentSlot,
|
|
150
|
-
realTime: realNow
|
|
151
|
-
};
|
|
152
|
-
return;
|
|
153
|
-
}
|
|
154
|
-
if (realNow - this.unfilledSlotFirstSeen.realTime > 2000) {
|
|
155
|
-
await this.warpToTimestamp(nextSlotTimestamp);
|
|
156
|
-
this.unfilledSlotFirstSeen = undefined;
|
|
157
|
-
this.logger.info(`Slot ${currentSlot} was missed with pending txs, jumped to next slot`);
|
|
158
|
-
}
|
|
159
|
-
return;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
// Fallback: warp when the dateProvider time has passed the next slot timestamp.
|
|
163
|
-
const currentTimestamp = this.dateProvider?.now() ?? Date.now();
|
|
164
|
-
if (currentTimestamp > nextSlotTimestamp * 1000) {
|
|
165
|
-
await this.warpToTimestamp(nextSlotTimestamp);
|
|
166
|
-
this.logger.info(`Slot ${currentSlot} was missed, jumped to next slot`);
|
|
167
|
-
}
|
|
168
|
-
} catch {
|
|
169
|
-
this.logger.error('mineIfSlotFilled failed');
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
async warpToTimestamp(timestamp) {
|
|
173
|
-
try {
|
|
174
|
-
await this.cheatcodes.warp(timestamp, {
|
|
175
|
-
resetBlockInterval: true
|
|
176
|
-
});
|
|
177
|
-
} catch (e) {
|
|
178
|
-
this.logger.error(`Failed to warp to timestamp ${timestamp}: ${e}`);
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { type ArchiverConfig, archiverConfigMappings, createArchiver, getArchiverConfigFromEnv } from '@aztec/archiver';
|
|
2
|
-
import { createLogger } from '@aztec/aztec.js/log';
|
|
3
|
-
import { type BlobClientConfig, blobClientConfigMapping, createBlobClient } from '@aztec/blob-client/client';
|
|
4
|
-
import { getL1Config } from '@aztec/cli/config';
|
|
5
|
-
import type { NamespacedApiHandlers } from '@aztec/foundation/json-rpc/server';
|
|
6
|
-
import { ArchiverApiSchema } from '@aztec/stdlib/interfaces/server';
|
|
7
|
-
import { type DataStoreConfig, dataConfigMappings } from '@aztec/stdlib/kv-store';
|
|
8
|
-
import { getConfigEnvVars as getTelemetryClientConfig, initTelemetryClient } from '@aztec/telemetry-client';
|
|
9
|
-
|
|
10
|
-
import { extractRelevantOptions } from '../util.js';
|
|
11
|
-
|
|
12
|
-
export type { ArchiverConfig, DataStoreConfig };
|
|
13
|
-
|
|
14
|
-
/** Starts a standalone archiver. */
|
|
15
|
-
export async function startArchiver(
|
|
16
|
-
options: any,
|
|
17
|
-
signalHandlers: (() => Promise<void>)[],
|
|
18
|
-
services: NamespacedApiHandlers,
|
|
19
|
-
): Promise<{ config: ArchiverConfig & DataStoreConfig }> {
|
|
20
|
-
const envConfig = getArchiverConfigFromEnv();
|
|
21
|
-
const cliOptions = extractRelevantOptions<ArchiverConfig & DataStoreConfig & BlobClientConfig>(
|
|
22
|
-
options,
|
|
23
|
-
{ ...archiverConfigMappings, ...dataConfigMappings, ...blobClientConfigMapping },
|
|
24
|
-
'archiver',
|
|
25
|
-
);
|
|
26
|
-
|
|
27
|
-
let archiverConfig = { ...envConfig, ...cliOptions };
|
|
28
|
-
archiverConfig.dataStoreMapSizeKb = archiverConfig.archiverStoreMapSizeKb ?? archiverConfig.dataStoreMapSizeKb;
|
|
29
|
-
|
|
30
|
-
if (!archiverConfig.l1Contracts.registryAddress || archiverConfig.l1Contracts.registryAddress.isZero()) {
|
|
31
|
-
throw new Error('L1 registry address is required to start an Archiver');
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const { addresses, config: l1Config } = await getL1Config(
|
|
35
|
-
archiverConfig.l1Contracts.registryAddress,
|
|
36
|
-
archiverConfig.l1RpcUrls,
|
|
37
|
-
archiverConfig.l1ChainId,
|
|
38
|
-
);
|
|
39
|
-
|
|
40
|
-
archiverConfig.l1Contracts = addresses;
|
|
41
|
-
archiverConfig = { ...archiverConfig, ...l1Config };
|
|
42
|
-
|
|
43
|
-
const telemetry = await initTelemetryClient(getTelemetryClientConfig());
|
|
44
|
-
const blobClient = createBlobClient(archiverConfig, { logger: createLogger('archiver:blob-client:client') });
|
|
45
|
-
const archiver = await createArchiver(archiverConfig, { telemetry, blobClient }, { blockUntilSync: true });
|
|
46
|
-
services.archiver = [archiver, ArchiverApiSchema];
|
|
47
|
-
signalHandlers.push(archiver.stop);
|
|
48
|
-
|
|
49
|
-
return { config: archiverConfig };
|
|
50
|
-
}
|
|
@@ -1,210 +0,0 @@
|
|
|
1
|
-
import { EthCheatCodes, RollupCheatCodes } from '@aztec/ethereum/test';
|
|
2
|
-
import type { ViemClient } from '@aztec/ethereum/types';
|
|
3
|
-
import { SlotNumber } from '@aztec/foundation/branded-types';
|
|
4
|
-
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
5
|
-
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
6
|
-
import { RunningPromise } from '@aztec/foundation/running-promise';
|
|
7
|
-
import type { TestDateProvider } from '@aztec/foundation/timer';
|
|
8
|
-
import { RollupAbi } from '@aztec/l1-artifacts/RollupAbi';
|
|
9
|
-
|
|
10
|
-
import { type GetContractReturnType, getAddress, getContract } from 'viem';
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Represents a watcher for a rollup contract.
|
|
14
|
-
*
|
|
15
|
-
* It started on a network like anvil where time traveling is allowed, and auto-mine is turned on
|
|
16
|
-
* it will periodically check if the current slot have already been filled, e.g., there was an L2
|
|
17
|
-
* block within the slot. And if so, it will time travel into the next slot.
|
|
18
|
-
*/
|
|
19
|
-
export class AnvilTestWatcher {
|
|
20
|
-
private isLocalNetwork: boolean = false;
|
|
21
|
-
|
|
22
|
-
private rollup: GetContractReturnType<typeof RollupAbi, ViemClient>;
|
|
23
|
-
private rollupCheatCodes: RollupCheatCodes;
|
|
24
|
-
private l2SlotDuration!: number;
|
|
25
|
-
|
|
26
|
-
private filledRunningPromise?: RunningPromise;
|
|
27
|
-
private syncDateProviderPromise?: RunningPromise;
|
|
28
|
-
private markingAsProvenRunningPromise?: RunningPromise;
|
|
29
|
-
|
|
30
|
-
private logger: Logger = createLogger(`aztecjs:utils:watcher`);
|
|
31
|
-
|
|
32
|
-
private isMarkingAsProven = true;
|
|
33
|
-
|
|
34
|
-
// Optional callback to check if there are pending txs in the mempool.
|
|
35
|
-
private getPendingTxCount?: () => Promise<number>;
|
|
36
|
-
|
|
37
|
-
// Optional callback to check if the sequencer is actively building a block.
|
|
38
|
-
private isSequencerBuilding?: () => boolean;
|
|
39
|
-
|
|
40
|
-
// Tracks when we first observed the current unfilled slot with pending txs (real wall time).
|
|
41
|
-
private unfilledSlotFirstSeen?: { slot: number; realTime: number };
|
|
42
|
-
|
|
43
|
-
constructor(
|
|
44
|
-
private cheatcodes: EthCheatCodes,
|
|
45
|
-
rollupAddress: EthAddress,
|
|
46
|
-
l1Client: ViemClient,
|
|
47
|
-
private dateProvider?: TestDateProvider,
|
|
48
|
-
) {
|
|
49
|
-
this.rollup = getContract({
|
|
50
|
-
address: getAddress(rollupAddress.toString()),
|
|
51
|
-
abi: RollupAbi,
|
|
52
|
-
client: l1Client,
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
this.rollupCheatCodes = new RollupCheatCodes(this.cheatcodes, {
|
|
56
|
-
rollupAddress,
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
this.logger.debug(`Watcher created for rollup at ${rollupAddress}`);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
setIsMarkingAsProven(isMarkingAsProven: boolean) {
|
|
63
|
-
this.logger.warn(`Watcher is now ${isMarkingAsProven ? 'marking' : 'not marking'} blocks as proven`);
|
|
64
|
-
this.isMarkingAsProven = isMarkingAsProven;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
setisLocalNetwork(isLocalNetwork: boolean) {
|
|
68
|
-
this.isLocalNetwork = isLocalNetwork;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/** Sets a callback to check for pending txs, used to skip unfilled slots faster when txs are waiting. */
|
|
72
|
-
setGetPendingTxCount(fn: () => Promise<number>) {
|
|
73
|
-
this.getPendingTxCount = fn;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/** Sets a callback to check if the sequencer is actively building, to avoid warping while it works. */
|
|
77
|
-
setIsSequencerBuilding(fn: () => boolean) {
|
|
78
|
-
this.isSequencerBuilding = fn;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
async start() {
|
|
82
|
-
if (this.filledRunningPromise) {
|
|
83
|
-
throw new Error('Watcher already watching for filled slot');
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
const config = await this.rollupCheatCodes.getConfig();
|
|
87
|
-
this.l2SlotDuration = config.slotDuration;
|
|
88
|
-
|
|
89
|
-
// If auto mining is not supported (e.g., we are on a real network), then we
|
|
90
|
-
// will simple do nothing. But if on an anvil or the like, this make sure that
|
|
91
|
-
// the local network and tests don't break because time is frozen and we never get to
|
|
92
|
-
// the next slot.
|
|
93
|
-
const isAutoMining = await this.cheatcodes.isAutoMining();
|
|
94
|
-
|
|
95
|
-
if (isAutoMining) {
|
|
96
|
-
this.filledRunningPromise = new RunningPromise(() => this.warpTimeIfNeeded(), this.logger, 200);
|
|
97
|
-
this.filledRunningPromise.start();
|
|
98
|
-
this.syncDateProviderPromise = new RunningPromise(() => this.syncDateProviderToL1IfBehind(), this.logger, 200);
|
|
99
|
-
this.syncDateProviderPromise.start();
|
|
100
|
-
this.markingAsProvenRunningPromise = new RunningPromise(() => this.markAsProven(), this.logger, 200);
|
|
101
|
-
this.markingAsProvenRunningPromise.start();
|
|
102
|
-
this.logger.info(`Watcher started for rollup at ${this.rollup.address}`);
|
|
103
|
-
} else {
|
|
104
|
-
this.logger.info(`Watcher not started because not auto mining`);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
async stop() {
|
|
109
|
-
await this.filledRunningPromise?.stop();
|
|
110
|
-
await this.syncDateProviderPromise?.stop();
|
|
111
|
-
await this.markingAsProvenRunningPromise?.stop();
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
async trigger() {
|
|
115
|
-
await this.filledRunningPromise?.trigger();
|
|
116
|
-
await this.syncDateProviderPromise?.trigger();
|
|
117
|
-
await this.markingAsProvenRunningPromise?.trigger();
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
async markAsProven() {
|
|
121
|
-
if (!this.isMarkingAsProven) {
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
await this.rollupCheatCodes.markAsProven();
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
async syncDateProviderToL1IfBehind() {
|
|
128
|
-
// this doesn't apply to the local network, because we don't have a date provider in the local network
|
|
129
|
-
if (!this.dateProvider) {
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
const l1Time = (await this.cheatcodes.timestamp()) * 1000;
|
|
134
|
-
const wallTime = this.dateProvider.now();
|
|
135
|
-
if (l1Time > wallTime) {
|
|
136
|
-
this.logger.warn(`L1 is ahead of wall time. Syncing wall time to L1 time`);
|
|
137
|
-
this.dateProvider.setTime(l1Time);
|
|
138
|
-
} else if (l1Time + Number(this.l2SlotDuration) * 1000 < wallTime) {
|
|
139
|
-
this.logger.warn(`L1 is more than 1 L2 slot behind wall time. Warping to wall time`);
|
|
140
|
-
await this.cheatcodes.warp(Math.ceil(wallTime / 1000));
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
async warpTimeIfNeeded() {
|
|
145
|
-
try {
|
|
146
|
-
const currentSlot = SlotNumber.fromBigInt(await this.rollup.read.getCurrentSlot());
|
|
147
|
-
const pendingCheckpointNumber = await this.rollup.read.getPendingCheckpointNumber();
|
|
148
|
-
const checkpointLog = await this.rollup.read.getCheckpoint([pendingCheckpointNumber]);
|
|
149
|
-
const nextSlot = SlotNumber(currentSlot + 1);
|
|
150
|
-
const nextSlotTimestamp = Number(await this.rollup.read.getTimestampForSlot([BigInt(nextSlot)]));
|
|
151
|
-
|
|
152
|
-
if (BigInt(currentSlot) === checkpointLog.slotNumber) {
|
|
153
|
-
// The current slot has been filled, we should jump to the next slot.
|
|
154
|
-
await this.warpToTimestamp(nextSlotTimestamp);
|
|
155
|
-
this.logger.info(`Slot ${currentSlot} was filled, jumped to next slot`);
|
|
156
|
-
return;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
// If we are not in local network, we don't need to warp time
|
|
160
|
-
if (!this.isLocalNetwork) {
|
|
161
|
-
return;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
// If there are pending txs and the sequencer missed them, warp quickly (after a 2s real-time debounce) so the
|
|
165
|
-
// sequencer can retry in the next slot. Without this, we'd have to wait a full real-time slot duration (~36s) for
|
|
166
|
-
// the dateProvider to catch up to the next slot timestamp. We skip the warp if the sequencer is actively building
|
|
167
|
-
// to avoid invalidating its in-progress work.
|
|
168
|
-
if (this.getPendingTxCount) {
|
|
169
|
-
const pendingTxs = await this.getPendingTxCount();
|
|
170
|
-
if (pendingTxs > 0) {
|
|
171
|
-
if (this.isSequencerBuilding?.()) {
|
|
172
|
-
this.unfilledSlotFirstSeen = undefined;
|
|
173
|
-
return;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
const realNow = Date.now();
|
|
177
|
-
if (!this.unfilledSlotFirstSeen || this.unfilledSlotFirstSeen.slot !== currentSlot) {
|
|
178
|
-
this.unfilledSlotFirstSeen = { slot: currentSlot, realTime: realNow };
|
|
179
|
-
return;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
if (realNow - this.unfilledSlotFirstSeen.realTime > 2000) {
|
|
183
|
-
await this.warpToTimestamp(nextSlotTimestamp);
|
|
184
|
-
this.unfilledSlotFirstSeen = undefined;
|
|
185
|
-
this.logger.info(`Slot ${currentSlot} was missed with pending txs, jumped to next slot`);
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
return;
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
// Fallback: warp when the dateProvider time has passed the next slot timestamp.
|
|
193
|
-
const currentTimestamp = this.dateProvider?.now() ?? Date.now();
|
|
194
|
-
if (currentTimestamp > nextSlotTimestamp * 1000) {
|
|
195
|
-
await this.warpToTimestamp(nextSlotTimestamp);
|
|
196
|
-
this.logger.info(`Slot ${currentSlot} was missed, jumped to next slot`);
|
|
197
|
-
}
|
|
198
|
-
} catch {
|
|
199
|
-
this.logger.error('mineIfSlotFilled failed');
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
private async warpToTimestamp(timestamp: number) {
|
|
204
|
-
try {
|
|
205
|
-
await this.cheatcodes.warp(timestamp, { resetBlockInterval: true });
|
|
206
|
-
} catch (e) {
|
|
207
|
-
this.logger.error(`Failed to warp to timestamp ${timestamp}: ${e}`);
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
}
|