Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
FrancoGiachetta committed Nov 28, 2024
2 parents 7e7f34e + 6f268c8 commit fdf3e39
Show file tree
Hide file tree
Showing 146 changed files with 1,832 additions and 1,291 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/blockifier_reexecution_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ jobs:
# Run blockifier re-execution tests.
- run: cargo test --release -p blockifier_reexecution -- --include-ignored
# Compile the rpc-tests, without running them.
- run: cargo test -p blockifier_reexecution --features blockifier_regression_https_testing --no-run
- run: cargo test --release -p blockifier_reexecution --features blockifier_regression_https_testing --no-run
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 50 additions & 0 deletions config/sequencer/default_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,56 @@
"privacy": "Public",
"value": "0.0.0.0:8080"
},
"components.state_sync.execution_mode": {
"description": "The component execution mode.",
"privacy": "Public",
"value": "LocalExecutionWithRemoteDisabled"
},
"components.state_sync.local_server_config.#is_none": {
"description": "Flag for an optional field.",
"privacy": "TemporaryValue",
"value": false
},
"components.state_sync.local_server_config.channel_buffer_size": {
"description": "The communication channel buffer size.",
"privacy": "Public",
"value": 32
},
"components.state_sync.remote_client_config.#is_none": {
"description": "Flag for an optional field.",
"privacy": "TemporaryValue",
"value": true
},
"components.state_sync.remote_client_config.idle_connections": {
"description": "The maximum number of idle connections to keep alive.",
"privacy": "Public",
"value": 18446744073709551615
},
"components.state_sync.remote_client_config.idle_timeout": {
"description": "The duration in seconds to keep an idle connection open before closing.",
"privacy": "Public",
"value": 90
},
"components.state_sync.remote_client_config.retries": {
"description": "The max number of retries for sending a message.",
"privacy": "Public",
"value": 3
},
"components.state_sync.remote_client_config.socket": {
"description": "The remote component server socket.",
"privacy": "Public",
"value": "0.0.0.0:8080"
},
"components.state_sync.remote_server_config.#is_none": {
"description": "Flag for an optional field.",
"privacy": "TemporaryValue",
"value": true
},
"components.state_sync.remote_server_config.socket": {
"description": "The remote component server socket.",
"privacy": "Public",
"value": "0.0.0.0:8080"
},
"consensus_manager_config.consensus_config.consensus_delay": {
"description": "Delay (seconds) before starting consensus to give time for network peering.",
"privacy": "Public",
Expand Down
3 changes: 2 additions & 1 deletion crates/blockifier/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ description = "The transaction-executing component in the Starknet sequencer."
workspace = true

[features]
cairo_native = ["dep:cairo-native"]
cairo_native = ["dep:cairo-native", "starknet_sierra_compile/cairo_native"]
jemalloc = ["dep:tikv-jemallocator"]
reexecution = ["transaction_serde"]
testing = ["rand", "rstest", "starknet_api/testing"]
Expand Down Expand Up @@ -50,6 +50,7 @@ serde_json = { workspace = true, features = ["arbitrary_precision"] }
sha2.workspace = true
starknet-types-core.workspace = true
starknet_api.workspace = true
starknet_sierra_compile = { workspace = true, optional = true }
strum.workspace = true
strum_macros.workspace = true
tempfile.workspace = true
Expand Down
123 changes: 45 additions & 78 deletions crates/blockifier/src/blockifier/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ use log::warn;
use starknet_api::block::{
BlockHashAndNumber,
BlockNumber,
BlockTimestamp,
GasPrice,
GasPriceVector,
GasPrices,
NonzeroGasPrice,
};
use starknet_api::core::ContractAddress;
Expand All @@ -13,93 +13,60 @@ use starknet_api::state::StorageKey;
use crate::abi::constants;
use crate::state::errors::StateError;
use crate::state::state_api::{State, StateResult};
use crate::transaction::objects::FeeType;
use crate::versioned_constants::VersionedConstants;

#[cfg(test)]
#[path = "block_test.rs"]
pub mod block_test;

#[cfg_attr(feature = "transaction_serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug)]
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,
}

#[cfg_attr(feature = "transaction_serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug)]
pub struct GasPrices {
eth_gas_prices: GasPriceVector, // In wei.
strk_gas_prices: GasPriceVector, // In fri.
}

impl GasPrices {
pub fn new(
eth_l1_gas_price: NonzeroGasPrice,
strk_l1_gas_price: NonzeroGasPrice,
eth_l1_data_gas_price: NonzeroGasPrice,
strk_l1_data_gas_price: NonzeroGasPrice,
eth_l2_gas_price: NonzeroGasPrice,
strk_l2_gas_price: NonzeroGasPrice,
) -> Self {
// TODO(Aner): fix backwards compatibility.
let expected_eth_l2_gas_price = VersionedConstants::latest_constants()
.convert_l1_to_l2_gas_price_round_up(eth_l1_gas_price.into());
if GasPrice::from(eth_l2_gas_price) != expected_eth_l2_gas_price {
// TODO!(Aner): change to panic! Requires fixing several tests.
warn!(
"eth_l2_gas_price {eth_l2_gas_price} does not match expected eth_l2_gas_price \
{expected_eth_l2_gas_price}."
)
}
let expected_strk_l2_gas_price = VersionedConstants::latest_constants()
.convert_l1_to_l2_gas_price_round_up(strk_l1_gas_price.into());
if GasPrice::from(strk_l2_gas_price) != expected_strk_l2_gas_price {
// TODO!(Aner): change to panic! Requires fixing test_discounted_gas_overdraft
warn!(
"strk_l2_gas_price {strk_l2_gas_price} does not match expected strk_l2_gas_price \
{expected_strk_l2_gas_price}."
)
}

Self {
eth_gas_prices: GasPriceVector {
l1_gas_price: eth_l1_gas_price,
l1_data_gas_price: eth_l1_data_gas_price,
l2_gas_price: eth_l2_gas_price,
},
strk_gas_prices: GasPriceVector {
l1_gas_price: strk_l1_gas_price,
l1_data_gas_price: strk_l1_data_gas_price,
l2_gas_price: strk_l2_gas_price,
},
}
/// 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.
let eth_l2_gas_price = gas_prices.eth_gas_prices.l2_gas_price;
let expected_eth_l2_gas_price = VersionedConstants::latest_constants()
.convert_l1_to_l2_gas_price_round_up(gas_prices.eth_gas_prices.l1_gas_price.into());
if GasPrice::from(eth_l2_gas_price) != expected_eth_l2_gas_price {
// TODO!(Aner): change to panic! Requires fixing several tests.
warn!(
"eth_l2_gas_price {} does not match expected eth_l2_gas_price {}.",
eth_l2_gas_price, expected_eth_l2_gas_price
)
}

pub fn get_l1_gas_price_by_fee_type(&self, fee_type: &FeeType) -> NonzeroGasPrice {
self.get_gas_prices_by_fee_type(fee_type).l1_gas_price
}

pub fn get_l1_data_gas_price_by_fee_type(&self, fee_type: &FeeType) -> NonzeroGasPrice {
self.get_gas_prices_by_fee_type(fee_type).l1_data_gas_price
let strk_l2_gas_price = gas_prices.strk_gas_prices.l2_gas_price;
let expected_strk_l2_gas_price = VersionedConstants::latest_constants()
.convert_l1_to_l2_gas_price_round_up(gas_prices.strk_gas_prices.l1_gas_price.into());
if GasPrice::from(strk_l2_gas_price) != expected_strk_l2_gas_price {
// TODO!(Aner): change to panic! Requires fixing test_discounted_gas_overdraft
warn!(
"strk_l2_gas_price {} does not match expected strk_l2_gas_price {}.",
strk_l2_gas_price, expected_strk_l2_gas_price
)
}
}

pub fn get_l2_gas_price_by_fee_type(&self, fee_type: &FeeType) -> NonzeroGasPrice {
self.get_gas_prices_by_fee_type(fee_type).l2_gas_price
}
pub fn validated_gas_prices(
eth_l1_gas_price: NonzeroGasPrice,
strk_l1_gas_price: NonzeroGasPrice,
eth_l1_data_gas_price: NonzeroGasPrice,
strk_l1_data_gas_price: NonzeroGasPrice,
eth_l2_gas_price: NonzeroGasPrice,
strk_l2_gas_price: NonzeroGasPrice,
) -> GasPrices {
let gas_prices = GasPrices {
eth_gas_prices: GasPriceVector {
l1_gas_price: eth_l1_gas_price,
l1_data_gas_price: eth_l1_data_gas_price,
l2_gas_price: eth_l2_gas_price,
},
strk_gas_prices: GasPriceVector {
l1_gas_price: strk_l1_gas_price,
l1_data_gas_price: strk_l1_data_gas_price,
l2_gas_price: strk_l2_gas_price,
},
};
validate_l2_gas_price(&gas_prices);

pub fn get_gas_prices_by_fee_type(&self, fee_type: &FeeType) -> &GasPriceVector {
match fee_type {
FeeType::Strk => &self.strk_gas_prices,
FeeType::Eth => &self.eth_gas_prices,
}
}
gas_prices
}

// Block pre-processing.
Expand Down
44 changes: 44 additions & 0 deletions crates/blockifier/src/blockifier/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use papyrus_config::dumping::{append_sub_config_name, ser_param, SerializeConfig
use papyrus_config::{ParamPath, ParamPrivacyInput, SerializedParam};
use serde::{Deserialize, Serialize};

use crate::state::global_cache::GLOBAL_CONTRACT_CACHE_SIZE_FOR_TEST;

#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
pub struct TransactionExecutorConfig {
pub concurrency_config: ConcurrencyConfig,
Expand Down Expand Up @@ -61,3 +63,45 @@ impl SerializeConfig for ConcurrencyConfig {
])
}
}

#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct ContractClassManagerConfig {
pub run_cairo_native: bool,
pub wait_on_native_compilation: bool,
pub contract_cache_size: usize,
}

impl Default for ContractClassManagerConfig {
fn default() -> Self {
Self {
run_cairo_native: false,
wait_on_native_compilation: false,
contract_cache_size: GLOBAL_CONTRACT_CACHE_SIZE_FOR_TEST,
}
}
}

impl SerializeConfig for ContractClassManagerConfig {
fn dump(&self) -> BTreeMap<ParamPath, SerializedParam> {
BTreeMap::from_iter([
ser_param(
"run_cairo_native",
&self.run_cairo_native,
"Enables Cairo native execution.",
ParamPrivacyInput::Public,
),
ser_param(
"wait_on_native_compilation",
&self.wait_on_native_compilation,
"Block Sequencer main program while compiling sierra, for testing.",
ParamPrivacyInput::Public,
),
ser_param(
"contract_cache_size",
&self.contract_cache_size,
"The size of the global contract cache.",
ParamPrivacyInput::Public,
),
])
}
}
2 changes: 1 addition & 1 deletion crates/blockifier/src/blockifier/transaction_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ impl<S: StateReader> TransactionExecutor<S> {
.block_state
.as_ref()
.expect(BLOCK_STATE_ACCESS_ERR)
.get_compiled_contract_class(*class_hash)?;
.get_compiled_class(*class_hash)?;
Ok((*class_hash, contract_class.get_visited_segments(class_visited_pcs)?))
})
.collect::<TransactionExecutorResult<_>>()?;
Expand Down
2 changes: 1 addition & 1 deletion crates/blockifier/src/bouncer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ pub fn get_casm_hash_calculation_resources<S: StateReader>(
let mut casm_hash_computation_resources = ExecutionResources::default();

for class_hash in executed_class_hashes {
let class = state_reader.get_compiled_contract_class(*class_hash)?;
let class = state_reader.get_compiled_class(*class_hash)?;
casm_hash_computation_resources += &class.estimate_casm_hash_computation_resources();
}

Expand Down
2 changes: 1 addition & 1 deletion crates/blockifier/src/concurrency/fee_utils_test.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use num_bigint::BigUint;
use rstest::rstest;
use starknet_api::block::FeeType;
use starknet_api::transaction::fields::{Fee, ValidResourceBounds};
use starknet_api::{felt, invoke_tx_args};
use starknet_types_core::felt::Felt;
Expand All @@ -12,7 +13,6 @@ use crate::state::state_api::StateReader;
use crate::test_utils::contracts::FeatureContract;
use crate::test_utils::initial_test_state::{fund_account, test_state, test_state_inner};
use crate::test_utils::{create_trivial_calldata, CairoVersion, BALANCE};
use crate::transaction::objects::FeeType;
use crate::transaction::test_utils::{
account_invoke_tx,
block_context,
Expand Down
11 changes: 4 additions & 7 deletions crates/blockifier/src/concurrency/versioned_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use starknet_types_core::felt::Felt;

use crate::concurrency::versioned_storage::VersionedStorage;
use crate::concurrency::TxIndex;
use crate::execution::contract_class::RunnableContractClass;
use crate::execution::contract_class::RunnableCompiledClass;
use crate::state::cached_state::{ContractClassMapping, StateMaps};
use crate::state::errors::StateError;
use crate::state::state_api::{StateReader, StateResult, UpdatableState};
Expand All @@ -34,7 +34,7 @@ pub struct VersionedState<S: StateReader> {
// the compiled contract classes mapping. Each key with value false, sohuld not apprear
// in the compiled contract classes mapping.
declared_contracts: VersionedStorage<ClassHash, bool>,
compiled_contract_classes: VersionedStorage<ClassHash, RunnableContractClass>,
compiled_contract_classes: VersionedStorage<ClassHash, RunnableCompiledClass>,
}

impl<S: StateReader> VersionedState<S> {
Expand Down Expand Up @@ -336,14 +336,11 @@ impl<S: StateReader> StateReader for VersionedStateProxy<S> {
}
}

fn get_compiled_contract_class(
&self,
class_hash: ClassHash,
) -> StateResult<RunnableContractClass> {
fn get_compiled_class(&self, class_hash: ClassHash) -> StateResult<RunnableCompiledClass> {
let mut state = self.state();
match state.compiled_contract_classes.read(self.tx_index, class_hash) {
Some(value) => Ok(value),
None => match state.initial_state.get_compiled_contract_class(class_hash) {
None => match state.initial_state.get_compiled_class(class_hash) {
Ok(initial_value) => {
state.declared_contracts.set_initial_value(class_hash, true);
state
Expand Down
Loading

0 comments on commit fdf3e39

Please sign in to comment.