-
Notifications
You must be signed in to change notification settings - Fork 297
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Revert to current date as timestamp for devnet
When running devnet, using the slot timestamps instead of current timestmap meant that blocks were often generated with a timestamp much into the future. This screwed up settings such as the min and max time between blocks for a sequencer configuration. In addition, the custom block timestamp interval in anvil meant that we could no longer rely on L1 timestamps for measuring time, which was needed for tracking the time between a block being submitted and its proof. This PR changes timestamps if devnet is set so that we use the current timestamp for building blocks, do not alter anvil's block timestamp, and drop time validations.
- Loading branch information
1 parent
bfbc4b2
commit 4780b21
Showing
13 changed files
with
143 additions
and
25 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
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
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
75 changes: 75 additions & 0 deletions
75
yarn-project/sequencer-client/src/global_variable_builder/devnet_global_builder.ts
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,75 @@ | ||
import { type AztecAddress, type EthAddress, GasFees, GlobalVariables } from '@aztec/circuits.js'; | ||
import { type L1ReaderConfig, createEthereumChain } from '@aztec/ethereum'; | ||
import { Fr } from '@aztec/foundation/fields'; | ||
import { createDebugLogger } from '@aztec/foundation/log'; | ||
import { RollupAbi } from '@aztec/l1-artifacts'; | ||
|
||
import { | ||
type GetContractReturnType, | ||
type HttpTransport, | ||
type PublicClient, | ||
createPublicClient, | ||
getAddress, | ||
getContract, | ||
http, | ||
} from 'viem'; | ||
import type * as chains from 'viem/chains'; | ||
|
||
/** | ||
* Simple global variables builder for devnet. Uses current timestamp and slots equal to block numbers. | ||
*/ | ||
export class DevnetGlobalVariableBuilder { | ||
private log = createDebugLogger('aztec:sequencer:devnet_global_variable_builder'); | ||
|
||
private rollupContract: GetContractReturnType<typeof RollupAbi, PublicClient<HttpTransport, chains.Chain>>; | ||
private publicClient: PublicClient<HttpTransport, chains.Chain>; | ||
|
||
constructor(config: L1ReaderConfig) { | ||
const { l1RpcUrl, l1ChainId: chainId, l1Contracts } = config; | ||
|
||
const chain = createEthereumChain(l1RpcUrl, chainId); | ||
|
||
this.publicClient = createPublicClient({ | ||
chain: chain.chainInfo, | ||
transport: http(chain.rpcUrl), | ||
}); | ||
|
||
this.rollupContract = getContract({ | ||
address: getAddress(l1Contracts.rollupAddress.toString()), | ||
abi: RollupAbi, | ||
client: this.publicClient, | ||
}); | ||
} | ||
|
||
/** | ||
* Simple builder of global variables that use the minimum time possible. | ||
* @param blockNumber - The block number to build global variables for. | ||
* @param coinbase - The address to receive block reward. | ||
* @param feeRecipient - The address to receive fees. | ||
* @returns The global variables for the given block number. | ||
*/ | ||
public async buildGlobalVariables( | ||
blockNumber: Fr, | ||
coinbase: EthAddress, | ||
feeRecipient: AztecAddress, | ||
): Promise<GlobalVariables> { | ||
const version = new Fr(await this.rollupContract.read.VERSION()); | ||
const chainId = new Fr(this.publicClient.chain.id); | ||
const timestamp = new Fr(Math.floor(Date.now() / 1000)); | ||
const slot = blockNumber; | ||
|
||
const gasFees = GasFees.default(); | ||
const globalVariables = new GlobalVariables( | ||
chainId, | ||
version, | ||
blockNumber, | ||
slot, | ||
timestamp, | ||
coinbase, | ||
feeRecipient, | ||
gasFees, | ||
); | ||
this.log.debug(`Built global variables for block ${blockNumber}`, globalVariables.toJSON()); | ||
return globalVariables; | ||
} | ||
} |
20 changes: 19 additions & 1 deletion
20
yarn-project/sequencer-client/src/global_variable_builder/index.ts
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 +1,19 @@ | ||
export { GlobalVariableBuilder } from './global_builder.js'; | ||
import { type AztecAddress, type EthAddress, type GlobalVariables } from '@aztec/circuits.js'; | ||
import { IS_DEV_NET } from '@aztec/circuits.js'; | ||
import { type L1ReaderConfig } from '@aztec/ethereum'; | ||
import { type Fr } from '@aztec/foundation/fields'; | ||
|
||
import { DevnetGlobalVariableBuilder } from './devnet_global_builder.js'; | ||
import { SimpleGlobalVariableBuilder } from './simple_global_builder.js'; | ||
|
||
export { DevnetGlobalVariableBuilder } from './devnet_global_builder.js'; | ||
export { SimpleGlobalVariableBuilder } from './simple_global_builder.js'; | ||
|
||
export function createGlobalVariableBuilder(config: L1ReaderConfig): GlobalVariableBuilder { | ||
return IS_DEV_NET ? new DevnetGlobalVariableBuilder(config) : new SimpleGlobalVariableBuilder(config); | ||
} | ||
|
||
/** Builds global variables for a block. */ | ||
export interface GlobalVariableBuilder { | ||
buildGlobalVariables(blockNumber: Fr, coinbase: EthAddress, feeRecipient: AztecAddress): Promise<GlobalVariables>; | ||
} |
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