Skip to content

Commit

Permalink
minimize solana-sdk usage in svm/src (#4172)
Browse files Browse the repository at this point in the history
* minimize solana-sdk usage in svm/src

* add back type aliases

* missing import
  • Loading branch information
kevinheavey authored Dec 20, 2024
1 parent ee31e31 commit 3deac72
Show file tree
Hide file tree
Showing 16 changed files with 270 additions and 182 deletions.
28 changes: 28 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions programs/sbf/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions svm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,42 @@ percentage = { workspace = true }
qualifier_attr = { workspace = true, optional = true }
serde = { workspace = true, features = ["rc"] }
serde_derive = { workspace = true }
solana-account = { workspace = true }
solana-bpf-loader-program = { workspace = true }
solana-clock = { workspace = true }
solana-compute-budget = { workspace = true }
solana-compute-budget-instruction = { workspace = true }
solana-feature-set = { workspace = true }
solana-fee = { workspace = true }
solana-fee-structure = { workspace = true }
solana-frozen-abi = { workspace = true, optional = true, features = [
"frozen-abi",
] }
solana-frozen-abi-macro = { workspace = true, optional = true, features = [
"frozen-abi",
] }
solana-hash = { workspace = true }
solana-instruction = { workspace = true, features = ["std"] }
solana-instructions-sysvar = { workspace = true }
solana-loader-v4-program = { workspace = true }
solana-log-collector = { workspace = true }
solana-measure = { workspace = true }
solana-message = { workspace = true }
solana-nonce = { workspace = true }
solana-precompiles = { workspace = true }
solana-program = { workspace = true, default-features = false }
solana-program-runtime = { workspace = true }
solana-pubkey = { workspace = true }
solana-rent = { workspace = true }
solana-rent-debits = { workspace = true }
solana-sdk = { workspace = true }
solana-sdk-ids = { workspace = true }
solana-svm-rent-collector = { workspace = true }
solana-svm-transaction = { workspace = true }
solana-system-program = { workspace = true }
solana-timings = { workspace = true }
solana-transaction-context = { workspace = true }
solana-transaction-error = { workspace = true }
solana-type-overrides = { workspace = true }
thiserror = { workspace = true }

Expand All @@ -54,15 +70,30 @@ openssl = { workspace = true }
prost = { workspace = true }
rand0-7 = { workspace = true }
shuttle = { workspace = true }
solana-clock = { workspace = true }
solana-compute-budget-interface = { workspace = true }
solana-compute-budget-program = { workspace = true }
solana-ed25519-program = { workspace = true }
solana-epoch-schedule = { workspace = true }
solana-fee-calculator = { workspace = true }
solana-keypair = { workspace = true }
solana-logger = { workspace = true }
solana-native-token = { workspace = true }
solana-pubkey = { workspace = true }
solana-rent = { workspace = true }
solana-reserved-account-keys = { workspace = true }
solana-sbpf = { workspace = true }
solana-sdk = { workspace = true, features = ["dev-context-only-utils"] }
solana-secp256k1-program = { workspace = true }
solana-secp256r1-program = { workspace = true, features = ["openssl-vendored"] }
solana-signature = { workspace = true }
solana-signer = { workspace = true }
# See order-crates-for-publishing.py for using this unusual `path = "."`
solana-svm = { path = ".", features = ["dev-context-only-utils"] }
solana-svm-conformance = { workspace = true }
solana-system-transaction = { workspace = true }
solana-sysvar = { workspace = true }
solana-transaction = { workspace = true }
test-case = { workspace = true }

[package.metadata.docs.rs]
Expand Down
16 changes: 16 additions & 0 deletions svm/examples/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

92 changes: 47 additions & 45 deletions svm/src/account_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,29 @@ use {
transaction_processing_callback::{AccountState, TransactionProcessingCallback},
},
ahash::{AHashMap, AHashSet},
solana_account::{
Account, AccountSharedData, ReadableAccount, WritableAccount, PROGRAM_OWNERS,
},
solana_compute_budget::compute_budget_limits::ComputeBudgetLimits,
solana_feature_set::{self as feature_set, FeatureSet},
solana_fee_structure::FeeDetails,
solana_instruction::{BorrowedAccountMeta, BorrowedInstruction},
solana_instructions_sysvar::construct_instructions_data,
solana_nonce::state::State as NonceState,
solana_program_runtime::loaded_programs::ProgramCacheForTxBatch,
solana_sdk::{
account::{Account, AccountSharedData, ReadableAccount, WritableAccount, PROGRAM_OWNERS},
fee::FeeDetails,
solana_pubkey::Pubkey,
solana_rent::RentDue,
solana_rent_debits::RentDebits,
solana_sdk::rent_collector::{CollectedInfo, RENT_EXEMPT_RENT_EPOCH},
solana_sdk_ids::{
native_loader,
nonce::State as NonceState,
pubkey::Pubkey,
rent::RentDue,
rent_collector::{CollectedInfo, RENT_EXEMPT_RENT_EPOCH},
rent_debits::RentDebits,
sysvar::{
self,
instructions::{construct_instructions_data, BorrowedAccountMeta, BorrowedInstruction},
slot_history,
},
transaction::{Result, TransactionError},
transaction_context::{IndexOfAccount, TransactionAccount},
sysvar::{self, slot_history},
},
solana_svm_rent_collector::svm_rent_collector::SVMRentCollector,
solana_svm_transaction::svm_message::SVMMessage,
solana_system_program::{get_system_account_kind, SystemAccountKind},
solana_transaction_context::{IndexOfAccount, TransactionAccount},
solana_transaction_error::{TransactionError, TransactionResult as Result},
std::{
collections::HashMap,
num::{NonZeroU32, Saturating},
Expand Down Expand Up @@ -580,7 +580,7 @@ fn load_transaction_account<CB: TransactionProcessingCallback>(
) -> LoadedTransactionAccount {
let usage_pattern = AccountUsagePattern::new(message, account_index);

let loaded_account = if solana_sdk::sysvar::instructions::check_id(account_key) {
let loaded_account = if solana_sdk_ids::sysvar::instructions::check_id(account_key) {
// Since the instructions sysvar is constructed by the SVM and modified
// for each transaction instruction, it cannot be loaded.
LoadedTransactionAccount {
Expand Down Expand Up @@ -697,38 +697,40 @@ mod tests {
transaction_account_state_info::TransactionAccountStateInfo,
transaction_processing_callback::TransactionProcessingCallback,
},
nonce::state::Versions as NonceVersions,
solana_account::{Account, AccountSharedData, ReadableAccount, WritableAccount},
solana_compute_budget::{compute_budget::ComputeBudget, compute_budget_limits},
solana_epoch_schedule::EpochSchedule,
solana_feature_set::FeatureSet,
solana_hash::Hash,
solana_instruction::{AccountMeta, Instruction},
solana_keypair::Keypair,
solana_message::{
compiled_instruction::CompiledInstruction,
v0::{LoadedAddresses, LoadedMessage},
LegacyMessage, Message, MessageHeader, SanitizedMessage,
},
solana_native_token::{sol_to_lamports, LAMPORTS_PER_SOL},
solana_nonce::{self as nonce, versions::Versions as NonceVersions},
solana_program::bpf_loader_upgradeable::UpgradeableLoaderState,
solana_program_runtime::loaded_programs::{
ProgramCacheEntry, ProgramCacheEntryOwner, ProgramCacheEntryType,
ProgramCacheForTxBatch,
},
solana_pubkey::Pubkey,
solana_rent::Rent,
solana_rent_debits::RentDebits,
solana_reserved_account_keys::ReservedAccountKeys,
solana_sbpf::program::BuiltinProgram,
solana_sdk::{
account::{Account, AccountSharedData, ReadableAccount, WritableAccount},
bpf_loader,
bpf_loader_upgradeable::{self, UpgradeableLoaderState},
epoch_schedule::EpochSchedule,
hash::Hash,
instruction::{AccountMeta, CompiledInstruction, Instruction},
message::{
v0::{LoadedAddresses, LoadedMessage},
LegacyMessage, Message, MessageHeader, SanitizedMessage,
},
native_loader,
native_token::{sol_to_lamports, LAMPORTS_PER_SOL},
nonce,
pubkey::Pubkey,
rent::Rent,
rent_collector::{RentCollector, RENT_EXEMPT_RENT_EPOCH},
rent_debits::RentDebits,
reserved_account_keys::ReservedAccountKeys,
signature::{Keypair, Signature, Signer},
system_program, system_transaction, sysvar,
transaction::{Result, SanitizedTransaction, Transaction, TransactionError},
transaction_context::{TransactionAccount, TransactionContext},
solana_sdk::rent_collector::{RentCollector, RENT_EXEMPT_RENT_EPOCH},
solana_sdk_ids::{
bpf_loader, bpf_loader_upgradeable, native_loader, system_program, sysvar,
},
solana_signature::Signature,
solana_signer::Signer,
solana_system_transaction::transfer,
solana_transaction::{sanitized::SanitizedTransaction, Transaction},
solana_transaction_context::{TransactionAccount, TransactionContext},
solana_transaction_error::{TransactionError, TransactionResult as Result},
std::{borrow::Cow, cell::RefCell, collections::HashMap, fs::File, io::Read, sync::Arc},
};

Expand Down Expand Up @@ -1134,12 +1136,12 @@ mod tests {
#[test]
fn test_instructions() {
solana_logger::setup();
let instructions_key = solana_sdk::sysvar::instructions::id();
let instructions_key = solana_sdk_ids::sysvar::instructions::id();
let keypair = Keypair::new();
let instructions = vec![CompiledInstruction::new(1, &(), vec![0, 1])];
let tx = Transaction::new_with_compiled_instructions(
&[&keypair],
&[solana_sdk::pubkey::new_rand(), instructions_key],
&[solana_pubkey::new_rand(), instructions_key],
Hash::default(),
vec![native_loader::id()],
instructions,
Expand Down Expand Up @@ -1364,7 +1366,7 @@ mod tests {
#[test]
fn test_construct_instructions_account() {
let loaded_message = LoadedMessage {
message: Cow::Owned(solana_sdk::message::v0::Message::default()),
message: Cow::Owned(solana_message::v0::Message::default()),
loaded_addresses: Cow::Owned(LoadedAddresses::default()),
is_writable_account_cache: vec![false],
};
Expand Down Expand Up @@ -2095,7 +2097,7 @@ mod tests {
.insert(recipient, AccountSharedData::default());
let mut account_loader = (&bank).into();

let tx = system_transaction::transfer(
let tx = transfer(
&mint_keypair,
&recipient,
sol_to_lamports(1.),
Expand Down Expand Up @@ -2471,7 +2473,7 @@ mod tests {
let program1 = program1_keypair.pubkey();
let program2 = Pubkey::new_unique();
let programdata2 = Pubkey::new_unique();
use solana_sdk::account_utils::StateMut;
use solana_account::state_traits::StateMut;

let program2_size = std::mem::size_of::<UpgradeableLoaderState>() as u32;
let mut program2_account = AccountSharedData::default();
Expand Down
6 changes: 3 additions & 3 deletions svm/src/account_overrides.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use {
solana_sdk::{account::AccountSharedData, pubkey::Pubkey, sysvar},
solana_account::AccountSharedData, solana_pubkey::Pubkey, solana_sdk_ids::sysvar,
std::collections::HashMap,
};

Expand Down Expand Up @@ -36,8 +36,8 @@ impl AccountOverrides {
#[cfg(test)]
mod test {
use {
crate::account_overrides::AccountOverrides,
solana_sdk::{account::AccountSharedData, pubkey::Pubkey, sysvar},
crate::account_overrides::AccountOverrides, solana_account::AccountSharedData,
solana_pubkey::Pubkey, solana_sdk_ids::sysvar,
};

#[test]
Expand Down
Loading

0 comments on commit 3deac72

Please sign in to comment.