From 21767bba4eccf252ed80b7e44afecfd7f14b96da Mon Sep 17 00:00:00 2001 From: Hardhat Chad Date: Fri, 16 Feb 2024 21:34:36 +0000 Subject: [PATCH] docs --- src/consts.rs | 1 - src/instruction.rs | 7 +++++++ src/lib.rs | 2 -- src/processor/mine.rs | 2 +- src/utils.rs | 6 +++--- 5 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/consts.rs b/src/consts.rs index 2431ba8..5d7e877 100644 --- a/src/consts.rs +++ b/src/consts.rs @@ -4,7 +4,6 @@ use solana_program::{keccak::Hash, pubkey, pubkey::Pubkey}; /// The unix timestamp after which mining is allowed. pub const START_AT: i64 = 0; -// SHA2 const stable /// Bus pubkeys pub const BUS_ADDRESSES: [Pubkey; BUS_COUNT] = [ pubkey!("E2EJ9xxK78b5XJu9cBnYf6fDbJuLqXuLN5fhaUtEuPPf"), diff --git a/src/instruction.rs b/src/instruction.rs index 0be9a65..36fe639 100644 --- a/src/instruction.rs +++ b/src/instruction.rs @@ -150,6 +150,7 @@ impl_instruction_from_bytes!(ClaimArgs); impl_instruction_from_bytes!(UpdateAdminArgs); impl_instruction_from_bytes!(UpdateDifficultyArgs); +/// Builds an initialize instruction. pub fn initialize(signer: Pubkey) -> Instruction { let treasury_tokens = spl_associated_token_account::get_associated_token_address( &TREASURY_ADDRESS, @@ -208,6 +209,7 @@ pub fn initialize(signer: Pubkey) -> Instruction { } } +/// Builds a claim instruction. pub fn claim(signer: Pubkey, beneficiary: Pubkey, amount: u64) -> Instruction { let proof = Pubkey::find_program_address(&[PROOF, signer.as_ref()], &crate::id()).0; let treasury_tokens = spl_associated_token_account::get_associated_token_address( @@ -237,6 +239,7 @@ pub fn claim(signer: Pubkey, beneficiary: Pubkey, amount: u64) -> Instruction { } } +/// Builds a mine instruction. pub fn mine(signer: Pubkey, bus: Pubkey, hash: Hash, nonce: u64) -> Instruction { let proof = Pubkey::find_program_address(&[PROOF, signer.as_ref()], &crate::id()).0; Instruction { @@ -261,6 +264,7 @@ pub fn mine(signer: Pubkey, bus: Pubkey, hash: Hash, nonce: u64) -> Instruction } } +/// Builds a register instruction. pub fn register(signer: Pubkey) -> Instruction { let proof_pda = Pubkey::find_program_address(&[PROOF, signer.as_ref()], &crate::id()); Instruction { @@ -278,6 +282,7 @@ pub fn register(signer: Pubkey) -> Instruction { } } +/// Builds a reset instruction. pub fn reset(signer: Pubkey) -> Instruction { let bus_0 = Pubkey::find_program_address(&[BUS, &[0]], &crate::id()).0; let bus_1 = Pubkey::find_program_address(&[BUS, &[1]], &crate::id()).0; @@ -312,6 +317,7 @@ pub fn reset(signer: Pubkey) -> Instruction { } } +/// Builds an update_admin instruction. pub fn update_admin(signer: Pubkey, new_admin: Pubkey) -> Instruction { Instruction { program_id: crate::id(), @@ -327,6 +333,7 @@ pub fn update_admin(signer: Pubkey, new_admin: Pubkey) -> Instruction { } } +/// Builds an update_difficulty instruction. pub fn update_difficulty(signer: Pubkey, new_difficulty: Hash) -> Instruction { Instruction { program_id: crate::id(), diff --git a/src/lib.rs b/src/lib.rs index d5bdd93..3009637 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,7 +14,6 @@ use solana_program::{ program_error::ProgramError, pubkey::Pubkey, }; -// TODO Test admin and difficulty adjustment functions // TODO Increase decimals? declare_id!("ore2mSzJwAZhxLyCLbNEnFvYq9U8jvCMvUBrVvbmqDF"); @@ -22,7 +21,6 @@ declare_id!("ore2mSzJwAZhxLyCLbNEnFvYq9U8jvCMvUBrVvbmqDF"); #[cfg(not(feature = "no-entrypoint"))] solana_program::entrypoint!(process_instruction); -/// Processes the incoming instruction pub fn process_instruction( program_id: &Pubkey, accounts: &[AccountInfo], diff --git a/src/processor/mine.rs b/src/processor/mine.rs index dad7a61..d9b07d3 100644 --- a/src/processor/mine.rs +++ b/src/processor/mine.rs @@ -69,7 +69,7 @@ pub fn process_mine<'a, 'info>( bus.rewards = bus.rewards.saturating_sub(treasury.reward_rate); proof.claimable_rewards = proof.claimable_rewards.saturating_add(treasury.reward_rate); - // Hash most recent slot hash into the next challenge to prevent pre-mining attacks + // Hash recent slot hash into the next challenge to prevent pre-mining attacks proof.hash = hashv(&[ KeccakHash::from(args.hash).as_ref(), &slot_hashes_info.data.borrow()[0..size_of::()], diff --git a/src/utils.rs b/src/utils.rs index 1fb0300..1769102 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -36,9 +36,9 @@ pub(crate) fn create_pda<'a, 'info>( #[repr(u8)] #[derive(Clone, Copy, Debug, Eq, PartialEq, IntoPrimitive, TryFromPrimitive)] pub enum AccountDiscriminator { - Bus = 0, - Proof = 1, - Treasury = 2, + Bus = 1, + Proof = 2, + Treasury = 3, } pub trait Discriminator {