Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
FrancoGiachetta committed Dec 10, 2024
1 parent d6f49b5 commit 72d67ec
Show file tree
Hide file tree
Showing 386 changed files with 2,549 additions and 3,060 deletions.
2 changes: 1 addition & 1 deletion crates/blockifier/bench/blockifier_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use blockifier::test_utils::transfers_generator::{
RecipientGeneratorType, TransfersGenerator, TransfersGeneratorConfig,
};
use criterion::{criterion_group, criterion_main, Criterion};
use criterion::{Criterion, criterion_group, criterion_main};

pub fn transfers_benchmark(c: &mut Criterion) {
let transfers_generator_config = TransfersGeneratorConfig {
Expand Down
4 changes: 0 additions & 4 deletions crates/blockifier/resources/versioned_constants_0_13_4.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
},
"invoke_tx_max_n_steps": 10000000,
"execute_max_sierra_gas": 1000000000,
"execute_max_sierra_gas": 1000000000,
"deprecated_l2_resource_gas_costs": {
"gas_per_data_felt": [
128,
Expand Down Expand Up @@ -42,7 +41,6 @@
"disable_cairo0_redeclaration": true,
"enable_stateful_compression": true,
"comprehensive_state_diff": true,
"comprehensive_state_diff": true,
"allocation_cost": {
"blob_cost": {
"l1_gas": 0,
Expand Down Expand Up @@ -95,7 +93,6 @@
},
"range_check_gas_cost": 70,
"keccak_builtin_gas_cost": 136189,
"keccak_builtin_gas_cost": 136189,
"pedersen_gas_cost": 4050,
"bitwise_builtin_gas_cost": 583,
"ecop_gas_cost": 4085,
Expand Down Expand Up @@ -616,7 +613,6 @@
},
"validate_max_n_steps": 1000000,
"validate_max_sierra_gas": 100000000,
"validate_max_sierra_gas": 100000000,
"min_compiler_version_for_sierra_gas": "2.8.0",
"vm_resource_fee_cost": {
"builtins": {
Expand Down
2 changes: 1 addition & 1 deletion crates/blockifier/src/abi/sierra_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use cairo_vm::vm::errors::memory_errors::MemoryError;
use cairo_vm::vm::vm_core::VirtualMachine;
use num_bigint::{BigUint, ToBigUint};
use num_traits::ToPrimitive;
use starknet_api::StarknetApiError;
use starknet_api::core::ContractAddress;
use starknet_api::state::StorageKey;
use starknet_api::StarknetApiError;
use starknet_types_core::felt::Felt;
use thiserror::Error;

Expand Down
2 changes: 1 addition & 1 deletion crates/blockifier/src/blockifier/block_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::context::ChainInfo;
use crate::state::state_api::StateReader;
use crate::test_utils::contracts::FeatureContract;
use crate::test_utils::initial_test_state::test_state;
use crate::test_utils::{CairoVersion, RunnableCairo1, BALANCE};
use crate::test_utils::{BALANCE, CairoVersion, RunnableCairo1};
use crate::versioned_constants::VersionedConstants;

#[test]
Expand Down
2 changes: 1 addition & 1 deletion crates/blockifier/src/blockifier/config.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::collections::BTreeMap;

use papyrus_config::dumping::{append_sub_config_name, ser_param, SerializeConfig};
use papyrus_config::dumping::{SerializeConfig, append_sub_config_name, ser_param};
use papyrus_config::{ParamPath, ParamPrivacyInput, SerializedParam};
use serde::{Deserialize, Serialize};

Expand Down
2 changes: 1 addition & 1 deletion crates/blockifier/src/blockifier/stateful_validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use thiserror::Error;

use crate::blockifier::config::TransactionExecutorConfig;
use crate::blockifier::transaction_executor::{
TransactionExecutor, TransactionExecutorError, BLOCK_STATE_ACCESS_ERR,
BLOCK_STATE_ACCESS_ERR, TransactionExecutor, TransactionExecutorError,
};
use crate::context::{BlockContext, TransactionContext};
use crate::execution::call_info::CallInfo;
Expand Down
9 changes: 5 additions & 4 deletions crates/blockifier/src/blockifier/stateful_validator_test.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
use assert_matches::assert_matches;
use rstest::rstest;
use starknet_api::executable_transaction::AccountTransaction as Transaction;
use starknet_api::transaction::fields::ValidResourceBounds;
use starknet_api::transaction::TransactionVersion;
use starknet_api::transaction::fields::ValidResourceBounds;

use crate::blockifier::stateful_validator::StatefulValidator;
use crate::context::BlockContext;
use crate::test_utils::contracts::FeatureContract;
use crate::test_utils::initial_test_state::{fund_account, test_state};
use crate::test_utils::{CairoVersion, RunnableCairo1, BALANCE};
use crate::test_utils::{BALANCE, CairoVersion, RunnableCairo1};
use crate::transaction::test_utils::{
block_context, create_account_tx_for_validate_test_nonce_0, default_all_resource_bounds,
default_l1_resource_bounds, FaultyAccountTxCreatorArgs, INVALID, VALID,
FaultyAccountTxCreatorArgs, INVALID, VALID, block_context,
create_account_tx_for_validate_test_nonce_0, default_all_resource_bounds,
default_l1_resource_bounds,
};
use crate::transaction::transaction_types::TransactionType;

Expand Down
2 changes: 1 addition & 1 deletion crates/blockifier/src/blockifier/transaction_executor.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::collections::{HashMap, HashSet};
use std::panic::{self, catch_unwind, AssertUnwindSafe};
use std::panic::{self, AssertUnwindSafe, catch_unwind};
use std::sync::{Arc, Mutex};

use itertools::FoldWhile::{Continue, Done};
Expand Down
23 changes: 11 additions & 12 deletions crates/blockifier/src/blockifier/transaction_executor_test.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
use assert_matches::assert_matches;
use pretty_assertions::assert_eq;
use rstest::rstest;
use starknet_api::test_utils::NonceManager;
use starknet_api::test_utils::declare::executable_declare_tx;
use starknet_api::test_utils::deploy_account::executable_deploy_account_tx;
use starknet_api::test_utils::invoke::executable_invoke_tx;
use starknet_api::test_utils::NonceManager;
use starknet_api::transaction::fields::Fee;
use starknet_api::transaction::TransactionVersion;
use starknet_api::transaction::fields::Fee;
use starknet_api::{declare_tx_args, deploy_account_tx_args, felt, invoke_tx_args, nonce};
use starknet_types_core::felt::Felt;

use crate::blockifier::config::TransactionExecutorConfig;
use crate::blockifier::transaction_executor::{
TransactionExecutor, TransactionExecutorError, BLOCK_STATE_ACCESS_ERR,
BLOCK_STATE_ACCESS_ERR, TransactionExecutor, TransactionExecutorError,
};
use crate::bouncer::{Bouncer, BouncerWeights};
use crate::context::BlockContext;
Expand All @@ -22,14 +22,14 @@ use crate::test_utils::contracts::FeatureContract;
use crate::test_utils::initial_test_state::test_state;
use crate::test_utils::l1_handler::l1handler_tx;
use crate::test_utils::{
create_calldata, maybe_dummy_block_hash_and_number, CairoVersion, RunnableCairo1, BALANCE,
DEFAULT_STRK_L1_GAS_PRICE,
BALANCE, CairoVersion, DEFAULT_STRK_L1_GAS_PRICE, RunnableCairo1, create_calldata,
maybe_dummy_block_hash_and_number,
};
use crate::transaction::account_transaction::AccountTransaction;
use crate::transaction::errors::TransactionExecutionError;
use crate::transaction::test_utils::{
block_context, calculate_class_info_for_testing, create_test_init_data, emit_n_events_tx,
l1_resource_bounds, TestInitData,
TestInitData, block_context, calculate_class_info_for_testing, create_test_init_data,
emit_n_events_tx, l1_resource_bounds,
};
use crate::transaction::transaction_execution::Transaction;
fn tx_executor_test_body<S: StateReader>(
Expand Down Expand Up @@ -205,11 +205,10 @@ fn test_invoke(
) {
let test_contract = FeatureContract::TestContract(cairo_version);
let account_contract = FeatureContract::AccountWithoutValidations(cairo_version);
let state = test_state(
&block_context.chain_info,
BALANCE,
&[(test_contract, 1), (account_contract, 1)],
);
let state = test_state(&block_context.chain_info, BALANCE, &[
(test_contract, 1),
(account_contract, 1),
]);

let calldata =
create_calldata(test_contract.get_instance_address(0), entry_point_name, &entry_point_args);
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 @@ -2,7 +2,7 @@ use std::collections::{BTreeMap, HashMap, HashSet};

use cairo_vm::types::builtin_name::BuiltinName;
use cairo_vm::vm::runners::cairo_runner::ExecutionResources;
use papyrus_config::dumping::{append_sub_config_name, ser_param, SerializeConfig};
use papyrus_config::dumping::{SerializeConfig, append_sub_config_name, ser_param};
use papyrus_config::{ParamPath, ParamPrivacyInput, SerializedParam};
use serde::{Deserialize, Serialize};
use starknet_api::core::ClassHash;
Expand Down
2 changes: 1 addition & 1 deletion crates/blockifier/src/bouncer_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use starknet_api::{class_hash, contract_address, storage_key};
use super::BouncerConfig;
use crate::blockifier::transaction_executor::TransactionExecutorError;
use crate::bouncer::{
verify_tx_weights_within_max_capacity, Bouncer, BouncerWeights, BuiltinCount,
Bouncer, BouncerWeights, BuiltinCount, verify_tx_weights_within_max_capacity,
};
use crate::context::BlockContext;
use crate::execution::call_info::ExecutionSummary;
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
Expand Up @@ -12,7 +12,7 @@ use crate::fee::fee_utils::get_sequencer_balance_keys;
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, RunnableCairo1, BALANCE};
use crate::test_utils::{BALANCE, CairoVersion, RunnableCairo1, create_trivial_calldata};
use crate::transaction::test_utils::{
block_context, default_all_resource_bounds, invoke_tx_with_default_flags,
};
Expand Down
4 changes: 2 additions & 2 deletions crates/blockifier/src/concurrency/flow_test.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use std::collections::HashMap;
use std::sync::atomic::Ordering;
use std::sync::Arc;
use std::sync::atomic::Ordering;

use rstest::rstest;
use starknet_api::{contract_address, felt, storage_key};

use crate::abi::sierra_types::{SierraType, SierraU128};
use crate::concurrency::scheduler::{Scheduler, Task, TransactionStatus};
use crate::concurrency::test_utils::{safe_versioned_state_for_testing, DEFAULT_CHUNK_SIZE};
use crate::concurrency::test_utils::{DEFAULT_CHUNK_SIZE, safe_versioned_state_for_testing};
use crate::concurrency::versioned_state::ThreadSafeVersionedState;
use crate::state::cached_state::{CachedState, ContractClassMapping, StateMaps};
use crate::state::state_api::UpdatableState;
Expand Down
2 changes: 1 addition & 1 deletion crates/blockifier/src/concurrency/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use std::cmp::min;
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
use std::sync::{Mutex, MutexGuard, TryLockError};

use crate::concurrency::utils::lock_mutex_in_array;
use crate::concurrency::TxIndex;
use crate::concurrency::utils::lock_mutex_in_array;

#[cfg(test)]
#[path = "scheduler_test.rs"]
Expand Down
4 changes: 2 additions & 2 deletions crates/blockifier/src/concurrency/scheduler_test.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use std::cmp::min;
use std::sync::atomic::Ordering;
use std::sync::Arc;
use std::sync::atomic::Ordering;

use pretty_assertions::assert_eq;
use rstest::rstest;

use crate::concurrency::TxIndex;
use crate::concurrency::scheduler::{Scheduler, Task, TransactionStatus};
use crate::concurrency::test_utils::DEFAULT_CHUNK_SIZE;
use crate::concurrency::TxIndex;
use crate::default_scheduler;

#[rstest]
Expand Down
2 changes: 1 addition & 1 deletion crates/blockifier/src/concurrency/versioned_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use starknet_api::core::{ClassHash, CompiledClassHash, ContractAddress, Nonce};
use starknet_api::state::StorageKey;
use starknet_types_core::felt::Felt;

use crate::concurrency::versioned_storage::VersionedStorage;
use crate::concurrency::TxIndex;
use crate::concurrency::versioned_storage::VersionedStorage;
use crate::execution::contract_class::RunnableCompiledClass;
use crate::state::cached_state::{ContractClassMapping, StateMaps};
use crate::state::errors::StateError;
Expand Down
50 changes: 23 additions & 27 deletions crates/blockifier/src/concurrency/versioned_state_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@ use std::thread;
use assert_matches::assert_matches;
use rstest::{fixture, rstest};
use starknet_api::abi::abi_utils::{get_fee_token_var_address, get_storage_var_address};
use starknet_api::core::{calculate_contract_address, ClassHash, ContractAddress};
use starknet_api::test_utils::deploy_account::executable_deploy_account_tx;
use starknet_api::core::{ClassHash, ContractAddress, calculate_contract_address};
use starknet_api::test_utils::NonceManager;
use starknet_api::test_utils::deploy_account::executable_deploy_account_tx;
use starknet_api::transaction::fields::{ContractAddressSalt, ValidResourceBounds};
use starknet_api::{
calldata, class_hash, compiled_class_hash, contract_address, deploy_account_tx_args, felt,
nonce, storage_key,
};

use crate::concurrency::TxIndex;
use crate::concurrency::test_utils::{
class_hash, contract_address, safe_versioned_state_for_testing,
};
use crate::concurrency::versioned_state::{
ThreadSafeVersionedState, VersionedState, VersionedStateProxy,
};
use crate::concurrency::TxIndex;
use crate::context::BlockContext;
use crate::state::cached_state::{
CachedState, ContractClassMapping, StateMaps, TransactionalState,
Expand All @@ -30,7 +30,7 @@ use crate::state::state_api::{State, StateReader, UpdatableState};
use crate::test_utils::contracts::FeatureContract;
use crate::test_utils::dict_state_reader::DictStateReader;
use crate::test_utils::initial_test_state::test_state;
use crate::test_utils::{CairoVersion, RunnableCairo1, BALANCE, DEFAULT_STRK_L1_GAS_PRICE};
use crate::test_utils::{BALANCE, CairoVersion, DEFAULT_STRK_L1_GAS_PRICE, RunnableCairo1};
use crate::transaction::account_transaction::AccountTransaction;
use crate::transaction::objects::HasRelatedFeeType;
use crate::transaction::test_utils::{default_all_resource_bounds, l1_resource_bounds};
Expand Down Expand Up @@ -91,11 +91,9 @@ fn test_versioned_state_proxy() {
StateError::UndeclaredClassHash(class_hash) if
another_class_hash == class_hash
);
assert!(!versioned_state_proxys[0]
.state()
.declared_contracts
.read(0, another_class_hash)
.unwrap());
assert!(
!versioned_state_proxys[0].state().declared_contracts.read(0, another_class_hash).unwrap()
);

// Write to the state.
let new_key = storage_key!(0x11_u8);
Expand Down Expand Up @@ -165,16 +163,12 @@ fn test_versioned_state_proxy() {
versioned_state_proxys[9].get_class_hash_at(contract_address).unwrap(),
class_hash_v7
);
assert!(!versioned_state_proxys[0]
.state()
.declared_contracts
.read(0, another_class_hash)
.unwrap());
assert!(versioned_state_proxys[4]
.state()
.declared_contracts
.read(4, another_class_hash)
.unwrap());
assert!(
!versioned_state_proxys[0].state().declared_contracts.read(0, another_class_hash).unwrap()
);
assert!(
versioned_state_proxys[4].state().declared_contracts.read(4, another_class_hash).unwrap()
);
// Include the writes in the current transaction.
assert_eq!(
versioned_state_proxys[10].get_class_hash_at(contract_address).unwrap(),
Expand Down Expand Up @@ -207,11 +201,11 @@ fn test_run_parallel_txs(default_all_resource_bounds: ValidResourceBounds) {
FeatureContract::AccountWithoutValidations(CairoVersion::Cairo0);

// Initiate States
let versioned_state = Arc::new(Mutex::new(VersionedState::new(test_state(
chain_info,
BALANCE,
&[(account_without_validation, 1), (grindy_account, 1)],
))));
let versioned_state =
Arc::new(Mutex::new(VersionedState::new(test_state(chain_info, BALANCE, &[
(account_without_validation, 1),
(grindy_account, 1),
]))));

let safe_versioned_state = ThreadSafeVersionedState(Arc::clone(&versioned_state));
let mut versioned_state_proxy_1 = safe_versioned_state.pin_version(1);
Expand Down Expand Up @@ -324,9 +318,11 @@ fn test_validate_reads(

assert_eq!(transactional_state.cache.borrow().initial_reads.declared_contracts.len(), 1);

assert!(safe_versioned_state
.pin_version(1)
.validate_reads(&transactional_state.cache.borrow().initial_reads));
assert!(
safe_versioned_state
.pin_version(1)
.validate_reads(&transactional_state.cache.borrow().initial_reads)
);
}

#[rstest]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use pretty_assertions::assert_eq;
use rstest::rstest;
use starknet_api::core::{ClassHash, ContractAddress};

use crate::concurrency::TxIndex;
use crate::concurrency::test_utils::{class_hash, contract_address};
use crate::concurrency::versioned_storage::VersionedStorage;
use crate::concurrency::TxIndex;

// TODO(barak, 01/07/2024): Split into test_read() and test_write().
#[test]
Expand Down
2 changes: 1 addition & 1 deletion crates/blockifier/src/concurrency/worker_logic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ use starknet_api::core::ClassHash;
use super::versioned_state::VersionedState;
use crate::blockifier::transaction_executor::TransactionExecutorError;
use crate::bouncer::Bouncer;
use crate::concurrency::TxIndex;
use crate::concurrency::fee_utils::complete_fee_transfer_flow;
use crate::concurrency::scheduler::{Scheduler, Task};
use crate::concurrency::utils::lock_mutex_in_array;
use crate::concurrency::versioned_state::ThreadSafeVersionedState;
use crate::concurrency::TxIndex;
use crate::context::BlockContext;
use crate::state::cached_state::{ContractClassMapping, StateMaps, TransactionalState};
use crate::state::state_api::{StateReader, UpdatableState};
Expand Down
8 changes: 4 additions & 4 deletions crates/blockifier/src/concurrency/worker_logic_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ use std::sync::Mutex;
use rstest::rstest;
use starknet_api::abi::abi_utils::get_fee_token_var_address;
use starknet_api::core::{ContractAddress, Nonce};
use starknet_api::test_utils::declare::executable_declare_tx;
use starknet_api::test_utils::NonceManager;
use starknet_api::test_utils::declare::executable_declare_tx;
use starknet_api::transaction::TransactionVersion;
use starknet_api::transaction::constants::DEPLOY_CONTRACT_FUNCTION_ENTRY_POINT_NAME;
use starknet_api::transaction::fields::{ContractAddressSalt, Fee, ValidResourceBounds};
use starknet_api::transaction::TransactionVersion;
use starknet_api::{contract_address, declare_tx_args, felt, invoke_tx_args, nonce, storage_key};
use starknet_types_core::felt::Felt;

Expand All @@ -26,8 +26,8 @@ use crate::state::state_api::StateReader;
use crate::test_utils::contracts::FeatureContract;
use crate::test_utils::initial_test_state::test_state;
use crate::test_utils::{
create_calldata, create_trivial_calldata, CairoVersion, RunnableCairo1, BALANCE,
TEST_ERC20_CONTRACT_ADDRESS2,
BALANCE, CairoVersion, RunnableCairo1, TEST_ERC20_CONTRACT_ADDRESS2, create_calldata,
create_trivial_calldata,
};
use crate::transaction::account_transaction::AccountTransaction;
use crate::transaction::objects::HasRelatedFeeType;
Expand Down
Loading

0 comments on commit 72d67ec

Please sign in to comment.