Skip to content

Commit 009b655

Browse files
committed
chore: Report prover metrics (#8155)
Reports a new histogram metric with the time that passes between a block being submitted and its proof. Uses the timestamp from the L2 block header global variables as block submission time, and the L1 block time for the proof submission time. Depends on #8193 Fixes #7675
1 parent 80121a6 commit 009b655

26 files changed

+486
-212
lines changed

yarn-project/archiver/src/archiver/archiver.test.ts

+25-9
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { EthAddress } from '@aztec/foundation/eth-address';
1010
import { Fr } from '@aztec/foundation/fields';
1111
import { sleep } from '@aztec/foundation/sleep';
1212
import { AvailabilityOracleAbi, type InboxAbi, RollupAbi } from '@aztec/l1-artifacts';
13-
import { NoopTelemetryClient } from '@aztec/telemetry-client/noop';
1413

1514
import { type MockProxy, mock } from 'jest-mock-extended';
1615
import {
@@ -25,6 +24,7 @@ import {
2524

2625
import { Archiver } from './archiver.js';
2726
import { type ArchiverDataStore } from './archiver_store.js';
27+
import { type ArchiverInstrumentation } from './instrumentation.js';
2828
import { MemoryArchiverStore } from './memory_archiver_store/memory_archiver_store.js';
2929

3030
describe('Archiver', () => {
@@ -35,31 +35,46 @@ describe('Archiver', () => {
3535
const blockNumbers = [1, 2, 3];
3636

3737
let publicClient: MockProxy<PublicClient<HttpTransport, Chain>>;
38+
let instrumentation: MockProxy<ArchiverInstrumentation>;
3839
let archiverStore: ArchiverDataStore;
3940
let proverId: Fr;
41+
let now: number;
42+
43+
let archiver: Archiver;
4044

4145
beforeEach(() => {
42-
publicClient = mock<PublicClient<HttpTransport, Chain>>();
46+
now = +new Date();
47+
publicClient = mock<PublicClient<HttpTransport, Chain>>({
48+
getBlock: ((args: any) => ({
49+
timestamp: args.blockNumber * 1000n + BigInt(now),
50+
})) as any,
51+
});
52+
instrumentation = mock({ isEnabled: () => true });
4353
archiverStore = new MemoryArchiverStore(1000);
4454
proverId = Fr.random();
4555
});
4656

57+
afterEach(async () => {
58+
await archiver?.stop();
59+
});
60+
4761
it('can start, sync and stop and handle l1 to l2 messages and logs', async () => {
48-
const archiver = new Archiver(
62+
archiver = new Archiver(
4963
publicClient,
5064
rollupAddress,
5165
availabilityOracleAddress,
5266
inboxAddress,
5367
registryAddress,
5468
archiverStore,
5569
1000,
56-
new NoopTelemetryClient(),
70+
instrumentation,
5771
);
5872

5973
let latestBlockNum = await archiver.getBlockNumber();
6074
expect(latestBlockNum).toEqual(0);
6175

6276
const blocks = blockNumbers.map(x => L2Block.random(x, 4, x, x + 1, 2, 2));
77+
blocks.forEach((b, i) => (b.header.globalVariables.timestamp = new Fr(now + 1000 * (i + 1))));
6378
const publishTxs = blocks.map(block => block.body).map(makePublishTx);
6479
const rollupTxs = blocks.map(makeRollupTx);
6580

@@ -157,20 +172,23 @@ describe('Archiver', () => {
157172
expect((await archiver.getBlocks(1, 100)).map(b => b.number)).toEqual([1, 2, 3]);
158173
expect((await archiver.getBlocks(1, 100, true)).map(b => b.number)).toEqual([1]);
159174

160-
await archiver.stop();
175+
// Check instrumentation of proven blocks
176+
expect(instrumentation.processProofsVerified).toHaveBeenCalledWith([
177+
{ delay: 1000n, l1BlockNumber: 102n, l2BlockNumber: 1n, proverId: proverId.toString() },
178+
]);
161179
}, 10_000);
162180

163181
it('does not sync past current block number', async () => {
164182
const numL2BlocksInTest = 2;
165-
const archiver = new Archiver(
183+
archiver = new Archiver(
166184
publicClient,
167185
rollupAddress,
168186
availabilityOracleAddress,
169187
inboxAddress,
170188
registryAddress,
171189
archiverStore,
172190
1000,
173-
new NoopTelemetryClient(),
191+
instrumentation,
174192
);
175193

176194
let latestBlockNum = await archiver.getBlockNumber();
@@ -207,8 +225,6 @@ describe('Archiver', () => {
207225

208226
latestBlockNum = await archiver.getBlockNumber();
209227
expect(latestBlockNum).toEqual(numL2BlocksInTest);
210-
211-
await archiver.stop();
212228
}, 10_000);
213229

214230
// logs should be created in order of how archiver syncs.

0 commit comments

Comments
 (0)