diff --git a/Cargo.lock b/Cargo.lock index afb8ac3b16..576352d8de 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -227,6 +227,7 @@ dependencies = [ "solana-genesis-utils", "solana-geyser-plugin-manager", "solana-gossip", + "solana-inline-spl", "solana-ledger", "solana-logger", "solana-metrics", @@ -5365,6 +5366,7 @@ dependencies = [ "solana-core", "solana-faucet", "solana-gossip", + "solana-inline-spl", "solana-local-cluster", "solana-logger", "solana-measure", @@ -5418,6 +5420,7 @@ dependencies = [ "solana-bucket-map", "solana-frozen-abi", "solana-frozen-abi-macro", + "solana-inline-spl", "solana-logger", "solana-measure", "solana-metrics", @@ -6293,6 +6296,15 @@ dependencies = [ "thiserror", ] +[[package]] +name = "solana-inline-spl" +version = "2.0.0" +dependencies = [ + "bytemuck", + "rustc_version 0.4.0", + "solana-sdk", +] + [[package]] name = "solana-keygen" version = "2.0.0" @@ -6725,6 +6737,7 @@ dependencies = [ "solana-banks-interface", "solana-banks-server", "solana-bpf-loader-program", + "solana-inline-spl", "solana-logger", "solana-program-runtime", "solana-runtime", @@ -6846,6 +6859,7 @@ dependencies = [ "solana-entry", "solana-faucet", "solana-gossip", + "solana-inline-spl", "solana-ledger", "solana-measure", "solana-metrics", @@ -7024,6 +7038,7 @@ dependencies = [ "solana-cost-model", "solana-frozen-abi", "solana-frozen-abi-macro", + "solana-inline-spl", "solana-loader-v4-program", "solana-logger", "solana-measure", diff --git a/Cargo.toml b/Cargo.toml index 348dfc2847..d9144de2ff 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -40,6 +40,7 @@ members = [ "geyser-plugin-interface", "geyser-plugin-manager", "gossip", + "inline-spl", "install", "keygen", "ledger", @@ -338,6 +339,7 @@ solana-genesis-utils = { path = "genesis-utils", version = "=2.0.0" } agave-geyser-plugin-interface = { path = "geyser-plugin-interface", version = "=2.0.0" } solana-geyser-plugin-manager = { path = "geyser-plugin-manager", version = "=2.0.0" } solana-gossip = { path = "gossip", version = "=2.0.0" } +solana-inline-spl = { path = "inline-spl", version = "=2.0.0" } solana-ledger = { path = "ledger", version = "=2.0.0" } solana-loader-v4-program = { path = "programs/loader-v4", version = "=2.0.0" } solana-local-cluster = { path = "local-cluster", version = "=2.0.0" } diff --git a/accounts-cluster-bench/Cargo.toml b/accounts-cluster-bench/Cargo.toml index 54a4557538..3d8c8c721c 100644 --- a/accounts-cluster-bench/Cargo.toml +++ b/accounts-cluster-bench/Cargo.toml @@ -14,12 +14,12 @@ log = { workspace = true } rand = { workspace = true } rayon = { workspace = true } solana-account-decoder = { workspace = true } -solana-accounts-db = { workspace = true } solana-clap-utils = { workspace = true } solana-cli-config = { workspace = true } solana-client = { workspace = true } solana-faucet = { workspace = true } solana-gossip = { workspace = true } +solana-inline-spl = { workspace = true } solana-logger = { workspace = true } solana-measure = { workspace = true } solana-net-utils = { workspace = true } @@ -32,6 +32,7 @@ solana-version = { workspace = true } spl-token = { workspace = true, features = ["no-entrypoint"] } [dev-dependencies] +solana-accounts-db = { workspace = true } solana-core = { workspace = true } solana-local-cluster = { workspace = true } solana-runtime = { workspace = true, features = ["dev-context-only-utils"] } diff --git a/accounts-cluster-bench/src/main.rs b/accounts-cluster-bench/src/main.rs index 1a945090b3..9e84456011 100644 --- a/accounts-cluster-bench/src/main.rs +++ b/accounts-cluster-bench/src/main.rs @@ -4,13 +4,13 @@ use { log::*, rand::{thread_rng, Rng}, rayon::prelude::*, - solana_accounts_db::inline_spl_token, solana_clap_utils::{ hidden_unless_forced, input_parsers::pubkey_of, input_validators::is_url_or_moniker, }, solana_cli_config::{ConfigInput, CONFIG_FILE}, solana_client::{rpc_request::TokenAccountsFilter, transaction_executor::TransactionExecutor}, solana_gossip::gossip_service::discover, + solana_inline_spl::token, solana_measure::measure::Measure, solana_rpc_client::rpc_client::RpcClient, solana_sdk::{ @@ -143,7 +143,7 @@ fn make_create_message( let instructions: Vec<_> = (0..num_instructions) .flat_map(|_| { let program_id = if mint.is_some() { - inline_spl_token::id() + token::id() } else { system_program::id() }; @@ -190,7 +190,7 @@ fn make_close_message( let instructions: Vec<_> = (0..num_instructions) .filter_map(|_| { let program_id = if spl_token { - inline_spl_token::id() + token::id() } else { system_program::id() }; @@ -465,7 +465,7 @@ fn make_rpc_bench_threads( num_rpc_bench_threads: usize, ) -> Vec> { let program_id = if mint.is_some() { - inline_spl_token::id() + token::id() } else { system_program::id() }; @@ -1055,10 +1055,7 @@ fn main() { pub mod test { use { super::*, - solana_accounts_db::{ - accounts_index::{AccountIndex, AccountSecondaryIndexes}, - inline_spl_token, - }, + solana_accounts_db::accounts_index::{AccountIndex, AccountSecondaryIndexes}, solana_core::validator::ValidatorConfig, solana_faucet::faucet::run_local_faucet, solana_local_cluster::{ @@ -1230,7 +1227,7 @@ pub mod test { &spl_mint_keypair.pubkey(), spl_mint_rent, spl_mint_len as u64, - &inline_spl_token::id(), + &token::id(), ), spl_token::instruction::initialize_mint( &spl_token::id(), diff --git a/accounts-db/Cargo.toml b/accounts-db/Cargo.toml index ff38118806..1a3abb6c04 100644 --- a/accounts-db/Cargo.toml +++ b/accounts-db/Cargo.toml @@ -37,6 +37,7 @@ smallvec = { workspace = true, features = ["const_generics"] } solana-bucket-map = { workspace = true } solana-frozen-abi = { workspace = true } solana-frozen-abi-macro = { workspace = true } +solana-inline-spl = { workspace = true } solana-measure = { workspace = true } solana-metrics = { workspace = true } solana-nohash-hasher = { workspace = true } diff --git a/accounts-db/src/accounts_db.rs b/accounts-db/src/accounts_db.rs index 54a8082af3..4819838b4c 100644 --- a/accounts-db/src/accounts_db.rs +++ b/accounts-db/src/accounts_db.rs @@ -9477,7 +9477,6 @@ pub mod tests { ancient_append_vecs, append_vec::{test_utils::TempFile, AppendVecStoredAccountMeta}, cache_hash_data::CacheHashDataFile, - inline_spl_token, }, assert_matches::assert_matches, itertools::Itertools, @@ -11597,14 +11596,15 @@ pub mod tests { // Set up account to be added to secondary index let mint_key = Pubkey::new_unique(); - let mut account_data_with_mint = vec![0; inline_spl_token::Account::get_packed_len()]; + let mut account_data_with_mint = + vec![0; solana_inline_spl::token::Account::get_packed_len()]; account_data_with_mint[..PUBKEY_BYTES].clone_from_slice(&(mint_key.to_bytes())); let mut normal_account = AccountSharedData::new(1, 0, AccountSharedData::default().owner()); - normal_account.set_owner(inline_spl_token::id()); + normal_account.set_owner(solana_inline_spl::token::id()); normal_account.set_data(account_data_with_mint.clone()); let mut zero_account = AccountSharedData::new(0, 0, AccountSharedData::default().owner()); - zero_account.set_owner(inline_spl_token::id()); + zero_account.set_owner(solana_inline_spl::token::id()); zero_account.set_data(account_data_with_mint); //store an account diff --git a/accounts-db/src/accounts_index.rs b/accounts-db/src/accounts_index.rs index 04426251f7..a0eac93c99 100644 --- a/accounts-db/src/accounts_index.rs +++ b/accounts-db/src/accounts_index.rs @@ -6,8 +6,6 @@ use { ancestors::Ancestors, bucket_map_holder::{Age, AtomicAge, BucketMapHolder}, contains::Contains, - inline_spl_token::{self, GenericTokenAccount}, - inline_spl_token_2022, pubkey_bins::PubkeyBinCalculator24, rolling_bit_field::RollingBitField, secondary_index::*, @@ -1468,7 +1466,7 @@ impl + Into> AccountsIndex { max_root } - fn update_spl_token_secondary_indexes( + fn update_spl_token_secondary_indexes( &self, token_id: &Pubkey, pubkey: &Pubkey, @@ -1559,15 +1557,15 @@ impl + Into> AccountsIndex { // (as persisted tombstone for snapshots). This will then ultimately be // filtered out by post-scan filters, like in `get_filtered_spl_token_accounts_by_owner()`. - self.update_spl_token_secondary_indexes::( - &inline_spl_token::id(), + self.update_spl_token_secondary_indexes::( + &solana_inline_spl::token::id(), pubkey, account_owner, account_data, account_indexes, ); - self.update_spl_token_secondary_indexes::( - &inline_spl_token_2022::id(), + self.update_spl_token_secondary_indexes::( + &solana_inline_spl::token_2022::id(), pubkey, account_owner, account_data, @@ -2016,7 +2014,7 @@ impl + Into> AccountsIndex { pub mod tests { use { super::*, - crate::inline_spl_token::*, + solana_inline_spl::token::SPL_TOKEN_ACCOUNT_OWNER_OFFSET, solana_sdk::{ account::{AccountSharedData, WritableAccount}, pubkey::PUBKEY_BYTES, @@ -2024,6 +2022,11 @@ pub mod tests { std::ops::RangeInclusive, }; + const SPL_TOKENS: &[Pubkey] = &[ + solana_inline_spl::token::id(), + solana_inline_spl::token_2022::id(), + ]; + pub enum SecondaryIndexTypes<'a> { RwLock(&'a SecondaryIndex), DashMap(&'a SecondaryIndex), @@ -3362,6 +3365,10 @@ pub mod tests { ); } + fn make_empty_token_account_data() -> Vec { + vec![0; solana_inline_spl::token::Account::get_packed_len()] + } + fn run_test_purge_exact_secondary_index< SecondaryIndexEntryType: SecondaryIndexEntry + Default + Sync + Send, >( @@ -3376,7 +3383,7 @@ pub mod tests { let index_key = Pubkey::new_unique(); let account_key = Pubkey::new_unique(); - let mut account_data = vec![0; inline_spl_token::Account::get_packed_len()]; + let mut account_data = make_empty_token_account_data(); account_data[key_start..key_end].clone_from_slice(&(index_key.to_bytes())); // Insert slots into secondary index @@ -3389,7 +3396,7 @@ pub mod tests { &AccountSharedData::create( 0, account_data.to_vec(), - inline_spl_token::id(), + solana_inline_spl::token::id(), false, 0, ), @@ -3558,7 +3565,7 @@ pub mod tests { let mut secondary_indexes = secondary_indexes.clone(); let account_key = Pubkey::new_unique(); let index_key = Pubkey::new_unique(); - let mut account_data = vec![0; inline_spl_token::Account::get_packed_len()]; + let mut account_data = make_empty_token_account_data(); account_data[key_start..key_end].clone_from_slice(&(index_key.to_bytes())); // Wrong program id @@ -3650,9 +3657,9 @@ pub mod tests { fn test_dashmap_secondary_index() { let (key_start, key_end, secondary_indexes) = create_dashmap_secondary_index_state(); let index = AccountsIndex::::default_for_tests(); - for token_id in [inline_spl_token::id(), inline_spl_token_2022::id()] { + for token_id in SPL_TOKENS { run_test_spl_token_secondary_indexes( - &token_id, + token_id, &index, &index.spl_token_mint_index, key_start, @@ -3666,9 +3673,9 @@ pub mod tests { fn test_rwlock_secondary_index() { let (key_start, key_end, secondary_indexes) = create_rwlock_secondary_index_state(); let index = AccountsIndex::::default_for_tests(); - for token_id in [inline_spl_token::id(), inline_spl_token_2022::id()] { + for token_id in SPL_TOKENS { run_test_spl_token_secondary_indexes( - &token_id, + token_id, &index, &index.spl_token_owner_index, key_start, @@ -3692,10 +3699,10 @@ pub mod tests { let secondary_key1 = Pubkey::new_unique(); let secondary_key2 = Pubkey::new_unique(); let slot = 1; - let mut account_data1 = vec![0; inline_spl_token::Account::get_packed_len()]; + let mut account_data1 = make_empty_token_account_data(); account_data1[index_key_start..index_key_end] .clone_from_slice(&(secondary_key1.to_bytes())); - let mut account_data2 = vec![0; inline_spl_token::Account::get_packed_len()]; + let mut account_data2 = make_empty_token_account_data(); account_data2[index_key_start..index_key_end] .clone_from_slice(&(secondary_key2.to_bytes())); @@ -3771,9 +3778,9 @@ pub mod tests { fn test_dashmap_secondary_index_same_slot_and_forks() { let (key_start, key_end, account_index) = create_dashmap_secondary_index_state(); let index = AccountsIndex::::default_for_tests(); - for token_id in [inline_spl_token::id(), inline_spl_token_2022::id()] { + for token_id in SPL_TOKENS { run_test_secondary_indexes_same_slot_and_forks( - &token_id, + token_id, &index, &index.spl_token_mint_index, key_start, @@ -3787,9 +3794,9 @@ pub mod tests { fn test_rwlock_secondary_index_same_slot_and_forks() { let (key_start, key_end, account_index) = create_rwlock_secondary_index_state(); let index = AccountsIndex::::default_for_tests(); - for token_id in [inline_spl_token::id(), inline_spl_token_2022::id()] { + for token_id in SPL_TOKENS { run_test_secondary_indexes_same_slot_and_forks( - &token_id, + token_id, &index, &index.spl_token_owner_index, key_start, diff --git a/accounts-db/src/lib.rs b/accounts-db/src/lib.rs index 7883f852d1..6a50eb1b0e 100644 --- a/accounts-db/src/lib.rs +++ b/accounts-db/src/lib.rs @@ -27,8 +27,6 @@ pub mod cache_hash_data_stats; pub mod contains; pub mod epoch_accounts_hash; pub mod hardened_unpack; -pub mod inline_spl_token; -pub mod inline_spl_token_2022; pub mod partitioned_rewards; mod pubkey_bins; mod read_only_accounts_cache; diff --git a/inline-spl/Cargo.toml b/inline-spl/Cargo.toml new file mode 100644 index 0000000000..e3ca8d0635 --- /dev/null +++ b/inline-spl/Cargo.toml @@ -0,0 +1,26 @@ +[package] +name = "solana-inline-spl" +description = "Limited types and ids from the Solana Program Library" +documentation = "https://docs.rs/solana-inline-spl" +version = { workspace = true } +authors = { workspace = true } +repository = { workspace = true } +homepage = { workspace = true } +license = { workspace = true } +edition = { workspace = true } + +[dependencies] +bytemuck = { workspace = true } +solana-sdk = { workspace = true } + +[lib] +crate-type = ["lib"] +name = "solana_inline_spl" + +[dev-dependencies] + +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] + +[build-dependencies] +rustc_version = { workspace = true } diff --git a/runtime/src/inline_spl_associated_token_account.rs b/inline-spl/src/associated_token_account.rs similarity index 89% rename from runtime/src/inline_spl_associated_token_account.rs rename to inline-spl/src/associated_token_account.rs index 6052d9a700..9057bee384 100644 --- a/runtime/src/inline_spl_associated_token_account.rs +++ b/inline-spl/src/associated_token_account.rs @@ -1,6 +1,6 @@ // Partial SPL Associated Token Account declarations inlined to avoid an external dependency on the spl-associated-token-account crate solana_sdk::declare_id!("ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"); -pub(crate) mod program_v1_1_0 { +pub mod program_v1_1_0 { solana_sdk::declare_id!("NatA1Zyo48dJ7yuwR7cGURwhskKA8ywUyxb9GvG7mTC"); } diff --git a/inline-spl/src/lib.rs b/inline-spl/src/lib.rs new file mode 100644 index 0000000000..4cceddeaf3 --- /dev/null +++ b/inline-spl/src/lib.rs @@ -0,0 +1,3 @@ +pub mod associated_token_account; +pub mod token; +pub mod token_2022; diff --git a/accounts-db/src/inline_spl_token.rs b/inline-spl/src/token.rs similarity index 97% rename from accounts-db/src/inline_spl_token.rs rename to inline-spl/src/token.rs index 0e936c5f40..a15822932c 100644 --- a/accounts-db/src/inline_spl_token.rs +++ b/inline-spl/src/token.rs @@ -38,7 +38,7 @@ pub trait GenericTokenAccount { // Call after account length has already been verified fn unpack_pubkey_unchecked(account_data: &[u8], offset: usize) -> &Pubkey { - bytemuck::from_bytes(&account_data[offset..offset + PUBKEY_BYTES]) + bytemuck::from_bytes(&account_data[offset..offset.wrapping_add(PUBKEY_BYTES)]) } fn unpack_account_owner(account_data: &[u8]) -> Option<&Pubkey> { diff --git a/accounts-db/src/inline_spl_token_2022.rs b/inline-spl/src/token_2022.rs similarity index 72% rename from accounts-db/src/inline_spl_token_2022.rs rename to inline-spl/src/token_2022.rs index a16dccc893..1787fa8176 100644 --- a/accounts-db/src/inline_spl_token_2022.rs +++ b/inline-spl/src/token_2022.rs @@ -1,5 +1,5 @@ /// Partial SPL Token declarations inlined to avoid an external dependency on the spl-token-2022 crate -use crate::inline_spl_token::{self, GenericTokenAccount}; +use crate::token::{self, GenericTokenAccount}; solana_sdk::declare_id!("TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb"); @@ -9,10 +9,10 @@ pub const ACCOUNTTYPE_ACCOUNT: u8 = 2; pub struct Account; impl GenericTokenAccount for Account { fn valid_account_data(account_data: &[u8]) -> bool { - inline_spl_token::Account::valid_account_data(account_data) + token::Account::valid_account_data(account_data) || ACCOUNTTYPE_ACCOUNT == *account_data - .get(inline_spl_token::Account::get_packed_len()) + .get(token::Account::get_packed_len()) .unwrap_or(&0) } } diff --git a/program-test/Cargo.toml b/program-test/Cargo.toml index b8b4fcdb33..1456d0dcca 100644 --- a/program-test/Cargo.toml +++ b/program-test/Cargo.toml @@ -22,6 +22,7 @@ solana-banks-client = { workspace = true } solana-banks-interface = { workspace = true } solana-banks-server = { workspace = true } solana-bpf-loader-program = { workspace = true } +solana-inline-spl = { workspace = true } solana-logger = { workspace = true } solana-program-runtime = { workspace = true } solana-runtime = { workspace = true } diff --git a/program-test/src/programs.rs b/program-test/src/programs.rs index 8d9a42790f..3046a713a3 100644 --- a/program-test/src/programs.rs +++ b/program-test/src/programs.rs @@ -5,30 +5,20 @@ use solana_sdk::{ rent::Rent, }; -mod spl_token { - solana_sdk::declare_id!("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"); -} -mod spl_token_2022 { - solana_sdk::declare_id!("TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb"); -} mod spl_memo_1_0 { solana_sdk::declare_id!("Memo1UhkJRfHyvLMcVucJwxXeuD728EqVDDwQDxFMNo"); } mod spl_memo_3_0 { solana_sdk::declare_id!("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"); } -mod spl_associated_token_account { - solana_sdk::declare_id!("ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"); -} - static SPL_PROGRAMS: &[(Pubkey, Pubkey, &[u8])] = &[ ( - spl_token::ID, + solana_inline_spl::token::ID, solana_sdk::bpf_loader::ID, include_bytes!("programs/spl_token-3.5.0.so"), ), ( - spl_token_2022::ID, + solana_inline_spl::token_2022::ID, solana_sdk::bpf_loader_upgradeable::ID, include_bytes!("programs/spl_token_2022-1.0.0.so"), ), @@ -43,7 +33,7 @@ static SPL_PROGRAMS: &[(Pubkey, Pubkey, &[u8])] = &[ include_bytes!("programs/spl_memo-3.0.0.so"), ), ( - spl_associated_token_account::ID, + solana_inline_spl::associated_token_account::ID, solana_sdk::bpf_loader::ID, include_bytes!("programs/spl_associated_token_account-1.1.1.so"), ), diff --git a/program-test/tests/compute_units.rs b/program-test/tests/compute_units.rs index 750f7eecfc..bcbdd0b252 100644 --- a/program-test/tests/compute_units.rs +++ b/program-test/tests/compute_units.rs @@ -2,7 +2,6 @@ use { solana_program_test::ProgramTest, solana_sdk::{ instruction::{AccountMeta, Instruction}, - pubkey::Pubkey, signature::{Keypair, Signer}, system_instruction, sysvar::rent, @@ -26,7 +25,7 @@ async fn max_compute_units() { // Invalid compute unit maximums are only triggered by BPF programs, so send // a valid instruction into a BPF program to make sure the issue doesn't // manifest. - let token_2022_id = Pubkey::try_from("TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb").unwrap(); + let token_2022_id = solana_inline_spl::token_2022::id(); let mint = Keypair::new(); let rent = context.banks_client.get_rent().await.unwrap(); let space = 82; diff --git a/program-test/tests/realloc.rs b/program-test/tests/realloc.rs index 00e2d768f7..14a93439e8 100644 --- a/program-test/tests/realloc.rs +++ b/program-test/tests/realloc.rs @@ -52,7 +52,7 @@ async fn realloc_smaller_in_cpi() { ); let mut context = program_test.start_with_context().await; - let token_2022_id = Pubkey::try_from("TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb").unwrap(); + let token_2022_id = solana_inline_spl::token_2022::id(); let mint = Keypair::new(); let account = Keypair::new(); let rent = context.banks_client.get_rent().await.unwrap(); diff --git a/program-test/tests/spl.rs b/program-test/tests/spl.rs index a97cdc51bd..fc6deff7ca 100644 --- a/program-test/tests/spl.rs +++ b/program-test/tests/spl.rs @@ -16,7 +16,7 @@ use { async fn programs_present() { let (mut banks_client, _, _) = ProgramTest::default().start().await; let rent = banks_client.get_rent().await.unwrap(); - let token_2022_id = Pubkey::try_from("TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb").unwrap(); + let token_2022_id = solana_inline_spl::token_2022::id(); let (token_2022_programdata_id, _) = Pubkey::find_program_address(&[token_2022_id.as_ref()], &bpf_loader_upgradeable::id()); @@ -34,7 +34,7 @@ async fn programs_present() { async fn token_2022() { let (mut banks_client, payer, recent_blockhash) = ProgramTest::default().start().await; - let token_2022_id = Pubkey::try_from("TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb").unwrap(); + let token_2022_id = solana_inline_spl::token_2022::id(); let mint = Keypair::new(); let rent = banks_client.get_rent().await.unwrap(); let space = 82; diff --git a/programs/sbf/Cargo.lock b/programs/sbf/Cargo.lock index 414dd6b0ad..6ce4b5570c 100644 --- a/programs/sbf/Cargo.lock +++ b/programs/sbf/Cargo.lock @@ -4657,6 +4657,7 @@ dependencies = [ "solana-bucket-map", "solana-frozen-abi", "solana-frozen-abi-macro", + "solana-inline-spl", "solana-measure", "solana-metrics", "solana-nohash-hasher", @@ -5182,6 +5183,15 @@ dependencies = [ "thiserror", ] +[[package]] +name = "solana-inline-spl" +version = "2.0.0" +dependencies = [ + "bytemuck", + "rustc_version", + "solana-sdk", +] + [[package]] name = "solana-ledger" version = "2.0.0" @@ -5462,6 +5472,7 @@ dependencies = [ "solana-banks-interface", "solana-banks-server", "solana-bpf-loader-program", + "solana-inline-spl", "solana-logger", "solana-program-runtime", "solana-runtime", @@ -5575,6 +5586,7 @@ dependencies = [ "solana-entry", "solana-faucet", "solana-gossip", + "solana-inline-spl", "solana-ledger", "solana-measure", "solana-metrics", @@ -5707,6 +5719,7 @@ dependencies = [ "solana-cost-model", "solana-frozen-abi", "solana-frozen-abi-macro", + "solana-inline-spl", "solana-loader-v4-program", "solana-measure", "solana-metrics", diff --git a/rpc/Cargo.toml b/rpc/Cargo.toml index d4f2648b6b..2a0c5c480d 100644 --- a/rpc/Cargo.toml +++ b/rpc/Cargo.toml @@ -35,6 +35,7 @@ solana-client = { workspace = true } solana-entry = { workspace = true } solana-faucet = { workspace = true } solana-gossip = { workspace = true } +solana-inline-spl = { workspace = true } solana-ledger = { workspace = true } solana-measure = { workspace = true } solana-metrics = { workspace = true } diff --git a/rpc/src/rpc.rs b/rpc/src/rpc.rs index f0856aeae4..4c8bacfa95 100644 --- a/rpc/src/rpc.rs +++ b/rpc/src/rpc.rs @@ -16,13 +16,15 @@ use { solana_accounts_db::{ accounts::AccountAddressFilter, accounts_index::{AccountIndex, AccountSecondaryIndexes, IndexKey, ScanConfig}, - inline_spl_token::{SPL_TOKEN_ACCOUNT_MINT_OFFSET, SPL_TOKEN_ACCOUNT_OWNER_OFFSET}, - inline_spl_token_2022::{self, ACCOUNTTYPE_ACCOUNT}, }, solana_client::connection_cache::{ConnectionCache, Protocol}, solana_entry::entry::Entry, solana_faucet::faucet::request_airdrop_transaction, solana_gossip::{cluster_info::ClusterInfo, contact_info::ContactInfo}, + solana_inline_spl::{ + token::{SPL_TOKEN_ACCOUNT_MINT_OFFSET, SPL_TOKEN_ACCOUNT_OWNER_OFFSET}, + token_2022::{self, ACCOUNTTYPE_ACCOUNT}, + }, solana_ledger::{ blockstore::{Blockstore, SignatureInfosForAddress}, blockstore_db::BlockstoreError, @@ -2388,7 +2390,7 @@ fn get_spl_token_owner_filter(program_id: &Pubkey, filters: &[RpcFilterType]) -> offset, bytes: MemcmpEncodedBytes::Bytes(bytes), .. - }) if *offset == account_packed_len && *program_id == inline_spl_token_2022::id() => { + }) if *offset == account_packed_len && *program_id == token_2022::id() => { memcmp_filter = Some(bytes) } #[allow(deprecated)] @@ -2446,7 +2448,7 @@ fn get_spl_token_mint_filter(program_id: &Pubkey, filters: &[RpcFilterType]) -> offset, bytes: MemcmpEncodedBytes::Bytes(bytes), .. - }) if *offset == account_packed_len && *program_id == inline_spl_token_2022::id() => { + }) if *offset == account_packed_len && *program_id == token_2022::id() => { memcmp_filter = Some(bytes) } #[allow(deprecated)] @@ -4720,7 +4722,6 @@ pub mod tests { jsonrpc_core::{futures, ErrorCode, MetaIoHandler, Output, Response, Value}, jsonrpc_core_client::transports::local, serde::de::DeserializeOwned, - solana_accounts_db::{inline_spl_token, inline_spl_token_2022}, solana_entry::entry::next_versioned_entry, solana_gossip::socketaddr, solana_ledger::{ @@ -7891,7 +7892,7 @@ pub mod tests { let token_account_pubkey = solana_sdk::pubkey::new_rand(); let token_with_different_mint_pubkey = solana_sdk::pubkey::new_rand(); let new_mint = SplTokenPubkey::new_from_array([5; 32]); - if program_id == inline_spl_token_2022::id() { + if program_id == solana_inline_spl::token_2022::id() { // Add the token account let account_base = TokenAccount { mint, @@ -8148,7 +8149,7 @@ pub mod tests { .expect("actual response deserialization"); let accounts: Vec = serde_json::from_value(result["result"].clone()).unwrap(); - if program_id == inline_spl_token::id() { + if program_id == solana_inline_spl::token::id() { // native mint is included for token-v3 assert_eq!(accounts.len(), 4); } else { @@ -8386,7 +8387,7 @@ pub mod tests { let delegate = SplTokenPubkey::new_from_array([4; 32]); let token_account_pubkey = solana_sdk::pubkey::new_rand(); let (program_name, account_size, mint_size) = if program_id - == inline_spl_token_2022::id() + == solana_inline_spl::token_2022::id() { let account_base = TokenAccount { mint, @@ -8539,7 +8540,7 @@ pub mod tests { } } }); - if program_id == inline_spl_token_2022::id() { + if program_id == solana_inline_spl::token_2022::id() { expected_value["parsed"]["info"]["extensions"] = json!([ { "extension": "immutableOwner" @@ -8575,7 +8576,7 @@ pub mod tests { } } }); - if program_id == inline_spl_token_2022::id() { + if program_id == solana_inline_spl::token_2022::id() { expected_value["parsed"]["info"]["extensions"] = json!([ { "extension": "mintCloseAuthority", @@ -8595,7 +8596,7 @@ pub mod tests { let owner = Pubkey::new_unique(); assert_eq!( get_spl_token_owner_filter( - &Pubkey::from_str("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA").unwrap(), + &spl_token::id(), &[ RpcFilterType::Memcmp(Memcmp::new_raw_bytes(32, owner.to_bytes().to_vec())), RpcFilterType::DataSize(165) @@ -8608,7 +8609,7 @@ pub mod tests { // Filtering on token-2022 account type assert_eq!( get_spl_token_owner_filter( - &Pubkey::from_str("TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb").unwrap(), + &token_2022::id(), &[ RpcFilterType::Memcmp(Memcmp::new_raw_bytes(32, owner.to_bytes().to_vec())), RpcFilterType::Memcmp(Memcmp::new_raw_bytes(165, vec![ACCOUNTTYPE_ACCOUNT])), @@ -8621,7 +8622,7 @@ pub mod tests { // Filtering on token account state assert_eq!( get_spl_token_owner_filter( - &Pubkey::from_str("TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb").unwrap(), + &token_2022::id(), &[ RpcFilterType::Memcmp(Memcmp::new_raw_bytes(32, owner.to_bytes().to_vec())), RpcFilterType::TokenAccountState, @@ -8633,7 +8634,7 @@ pub mod tests { // Can't filter on account type for token-v3 assert!(get_spl_token_owner_filter( - &Pubkey::from_str("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA").unwrap(), + &solana_inline_spl::token::id(), &[ RpcFilterType::Memcmp(Memcmp::new_raw_bytes(32, owner.to_bytes().to_vec())), RpcFilterType::Memcmp(Memcmp::new_raw_bytes(165, vec![ACCOUNTTYPE_ACCOUNT])), @@ -8643,7 +8644,7 @@ pub mod tests { // Filtering on mint instead of owner assert!(get_spl_token_owner_filter( - &Pubkey::from_str("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA").unwrap(), + &solana_inline_spl::token::id(), &[ RpcFilterType::Memcmp(Memcmp::new_raw_bytes(0, owner.to_bytes().to_vec())), RpcFilterType::DataSize(165) @@ -8676,7 +8677,7 @@ pub mod tests { let mint = Pubkey::new_unique(); assert_eq!( get_spl_token_mint_filter( - &Pubkey::from_str("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA").unwrap(), + &solana_inline_spl::token::id(), &[ RpcFilterType::Memcmp(Memcmp::new_raw_bytes(0, mint.to_bytes().to_vec())), RpcFilterType::DataSize(165) @@ -8689,7 +8690,7 @@ pub mod tests { // Filtering on token-2022 account type assert_eq!( get_spl_token_mint_filter( - &Pubkey::from_str("TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb").unwrap(), + &solana_inline_spl::token_2022::id(), &[ RpcFilterType::Memcmp(Memcmp::new_raw_bytes(0, mint.to_bytes().to_vec())), RpcFilterType::Memcmp(Memcmp::new_raw_bytes(165, vec![ACCOUNTTYPE_ACCOUNT])), @@ -8702,7 +8703,7 @@ pub mod tests { // Filtering on token account state assert_eq!( get_spl_token_mint_filter( - &Pubkey::from_str("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA").unwrap(), + &solana_inline_spl::token::id(), &[ RpcFilterType::Memcmp(Memcmp::new_raw_bytes(0, mint.to_bytes().to_vec())), RpcFilterType::TokenAccountState, @@ -8714,7 +8715,7 @@ pub mod tests { // Can't filter on account type for token-v3 assert!(get_spl_token_mint_filter( - &Pubkey::from_str("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA").unwrap(), + &solana_inline_spl::token::id(), &[ RpcFilterType::Memcmp(Memcmp::new_raw_bytes(0, mint.to_bytes().to_vec())), RpcFilterType::Memcmp(Memcmp::new_raw_bytes(165, vec![ACCOUNTTYPE_ACCOUNT])), @@ -8724,7 +8725,7 @@ pub mod tests { // Filtering on owner instead of mint assert!(get_spl_token_mint_filter( - &Pubkey::from_str("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA").unwrap(), + &solana_inline_spl::token::id(), &[ RpcFilterType::Memcmp(Memcmp::new_raw_bytes(32, mint.to_bytes().to_vec())), RpcFilterType::DataSize(165) diff --git a/rpc/src/rpc_subscription_tracker.rs b/rpc/src/rpc_subscription_tracker.rs index 97ceb57663..0d6c7a0c10 100644 --- a/rpc/src/rpc_subscription_tracker.rs +++ b/rpc/src/rpc_subscription_tracker.rs @@ -595,7 +595,6 @@ mod tests { crate::rpc_pubsub_service::PubSubConfig, solana_ledger::genesis_utils::{create_genesis_config, GenesisConfigInfo}, solana_runtime::bank::Bank, - std::str::FromStr, }; struct ControlWrapper { @@ -715,7 +714,7 @@ mod tests { assert_eq!(*info.last_notified_slot.read().unwrap(), 0); let account_params = SubscriptionParams::Account(AccountSubscriptionParams { - pubkey: Pubkey::from_str("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA").unwrap(), + pubkey: solana_inline_spl::token::id(), commitment: CommitmentConfig::finalized(), encoding: UiAccountEncoding::Base64Zstd, data_slice: None, @@ -755,7 +754,7 @@ mod tests { assert_eq!(counts(&tracker), (0, 0, 0, 0)); let account_params = SubscriptionParams::Account(AccountSubscriptionParams { - pubkey: Pubkey::from_str("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA").unwrap(), + pubkey: solana_inline_spl::token::id(), commitment: CommitmentConfig::finalized(), encoding: UiAccountEncoding::Base64Zstd, data_slice: None, @@ -766,7 +765,7 @@ mod tests { assert_eq!(counts(&tracker), (0, 0, 0, 0)); let account_params2 = SubscriptionParams::Account(AccountSubscriptionParams { - pubkey: Pubkey::from_str("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA").unwrap(), + pubkey: solana_inline_spl::token::id(), commitment: CommitmentConfig::confirmed(), encoding: UiAccountEncoding::Base64Zstd, data_slice: None, diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index d4e554a5a8..f5ec09fa67 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -55,6 +55,7 @@ solana-config-program = { workspace = true } solana-cost-model = { workspace = true } solana-frozen-abi = { workspace = true } solana-frozen-abi-macro = { workspace = true } +solana-inline-spl = { workspace = true } solana-loader-v4-program = { workspace = true } solana-measure = { workspace = true } solana-metrics = { workspace = true } diff --git a/runtime/src/bank/tests.rs b/runtime/src/bank/tests.rs index 0fdfb96814..dc3a312155 100644 --- a/runtime/src/bank/tests.rs +++ b/runtime/src/bank/tests.rs @@ -33,9 +33,9 @@ use { }, accounts_partition::{self, PartitionIndex, RentPayingAccountsByPartition}, ancestors::Ancestors, - inline_spl_token, partitioned_rewards::TestPartitionedEpochRewards, }, + solana_inline_spl::token, solana_logger, solana_program_runtime::{ compute_budget::ComputeBudget, @@ -7099,15 +7099,10 @@ fn test_reconfigure_token2_native_mint() { let genesis_config = create_genesis_config_with_leader(5, &solana_sdk::pubkey::new_rand(), 0).genesis_config; let bank = Arc::new(Bank::new_for_tests(&genesis_config)); - assert_eq!( - bank.get_balance(&inline_spl_token::native_mint::id()), - 1000000000 - ); - let native_mint_account = bank - .get_account(&inline_spl_token::native_mint::id()) - .unwrap(); + assert_eq!(bank.get_balance(&token::native_mint::id()), 1000000000); + let native_mint_account = bank.get_account(&token::native_mint::id()).unwrap(); assert_eq!(native_mint_account.data().len(), 82); - assert_eq!(native_mint_account.owner(), &inline_spl_token::id()); + assert_eq!(native_mint_account.owner(), &token::id()); } #[test] diff --git a/runtime/src/genesis_utils.rs b/runtime/src/genesis_utils.rs index 81cbf2c198..379750b174 100644 --- a/runtime/src/genesis_utils.rs +++ b/runtime/src/genesis_utils.rs @@ -1,5 +1,4 @@ use { - solana_accounts_db::inline_spl_token, solana_sdk::{ account::{Account, AccountSharedData}, feature::{self, Feature}, @@ -256,13 +255,16 @@ pub fn create_genesis_config_with_leader_ex( initial_accounts.push((*validator_stake_account_pubkey, validator_stake_account)); let native_mint_account = solana_sdk::account::AccountSharedData::from(Account { - owner: inline_spl_token::id(), - data: inline_spl_token::native_mint::ACCOUNT_DATA.to_vec(), + owner: solana_inline_spl::token::id(), + data: solana_inline_spl::token::native_mint::ACCOUNT_DATA.to_vec(), lamports: sol_to_lamports(1.), executable: false, rent_epoch: 1, }); - initial_accounts.push((inline_spl_token::native_mint::id(), native_mint_account)); + initial_accounts.push(( + solana_inline_spl::token::native_mint::id(), + native_mint_account, + )); let mut genesis_config = GenesisConfig { accounts: initial_accounts diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 57936c2c7e..12eab54a41 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -14,7 +14,6 @@ pub mod compute_budget_details; mod epoch_rewards_hasher; pub mod epoch_stakes; pub mod genesis_utils; -pub mod inline_spl_associated_token_account; pub mod installed_scheduler_pool; pub mod loader_utils; pub mod non_circulating_supply; diff --git a/runtime/src/static_ids.rs b/runtime/src/static_ids.rs index 4cedf3b847..b7a8a5b5e2 100644 --- a/runtime/src/static_ids.rs +++ b/runtime/src/static_ids.rs @@ -1,16 +1,15 @@ use { - crate::inline_spl_associated_token_account, - solana_accounts_db::{inline_spl_token, inline_spl_token_2022}, + solana_inline_spl::{associated_token_account, token, token_2022}, solana_sdk::pubkey::Pubkey, }; lazy_static! { /// Vector of static token & mint IDs pub static ref STATIC_IDS: Vec = vec![ - inline_spl_associated_token_account::id(), - inline_spl_associated_token_account::program_v1_1_0::id(), - inline_spl_token::id(), - inline_spl_token::native_mint::id(), - inline_spl_token_2022::id(), + associated_token_account::id(), + associated_token_account::program_v1_1_0::id(), + token::id(), + token::native_mint::id(), + token_2022::id(), ]; } diff --git a/validator/Cargo.toml b/validator/Cargo.toml index 0a6324f454..6222435906 100644 --- a/validator/Cargo.toml +++ b/validator/Cargo.toml @@ -70,6 +70,7 @@ tokio = { workspace = true } [dev-dependencies] solana-account-decoder = { workspace = true } +solana-inline-spl = { workspace = true } solana-runtime = { workspace = true, features = ["dev-context-only-utils"] } spl-token-2022 = { workspace = true, features = ["no-entrypoint"] } diff --git a/validator/src/admin_rpc_service.rs b/validator/src/admin_rpc_service.rs index b6d65e3ec4..99ef4b53a0 100644 --- a/validator/src/admin_rpc_service.rs +++ b/validator/src/admin_rpc_service.rs @@ -860,9 +860,10 @@ mod tests { use { super::*, serde_json::Value, - solana_accounts_db::{accounts_index::AccountSecondaryIndexes, inline_spl_token}, + solana_accounts_db::accounts_index::AccountSecondaryIndexes, solana_core::consensus::tower_storage::NullTowerStorage, solana_gossip::cluster_info::ClusterInfo, + solana_inline_spl::token, solana_ledger::genesis_utils::{create_genesis_config, GenesisConfigInfo}, solana_rpc::rpc::create_validator_exit, solana_runtime::{ @@ -1020,7 +1021,7 @@ mod tests { // Count SPL Token Program Default Accounts let req = format!( r#"{{"jsonrpc":"2.0","id":1,"method":"getSecondaryIndexKeySize","params":["{}"]}}"#, - inline_spl_token::id(), + token::id(), ); let res = io.handle_request_sync(&req, meta.clone()); let result: Value = serde_json::from_str(&res.expect("actual response")) @@ -1075,7 +1076,7 @@ mod tests { let token_account1 = AccountSharedData::from(Account { lamports: 111, data: account1_data.to_vec(), - owner: inline_spl_token::id(), + owner: token::id(), ..Account::default() }); bank.store_account(&token_account1_pubkey, &token_account1); @@ -1093,7 +1094,7 @@ mod tests { let mint_account1 = AccountSharedData::from(Account { lamports: 222, data: mint1_data.to_vec(), - owner: inline_spl_token::id(), + owner: token::id(), ..Account::default() }); bank.store_account(&mint1_pubkey, &mint_account1); @@ -1114,7 +1115,7 @@ mod tests { let token_account2 = AccountSharedData::from(Account { lamports: 333, data: account2_data.to_vec(), - owner: inline_spl_token::id(), + owner: token::id(), ..Account::default() }); bank.store_account(&token_account2_pubkey, &token_account2); @@ -1135,7 +1136,7 @@ mod tests { let token_account3 = AccountSharedData::from(Account { lamports: 444, data: account3_data.to_vec(), - owner: inline_spl_token::id(), + owner: token::id(), ..Account::default() }); bank.store_account(&token_account3_pubkey, &token_account3); @@ -1153,7 +1154,7 @@ mod tests { let mint_account2 = AccountSharedData::from(Account { lamports: 555, data: mint2_data.to_vec(), - owner: inline_spl_token::id(), + owner: token::id(), ..Account::default() }); bank.store_account(&mint2_pubkey, &mint_account2); @@ -1233,7 +1234,7 @@ mod tests { // 5) SPL Token Program Owns 6 Accounts - 1 Default, 5 created above. let req = format!( r#"{{"jsonrpc":"2.0","id":1,"method":"getSecondaryIndexKeySize","params":["{}"]}}"#, - inline_spl_token::id(), + token::id(), ); let res = io.handle_request_sync(&req, meta.clone()); let result: Value = serde_json::from_str(&res.expect("actual response"))