|
| 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 | +} |
0 commit comments