From 8ab012ce4eb8473cbd7ee84bc4fbd3dec3221212 Mon Sep 17 00:00:00 2001 From: Rahul Kothari Date: Thu, 17 Aug 2023 17:09:16 +0000 Subject: [PATCH] move timestamp change to sequencer --- yarn-project/end-to-end/src/e2e_cheat_codes.test.ts | 9 ++++++++- .../src/sequencer/public_processor.ts | 11 ----------- .../sequencer-client/src/sequencer/sequencer.ts | 10 ++++++++++ 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/yarn-project/end-to-end/src/e2e_cheat_codes.test.ts b/yarn-project/end-to-end/src/e2e_cheat_codes.test.ts index c7a30ec5f562..94d74b6672d4 100644 --- a/yarn-project/end-to-end/src/e2e_cheat_codes.test.ts +++ b/yarn-project/end-to-end/src/e2e_cheat_codes.test.ts @@ -170,7 +170,14 @@ describe('e2e_cheat_codes', () => { expect(await cc.eth.timestamp()).toEqual(newTimestamp); // ensure rollup contract is correctly updated expect(Number(await rollup.read.lastBlockTs())).toEqual(newTimestamp); - }, 50_000); + + // do another transaction (for the next rollup block), where we expect timestamp to be 1 + newTimestamp + // because of the hack explained in https://github.com/AztecProtocol/aztec-packages/issues/1614 + const txUpdate = contract.methods.update_tot().send({ origin: recipient }); + await txUpdate.isMined({ interval: 0.1 }); + const lastUpdatedTs2 = Number((await contract.methods.getTot(0).view())['last_updated_ts']); + expect(lastUpdatedTs2).toEqual(newTimestamp + 1); + }, 25_000); it('should throw if setting L2 block time to a past timestamp', async () => { const timestamp = await cc.eth.timestamp(); diff --git a/yarn-project/sequencer-client/src/sequencer/public_processor.ts b/yarn-project/sequencer-client/src/sequencer/public_processor.ts index 8a6e3fcbb0a9..8574a9083fd4 100644 --- a/yarn-project/sequencer-client/src/sequencer/public_processor.ts +++ b/yarn-project/sequencer-client/src/sequencer/public_processor.ts @@ -62,17 +62,6 @@ export class PublicProcessorFactory { globalVariables: GlobalVariables, ): Promise { const blockData = await getHistoricBlockData(this.merkleTree, prevGlobalVariables); - - // TODO(rahul) - fix #1614. By using the cheatcode warp to modify L2 time, - // txs in the new rollup would have same time as the txs in the previous rollup. - // We overcome this now by identifying if the last rollup time was warped (if two rollups have same time) - // and tell public-processor to use a different time (increment last rollup block) - // more details at https://github.com/AztecProtocol/aztec-packages/issues/1614 - const isWarped = prevGlobalVariables.timestamp == globalVariables.timestamp; - if (isWarped) { - globalVariables.timestamp = new Fr(globalVariables.timestamp.value + 1n); - } - return new PublicProcessor( this.merkleTree, getPublicExecutor(this.merkleTree, this.contractDataSource, this.l1Tol2MessagesDataSource, blockData), diff --git a/yarn-project/sequencer-client/src/sequencer/sequencer.ts b/yarn-project/sequencer-client/src/sequencer/sequencer.ts index 332486468531..14b75de5c7b5 100644 --- a/yarn-project/sequencer-client/src/sequencer/sequencer.ts +++ b/yarn-project/sequencer-client/src/sequencer/sequencer.ts @@ -144,6 +144,16 @@ export class Sequencer { const newGlobalVariables = await this.globalsBuilder.buildGlobalVariables(new Fr(blockNumber)); const prevGlobalVariables = (await this.l2BlockSource.getL2Block(-1))?.globalVariables ?? GlobalVariables.empty(); + // TODO(rahul) - fix #1614. By using the cheatcode warp to modify L2 time, + // txs in the new rollup would have same time as the txs in the previous rollup. + // We overcome this now by identifying if the last rollup time was warped (if two rollups have same time) + // and tell public-processor to use a different time (increment last rollup block) + // more details at https://github.com/AztecProtocol/aztec-packages/issues/1614 + const isWarped = prevGlobalVariables.timestamp.equals(newGlobalVariables.timestamp); + if (isWarped) { + newGlobalVariables.timestamp = new Fr(newGlobalVariables.timestamp.value + 1n); + } + // Process txs and drop the ones that fail processing // We create a fresh processor each time to reset any cached state (eg storage writes) const processor = await this.publicProcessorFactory.create(prevGlobalVariables, newGlobalVariables);