Skip to content

Commit a9f2364

Browse files
authored
feat: archiver fork block num (#8425)
This PR adds a start point for the archiver so that it doesn't scan the whole L1 chain.
1 parent 21c06b5 commit a9f2364

File tree

12 files changed

+61
-36
lines changed

12 files changed

+61
-36
lines changed

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

+8-2
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ export class Archiver implements ArchiveSource {
9292
private readonly store: ArchiverDataStore,
9393
private readonly pollingIntervalMs = 10_000,
9494
private readonly instrumentation: ArchiverInstrumentation,
95+
private readonly l1StartBlock: bigint = 0n,
9596
private readonly log: DebugLogger = createDebugLogger('aztec:archiver'),
9697
) {}
9798

@@ -124,6 +125,7 @@ export class Archiver implements ArchiveSource {
124125
archiverStore,
125126
config.archiverPollingIntervalMS,
126127
new ArchiverInstrumentation(telemetry),
128+
BigInt(config.archiverL1StartBlock),
127129
);
128130
await archiver.start(blockUntilSynced);
129131
return archiver;
@@ -175,8 +177,12 @@ export class Archiver implements ArchiveSource {
175177
*
176178
* This code does not handle reorgs.
177179
*/
178-
const { blockBodiesSynchedTo, blocksSynchedTo, messagesSynchedTo, provenLogsSynchedTo } =
179-
await this.store.getSynchPoint();
180+
const {
181+
blockBodiesSynchedTo = this.l1StartBlock,
182+
blocksSynchedTo = this.l1StartBlock,
183+
messagesSynchedTo = this.l1StartBlock,
184+
provenLogsSynchedTo = this.l1StartBlock,
185+
} = await this.store.getSynchPoint();
180186
const currentL1BlockNumber = await this.publicClient.getBlockNumber();
181187

182188
if (

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ import { type L1Published } from './structs/published.js';
3232
*/
3333
export type ArchiverL1SynchPoint = {
3434
/** Number of the last L1 block that added a new L2 block metadata. */
35-
blocksSynchedTo: bigint;
35+
blocksSynchedTo?: bigint;
3636
/** Number of the last L1 block that added a new L2 block body. */
37-
blockBodiesSynchedTo: bigint;
37+
blockBodiesSynchedTo?: bigint;
3838
/** Number of the last L1 block that added L1 -> L2 messages from the Inbox. */
39-
messagesSynchedTo: bigint;
39+
messagesSynchedTo?: bigint;
4040
/** Number of the last L1 block that added a new proven block. */
41-
provenLogsSynchedTo: bigint;
41+
provenLogsSynchedTo?: bigint;
4242
};
4343

4444
/**

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

+17-17
Original file line numberDiff line numberDiff line change
@@ -97,32 +97,32 @@ export function describeArchiverDataStore(testName: string, getStore: () => Arch
9797
});
9898

9999
describe('getSynchPoint', () => {
100-
it('returns 0n if no blocks have been added', async () => {
100+
it('returns undefined if no blocks have been added', async () => {
101101
await expect(store.getSynchPoint()).resolves.toEqual({
102-
blocksSynchedTo: 0n,
103-
messagesSynchedTo: 0n,
104-
blockBodiesSynchedTo: 0n,
105-
provenLogsSynchedTo: 0n,
102+
blocksSynchedTo: undefined,
103+
messagesSynchedTo: undefined,
104+
blockBodiesSynchedTo: undefined,
105+
provenLogsSynchedTo: undefined,
106106
} satisfies ArchiverL1SynchPoint);
107107
});
108108

109109
it('returns the L1 block number in which the most recent L2 block was published', async () => {
110110
await store.addBlocks(blocks);
111111
await expect(store.getSynchPoint()).resolves.toEqual({
112112
blocksSynchedTo: 19n,
113-
messagesSynchedTo: 0n,
114-
blockBodiesSynchedTo: 0n,
115-
provenLogsSynchedTo: 0n,
113+
messagesSynchedTo: undefined,
114+
blockBodiesSynchedTo: undefined,
115+
provenLogsSynchedTo: undefined,
116116
} satisfies ArchiverL1SynchPoint);
117117
});
118118

119119
it('returns the L1 block number in which the most recent L2 block body was published', async () => {
120120
await store.addBlockBodies(blockBodies);
121121
await expect(store.getSynchPoint()).resolves.toEqual({
122-
blocksSynchedTo: 0n,
123-
messagesSynchedTo: 0n,
122+
blocksSynchedTo: undefined,
123+
messagesSynchedTo: undefined,
124124
blockBodiesSynchedTo: blockBodies.lastProcessedL1BlockNumber,
125-
provenLogsSynchedTo: 0n,
125+
provenLogsSynchedTo: undefined,
126126
} satisfies ArchiverL1SynchPoint);
127127
});
128128

@@ -132,19 +132,19 @@ export function describeArchiverDataStore(testName: string, getStore: () => Arch
132132
retrievedData: [new InboxLeaf(0n, 0n, Fr.ZERO)],
133133
});
134134
await expect(store.getSynchPoint()).resolves.toEqual({
135-
blocksSynchedTo: 0n,
135+
blocksSynchedTo: undefined,
136136
messagesSynchedTo: 1n,
137-
blockBodiesSynchedTo: 0n,
138-
provenLogsSynchedTo: 0n,
137+
blockBodiesSynchedTo: undefined,
138+
provenLogsSynchedTo: undefined,
139139
} satisfies ArchiverL1SynchPoint);
140140
});
141141

142142
it('returns the L1 block number that most recently logged a proven block', async () => {
143143
await store.setProvenL2BlockNumber({ lastProcessedL1BlockNumber: 3n, retrievedData: 5 });
144144
await expect(store.getSynchPoint()).resolves.toEqual({
145-
blocksSynchedTo: 0n,
146-
messagesSynchedTo: 0n,
147-
blockBodiesSynchedTo: 0n,
145+
blocksSynchedTo: undefined,
146+
messagesSynchedTo: undefined,
147+
blockBodiesSynchedTo: undefined,
148148
provenLogsSynchedTo: 3n,
149149
} satisfies ArchiverL1SynchPoint);
150150
});

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

+10
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ export type ArchiverConfig = {
2222
*/
2323
archiverPollingIntervalMS?: number;
2424

25+
/**
26+
* The L1 block to start reading from
27+
*/
28+
archiverL1StartBlock: number;
29+
2530
/**
2631
* The polling interval viem uses in ms
2732
*/
@@ -52,6 +57,11 @@ export const archiverConfigMappings: ConfigMappingsType<ArchiverConfig> = {
5257
description: 'The polling interval in ms for retrieving new L2 blocks and encrypted logs.',
5358
...numberConfigHelper(1000),
5459
},
60+
archiverL1StartBlock: {
61+
env: 'ARCHIVER_L1_START_BLOCK',
62+
description: 'The L1 block the archiver should start reading logs from',
63+
...numberConfigHelper(0),
64+
},
5565
viemPollingIntervalMS: {
5666
env: 'ARCHIVER_VIEM_POLLING_INTERVAL_MS',
5767
description: 'The polling interval viem uses in ms',

yarn-project/archiver/src/archiver/kv_archiver_store/block_body_store.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export class BlockBodyStore {
6868
* Gets the last L1 block number in which a L2 block body was included
6969
* @returns The L1 block number
7070
*/
71-
getSynchedL1BlockNumber(): bigint {
72-
return this.#lastSynchedL1Block.get() ?? 0n;
71+
getSynchedL1BlockNumber(): bigint | undefined {
72+
return this.#lastSynchedL1Block.get();
7373
}
7474
}

yarn-project/archiver/src/archiver/kv_archiver_store/block_store.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,8 @@ export class BlockStore {
180180
* Gets the most recent L1 block processed.
181181
* @returns The L1 block that published the latest L2 block
182182
*/
183-
getSynchedL1BlockNumber(): bigint {
184-
return this.#lastSynchedL1Block.get() ?? 0n;
183+
getSynchedL1BlockNumber(): bigint | undefined {
184+
return this.#lastSynchedL1Block.get();
185185
}
186186

187187
#computeBlockRange(start: number, limit: number): Required<Pick<Range<number>, 'start' | 'end'>> {

yarn-project/archiver/src/archiver/kv_archiver_store/message_store.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ export class MessageStore {
3232
* Gets the last L1 block number that emitted new messages.
3333
* @returns The last L1 block number processed
3434
*/
35-
getSynchedL1BlockNumber(): bigint {
36-
return this.#lastL1BlockMessages.get() ?? 0n;
35+
getSynchedL1BlockNumber(): bigint | undefined {
36+
return this.#lastL1BlockMessages.get();
3737
}
3838

3939
/**

yarn-project/archiver/src/archiver/kv_archiver_store/proven_store.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ export class ProvenStore {
1717
/**
1818
* Gets the most recent L1 block processed.
1919
*/
20-
getSynchedL1BlockNumber(): bigint {
21-
return this.#lastSynchedL1Block.get() ?? 0n;
20+
getSynchedL1BlockNumber(): bigint | undefined {
21+
return this.#lastSynchedL1Block.get();
2222
}
2323

2424
getProvenL2BlockNumber(): number {

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

+8-5
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ export class MemoryArchiverStore implements ArchiverDataStore {
8383

8484
private contractInstances: Map<string, ContractInstanceWithAddress> = new Map();
8585

86-
private lastL1BlockNewBlocks: bigint = 0n;
87-
private lastL1BlockNewBlockBodies: bigint = 0n;
88-
private lastL1BlockNewMessages: bigint = 0n;
89-
private lastL1BlockNewProvenLogs: bigint = 0n;
86+
private lastL1BlockNewBlocks: bigint | undefined = undefined;
87+
private lastL1BlockNewBlockBodies: bigint | undefined = undefined;
88+
private lastL1BlockNewMessages: bigint | undefined = undefined;
89+
private lastL1BlockNewProvenLogs: bigint | undefined = undefined;
9090

9191
private lastProvenL2BlockNumber: number = 0;
9292

@@ -225,7 +225,10 @@ export class MemoryArchiverStore implements ArchiverDataStore {
225225
* @returns True if the operation is successful.
226226
*/
227227
public addL1ToL2Messages(messages: DataRetrieval<InboxLeaf>): Promise<boolean> {
228-
if (messages.lastProcessedL1BlockNumber <= this.lastL1BlockNewMessages) {
228+
if (
229+
typeof this.lastL1BlockNewMessages === 'bigint' &&
230+
messages.lastProcessedL1BlockNumber <= this.lastL1BlockNewMessages
231+
) {
229232
return Promise.resolve(false);
230233
}
231234

yarn-project/aztec/terraform/node/main.tf

+4
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,10 @@ resource "aws_ecs_task_definition" "aztec-node" {
267267
name = "ARCHIVER_POLLING_INTERVAL"
268268
value = "10000"
269269
},
270+
{
271+
name = "ARCHIVER_L1_START_BLOCK",
272+
value = "15918000"
273+
},
270274
{
271275
name = "SEQ_RETRY_INTERVAL"
272276
value = "10000"

yarn-project/aztec/terraform/prover-node/main.tf

+1
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ resource "aws_ecs_task_definition" "aztec-prover-node" {
250250

251251
// Archiver
252252
{ name = "ARCHIVER_POLLING_INTERVAL", value = "10000" },
253+
{ name = "ARCHIVER_L1_START_BLOCK", value = "15918000" },
253254

254255
// Aztec node to pull clientivc proofs from (to be replaced with a p2p connection)
255256
{ name = "TX_PROVIDER_NODE_URL", value = "http://${var.DEPLOY_TAG}-aztec-node-${count.index + 1}.local/${var.DEPLOY_TAG}/aztec-node-${count.index + 1}/${var.API_KEY}" },

yarn-project/foundation/src/config/env_var.ts

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export type EnvVar =
4848
| 'ARCHIVER_POLLING_INTERVAL_MS'
4949
| 'ARCHIVER_VIEM_POLLING_INTERVAL_MS'
5050
| 'ARCHIVER_MAX_LOGS'
51+
| 'ARCHIVER_L1_START_BLOCK'
5152
| 'SEQ_TX_POLLING_INTERVAL_MS'
5253
| 'SEQ_MAX_TX_PER_BLOCK'
5354
| 'SEQ_MIN_TX_PER_BLOCK'

0 commit comments

Comments
 (0)