diff --git a/crates/starknet-devnet-core/src/blocks/mod.rs b/crates/starknet-devnet-core/src/blocks/mod.rs index b646d386e..e874feb5e 100644 --- a/crates/starknet-devnet-core/src/blocks/mod.rs +++ b/crates/starknet-devnet-core/src/blocks/mod.rs @@ -2,7 +2,7 @@ use std::collections::HashMap; use indexmap::IndexMap; use starknet_api::block::{ - BlockHeader, BlockHeaderWithoutHash, BlockNumber, BlockStatus, BlockTimestamp, + BlockHeader, BlockHeaderWithoutHash, BlockNumber, BlockStatus, BlockTimestamp, GasPrice, }; use starknet_api::data_availability::L1DataAvailabilityMode; use starknet_api::felt; @@ -12,6 +12,7 @@ use starknet_types::felt::{BlockHash, TransactionHash}; use starknet_types::rpc::block::{ BlockHeader as TypesBlockHeader, PendingBlockHeader as TypesPendingBlockHeader, ResourcePrice, }; +use starknet_types::rpc::gas_modification::GasModification; use starknet_types::traits::HashProducer; use starknet_types_core::hash::{Pedersen, StarkHash}; @@ -393,6 +394,15 @@ impl StarknetBlock { pub(crate) fn set_timestamp(&mut self, timestamp: BlockTimestamp) { self.header.block_header_without_hash.timestamp = timestamp; } + + pub(crate) fn apply_gas_modification(&mut self, gas_modification: &GasModification) { + self.header.block_header_without_hash.l1_gas_price.price_in_fri = + GasPrice(gas_modification.l1_gas_price.get()); + self.header.block_header_without_hash.l1_data_gas_price.price_in_fri = + GasPrice(gas_modification.l1_data_gas_price.get()); + self.header.block_header_without_hash.l2_gas_price.price_in_fri = + GasPrice(gas_modification.l2_gas_price.get()); + } } impl HashProducer for StarknetBlock { diff --git a/crates/starknet-devnet-core/src/starknet/add_deploy_account_transaction.rs b/crates/starknet-devnet-core/src/starknet/add_deploy_account_transaction.rs index 39d27d646..58d751187 100644 --- a/crates/starknet-devnet-core/src/starknet/add_deploy_account_transaction.rs +++ b/crates/starknet-devnet-core/src/starknet/add_deploy_account_transaction.rs @@ -288,9 +288,6 @@ mod tests { .declare_contract_class(class_hash, None, contract_class.into()) .unwrap(); starknet.block_context = Starknet::init_block_context( - nonzero!(GAS_PRICE), - nonzero!(GAS_PRICE), - nonzero!(GAS_PRICE), nonzero!(GAS_PRICE), nonzero!(GAS_PRICE), nonzero!(GAS_PRICE), diff --git a/crates/starknet-devnet-core/src/starknet/add_invoke_transaction.rs b/crates/starknet-devnet-core/src/starknet/add_invoke_transaction.rs index 3c66a907f..f447da5bd 100644 --- a/crates/starknet-devnet-core/src/starknet/add_invoke_transaction.rs +++ b/crates/starknet-devnet-core/src/starknet/add_invoke_transaction.rs @@ -418,9 +418,6 @@ mod tests { // change storage of dummy contract starknet.block_context = Starknet::init_block_context( - nonzero!(1u128), - nonzero!(1u128), - nonzero!(1u128), nonzero!(1u128), nonzero!(1u128), nonzero!(1u128), @@ -430,12 +427,9 @@ mod tests { DEVNET_DEFAULT_STARTING_BLOCK_NUMBER, ); starknet.next_block_gas = GasModification { - gas_price_wei: nonzero!(1u128), - data_gas_price_wei: nonzero!(1u128), - l2_gas_price_wei: nonzero!(1u128), - gas_price_fri: nonzero!(1u128), - data_gas_price_fri: nonzero!(1u128), - l2_gas_price_fri: nonzero!(1u128), + l1_gas_price: nonzero!(1u128), + l1_data_gas_price: nonzero!(1u128), + l2_gas_price: nonzero!(1u128), }; starknet.restart_pending_block().unwrap(); diff --git a/crates/starknet-devnet-core/src/starknet/add_l1_handler_transaction.rs b/crates/starknet-devnet-core/src/starknet/add_l1_handler_transaction.rs index 28510284c..0532bf21e 100644 --- a/crates/starknet-devnet-core/src/starknet/add_l1_handler_transaction.rs +++ b/crates/starknet-devnet-core/src/starknet/add_l1_handler_transaction.rs @@ -262,9 +262,6 @@ mod tests { .predeploy_contract(dummy_contract_address, dummy_contract_class_hash) .unwrap(); starknet.block_context = Starknet::init_block_context( - nonzero!(1u128), - nonzero!(1u128), - nonzero!(1u128), nonzero!(1u128), nonzero!(1u128), nonzero!(1u128), diff --git a/crates/starknet-devnet-core/src/starknet/estimations.rs b/crates/starknet-devnet-core/src/starknet/estimations.rs index c60b98be2..f1fc9afdb 100644 --- a/crates/starknet-devnet-core/src/starknet/estimations.rs +++ b/crates/starknet-devnet-core/src/starknet/estimations.rs @@ -109,12 +109,12 @@ pub fn estimate_message_fee( let mut transactional_state = CachedState::create_transactional(&mut state.state); - let l1_transaction = estimate_message_fee.create_blockifier_l1_transaction()?; + let executable_tx = estimate_message_fee.create_blockifier_l1_handler_tx()?; estimate_transaction_fee( &mut transactional_state, &block_context, - Transaction::L1Handler(l1_transaction), + Transaction::L1Handler(executable_tx), true, // Using only L1 gas, because msgs coming from L1 are L1 txs, with their own gas cost GasVectorComputationMode::NoL2Gas, diff --git a/crates/starknet-devnet-core/src/starknet/mod.rs b/crates/starknet-devnet-core/src/starknet/mod.rs index 64bc0f042..eacff4db0 100644 --- a/crates/starknet-devnet-core/src/starknet/mod.rs +++ b/crates/starknet-devnet-core/src/starknet/mod.rs @@ -13,8 +13,8 @@ use cairo_lang_starknet_classes::casm_contract_class::CasmContractClass; use ethers::types::H256; use parking_lot::RwLock; use starknet_api::block::{ - BlockInfo, BlockNumber, BlockStatus, BlockTimestamp, FeeType, GasPrice, GasPricePerToken, - GasPriceVector, GasPrices, + BlockInfo, BlockNumber, BlockStatus, BlockTimestamp, FeeType, GasPricePerToken, GasPriceVector, + GasPrices, }; use starknet_api::core::SequencerContractAddress; use starknet_api::data_availability::DataAvailabilityMode; @@ -97,6 +97,15 @@ pub mod starknet_config; mod state_update; pub(crate) mod transaction_trace; +/// Used when the actual prices are no longer important. ETH transactions are no longer supported. +fn eth_gas_price_vector() -> GasPriceVector { + GasPriceVector { + l1_gas_price: nonzero_gas_price!(DEVNET_DEFAULT_L1_GAS_PRICE), + l1_data_gas_price: nonzero_gas_price!(DEVNET_DEFAULT_L1_DATA_GAS_PRICE), + l2_gas_price: nonzero_gas_price!(DEVNET_DEFAULT_L2_GAS_PRICE), + } +} + pub struct Starknet { pub latest_state: StarknetState, pub pending_state: StarknetState, @@ -121,11 +130,8 @@ impl Default for Starknet { fn default() -> Self { Self { block_context: Self::init_block_context( - DEVNET_DEFAULT_L1_GAS_PRICE, DEVNET_DEFAULT_L1_GAS_PRICE, DEVNET_DEFAULT_L1_DATA_GAS_PRICE, - DEVNET_DEFAULT_L1_DATA_GAS_PRICE, - DEVNET_DEFAULT_L2_GAS_PRICE, DEVNET_DEFAULT_L2_GAS_PRICE, ETH_ERC20_CONTRACT_ADDRESS, STRK_ERC20_CONTRACT_ADDRESS, @@ -142,12 +148,9 @@ impl Default for Starknet { pending_block_timestamp_shift: 0, next_block_timestamp: None, next_block_gas: GasModification { - gas_price_wei: DEVNET_DEFAULT_L1_GAS_PRICE, - data_gas_price_wei: DEVNET_DEFAULT_L1_DATA_GAS_PRICE, - gas_price_fri: DEVNET_DEFAULT_L1_GAS_PRICE, - data_gas_price_fri: DEVNET_DEFAULT_L1_DATA_GAS_PRICE, - l2_gas_price_fri: DEVNET_DEFAULT_L2_GAS_PRICE, - l2_gas_price_wei: DEVNET_DEFAULT_L2_GAS_PRICE, + l1_gas_price: DEVNET_DEFAULT_L1_GAS_PRICE, + l1_data_gas_price: DEVNET_DEFAULT_L1_DATA_GAS_PRICE, + l2_gas_price: DEVNET_DEFAULT_L2_GAS_PRICE, }, messaging: Default::default(), rpc_contract_classes: Default::default(), @@ -253,12 +256,9 @@ impl Starknet { pending_state_diff, predeployed_accounts, block_context: Self::init_block_context( - config.gas_price_wei, - config.gas_price_fri, - config.data_gas_price_wei, - config.data_gas_price_fri, - config.l2_gas_price_wei, - config.l2_gas_price_fri, + config.l1_gas_price, + config.l1_data_gas_price, + config.l2_gas_price, ETH_ERC20_CONTRACT_ADDRESS, STRK_ERC20_CONTRACT_ADDRESS, config.chain_id, @@ -270,12 +270,9 @@ impl Starknet { pending_block_timestamp_shift: 0, next_block_timestamp: None, next_block_gas: GasModification { - gas_price_wei: config.gas_price_wei, - data_gas_price_wei: config.data_gas_price_wei, - gas_price_fri: config.gas_price_fri, - data_gas_price_fri: config.data_gas_price_fri, - l2_gas_price_wei: config.l2_gas_price_wei, - l2_gas_price_fri: config.l2_gas_price_fri, + l1_gas_price: config.l1_gas_price, + l1_data_gas_price: config.l1_data_gas_price, + l2_gas_price: config.l2_gas_price, }, messaging: Default::default(), rpc_contract_classes, @@ -318,20 +315,7 @@ impl Starknet { Self::advance_block_context_block_number(&mut self.block_context); Self::set_block_context_gas(&mut self.block_context, &self.next_block_gas); - - // Pending block header gas data needs to be set - self.blocks.pending_block.header.block_header_without_hash.l1_gas_price.price_in_wei = - GasPrice(self.next_block_gas.gas_price_wei.get()); - self.blocks.pending_block.header.block_header_without_hash.l1_data_gas_price.price_in_wei = - GasPrice(self.next_block_gas.data_gas_price_wei.get()); - self.blocks.pending_block.header.block_header_without_hash.l2_gas_price.price_in_wei = - GasPrice(self.next_block_gas.l2_gas_price_wei.get()); - self.blocks.pending_block.header.block_header_without_hash.l1_gas_price.price_in_fri = - GasPrice(self.next_block_gas.gas_price_fri.get()); - self.blocks.pending_block.header.block_header_without_hash.l1_data_gas_price.price_in_fri = - GasPrice(self.next_block_gas.data_gas_price_fri.get()); - self.blocks.pending_block.header.block_header_without_hash.l2_gas_price.price_in_fri = - GasPrice(self.next_block_gas.l2_gas_price_fri.get()); + self.blocks.pending_block.apply_gas_modification(&self.next_block_gas); self.restart_pending_block()?; @@ -356,20 +340,7 @@ impl Starknet { pub(crate) fn generate_new_block_and_state(&mut self) -> DevnetResult { let mut new_block = self.pending_block().clone(); - // Set new block header - // TODO why not store the whole next block header instead of storing separate properties? - new_block.header.block_header_without_hash.l1_gas_price.price_in_fri = - GasPrice(self.next_block_gas.gas_price_fri.get()); - new_block.header.block_header_without_hash.l1_gas_price.price_in_wei = - GasPrice(self.next_block_gas.gas_price_wei.get()); - new_block.header.block_header_without_hash.l1_data_gas_price.price_in_fri = - GasPrice(self.next_block_gas.data_gas_price_fri.get()); - new_block.header.block_header_without_hash.l1_data_gas_price.price_in_wei = - GasPrice(self.next_block_gas.data_gas_price_wei.get()); - new_block.header.block_header_without_hash.l2_gas_price.price_in_fri = - GasPrice(self.next_block_gas.l2_gas_price_fri.get()); - new_block.header.block_header_without_hash.l2_gas_price.price_in_wei = - GasPrice(self.next_block_gas.l2_gas_price_wei.get()); + new_block.apply_gas_modification(&self.next_block_gas); let new_block_number = self.blocks.next_block_number(); new_block.set_block_hash(if self.config.lite_mode { @@ -464,12 +435,9 @@ impl Starknet { #[allow(clippy::too_many_arguments)] /// Create a BlockContext based on BlockContext::create_for_testing() fn init_block_context( - gas_price_wei: NonZeroU128, - gas_price_fri: NonZeroU128, - data_gas_price_wei: NonZeroU128, - data_gas_price_fri: NonZeroU128, - l2_gas_price_wei: NonZeroU128, - l2_gas_price_fri: NonZeroU128, + l1_gas_price: NonZeroU128, + l1_data_gas_price: NonZeroU128, + l2_gas_price: NonZeroU128, eth_fee_token_address: Felt, strk_fee_token_address: Felt, chain_id: ChainId, @@ -480,15 +448,11 @@ impl Starknet { block_timestamp: BlockTimestamp(0), sequencer_address: starknet_api::contract_address!("0x1000"), gas_prices: GasPrices { - eth_gas_prices: GasPriceVector { - l1_gas_price: nonzero_gas_price!(gas_price_wei), - l1_data_gas_price: nonzero_gas_price!(data_gas_price_wei), - l2_gas_price: nonzero_gas_price!(l2_gas_price_wei), - }, + eth_gas_prices: eth_gas_price_vector(), strk_gas_prices: GasPriceVector { - l1_gas_price: nonzero_gas_price!(gas_price_fri), - l1_data_gas_price: nonzero_gas_price!(data_gas_price_fri), - l2_gas_price: nonzero_gas_price!(l2_gas_price_fri), + l1_gas_price: nonzero_gas_price!(l1_gas_price), + l1_data_gas_price: nonzero_gas_price!(l1_data_gas_price), + l2_gas_price: nonzero_gas_price!(l2_gas_price), }, }, use_kzg_da: USE_KZG_DA, @@ -534,15 +498,11 @@ impl Starknet { // Block info gas needs to be set here block_info.gas_prices = GasPrices { - eth_gas_prices: GasPriceVector { - l1_gas_price: nonzero_gas_price!(gas_modification.gas_price_wei), - l1_data_gas_price: nonzero_gas_price!(gas_modification.data_gas_price_wei), - l2_gas_price: nonzero_gas_price!(gas_modification.l2_gas_price_wei), - }, + eth_gas_prices: eth_gas_price_vector(), strk_gas_prices: GasPriceVector { - l1_gas_price: nonzero_gas_price!(gas_modification.gas_price_fri), - l1_data_gas_price: nonzero_gas_price!(gas_modification.data_gas_price_fri), - l2_gas_price: nonzero_gas_price!(gas_modification.l2_gas_price_fri), + l1_gas_price: nonzero_gas_price!(gas_modification.l1_gas_price), + l1_data_gas_price: nonzero_gas_price!(gas_modification.l1_data_gas_price), + l2_gas_price: nonzero_gas_price!(gas_modification.l2_gas_price), }, }; @@ -860,11 +820,11 @@ impl Starknet { nonce: nonce.0, resource_bounds: ResourceBoundsWrapper::new( 1_000_000, - self.config.gas_price_fri.get(), + self.config.l1_gas_price.get(), 1_000_000, - self.config.data_gas_price_fri.get(), + self.config.l1_data_gas_price.get(), 1_000_000_000, - self.config.l2_gas_price_fri.get(), + self.config.l2_gas_price.get(), ), tip: Tip(0), paymaster_data: vec![], @@ -1547,12 +1507,9 @@ mod tests { state_archive: StateArchiveCapacity, ) -> (Starknet, Account) { let mut starknet = Starknet::new(&StarknetConfig { - gas_price_wei: nonzero!(1u128), - gas_price_fri: nonzero!(1u128), - data_gas_price_wei: nonzero!(1u128), - data_gas_price_fri: nonzero!(1u128), - l2_gas_price_wei: nonzero!(1u128), - l2_gas_price_fri: nonzero!(1u128), + l1_gas_price: nonzero!(1u128), + l1_data_gas_price: nonzero!(1u128), + l2_gas_price: nonzero!(1u128), state_archive, ..Default::default() }) @@ -1612,11 +1569,8 @@ mod tests { ContractAddress::new(felt_from_prefixed_hex("0xAA").unwrap()).unwrap(); let block_ctx = Starknet::init_block_context( nonzero!(10u128), - nonzero!(10u128), - nonzero!(10u128), - nonzero!(10u128), - nonzero!(10u128), - nonzero!(10u128), + nonzero!(11u128), + nonzero!(12u128), felt_from_prefixed_hex("0xAA").unwrap(), STRK_ERC20_CONTRACT_ADDRESS, DEVNET_DEFAULT_CHAIN_ID, @@ -1624,7 +1578,9 @@ mod tests { ); assert_eq!(block_ctx.block_info().block_number, BlockNumber(0)); assert_eq!(block_ctx.block_info().block_timestamp, BlockTimestamp(0)); - assert_eq!(block_ctx.block_info().gas_prices.l1_gas_price(&FeeType::Eth).get().0, 10); + assert_eq!(block_ctx.block_info().gas_prices.l1_gas_price(&FeeType::Strk).get().0, 10); + assert_eq!(block_ctx.block_info().gas_prices.l1_data_gas_price(&FeeType::Strk).get().0, 11); + assert_eq!(block_ctx.block_info().gas_prices.l2_gas_price(&FeeType::Strk).get().0, 12); assert_eq!( ContractAddress::from(block_ctx.chain_info().fee_token_addresses.eth_fee_token_address), fee_token_address @@ -1677,14 +1633,13 @@ mod tests { let mut starknet = Starknet::new(&config).unwrap(); let initial_block_number = starknet.block_context.block_info().block_number; - let initial_gas_price_wei = - starknet.block_context.block_info().gas_prices.l1_gas_price(&FeeType::Eth); - let initial_gas_price_fri = + let initial_l1_gas_price = starknet.block_context.block_info().gas_prices.l1_gas_price(&FeeType::Strk); - let initial_data_gas_price_wei = - starknet.block_context.block_info().gas_prices.l1_gas_price(&FeeType::Eth); - let initial_data_gas_price_fri = + let initial_l1_data_gas_price = starknet.block_context.block_info().gas_prices.l1_data_gas_price(&FeeType::Strk); + let initial_l2_gas_price = + starknet.block_context.block_info().gas_prices.l2_gas_price(&FeeType::Strk); + let initial_block_timestamp = starknet.block_context.block_info().block_timestamp; let initial_sequencer = starknet.block_context.block_info().sequencer_address; @@ -1715,22 +1670,9 @@ mod tests { starknet.pending_block().header.block_header_without_hash.parent_hash, BlockHash::default() ); - assert_eq!( - starknet.pending_block().header.block_header_without_hash.l1_gas_price.price_in_wei, - initial_gas_price_wei.get() - ); assert_eq!( starknet.pending_block().header.block_header_without_hash.l1_gas_price.price_in_fri, - initial_gas_price_fri.get() - ); - assert_eq!( - starknet - .pending_block() - .header - .block_header_without_hash - .l1_data_gas_price - .price_in_wei, - initial_data_gas_price_wei.get() + initial_l1_gas_price.get() ); assert_eq!( starknet @@ -1739,11 +1681,11 @@ mod tests { .block_header_without_hash .l1_data_gas_price .price_in_fri, - initial_data_gas_price_fri.get() + initial_l1_data_gas_price.get() ); assert_eq!( starknet.pending_block().header.block_header_without_hash.l2_gas_price.price_in_fri, - initial_data_gas_price_fri.get() + initial_l2_gas_price.get() ); assert_eq!( starknet.pending_block().header.block_header_without_hash.sequencer.0, @@ -1754,9 +1696,6 @@ mod tests { #[test] fn correct_block_context_update() { let mut block_ctx = Starknet::init_block_context( - nonzero!(1u128), - nonzero!(1u128), - nonzero!(1u128), nonzero!(1u128), nonzero!(1u128), nonzero!(1u128), diff --git a/crates/starknet-devnet-core/src/starknet/starknet_config.rs b/crates/starknet-devnet-core/src/starknet/starknet_config.rs index f67c6f244..ffc942ba4 100644 --- a/crates/starknet-devnet-core/src/starknet/starknet_config.rs +++ b/crates/starknet-devnet-core/src/starknet/starknet_config.rs @@ -106,12 +106,9 @@ pub struct StarknetConfig { #[serde(serialize_with = "serialize_initial_balance")] pub predeployed_accounts_initial_balance: Balance, pub start_time: Option, - pub gas_price_wei: NonZeroU128, - pub gas_price_fri: NonZeroU128, - pub data_gas_price_wei: NonZeroU128, - pub data_gas_price_fri: NonZeroU128, - pub l2_gas_price_wei: NonZeroU128, - pub l2_gas_price_fri: NonZeroU128, + pub l1_gas_price: NonZeroU128, + pub l1_data_gas_price: NonZeroU128, + pub l2_gas_price: NonZeroU128, #[serde(serialize_with = "serialize_chain_id")] pub chain_id: ChainId, pub dump_on: Option, @@ -155,12 +152,9 @@ impl Default for StarknetConfig { account_contract_class, predeployed_accounts_initial_balance: DEVNET_DEFAULT_INITIAL_BALANCE.into(), start_time: None, - gas_price_wei: DEVNET_DEFAULT_L1_GAS_PRICE.get().try_into().unwrap(), - gas_price_fri: DEVNET_DEFAULT_L1_GAS_PRICE.get().try_into().unwrap(), - data_gas_price_wei: DEVNET_DEFAULT_L1_DATA_GAS_PRICE.get().try_into().unwrap(), - data_gas_price_fri: DEVNET_DEFAULT_L1_DATA_GAS_PRICE.get().try_into().unwrap(), - l2_gas_price_wei: DEVNET_DEFAULT_L2_GAS_PRICE.get().try_into().unwrap(), - l2_gas_price_fri: DEVNET_DEFAULT_L2_GAS_PRICE.get().try_into().unwrap(), + l1_gas_price: DEVNET_DEFAULT_L1_GAS_PRICE.get().try_into().unwrap(), + l1_data_gas_price: DEVNET_DEFAULT_L1_DATA_GAS_PRICE.get().try_into().unwrap(), + l2_gas_price: DEVNET_DEFAULT_L2_GAS_PRICE.get().try_into().unwrap(), chain_id: DEVNET_DEFAULT_CHAIN_ID, dump_on: None, dump_path: None, diff --git a/crates/starknet-devnet-core/src/state/state_diff.rs b/crates/starknet-devnet-core/src/state/state_diff.rs index 40d08ea5f..9833350d4 100644 --- a/crates/starknet-devnet-core/src/state/state_diff.rs +++ b/crates/starknet-devnet-core/src/state/state_diff.rs @@ -267,12 +267,9 @@ mod tests { #[test] fn test_class_replacement_produces_correct_state_diff() { let mut starknet = Starknet::new(&StarknetConfig { - gas_price_wei: nonzero!(1u128), - gas_price_fri: nonzero!(1u128), - data_gas_price_wei: nonzero!(1u128), - data_gas_price_fri: nonzero!(1u128), - l2_gas_price_wei: nonzero!(1u128), - l2_gas_price_fri: nonzero!(1u128), + l1_gas_price: nonzero!(1u128), + l1_data_gas_price: nonzero!(1u128), + l2_gas_price: nonzero!(1u128), ..Default::default() }) .unwrap(); diff --git a/crates/starknet-devnet-types/src/rpc/block.rs b/crates/starknet-devnet-types/src/rpc/block.rs index fcad382bd..31b0aa9bc 100644 --- a/crates/starknet-devnet-types/src/rpc/block.rs +++ b/crates/starknet-devnet-types/src/rpc/block.rs @@ -115,8 +115,6 @@ pub struct PendingBlockHeader { #[derive(Debug, Clone, Serialize)] #[cfg_attr(feature = "testing", derive(Deserialize), serde(deny_unknown_fields))] pub struct ResourcePrice { - // for now this will be always 0, this field is introduced in 0.5.0 - // but current version of blockifier/starknet_api doesn't return this value pub price_in_fri: Felt, pub price_in_wei: Felt, } diff --git a/crates/starknet-devnet-types/src/rpc/estimate_message_fee.rs b/crates/starknet-devnet-types/src/rpc/estimate_message_fee.rs index 7bf040dac..92127b259 100644 --- a/crates/starknet-devnet-types/src/rpc/estimate_message_fee.rs +++ b/crates/starknet-devnet-types/src/rpc/estimate_message_fee.rs @@ -61,7 +61,7 @@ impl EstimateMessageFeeRequestWrapper { &self.inner.message } - pub fn create_blockifier_l1_transaction(&self) -> DevnetResult { + pub fn create_blockifier_l1_handler_tx(&self) -> DevnetResult { let calldata = [&[self.get_from_address().into()], self.get_payload()].concat(); let l1_transaction = L1HandlerTransaction { @@ -71,7 +71,8 @@ impl EstimateMessageFeeRequestWrapper { )?, entry_point_selector: EntryPointSelector(self.get_entry_point_selector()), calldata: Calldata(Arc::new(calldata)), - ..Default::default() + nonce: Default::default(), + version: starknet_api::transaction::L1HandlerTransaction::VERSION, }, paid_fee_on_l1: starknet_api::transaction::fields::Fee(1), tx_hash: Default::default(), diff --git a/crates/starknet-devnet-types/src/rpc/gas_modification.rs b/crates/starknet-devnet-types/src/rpc/gas_modification.rs index e7e39e7eb..96690e575 100644 --- a/crates/starknet-devnet-types/src/rpc/gas_modification.rs +++ b/crates/starknet-devnet-types/src/rpc/gas_modification.rs @@ -5,45 +5,30 @@ use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, Serialize, Deserialize)] #[serde(deny_unknown_fields)] pub struct GasModificationRequest { - pub gas_price_wei: Option, - pub data_gas_price_wei: Option, - pub gas_price_fri: Option, - pub data_gas_price_fri: Option, - pub l2_gas_price_wei: Option, - pub l2_gas_price_fri: Option, + pub l1_gas_price: Option, + pub l1_data_gas_price: Option, + pub l2_gas_price: Option, pub generate_block: Option, } #[derive(Clone, Debug, Serialize)] #[cfg_attr(feature = "testing", derive(serde::Deserialize), serde(deny_unknown_fields))] pub struct GasModification { - pub gas_price_wei: NonZeroU128, - pub data_gas_price_wei: NonZeroU128, - pub gas_price_fri: NonZeroU128, - pub data_gas_price_fri: NonZeroU128, - pub l2_gas_price_wei: NonZeroU128, - pub l2_gas_price_fri: NonZeroU128, + pub l1_gas_price: NonZeroU128, + pub l1_data_gas_price: NonZeroU128, + pub l2_gas_price: NonZeroU128, } impl GasModification { pub fn update(&mut self, request: GasModificationRequest) { - if let Some(gas_price_wei) = request.gas_price_wei { - self.gas_price_wei = gas_price_wei; + if let Some(l1_gas_price) = request.l1_gas_price { + self.l1_gas_price = l1_gas_price; } - if let Some(data_gas_price_wei) = request.data_gas_price_wei { - self.data_gas_price_wei = data_gas_price_wei; + if let Some(l1_data_gas_price) = request.l1_data_gas_price { + self.l1_data_gas_price = l1_data_gas_price; } - if let Some(gas_price_fri) = request.gas_price_fri { - self.gas_price_fri = gas_price_fri; - } - if let Some(data_gas_price_fri) = request.data_gas_price_fri { - self.data_gas_price_fri = data_gas_price_fri; - } - if let Some(l2_gas_price_wei) = request.l2_gas_price_wei { - self.l2_gas_price_wei = l2_gas_price_wei; - } - if let Some(l2_gas_price_fri) = request.l2_gas_price_fri { - self.l2_gas_price_fri = l2_gas_price_fri; + if let Some(l2_gas_price) = request.l2_gas_price { + self.l2_gas_price = l2_gas_price; } } } diff --git a/crates/starknet-devnet/src/cli.rs b/crates/starknet-devnet/src/cli.rs index 9c8051fae..a4374a276 100644 --- a/crates/starknet-devnet/src/cli.rs +++ b/crates/starknet-devnet/src/cli.rs @@ -113,54 +113,26 @@ pub(crate) struct Args { #[arg(help = "Specify the server timeout in seconds;")] timeout: u16, - // Gas price in wei - #[arg(long = "gas-price")] - #[arg(env = "GAS_PRICE")] - #[arg(value_name = "WEI_PER_GAS_UNIT")] - #[arg(default_value_t = DEVNET_DEFAULT_L1_GAS_PRICE)] - #[arg(help = "Specify the gas price in wei per L1 gas unit;")] - gas_price_wei: NonZeroU128, - - // Gas price in fri - #[arg(long = "gas-price-fri")] - #[arg(env = "GAS_PRICE_FRI")] + #[arg(long = "l1-gas-price")] + #[arg(env = "L1_GAS_PRICE")] #[arg(value_name = "FRI_PER_GAS_UNIT")] #[arg(default_value_t = DEVNET_DEFAULT_L1_GAS_PRICE)] #[arg(help = "Specify the gas price in fri per L1 gas unit;")] - gas_price_fri: NonZeroU128, - - // TODO perhaps make this affect only fri and remove -fri flags - // Gas price in wei - #[arg(long = "data-gas-price")] - #[arg(env = "DATA_GAS_PRICE")] - #[arg(value_name = "WEI_PER_GAS_UNIT")] - #[arg(default_value_t = DEVNET_DEFAULT_L1_DATA_GAS_PRICE)] - #[arg(help = "Specify the gas price in wei per L1 data gas unit;")] - data_gas_price_wei: NonZeroU128, + l1_gas_price: NonZeroU128, - // Gas price in fri - #[arg(long = "data-gas-price-fri")] - #[arg(env = "DATA_GAS_PRICE_FRI")] + #[arg(long = "l1-data-gas-price")] + #[arg(env = "L1_DATA_GAS_PRICE")] #[arg(value_name = "FRI_PER_GAS_UNIT")] #[arg(default_value_t = DEVNET_DEFAULT_L1_DATA_GAS_PRICE)] #[arg(help = "Specify the gas price in fri per L1 data gas unit;")] - data_gas_price_fri: NonZeroU128, + l1_data_gas_price: NonZeroU128, - // L2 Gas price in wei #[arg(long = "l2-gas-price")] #[arg(env = "L2_GAS_PRICE")] - #[arg(value_name = "WEI_PER_GAS_UNIT")] - #[arg(default_value_t = DEVNET_DEFAULT_L2_GAS_PRICE)] - #[arg(help = "Specify the gas price in wei per L2 gas unit;")] - l2_gas_price_wei: NonZeroU128, - - // L2 Gas price in fri - #[arg(long = "l2-gas-price-fri")] - #[arg(env = "L2_GAS_PRICE_FRI")] #[arg(value_name = "FRI_PER_GAS_UNIT")] #[arg(default_value_t = DEVNET_DEFAULT_L2_GAS_PRICE)] #[arg(help = "Specify the gas price in fri per L2 gas unit;")] - l2_gas_price_fri: NonZeroU128, + l2_gas_price: NonZeroU128, #[arg(long = "chain-id")] #[arg(env = "CHAIN_ID")] @@ -249,12 +221,9 @@ impl Args { account_contract_class_hash: account_class_wrapper.class_hash, predeployed_accounts_initial_balance: self.initial_balance.0.clone(), start_time: self.start_time, - gas_price_wei: self.gas_price_wei, - gas_price_fri: self.gas_price_fri, - data_gas_price_wei: self.data_gas_price_wei, - data_gas_price_fri: self.data_gas_price_fri, - l2_gas_price_wei: self.l2_gas_price_wei, - l2_gas_price_fri: self.l2_gas_price_fri, + l1_gas_price: self.l1_gas_price, + l1_data_gas_price: self.l1_data_gas_price, + l2_gas_price: self.l2_gas_price, chain_id: self.chain_id, dump_on: self.dump_on, dump_path: self.dump_path.clone(), @@ -578,10 +547,9 @@ mod tests { ("--port", "PORT", "1234"), ("--start-time", "START_TIME", "123"), ("--timeout", "TIMEOUT", "12"), - ("--gas-price", "GAS_PRICE", "1"), - ("--gas-price-fri", "GAS_PRICE_FRI", "2"), - ("--data-gas-price", "DATA_GAS_PRICE", "3"), - ("--data-gas-price-fri", "DATA_GAS_PRICE_FRI", "4"), + ("--l1-gas-price", "L1_GAS_PRICE", "1"), + ("--l1-data-gas-price", "L1_DATA_GAS_PRICE", "2"), + ("--l2-gas-price", "L2_GAS_PRICE", "3"), ("--dump-on", "DUMP_ON", "exit"), ("--dump-path", "DUMP_PATH", "dummy-path"), ("--state-archive-capacity", "STATE_ARCHIVE_CAPACITY", "full"), diff --git a/tests/integration/common/utils.rs b/tests/integration/common/utils.rs index f0c557e8f..81dfa1b55 100644 --- a/tests/integration/common/utils.rs +++ b/tests/integration/common/utils.rs @@ -442,6 +442,11 @@ pub fn felt_to_u128(f: Felt) -> u128 { bigint.try_into().unwrap() } +/// Unchecked conversion +fn felt_to_u64(f: Felt) -> u64 { + u64::from_le_bytes(f.to_bytes_le()[..8].try_into().unwrap()) +} + /// Helper for extracting JSON RPC error from the provider instance of `ProviderError`. /// To be used when there are discrepancies between starknet-rs and the target RPC spec. pub fn extract_json_rpc_error(error: ProviderError) -> Result { @@ -628,28 +633,13 @@ impl From for ResourceBoundsMapping { impl From for LocalFee { fn from(fee: FeeEstimate) -> Self { - let l1_gas_consumed = - u64::from_le_bytes(fee.l1_gas_consumed.to_bytes_le()[..8].try_into().unwrap()); - let l1_gas_price = - u128::from_le_bytes(fee.l1_gas_price.to_bytes_le()[..16].try_into().unwrap()); - - let l2_gas_consumed = - u64::from_le_bytes(fee.l2_gas_consumed.to_bytes_le()[..8].try_into().unwrap()); - let l2_gas_price = - u128::from_le_bytes(fee.l2_gas_price.to_bytes_le()[..16].try_into().unwrap()); - - let l1_data_gas_consumed = - u64::from_le_bytes(fee.l1_data_gas_consumed.to_bytes_le()[..8].try_into().unwrap()); - let l1_data_gas_price = - u128::from_le_bytes(fee.l1_data_gas_price.to_bytes_le()[..16].try_into().unwrap()); - LocalFee { - l1_gas: l1_gas_consumed, - l1_gas_price, - l1_data_gas: l1_data_gas_consumed, - l1_data_gas_price, - l2_gas: l2_gas_consumed, - l2_gas_price, + l1_gas: felt_to_u64(fee.l1_gas_consumed), + l1_gas_price: felt_to_u128(fee.l1_gas_price), + l1_data_gas: felt_to_u64(fee.l1_data_gas_consumed), + l1_data_gas_price: felt_to_u128(fee.l1_data_gas_price), + l2_gas: felt_to_u64(fee.l2_gas_consumed), + l2_gas_price: felt_to_u128(fee.l2_gas_price), } } } diff --git a/tests/integration/general_integration_tests.rs b/tests/integration/general_integration_tests.rs index e23f1c83f..5d969f63d 100644 --- a/tests/integration/general_integration_tests.rs +++ b/tests/integration/general_integration_tests.rs @@ -36,13 +36,10 @@ async fn test_config() { "total_accounts": 2, "account_contract_class_hash": Felt::from_hex_unchecked(CAIRO_1_ACCOUNT_CONTRACT_SIERRA_HASH), "predeployed_accounts_initial_balance": "3", - "start_time": 4, - "gas_price_wei": 5, - "gas_price_fri": 7, - "data_gas_price_wei": 6, - "data_gas_price_fri": 8, - "l2_gas_price_wei": 9, - "l2_gas_price_fri": 10, + "start_time": 3, + "l1_gas_price": 4, + "l1_data_gas_price": 5, + "l2_gas_price": 6, "chain_id": "SN_MAIN", "dump_on": "exit", "dump_path": dump_file.path, @@ -72,18 +69,12 @@ async fn test_config() { expected_config["predeployed_accounts_initial_balance"].as_str().unwrap(), "--start-time", &serde_json::to_string(&expected_config["start_time"]).unwrap(), - "--gas-price", - &serde_json::to_string(&expected_config["gas_price_wei"]).unwrap(), - "--gas-price-fri", - &serde_json::to_string(&expected_config["gas_price_fri"]).unwrap(), - "--data-gas-price", - &serde_json::to_string(&expected_config["data_gas_price_wei"]).unwrap(), - "--data-gas-price-fri", - &serde_json::to_string(&expected_config["data_gas_price_fri"]).unwrap(), + "--l1-gas-price", + &serde_json::to_string(&expected_config["l1_gas_price"]).unwrap(), + "--l1-data-gas-price", + &serde_json::to_string(&expected_config["l1_data_gas_price"]).unwrap(), "--l2-gas-price", - &serde_json::to_string(&expected_config["l2_gas_price_wei"]).unwrap(), - "--l2-gas-price-fri", - &serde_json::to_string(&expected_config["l2_gas_price_fri"]).unwrap(), + &serde_json::to_string(&expected_config["l2_gas_price"]).unwrap(), "--chain-id", "MAINNET", "--dump-on", diff --git a/tests/integration/test_estimate_message_fee.rs b/tests/integration/test_estimate_message_fee.rs index 3f1b51c92..8bc81a335 100644 --- a/tests/integration/test_estimate_message_fee.rs +++ b/tests/integration/test_estimate_message_fee.rs @@ -2,7 +2,9 @@ use std::sync::Arc; use starknet_rs_accounts::{Account, ExecutionEncoding, SingleOwnerAccount}; use starknet_rs_contract::ContractFactory; -use starknet_rs_core::types::{BlockId, BlockTag, EthAddress, Felt, MsgFromL1, StarknetError}; +use starknet_rs_core::types::{ + BlockId, BlockTag, EthAddress, FeeEstimate, Felt, MsgFromL1, StarknetError, +}; use starknet_rs_core::utils::{UdcUniqueness, get_udc_deployed_address}; use starknet_rs_providers::{Provider, ProviderError}; @@ -49,7 +51,7 @@ async fn estimate_message_fee() { .await .expect("Cannot deploy"); - let res = devnet + let estimate = devnet .json_rpc_client .estimate_message_fee( MsgFromL1 { @@ -63,8 +65,20 @@ async fn estimate_message_fee() { .await .unwrap(); - assert_eq!(res.l1_gas_consumed, Felt::from(16029)); - assert_eq!(res.l2_gas_consumed, Felt::ZERO); + let devnet_default_gas_price = Felt::from(1_000_000_000u128); + assert_eq!( + estimate, + FeeEstimate { + l1_gas_consumed: Felt::from(16029), + l1_gas_price: devnet_default_gas_price, + l2_gas_consumed: Felt::ZERO, + l2_gas_price: devnet_default_gas_price, + l1_data_gas_consumed: Felt::ZERO, + l1_data_gas_price: devnet_default_gas_price, + overall_fee: Felt::from(16029), + unit: starknet_rs_core::types::PriceUnit::Wei, + } + ); } #[tokio::test] diff --git a/tests/integration/test_gas_modification.rs b/tests/integration/test_gas_modification.rs index ab726635b..2b11554ad 100644 --- a/tests/integration/test_gas_modification.rs +++ b/tests/integration/test_gas_modification.rs @@ -6,7 +6,7 @@ use starknet_core::constants::{ }; use starknet_rs_accounts::{Account, AccountError, ExecutionEncoding, SingleOwnerAccount}; use starknet_rs_core::chain_id::SEPOLIA; -use starknet_rs_core::types::{Felt, ResourcePrice, StarknetError}; +use starknet_rs_core::types::{Felt, StarknetError}; use starknet_rs_core::utils::cairo_short_string_to_felt; use starknet_rs_providers::{Provider, ProviderError}; use starknet_rs_signers::Signer; @@ -18,7 +18,7 @@ use crate::common::constants::{ use crate::common::errors::RpcError; use crate::common::fees::assert_difference_if_validation; use crate::common::utils::{ - assert_tx_successful, felt_to_u128, get_flattened_sierra_contract_and_casm_hash, + assert_tx_successful, get_flattened_sierra_contract_and_casm_hash, get_simple_contract_artifacts, iter_to_hex_felt, to_hex_felt, to_num_as_hex, }; @@ -170,12 +170,9 @@ async fn set_gas_scenario(devnet: BackgroundDevnet, expected_chain_id: Felt) { let l1_data_fri_price = 7.5e18 as u128; let l2_fri_price = 6.5e18 as u128; let gas_request = json!({ - "gas_price_wei": 9e18 as u128, - "gas_price_fri": l1_fri_price, - "data_gas_price_wei": 8e18 as u128, - "data_gas_price_fri": l1_data_fri_price, - "l2_gas_price_wei": 7e18 as u128, - "l2_gas_price_fri": l2_fri_price, + "l1_gas_price": l1_fri_price, + "l1_data_gas_price": l1_data_fri_price, + "l2_gas_price": l2_fri_price, }); let gas_response = &devnet.set_gas_price(&gas_request, true).await.unwrap(); @@ -240,42 +237,24 @@ async fn set_gas_fork() { async fn set_gas_check_blocks() { let devnet = BackgroundDevnet::spawn().await.expect("Could not start Devnet"); - let default_gas_price = ResourcePrice { - price_in_wei: u128::from(DEVNET_DEFAULT_L1_GAS_PRICE).into(), - price_in_fri: u128::from(DEVNET_DEFAULT_L1_GAS_PRICE).into(), - }; - let default_data_gas_price = ResourcePrice { - price_in_wei: u128::from(DEVNET_DEFAULT_L1_DATA_GAS_PRICE).into(), - price_in_fri: u128::from(DEVNET_DEFAULT_L1_DATA_GAS_PRICE).into(), - }; - let default_l2_gas_price = ResourcePrice { - price_in_wei: u128::from(DEVNET_DEFAULT_L2_GAS_PRICE).into(), - price_in_fri: u128::from(DEVNET_DEFAULT_L2_GAS_PRICE).into(), - }; + let default_l1_gas_price = u128::from(DEVNET_DEFAULT_L1_GAS_PRICE); + let default_l1_data_gas_price = u128::from(DEVNET_DEFAULT_L1_DATA_GAS_PRICE); + let default_l2_gas_price = u128::from(DEVNET_DEFAULT_L2_GAS_PRICE); // First update - don't generate new block let latest_block = devnet.get_latest_block_with_txs().await.unwrap(); assert_eq!(latest_block.block_number, 0); - assert_eq!(latest_block.l1_gas_price, default_gas_price); - assert_eq!(latest_block.l1_data_gas_price, default_data_gas_price); - assert_eq!(latest_block.l2_gas_price, default_l2_gas_price); - - let first_update_gas_price = - ResourcePrice { price_in_wei: (9e18 as u128).into(), price_in_fri: (7e18 as u128).into() }; - let first_update_data_gas_price = - ResourcePrice { price_in_wei: (8e18 as u128).into(), price_in_fri: (6e18 as u128).into() }; - let first_update_l2_gas_price = ResourcePrice { - price_in_wei: (8.5e18 as u128).into(), - price_in_fri: (7.5e18 as u128).into(), - }; - let gas_request = json!({ - "gas_price_wei": felt_to_u128(first_update_gas_price.price_in_wei), - "data_gas_price_wei": felt_to_u128(first_update_data_gas_price.price_in_wei), - "l2_gas_price_wei": felt_to_u128(first_update_l2_gas_price.price_in_wei), - "gas_price_fri": felt_to_u128(first_update_gas_price.price_in_fri), - "data_gas_price_fri": felt_to_u128(first_update_data_gas_price.price_in_fri), - "l2_gas_price_fri": felt_to_u128(first_update_l2_gas_price.price_in_fri), + assert_eq!(latest_block.l1_gas_price.price_in_fri, default_l1_gas_price.into()); + assert_eq!(latest_block.l1_data_gas_price.price_in_fri, default_l1_data_gas_price.into()); + assert_eq!(latest_block.l2_gas_price.price_in_fri, default_l2_gas_price.into()); + let first_update_l1_gas_price = 7e18 as u128; + let first_update_l1_data_gas_price = 6e18 as u128; + let first_update_l2_gas_price = 7.5e18 as u128; + let gas_request = json!({ + "l1_gas_price": first_update_l1_gas_price, + "l1_data_gas_price": first_update_l1_data_gas_price, + "l2_gas_price": first_update_l2_gas_price, }); let gas_response = devnet.set_gas_price(&gas_request, false).await.unwrap(); assert_eq!(gas_response, gas_request); @@ -284,50 +263,48 @@ async fn set_gas_check_blocks() { assert_eq!(latest_block.block_number, 0); let pending_block = devnet.get_pending_block_with_tx_hashes().await.unwrap(); - assert_eq!(pending_block.l1_gas_price, default_gas_price); - assert_eq!(pending_block.l1_data_gas_price, default_gas_price); + assert_eq!(pending_block.l1_gas_price.price_in_fri, default_l1_gas_price.into()); + assert_eq!(pending_block.l1_data_gas_price.price_in_fri, default_l1_data_gas_price.into()); + assert_eq!(pending_block.l2_gas_price.price_in_fri, default_l2_gas_price.into()); devnet.create_block().await.unwrap(); let pending_block = devnet.get_pending_block_with_tx_hashes().await.unwrap(); - assert_eq!(pending_block.l1_gas_price, first_update_gas_price); - assert_eq!(pending_block.l1_data_gas_price, first_update_data_gas_price); + assert_eq!(pending_block.l1_gas_price.price_in_fri, first_update_l1_gas_price.into()); + assert_eq!(pending_block.l1_data_gas_price.price_in_fri, first_update_l1_data_gas_price.into()); + assert_eq!(pending_block.l2_gas_price.price_in_fri, first_update_l2_gas_price.into()); let latest_block = devnet.get_latest_block_with_txs().await.unwrap(); assert_eq!(latest_block.block_number, 1); - assert_eq!(latest_block.l1_gas_price, first_update_gas_price); - assert_eq!(latest_block.l1_data_gas_price, first_update_data_gas_price); + assert_eq!(latest_block.l1_gas_price.price_in_fri, first_update_l1_gas_price.into()); + assert_eq!(latest_block.l1_data_gas_price.price_in_fri, first_update_l1_data_gas_price.into()); + assert_eq!(latest_block.l2_gas_price.price_in_fri, first_update_l2_gas_price.into()); // Second update - generate new block - let second_update_gas_price = - ResourcePrice { price_in_wei: (8e18 as u128).into(), price_in_fri: (6e18 as u128).into() }; - let second_update_data_gas_price = - ResourcePrice { price_in_wei: (7e18 as u128).into(), price_in_fri: (5e18 as u128).into() }; - let second_update_l2_gas_price = ResourcePrice { - price_in_wei: (7.5e18 as u128).into(), - price_in_fri: (6.5e18 as u128).into(), - }; + let second_update_l1_gas_price = 6e18 as u128; + let second_update_l1_data_gas_price = 5e18 as u128; + let second_update_l2_gas_price = 6.5e18 as u128; let gas_price = json!({ - "gas_price_wei": felt_to_u128(second_update_gas_price.price_in_wei), - "data_gas_price_wei": felt_to_u128(second_update_data_gas_price.price_in_wei), - "l2_gas_price_wei": felt_to_u128(second_update_l2_gas_price.price_in_wei), - "gas_price_fri": felt_to_u128(second_update_gas_price.price_in_fri), - "data_gas_price_fri": felt_to_u128(second_update_data_gas_price.price_in_fri), - "l2_gas_price_fri": felt_to_u128(second_update_l2_gas_price.price_in_fri), + "l1_gas_price": second_update_l1_gas_price, + "l1_data_gas_price": second_update_l1_data_gas_price, + "l2_gas_price": second_update_l2_gas_price, }); let gas_response = devnet.set_gas_price(&gas_price, true).await.unwrap(); assert_eq!(gas_response, gas_price); let latest_block = devnet.get_latest_block_with_txs().await.unwrap(); assert_eq!(latest_block.block_number, 2); - assert_eq!(latest_block.l1_gas_price, second_update_gas_price); - assert_eq!(latest_block.l1_data_gas_price, second_update_data_gas_price); - assert_eq!(latest_block.l2_gas_price, second_update_l2_gas_price); + assert_eq!(latest_block.l1_gas_price.price_in_fri, second_update_l1_gas_price.into()); + assert_eq!(latest_block.l1_data_gas_price.price_in_fri, second_update_l1_data_gas_price.into()); + assert_eq!(latest_block.l2_gas_price.price_in_fri, second_update_l2_gas_price.into()); let pending_block = devnet.get_pending_block_with_tx_hashes().await.unwrap(); - assert_eq!(pending_block.l1_gas_price, second_update_gas_price); - assert_eq!(pending_block.l1_data_gas_price, second_update_data_gas_price); - assert_eq!(pending_block.l2_gas_price, second_update_l2_gas_price); + assert_eq!(pending_block.l1_gas_price.price_in_fri, second_update_l1_gas_price.into()); + assert_eq!( + pending_block.l1_data_gas_price.price_in_fri, + second_update_l1_data_gas_price.into() + ); + assert_eq!(pending_block.l2_gas_price.price_in_fri, second_update_l2_gas_price.into()); } #[tokio::test] @@ -365,35 +342,23 @@ async fn unsuccessful_declare_set_gas_successful_declare() { }; let new_l2_fri_price = 9e7 as u128; // approximate upper limit that will pass - let gas_price = json!({ "l2_gas_price_fri": new_l2_fri_price }); + let gas_price = json!({ "l2_gas_price": new_l2_fri_price }); let gas_response = devnet.set_gas_price(&gas_price, true).await.unwrap(); - assert_eq!(gas_response["l2_gas_price_fri"], json!(new_l2_fri_price)); + assert_eq!(gas_response["l2_gas_price"], json!(new_l2_fri_price)); let latest_block = devnet.get_latest_block_with_txs().await.unwrap(); assert_eq!(latest_block.block_number, 1); let pending_block = devnet.get_pending_block_with_tx_hashes().await.unwrap(); assert_eq!( - pending_block.l1_gas_price, - ResourcePrice { - price_in_wei: u128::from(DEVNET_DEFAULT_L1_GAS_PRICE).into(), - price_in_fri: u128::from(DEVNET_DEFAULT_L1_GAS_PRICE).into() - } + pending_block.l1_gas_price.price_in_fri, + u128::from(DEVNET_DEFAULT_L1_GAS_PRICE).into() ); assert_eq!( - pending_block.l1_data_gas_price, - ResourcePrice { - price_in_wei: u128::from(DEVNET_DEFAULT_L1_DATA_GAS_PRICE).into(), - price_in_fri: u128::from(DEVNET_DEFAULT_L1_DATA_GAS_PRICE).into() - } - ); - assert_eq!( - pending_block.l2_gas_price, - ResourcePrice { - price_in_wei: u128::from(DEVNET_DEFAULT_L2_GAS_PRICE).into(), - price_in_fri: new_l2_fri_price.into() - } + pending_block.l1_data_gas_price.price_in_fri, + u128::from(DEVNET_DEFAULT_L1_DATA_GAS_PRICE).into() ); + assert_eq!(pending_block.l2_gas_price.price_in_fri, new_l2_fri_price.into()); let successful_declare_tx = predeployed_account .declare_v3(shared_class, casm_class_hash) @@ -412,11 +377,8 @@ async fn set_gas_optional_parameters() { let latest_block = devnet.get_latest_block_with_txs().await.unwrap(); assert_eq!( - latest_block.l1_gas_price, - ResourcePrice { - price_in_wei: (u128::from(DEVNET_DEFAULT_L1_GAS_PRICE)).into(), - price_in_fri: (u128::from(DEVNET_DEFAULT_L1_GAS_PRICE)).into(), - } + latest_block.l1_gas_price.price_in_fri, + u128::from(DEVNET_DEFAULT_L1_GAS_PRICE).into() ); // set nothing, get initial gas information and assert @@ -424,22 +386,16 @@ async fn set_gas_optional_parameters() { assert_eq!( gas_response, json!({ - "gas_price_wei": DEVNET_DEFAULT_L1_GAS_PRICE, - "data_gas_price_wei": DEVNET_DEFAULT_L1_GAS_PRICE, - "l2_gas_price_wei": DEVNET_DEFAULT_L2_GAS_PRICE, - "gas_price_fri": DEVNET_DEFAULT_L1_GAS_PRICE, - "data_gas_price_fri": DEVNET_DEFAULT_L1_GAS_PRICE, - "l2_gas_price_fri": DEVNET_DEFAULT_L2_GAS_PRICE, + "l1_gas_price": DEVNET_DEFAULT_L1_GAS_PRICE, + "l1_data_gas_price": DEVNET_DEFAULT_L1_DATA_GAS_PRICE, + "l2_gas_price": DEVNET_DEFAULT_L2_GAS_PRICE, }) ); let expected_final_gas_price = json!({ - "gas_price_wei": 9e18 as u128, - "data_gas_price_wei": 8e18 as u128, - "l2_gas_price_wei": 7.5e18 as u128, - "gas_price_fri": 7e18 as u128, - "data_gas_price_fri": 6e18 as u128, - "l2_gas_price_fri": 5.5e18 as u128, + "l1_gas_price": 9e18 as u128, + "l2_gas_price": 8e18 as u128, + "l1_data_gas_price": 7e18 as u128, }); for (gas_prop, gas_price) in expected_final_gas_price.as_object().unwrap() { diff --git a/tests/integration/test_restart.rs b/tests/integration/test_restart.rs index ceb32516f..7497b8e75 100644 --- a/tests/integration/test_restart.rs +++ b/tests/integration/test_restart.rs @@ -116,18 +116,18 @@ async fn assert_account_deployment_reverted() { #[tokio::test] async fn assert_gas_price_unaffected_by_restart() { let expected_l1_gas_price = 1_000_000_u64; + let expected_l1_data_gas_price = 3_000_000_u64; let expected_l2_gas_price = 2_000_000_u64; - let expected_data_gas_price = 3_000_000_u64; // assert difference to ensure values don't get mixed up in the logic - assert_ne!(expected_l1_gas_price, expected_data_gas_price); + assert_ne!(expected_l1_gas_price, expected_l1_data_gas_price); let devnet_args = [ - "--gas-price-fri", + "--l1-gas-price", &expected_l1_gas_price.to_string(), - "--l2-gas-price-fri", + "--l1-data-gas-price", + &expected_l1_data_gas_price.to_string(), + "--l2-gas-price", &expected_l2_gas_price.to_string(), - "--data-gas-price-fri", - &expected_data_gas_price.to_string(), ]; let devnet = BackgroundDevnet::spawn_with_additional_args(&devnet_args).await.unwrap(); @@ -153,7 +153,7 @@ async fn assert_gas_price_unaffected_by_restart() { .unwrap(); assert_eq!(estimate_before.l1_gas_price, Felt::from(expected_l1_gas_price)); assert_eq!(estimate_before.l2_gas_price, Felt::from(expected_l2_gas_price)); - assert_eq!(estimate_before.l1_data_gas_price, Felt::from(expected_data_gas_price)); + assert_eq!(estimate_before.l1_data_gas_price, Felt::from(expected_l1_data_gas_price)); devnet.restart().await; @@ -163,7 +163,7 @@ async fn assert_gas_price_unaffected_by_restart() { // assert gas_price and fee are equal to the values before restart assert_eq!(estimate_after.l1_gas_price, Felt::from(expected_l1_gas_price)); assert_eq!(estimate_after.l2_gas_price, Felt::from(expected_l2_gas_price)); - assert_eq!(estimate_after.l1_data_gas_price, Felt::from(expected_data_gas_price)); + assert_eq!(estimate_after.l1_data_gas_price, Felt::from(expected_l1_data_gas_price)); assert_eq!(estimate_before.overall_fee, estimate_after.overall_fee); } diff --git a/tests/integration/test_simulate_transactions.rs b/tests/integration/test_simulate_transactions.rs index 26f4bd234..c2f01839e 100644 --- a/tests/integration/test_simulate_transactions.rs +++ b/tests/integration/test_simulate_transactions.rs @@ -28,7 +28,7 @@ use crate::common::constants::{ }; use crate::common::fees::{assert_difference_if_validation, assert_fee_in_resp_at_least_equal}; use crate::common::utils::{ - LocalFee, assert_contains, declare_v3_deploy_v3, get_deployable_account_signer, + LocalFee, assert_contains, declare_v3_deploy_v3, felt_to_u128, get_deployable_account_signer, get_flattened_sierra_contract_and_casm_hash, get_simple_contract_artifacts, iter_to_hex_felt, to_hex_felt, to_num_as_hex, }; @@ -456,13 +456,11 @@ async fn test_simulation_of_panicking_invoke() { .await .unwrap(); - let gas_price = match block { - starknet_rs_core::types::MaybePendingBlockWithTxHashes::Block(latest) => { - latest.l2_gas_price.price_in_fri - } + let gas_price = felt_to_u128(match block { + MaybePendingBlockWithTxHashes::Block(latest) => latest.l2_gas_price.price_in_fri, MaybePendingBlockWithTxHashes::PendingBlock(pending) => pending.l2_gas_price.price_in_fri, - }; - let gas_price = u128::from_le_bytes(gas_price.to_bytes_le()[..16].try_into().unwrap()); + }); + let nonce = Felt::TWO; // after declare + deploy let simulation = account .execute_v3(calls) diff --git a/website/static/devnet_api.json b/website/static/devnet_api.json index ede875e65..610a07b29 100644 --- a/website/static/devnet_api.json +++ b/website/static/devnet_api.json @@ -384,28 +384,16 @@ "summary": "Set gas price", "params": [ { - "gas_price_wei": { - "title": "L1 Gas price in WEI", + "l1_gas_price": { + "title": "L1 gas price in FRI", "$ref": "#/components/schemas/u128" }, - "data_gas_price_wei": { - "title": "L1 Data gas price in WEI", + "l1_data_gas_price": { + "title": "L1 data gas price in FRI", "$ref": "#/components/schemas/u128" }, - "gas_price_fri": { - "title": "L1 Gas price in FRI", - "$ref": "#/components/schemas/u128" - }, - "data_gas_price_fri": { - "title": "L1 Data gas price in FRI", - "$ref": "#/components/schemas/u128" - }, - "l2_gas_price_wei": { - "title": "L2 Gas price in WEI", - "$ref": "#/components/schemas/u128" - }, - "l2_gas_price_fri": { - "title": "L2 Gas price in FRI", + "l2_gas_price": { + "title": "L2 gas price in FRI", "$ref": "#/components/schemas/u128" }, "generate_block": { @@ -420,37 +408,20 @@ "schema": { "type": "object", "properties": { - "gas_price_wei": { - "title": "Gas price in WEI", - "$ref": "#/components/schemas/u128" - }, - "data_gas_price_wei": { - "title": "L1 Data gas price in WEI", - "$ref": "#/components/schemas/u128" - }, - "gas_price_fri": { - "title": "L1 Gas price in FRI", + "l1_gas_price": { + "title": "L1 gas price in FRI", "$ref": "#/components/schemas/u128" }, - "data_gas_price_fri": { - "title": "L1 Data gas price in FRI", + "l1_data_gas_price": { + "title": "L1 data gas price in FRI", "$ref": "#/components/schemas/u128" }, - "l2_gas_price_wei": { - "title": "L2 Gas price in WEI", - "$ref": "#/components/schemas/u128" - }, - "l2_gas_price_fri": { - "title": "L2 Gas price in FRI", + "l2_gas_price": { + "title": "L2 gas price in FRI", "$ref": "#/components/schemas/u128" } }, - "required": [ - "gas_price_wei", - "data_gas_price_wei", - "gas_price_fri", - "data_gas_price_fri" - ] + "required": ["l1_gas_price", "l1_data_gas_price", "l2_gas_price"] } }, "errors": [ @@ -762,28 +733,16 @@ "title": "Start time", "type": "integer" }, - "gas_price_wei": { - "title": "L1 Gas price in WEI", - "$ref": "#/components/schemas/u128" - }, - "data_gas_price_wei": { - "title": "L1 Data gas price in WEI", - "$ref": "#/components/schemas/u128" - }, - "gas_price_fri": { - "title": "L1 Gas price in FRI", - "$ref": "#/components/schemas/u128" - }, - "data_gas_price_fri": { - "title": "L1 Data gas price in FRI", + "l1_gas_price": { + "title": "L1 gas price in FRI", "$ref": "#/components/schemas/u128" }, - "l2_gas_price_wei": { - "title": "L2 Gas price in WEI", + "l1_data_gas_price": { + "title": "L1 data gas price in FRI", "$ref": "#/components/schemas/u128" }, - "l2_gas_price_fri": { - "title": "L2 Gas price in FRI", + "l2_gas_price": { + "title": "L2 gas price in FRI", "$ref": "#/components/schemas/u128" }, "chain_id": { @@ -828,10 +787,9 @@ "account_contract_class_hash", "predeployed_accounts_initial_balance", "start_time", - "gas_price_fri", - "gas_price_wei", - "data_gas_price_fri", - "data_gas_price_wei", + "l1_gas_price", + "l1_data_gas_price", + "l2_gas_price", "chain_id", "block_generation_on", "lite_mode",