Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

refactor: use gas price from BlockInfo #1256

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions rpc_state_reader/src/sir_state_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,7 @@ pub fn execute_tx_configurable_with_state(
RpcChain::TestNet => StarknetChainId::TestNet,
RpcChain::TestNet2 => StarknetChainId::TestNet2,
};
let starknet_os_config = StarknetOsConfig::new(
chain_id.to_felt(),
fee_token_address,
block_info.gas_price.clone(),
);
let starknet_os_config = StarknetOsConfig::new(chain_id.to_felt(), fee_token_address);

// Get transaction before giving ownership of the reader
let tx = match tx {
Expand Down
6 changes: 1 addition & 5 deletions src/bin/invoke_with_cachedstate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,7 @@ fn create_initial_state() -> CachedState<InMemoryStateReader, PermanentContractC

pub fn new_starknet_block_context_for_testing() -> BlockContext {
BlockContext::new(
StarknetOsConfig::new(
StarknetChainId::TestNet.to_felt(),
Default::default(),
Default::default(),
),
StarknetOsConfig::new(StarknetChainId::TestNet.to_felt(), Default::default()),
0,
0,
Default::default(),
Expand Down
12 changes: 2 additions & 10 deletions src/definitions/block_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@ pub struct StarknetOsConfig {
/// Address of the token used when paying fees
#[get = "pub"]
pub(crate) fee_token_address: FeeTokenAddresses,
/// Price of gas
#[get = "pub"]
pub(crate) gas_price: GasPrices,
}

#[derive(Clone, Debug, PartialEq, Eq, Default)]
Expand Down Expand Up @@ -135,15 +132,10 @@ impl StarknetOsConfig {
/// * `chain_id` - [`Felt252`] of the configured chain.
/// * `fee_token_address` - Address of the token used when paying fees.
/// * `gas_price` - Price of gas.
pub const fn new(
chain_id: Felt252,
fee_token_address: FeeTokenAddresses,
gas_price: GasPrices,
) -> Self {
pub const fn new(chain_id: Felt252, fee_token_address: FeeTokenAddresses) -> Self {
StarknetOsConfig {
chain_id,
fee_token_address,
gas_price,
}
}
}
Expand Down Expand Up @@ -218,7 +210,7 @@ impl BlockContext {
}

pub fn get_gas_price_by_fee_type(&self, fee_type: &FeeType) -> u128 {
self.starknet_os_config.gas_price.get_by_fee_type(fee_type)
self.block_info().gas_price.get_by_fee_type(fee_type)
}

pub fn get_fee_token_address_by_fee_type(&self, fee_type: &FeeType) -> &Address {
Expand Down
1 change: 0 additions & 1 deletion src/definitions/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ lazy_static! {
"0x4c07059285c2607d528a4c5220ef1f64d8f01273c23cfd9dec68759f61b544"
).unwrap()),
},
gas_price: crate::definitions::block_context::GasPrices::default(),
};

pub static ref DECLARE_VERSION: Felt252 = 2.into();
Expand Down
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ mod test {
);

let mut block_context = BlockContext::default();
block_context.starknet_os_config.gas_price = GasPrices::new(1, 0);
block_context.block_info_mut().gas_price = GasPrices::new(1, 0);

let estimated_fee = estimate_message_fee(
&l1_handler,
Expand Down Expand Up @@ -1072,7 +1072,7 @@ mod test {
.unwrap();

let mut block_context = BlockContext::default();
block_context.starknet_os_config.gas_price = GasPrices::new(1, 0);
block_context.block_info_mut().gas_price = GasPrices::new(1, 0);

simulate_transaction(
&[&l1_handler_tx],
Expand Down Expand Up @@ -1272,7 +1272,7 @@ mod test {
declare.hash_value = Felt252::from_dec_str("2718").unwrap();

let mut block_context = BlockContext::default();
block_context.starknet_os_config_mut().gas_price = GasPrices::new(12, 0);
block_context.block_info.gas_price = GasPrices::new(12, 0);

let declare_tx = Transaction::DeclareDeprecated(declare);

Expand Down
2 changes: 1 addition & 1 deletion src/transaction/declare_deprecated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -961,7 +961,7 @@ mod tests {
// ---------------------
let mut state_copy = state.clone_for_testing();
let mut bock_context = BlockContext::default();
bock_context.starknet_os_config.gas_price = GasPrices::new(12, 0);
bock_context.block_info_mut().gas_price = GasPrices::new(12, 0);
assert!(
declare
.execute(
Expand Down
4 changes: 2 additions & 2 deletions src/transaction/fee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ mod tests {
);
let mut tx_execution_context = TransactionExecutionContext::default();
let mut block_context = BlockContext::default();
block_context.starknet_os_config.gas_price = GasPrices::new(1, 0);
block_context.block_info.gas_price = GasPrices::new(1, 0);
let resources = HashMap::from([
("l1_gas_usage".to_string(), 200_usize),
("pedersen_builtin".to_string(), 10000_usize),
Expand Down Expand Up @@ -420,7 +420,7 @@ mod tests {
..Default::default()
};
let mut block_context = BlockContext::default();
block_context.starknet_os_config.gas_price = GasPrices::new(1, 0);
block_context.block_info.gas_price = GasPrices::new(1, 0);
let resources = HashMap::from([
("l1_gas_usage".to_string(), 200_usize),
("pedersen_builtin".to_string(), 10000_usize),
Expand Down
2 changes: 1 addition & 1 deletion src/transaction/invoke_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1219,7 +1219,7 @@ mod tests {
.unwrap();

let mut block_context = BlockContext::default();
block_context.starknet_os_config.gas_price = GasPrices::new(1, 0);
block_context.block_info.gas_price = GasPrices::new(1, 0);

let tx_info = internal_invoke_function
.execute(
Expand Down
2 changes: 1 addition & 1 deletion src/transaction/l1_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ mod test {
.unwrap();

let mut block_context = BlockContext::default();
block_context.starknet_os_config.gas_price = GasPrices::new(1, 0);
block_context.block_info.gas_price = GasPrices::new(1, 0);

let tx_exec = l1_handler
.execute(
Expand Down
7 changes: 5 additions & 2 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -681,14 +681,17 @@ pub mod test_utils {
StarknetOsConfig::new(
StarknetChainId::TestNet.to_felt(),
TEST_FEE_TOKEN_ADDRESSES.clone(),
GasPrices::new(1, 1),
),
0,
0,
DEFAULT_CAIRO_RESOURCE_FEE_WEIGHTS.clone(),
1_000_000,
0,
BlockInfo::empty(TEST_SEQUENCER_ADDRESS.clone()),
BlockInfo {
gas_price: GasPrices::new(1, 1),
sequencer_address: TEST_SEQUENCER_ADDRESS.clone(),
..Default::default()
},
HashMap::default(),
true,
)
Expand Down
1 change: 0 additions & 1 deletion tests/integration_tests/internals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ pub fn new_starknet_block_context_for_testing() -> BlockContext {
StarknetOsConfig::new(
StarknetChainId::TestNet.to_felt(),
TEST_FEE_TOKEN_ADDRESSES.clone(),
GAS_PRICES.clone(),
),
0,
0,
Expand Down
Loading