Skip to content

Commit

Permalink
chore(blockifier): remove concurrency feature (#1262)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yoni-Starkware authored Oct 9, 2024
1 parent 53624e6 commit 25949ac
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 48 deletions.
1 change: 0 additions & 1 deletion crates/blockifier/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ description = "The transaction-executing component in the Starknet sequencer."
workspace = true

[features]
concurrency = []
jemalloc = ["dep:tikv-jemallocator"]
testing = ["rand", "rstest", "starknet_api/testing"]
transaction_serde = []
Expand Down
18 changes: 7 additions & 11 deletions crates/blockifier/src/blockifier/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ pub struct TransactionExecutorConfig {
}
impl TransactionExecutorConfig {
#[cfg(any(test, feature = "testing"))]
pub fn create_for_testing() -> Self {
Self { concurrency_config: ConcurrencyConfig::create_for_testing() }
pub fn create_for_testing(concurrency_enabled: bool) -> Self {
Self { concurrency_config: ConcurrencyConfig::create_for_testing(concurrency_enabled) }
}
}

Expand All @@ -15,16 +15,12 @@ pub struct ConcurrencyConfig {
pub n_workers: usize,
pub chunk_size: usize,
}
#[cfg(all(any(test, feature = "testing"), not(feature = "concurrency")))]
impl ConcurrencyConfig {
pub fn create_for_testing() -> Self {
Self { enabled: false, n_workers: 0, chunk_size: 0 }
}
}

#[cfg(all(any(test, feature = "testing"), feature = "concurrency"))]
impl ConcurrencyConfig {
pub fn create_for_testing() -> Self {
Self { enabled: true, n_workers: 4, chunk_size: 64 }
pub fn create_for_testing(concurrency_enabled: bool) -> Self {
if concurrency_enabled {
return Self { enabled: true, n_workers: 4, chunk_size: 64 };
}
Self { enabled: false, n_workers: 0, chunk_size: 0 }
}
}
17 changes: 1 addition & 16 deletions crates/blockifier/src/blockifier/transaction_executor.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
#[cfg(feature = "concurrency")]
use std::collections::{HashMap, HashSet};
#[cfg(feature = "concurrency")]
use std::panic::{self, catch_unwind, AssertUnwindSafe};
#[cfg(feature = "concurrency")]
use std::sync::Arc;
#[cfg(feature = "concurrency")]
use std::sync::Mutex;
use std::sync::{Arc, Mutex};

use itertools::FoldWhile::{Continue, Done};
use itertools::Itertools;
Expand All @@ -15,7 +10,6 @@ use thiserror::Error;
use crate::blockifier::block::{pre_process_block, BlockNumberHashPair};
use crate::blockifier::config::TransactionExecutorConfig;
use crate::bouncer::{Bouncer, BouncerWeights};
#[cfg(feature = "concurrency")]
use crate::concurrency::worker_logic::WorkerExecutor;
use crate::context::BlockContext;
use crate::state::cached_state::{CachedState, CommitmentStateDiff, TransactionalState};
Expand Down Expand Up @@ -144,14 +138,6 @@ impl<S: StateReader> TransactionExecutor<S> {
results
}

#[cfg(not(feature = "concurrency"))]
pub fn execute_chunk(
&mut self,
_chunk: &[Transaction],
) -> Vec<TransactionExecutorResult<TransactionExecutionInfo>> {
unimplemented!()
}

/// Returns the state diff, a list of contract class hash with the corresponding list of
/// visited segment values and the block weights.
pub fn finalize(
Expand Down Expand Up @@ -229,7 +215,6 @@ impl<S: StateReader + Send + Sync> TransactionExecutor<S> {
}
}

#[cfg(feature = "concurrency")]
pub fn execute_chunk(
&mut self,
chunk: &[Transaction],
Expand Down
4 changes: 2 additions & 2 deletions crates/blockifier/src/blockifier/transaction_executor_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,8 @@ fn test_bouncing(#[case] initial_bouncer_weights: BouncerWeights, #[case] n_even
}

#[rstest]
fn test_execute_txs_bouncing() {
let config = TransactionExecutorConfig::create_for_testing();
fn test_execute_txs_bouncing(#[values(true, false)] concurrency_enabled: bool) {
let config = TransactionExecutorConfig::create_for_testing(concurrency_enabled);
let max_n_events_in_block = 10;
let block_context = BlockContext::create_for_bouncer_testing(max_n_events_in_block);

Expand Down
10 changes: 8 additions & 2 deletions crates/blockifier/src/blockifier/transfers_flow_test.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
use rstest::rstest;

use crate::blockifier::config::ConcurrencyConfig;
use crate::test_utils::transfers_generator::{
RecipientGeneratorType,
TransfersGenerator,
TransfersGeneratorConfig,
};

#[test]
pub fn transfers_flow_test() {
#[rstest]
#[case::concurrency_enabled(ConcurrencyConfig{enabled: true, n_workers: 4, chunk_size: 100})]
#[case::concurrency_disabled(ConcurrencyConfig{enabled: false, n_workers: 0, chunk_size: 0})]
pub fn transfers_flow_test(#[case] concurrency_config: ConcurrencyConfig) {
let transfers_generator_config = TransfersGeneratorConfig {
recipient_generator_type: RecipientGeneratorType::DisjointFromSenders,
concurrency_config,
..Default::default()
};
assert!(
Expand Down
1 change: 0 additions & 1 deletion crates/blockifier/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
pub mod abi;
pub mod blockifier;
pub mod bouncer;
#[cfg(feature = "concurrency")]
pub mod concurrency;
pub mod context;
pub mod execution;
Expand Down
3 changes: 1 addition & 2 deletions crates/blockifier/src/state/cached_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,7 @@ impl From<StorageView> for IndexMap<ContractAddress, IndexMap<StorageKey, Felt>>
}
}

#[cfg_attr(any(feature = "testing", test), derive(Clone))]
#[derive(Debug, Default, PartialEq, Eq)]
#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub struct StateMaps {
pub nonces: HashMap<ContractAddress, Nonce>,
pub class_hashes: HashMap<ContractAddress, ClassHash>,
Expand Down
12 changes: 1 addition & 11 deletions crates/blockifier/src/test_utils/transfers_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@ const RANDOMIZATION_SEED: u64 = 0;
const CAIRO_VERSION: CairoVersion = CairoVersion::Cairo0;
const TRANSACTION_VERSION: TransactionVersion = TransactionVersion(Felt::THREE);
const RECIPIENT_GENERATOR_TYPE: RecipientGeneratorType = RecipientGeneratorType::RoundRobin;
#[cfg(feature = "concurrency")]
const CONCURRENCY_MODE: bool = true;
#[cfg(not(feature = "concurrency"))]
const CONCURRENCY_MODE: bool = false;
const N_WORKERS: usize = 4;
const CHUNK_SIZE: usize = 100;

pub struct TransfersGeneratorConfig {
pub n_accounts: u16,
Expand All @@ -55,11 +49,7 @@ impl Default for TransfersGeneratorConfig {
cairo_version: CAIRO_VERSION,
tx_version: TRANSACTION_VERSION,
recipient_generator_type: RECIPIENT_GENERATOR_TYPE,
concurrency_config: ConcurrencyConfig {
enabled: CONCURRENCY_MODE,
n_workers: N_WORKERS,
chunk_size: CHUNK_SIZE,
},
concurrency_config: ConcurrencyConfig::default(),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/native_blockifier/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ crate-type = ["cdylib"]

[dependencies]
# TODO(Dori, 1/1/2025): Add the "jemalloc" feature to the blockifier crate when possible.
blockifier = { workspace = true, features = ["concurrency", "testing"] }
blockifier = { workspace = true, features = ["testing"] }
cairo-lang-starknet-classes.workspace = true
cairo-vm.workspace = true
indexmap.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion crates/native_blockifier/src/py_block_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ impl PyBlockExecutor {
use blockifier::state::global_cache::GLOBAL_CONTRACT_CACHE_SIZE_FOR_TEST;
Self {
bouncer_config: BouncerConfig::max(),
tx_executor_config: TransactionExecutorConfig::create_for_testing(),
tx_executor_config: TransactionExecutorConfig::create_for_testing(true),
storage: Box::new(storage),
chain_info: ChainInfo::default(),
versioned_constants: VersionedConstants::latest_constants().clone(),
Expand Down

0 comments on commit 25949ac

Please sign in to comment.