-
Notifications
You must be signed in to change notification settings - Fork 0
refactor: adds block module #86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,99 @@ | ||
//! This file implements the [`trevm::Cfg`] and [`trevm::Block`] traits for Pecorino blocks. | ||
use alloy::primitives::{Address, B256, FixedBytes, U256}; | ||
use trevm::{ | ||
Block, | ||
revm::{ | ||
context::{BlockEnv, CfgEnv}, | ||
context_interface::block::BlobExcessGasAndPrice, | ||
primitives::hardfork::SpecId, | ||
}, | ||
}; | ||
|
||
use crate::config::BuilderConfig; | ||
|
||
/// PecorinoCfg holds network-level configuration values. | ||
#[derive(Debug, Clone, Copy)] | ||
pub struct PecorinoCfg {} | ||
|
||
impl trevm::Cfg for PecorinoCfg { | ||
/// Fills the configuration environment with Pecorino-specific values. | ||
/// | ||
/// # Arguments | ||
/// | ||
/// - `cfg_env`: The configuration environment to be filled. | ||
fn fill_cfg_env(&self, cfg_env: &mut CfgEnv) { | ||
let CfgEnv { chain_id, spec, .. } = cfg_env; | ||
|
||
*chain_id = signet_constants::pecorino::RU_CHAIN_ID; | ||
*spec = SpecId::default(); | ||
} | ||
} | ||
|
||
/// PecorinoBlockEnv holds block-level configurations for Pecorino blocks. | ||
#[derive(Debug, Clone, Copy)] | ||
pub struct PecorinoBlockEnv { | ||
/// The block number for this block. | ||
pub number: u64, | ||
/// The address the block reward should be sent to. | ||
pub beneficiary: Address, | ||
/// Timestamp for the block. | ||
pub timestamp: u64, | ||
/// The gas limit for this block environment. | ||
pub gas_limit: u64, | ||
/// The basefee to use for calculating gas usage. | ||
pub basefee: u64, | ||
/// The prevrandao to use for this block. | ||
pub prevrandao: Option<FixedBytes<32>>, | ||
} | ||
|
||
/// Implements [`trevm::Block`] for the Pecorino block. | ||
impl Block for PecorinoBlockEnv { | ||
/// Fills the block environment with the Pecorino specific values | ||
fn fill_block_env(&self, block_env: &mut BlockEnv) { | ||
// Destructure the fields off of the block_env and modify them | ||
let BlockEnv { | ||
number, | ||
beneficiary, | ||
timestamp, | ||
gas_limit, | ||
basefee, | ||
difficulty, | ||
prevrandao, | ||
blob_excess_gas_and_price, | ||
} = block_env; | ||
*number = self.number; | ||
*beneficiary = self.beneficiary; | ||
*timestamp = self.timestamp; | ||
*gas_limit = self.gas_limit; | ||
*basefee = self.basefee; | ||
*prevrandao = self.prevrandao; | ||
|
||
// NB: The following fields are set to sane defaults because they | ||
// are not supported by the rollup | ||
*difficulty = U256::ZERO; | ||
*blob_excess_gas_and_price = | ||
Some(BlobExcessGasAndPrice { excess_blob_gas: 0, blob_gasprice: 0 }); | ||
} | ||
} | ||
|
||
impl PecorinoBlockEnv { | ||
/// Returns a new PecorinoBlockEnv with the specified values. | ||
/// | ||
/// # Arguments | ||
/// | ||
/// - config: The BuilderConfig for the builder. | ||
/// - number: The block number of this block, usually the latest block number plus 1, | ||
/// unless simulating blocks in the past. | ||
/// - timestamp: The timestamp of the block, typically set to the deadline of the | ||
/// block building task. | ||
pub fn new(config: BuilderConfig, number: u64, timestamp: u64, basefee: u64) -> Self { | ||
PecorinoBlockEnv { | ||
number, | ||
beneficiary: config.builder_rewards_address, | ||
timestamp, | ||
gas_limit: config.rollup_block_gas_limit, | ||
basefee, | ||
prevrandao: Some(B256::random()), | ||
} | ||
} | ||
} |
This file contains hidden or 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,8 @@ | ||
//! block holds the tasks responsible for block environment configuration, | ||
//! preparation, and simulation. | ||
|
||
/// Block simulation task for building blocks. | ||
pub mod sim; | ||
|
||
/// Block environment configuration for the builder. | ||
pub mod cfg; |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.