Skip to content

Commit 5929a42

Browse files
authored
feat: Add CLI command for gathering proving metrics (#8221)
Run `yarn aztec prover-stats --l1-rpc-url https://provernet-mainnet-fork.aztec.network:8545/$APIKEY -c 677692 --start-block 15918000 --batch-size 200 --node-url https://api.aztec.network/provernet/aztec-node-1/$APIKEY` to get prover stats from provernet.
1 parent 03bcd62 commit 5929a42

File tree

5 files changed

+84
-4
lines changed

5 files changed

+84
-4
lines changed

yarn-project/cli/package.json

+3
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
]
6464
},
6565
"dependencies": {
66+
"@aztec/archiver": "workspace:^",
6667
"@aztec/aztec.js": "workspace:^",
6768
"@aztec/circuit-types": "workspace:^",
6869
"@aztec/foundation": "workspace:^",
@@ -71,6 +72,7 @@
7172
"@iarna/toml": "^2.2.5",
7273
"@libp2p/peer-id-factory": "^3.0.4",
7374
"commander": "^12.1.0",
75+
"lodash.groupby": "^4.6.0",
7476
"semver": "^7.5.4",
7577
"solc": "^0.8.26",
7678
"source-map-support": "^0.5.21",
@@ -84,6 +86,7 @@
8486
"@aztec/protocol-contracts": "workspace:^",
8587
"@jest/globals": "^29.5.0",
8688
"@types/jest": "^29.5.0",
89+
"@types/lodash.groupby": "^4.6.9",
8790
"@types/lodash.startcase": "^4.4.7",
8891
"@types/node": "^18.7.23",
8992
"@types/semver": "^7.5.2",

yarn-project/cli/src/cmds/l1/index.ts

+22-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ export function injectCommands(program: Command, log: LogFn, debugLogger: DebugL
159159
});
160160

161161
program
162-
.command('set-proven-until')
162+
.command('set-proven-until', { hidden: true })
163163
.description(
164164
'Instructs the L1 rollup contract to assume all blocks until the given number are automatically proven.',
165165
)
@@ -190,5 +190,26 @@ export function injectCommands(program: Command, log: LogFn, debugLogger: DebugL
190190
);
191191
});
192192

193+
program
194+
.command('prover-stats', { hidden: true })
195+
.requiredOption(
196+
'--l1-rpc-url <string>',
197+
'Url of the ethereum host. Chain identifiers localhost and testnet can be used',
198+
ETHEREUM_HOST,
199+
)
200+
.addOption(l1ChainIdOption)
201+
.option('--start-block <number>', 'The block number to start from', parseBigint, 1n)
202+
.option('--batch-size <number>', 'The number of blocks to query in each batch', parseBigint, 100n)
203+
.option('--l1-rollup-address <string>', 'Address of the rollup contract (required if node URL is not set)')
204+
.option(
205+
'--node-url <string>',
206+
'JSON RPC URL of an Aztec node to retrieve the rollup contract address (required if L1 rollup address is not set)',
207+
)
208+
.action(async options => {
209+
const { proverStats } = await import('./prover_stats.js');
210+
const { l1RpcUrl, chainId, l1RollupAddress, startBlock, batchSize, nodeUrl } = options;
211+
await proverStats({ l1RpcUrl, chainId, l1RollupAddress, startBlock, batchSize, nodeUrl, log });
212+
});
213+
193214
return program;
194215
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { retrieveL2ProofVerifiedEvents } from '@aztec/archiver';
2+
import { createAztecNodeClient } from '@aztec/circuit-types';
3+
import { EthAddress } from '@aztec/circuits.js';
4+
import { createEthereumChain } from '@aztec/ethereum';
5+
import { type LogFn, createDebugLogger } from '@aztec/foundation/log';
6+
7+
import groupBy from 'lodash.groupby';
8+
import { createPublicClient, http } from 'viem';
9+
10+
export async function proverStats(opts: {
11+
l1RpcUrl: string;
12+
chainId: number;
13+
l1RollupAddress: string | undefined;
14+
nodeUrl: string | undefined;
15+
log: LogFn;
16+
startBlock: bigint;
17+
batchSize: bigint;
18+
}) {
19+
const debugLog = createDebugLogger('aztec:cli:prover_stats');
20+
const { startBlock, chainId, l1RpcUrl, l1RollupAddress, batchSize, nodeUrl, log } = opts;
21+
if (!l1RollupAddress && !nodeUrl) {
22+
throw new Error('Either L1 rollup address or node URL must be set');
23+
}
24+
const rollup = l1RollupAddress
25+
? EthAddress.fromString(l1RollupAddress)
26+
: await createAztecNodeClient(nodeUrl!)
27+
.getL1ContractAddresses()
28+
.then(a => a.rollupAddress);
29+
30+
const chain = createEthereumChain(l1RpcUrl, chainId).chainInfo;
31+
const publicClient = createPublicClient({ chain, transport: http(l1RpcUrl) });
32+
const lastBlockNum = await publicClient.getBlockNumber();
33+
debugLog.verbose(`Querying events on rollup at ${rollup.toString()} from ${startBlock} up to ${lastBlockNum}`);
34+
35+
let blockNum = startBlock;
36+
const events = [];
37+
while (blockNum <= lastBlockNum) {
38+
const end = blockNum + batchSize > lastBlockNum + 1n ? lastBlockNum + 1n : blockNum + batchSize;
39+
debugLog.verbose(`Querying events from block ${blockNum} to ${end}`);
40+
const newEvents = await retrieveL2ProofVerifiedEvents(publicClient, rollup, blockNum, end);
41+
events.push(...newEvents);
42+
debugLog.verbose(`Got ${newEvents.length} events`);
43+
blockNum += batchSize;
44+
}
45+
46+
const stats = groupBy(events, 'proverId');
47+
for (const proverId in stats) {
48+
log(`${proverId}, ${stats[proverId].length}`);
49+
}
50+
}

yarn-project/cli/tsconfig.json

+6-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
"tsBuildInfoFile": ".tsbuildinfo"
77
},
88
"references": [
9+
{
10+
"path": "../archiver"
11+
},
912
{
1013
"path": "../aztec.js"
1114
},
@@ -15,6 +18,9 @@
1518
{
1619
"path": "../foundation"
1720
},
21+
{
22+
"path": "../l1-artifacts"
23+
},
1824
{
1925
"path": "../types"
2026
},
@@ -27,9 +33,6 @@
2733
{
2834
"path": "../ethereum"
2935
},
30-
{
31-
"path": "../l1-artifacts"
32-
},
3336
{
3437
"path": "../protocol-contracts"
3538
}

yarn-project/yarn.lock

+3
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,7 @@ __metadata:
448448
resolution: "@aztec/cli@workspace:cli"
449449
dependencies:
450450
"@aztec/accounts": "workspace:^"
451+
"@aztec/archiver": "workspace:^"
451452
"@aztec/aztec.js": "workspace:^"
452453
"@aztec/circuit-types": "workspace:^"
453454
"@aztec/circuits.js": "workspace:^"
@@ -460,13 +461,15 @@ __metadata:
460461
"@jest/globals": ^29.5.0
461462
"@libp2p/peer-id-factory": ^3.0.4
462463
"@types/jest": ^29.5.0
464+
"@types/lodash.groupby": ^4.6.9
463465
"@types/lodash.startcase": ^4.4.7
464466
"@types/node": ^18.7.23
465467
"@types/semver": ^7.5.2
466468
"@types/source-map-support": ^0.5.10
467469
commander: ^12.1.0
468470
jest: ^29.5.0
469471
jest-mock-extended: ^3.0.5
472+
lodash.groupby: ^4.6.0
470473
semver: ^7.5.4
471474
solc: ^0.8.26
472475
source-map-support: ^0.5.21

0 commit comments

Comments
 (0)