Skip to content

Commit

Permalink
Feature Gate: replace token 2022 program on testnet
Browse files Browse the repository at this point in the history
  • Loading branch information
nibty committed Feb 6, 2025
1 parent 76e2572 commit 7bf716f
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 1 deletion.
66 changes: 66 additions & 0 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
//! It offers a high-level API that signs transactions
//! on behalf of the caller, and a low-level API for when they have
//! already been signed and verified.
use {
crate::{
bank::{
Expand Down Expand Up @@ -92,6 +93,7 @@ use {
compute_budget_processor::process_compute_budget_instructions,
},
solana_cost_model::cost_tracker::CostTracker,
solana_inline_spl,
solana_loader_v4_program::create_program_runtime_environment_v2,
solana_measure::{measure, measure::Measure, measure_us},
solana_perf::perf_libs,
Expand Down Expand Up @@ -186,6 +188,7 @@ use {
ops::{AddAssign, RangeFull, RangeInclusive},
path::PathBuf,
slice,
str::FromStr,
sync::{
atomic::{
AtomicBool, AtomicI64, AtomicU64, AtomicUsize,
Expand Down Expand Up @@ -317,6 +320,7 @@ pub struct BankRc {

#[cfg(all(RUSTC_WITH_SPECIALIZATION, feature = "frozen-abi"))]
use solana_frozen_abi::abi_example::AbiExample;
use solana_sdk::bpf_loader_upgradeable::UpgradeableLoaderState;

#[cfg(all(RUSTC_WITH_SPECIALIZATION, feature = "frozen-abi"))]
impl AbiExample for BankRc {
Expand Down Expand Up @@ -6472,6 +6476,68 @@ impl Bank {
if new_feature_activations.contains(&feature_set::update_hashes_per_tick6::id()) {
self.apply_updated_hashes_per_tick(UPDATED_HASHES_PER_TICK6);
}

if new_feature_activations.contains(&feature_set::replace_token_program_2022::id()) {
self.apply_replacement_token();
}
}

/// Need to replace the token program with a new one.
/// This is a one-time operation for our testnet.
/// Remove this function after the testnet upgrade to v2.1.x.
fn apply_replacement_token(&mut self) {
let program_data_elf = include_bytes!("./spl_token-2022-5.0.2.so");
let (programdata_address, ..) = Pubkey::find_program_address(
&[solana_inline_spl::token_2022::id().as_ref()],
&bpf_loader_upgradeable::id(),
);
info!(
"Replacing token 2022: programdata_address: {:?}",
programdata_address
);

// X1 lab's upgrade authority address
let upgrade_authority_address =
Pubkey::from_str("FwJkGYPdpp3BjfRBtrU5duGHMBmiSHmEwGX6oBSMXEQx").unwrap();
let mut program_data = bincode::serialize(&UpgradeableLoaderState::ProgramData {
slot: self.slot,
upgrade_authority_address: Some(upgrade_authority_address),
})
.unwrap();
program_data.extend_from_slice(program_data_elf);

self.store_account_and_update_capitalization(
&programdata_address,
&AccountSharedData::from(Account {
lamports: self
.parent()
.unwrap()
.get_minimum_balance_for_rent_exemption(program_data.len()),
data: program_data,
owner: bpf_loader_upgradeable::id(),
executable: false,
rent_epoch: 0,
}),
);

let program_data = bincode::serialize(&UpgradeableLoaderState::Program {
programdata_address,
})
.unwrap();

self.store_account_and_update_capitalization(
&solana_inline_spl::token_2022::id(),
&AccountSharedData::from(Account {
lamports: self
.parent()
.unwrap()
.get_minimum_balance_for_rent_exemption(program_data.len()),
data: program_data,
owner: bpf_loader_upgradeable::id(),
executable: true,
rent_epoch: 0,
}),
);
}

fn apply_updated_hashes_per_tick(&mut self, hashes_per_tick: u64) {
Expand Down
Binary file added runtime/src/spl_token-2022-5.0.2.so
Binary file not shown.
5 changes: 5 additions & 0 deletions sdk/src/feature_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,10 @@ pub mod disable_account_loader_special_case {
solana_program::declare_id!("7QkayNydJtEKXghHvc4EqedXWsadK3crvFs732jruVXM");
}

pub mod replace_token_program_2022 {
solana_program::declare_id!("8FbKvGXFBMjpYXhtnX6KuuLquqMRFaGouQkrDkKYp64b");
}

lazy_static! {
/// Map of feature identifiers to user-visible description
pub static ref FEATURE_NAMES: HashMap<Pubkey, &'static str> = [
Expand Down Expand Up @@ -1071,6 +1075,7 @@ lazy_static! {
(enable_turbine_extended_fanout_experiments::id(), "enable turbine extended fanout experiments #2373"),
(deprecate_legacy_vote_ixs::id(), "Deprecate legacy vote instructions"),
(disable_account_loader_special_case::id(), "Disable account loader special case"),
(replace_token_program_2022::id(), "Replace Token Program 2022"),
/*************** ADD NEW FEATURES HERE ***************/
]
.iter()
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/genesis_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl ClusterType {
Some(Hash::from_str("5eykt4UsFv8P8NJdTREpY1vzqKqZKvdpKuc147dw2N9d").unwrap())
}
Self::Testnet => {
Some(Hash::from_str("4uhcVJyU9pJkvQyS88uRDiswHXSCkY3zQawwpjk2NsNY").unwrap())
Some(Hash::from_str("C7ucgdDEhxLTpXHhWSZxavSVmaNTUJWwT5iTdeaviDho").unwrap())
}
Self::Devnet => {
Some(Hash::from_str("EtWTRABZaYq6iMfeYKouRu166VU2xqa1wcaWoxPkrZBG").unwrap())
Expand Down

0 comments on commit 7bf716f

Please sign in to comment.