mirror of
https://github.com/d0zingcat/ore.git
synced 2026-05-13 23:16:52 +00:00
comments and tests
This commit is contained in:
@@ -12,7 +12,7 @@ use crate::{
|
||||
TREASURY,
|
||||
};
|
||||
|
||||
/// Claim distributes owed token rewards from the treasury to the miner. It has 4 responsibilies:
|
||||
/// Claim distributes owed token rewards from the treasury to the miner. Its responsibilies include:
|
||||
/// 1. Transfer tokens from the treasury to the miner.
|
||||
/// 2. Decrement the miner's claimable rewards counter by an appropriate amount.
|
||||
/// 3. Update the program's lifetime stats.
|
||||
|
||||
@@ -22,7 +22,7 @@ use crate::{
|
||||
TOKEN_DECIMALS, TREASURY, TREASURY_ADDRESS,
|
||||
};
|
||||
|
||||
/// Initialize sets up the Ore program state. Its responsibilities include:
|
||||
/// Initialize sets up the Ore program. Its responsibilities include:
|
||||
/// 1. Initialize the 8 bus accounts.
|
||||
/// 2. Initialize the treasury account.
|
||||
/// 3. Initialize the Ore mint account.
|
||||
|
||||
@@ -22,7 +22,7 @@ use crate::{
|
||||
EPOCH_DURATION,
|
||||
};
|
||||
|
||||
/// Mine is the primary workhorse instruction of the Ore program. It has 4 responsibilities including:
|
||||
/// Mine is the primary workhorse instruction of the Ore program. Its responsibilities include:
|
||||
/// 1. Verify the provided hash is valid.
|
||||
/// 2. Increment the user's claimable rewards counter.
|
||||
/// 3. Generate a new challenge for the miner.
|
||||
|
||||
@@ -14,9 +14,9 @@ use crate::{
|
||||
PROOF,
|
||||
};
|
||||
|
||||
/// Register generates a new hash chain for a prospective miner. It has 2 responsibilities:
|
||||
/// 1. Initializes a new proof account.
|
||||
/// 2. Generates an initial hash for the miner from the signer's key.
|
||||
/// 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.
|
||||
///
|
||||
/// Safety requirements:
|
||||
/// - Register is a permissionless instruction and can be called by anyone.
|
||||
|
||||
@@ -12,8 +12,7 @@ use crate::{
|
||||
TARGET_EPOCH_REWARDS, TREASURY,
|
||||
};
|
||||
|
||||
/// Reset transitions the Ore program from one epoch to the next. It is the most complex instruction in the
|
||||
/// Ore program and has three primary responsibilities including:
|
||||
/// Reset transitions the Ore program from one epoch to the next. 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.
|
||||
@@ -167,6 +166,7 @@ mod tests {
|
||||
let current_rate = 1000;
|
||||
let new_rate =
|
||||
calculate_new_reward_rate(current_rate, TARGET_EPOCH_REWARDS.saturating_sub(1_000_000));
|
||||
println!("{:?} {:?}", new_rate, current_rate);
|
||||
assert!(new_rate.gt(¤t_rate));
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ use solana_program::{
|
||||
|
||||
use crate::{instruction::UpdateAdminArgs, loaders::*, state::Treasury, utils::AccountDeserialize};
|
||||
|
||||
/// UpdateAdmin updates the program's admin account. It has 1 responsibility:
|
||||
/// UpdateAdmin updates the program's admin account. Its responsibilities include:
|
||||
/// 1. Update the treasury admin address.
|
||||
///
|
||||
/// Safety requirements:
|
||||
@@ -13,17 +13,17 @@ use crate::{instruction::UpdateAdminArgs, loaders::*, state::Treasury, utils::Ac
|
||||
/// - Can only succeed if the provided treasury is valid.
|
||||
///
|
||||
/// Discussion:
|
||||
/// - The admin authority has one lever of power: the ability to adjust the global
|
||||
/// - The admin authority has one lever of power: the ability to adjust the global
|
||||
/// mining difficulty. If the difficulty is too easy, miners will find hashes very quickly
|
||||
/// and the bottleneck for mining will shift from local compute to Solana bandwidth. In essence,
|
||||
/// if the Ore token has value and difficulty is low, mining becomes an incentivized stress
|
||||
/// test for the Solana network.
|
||||
/// test for the Solana network.
|
||||
/// - At the same time, if difficulty is too hard, miners will have to wait a very long period
|
||||
/// of time between finding valid hashes. This will bias rewards to well-resourced miners
|
||||
/// with large compute operations. Keeping a low difficulty ensures casual miners can
|
||||
/// of time between finding valid hashes. This will bias rewards to well-resourced miners
|
||||
/// with large compute operations. Keeping a low difficulty ensures casual miners can
|
||||
/// consistently earn rewards and undercuts some of the advantage of larger players.
|
||||
/// - Ultimately admin authority should be delegated to a governance mechanism – either
|
||||
/// democratic or futarchic – to ensure difficulty is kept at a value that represents the
|
||||
/// - Ultimately admin authority should be delegated to a governance mechanism – either
|
||||
/// democratic or futarchic – to ensure difficulty is kept at a value that represents the
|
||||
/// values and interests of the whole ecosystem.
|
||||
pub fn process_update_admin<'a, 'info>(
|
||||
_program_id: &Pubkey,
|
||||
|
||||
@@ -7,7 +7,7 @@ use crate::{
|
||||
instruction::UpdateDifficultyArgs, loaders::*, state::Treasury, utils::AccountDeserialize,
|
||||
};
|
||||
|
||||
/// UpdateDifficulty updates the program's global difficulty value. It has 1 responsibility:
|
||||
/// UpdateDifficulty updates the program's global difficulty value. Its responsibilities include:
|
||||
/// 1. Update the difficulty.
|
||||
///
|
||||
/// Safety requirements:
|
||||
@@ -18,14 +18,14 @@ use crate::{
|
||||
/// - Ore subdivides into 1 billion indivisible atomic units. Therefore if global hashpower
|
||||
/// were to increase to the point where >1B valid hashes were submitted to the protocol for
|
||||
/// validation per epoch, the Ore inflation rate could be pushed above the 1 ORE / min target.
|
||||
/// - The strict limits on bus reward counters guarantee inflation can never exceed 2 ORE / min,
|
||||
/// - The strict limits on bus reward counters guarantee inflation can never exceed 2 ORE / min,
|
||||
/// but it is the responsibility of the admin to adjust mining difficulty if needed to maintain
|
||||
/// the 1 ORE / min target average.
|
||||
/// - It is worth noting that Solana today processes well below 1 million real TPS or
|
||||
/// - It is worth noting that Solana today processes well below 1 million real TPS or
|
||||
/// (60 * 1,000,000) = 60,000,000 transactions per minute. Even if every transaction on Solana
|
||||
/// were a mine operation, this would still be two orders of magnitude below the boundary
|
||||
/// condition where Ore inflation targets would be challenged. So in practice, Solana is likely
|
||||
/// to reach its network saturation point long before Ore ever hits its theoretical limits.
|
||||
/// were a mine operation, this would still be two orders of magnitude below the boundary
|
||||
/// condition where Ore inflation targets would be challenged. So in practice, Solana is likely
|
||||
/// to reach its network saturation point long before Ore ever hits its theoretical limits.
|
||||
pub fn process_update_difficulty<'a, 'info>(
|
||||
_program_id: &Pubkey,
|
||||
accounts: &'a [AccountInfo<'info>],
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
use ore::{state::Treasury, utils::AccountDeserialize, TREASURY_ADDRESS};
|
||||
use solana_program::{hash::Hash, pubkey::Pubkey};
|
||||
use solana_program_test::{processor, BanksClient, ProgramTest};
|
||||
use solana_program::{hash::Hash, pubkey::Pubkey, rent::Rent};
|
||||
use solana_program_test::{processor, read_file, BanksClient, ProgramTest};
|
||||
use solana_sdk::{
|
||||
account::Account,
|
||||
signature::{Keypair, Signer},
|
||||
transaction::Transaction,
|
||||
};
|
||||
@@ -71,5 +72,19 @@ async fn test_update_admin_bad_signer() {
|
||||
async fn setup_program_test_env() -> (BanksClient, Keypair, Hash) {
|
||||
let mut program_test = ProgramTest::new("ore", ore::ID, processor!(ore::process_instruction));
|
||||
program_test.prefer_bpf(true);
|
||||
|
||||
// Setup metadata program
|
||||
let data = read_file(&"tests/buffers/metadata_program.bpf");
|
||||
program_test.add_account(
|
||||
mpl_token_metadata::ID,
|
||||
Account {
|
||||
lamports: Rent::default().minimum_balance(data.len()).max(1),
|
||||
data,
|
||||
owner: solana_sdk::bpf_loader::id(),
|
||||
executable: true,
|
||||
rent_epoch: 0,
|
||||
},
|
||||
);
|
||||
|
||||
program_test.start().await
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
use ore::{state::Treasury, utils::AccountDeserialize, TREASURY_ADDRESS};
|
||||
use solana_program::{hash::Hash, keccak::Hash as KeccakHash};
|
||||
use solana_program_test::{processor, BanksClient, ProgramTest};
|
||||
use solana_program::{hash::Hash, keccak::Hash as KeccakHash, rent::Rent};
|
||||
use solana_program_test::{processor, read_file, BanksClient, ProgramTest};
|
||||
use solana_sdk::{
|
||||
account::Account,
|
||||
signature::{Keypair, Signer},
|
||||
transaction::Transaction,
|
||||
};
|
||||
@@ -66,5 +67,19 @@ async fn test_update_difficulty_bad_signer() {
|
||||
async fn setup_program_test_env() -> (BanksClient, Keypair, Hash) {
|
||||
let mut program_test = ProgramTest::new("ore", ore::ID, processor!(ore::process_instruction));
|
||||
program_test.prefer_bpf(true);
|
||||
|
||||
// Setup metadata program
|
||||
let data = read_file(&"tests/buffers/metadata_program.bpf");
|
||||
program_test.add_account(
|
||||
mpl_token_metadata::ID,
|
||||
Account {
|
||||
lamports: Rent::default().minimum_balance(data.len()).max(1),
|
||||
data,
|
||||
owner: solana_sdk::bpf_loader::id(),
|
||||
executable: true,
|
||||
rent_epoch: 0,
|
||||
},
|
||||
);
|
||||
|
||||
program_test.start().await
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user