Skip to content

Commit

Permalink
fix: correctly use historical header
Browse files Browse the repository at this point in the history
  • Loading branch information
alexghr committed Oct 30, 2024
1 parent 8eb1c99 commit d583dd6
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
type DebugLogger,
EpochProofQuote,
EpochProofQuotePayload,
TxStatus,
createDebugLogger,
sleep,
} from '@aztec/aztec.js';
Expand Down Expand Up @@ -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 !!!
Expand All @@ -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({
Expand All @@ -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 });
Expand Down
10 changes: 5 additions & 5 deletions yarn-project/p2p/src/client/p2p_client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]);

Expand All @@ -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([
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/p2p/src/client/p2p_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Expand Down

0 comments on commit d583dd6

Please sign in to comment.