From fbb607ea07e9b055ee1b9d19904d177ebe9bc94f Mon Sep 17 00:00:00 2001 From: Joe Caulfield Date: Tue, 15 Oct 2024 18:39:35 +0700 Subject: [PATCH] SVM: API: rename `new` to `new_uninitialized` --- runtime/src/bank.rs | 4 ++-- .../json-rpc/server/src/rpc_process.rs | 2 +- svm/src/transaction_processor.rs | 21 ++++++++++++++++++- svm/tests/conformance.rs | 2 +- svm/tests/integration_test.rs | 4 ++-- 5 files changed, 26 insertions(+), 7 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/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/conformance.rs b/svm/tests/conformance.rs index dc521bc36eee15..d8d9c81a360601 100644 --- a/svm/tests/conformance.rs +++ b/svm/tests/conformance.rs @@ -244,7 +244,7 @@ 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(),