From d583dd680548cd1a072fce5b2b7bce31e790f2cd Mon Sep 17 00:00:00 2001 From: Alex Gherghisan Date: Wed, 30 Oct 2024 11:42:44 +0000 Subject: [PATCH] fix: correctly use historical header --- .../e2e_prover_coordination.test.ts | 30 +++++++++++++++---- .../p2p/src/client/p2p_client.test.ts | 10 +++---- yarn-project/p2p/src/client/p2p_client.ts | 2 +- 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/yarn-project/end-to-end/src/prover-coordination/e2e_prover_coordination.test.ts b/yarn-project/end-to-end/src/prover-coordination/e2e_prover_coordination.test.ts index 11a2dc5c075..f5b15cfb4e5 100644 --- a/yarn-project/end-to-end/src/prover-coordination/e2e_prover_coordination.test.ts +++ b/yarn-project/end-to-end/src/prover-coordination/e2e_prover_coordination.test.ts @@ -5,6 +5,7 @@ import { type DebugLogger, EpochProofQuote, EpochProofQuotePayload, + TxStatus, createDebugLogger, sleep, } from '@aztec/aztec.js'; @@ -387,12 +388,12 @@ describe('e2e_prover_coordination', () => { // Progress epochs with a block in each until we hit a reorg // Note tips are block numbers, not slots await expectTips({ pending: 3n, proven: 3n }); - await contract.methods.create_note(recipient, recipient, 10).send().wait(); + const tx2BeforeReorg = await contract.methods.create_note(recipient, recipient, 10).send().wait(); await expectTips({ pending: 4n, proven: 3n }); // Go to epoch 3 await advanceToNextEpoch(); - await contract.methods.create_note(recipient, recipient, 10).send().wait(); + const tx3BeforeReorg = await contract.methods.create_note(recipient, recipient, 10).send().wait(); await expectTips({ pending: 5n, proven: 3n }); // Go to epoch 4 !!! REORG !!! ay caramba !!! @@ -401,15 +402,32 @@ describe('e2e_prover_coordination', () => { // Wait a bit for the sequencer / node to notice a re-org await sleep(2000); + // the sequencer will add valid txs again but in a new block + const tx2AfterReorg = await ctx.aztecNode.getTxReceipt(tx2BeforeReorg.txHash); + const tx3AfterReorg = await ctx.aztecNode.getTxReceipt(tx3BeforeReorg.txHash); + + // the tx from epoch 2 is still valid since it references a proven block + // this will be added back onto the chain + expect(tx2AfterReorg.status).toEqual(TxStatus.SUCCESS); + expect(tx2AfterReorg.blockNumber).toEqual(tx2BeforeReorg.blockNumber); + expect(tx2AfterReorg.blockHash).not.toEqual(tx2BeforeReorg.blockHash); + + // the tx from epoch 3 is not valid anymore, since it was built against a reorged block + // should be dropped + expect(tx3AfterReorg.status).toEqual(TxStatus.DROPPED); + // new pxe, as it does not support reorgs const pxeServiceConfig = { ...getPXEServiceConfig() }; const newPxe = await createPXEService(ctx.aztecNode, pxeServiceConfig); const newWallet = await createAccount(newPxe); const newWalletAddress = newWallet.getAddress(); - // The chain will re-org back to block 3, but creating a new account will produce a block, so we expect - // 4 blocks in the pending chain here! - await expectTips({ pending: 4n, proven: 3n }); + // The chain will prune back to block 3 + // then include the txs from the pruned epochs that are still valid + // bringing us back to block 4 (same number, different hash) + // creating a new account will produce another block + // so we expect 5 blocks in the pending chain here! + await expectTips({ pending: 5n, proven: 3n }); // Submit proof claim for the new epoch const quoteForEpoch4 = await makeEpochProofQuote({ @@ -427,7 +445,7 @@ describe('e2e_prover_coordination', () => { logger.info('Sending new tx on reorged chain'); await contractFromNewPxe.methods.create_note(newWalletAddress, newWalletAddress, 10).send().wait(); - await expectTips({ pending: 5n, proven: 3n }); + await expectTips({ pending: 6n, proven: 3n }); // Expect the proof claim to be accepted for the chain after the reorg await expectProofClaimOnL1({ ...quoteForEpoch4.payload, proposer: publisherAddress }); diff --git a/yarn-project/p2p/src/client/p2p_client.test.ts b/yarn-project/p2p/src/client/p2p_client.test.ts index 0cf8baeddf1..c19fd464dcc 100644 --- a/yarn-project/p2p/src/client/p2p_client.test.ts +++ b/yarn-project/p2p/src/client/p2p_client.test.ts @@ -284,10 +284,10 @@ describe('In-Memory P2P Client', () => { // then prune the chain back to block 90 // only one tx should be deleted const goodTx = mockTx(); - goodTx.data.constants.globalVariables.blockNumber = new Fr(90); + goodTx.data.constants.historicalHeader.globalVariables.blockNumber = new Fr(90); const badTx = mockTx(); - badTx.data.constants.globalVariables.blockNumber = new Fr(95); + badTx.data.constants.historicalHeader.globalVariables.blockNumber = new Fr(95); txPool.getAllTxs.mockReturnValue([goodTx, badTx]); @@ -306,13 +306,13 @@ describe('In-Memory P2P Client', () => { // then prune the chain back to block 90 // only one tx should be deleted const goodButOldTx = mockTx(); - goodButOldTx.data.constants.globalVariables.blockNumber = new Fr(89); + goodButOldTx.data.constants.historicalHeader.globalVariables.blockNumber = new Fr(89); const goodTx = mockTx(); - goodTx.data.constants.globalVariables.blockNumber = new Fr(90); + goodTx.data.constants.historicalHeader.globalVariables.blockNumber = new Fr(90); const badTx = mockTx(); - badTx.data.constants.globalVariables.blockNumber = new Fr(95); + badTx.data.constants.historicalHeader.globalVariables.blockNumber = new Fr(95); txPool.getAllTxs.mockReturnValue([goodButOldTx, goodTx, badTx]); txPool.getMinedTxHashes.mockReturnValue([ diff --git a/yarn-project/p2p/src/client/p2p_client.ts b/yarn-project/p2p/src/client/p2p_client.ts index 3ce86f36d1d..a8bd5954eb4 100644 --- a/yarn-project/p2p/src/client/p2p_client.ts +++ b/yarn-project/p2p/src/client/p2p_client.ts @@ -642,7 +642,7 @@ export class P2PClient extends WithTracer implements P2P { const txsToDelete: TxHash[] = []; for (const tx of this.txPool.getAllTxs()) { // every tx that's been generated against a block that has now been pruned is no longer valid - if (tx.data.constants.globalVariables.blockNumber.toNumber() > latestBlock) { + if (tx.data.constants.historicalHeader.globalVariables.blockNumber.toNumber() > latestBlock) { txsToDelete.push(tx.getTxHash()); } }