From c29f08273af68f390a458acefba38fdd1126bce2 Mon Sep 17 00:00:00 2001 From: Hardhat Chad Date: Sun, 24 Mar 2024 14:24:49 +0000 Subject: [PATCH] little cleanup --- src/error.rs | 6 +++--- src/instruction.rs | 20 +++++++++++--------- src/processor/register.rs | 4 ++-- src/processor/reset.rs | 20 ++++++++++++-------- 4 files changed, 28 insertions(+), 22 deletions(-) diff --git a/src/error.rs b/src/error.rs index f0798a5..597331b 100644 --- a/src/error.rs +++ b/src/error.rs @@ -5,7 +5,7 @@ use thiserror::Error; #[derive(Debug, Error, Clone, Copy, PartialEq, Eq, IntoPrimitive)] #[repr(u32)] pub enum OreError { - #[error("The start time has not passed yet")] + #[error("The starting time has not passed yet")] NotStarted = 0, #[error("The epoch has ended and needs reset")] NeedsReset = 1, @@ -15,9 +15,9 @@ pub enum OreError { HashInvalid = 3, #[error("The provided hash does not satisfy the difficulty requirement")] DifficultyNotSatisfied = 4, - #[error("The bus has insufficient rewards to issue at this time")] + #[error("The bus does not have enough rewards to issue at this time")] BusRewardsInsufficient = 5, - #[error("The claim amount cannot be larger than the claimable rewards")] + #[error("The claim amount cannot be greater than the claimable rewards")] ClaimTooLarge = 6, } diff --git a/src/instruction.rs b/src/instruction.rs index c639d23..df9208a 100644 --- a/src/instruction.rs +++ b/src/instruction.rs @@ -34,14 +34,14 @@ pub enum OreInstruction { #[account(0, name = "ore_program", desc = "Ore program")] #[account(1, name = "signer", desc = "Signer", signer)] - #[account(2, name = "proof", desc = "Ore miner proof account", writable)] + #[account(2, name = "proof", desc = "Ore proof account", writable)] #[account(3, name = "system_program", desc = "Solana system program")] Register = 1, #[account(0, name = "ore_program", desc = "Ore program")] #[account(1, name = "signer", desc = "Signer", signer)] #[account(2, name = "bus", desc = "Ore bus account", writable)] - #[account(3, name = "proof", desc = "Ore miner proof account", writable)] + #[account(3, name = "proof", desc = "Ore proof account", writable)] #[account(4, name = "treasury", desc = "Ore treasury account")] #[account(5, name = "slot_hashes", desc = "Solana slot hashes sysvar")] Mine = 2, @@ -50,14 +50,14 @@ pub enum OreInstruction { #[account(1, name = "signer", desc = "Signer", signer)] #[account(2, name = "beneficiary", desc = "Beneficiary token account", writable)] #[account(3, name = "mint", desc = "Ore token mint account")] - #[account(4, name = "proof", desc = "Ore miner proof account", writable)] + #[account(4, name = "proof", desc = "Ore proof account", writable)] #[account(5, name = "treasury", desc = "Ore treasury account", writable)] #[account(6, name = "treasury_tokens", desc = "Ore treasury token account", writable)] #[account(7, name = "token_program", desc = "SPL token program")] Claim = 3, #[account(0, name = "ore_program", desc = "Ore program")] - #[account(1, name = "admin", desc = "Admin signer", signer)] + #[account(1, name = "signer", desc = "Admin signer", signer)] #[account(2, name = "bus_0", desc = "Ore bus account 0", writable)] #[account(3, name = "bus_1", desc = "Ore bus account 1", writable)] #[account(4, name = "bus_2", desc = "Ore bus account 2", writable)] @@ -73,17 +73,19 @@ pub enum OreInstruction { #[account(14, name = "system_program", desc = "Solana system program")] #[account(15, name = "token_program", desc = "SPL token program")] #[account(16, name = "associated_token_program", desc = "SPL associated token program")] - #[account(17, name = "mpl_metadata_program", desc = "MPL token metadata program")] + #[account(17, name = "mpl_metadata_program", desc = "Metaplex metadata program")] #[account(18, name = "rent", desc = "Solana rent sysvar")] Initialize = 100, #[account(0, name = "ore_program", desc = "Ore program")] - #[account(1, name = "treasury", desc = "Ore treasury account")] - UpdateAdmin = 102, + #[account(1, name = "signer", desc = "Admin signer", signer)] + #[account(2, name = "treasury", desc = "Ore treasury account")] + UpdateAdmin = 101, #[account(0, name = "ore_program", desc = "Ore program")] - #[account(1, name = "treasury", desc = "Ore treasury account")] - UpdateDifficulty = 103, + #[account(1, name = "signer", desc = "Admin signer", signer)] + #[account(2, name = "treasury", desc = "Ore treasury account")] + UpdateDifficulty = 102, } impl OreInstruction { diff --git a/src/processor/register.rs b/src/processor/register.rs index f9245ab..94fc9fd 100644 --- a/src/processor/register.rs +++ b/src/processor/register.rs @@ -16,10 +16,10 @@ use crate::{ /// Register generates a new hash chain for a prospective miner. Its responsibilities include: /// 1. Initialize a new proof account. -/// 2. Generate an initial hash for the miner from the signer's key. +/// 2. Generate an initial hash from the signer's key. /// /// Safety requirements: -/// - Register is a permissionless instruction and can be called by anyone. +/// - Register is a permissionless instruction and can be invoked by any singer. /// - Can only succeed if the provided proof acount PDA is valid (associated with the signer). /// - Can only succeed once per signer. /// - The provided system program must be valid. diff --git a/src/processor/reset.rs b/src/processor/reset.rs index ba9ddb4..68b961c 100644 --- a/src/processor/reset.rs +++ b/src/processor/reset.rs @@ -12,21 +12,21 @@ use crate::{ TARGET_EPOCH_REWARDS, TREASURY, }; -/// Reset transitions the Ore program from one epoch to the next. Its responsibilities include: +/// Reset sets up the Ore program for the next epoch. Its responsibilities include: /// 1. Reset bus account rewards counters. /// 2. Adjust the reward rate to stabilize inflation. /// 3. Top up the treasury token account to backup claims. /// /// Safety requirements: -/// - Reset is a permissionless crank function and can be invoked by any signer. +/// - Reset is a permissionless instruction and can be invoked by any signer. /// - Can only succeed if START_AT has passed. -/// - Can only succeed if more 60 seconds or more have passed since the last successful reset. +/// - Can only succeed if more tha 60 seconds or more have passed since the last successful reset. /// - The busses, mint, treasury, treasury token account, and token program must all be valid. /// /// Discussion: /// - It is important that `reset` can only be invoked once per 60 second period to ensure the supply growth rate /// stays within the guaranteed bounds of 0 ≤ R ≤ 2 ORE/min. -/// - The reward rate is dynamically adjusted based on last epoch's actual reward rate (proxy hashpower) to +/// - The reward rate is dynamically adjusted based on last epoch's actual reward rate (proxy for hashpower) to /// target an average supply growth rate of 1 ORE/min. pub fn process_reset<'a, 'info>( _program_id: &Pubkey, @@ -116,11 +116,15 @@ pub fn process_reset<'a, 'info>( Ok(()) } -/// This function calculates what the new reward rate should be based on how many total rewards were mined in the prior epoch. -/// The math is largely identitical to that used by the Bitcoin network for updating the difficulty between each epoch. +/// This function calculates what the new reward rate should be based on how many total rewards +/// were mined in the prior epoch. The math is largely identitical to function used by the Bitcoin +/// network to update the difficulty between each epoch. +/// /// new_rate = current_rate * (target_rewards / actual_rewards) -/// The new rate is then smoothed by a constant factor to avoid unexpectedly large fluctuations. -/// In Ore's case, the epochs are so short (60 seconds) that the smoothing factor of 2 has been chosen. +/// +/// The new rate is then smoothed by a constant factor to avoid large fluctuations. In Ore's case, +/// the epochs are short (60 seconds) so a smoothing factor of 2 has been chosen. That is, the reward rate +/// can at most double or halve from one epoch to the next. pub(crate) fn calculate_new_reward_rate(current_rate: u64, epoch_rewards: u64) -> u64 { // Avoid division by zero. Leave the reward rate unchanged, if detected. if epoch_rewards.eq(&0) {