miner migration

This commit is contained in:
Hardhat Chad
2025-08-28 13:29:57 -07:00
parent e17a90db4a
commit 53b340268d
8 changed files with 155 additions and 5 deletions

View File

@@ -2,6 +2,7 @@ mod claim;
mod close;
mod initialize;
mod log;
mod migrate_miner_account;
mod mine;
mod open;
mod reset;
@@ -17,6 +18,7 @@ use claim::*;
use close::*;
use initialize::*;
use log::*;
use migrate_miner_account::*;
use mine::*;
use open::*;
use reset::*;
@@ -54,6 +56,9 @@ pub fn process_instruction(
OreInstruction::SetFeeCollector => process_set_fee_collector(accounts, data)?,
OreInstruction::SetFeeRate => process_set_fee_rate(accounts, data)?,
OreInstruction::SetSniperFeeDuration => process_set_sniper_fee_duration(accounts, data)?,
// Migration
OreInstruction::MigrateMinerAccount => process_migrate_miner_account(accounts, data)?,
}
Ok(())

View File

@@ -0,0 +1,42 @@
use std::mem::size_of;
use ore_api::prelude::*;
use solana_program::log::sol_log;
use steel::*;
/// Migrates a miner account from the old format to the new format.
pub fn process_migrate_miner_account(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResult {
// Load accounts.
let [signer_info, config_info, miner_info, system_program] = accounts else {
return Err(ProgramError::NotEnoughAccountKeys);
};
signer_info.is_signer()?;
config_info
.as_account_mut::<Config>(&ore_api::ID)?
.assert_mut(|c| c.admin == *signer_info.key)?;
let miner = miner_info.as_account_mut::<MinerOLD>(&ore_api::ID)?;
system_program.is_program(&system_program::ID)?;
// Copy old data.
let authority = miner.authority;
let block_id = miner.block_id;
let hashpower = miner.hashpower;
let seed = miner.seed;
let total_hashpower = miner.total_hashpower;
let total_rewards = miner.total_rewards;
// Reallocate new account.
miner_info.realloc(8 + size_of::<Miner>(), false)?;
// Copy new data.
let miner = miner_info.as_account_mut::<Miner>(&ore_api::ID)?;
miner.authority = authority;
miner.block_id = block_id;
miner.executor = Pubkey::default();
miner.hashpower = hashpower;
miner.seed = seed;
miner.total_hashpower = total_hashpower;
miner.total_rewards = total_rewards;
Ok(())
}