-
Notifications
You must be signed in to change notification settings - Fork 234
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: get rid of timetraveler from l1-publisher
- Loading branch information
Showing
17 changed files
with
218 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './fixtures.js'; | ||
export * from './logging.js'; | ||
export * from './utils.js'; | ||
export * from './watcher.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { type DebugLogger, type EthCheatCodes, createDebugLogger } from '@aztec/aztec.js'; | ||
import { type EthAddress } from '@aztec/circuits.js'; | ||
import { RunningPromise } from '@aztec/foundation/running-promise'; | ||
import { RollupAbi } from '@aztec/l1-artifacts'; | ||
|
||
import { type GetContractReturnType, type HttpTransport, type PublicClient, getAddress, getContract } from 'viem'; | ||
import type * as chains from 'viem/chains'; | ||
|
||
export class Watcher { | ||
private rollup: GetContractReturnType<typeof RollupAbi, PublicClient<HttpTransport, chains.Chain>>; | ||
|
||
private filledRunningPromise?: RunningPromise; | ||
|
||
private logger: DebugLogger = createDebugLogger(`aztec:utils:watcher`); | ||
|
||
constructor( | ||
private cheatcodes: EthCheatCodes, | ||
rollupAddress: EthAddress, | ||
publicClient: PublicClient<HttpTransport, chains.Chain>, | ||
) { | ||
this.rollup = getContract({ | ||
address: getAddress(rollupAddress.toString()), | ||
abi: RollupAbi, | ||
client: publicClient, | ||
}); | ||
|
||
this.logger.info(`Watcher created for rollup at ${rollupAddress}`); | ||
} | ||
|
||
start() { | ||
if (this.filledRunningPromise) { | ||
throw new Error('Watcher already watching for filled slot'); | ||
} | ||
this.filledRunningPromise = new RunningPromise(() => this.mineIfSlotFilled(), 1000); | ||
this.filledRunningPromise.start(); | ||
this.logger.info(`Watcher started`); | ||
} | ||
|
||
async stop() { | ||
await this.filledRunningPromise?.stop(); | ||
} | ||
|
||
async mineIfSlotFilled() { | ||
try { | ||
const currentSlot = await this.rollup.read.getCurrentSlot(); | ||
const pendingBlockNumber = BigInt(await this.rollup.read.pendingBlockCount()) - 1n; | ||
const [, , lastSlotNumber] = await this.rollup.read.blocks([pendingBlockNumber]); | ||
|
||
if (currentSlot === lastSlotNumber) { | ||
// We should jump to the next slot | ||
const timestamp = await this.rollup.read.getTimestampForSlot([currentSlot + 1n]); | ||
try { | ||
await this.cheatcodes.warp(Number(timestamp)); | ||
} catch (e) { | ||
this.logger.error(`Failed to warp to timestamp ${timestamp}: ${e}`); | ||
} | ||
|
||
this.logger.info(`Slot ${currentSlot} was filled, jumped to next slot`); | ||
} | ||
} catch (err) { | ||
this.logger.error('mineIfSlotFilled failed', err); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.