Skip to content

Commit

Permalink
chore(blockifier): move block info to starknet api
Browse files Browse the repository at this point in the history
  • Loading branch information
ArniStarkware committed Nov 28, 2024
1 parent 33cef26 commit 1153ca9
Show file tree
Hide file tree
Showing 18 changed files with 64 additions and 45 deletions.
13 changes: 0 additions & 13 deletions crates/blockifier/src/blockifier/block.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use log::warn;
use serde::{Deserialize, Serialize};
use starknet_api::block::{
BlockHashAndNumber,
BlockNumber,
BlockTimestamp,
GasPrice,
GasPriceVector,
GasPrices,
Expand All @@ -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.
Expand Down
3 changes: 1 addition & 2 deletions crates/blockifier/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ 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,
GasVectorComputationMode,
ValidResourceBounds,
};

use crate::blockifier::block::BlockInfo;
use crate::bouncer::BouncerConfig;
use crate::transaction::objects::{
CurrentTransactionInfo,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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::{
Expand Down
3 changes: 1 addition & 2 deletions crates/blockifier/src/fee/fee_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ 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;
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;
Expand Down
15 changes: 10 additions & 5 deletions crates/blockifier/src/test_utils/struct_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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};
Expand Down Expand Up @@ -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),
Expand All @@ -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() }
}
}
Expand Down
3 changes: 1 addition & 2 deletions crates/blockifier/src/transaction/objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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};
Expand Down
4 changes: 2 additions & 2 deletions crates/native_blockifier/src/py_state_diff.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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};

Expand Down
10 changes: 8 additions & 2 deletions crates/papyrus_execution/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
12 changes: 12 additions & 0 deletions crates/starknet_api/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use starknet_types_core::hash::{Poseidon, StarkHash as CoreStarkHash};
use strum_macros::EnumIter;

use crate::core::{
ContractAddress,
EventCommitment,
GlobalRoot,
ReceiptCommitment,
Expand Down Expand Up @@ -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(
Expand Down
10 changes: 8 additions & 2 deletions crates/starknet_batcher/src/block_builder.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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;
Expand Down
11 changes: 9 additions & 2 deletions crates/starknet_gateway/src/rpc_objects.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
3 changes: 1 addition & 2 deletions crates/starknet_gateway/src/rpc_state_reader.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use blockifier::blockifier::block::BlockInfo;
use blockifier::execution::contract_class::{
CompiledClassV0,
CompiledClassV1,
Expand All @@ -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;
Expand Down
6 changes: 5 additions & 1 deletion crates/starknet_gateway/src/state_reader.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
3 changes: 1 addition & 2 deletions crates/starknet_gateway/src/state_reader_test_utils.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use blockifier::blockifier::block::BlockInfo;
use blockifier::context::BlockContext;
use blockifier::execution::contract_class::RunnableCompiledClass;
use blockifier::state::errors::StateError;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use blockifier::blockifier::block::BlockInfo;
use blockifier::blockifier::stateful_validator::{
StatefulValidator,
StatefulValidatorResult as BlockifierStatefulValidatorResult,
Expand All @@ -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,
Expand Down

0 comments on commit 1153ca9

Please sign in to comment.