From e1e1bf01ff5f962985365bb50c7d0bc2de8b493b Mon Sep 17 00:00:00 2001 From: Santiago Palladino Date: Wed, 14 Aug 2024 12:04:38 -0300 Subject: [PATCH] chore: Fork logs and prover job catch Add logs to forking and a catch to the prover job. --- yarn-project/kv-store/src/lmdb/store.ts | 6 ++- yarn-project/prover-node/src/prover-node.ts | 50 ++++++++++++--------- 2 files changed, 34 insertions(+), 22 deletions(-) diff --git a/yarn-project/kv-store/src/lmdb/store.ts b/yarn-project/kv-store/src/lmdb/store.ts index 55e41e7bc24..f23ca16338c 100644 --- a/yarn-project/kv-store/src/lmdb/store.ts +++ b/yarn-project/kv-store/src/lmdb/store.ts @@ -24,6 +24,7 @@ export class AztecLmdbStore implements AztecKVStore { #rootDb: RootDatabase; #data: Database; #multiMapData: Database; + #log = createDebugLogger('aztec:kv-store:lmdb'); constructor(rootDb: RootDatabase, public readonly isEphemeral: boolean, private path?: string) { this.#rootDb = rootDb; @@ -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); } @@ -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); } diff --git a/yarn-project/prover-node/src/prover-node.ts b/yarn-project/prover-node/src/prover-node.ts index 1e1c5c06bbd..8c9f7a21fb1 100644 --- a/yarn-project/prover-node/src/prover-node.ts +++ b/yarn-project/prover-node/src/prover-node.ts @@ -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; } /**