From f3a834657d93de65b7089a854442e3301e12d63d Mon Sep 17 00:00:00 2001 From: Eric Semeniuc <3838856+esemeniuc@users.noreply.github.com> Date: Sat, 2 Dec 2023 17:16:55 +0100 Subject: [PATCH] [JIT-1710] - Optimize Bundle Consumer Checks (#490) --- Cargo.toml | 2 +- bundle/Cargo.toml | 1 + bundle/src/bundle_execution.rs | 8 ++++---- ci/buildkite-pipeline.sh | 2 +- core/benches/banking_stage.rs | 11 ++++++++++- core/src/banking_stage.rs | 3 ++- core/src/banking_stage/consumer.rs | 2 +- core/src/bundle_stage/bundle_consumer.rs | 16 ++++++++-------- .../bundle_reserved_space_manager.rs | 6 ++---- tip-distributor/Cargo.toml | 1 + .../src/stake_meta_generator_workflow.rs | 3 +-- turbine/benches/retransmit_stage.rs | 2 +- 12 files changed, 33 insertions(+), 24 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 56069a5224..cbe9417387 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -87,8 +87,8 @@ members = [ "rpc-client-nonce-utils", "rpc-test", "runtime", - "runtime-transaction", "runtime-plugin", + "runtime-transaction", "sdk", "sdk/cargo-build-bpf", "sdk/cargo-build-sbf", diff --git a/bundle/Cargo.toml b/bundle/Cargo.toml index babb13bcd7..7280b7ee67 100644 --- a/bundle/Cargo.toml +++ b/bundle/Cargo.toml @@ -29,6 +29,7 @@ thiserror = { workspace = true } [dev-dependencies] assert_matches = { workspace = true } solana-logger = { workspace = true } +solana-runtime = { workspace = true, features = ["dev-context-only-utils"] } [lib] crate-type = ["lib"] diff --git a/bundle/src/bundle_execution.rs b/bundle/src/bundle_execution.rs index e69096f8ed..d7a97c0dbb 100644 --- a/bundle/src/bundle_execution.rs +++ b/bundle/src/bundle_execution.rs @@ -523,7 +523,7 @@ mod tests { fn create_simple_test_bank(lamports: u64) -> (GenesisConfigInfo, Arc) { let genesis_config_info = create_genesis_config(lamports); - let bank = Arc::new(Bank::new_for_tests(&genesis_config_info.genesis_config)); + let (bank, _) = Bank::new_with_bank_forks_for_tests(&genesis_config_info.genesis_config); (genesis_config_info, bank) } @@ -588,7 +588,7 @@ mod tests { // check to make sure there was one batch returned with one transaction that was the same that was put in assert_eq!(execution_result.bundle_transaction_results.len(), 1); - let tx_result = execution_result.bundle_transaction_results.get(0).unwrap(); + let tx_result = execution_result.bundle_transaction_results.first().unwrap(); assert_eq!(tx_result.transactions.len(), 1); assert_eq!(tx_result.transactions[0], bundle.transactions[0]); @@ -603,14 +603,14 @@ mod tests { let execution_result = tx_result .load_and_execute_transactions_output .execution_results - .get(0) + .first() .unwrap(); assert!(execution_result.was_executed()); assert!(execution_result.was_executed_successfully()); // Make sure the post-balances are correct assert_eq!(tx_result.pre_balance_info.native.len(), 1); - let post_tx_sol_balances = tx_result.post_balance_info.0.get(0).unwrap(); + let post_tx_sol_balances = tx_result.post_balance_info.0.first().unwrap(); let minter_message_index = find_account_index(&transactions[0], &genesis_config_info.mint_keypair.pubkey()) diff --git a/ci/buildkite-pipeline.sh b/ci/buildkite-pipeline.sh index b4c26775a2..e3da77c5a3 100755 --- a/ci/buildkite-pipeline.sh +++ b/ci/buildkite-pipeline.sh @@ -142,7 +142,7 @@ wait_step() { all_test_steps() { command_step checks1 ". ci/rust-version.sh; ci/docker-run.sh \$\$rust_nightly_docker_image ci/test-checks.sh" 20 check command_step checks2 ". ci/rust-version.sh; ci/docker-run.sh \$\$rust_nightly_docker_image ci/test-dev-context-only-utils.sh check-bins" 15 check - command_step checks3 ". ci/rust-version.sh; ci/docker-run.sh \$\$rust_nightly_docker_image ci/test-dev-context-only-utils.sh check-all-targets" 15 check + command_step checks3 ". ci/rust-version.sh; ci/docker-run.sh \$\$rust_nightly_docker_image ci/test-dev-context-only-utils.sh check-all-targets" 20 check wait_step # Full test suite diff --git a/core/benches/banking_stage.rs b/core/benches/banking_stage.rs index 00a7d91c9c..ee9795b345 100644 --- a/core/benches/banking_stage.rs +++ b/core/benches/banking_stage.rs @@ -118,7 +118,14 @@ fn bench_consume_buffered(bencher: &mut Bencher) { ); let (s, _r) = unbounded(); let committer = Committer::new(None, s, Arc::new(PrioritizationFeeCache::new(0u64))); - let consumer = Consumer::new(committer, recorder, QosService::new(1), None); + let consumer = Consumer::new( + committer, + recorder, + QosService::new(1), + None, + HashSet::default(), + BundleAccountLocker::default(), + ); // This tests the performance of buffering packets. // If the packet buffers are copied, performance will be poor. bencher.iter(move || { @@ -311,6 +318,8 @@ fn bench_banking(bencher: &mut Bencher, tx_type: TransactionType) { Arc::new(ConnectionCache::new("connection_cache_test")), bank_forks, &Arc::new(PrioritizationFeeCache::new(0u64)), + HashSet::default(), + BundleAccountLocker::default(), ); let chunk_len = verified.len() / CHUNKS; diff --git a/core/src/banking_stage.rs b/core/src/banking_stage.rs index a742ab2b93..7bd9e1dd99 100644 --- a/core/src/banking_stage.rs +++ b/core/src/banking_stage.rs @@ -633,6 +633,7 @@ impl BankingStage { Self { bank_thread_hdls } } + #[allow(clippy::too_many_arguments)] fn spawn_thread_local_multi_iterator_thread( id: u32, packet_receiver: BankingPacketReceiver, @@ -1311,7 +1312,7 @@ mod tests { bank, entries_ticks, } = entry_receiver.recv().unwrap(); - let entry = &entries_ticks.get(0).unwrap().0; + let entry = &entries_ticks.first().unwrap().0; assert_eq!(entry.transactions, txs); // Once bank is set to a new bank (setting bank.slot() + 1 in record_transactions), diff --git a/core/src/banking_stage/consumer.rs b/core/src/banking_stage/consumer.rs index 7f7c80bba4..b0119b7675 100644 --- a/core/src/banking_stage/consumer.rs +++ b/core/src/banking_stage/consumer.rs @@ -1036,7 +1036,7 @@ mod tests { }) = entry_receiver.recv() { assert!(entries_ticks.len() == 1); - let entry = &entries_ticks.get(0).unwrap().0; + let entry = &entries_ticks.first().unwrap().0; if !entry.is_tick() { trace!("got entry"); assert_eq!(entry.transactions.len(), transactions.len()); diff --git a/core/src/bundle_stage/bundle_consumer.rs b/core/src/bundle_stage/bundle_consumer.rs index 49af1b4afc..0b3f570a14 100644 --- a/core/src/bundle_stage/bundle_consumer.rs +++ b/core/src/bundle_stage/bundle_consumer.rs @@ -290,10 +290,11 @@ impl BundleConsumer { return Err(BundleExecutionError::BankProcessingTimeLimitReached); } - if Self::bundle_touches_tip_pdas( - locked_bundle.sanitized_bundle(), - &tip_manager.get_tip_accounts(), - ) && bank_start.working_bank.slot() != *last_tip_updated_slot + if bank_start.working_bank.slot() != *last_tip_updated_slot + && Self::bundle_touches_tip_pdas( + locked_bundle.sanitized_bundle(), + &tip_manager.get_tip_accounts(), + ) { let start = Instant::now(); let result = Self::handle_tip_programs( @@ -810,7 +811,6 @@ mod tests { solana_sdk::{ bundle::{derive_bundle_id, SanitizedBundle}, clock::MAX_PROCESSING_AGE, - feature_set::delay_visibility_of_program_deployment, fee_calculator::{FeeRateGovernor, DEFAULT_TARGET_LAMPORTS_PER_SIGNATURE}, genesis_config::ClusterType, hash::Hash, @@ -936,9 +936,9 @@ mod tests { // workaround for https://github.com/solana-labs/solana/issues/30085 // the test can deploy and use spl_programs in the genensis slot without waiting for the next one - let mut bank = Bank::new_for_tests(&genesis_config); - bank.deactivate_feature(&delay_visibility_of_program_deployment::id()); - let bank = Arc::new(bank); + let (bank, _) = Bank::new_with_bank_forks_for_tests(&genesis_config); + + let bank = Arc::new(Bank::new_from_parent(bank, &Pubkey::default(), 1)); let ledger_path = get_tmp_ledger_path_auto_delete!(); let blockstore = Arc::new( diff --git a/core/src/bundle_stage/bundle_reserved_space_manager.rs b/core/src/bundle_stage/bundle_reserved_space_manager.rs index 7b48298934..24cca76aa1 100644 --- a/core/src/bundle_stage/bundle_reserved_space_manager.rs +++ b/core/src/bundle_stage/bundle_reserved_space_manager.rs @@ -82,10 +82,8 @@ impl BundleReservedSpaceManager { mod tests { use { crate::bundle_stage::bundle_reserved_space_manager::BundleReservedSpaceManager, - solana_ledger::genesis_utils::create_genesis_config, - solana_runtime::bank::Bank, - solana_sdk::{hash::Hash, pubkey::Pubkey}, - std::sync::{Arc, RwLock}, + solana_ledger::genesis_utils::create_genesis_config, solana_runtime::bank::Bank, + solana_sdk::pubkey::Pubkey, std::sync::Arc, }; #[test] diff --git a/tip-distributor/Cargo.toml b/tip-distributor/Cargo.toml index 6d6e9b7f78..f15085a262 100644 --- a/tip-distributor/Cargo.toml +++ b/tip-distributor/Cargo.toml @@ -40,6 +40,7 @@ thiserror = { workspace = true } tokio = { workspace = true, features = ["rt-multi-thread", "macros"] } [dev-dependencies] +solana-runtime = { workspace = true, features = ["dev-context-only-utils"] } solana-sdk = { workspace = true, features = ["dev-context-only-utils"] } [[bin]] diff --git a/tip-distributor/src/stake_meta_generator_workflow.rs b/tip-distributor/src/stake_meta_generator_workflow.rs index e0c82aa01e..80712cd97c 100644 --- a/tip-distributor/src/stake_meta_generator_workflow.rs +++ b/tip-distributor/src/stake_meta_generator_workflow.rs @@ -394,7 +394,7 @@ mod tests { vec![INITIAL_VALIDATOR_STAKES; 3], ); - let bank = Bank::new_for_tests(&genesis_config); + let (mut bank, _) = Bank::new_with_bank_forks_for_tests(&genesis_config); /* 2. Seed the Bank with [TipDistributionAccount]'s */ let merkle_root_upload_authority = Pubkey::new_unique(); @@ -585,7 +585,6 @@ mod tests { )) } - let mut bank = Arc::new(bank); let mut stake_pubkeys = validator_0_delegations .iter() .map(|v| v.stake_account_pubkey) diff --git a/turbine/benches/retransmit_stage.rs b/turbine/benches/retransmit_stage.rs index d1b7493d8c..44b3f918d1 100644 --- a/turbine/benches/retransmit_stage.rs +++ b/turbine/benches/retransmit_stage.rs @@ -32,7 +32,7 @@ use { net::{Ipv4Addr, UdpSocket}, sync::{ atomic::{AtomicUsize, Ordering}, - Arc, + Arc, RwLock, }, thread::{sleep, Builder}, time::Duration,