Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: archiver fork block num #8425

Merged
merged 2 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions yarn-project/archiver/src/archiver/archiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
) {}

Expand Down Expand Up @@ -124,6 +125,7 @@ export class Archiver implements ArchiveSource {
archiverStore,
config.archiverPollingIntervalMS,
new ArchiverInstrumentation(telemetry),
BigInt(config.archiverL1StartBlock),
);
await archiver.start(blockUntilSynced);
return archiver;
Expand Down Expand Up @@ -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();
Comment on lines +180 to +185
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL the default syntax for destructuring

const currentL1BlockNumber = await this.publicClient.getBlockNumber();

if (
Expand Down
8 changes: 4 additions & 4 deletions yarn-project/archiver/src/archiver/archiver_store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

/**
Expand Down
34 changes: 17 additions & 17 deletions yarn-project/archiver/src/archiver/archiver_store_test_suite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,32 +97,32 @@ 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);
});

it('returns the L1 block number in which the most recent L2 block was published', async () => {
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);
});

Expand All @@ -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);
});
Expand Down
10 changes: 10 additions & 0 deletions yarn-project/archiver/src/archiver/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -52,6 +57,11 @@ export const archiverConfigMappings: ConfigMappingsType<ArchiverConfig> = {
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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Pick<Range<number>, 'start' | 'end'>> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ export class MemoryArchiverStore implements ArchiverDataStore {

private contractInstances: Map<string, ContractInstanceWithAddress> = 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;

Expand Down Expand Up @@ -225,7 +225,10 @@ export class MemoryArchiverStore implements ArchiverDataStore {
* @returns True if the operation is successful.
*/
public addL1ToL2Messages(messages: DataRetrieval<InboxLeaf>): Promise<boolean> {
if (messages.lastProcessedL1BlockNumber <= this.lastL1BlockNewMessages) {
if (
typeof this.lastL1BlockNewMessages === 'bigint' &&
messages.lastProcessedL1BlockNumber <= this.lastL1BlockNewMessages
) {
return Promise.resolve(false);
}

Expand Down
4 changes: 4 additions & 0 deletions yarn-project/aztec/terraform/node/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,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"
Expand Down
1 change: 1 addition & 0 deletions yarn-project/aztec/terraform/prover-node/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,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}" },
Expand Down
1 change: 1 addition & 0 deletions yarn-project/foundation/src/config/env_var.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Loading