diff --git a/crates/blockifier/src/blockifier/block.rs b/crates/blockifier/src/blockifier/block.rs index 12307ef3f8..6dba16f6b3 100644 --- a/crates/blockifier/src/blockifier/block.rs +++ b/crates/blockifier/src/blockifier/block.rs @@ -1,13 +1,6 @@ use log::warn; -use serde::{Deserialize, Serialize}; pub use starknet_api::block::GasPrices; -use starknet_api::block::{ - BlockHashAndNumber, - BlockNumber, - BlockTimestamp, - GasPrice, - NonzeroGasPrice, -}; +use starknet_api::block::{BlockHashAndNumber, BlockNumber, GasPrice, NonzeroGasPrice}; use starknet_api::core::ContractAddress; use starknet_api::state::StorageKey; use starknet_api::transaction::fields::FeeType; @@ -21,17 +14,6 @@ use crate::versioned_constants::VersionedConstants; #[path = "block_test.rs"] pub mod block_test; -#[derive(Clone, Debug, Deserialize, Serialize)] -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, -} - /// Warns if the submitted gas prices do not match the expected gas prices. fn validate_l2_gas_price(gas_prices: &GasPrices) { // TODO(Aner): fix backwards compatibility. diff --git a/crates/blockifier/src/context.rs b/crates/blockifier/src/context.rs index e77c5e0382..0a4aa66a79 100644 --- a/crates/blockifier/src/context.rs +++ b/crates/blockifier/src/context.rs @@ -3,7 +3,7 @@ use std::collections::BTreeMap; use papyrus_config::dumping::{append_sub_config_name, ser_param, SerializeConfig}; use papyrus_config::{ParamPath, ParamPrivacyInput, SerializedParam}; use serde::{Deserialize, Serialize}; -use starknet_api::block::GasPriceVector; +use starknet_api::block::{BlockInfo, GasPriceVector}; use starknet_api::core::{ChainId, ContractAddress}; use starknet_api::transaction::fields::{ AllResourceBounds, @@ -11,7 +11,6 @@ use starknet_api::transaction::fields::{ ValidResourceBounds, }; -use crate::blockifier::block::BlockInfo; use crate::bouncer::BouncerConfig; use crate::transaction::objects::{ CurrentTransactionInfo, diff --git a/crates/blockifier/src/execution/deprecated_syscalls/hint_processor.rs b/crates/blockifier/src/execution/deprecated_syscalls/hint_processor.rs index 0ea7f175f6..16f24ce504 100644 --- a/crates/blockifier/src/execution/deprecated_syscalls/hint_processor.rs +++ b/crates/blockifier/src/execution/deprecated_syscalls/hint_processor.rs @@ -17,6 +17,7 @@ use cairo_vm::vm::errors::vm_errors::VirtualMachineError; use cairo_vm::vm::runners::cairo_runner::{ResourceTracker, RunResources}; use cairo_vm::vm::vm_core::VirtualMachine; use num_bigint::{BigUint, TryFromBigIntError}; +use starknet_api::block::BlockInfo; use starknet_api::contract_class::EntryPointType; use starknet_api::core::{ClassHash, ContractAddress, EntryPointSelector}; use starknet_api::state::StorageKey; @@ -25,7 +26,6 @@ use starknet_api::StarknetApiError; use starknet_types_core::felt::{Felt, FromStrError}; use thiserror::Error; -use crate::blockifier::block::BlockInfo; use crate::context::TransactionContext; use crate::execution::call_info::{CallInfo, OrderedEvent, OrderedL2ToL1Message}; use crate::execution::common_hints::{ diff --git a/crates/blockifier/src/fee/fee_utils.rs b/crates/blockifier/src/fee/fee_utils.rs index 89a3685f3e..45f4ed278a 100644 --- a/crates/blockifier/src/fee/fee_utils.rs +++ b/crates/blockifier/src/fee/fee_utils.rs @@ -4,6 +4,7 @@ use cairo_vm::types::builtin_name::BuiltinName; use cairo_vm::vm::runners::cairo_runner::ExecutionResources; use num_bigint::BigUint; use starknet_api::abi::abi_utils::get_fee_token_var_address; +use starknet_api::block::BlockInfo; use starknet_api::core::ContractAddress; use starknet_api::execution_resources::GasVector; use starknet_api::state::StorageKey; @@ -11,7 +12,6 @@ use starknet_api::transaction::fields::ValidResourceBounds::{AllResources, L1Gas use starknet_api::transaction::fields::{Fee, GasVectorComputationMode, Resource}; use starknet_types_core::felt::Felt; -use crate::blockifier::block::BlockInfo; use crate::context::{BlockContext, TransactionContext}; use crate::fee::resources::TransactionFeeResult; use crate::state::state_api::StateReader; diff --git a/crates/blockifier/src/test_utils/struct_impls.rs b/crates/blockifier/src/test_utils/struct_impls.rs index 7b5fc0d85b..dadef4b0d2 100644 --- a/crates/blockifier/src/test_utils/struct_impls.rs +++ b/crates/blockifier/src/test_utils/struct_impls.rs @@ -10,7 +10,7 @@ use cairo_lang_starknet_classes::contract_class::ContractClass as SierraContract #[cfg(feature = "cairo_native")] use cairo_native::executor::AotContractExecutor; use serde_json::Value; -use starknet_api::block::{BlockNumber, BlockTimestamp, NonzeroGasPrice}; +use starknet_api::block::{BlockInfo, BlockNumber, BlockTimestamp, NonzeroGasPrice}; use starknet_api::contract_address; use starknet_api::core::{ChainId, ClassHash}; use starknet_api::deprecated_contract_class::ContractClass as DeprecatedContractClass; @@ -21,7 +21,7 @@ use super::{ TEST_ERC20_CONTRACT_ADDRESS2, TEST_SEQUENCER_ADDRESS, }; -use crate::blockifier::block::{gas_prices, BlockInfo}; +use crate::blockifier::block::gas_prices; use crate::bouncer::{BouncerConfig, BouncerWeights, BuiltinCount}; use crate::context::{BlockContext, ChainInfo, FeeTokenAddresses, TransactionContext}; use crate::execution::call_info::{CallExecution, CallInfo, Retdata}; @@ -146,8 +146,13 @@ impl ChainInfo { } } -impl BlockInfo { - pub fn create_for_testing() -> Self { +pub trait BlockInfoExt { + fn create_for_testing() -> Self; + fn create_for_testing_with_kzg(use_kzg_da: bool) -> Self; +} + +impl BlockInfoExt for BlockInfo { + fn create_for_testing() -> Self { Self { block_number: BlockNumber(CURRENT_BLOCK_NUMBER), block_timestamp: BlockTimestamp(CURRENT_BLOCK_TIMESTAMP), @@ -172,7 +177,7 @@ impl BlockInfo { } } - pub fn create_for_testing_with_kzg(use_kzg_da: bool) -> Self { + fn create_for_testing_with_kzg(use_kzg_da: bool) -> Self { Self { use_kzg_da, ..Self::create_for_testing() } } } diff --git a/crates/blockifier/src/transaction/objects.rs b/crates/blockifier/src/transaction/objects.rs index 66e58aa5b5..b9aeec6183 100644 --- a/crates/blockifier/src/transaction/objects.rs +++ b/crates/blockifier/src/transaction/objects.rs @@ -2,6 +2,7 @@ use std::collections::HashMap; use cairo_vm::types::builtin_name::BuiltinName; use cairo_vm::vm::runners::cairo_runner::ExecutionResources; +use starknet_api::block::BlockInfo; use starknet_api::core::{ContractAddress, Nonce}; use starknet_api::data_availability::DataAvailabilityMode; use starknet_api::execution_resources::GasVector; @@ -25,7 +26,6 @@ use starknet_api::transaction::{ }; use crate::abi::constants as abi_constants; -use crate::blockifier::block::BlockInfo; use crate::execution::call_info::{CallInfo, ExecutionSummary}; use crate::execution::stack_trace::ErrorStack; use crate::fee::fee_checks::FeeCheckError; diff --git a/crates/blockifier_reexecution/src/state_reader/raw_rpc_json_test.rs b/crates/blockifier_reexecution/src/state_reader/raw_rpc_json_test.rs index f79d104685..5ff477ad64 100644 --- a/crates/blockifier_reexecution/src/state_reader/raw_rpc_json_test.rs +++ b/crates/blockifier_reexecution/src/state_reader/raw_rpc_json_test.rs @@ -1,11 +1,10 @@ use std::collections::HashMap; use assert_matches::assert_matches; -use blockifier::blockifier::block::BlockInfo; use blockifier::state::cached_state::StateMaps; use pretty_assertions::assert_eq; use rstest::{fixture, rstest}; -use starknet_api::block::BlockNumber; +use starknet_api::block::{BlockInfo, BlockNumber}; use starknet_api::test_utils::read_json_file; use starknet_api::transaction::{ DeclareTransaction, diff --git a/crates/blockifier_reexecution/src/state_reader/rpc_https_test.rs b/crates/blockifier_reexecution/src/state_reader/rpc_https_test.rs index d3595d67a6..bce11597c6 100644 --- a/crates/blockifier_reexecution/src/state_reader/rpc_https_test.rs +++ b/crates/blockifier_reexecution/src/state_reader/rpc_https_test.rs @@ -13,9 +13,8 @@ use std::env; use std::sync::{Arc, Mutex}; use assert_matches::assert_matches; -use blockifier::blockifier::block::BlockInfo; use rstest::{fixture, rstest}; -use starknet_api::block::BlockNumber; +use starknet_api::block::{BlockInfo, BlockNumber}; use starknet_api::class_hash; use starknet_api::core::ChainId; use starknet_api::transaction::{ diff --git a/crates/blockifier_reexecution/src/state_reader/test_state_reader.rs b/crates/blockifier_reexecution/src/state_reader/test_state_reader.rs index 5362a6ef63..9872a4ee10 100644 --- a/crates/blockifier_reexecution/src/state_reader/test_state_reader.rs +++ b/crates/blockifier_reexecution/src/state_reader/test_state_reader.rs @@ -4,7 +4,6 @@ use std::sync::{Arc, Mutex}; use assert_matches::assert_matches; use blockifier::abi::constants; -use blockifier::blockifier::block::BlockInfo; use blockifier::blockifier::config::TransactionExecutorConfig; use blockifier::blockifier::transaction_executor::TransactionExecutor; use blockifier::bouncer::BouncerConfig; @@ -17,7 +16,7 @@ use blockifier::transaction::transaction_execution::Transaction as BlockifierTra use blockifier::versioned_constants::VersionedConstants; use serde::{Deserialize, Serialize}; use serde_json::{json, to_value}; -use starknet_api::block::{BlockHash, BlockHashAndNumber, BlockNumber, StarknetVersion}; +use starknet_api::block::{BlockHash, BlockHashAndNumber, BlockInfo, BlockNumber, StarknetVersion}; use starknet_api::core::{ChainId, ClassHash, CompiledClassHash, ContractAddress, Nonce}; use starknet_api::state::StorageKey; use starknet_api::transaction::{Transaction, TransactionHash}; diff --git a/crates/native_blockifier/src/py_state_diff.rs b/crates/native_blockifier/src/py_state_diff.rs index 74d5afc8b9..00e7d7d95d 100644 --- a/crates/native_blockifier/src/py_state_diff.rs +++ b/crates/native_blockifier/src/py_state_diff.rs @@ -1,7 +1,7 @@ use std::collections::HashMap; use std::convert::TryFrom; -use blockifier::blockifier::block::{gas_prices, BlockInfo}; +use blockifier::blockifier::block::gas_prices; use blockifier::state::cached_state::CommitmentStateDiff; use blockifier::test_utils::{ DEFAULT_ETH_L1_DATA_GAS_PRICE, @@ -13,7 +13,7 @@ use blockifier::versioned_constants::VersionedConstants; use indexmap::IndexMap; use pyo3::prelude::*; use pyo3::FromPyObject; -use starknet_api::block::{BlockNumber, BlockTimestamp, NonzeroGasPrice}; +use starknet_api::block::{BlockInfo, BlockNumber, BlockTimestamp, NonzeroGasPrice}; use starknet_api::core::{ClassHash, ContractAddress, Nonce}; use starknet_api::state::{StateDiff, StorageKey}; diff --git a/crates/papyrus_execution/src/lib.rs b/crates/papyrus_execution/src/lib.rs index 637df74f99..c62c2ac824 100644 --- a/crates/papyrus_execution/src/lib.rs +++ b/crates/papyrus_execution/src/lib.rs @@ -23,7 +23,7 @@ use std::cell::Cell; use std::collections::BTreeMap; use std::sync::{Arc, LazyLock}; -use blockifier::blockifier::block::{gas_prices, pre_process_block, BlockInfo}; +use blockifier::blockifier::block::{gas_prices, pre_process_block}; use blockifier::bouncer::BouncerConfig; use blockifier::context::{BlockContext, ChainInfo, FeeTokenAddresses, TransactionContext}; use blockifier::execution::call_info::CallExecution; @@ -51,7 +51,13 @@ use papyrus_config::{ParamPath, ParamPrivacyInput, SerializedParam}; use papyrus_storage::header::HeaderStorageReader; use papyrus_storage::{StorageError, StorageReader}; use serde::{Deserialize, Serialize}; -use starknet_api::block::{BlockHashAndNumber, BlockNumber, NonzeroGasPrice, StarknetVersion}; +use starknet_api::block::{ + BlockHashAndNumber, + BlockInfo, + BlockNumber, + NonzeroGasPrice, + StarknetVersion, +}; use starknet_api::contract_class::{ClassInfo, EntryPointType}; use starknet_api::core::{ChainId, ClassHash, ContractAddress, EntryPointSelector}; use starknet_api::data_availability::L1DataAvailabilityMode; diff --git a/crates/starknet_api/src/block.rs b/crates/starknet_api/src/block.rs index b2b13a6f31..56164fff57 100644 --- a/crates/starknet_api/src/block.rs +++ b/crates/starknet_api/src/block.rs @@ -8,6 +8,7 @@ use starknet_types_core::felt::Felt; use starknet_types_core::hash::{Poseidon, StarkHash as CoreStarkHash}; use crate::core::{ + ContractAddress, EventCommitment, GlobalRoot, ReceiptCommitment, @@ -499,6 +500,17 @@ impl GasPrices { )] pub struct BlockTimestamp(pub u64); +#[derive(Clone, Debug, Deserialize, Serialize)] +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, +} + /// The signature of a [Block](`crate::block::Block`), signed by the sequencer. The signed message /// is defined as poseidon_hash(block_hash, state_diff_commitment). #[derive( diff --git a/crates/starknet_batcher/src/block_builder.rs b/crates/starknet_batcher/src/block_builder.rs index f11020570e..2fc16a721f 100644 --- a/crates/starknet_batcher/src/block_builder.rs +++ b/crates/starknet_batcher/src/block_builder.rs @@ -1,7 +1,7 @@ use std::collections::BTreeMap; use async_trait::async_trait; -use blockifier::blockifier::block::{gas_prices, BlockInfo}; +use blockifier::blockifier::block::gas_prices; use blockifier::blockifier::config::TransactionExecutorConfig; use blockifier::blockifier::transaction_executor::{ TransactionExecutor, @@ -26,7 +26,13 @@ use papyrus_config::{ParamPath, ParamPrivacyInput, SerializedParam}; use papyrus_state_reader::papyrus_state::PapyrusReader; use papyrus_storage::StorageReader; use serde::{Deserialize, Serialize}; -use starknet_api::block::{BlockHashAndNumber, BlockNumber, BlockTimestamp, NonzeroGasPrice}; +use starknet_api::block::{ + BlockHashAndNumber, + BlockInfo, + BlockNumber, + BlockTimestamp, + NonzeroGasPrice, +}; use starknet_api::core::ContractAddress; use starknet_api::executable_transaction::Transaction; use starknet_api::transaction::TransactionHash; diff --git a/crates/starknet_gateway/src/rpc_objects.rs b/crates/starknet_gateway/src/rpc_objects.rs index 3baaaf27eb..0df82c6387 100644 --- a/crates/starknet_gateway/src/rpc_objects.rs +++ b/crates/starknet_gateway/src/rpc_objects.rs @@ -1,7 +1,14 @@ -use blockifier::blockifier::block::{gas_prices, BlockInfo}; +use blockifier::blockifier::block::gas_prices; use serde::{Deserialize, Serialize}; use serde_json::Value; -use starknet_api::block::{BlockHash, BlockNumber, BlockTimestamp, GasPrice, NonzeroGasPrice}; +use starknet_api::block::{ + BlockHash, + BlockInfo, + BlockNumber, + BlockTimestamp, + GasPrice, + NonzeroGasPrice, +}; use starknet_api::core::{ClassHash, ContractAddress, GlobalRoot}; use starknet_api::data_availability::L1DataAvailabilityMode; use starknet_api::state::StorageKey; diff --git a/crates/starknet_gateway/src/rpc_state_reader.rs b/crates/starknet_gateway/src/rpc_state_reader.rs index 57eb41212c..5df9a34d6b 100644 --- a/crates/starknet_gateway/src/rpc_state_reader.rs +++ b/crates/starknet_gateway/src/rpc_state_reader.rs @@ -1,4 +1,3 @@ -use blockifier::blockifier::block::BlockInfo; use blockifier::execution::contract_class::{ ContractClassV0, ContractClassV1, @@ -10,7 +9,7 @@ use papyrus_rpc::CompiledContractClass; use reqwest::blocking::Client as BlockingClient; use serde::Serialize; use serde_json::{json, Value}; -use starknet_api::block::BlockNumber; +use starknet_api::block::{BlockInfo, BlockNumber}; use starknet_api::core::{ClassHash, CompiledClassHash, ContractAddress, Nonce}; use starknet_api::state::StorageKey; use starknet_types_core::felt::Felt; diff --git a/crates/starknet_gateway/src/state_reader.rs b/crates/starknet_gateway/src/state_reader.rs index 993fe4b5d5..04a83048d2 100644 --- a/crates/starknet_gateway/src/state_reader.rs +++ b/crates/starknet_gateway/src/state_reader.rs @@ -1,10 +1,9 @@ -use blockifier::blockifier::block::BlockInfo; use blockifier::execution::contract_class::RunnableContractClass; use blockifier::state::errors::StateError; use blockifier::state::state_api::{StateReader as BlockifierStateReader, StateResult}; #[cfg(test)] use mockall::automock; -use starknet_api::block::BlockNumber; +use starknet_api::block::{BlockInfo, BlockNumber}; use starknet_api::core::{ClassHash, CompiledClassHash, ContractAddress, Nonce}; use starknet_api::state::StorageKey; use starknet_types_core::felt::Felt; diff --git a/crates/starknet_gateway/src/state_reader_test_utils.rs b/crates/starknet_gateway/src/state_reader_test_utils.rs index faf1121a53..8d909be2e8 100644 --- a/crates/starknet_gateway/src/state_reader_test_utils.rs +++ b/crates/starknet_gateway/src/state_reader_test_utils.rs @@ -1,4 +1,3 @@ -use blockifier::blockifier::block::BlockInfo; use blockifier::context::BlockContext; use blockifier::execution::contract_class::RunnableContractClass; use blockifier::state::errors::StateError; @@ -7,7 +6,7 @@ use blockifier::test_utils::contracts::FeatureContract; use blockifier::test_utils::dict_state_reader::DictStateReader; use blockifier::test_utils::initial_test_state::test_state; use blockifier::test_utils::{CairoVersion, BALANCE}; -use starknet_api::block::BlockNumber; +use starknet_api::block::{BlockInfo, BlockNumber}; use starknet_api::core::{ClassHash, CompiledClassHash, ContractAddress, Nonce}; use starknet_api::state::StorageKey; use starknet_api::transaction::fields::Fee; diff --git a/crates/starknet_gateway/src/stateful_transaction_validator.rs b/crates/starknet_gateway/src/stateful_transaction_validator.rs index ddcbe80e87..db04f52c79 100644 --- a/crates/starknet_gateway/src/stateful_transaction_validator.rs +++ b/crates/starknet_gateway/src/stateful_transaction_validator.rs @@ -1,4 +1,3 @@ -use blockifier::blockifier::block::BlockInfo; use blockifier::blockifier::stateful_validator::{ StatefulValidator, StatefulValidatorResult as BlockifierStatefulValidatorResult, @@ -10,6 +9,7 @@ use blockifier::transaction::account_transaction::AccountTransaction; use blockifier::versioned_constants::VersionedConstants; #[cfg(test)] use mockall::automock; +use starknet_api::block::BlockInfo; use starknet_api::core::{ContractAddress, Nonce}; use starknet_api::executable_transaction::{ AccountTransaction as ExecutableTransaction,