Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: sync repos #6

Merged
merged 1 commit into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
562 changes: 465 additions & 97 deletions Cargo.lock

Large diffs are not rendered by default.

26 changes: 17 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ members = [
"crates/mempool",
"crates/mempool_infra",
"crates/mempool_node",
"crates/mempool_test_utils",
"crates/mempool_types",
"crates/native_blockifier",
"crates/papyrus_base_layer",
"crates/papyrus_common",
"crates/papyrus_config",
Expand All @@ -19,12 +22,18 @@ members = [
"crates/papyrus_node",
"crates/papyrus_p2p_sync",
"crates/papyrus_proc_macros",
"crates/papyrus_protobuf",
"crates/papyrus_rpc",
"crates/papyrus_storage",
"crates/papyrus_sync",
"crates/papyrus_test_utils",
"crates/sequencing/papyrus_block_builder",
"crates/sequencing/papyrus_consensus",
"crates/starknet_api",
"crates/starknet_client",
"crates/starknet-api",
"crates/test_utils",
"crates/starknet_sierra_compile",
"crates/task_executor",
"crates/tests-integration",
]

[workspace.package]
Expand All @@ -46,6 +55,7 @@ cached = "0.44.0"
cairo-felt = "0.9.1"
cairo-lang-casm = "2.6.0"
cairo-lang-runner = "2.6.0"
cairo-lang-sierra = "2.6.0"
cairo-lang-starknet-classes = "2.6.0"
cairo-lang-utils = "2.6.0"
cairo-vm = "0.9.2"
Expand All @@ -71,7 +81,6 @@ tempfile = "3.7.0"
thiserror = "1.0.37"
clap = "4.3.10"
const_format = "0.2.30"
papyrus_config = "0.3.0"
pretty_assertions = "1.4.0"
tower = "0.4.13"
url = "2.5.0"
Expand All @@ -81,7 +90,6 @@ assert-json-diff = "2.0.2"
async-stream = "0.3.3"
base64 = "0.13.0"
bitvec = "1.0.1"
blockifier = "0.7.0-dev.1"
bytes = "1"
byteorder = "1.4.3"
camelpaste = "0.1.0"
Expand Down Expand Up @@ -119,8 +127,8 @@ os_info = "3.6.0"
page_size = "0.6.0"
# fixating the version of parity-scale-codec and parity-scale-codec-derive due to an error in udeps.
# TODO: Remove this once udeps is fixed.
parity-scale-codec = "=3.6.5"
parity-scale-codec-derive = "=3.6.5"
parity-scale-codec = "=3.6.9"
parity-scale-codec-derive = "=3.6.9"
paste = "1.0.9"
primitive-types = "0.12.1"
prometheus-parse = "0.2.4"
Expand All @@ -130,7 +138,7 @@ prost-types = "0.12.1"
rand = "0.8.5"
rand_chacha = "0.3.1"
replace_with = "0.1.7"
reqwest = "0.11"
reqwest = { version = "0.11", features = ["blocking", "json"] }
rustc-hex = "2.1.0"
schemars = "0.8.12"
serde_repr = "0.1"
Expand All @@ -144,14 +152,14 @@ strum = "0.25.0"
strum_macros = "0.25.2"
test-case = "3.2.1"
test-log = "0.2.14"
tokio = "1.18.2"
tokio = { version = "1.37.0", features = ["full"] }
tokio-retry = "0.3"
tokio-stream = "0.1.8"
tokio-test = "0.4.4"
tracing = "0.1.37"
tracing-subscriber = "0.3.16"
unsigned-varint = "0.8.0"
void = "1.0.2"
starknet_api = "0.12.0-dev.1"

[workspace.lints.rust]
warnings = "deny"
Expand Down
1 change: 0 additions & 1 deletion _blockifier_old
Submodule _blockifier_old deleted from 605118
1 change: 0 additions & 1 deletion _mempool_old
Submodule _mempool_old deleted from cfe3fd
1 change: 0 additions & 1 deletion _papyrus_old
Submodule _papyrus_old deleted from d224d5
82 changes: 82 additions & 0 deletions config/mempool_default_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
{
"components.gateway_component.execute": {
"description": "The component execution flag.",
"privacy": "Public",
"value": true
},
"components.mempool_component.execute": {
"description": "The component execution flag.",
"privacy": "Public",
"value": true
},
"gateway_config.network_config.ip": {
"description": "The gateway server ip.",
"privacy": "Public",
"value": "0.0.0.0"
},
"gateway_config.network_config.port": {
"description": "The gateway server port.",
"privacy": "Public",
"value": 8080
},
"gateway_config.stateful_tx_validator_config.chain_info.chain_id": {
"description": "The chain ID of the StarkNet chain.",
"privacy": "Public",
"value": "0x0"
},
"gateway_config.stateful_tx_validator_config.chain_info.eth_fee_token_address": {
"description": "Address of the ETH fee token.",
"privacy": "Public",
"value": "0x0"
},
"gateway_config.stateful_tx_validator_config.chain_info.strk_fee_token_address": {
"description": "Address of the STRK fee token.",
"privacy": "Public",
"value": "0x0"
},
"gateway_config.stateful_tx_validator_config.max_nonce_for_validation_skip": {
"description": "The maximum nonce for which the validation is skipped.",
"privacy": "Public",
"value": "0x0"
},
"gateway_config.stateful_tx_validator_config.max_recursion_depth": {
"description": "The maximum recursion depth allowed in a transaction.",
"privacy": "Public",
"value": 0
},
"gateway_config.stateful_tx_validator_config.validate_max_n_steps": {
"description": "The maximum number of steps the validation function is allowed to take.",
"privacy": "Public",
"value": 0
},
"gateway_config.stateless_tx_validator_config.max_calldata_length": {
"description": "Validates that a transaction has signature length less than or equal to this value.",
"privacy": "Public",
"value": 0
},
"gateway_config.stateless_tx_validator_config.max_signature_length": {
"description": "Validates that a transaction has calldata length less than or equal to this value.",
"privacy": "Public",
"value": 0
},
"gateway_config.stateless_tx_validator_config.validate_non_zero_l1_gas_fee": {
"description": "If true, validates that a transaction has non-zero L1 resource bounds.",
"privacy": "Public",
"value": false
},
"gateway_config.stateless_tx_validator_config.validate_non_zero_l2_gas_fee": {
"description": "If true, validates that a transaction has non-zero L2 resource bounds.",
"privacy": "Public",
"value": false
},
"rpc_state_reader_config.json_rpc_version": {
"description": "The json rpc version.",
"privacy": "Public",
"value": ""
},
"rpc_state_reader_config.url": {
"description": "The url of the rpc server.",
"privacy": "Public",
"value": ""
}
}
1 change: 0 additions & 1 deletion crates/blockifier/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true, features = ["arbitrary_precision"] }
sha3.workspace = true
starknet-crypto.workspace = true
# TODO: bump to use latest version.
starknet_api = { version = "0.12.0-dev.0", features = ["testing"] }
strum.workspace = true
strum_macros.workspace = true
Expand Down
94 changes: 58 additions & 36 deletions crates/blockifier/bench/blockifier_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,19 @@
//! Run the benchmarks using `cargo bench --bench blockifier_bench`.

use blockifier::abi::abi_utils::selector_from_name;
use blockifier::context::BlockContext;
use blockifier::blockifier::config::TransactionExecutorConfig;
use blockifier::blockifier::transaction_executor::TransactionExecutor;
use blockifier::bouncer::BouncerConfig;
use blockifier::context::{BlockContext, ChainInfo};
use blockifier::invoke_tx_args;
use blockifier::state::cached_state::CachedState;
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::invoke::invoke_tx;
use blockifier::test_utils::{CairoVersion, NonceManager, BALANCE, MAX_FEE};
use blockifier::transaction::account_transaction::AccountTransaction;
use blockifier::transaction::transactions::ExecutableTransaction;
use blockifier::transaction::constants::TRANSFER_ENTRY_POINT_NAME;
use blockifier::transaction::transaction_execution::Transaction;
use criterion::{criterion_group, criterion_main, Criterion};
use rand::{Rng, SeedableRng};
use starknet_api::core::ContractAddress;
Expand All @@ -26,63 +29,85 @@ use starknet_api::transaction::{Calldata, Fee, TransactionVersion};
use starknet_api::{calldata, stark_felt};

const N_ACCOUNTS: u16 = 10000;
const CHUNK_SIZE: usize = 10;
const RANDOMIZATION_SEED: u64 = 0;
const CHARGE_FEE: bool = false;
const RUN_VALIDATION: bool = false;
const TRANSACTION_VERSION: TransactionVersion = TransactionVersion(StarkFelt::ONE);

pub fn transfers_benchmark(c: &mut Criterion) {
let account_contract = FeatureContract::AccountWithLongValidate(CairoVersion::Cairo0);
let block_context = &BlockContext::create_for_account_testing();
let mut state =
test_state(block_context.chain_info(), BALANCE * 1000, &[(account_contract, N_ACCOUNTS)]);
let account_contract = FeatureContract::AccountWithoutValidations(CairoVersion::Cairo0);
let block_context = BlockContext::create_for_account_testing();
let chain_info = &block_context.chain_info().clone();
let state = test_state(chain_info, BALANCE * 1000, &[(account_contract, N_ACCOUNTS)]);
// TODO(Avi, 20/05/2024): Enable concurrency.
let executor_config = TransactionExecutorConfig::default();
let executor =
&mut TransactionExecutor::new(state, block_context, BouncerConfig::max(), executor_config);
let accounts = (0..N_ACCOUNTS)
.map(|instance_id| account_contract.get_instance_address(instance_id))
.collect::<Vec<_>>();
let nonce_manager = &mut NonceManager::default();

let mut sender_account = 0;
let mut first_sender_index = 0;
let mut random_generator = rand::rngs::StdRng::seed_from_u64(RANDOMIZATION_SEED);
let mut recipient_account = random_generator.gen::<usize>() % accounts.len();
// Create a benchmark group called "transfers", which iterates over the accounts round-robin
// and performs transfers.
c.bench_function("transfers", |benchmark| {
benchmark.iter(|| {
do_transfer(
sender_account,
recipient_account,
execute_chunk_of_transfers(
first_sender_index,
&mut random_generator,
&accounts,
nonce_manager,
block_context,
&mut state,
chain_info,
executor,
);
sender_account = (sender_account + 1) % accounts.len();
recipient_account = random_generator.gen::<usize>() % accounts.len();
first_sender_index = (first_sender_index + CHUNK_SIZE) % accounts.len();
})
});
}

fn do_transfer(
sender_account: usize,
recipient_account: usize,
fn execute_chunk_of_transfers(
first_sender_index: usize,
random_generator: &mut rand::rngs::StdRng,
accounts: &[ContractAddress],
nonce_manager: &mut NonceManager,
block_context: &BlockContext,
state: &mut CachedState<DictStateReader>,
chain_info: &ChainInfo,
executor: &mut TransactionExecutor<DictStateReader>,
) {
let sender_address = accounts[sender_account];
let recipient_account_address = accounts[recipient_account];
let mut chunk: Vec<Transaction> = Vec::with_capacity(CHUNK_SIZE);
let mut sender_index = first_sender_index;
for _ in 0..CHUNK_SIZE {
let recipient_index = random_generator.gen::<usize>() % accounts.len();
let account_tx =
generate_transfer(accounts, sender_index, recipient_index, nonce_manager, chain_info);
chunk.push(Transaction::AccountTransaction(account_tx));
sender_index = (sender_index + 1) % accounts.len();
}
let results = executor.execute_txs(&chunk, CHARGE_FEE);
assert_eq!(results.len(), CHUNK_SIZE);
for result in results {
assert!(!result.unwrap().is_reverted());
}
// TODO(Avi, 01/06/2024): Run the same transactions concurrently on a new state and compare the
// state diffs.
}

fn generate_transfer(
accounts: &[ContractAddress],
sender_index: usize,
recipient_index: usize,
nonce_manager: &mut NonceManager,
chain_info: &ChainInfo,
) -> AccountTransaction {
let sender_address = accounts[sender_index];
let recipient_account_address = accounts[recipient_index];
let nonce = nonce_manager.next(sender_address);

let entry_point_selector =
selector_from_name(blockifier::transaction::constants::TRANSFER_ENTRY_POINT_NAME);
let entry_point_selector = selector_from_name(TRANSFER_ENTRY_POINT_NAME);
let contract_address = match TRANSACTION_VERSION {
TransactionVersion::ONE => {
*block_context.chain_info().fee_token_addresses.eth_fee_token_address.0.key()
}
TransactionVersion::THREE => {
*block_context.chain_info().fee_token_addresses.strk_fee_token_address.0.key()
}
TransactionVersion::ONE => *chain_info.fee_token_addresses.eth_fee_token_address.0.key(),
TransactionVersion::THREE => *chain_info.fee_token_addresses.strk_fee_token_address.0.key(),
_ => panic!("Unsupported transaction version: {TRANSACTION_VERSION:?}"),
};

Expand All @@ -102,10 +127,7 @@ fn do_transfer(
version: TRANSACTION_VERSION,
nonce,
});
let account_tx = AccountTransaction::Invoke(tx);
let charge_fee = CHARGE_FEE;
let validate = RUN_VALIDATION;
account_tx.execute(state, block_context, charge_fee, validate).unwrap();
AccountTransaction::Invoke(tx)
}

criterion_group!(benches, transfers_benchmark);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use core::option::OptionTrait;
use core::traits::TryInto;
#[starknet::contract]
#[starknet::contract(account)]

// A dummy account contract with faulty validations.

Expand Down Expand Up @@ -69,7 +69,7 @@ mod Account {
send_message_to_l1_syscall(
to_address: to_address,
payload: calldata.span()
);
).unwrap_syscall();
faulty_validate()
}

Expand All @@ -85,7 +85,7 @@ mod Account {
send_message_to_l1_syscall(
to_address: to_address,
payload: calldata.span()
);
).unwrap_syscall();

starknet::VALIDATED
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[starknet::contract]
#[starknet::contract(account)]
mod Account {
use array::{ArrayTrait, SpanTrait};
use starknet::{ContractAddress, call_contract_syscall};
Expand Down
Loading
Loading