Skip to content

Commit

Permalink
feat(blockifier): add starknet_version to block info
Browse files Browse the repository at this point in the history
  • Loading branch information
nimrod-starkware committed Nov 5, 2024
1 parent 8eaf172 commit d628fe7
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 7 deletions.
9 changes: 8 additions & 1 deletion crates/batcher/src/block_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@ use papyrus_config::dumping::{append_sub_config_name, ser_param, SerializeConfig
use papyrus_config::{ParamPath, ParamPrivacyInput, SerializedParam};
use papyrus_storage::StorageReader;
use serde::{Deserialize, Serialize};
use starknet_api::block::{BlockHashAndNumber, BlockNumber, BlockTimestamp, NonzeroGasPrice};
use starknet_api::block::{
BlockHashAndNumber,
BlockNumber,
BlockTimestamp,
NonzeroGasPrice,
StarknetVersion,
};
use starknet_api::core::ContractAddress;
use starknet_api::executable_transaction::Transaction;
use starknet_api::transaction::TransactionHash;
Expand Down Expand Up @@ -256,6 +262,7 @@ impl BlockBuilderFactory {
GasPrices::new(tmp_val, tmp_val, tmp_val, tmp_val, tmp_val, tmp_val)
},
use_kzg_da: block_builder_config.use_kzg_da,
starknet_version: StarknetVersion::LATEST,
};
let block_context = BlockContext::new(
next_block_info,
Expand Down
2 changes: 2 additions & 0 deletions crates/blockifier/src/blockifier/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use starknet_api::block::{
GasPrice,
GasPriceVector,
NonzeroGasPrice,
StarknetVersion,
};
use starknet_api::core::ContractAddress;
use starknet_api::state::StorageKey;
Expand All @@ -30,6 +31,7 @@ pub struct BlockInfo {
pub sequencer_address: ContractAddress,
pub gas_prices: GasPrices,
pub use_kzg_da: bool,
pub starknet_version: StarknetVersion,
}

#[cfg_attr(feature = "transaction_serde", derive(serde::Serialize, serde::Deserialize))]
Expand Down
3 changes: 2 additions & 1 deletion crates/blockifier/src/test_utils/struct_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::sync::Arc;
use cairo_lang_starknet_classes::casm_contract_class::CasmContractClass;
use cairo_vm::vm::runners::cairo_runner::ExecutionResources;
use serde_json::Value;
use starknet_api::block::{BlockNumber, BlockTimestamp, NonzeroGasPrice};
use starknet_api::block::{BlockNumber, BlockTimestamp, NonzeroGasPrice, StarknetVersion};
use starknet_api::core::{ChainId, ClassHash, ContractAddress, Nonce};
use starknet_api::deprecated_contract_class::ContractClass as DeprecatedContractClass;
use starknet_api::transaction::{Fee, TransactionHash, TransactionVersion};
Expand Down Expand Up @@ -157,6 +157,7 @@ impl BlockInfo {
.unwrap(),
),
use_kzg_da: false,
starknet_version: StarknetVersion::LATEST,
}
}

Expand Down
3 changes: 3 additions & 0 deletions crates/gateway/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use blockifier::state::errors::StateError;
use serde_json::{Error as SerdeError, Value};
use starknet_api::block::GasPrice;
use starknet_api::transaction::{Resource, ResourceBounds};
use starknet_api::StarknetApiError;
use starknet_gateway_types::errors::GatewaySpecError;
use thiserror::Error;

Expand Down Expand Up @@ -84,6 +85,8 @@ pub enum RPCStateReaderError {
ReqwestError(#[from] reqwest::Error),
#[error("Unexpected error code: {0}")]
UnexpectedErrorCode(u16),
#[error(transparent)]
StarknetAPIError(#[from] StarknetApiError),
}

pub type RPCStateReaderResult<T> = Result<T, RPCStateReaderError>;
Expand Down
1 change: 1 addition & 0 deletions crates/gateway/src/rpc_objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ impl TryInto<BlockInfo> for BlockHeader {
parse_gas_price(self.l2_gas_price.price_in_fri)?,
),
use_kzg_da: matches!(self.l1_da_mode, L1DataAvailabilityMode::Blob),
starknet_version: self.starknet_version.try_into()?,
})
}
}
Expand Down
8 changes: 7 additions & 1 deletion crates/native_blockifier/src/py_state_diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{BlockNumber, BlockTimestamp, NonzeroGasPrice, StarknetVersion};
use starknet_api::core::{ClassHash, ContractAddress, Nonce};
use starknet_api::state::{StateDiff, StorageKey};

Expand Down Expand Up @@ -144,6 +144,7 @@ pub struct PyBlockInfo {
pub l2_gas_price: PyResourcePrice,
pub sequencer_address: PyFelt,
pub use_kzg_da: bool,
pub starknet_version: Option<String>,
}

/// Block info cannot have gas prices set to zero; implement `Default` explicitly.
Expand All @@ -170,6 +171,7 @@ impl Default for PyBlockInfo {
},
sequencer_address: PyFelt::default(),
use_kzg_da: bool::default(),
starknet_version: Some(StarknetVersion::LATEST.into()),
}
}
}
Expand Down Expand Up @@ -231,6 +233,10 @@ impl TryFrom<PyBlockInfo> for BlockInfo {
})?,
),
use_kzg_da: block_info.use_kzg_da,
starknet_version: block_info
.starknet_version
.unwrap_or(StarknetVersion::LATEST.into())
.try_into()?,
})
}
}
9 changes: 5 additions & 4 deletions crates/papyrus_execution/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,10 @@ fn create_block_context(
}
};

let starknet_version = storage_reader
.begin_ro_txn()?
.get_starknet_version(block_number)?
.unwrap_or(StarknetVersion::LATEST);
let block_info = BlockInfo {
block_timestamp,
sequencer_address: sequencer_address.0,
Expand All @@ -385,6 +389,7 @@ fn create_block_context(
NonzeroGasPrice::new(l2_gas_price.price_in_wei).unwrap_or(NonzeroGasPrice::MIN),
NonzeroGasPrice::new(l2_gas_price.price_in_fri).unwrap_or(NonzeroGasPrice::MIN),
),
starknet_version,
};
let chain_info = ChainInfo {
chain_id,
Expand All @@ -393,10 +398,6 @@ fn create_block_context(
eth_fee_token_address: execution_config.eth_fee_contract_address,
},
};
let starknet_version = storage_reader
.begin_ro_txn()?
.get_starknet_version(block_number)?
.unwrap_or(StarknetVersion::LATEST);
let versioned_constants = VersionedConstants::get(&starknet_version)?;

let block_context = BlockContext::new(
Expand Down

0 comments on commit d628fe7

Please sign in to comment.