From 9669db07392b9feeca2789aca181aec58dddcfec Mon Sep 17 00:00:00 2001 From: Santiago Palladino Date: Fri, 4 Oct 2024 12:38:59 -0300 Subject: [PATCH] fix: Archiver getBlocksForEpoch and EpochProvingJob on block 1 (#9016) Fixes a few issues around proving: - Archiver was returning block headers in reverse order when filtering by epoch. This hadn't popped up in e2e tests before because we were testing with single-block epochs. We now changed the e2e_prover test to have two blocks in the epoch. - Epoch proving job would fail to prove an epoch that started in block one because it requested the header of the previous block to begin, which was undefined. That edge case is now handled. - Bond manager would trigger a top up when the amount to top up was exactly zero. --- yarn-project/archiver/src/archiver/archiver.ts | 2 +- .../end-to-end/src/e2e_prover/full.test.ts | 17 ++++++++++++----- .../prover-node/src/bond/bond-manager.ts | 2 +- .../prover-node/src/job/epoch-proving-job.ts | 7 ++++++- .../simulator/src/public/public_processor.ts | 4 ++++ 5 files changed, 24 insertions(+), 8 deletions(-) diff --git a/yarn-project/archiver/src/archiver/archiver.ts b/yarn-project/archiver/src/archiver/archiver.ts index cccef6420c9..5707fbf86cf 100644 --- a/yarn-project/archiver/src/archiver/archiver.ts +++ b/yarn-project/archiver/src/archiver/archiver.ts @@ -479,7 +479,7 @@ export class Archiver implements ArchiveSource { block = await this.getBlock(block.number - 1); } - return blocks; + return blocks.reverse(); } public async isEpochComplete(epochNumber: bigint): Promise { diff --git a/yarn-project/end-to-end/src/e2e_prover/full.test.ts b/yarn-project/end-to-end/src/e2e_prover/full.test.ts index 316b65b42d7..fb53e7845a4 100644 --- a/yarn-project/end-to-end/src/e2e_prover/full.test.ts +++ b/yarn-project/end-to-end/src/e2e_prover/full.test.ts @@ -60,12 +60,19 @@ describe('full_prover', () => { await expect(t.circuitProofVerifier?.verifyProof(publicTx)).resolves.not.toThrow(); await expect(t.circuitProofVerifier?.verifyProof(privateTx)).resolves.not.toThrow(); - // Sends the txs to node and awaits them to be mined - logger.info(`Sending txs`); + // Sends the txs to node and awaits them to be mined separately, so they land on different blocks, + // and we have more than one block in the epoch we end up proving + logger.info(`Sending private tx`); const sendOpts = { skipPublicSimulation: true }; - const txs = [privateInteraction.send(sendOpts), publicInteraction.send(sendOpts)]; - logger.info(`Awaiting txs to be mined`); - await Promise.all(txs.map(tx => tx.wait({ timeout: 300, interval: 10, proven: false }))); + const txPrivate = privateInteraction.send(sendOpts); + await txPrivate.wait({ timeout: 300, interval: 10, proven: false }); + + logger.info(`Sending public tx`); + const txPublic = publicInteraction.send(sendOpts); + await txPublic.wait({ timeout: 300, interval: 10, proven: false }); + + logger.info(`Both txs have been mined`); + const txs = [txPrivate, txPublic]; // Flag the transfers on the token simulator tokenSim.transferPrivate(sender, recipient, privateSendAmount); diff --git a/yarn-project/prover-node/src/bond/bond-manager.ts b/yarn-project/prover-node/src/bond/bond-manager.ts index 6404c148470..75c3bacfc8f 100644 --- a/yarn-project/prover-node/src/bond/bond-manager.ts +++ b/yarn-project/prover-node/src/bond/bond-manager.ts @@ -25,7 +25,7 @@ export class BondManager { try { const current = await this.escrowContract.getProverDeposit(); - if (current > minimum) { + if (current >= minimum) { this.logger.debug(`Current prover bond ${current} is above minimum ${minimum}`); return; } diff --git a/yarn-project/prover-node/src/job/epoch-proving-job.ts b/yarn-project/prover-node/src/job/epoch-proving-job.ts index 22c2f640d54..1fcb0f0801c 100644 --- a/yarn-project/prover-node/src/job/epoch-proving-job.ts +++ b/yarn-project/prover-node/src/job/epoch-proving-job.ts @@ -63,7 +63,12 @@ export class EpochProvingJob { try { this.prover.startNewEpoch(epochNumber, epochSize); - let previousHeader = await this.l2BlockSource.getBlockHeader(this.blocks[0].number - 1); + + // Get the genesis header if the first block of the epoch is the first block of the chain + let previousHeader = + this.blocks[0].number === 1 + ? this.publicProcessorFactory.getInitialHeader() + : await this.l2BlockSource.getBlockHeader(this.blocks[0].number - 1); for (const block of this.blocks) { // Gather all data to prove this block diff --git a/yarn-project/simulator/src/public/public_processor.ts b/yarn-project/simulator/src/public/public_processor.ts index 486747c7f92..7879d0457b7 100644 --- a/yarn-project/simulator/src/public/public_processor.ts +++ b/yarn-project/simulator/src/public/public_processor.ts @@ -70,6 +70,10 @@ export class PublicProcessorFactory { this.telemetryClient, ); } + + public getInitialHeader() { + return this.merkleTree.getInitialHeader(); + } } /**