From da4a81c30b2dd207cc1fcba72ddcdf943e1fa109 Mon Sep 17 00:00:00 2001 From: Hardhat Chad Date: Fri, 24 May 2024 21:54:38 +0000 Subject: [PATCH] cleanup --- src/error.rs | 8 +++++--- src/lib.rs | 5 +---- src/processor/initialize.rs | 11 ++++++++++- src/processor/mine.rs | 5 +++-- src/state/bus.rs | 2 +- 5 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/error.rs b/src/error.rs index a0bf815..4a1dfd3 100644 --- a/src/error.rs +++ b/src/error.rs @@ -17,12 +17,14 @@ pub enum OreError { ClaimTooLarge = 4, #[error("The clock time is invalid")] ClockInvalid = 5, + #[error("You are trying to submit too soon")] + Spam = 6, #[error("Only one hash may be validated per transaction")] - TransactionInvalid = 6, + TransactionInvalid = 7, #[error("The tolerance cannot exceed i64 max value")] - ToleranceOverflow = 7, + ToleranceOverflow = 8, #[error("The maximum supply has been reached")] - MaxSupply = 8, + MaxSupply = 9, } impl From for ProgramError { diff --git a/src/lib.rs b/src/lib.rs index 2a0fe43..c1ed6c5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,7 @@ pub mod consts; pub mod error; pub mod instruction; -mod loaders; +pub mod loaders; mod processor; pub mod state; pub mod utils; @@ -14,9 +14,6 @@ use solana_program::{ program_error::ProgramError, pubkey::Pubkey, }; -// TODO Initialize with mining paused -// TODO Require hardcoded admin key for initialization - declare_id!("mineQW6HcBby3YyZMTaRRtuFWPaGEg8AjmCAWs4nBU8"); #[cfg(not(feature = "no-entrypoint"))] diff --git a/src/processor/initialize.rs b/src/processor/initialize.rs index bc8512a..c594a8e 100644 --- a/src/processor/initialize.rs +++ b/src/processor/initialize.rs @@ -5,6 +5,7 @@ use solana_program::{ entrypoint::ProgramResult, program_error::ProgramError, program_pack::Pack, + pubkey, pubkey::Pubkey, system_program, {self, sysvar}, }; @@ -21,6 +22,9 @@ use crate::{ METADATA_SYMBOL, METADATA_URI, MINT, MINT_ADDRESS, MINT_NOISE, TOKEN_DECIMALS, TREASURY, }; +/// The address to allow for initialization. +const AUTHORIZED_INITIALIZER: Pubkey = pubkey!("HBUh9g46wk2X89CvaNN15UmsznP59rh6od1h8JwYAopk"); + /// Initialize sets up the Ore program. Its responsibilities include: /// 1. Initialize the 8 bus accounts. /// 2. Initialize the treasury account. @@ -87,6 +91,11 @@ pub fn process_initialize<'a, 'info>( load_program(metadata_program, mpl_token_metadata::ID)?; load_sysvar(rent_sysvar, sysvar::rent::id())?; + // Check signer + if signer.key.ne(&AUTHORIZED_INITIALIZER) { + return Err(ProgramError::MissingRequiredSignature); + } + // Initialize bus accounts let bus_infos = [ bus_0_info, bus_1_info, bus_2_info, bus_3_info, bus_4_info, bus_5_info, bus_6_info, @@ -133,7 +142,7 @@ pub fn process_initialize<'a, 'info>( config.admin = *signer.key; config.base_reward_rate = INITIAL_BASE_REWARD_RATE; config.last_reset_at = 0; - config.paused = 0; + config.paused = 1; config.tolerance_liveness = INITIAL_TOLERANCE; config.tolerance_spam = INITIAL_TOLERANCE; diff --git a/src/processor/mine.rs b/src/processor/mine.rs index 1c45280..7548caa 100644 --- a/src/processor/mine.rs +++ b/src/processor/mine.rs @@ -7,14 +7,15 @@ use solana_program::{ blake3::hashv, clock::Clock, entrypoint::ProgramResult, + log::sol_log, program_error::ProgramError, + pubkey, pubkey::Pubkey, sanitize::SanitizeError, serialize_utils::{read_pubkey, read_u16, read_u8}, slot_hashes::SlotHash, sysvar::{self, instructions::load_current_index, Sysvar}, }; -use solana_program::{log::sol_log, pubkey}; use crate::{ error::OreError, @@ -134,8 +135,8 @@ pub fn process_mine<'a, 'info>( let t_target = proof.last_hash_at.saturating_add(ONE_MINUTE); let t_spam = t_target.saturating_sub(config.tolerance_spam); if t.lt(&t_spam) { - reward = 0; sol_log("Spam penalty"); + return Err(OreError::Spam.into()); } // Apply liveness penalty diff --git a/src/state/bus.rs b/src/state/bus.rs index e3fef7c..36b3479 100644 --- a/src/state/bus.rs +++ b/src/state/bus.rs @@ -15,7 +15,7 @@ pub struct Bus { /// The ID of the bus account. pub id: u64, - /// The remaining rewards this bus has left to payout in the current epoch epoch. + /// The remaining rewards this bus has left to payout in the current epoch. pub rewards: u64, /// The rewards this bus would have paid out in the current epoch if there no limit.