Skip to content

Commit

Permalink
Remove duplicated token ids and use a shared inline-spl crate (#456)
Browse files Browse the repository at this point in the history
  • Loading branch information
sakridge authored Apr 1, 2024
1 parent 3c8da0d commit e0e6596
Show file tree
Hide file tree
Showing 29 changed files with 165 additions and 113 deletions.
15 changes: 15 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ members = [
"geyser-plugin-interface",
"geyser-plugin-manager",
"gossip",
"inline-spl",
"install",
"keygen",
"ledger",
Expand Down Expand Up @@ -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" }
Expand Down
3 changes: 2 additions & 1 deletion accounts-cluster-bench/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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"] }
Expand Down
15 changes: 6 additions & 9 deletions accounts-cluster-bench/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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()
};
Expand Down Expand Up @@ -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()
};
Expand Down Expand Up @@ -465,7 +465,7 @@ fn make_rpc_bench_threads(
num_rpc_bench_threads: usize,
) -> Vec<JoinHandle<()>> {
let program_id = if mint.is_some() {
inline_spl_token::id()
token::id()
} else {
system_program::id()
};
Expand Down Expand Up @@ -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::{
Expand Down Expand Up @@ -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(),
Expand Down
1 change: 1 addition & 0 deletions accounts-db/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
8 changes: 4 additions & 4 deletions accounts-db/src/accounts_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
49 changes: 28 additions & 21 deletions accounts-db/src/accounts_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*,
Expand Down Expand Up @@ -1468,7 +1466,7 @@ impl<T: IndexValue, U: DiskIndexValue + From<T> + Into<T>> AccountsIndex<T, U> {
max_root
}

fn update_spl_token_secondary_indexes<G: GenericTokenAccount>(
fn update_spl_token_secondary_indexes<G: solana_inline_spl::token::GenericTokenAccount>(
&self,
token_id: &Pubkey,
pubkey: &Pubkey,
Expand Down Expand Up @@ -1559,15 +1557,15 @@ impl<T: IndexValue, U: DiskIndexValue + From<T> + Into<T>> AccountsIndex<T, U> {
// (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::Account>(
&inline_spl_token::id(),
self.update_spl_token_secondary_indexes::<solana_inline_spl::token::Account>(
&solana_inline_spl::token::id(),
pubkey,
account_owner,
account_data,
account_indexes,
);
self.update_spl_token_secondary_indexes::<inline_spl_token_2022::Account>(
&inline_spl_token_2022::id(),
self.update_spl_token_secondary_indexes::<solana_inline_spl::token_2022::Account>(
&solana_inline_spl::token_2022::id(),
pubkey,
account_owner,
account_data,
Expand Down Expand Up @@ -2016,14 +2014,19 @@ impl<T: IndexValue, U: DiskIndexValue + From<T> + Into<T>> AccountsIndex<T, U> {
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,
},
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<RwLockSecondaryIndexEntry>),
DashMap(&'a SecondaryIndex<DashMapSecondaryIndexEntry>),
Expand Down Expand Up @@ -3362,6 +3365,10 @@ pub mod tests {
);
}

fn make_empty_token_account_data() -> Vec<u8> {
vec![0; solana_inline_spl::token::Account::get_packed_len()]
}

fn run_test_purge_exact_secondary_index<
SecondaryIndexEntryType: SecondaryIndexEntry + Default + Sync + Send,
>(
Expand All @@ -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
Expand All @@ -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,
),
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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::<bool, bool>::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,
Expand All @@ -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::<bool, bool>::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,
Expand All @@ -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()));

Expand Down Expand Up @@ -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::<bool, bool>::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,
Expand All @@ -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::<bool, bool>::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,
Expand Down
2 changes: 0 additions & 2 deletions accounts-db/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
26 changes: 26 additions & 0 deletions inline-spl/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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 }
Loading

0 comments on commit e0e6596

Please sign in to comment.