From 75450a6542164ee4f64cadc7a97a24d25ff37e2a Mon Sep 17 00:00:00 2001 From: Joe C Date: Tue, 15 Oct 2024 23:15:03 +0700 Subject: [PATCH] SVM: API: rename `new` to `new_uninitialized` (#3170) --- runtime/src/bank.rs | 4 ++-- .../json-rpc/server/src/rpc_process.rs | 2 +- svm/examples/paytube/src/processor.rs | 2 +- svm/src/transaction_processor.rs | 21 ++++++++++++++++++- svm/tests/concurrent_tests.rs | 11 +++++----- svm/tests/conformance.rs | 3 ++- svm/tests/integration_test.rs | 4 ++-- 7 files changed, 33 insertions(+), 14 deletions(-) diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index 6770010b5d1b84..0975a6dbccde23 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -1048,7 +1048,7 @@ impl Bank { }; bank.transaction_processor = - TransactionBatchProcessor::new(bank.slot, bank.epoch, HashSet::default()); + TransactionBatchProcessor::new_uninitialized(bank.slot, bank.epoch, HashSet::default()); let accounts_data_size_initial = bank.get_total_accounts_stats().unwrap().data_len as u64; bank.accounts_data_size_initial = accounts_data_size_initial; @@ -1702,7 +1702,7 @@ impl Bank { }; bank.transaction_processor = - TransactionBatchProcessor::new(bank.slot, bank.epoch, HashSet::default()); + TransactionBatchProcessor::new_uninitialized(bank.slot, bank.epoch, HashSet::default()); let thread_pool = ThreadPoolBuilder::new() .thread_name(|i| format!("solBnkNewFlds{i:02}")) diff --git a/svm/examples/json-rpc/server/src/rpc_process.rs b/svm/examples/json-rpc/server/src/rpc_process.rs index ed239323b462b4..f0721783c9d38d 100644 --- a/svm/examples/json-rpc/server/src/rpc_process.rs +++ b/svm/examples/json-rpc/server/src/rpc_process.rs @@ -208,7 +208,7 @@ impl JsonRpcRequestProcessor { (pubkey, acc_data) }) .collect(); - let batch_processor = TransactionBatchProcessor::::new( + let batch_processor = TransactionBatchProcessor::::new_uninitialized( EXECUTION_SLOT, EXECUTION_EPOCH, HashSet::new(), diff --git a/svm/examples/paytube/src/processor.rs b/svm/examples/paytube/src/processor.rs index 03a8336209ca29..663c1b5044665e 100644 --- a/svm/examples/paytube/src/processor.rs +++ b/svm/examples/paytube/src/processor.rs @@ -50,7 +50,7 @@ pub(crate) fn create_transaction_batch_processor::new( + let processor = TransactionBatchProcessor::::new_uninitialized( /* slot */ 1, /* epoch */ 1, /* builtin_program_ids */ HashSet::new(), diff --git a/svm/src/transaction_processor.rs b/svm/src/transaction_processor.rs index 92706997471c52..91f79952254095 100644 --- a/svm/src/transaction_processor.rs +++ b/svm/src/transaction_processor.rs @@ -189,7 +189,20 @@ impl Default for TransactionBatchProcessor { } impl TransactionBatchProcessor { - pub fn new(slot: Slot, epoch: Epoch, builtin_program_ids: HashSet) -> Self { + /// Create a new, uninitialized `TransactionBatchProcessor`. + /// + /// In this context, uninitialized means that the `TransactionBatchProcessor` + /// has been initialized with an empty program cache. The cache contains no + /// programs (including builtins) and has not been configured with a valid + /// fork graph. + /// + /// When using this method, it's advisable to call `set_fork_graph_in_program_cache` + /// as well as `add_builtin` to configure the cache before using the processor. + pub fn new_uninitialized( + slot: Slot, + epoch: Epoch, + builtin_program_ids: HashSet, + ) -> Self { Self { slot, epoch, @@ -199,6 +212,12 @@ impl TransactionBatchProcessor { } } + /// Create a new `TransactionBatchProcessor` from the current instance, but + /// with the provided slot and epoch. + /// + /// * Inherits the program cache and builtin program ids from the current + /// instance. + /// * Resets the sysvar cache. pub fn new_from(&self, slot: Slot, epoch: Epoch) -> Self { Self { slot, diff --git a/svm/tests/concurrent_tests.rs b/svm/tests/concurrent_tests.rs index 2e84fbba243663..4c547675784577 100644 --- a/svm/tests/concurrent_tests.rs +++ b/svm/tests/concurrent_tests.rs @@ -40,7 +40,8 @@ mod transaction_builder; fn program_cache_execution(threads: usize) { let mut mock_bank = MockBankCallback::default(); - let batch_processor = TransactionBatchProcessor::::new(5, 5, HashSet::new()); + let batch_processor = + TransactionBatchProcessor::::new_uninitialized(5, 5, HashSet::new()); let fork_graph = Arc::new(RwLock::new(MockForkGraph {})); batch_processor.program_cache.write().unwrap().fork_graph = Some(Arc::downgrade(&fork_graph)); @@ -126,11 +127,9 @@ fn test_program_cache_with_exhaustive_scheduler() { // correctly. fn svm_concurrent() { let mock_bank = Arc::new(MockBankCallback::default()); - let batch_processor = Arc::new(TransactionBatchProcessor::::new( - 5, - 2, - HashSet::new(), - )); + let batch_processor = Arc::new( + TransactionBatchProcessor::::new_uninitialized(5, 2, HashSet::new()), + ); let fork_graph = Arc::new(RwLock::new(MockForkGraph {})); create_executable_environment( diff --git a/svm/tests/conformance.rs b/svm/tests/conformance.rs index dc521bc36eee15..7bc9ee5184b2c6 100644 --- a/svm/tests/conformance.rs +++ b/svm/tests/conformance.rs @@ -244,7 +244,8 @@ fn run_fixture(fixture: InstrFixture, filename: OsString, execute_as_instr: bool create_program_runtime_environment_v1(&feature_set, &compute_budget, false, false).unwrap(); mock_bank.override_feature_set(feature_set); - let batch_processor = TransactionBatchProcessor::::new(42, 2, HashSet::new()); + let batch_processor = + TransactionBatchProcessor::::new_uninitialized(42, 2, HashSet::new()); let fork_graph = Arc::new(RwLock::new(MockForkGraph {})); { diff --git a/svm/tests/integration_test.rs b/svm/tests/integration_test.rs index 6b1325a643d2f0..9f781607aa3112 100644 --- a/svm/tests/integration_test.rs +++ b/svm/tests/integration_test.rs @@ -872,7 +872,7 @@ fn execute_test_entry(test_entry: SvmTestEntry) { .insert(*pubkey, account.clone()); } - let batch_processor = TransactionBatchProcessor::::new( + let batch_processor = TransactionBatchProcessor::::new_uninitialized( EXECUTION_SLOT, EXECUTION_EPOCH, HashSet::new(), @@ -1059,7 +1059,7 @@ fn svm_inspect_account() { // Load and execute the transaction - let batch_processor = TransactionBatchProcessor::::new( + let batch_processor = TransactionBatchProcessor::::new_uninitialized( EXECUTION_SLOT, EXECUTION_EPOCH, HashSet::new(),