Skip to content

Commit

Permalink
chore: Fork logs and prover job catch (#7982)
Browse files Browse the repository at this point in the history
Add logs to forking and a catch to the prover job.
  • Loading branch information
spalladino authored Aug 14, 2024
1 parent cdf62a0 commit 69bde53
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 22 deletions.
6 changes: 5 additions & 1 deletion yarn-project/kv-store/src/lmdb/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export class AztecLmdbStore implements AztecKVStore {
#rootDb: RootDatabase;
#data: Database<unknown, Key>;
#multiMapData: Database<unknown, Key>;
#log = createDebugLogger('aztec:kv-store:lmdb');

constructor(rootDb: RootDatabase, public readonly isEphemeral: boolean, private path?: string) {
this.#rootDb = rootDb;
Expand Down Expand Up @@ -59,7 +60,7 @@ export class AztecLmdbStore implements AztecKVStore {
ephemeral: boolean = false,
log = createDebugLogger('aztec:kv-store:lmdb'),
): AztecLmdbStore {
log.info(`Opening LMDB database at ${path || 'temporary location'}`);
log.verbose(`Opening LMDB database at ${path || 'temporary location'}`);
const rootDb = open({ path, noSync: ephemeral });
return new AztecLmdbStore(rootDb, ephemeral, path);
}
Expand All @@ -70,9 +71,12 @@ export class AztecLmdbStore implements AztecKVStore {
*/
async fork() {
const baseDir = this.path ? dirname(this.path) : tmpdir();
this.#log.debug(`Forking store with basedir ${baseDir}`);
const forkPath = join(await mkdtemp(join(baseDir, 'aztec-store-fork-')), 'root.mdb');
this.#log.verbose(`Forking store to ${forkPath}`);
await this.#rootDb.backup(forkPath, false);
const forkDb = open(forkPath, { noSync: this.isEphemeral });
this.#log.debug(`Forked store at ${forkPath} opened successfully`);
return new AztecLmdbStore(forkDb, this.isEphemeral, forkPath);
}

Expand Down
50 changes: 29 additions & 21 deletions yarn-project/prover-node/src/prover-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,28 +63,36 @@ export class ProverNode {
* Checks whether there are new blocks to prove, proves them, and submits them.
*/
protected async work() {
if (this.options.disableAutomaticProving) {
return;
try {
if (this.options.disableAutomaticProving) {
return;
}

const [latestBlockNumber, latestProvenBlockNumber] = await Promise.all([
this.l2BlockSource.getBlockNumber(),
this.l2BlockSource.getProvenBlockNumber(),
]);

// Consider both the latest block we are proving and the last block proven on the chain
const latestBlockBeingProven = this.latestBlockWeAreProving ?? 0;
const latestProven = Math.max(latestBlockBeingProven, latestProvenBlockNumber);
if (latestProven >= latestBlockNumber) {
this.log.debug(`No new blocks to prove`, {
latestBlockNumber,
latestProvenBlockNumber,
latestBlockBeingProven,
});
return;
}

const fromBlock = latestProven + 1;
const toBlock = fromBlock; // We only prove one block at a time for now

await this.startProof(fromBlock, toBlock);
this.latestBlockWeAreProving = toBlock;
} catch (err) {
this.log.error(`Error in prover node work`, err);
}

const [latestBlockNumber, latestProvenBlockNumber] = await Promise.all([
this.l2BlockSource.getBlockNumber(),
this.l2BlockSource.getProvenBlockNumber(),
]);

// Consider both the latest block we are proving and the last block proven on the chain
const latestBlockBeingProven = this.latestBlockWeAreProving ?? 0;
const latestProven = Math.max(latestBlockBeingProven, latestProvenBlockNumber);
if (latestProven >= latestBlockNumber) {
this.log.debug(`No new blocks to prove`, { latestBlockNumber, latestProvenBlockNumber, latestBlockBeingProven });
return;
}

const fromBlock = latestProven + 1;
const toBlock = fromBlock; // We only prove one block at a time for now

await this.startProof(fromBlock, toBlock);
this.latestBlockWeAreProving = toBlock;
}

/**
Expand Down

0 comments on commit 69bde53

Please sign in to comment.