Skip to content

Commit

Permalink
SVM: API: rename new to new_uninitialized
Browse files Browse the repository at this point in the history
  • Loading branch information
buffalojoec committed Oct 15, 2024
1 parent 9695566 commit fbb607e
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 7 deletions.
4 changes: 2 additions & 2 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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}"))
Expand Down
2 changes: 1 addition & 1 deletion svm/examples/json-rpc/server/src/rpc_process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ impl JsonRpcRequestProcessor {
(pubkey, acc_data)
})
.collect();
let batch_processor = TransactionBatchProcessor::<MockForkGraph>::new(
let batch_processor = TransactionBatchProcessor::<MockForkGraph>::new_uninitialized(
EXECUTION_SLOT,
EXECUTION_EPOCH,
HashSet::new(),
Expand Down
21 changes: 20 additions & 1 deletion svm/src/transaction_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,20 @@ impl<FG: ForkGraph> Default for TransactionBatchProcessor<FG> {
}

impl<FG: ForkGraph> TransactionBatchProcessor<FG> {
pub fn new(slot: Slot, epoch: Epoch, builtin_program_ids: HashSet<Pubkey>) -> 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<Pubkey>,
) -> Self {
Self {
slot,
epoch,
Expand All @@ -199,6 +212,12 @@ impl<FG: ForkGraph> TransactionBatchProcessor<FG> {
}
}

/// 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,
Expand Down
2 changes: 1 addition & 1 deletion svm/tests/conformance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<MockForkGraph>::new(42, 2, HashSet::new());
let batch_processor = TransactionBatchProcessor::<MockForkGraph>::new_uninitialized(42, 2, HashSet::new());

let fork_graph = Arc::new(RwLock::new(MockForkGraph {}));
{
Expand Down
4 changes: 2 additions & 2 deletions svm/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,7 @@ fn execute_test_entry(test_entry: SvmTestEntry) {
.insert(*pubkey, account.clone());
}

let batch_processor = TransactionBatchProcessor::<MockForkGraph>::new(
let batch_processor = TransactionBatchProcessor::<MockForkGraph>::new_uninitialized(
EXECUTION_SLOT,
EXECUTION_EPOCH,
HashSet::new(),
Expand Down Expand Up @@ -1059,7 +1059,7 @@ fn svm_inspect_account() {

// Load and execute the transaction

let batch_processor = TransactionBatchProcessor::<MockForkGraph>::new(
let batch_processor = TransactionBatchProcessor::<MockForkGraph>::new_uninitialized(
EXECUTION_SLOT,
EXECUTION_EPOCH,
HashSet::new(),
Expand Down

0 comments on commit fbb607e

Please sign in to comment.