Skip to content

Commit

Permalink
fix: Fix epoch monitoring and related e2e tests (#12096)
Browse files Browse the repository at this point in the history
Fixes the prover-node's epoch monitor so it accounts for the previous
epoch to be proven. The updated logic is that an epoch is ready to prove
only if it is completed and it contains the first unproven block (which
gets updated over a reorg).

Also fixes #11840 

Builds on top of @PhilWindle's #12014

---------

Co-authored-by: PhilWindle <philip.windle@gmail.com>
  • Loading branch information
spalladino and PhilWindle authored Feb 21, 2025
1 parent e332eeb commit e2f675f
Show file tree
Hide file tree
Showing 27 changed files with 817 additions and 355 deletions.
6 changes: 6 additions & 0 deletions yarn-project/aztec-node/src/aztec-node/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
type ProverConfig,
type SequencerConfig,
type Service,
type WorldStateSyncStatus,
type WorldStateSynchronizer,
tryStop,
} from '@aztec/circuit-types/interfaces/server';
Expand Down Expand Up @@ -127,6 +128,11 @@ export class AztecNodeService implements AztecNode, Traceable {
this.log.info(`Aztec Node started on chain 0x${l1ChainId.toString(16)}`, config.l1Contracts);
}

public async getWorldStateSyncStatus(): Promise<WorldStateSyncStatus> {
const status = await this.worldStateSynchronizer.status();
return status.syncSummary;
}

public getL2Tips() {
return this.blockSource.getL2Tips();
}
Expand Down
7 changes: 6 additions & 1 deletion yarn-project/circuit-types/src/epoch-helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ export function getEpochNumberAtTimestamp(
ts: bigint,
constants: Pick<L1RollupConstants, 'epochDuration' | 'slotDuration' | 'l1GenesisTime'>,
) {
return getSlotAtTimestamp(ts, constants) / BigInt(constants.epochDuration);
return getEpochAtSlot(getSlotAtTimestamp(ts, constants), constants);
}

/** Returns the epoch number for a given slot. */
export function getEpochAtSlot(slot: bigint, constants: Pick<L1RollupConstants, 'epochDuration'>) {
return slot / BigInt(constants.epochDuration);
}

/** Returns the range of L2 slots (inclusive) for a given epoch number. */
Expand Down
16 changes: 16 additions & 0 deletions yarn-project/circuit-types/src/interfaces/aztec-node.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import { type AztecNode, AztecNodeApiSchema } from './aztec-node.js';
import { type SequencerConfig } from './configs.js';
import { NullifierMembershipWitness } from './nullifier_membership_witness.js';
import { type ProverConfig } from './prover-client.js';
import type { WorldStateSyncStatus } from './world_state.js';

describe('AztecNodeApiSchema', () => {
let handler: MockAztecNode;
Expand Down Expand Up @@ -353,11 +354,26 @@ describe('AztecNodeApiSchema', () => {
const contractClass = await getContractClassFromArtifact(artifact);
await context.client.addContractClass({ ...contractClass, unconstrainedFunctions: [], privateFunctions: [] });
});

it('getWorldStateSyncStatus', async () => {
const response = await context.client.getWorldStateSyncStatus();
expect(response).toEqual(await handler.getWorldStateSyncStatus());
});
});

class MockAztecNode implements AztecNode {
constructor(private artifact: ContractArtifact) {}

getWorldStateSyncStatus(): Promise<WorldStateSyncStatus> {
return Promise.resolve({
finalisedBlockNumber: 1,
latestBlockHash: '0x',
latestBlockNumber: 1,
oldestHistoricBlockNumber: 1,
treesAreSynched: true,
});
}

getL2Tips(): Promise<L2Tips> {
return Promise.resolve({
latest: { number: 1, hash: `0x01` },
Expand Down
8 changes: 8 additions & 0 deletions yarn-project/circuit-types/src/interfaces/aztec-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import { type L2BlockNumber, L2BlockNumberSchema } from './l2_block_number.js';
import { NullifierMembershipWitness } from './nullifier_membership_witness.js';
import { type ProverConfig, ProverConfigSchema } from './prover-client.js';
import { type ProverCoordination } from './prover-coordination.js';
import { type WorldStateSyncStatus, WorldStateSyncStatusSchema } from './world_state.js';

/**
* The aztec node.
Expand All @@ -69,6 +70,11 @@ export interface AztecNode
*/
getL2Tips(): Promise<L2Tips>;

/**
* Returns the sync status of the node's world state
*/
getWorldStateSyncStatus(): Promise<WorldStateSyncStatus>;

/**
* Find the indexes of the given leaves in the given tree.
* @param blockNumber - The block number at which to get the data or 'latest' for latest data
Expand Down Expand Up @@ -453,6 +459,8 @@ export interface AztecNode
export const AztecNodeApiSchema: ApiSchemaFor<AztecNode> = {
getL2Tips: z.function().args().returns(L2TipsSchema),

getWorldStateSyncStatus: z.function().args().returns(WorldStateSyncStatusSchema),

findLeavesIndexes: z
.function()
.args(L2BlockNumberSchema, z.nativeEnum(MerkleTreeId), z.array(schemas.Fr))
Expand Down
2 changes: 2 additions & 0 deletions yarn-project/circuit-types/src/interfaces/prover-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ export interface EpochProverManager {

getProvingJobSource(): ProvingJobConsumer;

getProverId(): Fr;

updateProverConfig(config: Partial<ProverConfig>): Promise<void>;
}

Expand Down
23 changes: 20 additions & 3 deletions yarn-project/circuit-types/src/interfaces/world_state.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { type L2BlockId } from '../l2_block_source.js';
import { z } from 'zod';

import type { MerkleTreeReadOperations, MerkleTreeWriteOperations } from './merkle_tree_operations.js';

/**
Expand All @@ -11,6 +12,14 @@ export enum WorldStateRunningState {
STOPPED,
}

export interface WorldStateSyncStatus {
latestBlockNumber: number;
latestBlockHash: string;
finalisedBlockNumber: number;
oldestHistoricBlockNumber: number;
treesAreSynched: boolean;
}

/**
* Defines the status of the world state synchronizer.
*/
Expand All @@ -20,9 +29,9 @@ export interface WorldStateSynchronizerStatus {
*/
state: WorldStateRunningState;
/**
* The block number that the world state synchronizer is synced to.
* The block numbers that the world state synchronizer is synced to.
*/
syncedToL2Block: L2BlockId;
syncSummary: WorldStateSyncStatus;
}

/** Provides writeable forks of the world state at a given block number. */
Expand Down Expand Up @@ -65,3 +74,11 @@ export interface WorldStateSynchronizer extends ForkMerkleTreeOperations {
*/
getCommitted(): MerkleTreeReadOperations;
}

export const WorldStateSyncStatusSchema = z.object({
finalisedBlockNumber: z.number(),
latestBlockNumber: z.number(),
latestBlockHash: z.string(),
oldestHistoricBlockNumber: z.number(),
treesAreSynched: z.boolean(),
}) satisfies z.ZodType<WorldStateSyncStatus>;
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export class L2BlockStream {
}
}

/** Interface to the local view of the chain. Implemented by world-state. */
/** Interface to the local view of the chain. Implemented by world-state and l2-tips-store. */
export interface L2BlockStreamLocalDataProvider {
getL2BlockHash(number: number): Promise<string | undefined>;
getL2Tips(): Promise<L2Tips>;
Expand Down
4 changes: 4 additions & 0 deletions yarn-project/circuits.js/src/structs/block_header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ export class BlockHeader {
return new BlockHeader(...BlockHeader.getFields(fields));
}

getSlot() {
return this.globalVariables.slotNumber.toBigInt();
}

getSize() {
return (
this.lastArchive.getSize() +
Expand Down
4 changes: 3 additions & 1 deletion yarn-project/end-to-end/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ function test_cmds {
echo "$prefix simple e2e_deploy_contract/deploy_method"
echo "$prefix simple e2e_deploy_contract/legacy"
echo "$prefix simple e2e_deploy_contract/private_initialization"
echo "$prefix simple e2e_epochs"
echo "$prefix simple e2e_epochs/epochs_empty_blocks"
echo "$prefix simple e2e_epochs/epochs_multi_proof"
echo "$prefix simple e2e_epochs/epochs_proof_fails"
echo "$prefix simple e2e_escrow_contract"
echo "$prefix simple e2e_event_logs"

Expand Down
206 changes: 0 additions & 206 deletions yarn-project/end-to-end/src/e2e_epochs.test.ts

This file was deleted.

Loading

0 comments on commit e2f675f

Please sign in to comment.