diff --git a/api/src/instruction.rs b/api/src/instruction.rs index e240062..e4891ea 100644 --- a/api/src/instruction.rs +++ b/api/src/instruction.rs @@ -19,9 +19,6 @@ pub enum OreInstruction { SetFeeCollector = 10, SetFeeRate = 11, SetSniperFeeDuration = 12, - - // Migration - MigrateMinerAccount = 13, } #[repr(C)] @@ -103,12 +100,6 @@ pub struct SetSniperFeeDuration { pub sniper_fee_duration: [u8; 8], } -#[repr(C)] -#[derive(Clone, Copy, Debug, Pod, Zeroable)] -pub struct MigrateMinerAccount { - pub authority: [u8; 32], -} - instruction!(OreInstruction, Claim); instruction!(OreInstruction, Open); instruction!(OreInstruction, Close); @@ -122,4 +113,3 @@ instruction!(OreInstruction, SetBlockDuration); instruction!(OreInstruction, SetFeeCollector); instruction!(OreInstruction, SetFeeRate); instruction!(OreInstruction, SetSniperFeeDuration); -instruction!(OreInstruction, MigrateMinerAccount); diff --git a/api/src/sdk.rs b/api/src/sdk.rs index 82d1d03..66b8526 100644 --- a/api/src/sdk.rs +++ b/api/src/sdk.rs @@ -287,20 +287,3 @@ pub fn set_sniper_fee_duration(signer: Pubkey, sniper_fee_duration: u64) -> Inst .to_bytes(), } } - -pub fn migrate_miner_account(signer: Pubkey, miner: Pubkey) -> Instruction { - let config_address = config_pda().0; - Instruction { - program_id: crate::ID, - accounts: vec![ - AccountMeta::new(signer, true), - AccountMeta::new(config_address, false), - AccountMeta::new(miner, false), - AccountMeta::new_readonly(system_program::ID, false), - ], - data: MigrateMinerAccount { - authority: miner.to_bytes(), - } - .to_bytes(), - } -} diff --git a/api/src/state/miner.rs b/api/src/state/miner.rs index adfb53f..a63c9ab 100644 --- a/api/src/state/miner.rs +++ b/api/src/state/miner.rs @@ -1,31 +1,9 @@ use steel::*; -use crate::state::{miner_pda, OreAccountOLD}; +use crate::state::miner_pda; use super::OreAccount; -#[repr(C)] -#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)] -pub struct MinerOLD { - /// The authority of this miner account. - pub authority: Pubkey, - - /// The ID of the last block this miner mined in. - pub block_id: u64, - - /// The amount of hashpower this miner has committed to the current block. - pub hashpower: u64, - - /// A user-supplied seed for random number generation. - pub seed: [u8; 32], - - /// The total amount of hashpower this miner has committed across all blocks. - pub total_hashpower: u64, - - /// The total amount of ORE this miner has mined across all blocks. - pub total_rewards: u64, -} - #[repr(C)] #[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)] pub struct Miner { @@ -58,4 +36,3 @@ impl Miner { } account!(OreAccount, Miner); -account!(OreAccountOLD, MinerOLD); diff --git a/api/src/state/mod.rs b/api/src/state/mod.rs index d8e9a81..7b25496 100644 --- a/api/src/state/mod.rs +++ b/api/src/state/mod.rs @@ -24,12 +24,6 @@ pub enum OreAccount { Treasury = 104, } -#[repr(u8)] -#[derive(Clone, Copy, Debug, Eq, PartialEq, IntoPrimitive, TryFromPrimitive)] -pub enum OreAccountOLD { - MinerOLD = 103, -} - pub fn block_pda(id: u64) -> (Pubkey, u8) { Pubkey::find_program_address(&[BLOCK, &id.to_le_bytes()], &crate::ID) } diff --git a/cli/src/main.rs b/cli/src/main.rs index 7d7eb08..a07b143 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -81,12 +81,6 @@ async fn main() { "set_fee_collector" => { set_fee_collector(&rpc, &payer).await.unwrap(); } - "migrate" => { - migrate(&rpc, &payer).await.unwrap(); - } - "migrate_all" => { - migrate_all(&rpc, &payer).await.unwrap(); - } "benchmark" => { benchmark_keccak().await.unwrap(); } @@ -247,36 +241,6 @@ async fn set_fee_collector( Ok(()) } -async fn migrate( - rpc: &RpcClient, - payer: &solana_sdk::signer::keypair::Keypair, -) -> Result<(), anyhow::Error> { - let address = std::env::var("ADDRESS").expect("Missing ADDRESS env var"); - let address = Pubkey::from_str(&address).expect("Invalid ADDRESS"); - let ix = ore_api::sdk::migrate_miner_account(payer.pubkey(), address); - simulate_transaction(rpc, payer, &[ix]).await; - Ok(()) -} - -async fn migrate_all( - rpc: &RpcClient, - payer: &solana_sdk::signer::keypair::Keypair, -) -> Result<(), anyhow::Error> { - let old_miners = get_old_miners(rpc).await?; - println!("Found {} old miners", old_miners.len()); - for (i, (miner_address, _)) in old_miners.iter().enumerate() { - println!( - "[{} / {}] Migrating miner {}", - i, - old_miners.len(), - miner_address - ); - let ix = ore_api::sdk::migrate_miner_account(payer.pubkey(), *miner_address); - let sig = submit_transaction(rpc, payer, &[ix]).await?; - } - Ok(()) -} - async fn log_treasury(_rpc: &RpcClient) -> Result<(), anyhow::Error> { let treasury_address = ore_api::state::treasury_pda().0; println!("Treasury"); @@ -403,10 +367,10 @@ async fn get_market(rpc: &RpcClient) -> Result { Ok(*market) } -async fn get_miner(rpc: &RpcClient, authority: Pubkey) -> Result { +async fn get_miner(rpc: &RpcClient, authority: Pubkey) -> Result { let miner_pda = ore_api::state::miner_pda(authority); let account = rpc.get_account(&miner_pda.0).await?; - let miner = MinerOLD::try_from_bytes(&account.data)?; + let miner = Miner::try_from_bytes(&account.data)?; Ok(*miner) } @@ -421,11 +385,6 @@ async fn get_blocks(rpc: &RpcClient) -> Result, anyhow::Err Ok(blocks) } -async fn get_old_miners(rpc: &RpcClient) -> Result, anyhow::Error> { - let miners = get_program_accounts::(rpc, ore_api::ID, vec![]).await?; - Ok(miners) -} - async fn get_miners(rpc: &RpcClient) -> Result, anyhow::Error> { let miners = get_program_accounts::(rpc, ore_api::ID, vec![]).await?; Ok(miners) diff --git a/program/src/lib.rs b/program/src/lib.rs index 31a2352..7279005 100644 --- a/program/src/lib.rs +++ b/program/src/lib.rs @@ -2,7 +2,6 @@ mod claim; mod close; mod initialize; mod log; -mod migrate_miner_account; mod mine; mod open; mod reset; @@ -18,7 +17,6 @@ use claim::*; use close::*; use initialize::*; use log::*; -use migrate_miner_account::*; use mine::*; use open::*; use reset::*; @@ -56,9 +54,6 @@ 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(()) diff --git a/program/src/migrate_miner_account.rs b/program/src/migrate_miner_account.rs deleted file mode 100644 index 3f766da..0000000 --- a/program/src/migrate_miner_account.rs +++ /dev/null @@ -1,48 +0,0 @@ -use std::mem::size_of; - -use ore_api::prelude::*; -use solana_program::{log::sol_log, rent::Rent}; -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::(&ore_api::ID)? - .assert_mut(|c| c.admin == *signer_info.key)?; - let miner = miner_info.as_account_mut::(&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::(), false)?; - - // Transfer min required rent. - let rent = Rent::get()?; - let min_rent = rent.minimum_balance(8 + size_of::()); - let lamport_delta = min_rent.saturating_sub(miner_info.lamports()); - miner_info.collect(lamport_delta, signer_info)?; - - // Copy new data. - let miner = miner_info.as_account_mut::(&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(()) -}