spl-token: New program feature flag (#21354)
* spl-token: Add feature flag for new release * Remove all spl token version declarations
This commit is contained in:
@ -7374,7 +7374,7 @@ pub mod tests {
|
||||
accounts_index::RefCount,
|
||||
accounts_index::{tests::*, AccountSecondaryIndexesIncludeExclude},
|
||||
append_vec::{test_utils::TempFile, AccountMeta},
|
||||
inline_spl_token_v2_0,
|
||||
inline_spl_token,
|
||||
};
|
||||
use assert_matches::assert_matches;
|
||||
use rand::{thread_rng, Rng};
|
||||
@ -8916,14 +8916,14 @@ 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_v2_0::state::Account::get_packed_len()];
|
||||
vec![0; inline_spl_token::state::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_v2_0::id());
|
||||
normal_account.set_owner(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_v2_0::id());
|
||||
zero_account.set_owner(inline_spl_token::id());
|
||||
zero_account.set_data(account_data_with_mint);
|
||||
|
||||
//store an account
|
||||
|
@ -4,7 +4,7 @@ use crate::{
|
||||
bucket_map_holder::{Age, BucketMapHolder},
|
||||
contains::Contains,
|
||||
in_mem_accounts_index::{InMemAccountsIndex, InsertNewEntryResults},
|
||||
inline_spl_token_v2_0::{self, SPL_TOKEN_ACCOUNT_MINT_OFFSET, SPL_TOKEN_ACCOUNT_OWNER_OFFSET},
|
||||
inline_spl_token::{self, SPL_TOKEN_ACCOUNT_MINT_OFFSET, SPL_TOKEN_ACCOUNT_OWNER_OFFSET},
|
||||
pubkey_bins::PubkeyBinCalculator24,
|
||||
secondary_index::*,
|
||||
};
|
||||
@ -1556,8 +1556,8 @@ impl<T: IndexValue> AccountsIndex<T> {
|
||||
// 2) When the fetch from storage occurs, it will return AccountSharedData::Default
|
||||
// (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()`.
|
||||
if *account_owner == inline_spl_token_v2_0::id()
|
||||
&& account_data.len() == inline_spl_token_v2_0::state::Account::get_packed_len()
|
||||
if *account_owner == inline_spl_token::id()
|
||||
&& account_data.len() == inline_spl_token::state::Account::get_packed_len()
|
||||
{
|
||||
if account_indexes.contains(&AccountIndex::SplTokenOwner) {
|
||||
let owner_key = Pubkey::new(
|
||||
@ -3696,7 +3696,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_v2_0::state::Account::get_packed_len()];
|
||||
let mut account_data = vec![0; inline_spl_token::state::Account::get_packed_len()];
|
||||
account_data[key_start..key_end].clone_from_slice(&(index_key.to_bytes()));
|
||||
|
||||
// Insert slots into secondary index
|
||||
@ -3705,7 +3705,7 @@ pub mod tests {
|
||||
*slot,
|
||||
&account_key,
|
||||
// Make sure these accounts are added to secondary index
|
||||
&inline_spl_token_v2_0::id(),
|
||||
&inline_spl_token::id(),
|
||||
&account_data,
|
||||
secondary_indexes,
|
||||
true,
|
||||
@ -3871,7 +3871,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_v2_0::state::Account::get_packed_len()];
|
||||
let mut account_data = vec![0; inline_spl_token::state::Account::get_packed_len()];
|
||||
account_data[key_start..key_end].clone_from_slice(&(index_key.to_bytes()));
|
||||
|
||||
// Wrong program id
|
||||
@ -3892,7 +3892,7 @@ pub mod tests {
|
||||
index.upsert(
|
||||
0,
|
||||
&account_key,
|
||||
&inline_spl_token_v2_0::id(),
|
||||
&inline_spl_token::id(),
|
||||
&account_data[1..],
|
||||
&secondary_indexes,
|
||||
true,
|
||||
@ -3908,7 +3908,7 @@ pub mod tests {
|
||||
for _ in 0..2 {
|
||||
index.update_secondary_indexes(
|
||||
&account_key,
|
||||
&inline_spl_token_v2_0::id(),
|
||||
&inline_spl_token::id(),
|
||||
&account_data,
|
||||
&secondary_indexes,
|
||||
);
|
||||
@ -3927,7 +3927,7 @@ pub mod tests {
|
||||
secondary_index.reverse_index.clear();
|
||||
index.update_secondary_indexes(
|
||||
&account_key,
|
||||
&inline_spl_token_v2_0::id(),
|
||||
&inline_spl_token::id(),
|
||||
&account_data,
|
||||
&secondary_indexes,
|
||||
);
|
||||
@ -3944,7 +3944,7 @@ pub mod tests {
|
||||
secondary_index.reverse_index.clear();
|
||||
index.update_secondary_indexes(
|
||||
&account_key,
|
||||
&inline_spl_token_v2_0::id(),
|
||||
&inline_spl_token::id(),
|
||||
&account_data,
|
||||
&secondary_indexes,
|
||||
);
|
||||
@ -4001,10 +4001,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_v2_0::state::Account::get_packed_len()];
|
||||
let mut account_data1 = vec![0; inline_spl_token::state::Account::get_packed_len()];
|
||||
account_data1[index_key_start..index_key_end]
|
||||
.clone_from_slice(&(secondary_key1.to_bytes()));
|
||||
let mut account_data2 = vec![0; inline_spl_token_v2_0::state::Account::get_packed_len()];
|
||||
let mut account_data2 = vec![0; inline_spl_token::state::Account::get_packed_len()];
|
||||
account_data2[index_key_start..index_key_end]
|
||||
.clone_from_slice(&(secondary_key2.to_bytes()));
|
||||
|
||||
@ -4012,7 +4012,7 @@ pub mod tests {
|
||||
index.upsert(
|
||||
slot,
|
||||
&account_key,
|
||||
&inline_spl_token_v2_0::id(),
|
||||
&inline_spl_token::id(),
|
||||
&account_data1,
|
||||
secondary_indexes,
|
||||
true,
|
||||
@ -4024,7 +4024,7 @@ pub mod tests {
|
||||
index.upsert(
|
||||
slot,
|
||||
&account_key,
|
||||
&inline_spl_token_v2_0::id(),
|
||||
&inline_spl_token::id(),
|
||||
&account_data2,
|
||||
secondary_indexes,
|
||||
true,
|
||||
@ -4044,7 +4044,7 @@ pub mod tests {
|
||||
index.upsert(
|
||||
later_slot,
|
||||
&account_key,
|
||||
&inline_spl_token_v2_0::id(),
|
||||
&inline_spl_token::id(),
|
||||
&account_data1,
|
||||
secondary_indexes,
|
||||
true,
|
||||
|
@ -46,7 +46,7 @@ use crate::{
|
||||
builtins::{self, ActivationType, Builtin, Builtins},
|
||||
cost_tracker::CostTracker,
|
||||
epoch_stakes::{EpochStakes, NodeVoteAccounts},
|
||||
inline_spl_token_v2_0,
|
||||
inline_spl_token,
|
||||
message_processor::MessageProcessor,
|
||||
rent_collector::RentCollector,
|
||||
stake_weighted_timestamp::{
|
||||
@ -6100,8 +6100,8 @@ impl Bank {
|
||||
self.rent_collector.rent.burn_percent = 50; // 50% rent burn
|
||||
}
|
||||
|
||||
if new_feature_activations.contains(&feature_set::spl_token_v2_set_authority_fix::id()) {
|
||||
self.apply_spl_token_v2_set_authority_fix();
|
||||
if new_feature_activations.contains(&feature_set::spl_token_v3_3_0_release::id()) {
|
||||
self.apply_spl_token_v3_3_0_release();
|
||||
}
|
||||
if new_feature_activations.contains(&feature_set::rent_for_sysvars::id()) {
|
||||
// when this feature is activated, immediately all of existing sysvars are susceptible
|
||||
@ -6237,13 +6237,13 @@ impl Bank {
|
||||
}
|
||||
}
|
||||
|
||||
fn apply_spl_token_v2_set_authority_fix(&mut self) {
|
||||
if let Some(old_account) = self.get_account_with_fixed_root(&inline_spl_token_v2_0::id()) {
|
||||
fn apply_spl_token_v3_3_0_release(&mut self) {
|
||||
if let Some(old_account) = self.get_account_with_fixed_root(&inline_spl_token::id()) {
|
||||
if let Some(new_account) =
|
||||
self.get_account_with_fixed_root(&inline_spl_token_v2_0::new_token_program::id())
|
||||
self.get_account_with_fixed_root(&inline_spl_token::new_token_program::id())
|
||||
{
|
||||
datapoint_info!(
|
||||
"bank-apply_spl_token_v2_set_authority_fix",
|
||||
"bank-apply_spl_token_v3_3_0_release",
|
||||
("slot", self.slot, i64),
|
||||
);
|
||||
|
||||
@ -6252,15 +6252,15 @@ impl Bank {
|
||||
.fetch_sub(old_account.lamports(), Relaxed);
|
||||
|
||||
// Transfer new token account to old token account
|
||||
self.store_account(&inline_spl_token_v2_0::id(), &new_account);
|
||||
self.store_account(&inline_spl_token::id(), &new_account);
|
||||
|
||||
// Clear new token account
|
||||
self.store_account(
|
||||
&inline_spl_token_v2_0::new_token_program::id(),
|
||||
&inline_spl_token::new_token_program::id(),
|
||||
&AccountSharedData::default(),
|
||||
);
|
||||
|
||||
self.remove_executor(&inline_spl_token_v2_0::id());
|
||||
self.remove_executor(&inline_spl_token::id());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -6274,8 +6274,8 @@ impl Bank {
|
||||
|
||||
if reconfigure_token2_native_mint {
|
||||
let mut native_mint_account = solana_sdk::account::AccountSharedData::from(Account {
|
||||
owner: inline_spl_token_v2_0::id(),
|
||||
data: inline_spl_token_v2_0::native_mint::ACCOUNT_DATA.to_vec(),
|
||||
owner: inline_spl_token::id(),
|
||||
data: inline_spl_token::native_mint::ACCOUNT_DATA.to_vec(),
|
||||
lamports: sol_to_lamports(1.),
|
||||
executable: false,
|
||||
rent_epoch: self.epoch() + 1,
|
||||
@ -6285,7 +6285,7 @@ impl Bank {
|
||||
// https://github.com/solana-labs/solana-program-library/issues/374, ensure that the
|
||||
// spl-token 2 native mint account is owned by the spl-token 2 program.
|
||||
let store = if let Some(existing_native_mint_account) =
|
||||
self.get_account_with_fixed_root(&inline_spl_token_v2_0::native_mint::id())
|
||||
self.get_account_with_fixed_root(&inline_spl_token::native_mint::id())
|
||||
{
|
||||
if existing_native_mint_account.owner() == &solana_sdk::system_program::id() {
|
||||
native_mint_account.set_lamports(existing_native_mint_account.lamports());
|
||||
@ -6300,10 +6300,7 @@ impl Bank {
|
||||
};
|
||||
|
||||
if store {
|
||||
self.store_account(
|
||||
&inline_spl_token_v2_0::native_mint::id(),
|
||||
&native_mint_account,
|
||||
);
|
||||
self.store_account(&inline_spl_token::native_mint::id(), &native_mint_account);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -12733,18 +12730,15 @@ pub(crate) mod tests {
|
||||
assert_eq!(genesis_config.cluster_type, ClusterType::Development);
|
||||
let bank = Arc::new(Bank::new_for_tests(&genesis_config));
|
||||
assert_eq!(
|
||||
bank.get_balance(&inline_spl_token_v2_0::native_mint::id()),
|
||||
bank.get_balance(&inline_spl_token::native_mint::id()),
|
||||
1000000000
|
||||
);
|
||||
|
||||
// Testnet - Native mint blinks into existence at epoch 93
|
||||
genesis_config.cluster_type = ClusterType::Testnet;
|
||||
let bank = Arc::new(Bank::new_for_tests(&genesis_config));
|
||||
assert_eq!(
|
||||
bank.get_balance(&inline_spl_token_v2_0::native_mint::id()),
|
||||
0
|
||||
);
|
||||
bank.deposit(&inline_spl_token_v2_0::native_mint::id(), 4200000000)
|
||||
assert_eq!(bank.get_balance(&inline_spl_token::native_mint::id()), 0);
|
||||
bank.deposit(&inline_spl_token::native_mint::id(), 4200000000)
|
||||
.unwrap();
|
||||
|
||||
let bank = Bank::new_from_parent(
|
||||
@ -12754,23 +12748,20 @@ pub(crate) mod tests {
|
||||
);
|
||||
|
||||
let native_mint_account = bank
|
||||
.get_account(&inline_spl_token_v2_0::native_mint::id())
|
||||
.get_account(&inline_spl_token::native_mint::id())
|
||||
.unwrap();
|
||||
assert_eq!(native_mint_account.data().len(), 82);
|
||||
assert_eq!(
|
||||
bank.get_balance(&inline_spl_token_v2_0::native_mint::id()),
|
||||
bank.get_balance(&inline_spl_token::native_mint::id()),
|
||||
4200000000
|
||||
);
|
||||
assert_eq!(native_mint_account.owner(), &inline_spl_token_v2_0::id());
|
||||
assert_eq!(native_mint_account.owner(), &inline_spl_token::id());
|
||||
|
||||
// MainnetBeta - Native mint blinks into existence at epoch 75
|
||||
genesis_config.cluster_type = ClusterType::MainnetBeta;
|
||||
let bank = Arc::new(Bank::new_for_tests(&genesis_config));
|
||||
assert_eq!(
|
||||
bank.get_balance(&inline_spl_token_v2_0::native_mint::id()),
|
||||
0
|
||||
);
|
||||
bank.deposit(&inline_spl_token_v2_0::native_mint::id(), 4200000000)
|
||||
assert_eq!(bank.get_balance(&inline_spl_token::native_mint::id()), 0);
|
||||
bank.deposit(&inline_spl_token::native_mint::id(), 4200000000)
|
||||
.unwrap();
|
||||
|
||||
let bank = Bank::new_from_parent(
|
||||
@ -12780,14 +12771,14 @@ pub(crate) mod tests {
|
||||
);
|
||||
|
||||
let native_mint_account = bank
|
||||
.get_account(&inline_spl_token_v2_0::native_mint::id())
|
||||
.get_account(&inline_spl_token::native_mint::id())
|
||||
.unwrap();
|
||||
assert_eq!(native_mint_account.data().len(), 82);
|
||||
assert_eq!(
|
||||
bank.get_balance(&inline_spl_token_v2_0::native_mint::id()),
|
||||
bank.get_balance(&inline_spl_token::native_mint::id()),
|
||||
4200000000
|
||||
);
|
||||
assert_eq!(native_mint_account.owner(), &inline_spl_token_v2_0::id());
|
||||
assert_eq!(native_mint_account.owner(), &inline_spl_token::id());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -13115,19 +13106,19 @@ pub(crate) mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_spl_token_v2_replacement() {
|
||||
fn test_spl_token_replacement() {
|
||||
let (genesis_config, _mint_keypair) = create_genesis_config(0);
|
||||
let mut bank = Bank::new_for_tests(&genesis_config);
|
||||
|
||||
// Setup original token account
|
||||
bank.store_account_and_update_capitalization(
|
||||
&inline_spl_token_v2_0::id(),
|
||||
&inline_spl_token::id(),
|
||||
&AccountSharedData::from(Account {
|
||||
lamports: 100,
|
||||
..Account::default()
|
||||
}),
|
||||
);
|
||||
assert_eq!(bank.get_balance(&inline_spl_token_v2_0::id()), 100);
|
||||
assert_eq!(bank.get_balance(&inline_spl_token::id()), 100);
|
||||
|
||||
// Setup new token account
|
||||
let new_token_account = AccountSharedData::from(Account {
|
||||
@ -13135,27 +13126,27 @@ pub(crate) mod tests {
|
||||
..Account::default()
|
||||
});
|
||||
bank.store_account_and_update_capitalization(
|
||||
&inline_spl_token_v2_0::new_token_program::id(),
|
||||
&inline_spl_token::new_token_program::id(),
|
||||
&new_token_account,
|
||||
);
|
||||
assert_eq!(
|
||||
bank.get_balance(&inline_spl_token_v2_0::new_token_program::id()),
|
||||
bank.get_balance(&inline_spl_token::new_token_program::id()),
|
||||
123
|
||||
);
|
||||
|
||||
let original_capitalization = bank.capitalization();
|
||||
|
||||
bank.apply_spl_token_v2_set_authority_fix();
|
||||
bank.apply_spl_token_v3_3_0_release();
|
||||
|
||||
// New token account is now empty
|
||||
assert_eq!(
|
||||
bank.get_balance(&inline_spl_token_v2_0::new_token_program::id()),
|
||||
bank.get_balance(&inline_spl_token::new_token_program::id()),
|
||||
0
|
||||
);
|
||||
|
||||
// Old token account holds the new token account
|
||||
assert_eq!(
|
||||
bank.get_account(&inline_spl_token_v2_0::id()),
|
||||
bank.get_account(&inline_spl_token::id()),
|
||||
Some(new_token_account)
|
||||
);
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
// Partial SPL Token v2.0.x declarations inlined to avoid an external dependency on the spl-token crate
|
||||
// Partial SPL Token declarations inlined to avoid an external dependency on the spl-token crate
|
||||
solana_sdk::declare_id!("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA");
|
||||
|
||||
pub(crate) mod new_token_program {
|
||||
solana_sdk::declare_id!("nTokHfnBtpt4V6xiEbBSduiGCrQ6wSF3rxC8WeWAQ9F");
|
||||
solana_sdk::declare_id!("nTok2oJvx1CgbYA2SznfJLmnKLEL6sYdh2ypZms2nhm");
|
||||
}
|
||||
|
||||
/*
|
@ -31,7 +31,7 @@ pub mod execute_cost_table;
|
||||
pub mod genesis_utils;
|
||||
pub mod hardened_unpack;
|
||||
pub mod in_mem_accounts_index;
|
||||
pub mod inline_spl_token_v2_0;
|
||||
pub mod inline_spl_token;
|
||||
pub mod loader_utils;
|
||||
pub mod message_processor;
|
||||
pub mod non_circulating_supply;
|
||||
|
Reference in New Issue
Block a user