Skip to content

Commit

Permalink
fix: Archiver getBlocksForEpoch and EpochProvingJob on block 1 (#9016)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
spalladino authored Oct 4, 2024
1 parent 931c59b commit 9669db0
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 8 deletions.
2 changes: 1 addition & 1 deletion yarn-project/archiver/src/archiver/archiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean> {
Expand Down
17 changes: 12 additions & 5 deletions yarn-project/end-to-end/src/e2e_prover/full.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/prover-node/src/bond/bond-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
7 changes: 6 additions & 1 deletion yarn-project/prover-node/src/job/epoch-proving-job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions yarn-project/simulator/src/public/public_processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ export class PublicProcessorFactory {
this.telemetryClient,
);
}

public getInitialHeader() {
return this.merkleTree.getInitialHeader();
}
}

/**
Expand Down

0 comments on commit 9669db0

Please sign in to comment.