This repository has been archived by the owner on Aug 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Rename block_context.rs -> context.rs. This will hold all context types. - Rename block_execution.rs -> block.rs and move `BlockInfo` and `GasPrices` there (`GasPrices` is only used inside `BlockInfo`). No other changes.
- Loading branch information
Gilad Chase
committed
Jan 22, 2024
1 parent
0716d4d
commit 1603e60
Showing
30 changed files
with
139 additions
and
134 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
use starknet_api::block::{BlockHash, BlockNumber, BlockTimestamp}; | ||
use starknet_api::core::ContractAddress; | ||
use starknet_api::hash::StarkFelt; | ||
use starknet_api::state::StorageKey; | ||
|
||
use crate::abi::constants; | ||
use crate::state::state_api::{State, StateResult}; | ||
use crate::transaction::objects::FeeType; | ||
|
||
#[cfg(test)] | ||
#[path = "block_test.rs"] | ||
pub mod block_test; | ||
|
||
#[derive(Clone, Debug)] | ||
pub struct BlockInfo { | ||
pub block_number: BlockNumber, | ||
pub block_timestamp: BlockTimestamp, | ||
|
||
// Fee-related. | ||
pub sequencer_address: ContractAddress, | ||
pub gas_prices: GasPrices, | ||
pub use_kzg_da: bool, | ||
} | ||
|
||
#[derive(Clone, Debug)] | ||
pub struct GasPrices { | ||
pub eth_l1_gas_price: u128, // In wei. | ||
pub strk_l1_gas_price: u128, // In fri. | ||
pub eth_l1_data_gas_price: u128, // In wei. | ||
pub strk_l1_data_gas_price: u128, // In fri. | ||
} | ||
|
||
impl GasPrices { | ||
pub fn get_gas_price_by_fee_type(&self, fee_type: &FeeType) -> u128 { | ||
match fee_type { | ||
FeeType::Strk => self.strk_l1_gas_price, | ||
FeeType::Eth => self.eth_l1_gas_price, | ||
} | ||
} | ||
|
||
pub fn get_data_gas_price_by_fee_type(&self, fee_type: &FeeType) -> u128 { | ||
match fee_type { | ||
FeeType::Strk => self.strk_l1_data_gas_price, | ||
FeeType::Eth => self.eth_l1_data_gas_price, | ||
} | ||
} | ||
} | ||
|
||
// Block pre-processing. | ||
// Writes the hash of the (current_block_number - N) block under its block number in the dedicated | ||
// contract state, where N=STORED_BLOCK_HASH_BUFFER. | ||
pub fn pre_process_block( | ||
state: &mut dyn State, | ||
old_block_number_and_hash: Option<(BlockNumber, BlockHash)>, | ||
) -> StateResult<()> { | ||
if let Some((block_number, block_hash)) = old_block_number_and_hash { | ||
state.set_storage_at( | ||
ContractAddress::try_from(StarkFelt::from(constants::BLOCK_HASH_CONTRACT_ADDRESS)) | ||
.expect("Failed to convert `BLOCK_HASH_CONTRACT_ADDRESS` to ContractAddress."), | ||
StorageKey::try_from(StarkFelt::from(block_number.0)) | ||
.expect("Failed to convert BlockNumber to StorageKey."), | ||
block_hash.0, | ||
)?; | ||
} | ||
|
||
Ok(()) | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
use starknet_api::core::{ChainId, ContractAddress}; | ||
|
||
use crate::block::BlockInfo; | ||
use crate::transaction::objects::FeeType; | ||
use crate::versioned_constants::VersionedConstants; | ||
|
||
#[derive(Clone, Debug)] | ||
pub struct BlockContext { | ||
pub block_info: BlockInfo, | ||
pub chain_info: ChainInfo, | ||
pub versioned_constants: VersionedConstants, | ||
} | ||
|
||
#[derive(Clone, Debug)] | ||
pub struct ChainInfo { | ||
pub chain_id: ChainId, | ||
pub fee_token_addresses: FeeTokenAddresses, | ||
} | ||
|
||
impl ChainInfo { | ||
pub fn fee_token_address(&self, fee_type: &FeeType) -> ContractAddress { | ||
self.fee_token_addresses.get_by_fee_type(fee_type) | ||
} | ||
} | ||
|
||
#[derive(Clone, Debug)] | ||
pub struct FeeTokenAddresses { | ||
pub strk_fee_token_address: ContractAddress, | ||
pub eth_fee_token_address: ContractAddress, | ||
} | ||
|
||
impl FeeTokenAddresses { | ||
pub fn get_by_fee_type(&self, fee_type: &FeeType) -> ContractAddress { | ||
match fee_type { | ||
FeeType::Strk => self.strk_fee_token_address, | ||
FeeType::Eth => self.eth_fee_token_address, | ||
} | ||
} | ||
} |
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
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
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
Oops, something went wrong.