Skip to content

Commit

Permalink
move timestamp change to sequencer
Browse files Browse the repository at this point in the history
  • Loading branch information
rahul-kothari committed Aug 18, 2023
1 parent 4b946b6 commit 8ab012c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
9 changes: 8 additions & 1 deletion yarn-project/end-to-end/src/e2e_cheat_codes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
11 changes: 0 additions & 11 deletions yarn-project/sequencer-client/src/sequencer/public_processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,6 @@ export class PublicProcessorFactory {
globalVariables: GlobalVariables,
): Promise<PublicProcessor> {
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),
Expand Down
10 changes: 10 additions & 0 deletions yarn-project/sequencer-client/src/sequencer/sequencer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 8ab012c

Please sign in to comment.