From 1153ca94413f47c005f9224580a408e6c9dacecd Mon Sep 17 00:00:00 2001 From: Arni Hod Date: Sun, 24 Nov 2024 14:09:00 +0200 Subject: [PATCH] chore(blockifier): move block info to starknet api --- crates/blockifier/src/blockifier/block.rs | 13 ------------- crates/blockifier/src/context.rs | 3 +-- .../deprecated_syscalls/hint_processor.rs | 2 +- crates/blockifier/src/fee/fee_utils.rs | 3 +-- crates/blockifier/src/test_utils/struct_impls.rs | 15 ++++++++++----- crates/blockifier/src/transaction/objects.rs | 3 +-- .../src/state_reader/raw_rpc_json_test.rs | 3 +-- .../src/state_reader/rpc_https_test.rs | 3 +-- .../src/state_reader/test_state_reader.rs | 3 +-- crates/native_blockifier/src/py_state_diff.rs | 4 ++-- crates/papyrus_execution/src/lib.rs | 10 ++++++++-- crates/starknet_api/src/block.rs | 12 ++++++++++++ crates/starknet_batcher/src/block_builder.rs | 10 ++++++++-- crates/starknet_gateway/src/rpc_objects.rs | 11 +++++++++-- crates/starknet_gateway/src/rpc_state_reader.rs | 3 +-- crates/starknet_gateway/src/state_reader.rs | 6 +++++- .../src/state_reader_test_utils.rs | 3 +-- .../src/stateful_transaction_validator.rs | 2 +- 18 files changed, 64 insertions(+), 45 deletions(-) diff --git a/crates/blockifier/src/blockifier/block.rs b/crates/blockifier/src/blockifier/block.rs index 59a8a1ec0f..5383d645f5 100644 --- a/crates/blockifier/src/blockifier/block.rs +++ b/crates/blockifier/src/blockifier/block.rs @@ -1,9 +1,7 @@ use log::warn; -use serde::{Deserialize, Serialize}; use starknet_api::block::{ BlockHashAndNumber, BlockNumber, - BlockTimestamp, GasPrice, GasPriceVector, GasPrices, @@ -21,17 +19,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 069fcb53e6..bd69be574f 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::{FeeType, GasPriceVector}; +use starknet_api::block::{BlockInfo, FeeType, 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 32c12710b0..097ccf9c56 100644 --- a/crates/blockifier/src/fee/fee_utils.rs +++ b/crates/blockifier/src/fee/fee_utils.rs @@ -4,7 +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::FeeType; +use starknet_api::block::{BlockInfo, FeeType}; use starknet_api::core::ContractAddress; use starknet_api::execution_resources::GasVector; use starknet_api::state::StorageKey; @@ -12,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 71d64061f9..fe9fdebff5 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::{validated_gas_prices, BlockInfo}; +use crate::blockifier::block::validated_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 0ce713a6a0..4cfef890e6 100644 --- a/crates/blockifier/src/transaction/objects.rs +++ b/crates/blockifier/src/transaction/objects.rs @@ -2,7 +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::FeeType; +use starknet_api::block::{BlockInfo, FeeType}; use starknet_api::core::{ContractAddress, Nonce}; use starknet_api::data_availability::DataAvailabilityMode; use starknet_api::execution_resources::GasVector; @@ -25,7 +25,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 a1d10da6cb..847bb77e55 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 7ebb38ac31..86cd5310a8 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 70ea8fb9d1..76a6063cbe 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::{validated_gas_prices, BlockInfo}; +use blockifier::blockifier::block::validated_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 6ed407c2dd..77e5348e4a 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::{pre_process_block, validated_gas_prices, BlockInfo}; +use blockifier::blockifier::block::{pre_process_block, validated_gas_prices}; 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 2e89212e8e..cef053fd29 100644 --- a/crates/starknet_api/src/block.rs +++ b/crates/starknet_api/src/block.rs @@ -9,6 +9,7 @@ use starknet_types_core::hash::{Poseidon, StarkHash as CoreStarkHash}; use strum_macros::EnumIter; use crate::core::{ + ContractAddress, EventCommitment, GlobalRoot, ReceiptCommitment, @@ -484,6 +485,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 0e72c761ff..ef7fcfb6e9 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::{validated_gas_prices, BlockInfo}; +use blockifier::blockifier::block::validated_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 5333f6e1cc..78ec71f82a 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::{validated_gas_prices, BlockInfo}; +use blockifier::blockifier::block::validated_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 fa4e5fc684..a01ccdc703 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::{ CompiledClassV0, CompiledClassV1, @@ -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 4109a426ee..efb3e6f4bf 100644 --- a/crates/starknet_gateway/src/state_reader.rs +++ b/crates/starknet_gateway/src/state_reader.rs @@ -1,10 +1,14 @@ +<<<<<<< HEAD use blockifier::blockifier::block::BlockInfo; use blockifier::execution::contract_class::RunnableCompiledClass; +======= +use blockifier::execution::contract_class::RunnableContractClass; +>>>>>>> 33e656ad5 (chore(blockifier): move block info to starknet api) 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 45184de5d4..80c8fc8b51 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::RunnableCompiledClass; 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,