diff --git a/Cargo.lock b/Cargo.lock index b1ce368a62f31c..259e3fa2b85913 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -614,6 +614,12 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b34d609dfbaf33d6889b2b7106d3ca345eacad44200913df5ba02bfd31d2ba9" +[[package]] +name = "assoc" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfdc70193dadb9d7287fa4b633f15f90c876915b31f6af17da307fc59c9859a8" + [[package]] name = "async-channel" version = "1.9.0" @@ -872,6 +878,18 @@ dependencies = [ "typenum", ] +[[package]] +name = "bitvec" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" +dependencies = [ + "funty", + "radium", + "tap", + "wyz", +] + [[package]] name = "blake3" version = "1.5.1" @@ -1261,7 +1279,7 @@ dependencies = [ "num-traits", "serde", "wasm-bindgen", - "windows-targets 0.52.0", + "windows-targets 0.52.5", ] [[package]] @@ -2228,6 +2246,12 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" +[[package]] +name = "funty" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" + [[package]] name = "futures" version = "0.1.31" @@ -2364,6 +2388,20 @@ dependencies = [ "regex", ] +[[package]] +name = "generator" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "186014d53bc231d0090ef8d6f03e0920c54d85a5ed22f4f2f74315ec56cf83fb" +dependencies = [ + "cc", + "cfg-if 1.0.0", + "libc", + "log", + "rustversion", + "windows", +] + [[package]] name = "generic-array" version = "0.12.4" @@ -3779,6 +3817,12 @@ version = "6.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8e22443d1643a904602595ba1cd8f7d896afe56d26712531c5ff73a15b2fbf64" +[[package]] +name = "owo-colors" +version = "3.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f" + [[package]] name = "parity-tokio-ipc" version = "0.9.0" @@ -4331,6 +4375,12 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "radium" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" + [[package]] name = "rand" version = "0.4.6" @@ -4430,6 +4480,15 @@ dependencies = [ "rand_core 0.5.1", ] +[[package]] +name = "rand_pcg" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59cad018caf63deb318e5a4586d99a24424a364f40f1e5778c29aca23f4fc73e" +dependencies = [ + "rand_core 0.6.4", +] + [[package]] name = "rand_xorshift" version = "0.3.0" @@ -4836,6 +4895,12 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "scoped-tls" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294" + [[package]] name = "scopeguard" version = "1.2.0" @@ -5178,6 +5243,25 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" +[[package]] +name = "shuttle" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d9a8db61a44e2b663f169a08206a789bcbd22ba32011e14951562848e7b9c98" +dependencies = [ + "assoc", + "bitvec", + "generator", + "hex", + "owo-colors", + "rand 0.8.5", + "rand_core 0.6.4", + "rand_pcg", + "scoped-tls", + "smallvec", + "tracing", +] + [[package]] name = "signal-hook" version = "0.3.17" @@ -5600,6 +5684,7 @@ dependencies = [ "memoffset 0.9.0", "rand 0.8.5", "scopeguard", + "shuttle", "solana-compute-budget", "solana-measure", "solana-poseidon", @@ -6395,6 +6480,7 @@ version = "2.0.0" dependencies = [ "bincode", "log", + "shuttle", "solana-compute-budget", "solana-measure", "solana-program-runtime", @@ -6712,6 +6798,7 @@ dependencies = [ "rand 0.8.5", "rustc_version 0.4.0", "serde", + "shuttle", "solana-compute-budget", "solana-frozen-abi", "solana-frozen-abi-macro", @@ -7325,6 +7412,7 @@ dependencies = [ "rustc_version 0.4.0", "serde", "serde_derive", + "shuttle", "solana-bpf-loader-program", "solana-compute-budget", "solana-frozen-abi", @@ -8234,6 +8322,12 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "tap" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" + [[package]] name = "tar" version = "0.4.40" @@ -8747,11 +8841,10 @@ checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" [[package]] name = "tracing" -version = "0.1.35" +version = "0.1.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a400e31aa60b9d44a52a8ee0343b5b18566b03a8321e0d321f695cf56e940160" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" dependencies = [ - "cfg-if 1.0.0", "log", "pin-project-lite", "tracing-attributes", @@ -9193,6 +9286,35 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows" +version = "0.54.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9252e5725dbed82865af151df558e754e4a3c2c30818359eb17465f1346a1b49" +dependencies = [ + "windows-core", + "windows-targets 0.52.5", +] + +[[package]] +name = "windows-core" +version = "0.54.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12661b9c89351d684a50a8a643ce5f608e20243b9fb84687800163429f161d65" +dependencies = [ + "windows-result", + "windows-targets 0.52.5", +] + +[[package]] +name = "windows-result" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "749f0da9cc72d82e600d8d2e44cadd0b9eedb9038f71a1c58556ac1c5791813b" +dependencies = [ + "windows-targets 0.52.5", +] + [[package]] name = "windows-sys" version = "0.48.0" @@ -9208,7 +9330,7 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows-targets 0.52.0", + "windows-targets 0.52.5", ] [[package]] @@ -9228,17 +9350,18 @@ dependencies = [ [[package]] name = "windows-targets" -version = "0.52.0" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a18201040b24831fbb9e4eb208f8892e1f50a37feb53cc7ff887feb8f50e7cd" +checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" dependencies = [ - "windows_aarch64_gnullvm 0.52.0", - "windows_aarch64_msvc 0.52.0", - "windows_i686_gnu 0.52.0", - "windows_i686_msvc 0.52.0", - "windows_x86_64_gnu 0.52.0", - "windows_x86_64_gnullvm 0.52.0", - "windows_x86_64_msvc 0.52.0", + "windows_aarch64_gnullvm 0.52.5", + "windows_aarch64_msvc 0.52.5", + "windows_i686_gnu 0.52.5", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.5", + "windows_x86_64_gnu 0.52.5", + "windows_x86_64_gnullvm 0.52.5", + "windows_x86_64_msvc 0.52.5", ] [[package]] @@ -9249,9 +9372,9 @@ checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" [[package]] name = "windows_aarch64_gnullvm" -version = "0.52.0" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb7764e35d4db8a7921e09562a0304bf2f93e0a51bfccee0bd0bb0b666b015ea" +checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" [[package]] name = "windows_aarch64_msvc" @@ -9261,9 +9384,9 @@ checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" [[package]] name = "windows_aarch64_msvc" -version = "0.52.0" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbaa0368d4f1d2aaefc55b6fcfee13f41544ddf36801e793edbbfd7d7df075ef" +checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" [[package]] name = "windows_i686_gnu" @@ -9273,9 +9396,15 @@ checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" [[package]] name = "windows_i686_gnu" -version = "0.52.0" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a28637cb1fa3560a16915793afb20081aba2c92ee8af57b4d5f28e4b3e7df313" +checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" [[package]] name = "windows_i686_msvc" @@ -9285,9 +9414,9 @@ checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" [[package]] name = "windows_i686_msvc" -version = "0.52.0" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffe5e8e31046ce6230cc7215707b816e339ff4d4d67c65dffa206fd0f7aa7b9a" +checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" [[package]] name = "windows_x86_64_gnu" @@ -9297,9 +9426,9 @@ checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" [[package]] name = "windows_x86_64_gnu" -version = "0.52.0" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6fa32db2bc4a2f5abeacf2b69f7992cd09dca97498da74a151a3132c26befd" +checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" [[package]] name = "windows_x86_64_gnullvm" @@ -9309,9 +9438,9 @@ checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" [[package]] name = "windows_x86_64_gnullvm" -version = "0.52.0" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a657e1e9d3f514745a572a6846d3c7aa7dbe1658c056ed9c3344c4109a6949e" +checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" [[package]] name = "windows_x86_64_msvc" @@ -9321,9 +9450,9 @@ checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" [[package]] name = "windows_x86_64_msvc" -version = "0.52.0" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" +checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" [[package]] name = "winnow" @@ -9344,6 +9473,15 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "wyz" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" +dependencies = [ + "tap", +] + [[package]] name = "x509-parser" version = "0.14.0" diff --git a/Cargo.toml b/Cargo.toml index 8e6c25eb7c5b2c..a18f55916ce765 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -307,6 +307,7 @@ serde_yaml = "0.9.34" serial_test = "2.0.0" sha2 = "0.10.8" sha3 = "0.10.8" +shuttle = "0.7.1" signal-hook = "0.3.17" siphasher = "0.3.11" smallvec = "1.13.2" diff --git a/program-runtime/Cargo.toml b/program-runtime/Cargo.toml index a3d25a9cb37f03..a9fd32fc750e14 100644 --- a/program-runtime/Cargo.toml +++ b/program-runtime/Cargo.toml @@ -22,6 +22,7 @@ num-traits = { workspace = true } percentage = { workspace = true } rand = { workspace = true } serde = { workspace = true } +shuttle = { workspace = true, optional = true } solana-compute-budget = { workspace = true } solana-frozen-abi = { workspace = true, optional = true } solana-frozen-abi-macro = { workspace = true, optional = true } @@ -54,3 +55,4 @@ frozen-abi = [ "solana-compute-budget/frozen-abi", "solana-sdk/frozen-abi", ] +shuttle-test = ["dep:shuttle"] diff --git a/program-runtime/src/invoke_context.rs b/program-runtime/src/invoke_context.rs index ace5e0de11475f..b1499ab11b0cbf 100644 --- a/program-runtime/src/invoke_context.rs +++ b/program-runtime/src/invoke_context.rs @@ -1,3 +1,7 @@ +#[cfg(feature = "shuttle-test")] +use shuttle::sync::{atomic::Ordering, Arc}; +#[cfg(not(feature = "shuttle-test"))] +use std::sync::{atomic::Ordering, Arc}; use { crate::{ ic_msg, @@ -41,7 +45,6 @@ use { cell::RefCell, fmt::{self, Debug}, rc::Rc, - sync::{atomic::Ordering, Arc}, }, }; @@ -669,13 +672,16 @@ macro_rules! with_mock_invoke_context { $transaction_context:ident, $transaction_accounts:expr $(,)? ) => { + #[cfg(feature = "shuttle-test")] + use shuttle::sync::Arc; + #[cfg(not(feature = "shuttle-test"))] + use std::sync::Arc; use { solana_compute_budget::compute_budget::ComputeBudget, solana_sdk::{ account::ReadableAccount, feature_set::FeatureSet, hash::Hash, sysvar::rent::Rent, transaction_context::TransactionContext, }, - std::sync::Arc, $crate::{ invoke_context::{EnvironmentConfig, InvokeContext}, loaded_programs::ProgramCacheForTxBatch, @@ -683,6 +689,7 @@ macro_rules! with_mock_invoke_context { sysvar_cache::SysvarCache, }, }; + let compute_budget = ComputeBudget::default(); let mut $transaction_context = TransactionContext::new( $transaction_accounts, diff --git a/program-runtime/src/loaded_programs.rs b/program-runtime/src/loaded_programs.rs index 9728fe274e65e0..7a7f81c5131114 100644 --- a/program-runtime/src/loaded_programs.rs +++ b/program-runtime/src/loaded_programs.rs @@ -1,3 +1,12 @@ +#[cfg(feature = "shuttle-test")] +use shuttle::{ + rand::{thread_rng, Rng}, + sync::{ + atomic::{AtomicU64, Ordering}, + Arc, Condvar, Mutex, RwLock, + }, + thread, +}; use { crate::{ invoke_context::{BuiltinFunctionWithContext, InvokeContext}, @@ -5,7 +14,6 @@ use { }, log::{debug, error, log_enabled, trace}, percentage::PercentageInteger, - rand::{thread_rng, Rng}, solana_measure::measure::Measure, solana_rbpf::{ elf::Executable, @@ -23,12 +31,17 @@ use { std::{ collections::{hash_map::Entry, HashMap}, fmt::{Debug, Formatter}, - sync::{ - atomic::{AtomicU64, Ordering}, - Arc, Condvar, Mutex, RwLock, - }, }, }; +#[cfg(not(feature = "shuttle-test"))] +use { + rand::{thread_rng, Rng}, + std::sync::{ + atomic::{AtomicU64, Ordering}, + Arc, Condvar, Mutex, RwLock, + }, + std::thread, +}; pub type ProgramRuntimeEnvironment = Arc>>; pub const MAX_LOADED_ENTRY_COUNT: usize = 256; @@ -598,7 +611,7 @@ enum IndexImplementation { /// It is possible that multiple TX batches from different slots need different versions of a /// program. The deployment slot of a program is only known after load tho, /// so all loads for a given program key are serialized. - loading_entries: Mutex>, + loading_entries: Mutex>, }, } @@ -1100,7 +1113,7 @@ impl ProgramCache { if let Entry::Vacant(entry) = entry { entry.insert(( loaded_programs_for_tx_batch.slot, - std::thread::current().id(), + thread::current().id(), )); cooperative_loading_task = Some((*key, *usage_count)); } @@ -1134,7 +1147,7 @@ impl ProgramCache { loading_entries, .. } => { let loading_thread = loading_entries.get_mut().unwrap().remove(&key); - debug_assert_eq!(loading_thread, Some((slot, std::thread::current().id()))); + debug_assert_eq!(loading_thread, Some((slot, thread::current().id()))); // Check that it will be visible to our own fork once inserted if loaded_program.deployment_slot > self.latest_root_slot && !matches!( diff --git a/program-runtime/src/sysvar_cache.rs b/program-runtime/src/sysvar_cache.rs index 313faec6e11b02..f0cae4d3acca2b 100644 --- a/program-runtime/src/sysvar_cache.rs +++ b/program-runtime/src/sysvar_cache.rs @@ -1,5 +1,9 @@ +#[cfg(feature = "shuttle-test")] +use shuttle::sync::Arc; #[allow(deprecated)] use solana_sdk::sysvar::{fees::Fees, recent_blockhashes::RecentBlockhashes}; +#[cfg(not(feature = "shuttle-test"))] +use std::sync::Arc; use { crate::invoke_context::InvokeContext, serde::de::DeserializeOwned, @@ -13,7 +17,6 @@ use { }, transaction_context::{IndexOfAccount, InstructionContext, TransactionContext}, }, - std::sync::Arc, }; #[cfg(all(RUSTC_WITH_SPECIALIZATION, feature = "frozen-abi"))] diff --git a/programs/bpf_loader/Cargo.toml b/programs/bpf_loader/Cargo.toml index 6d3147d1e6bf03..32a9b9ce39c6ba 100644 --- a/programs/bpf_loader/Cargo.toml +++ b/programs/bpf_loader/Cargo.toml @@ -15,6 +15,7 @@ byteorder = { workspace = true } libsecp256k1 = { workspace = true } log = { workspace = true } scopeguard = { workspace = true } +shuttle = { workspace = true, optional = true } solana-compute-budget = { workspace = true } solana-measure = { workspace = true } solana-poseidon = { workspace = true } @@ -37,3 +38,6 @@ name = "solana_bpf_loader_program" [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] + +[features] +shuttle-test = ["dep:shuttle"] diff --git a/programs/bpf_loader/src/lib.rs b/programs/bpf_loader/src/lib.rs index 8f14544ffcf0b3..4c948b4a3b0001 100644 --- a/programs/bpf_loader/src/lib.rs +++ b/programs/bpf_loader/src/lib.rs @@ -4,6 +4,10 @@ pub mod serialization; pub mod syscalls; +#[cfg(feature = "shuttle-test")] +use shuttle::sync::{atomic::Ordering, Arc}; +#[cfg(not(feature = "shuttle-test"))] +use std::sync::{atomic::Ordering, Arc}; use { solana_measure::measure::Measure, solana_program_runtime::{ @@ -46,12 +50,7 @@ use { system_instruction::{self, MAX_PERMITTED_DATA_LENGTH}, transaction_context::{IndexOfAccount, InstructionContext, TransactionContext}, }, - std::{ - cell::RefCell, - mem, - rc::Rc, - sync::{atomic::Ordering, Arc}, - }, + std::{cell::RefCell, mem, rc::Rc}, syscalls::{create_program_runtime_environment_v1, morph_into_deployment_environment_v1}, }; @@ -324,7 +323,12 @@ macro_rules! create_vm { #[macro_export] macro_rules! mock_create_vm { ($vm:ident, $additional_regions:expr, $accounts_metadata:expr, $invoke_context:expr $(,)?) => { + #[cfg(not(feature = "shuttle-test"))] let loader = std::sync::Arc::new(BuiltinProgram::new_mock()); + + #[cfg(feature = "shuttle-test")] + let loader = shuttle::sync::Arc::new(BuiltinProgram::new_mock()); + let function_registry = solana_rbpf::program::FunctionRegistry::default(); let executable = solana_rbpf::elf::Executable::::from_text_bytes( &[0x95, 0, 0, 0, 0, 0, 0, 0], diff --git a/programs/bpf_loader/src/syscalls/mod.rs b/programs/bpf_loader/src/syscalls/mod.rs index 425cbf8d56e820..18b89b100b00ce 100644 --- a/programs/bpf_loader/src/syscalls/mod.rs +++ b/programs/bpf_loader/src/syscalls/mod.rs @@ -10,6 +10,10 @@ pub use self::{ SyscallGetSysvar, }, }; +#[cfg(feature = "shuttle-test")] +use shuttle::sync::Arc; +#[cfg(not(feature = "shuttle-test"))] +use std::sync::Arc; #[allow(deprecated)] use { solana_compute_budget::compute_budget::ComputeBudget, @@ -62,7 +66,6 @@ use { mem::{align_of, size_of}, slice::from_raw_parts_mut, str::{from_utf8, Utf8Error}, - sync::Arc, }, thiserror::Error as ThisError, }; diff --git a/programs/loader-v4/Cargo.toml b/programs/loader-v4/Cargo.toml index da7d5c10c72a51..ebcf0def3b552d 100644 --- a/programs/loader-v4/Cargo.toml +++ b/programs/loader-v4/Cargo.toml @@ -10,6 +10,7 @@ edition = { workspace = true } [dependencies] log = { workspace = true } +shuttle = { workspace = true, optional = true } solana-compute-budget = { workspace = true } solana-measure = { workspace = true } solana-program-runtime = { workspace = true } @@ -25,3 +26,6 @@ name = "solana_loader_v4_program" [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] + +[features] +shuttle-test = ["dep:shuttle"] diff --git a/programs/loader-v4/src/lib.rs b/programs/loader-v4/src/lib.rs index b564e84c43a9d4..554615549efb53 100644 --- a/programs/loader-v4/src/lib.rs +++ b/programs/loader-v4/src/lib.rs @@ -1,3 +1,7 @@ +#[cfg(feature = "shuttle-test")] +use shuttle::sync::{atomic::Ordering, Arc}; +#[cfg(not(feature = "shuttle-test"))] +use std::sync::{atomic::Ordering, Arc}; use { solana_compute_budget::compute_budget::ComputeBudget, solana_measure::measure::Measure, @@ -30,11 +34,7 @@ use { saturating_add_assign, transaction_context::{BorrowedAccount, InstructionContext}, }, - std::{ - cell::RefCell, - rc::Rc, - sync::{atomic::Ordering, Arc}, - }, + std::{cell::RefCell, rc::Rc}, }; pub const DEFAULT_COMPUTE_UNITS: u64 = 2_000; diff --git a/svm/Cargo.toml b/svm/Cargo.toml index ebe845cd130837..49c45bad43028a 100644 --- a/svm/Cargo.toml +++ b/svm/Cargo.toml @@ -15,6 +15,7 @@ log = { workspace = true } percentage = { workspace = true } serde = { workspace = true, features = ["rc"] } serde_derive = { workspace = true } +shuttle = { workspace = true, optional = true } solana-bpf-loader-program = { workspace = true } solana-compute-budget = { workspace = true } solana-frozen-abi = { workspace = true, optional = true } @@ -57,3 +58,4 @@ frozen-abi = [ "solana-program-runtime/frozen-abi", "solana-sdk/frozen-abi", ] +shuttle-test = ["dep:shuttle"] diff --git a/svm/src/message_processor.rs b/svm/src/message_processor.rs index 7b366e82304975..de1980c1710098 100644 --- a/svm/src/message_processor.rs +++ b/svm/src/message_processor.rs @@ -654,7 +654,11 @@ mod tests { // copies the `random` implementation at: // https://docs.rs/libsecp256k1/latest/src/libsecp256k1/lib.rs.html#430 let secret_key = { + #[cfg(not(feature = "shuttle-test"))] use rand::RngCore; + #[cfg(feature = "shuttle-test")] + use shuttle::rand::RngCore; + let mut rng = rand::thread_rng(); loop { let mut ret = [0u8; libsecp256k1::util::SECRET_KEY_SIZE]; diff --git a/svm/src/program_loader.rs b/svm/src/program_loader.rs index 8920340d4a2544..9e2bd0cc2c8f09 100644 --- a/svm/src/program_loader.rs +++ b/svm/src/program_loader.rs @@ -1,3 +1,7 @@ +#[cfg(feature = "shuttle-test")] +use shuttle::sync::Arc; +#[cfg(not(feature = "shuttle-test"))] +use std::sync::Arc; use { crate::transaction_processing_callback::TransactionProcessingCallback, solana_program_runtime::{ @@ -18,7 +22,6 @@ use { loader_v4::{self, LoaderV4State, LoaderV4Status}, pubkey::Pubkey, }, - std::sync::Arc, }; #[derive(Debug)] diff --git a/svm/src/transaction_processing_callback.rs b/svm/src/transaction_processing_callback.rs index ded481eda8ea5f..3da173dd955878 100644 --- a/svm/src/transaction_processing_callback.rs +++ b/svm/src/transaction_processing_callback.rs @@ -1,10 +1,13 @@ +#[cfg(feature = "shuttle-test")] +use shuttle::sync::Arc; +#[cfg(not(feature = "shuttle-test"))] +use std::sync::Arc; use { solana_program_runtime::loaded_programs::ProgramCacheMatchCriteria, solana_sdk::{ account::AccountSharedData, feature_set::FeatureSet, hash::Hash, pubkey::Pubkey, rent_collector::RentCollector, }, - std::sync::Arc, }; /// Runtime callbacks for transaction processing. diff --git a/svm/src/transaction_processor.rs b/svm/src/transaction_processor.rs index f69b1c4e0ea52b..e9947d42be2ef9 100644 --- a/svm/src/transaction_processor.rs +++ b/svm/src/transaction_processor.rs @@ -1,3 +1,13 @@ +#[cfg(feature = "shuttle-test")] +use shuttle::sync::{ + atomic::Ordering::{self, Relaxed}, + Arc, RwLock, +}; +#[cfg(not(feature = "shuttle-test"))] +use std::sync::{ + atomic::Ordering::{self, Relaxed}, + Arc, RwLock, +}; use { crate::{ account_loader::{ @@ -47,10 +57,6 @@ use { collections::{hash_map::Entry, HashMap, HashSet}, fmt::{Debug, Formatter}, rc::Rc, - sync::{ - atomic::Ordering::{self, Relaxed}, - Arc, RwLock, - }, }, };