From 6116f8d770e4fc4482d49271519d5582b433acfb Mon Sep 17 00:00:00 2001 From: Alex Gherghisan Date: Fri, 6 Sep 2024 09:53:28 +0000 Subject: [PATCH] feat: add a start point for the archiver --- .../archiver/src/archiver/archiver.ts | 10 ++++-- .../archiver/src/archiver/archiver_store.ts | 8 ++--- .../src/archiver/archiver_store_test_suite.ts | 34 +++++++++---------- yarn-project/archiver/src/archiver/config.ts | 10 ++++++ .../kv_archiver_store/block_body_store.ts | 4 +-- .../archiver/kv_archiver_store/block_store.ts | 4 +-- .../kv_archiver_store/message_store.ts | 4 +-- .../kv_archiver_store/proven_store.ts | 4 +-- .../memory_archiver_store.ts | 13 ++++--- yarn-project/aztec/terraform/node/main.tf | 4 +++ .../aztec/terraform/prover-node/main.tf | 1 + yarn-project/foundation/src/config/env_var.ts | 1 + 12 files changed, 61 insertions(+), 36 deletions(-) diff --git a/yarn-project/archiver/src/archiver/archiver.ts b/yarn-project/archiver/src/archiver/archiver.ts index 3805c4c3632..4ee7c228e60 100644 --- a/yarn-project/archiver/src/archiver/archiver.ts +++ b/yarn-project/archiver/src/archiver/archiver.ts @@ -92,6 +92,7 @@ export class Archiver implements ArchiveSource { private readonly store: ArchiverDataStore, private readonly pollingIntervalMs = 10_000, private readonly instrumentation: ArchiverInstrumentation, + private readonly l1StartBlock: bigint = 0n, private readonly log: DebugLogger = createDebugLogger('aztec:archiver'), ) {} @@ -124,6 +125,7 @@ export class Archiver implements ArchiveSource { archiverStore, config.archiverPollingIntervalMS, new ArchiverInstrumentation(telemetry), + BigInt(config.archiverL1StartBlock), ); await archiver.start(blockUntilSynced); return archiver; @@ -175,8 +177,12 @@ export class Archiver implements ArchiveSource { * * This code does not handle reorgs. */ - const { blockBodiesSynchedTo, blocksSynchedTo, messagesSynchedTo, provenLogsSynchedTo } = - await this.store.getSynchPoint(); + const { + blockBodiesSynchedTo = this.l1StartBlock, + blocksSynchedTo = this.l1StartBlock, + messagesSynchedTo = this.l1StartBlock, + provenLogsSynchedTo = this.l1StartBlock, + } = await this.store.getSynchPoint(); const currentL1BlockNumber = await this.publicClient.getBlockNumber(); if ( diff --git a/yarn-project/archiver/src/archiver/archiver_store.ts b/yarn-project/archiver/src/archiver/archiver_store.ts index 1d7c6c81afe..2d1f5e52425 100644 --- a/yarn-project/archiver/src/archiver/archiver_store.ts +++ b/yarn-project/archiver/src/archiver/archiver_store.ts @@ -32,13 +32,13 @@ import { type L1Published } from './structs/published.js'; */ export type ArchiverL1SynchPoint = { /** Number of the last L1 block that added a new L2 block metadata. */ - blocksSynchedTo: bigint; + blocksSynchedTo?: bigint; /** Number of the last L1 block that added a new L2 block body. */ - blockBodiesSynchedTo: bigint; + blockBodiesSynchedTo?: bigint; /** Number of the last L1 block that added L1 -> L2 messages from the Inbox. */ - messagesSynchedTo: bigint; + messagesSynchedTo?: bigint; /** Number of the last L1 block that added a new proven block. */ - provenLogsSynchedTo: bigint; + provenLogsSynchedTo?: bigint; }; /** diff --git a/yarn-project/archiver/src/archiver/archiver_store_test_suite.ts b/yarn-project/archiver/src/archiver/archiver_store_test_suite.ts index 3c6127e5b16..48b118a67b8 100644 --- a/yarn-project/archiver/src/archiver/archiver_store_test_suite.ts +++ b/yarn-project/archiver/src/archiver/archiver_store_test_suite.ts @@ -97,12 +97,12 @@ export function describeArchiverDataStore(testName: string, getStore: () => Arch }); describe('getSynchPoint', () => { - it('returns 0n if no blocks have been added', async () => { + it('returns undefined if no blocks have been added', async () => { await expect(store.getSynchPoint()).resolves.toEqual({ - blocksSynchedTo: 0n, - messagesSynchedTo: 0n, - blockBodiesSynchedTo: 0n, - provenLogsSynchedTo: 0n, + blocksSynchedTo: undefined, + messagesSynchedTo: undefined, + blockBodiesSynchedTo: undefined, + provenLogsSynchedTo: undefined, } satisfies ArchiverL1SynchPoint); }); @@ -110,19 +110,19 @@ export function describeArchiverDataStore(testName: string, getStore: () => Arch await store.addBlocks(blocks); await expect(store.getSynchPoint()).resolves.toEqual({ blocksSynchedTo: 19n, - messagesSynchedTo: 0n, - blockBodiesSynchedTo: 0n, - provenLogsSynchedTo: 0n, + messagesSynchedTo: undefined, + blockBodiesSynchedTo: undefined, + provenLogsSynchedTo: undefined, } satisfies ArchiverL1SynchPoint); }); it('returns the L1 block number in which the most recent L2 block body was published', async () => { await store.addBlockBodies(blockBodies); await expect(store.getSynchPoint()).resolves.toEqual({ - blocksSynchedTo: 0n, - messagesSynchedTo: 0n, + blocksSynchedTo: undefined, + messagesSynchedTo: undefined, blockBodiesSynchedTo: blockBodies.lastProcessedL1BlockNumber, - provenLogsSynchedTo: 0n, + provenLogsSynchedTo: undefined, } satisfies ArchiverL1SynchPoint); }); @@ -132,19 +132,19 @@ export function describeArchiverDataStore(testName: string, getStore: () => Arch retrievedData: [new InboxLeaf(0n, 0n, Fr.ZERO)], }); await expect(store.getSynchPoint()).resolves.toEqual({ - blocksSynchedTo: 0n, + blocksSynchedTo: undefined, messagesSynchedTo: 1n, - blockBodiesSynchedTo: 0n, - provenLogsSynchedTo: 0n, + blockBodiesSynchedTo: undefined, + provenLogsSynchedTo: undefined, } satisfies ArchiverL1SynchPoint); }); it('returns the L1 block number that most recently logged a proven block', async () => { await store.setProvenL2BlockNumber({ lastProcessedL1BlockNumber: 3n, retrievedData: 5 }); await expect(store.getSynchPoint()).resolves.toEqual({ - blocksSynchedTo: 0n, - messagesSynchedTo: 0n, - blockBodiesSynchedTo: 0n, + blocksSynchedTo: undefined, + messagesSynchedTo: undefined, + blockBodiesSynchedTo: undefined, provenLogsSynchedTo: 3n, } satisfies ArchiverL1SynchPoint); }); diff --git a/yarn-project/archiver/src/archiver/config.ts b/yarn-project/archiver/src/archiver/config.ts index f4ec61d3106..3b067f4e4ae 100644 --- a/yarn-project/archiver/src/archiver/config.ts +++ b/yarn-project/archiver/src/archiver/config.ts @@ -22,6 +22,11 @@ export type ArchiverConfig = { */ archiverPollingIntervalMS?: number; + /** + * The L1 block to start reading from + */ + archiverL1StartBlock: number; + /** * The polling interval viem uses in ms */ @@ -52,6 +57,11 @@ export const archiverConfigMappings: ConfigMappingsType = { description: 'The polling interval in ms for retrieving new L2 blocks and encrypted logs.', ...numberConfigHelper(1000), }, + archiverL1StartBlock: { + env: 'ARCHIVER_L1_START_BLOCK', + description: 'The L1 block the archiver should start reading logs from', + ...numberConfigHelper(0), + }, viemPollingIntervalMS: { env: 'ARCHIVER_VIEM_POLLING_INTERVAL_MS', description: 'The polling interval viem uses in ms', diff --git a/yarn-project/archiver/src/archiver/kv_archiver_store/block_body_store.ts b/yarn-project/archiver/src/archiver/kv_archiver_store/block_body_store.ts index 9f1c5b3ac64..566e637e11b 100644 --- a/yarn-project/archiver/src/archiver/kv_archiver_store/block_body_store.ts +++ b/yarn-project/archiver/src/archiver/kv_archiver_store/block_body_store.ts @@ -68,7 +68,7 @@ export class BlockBodyStore { * Gets the last L1 block number in which a L2 block body was included * @returns The L1 block number */ - getSynchedL1BlockNumber(): bigint { - return this.#lastSynchedL1Block.get() ?? 0n; + getSynchedL1BlockNumber(): bigint | undefined { + return this.#lastSynchedL1Block.get(); } } diff --git a/yarn-project/archiver/src/archiver/kv_archiver_store/block_store.ts b/yarn-project/archiver/src/archiver/kv_archiver_store/block_store.ts index 2fb206487b6..7ae29bd41b4 100644 --- a/yarn-project/archiver/src/archiver/kv_archiver_store/block_store.ts +++ b/yarn-project/archiver/src/archiver/kv_archiver_store/block_store.ts @@ -180,8 +180,8 @@ export class BlockStore { * Gets the most recent L1 block processed. * @returns The L1 block that published the latest L2 block */ - getSynchedL1BlockNumber(): bigint { - return this.#lastSynchedL1Block.get() ?? 0n; + getSynchedL1BlockNumber(): bigint | undefined { + return this.#lastSynchedL1Block.get(); } #computeBlockRange(start: number, limit: number): Required, 'start' | 'end'>> { diff --git a/yarn-project/archiver/src/archiver/kv_archiver_store/message_store.ts b/yarn-project/archiver/src/archiver/kv_archiver_store/message_store.ts index 0d412b4b70e..38bfb1fc6ee 100644 --- a/yarn-project/archiver/src/archiver/kv_archiver_store/message_store.ts +++ b/yarn-project/archiver/src/archiver/kv_archiver_store/message_store.ts @@ -32,8 +32,8 @@ export class MessageStore { * Gets the last L1 block number that emitted new messages. * @returns The last L1 block number processed */ - getSynchedL1BlockNumber(): bigint { - return this.#lastL1BlockMessages.get() ?? 0n; + getSynchedL1BlockNumber(): bigint | undefined { + return this.#lastL1BlockMessages.get(); } /** diff --git a/yarn-project/archiver/src/archiver/kv_archiver_store/proven_store.ts b/yarn-project/archiver/src/archiver/kv_archiver_store/proven_store.ts index 2009ce80627..d94b75b7ada 100644 --- a/yarn-project/archiver/src/archiver/kv_archiver_store/proven_store.ts +++ b/yarn-project/archiver/src/archiver/kv_archiver_store/proven_store.ts @@ -17,8 +17,8 @@ export class ProvenStore { /** * Gets the most recent L1 block processed. */ - getSynchedL1BlockNumber(): bigint { - return this.#lastSynchedL1Block.get() ?? 0n; + getSynchedL1BlockNumber(): bigint | undefined { + return this.#lastSynchedL1Block.get(); } getProvenL2BlockNumber(): number { diff --git a/yarn-project/archiver/src/archiver/memory_archiver_store/memory_archiver_store.ts b/yarn-project/archiver/src/archiver/memory_archiver_store/memory_archiver_store.ts index 27e69b174e3..5094382b15c 100644 --- a/yarn-project/archiver/src/archiver/memory_archiver_store/memory_archiver_store.ts +++ b/yarn-project/archiver/src/archiver/memory_archiver_store/memory_archiver_store.ts @@ -83,10 +83,10 @@ export class MemoryArchiverStore implements ArchiverDataStore { private contractInstances: Map = new Map(); - private lastL1BlockNewBlocks: bigint = 0n; - private lastL1BlockNewBlockBodies: bigint = 0n; - private lastL1BlockNewMessages: bigint = 0n; - private lastL1BlockNewProvenLogs: bigint = 0n; + private lastL1BlockNewBlocks: bigint | undefined = undefined; + private lastL1BlockNewBlockBodies: bigint | undefined = undefined; + private lastL1BlockNewMessages: bigint | undefined = undefined; + private lastL1BlockNewProvenLogs: bigint | undefined = undefined; private lastProvenL2BlockNumber: number = 0; @@ -225,7 +225,10 @@ export class MemoryArchiverStore implements ArchiverDataStore { * @returns True if the operation is successful. */ public addL1ToL2Messages(messages: DataRetrieval): Promise { - if (messages.lastProcessedL1BlockNumber <= this.lastL1BlockNewMessages) { + if ( + typeof this.lastL1BlockNewMessages === 'bigint' && + messages.lastProcessedL1BlockNumber <= this.lastL1BlockNewMessages + ) { return Promise.resolve(false); } diff --git a/yarn-project/aztec/terraform/node/main.tf b/yarn-project/aztec/terraform/node/main.tf index 6304b37ab45..fc16f3dcf5b 100644 --- a/yarn-project/aztec/terraform/node/main.tf +++ b/yarn-project/aztec/terraform/node/main.tf @@ -202,6 +202,10 @@ resource "aws_ecs_task_definition" "aztec-node" { name = "ARCHIVER_POLLING_INTERVAL" value = "10000" }, + { + name = "ARCHIVER_L1_START_BLOCK", + value = "15918000" + }, { name = "SEQ_RETRY_INTERVAL" value = "10000" diff --git a/yarn-project/aztec/terraform/prover-node/main.tf b/yarn-project/aztec/terraform/prover-node/main.tf index 9ea84547ac0..9a8b90c603f 100644 --- a/yarn-project/aztec/terraform/prover-node/main.tf +++ b/yarn-project/aztec/terraform/prover-node/main.tf @@ -186,6 +186,7 @@ resource "aws_ecs_task_definition" "aztec-prover-node" { // Archiver { name = "ARCHIVER_POLLING_INTERVAL", value = "10000" }, + { name = "ARCHIVER_L1_START_BLOCK", value = "15918000" }, // Aztec node to pull clientivc proofs from (to be replaced with a p2p connection) { 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}" }, diff --git a/yarn-project/foundation/src/config/env_var.ts b/yarn-project/foundation/src/config/env_var.ts index 43f908c5d72..ebd360bcf5a 100644 --- a/yarn-project/foundation/src/config/env_var.ts +++ b/yarn-project/foundation/src/config/env_var.ts @@ -48,6 +48,7 @@ export type EnvVar = | 'ARCHIVER_POLLING_INTERVAL_MS' | 'ARCHIVER_VIEM_POLLING_INTERVAL_MS' | 'ARCHIVER_MAX_LOGS' + | 'ARCHIVER_L1_START_BLOCK' | 'SEQ_TX_POLLING_INTERVAL_MS' | 'SEQ_MAX_TX_PER_BLOCK' | 'SEQ_MIN_TX_PER_BLOCK'