Skip to content

Commit

Permalink
Ensure that the spl-token 2 native mint account is owned by the spl-t…
Browse files Browse the repository at this point in the history
…oken 2 program.

Workaround for solana-labs/solana-program-library#374 until spl-token 3 is shipped
  • Loading branch information
mvines committed Sep 1, 2020
1 parent 0ed360b commit 9c94277
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ solana-sdk = { path = "../sdk", version = "1.4.0" }
solana-sdk-macro-frozen-abi = { path = "../sdk/macro-frozen-abi", version = "1.4.0" }
solana-stake-program = { path = "../programs/stake", version = "1.4.0" }
solana-vote-program = { path = "../programs/vote", version = "1.4.0" }
spl-token-v2-0 = { package = "spl-token", version = "2.0.3", features = ["skip-no-mangle"] }
symlink = "0.1.0"
tar = "0.4.28"
tempfile = "3.1.0"
Expand Down
43 changes: 43 additions & 0 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3208,6 +3208,7 @@ impl Bank {
self.reinvoke_entered_epoch_callback(initiate_callback);
self.recheck_cross_program_support();
self.recheck_compute_budget();
self.reconfigure_token2_native_mint();
}

fn ensure_builtins(&mut self, init_or_warp: bool) {
Expand Down Expand Up @@ -3257,6 +3258,48 @@ impl Bank {
self.set_compute_budget(compute_budget);
}

fn reconfigure_token2_native_mint(self: &mut Bank) {
let reconfigure_token2_native_mint = match self.operating_mode() {
OperatingMode::Development => true,
OperatingMode::Preview => self.epoch() >= 93,
OperatingMode::Stable => self.epoch() >= 74,
};

if reconfigure_token2_native_mint {
mod spl_token2 {
// Inline spl_token_v2_0::id() to avoid solana_sdk::pubkey::Pubkey struct mismatch...
solana_sdk::declare_id!("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA");
pub mod native_mint {
solana_sdk::declare_id!("So11111111111111111111111111111111111111112");
}
}

use spl_token_v2_0::{option::COption, pack::Pack, state::Mint};
// As a workaround for
// 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.
if let Some(mut account) = self.get_account(&spl_token_2_0::native_mint::id()) {
if account.owner == solana_sdk::system_program::id() {
info!("Reconfiguring spl-token2 native mint");
let mut data = vec![0; Mint::get_packed_len()];
let mint = Mint {
mint_authority: COption::None,
supply: 0,
decimals: 9,
is_initialized: true,
freeze_authority: COption::None,
};
Mint::pack(mint, &mut data).unwrap();
account.owner = spl_token2::id();
account.data = data;
account.rent_epoch = self.epoch() + 1;
error!("new token2 mint: {:?}", account);
self.store_account(&spl_token2::native_mint::id(), &account);
}
}
}
}

fn fix_recent_blockhashes_sysvar_delay(&self) -> bool {
let activation_slot = match self.operating_mode() {
OperatingMode::Development => 0,
Expand Down

0 comments on commit 9c94277

Please sign in to comment.