cleanup loaders

This commit is contained in:
Hardhat Chad
2024-03-19 14:40:19 +00:00
parent 6376b0803d
commit 77dc9a83b1
5 changed files with 86 additions and 41 deletions

View File

@@ -136,10 +136,10 @@ pub fn process_initialize<'a, 'info>(
let mut treasury_data = treasury_info.data.borrow_mut();
treasury_data[0] = Treasury::discriminator() as u8;
let treasury = Treasury::try_from_bytes_mut(&mut treasury_data)?;
treasury.bump = args.treasury_bump as u64;
treasury.admin = *signer.key;
treasury.last_reset_at = 0;
treasury.bump = args.treasury_bump as u64;
treasury.difficulty = INITIAL_DIFFICULTY.into();
treasury.last_reset_at = 0;
treasury.reward_rate = INITIAL_REWARD_RATE;
treasury.total_claimed_rewards = 0;
drop(treasury_data);

View File

@@ -29,7 +29,8 @@ use crate::{
/// 4. Update the miner's lifetime stats.
///
/// Safety requirements:
/// - Mine is a permissionless instruction and can be called by any miner.
/// - Mine is a permissionless instruction and can be called by any signer.
/// - Can only succeed if START_AT has passed.
/// - Can only succeed if the last reset was less than 60 seconds ago.
/// - Can only succeed if the provided SHA3 hash and nonce are valid and satisfy the difficulty.
/// - The the provided proof account must be associated with the signer.
@@ -70,8 +71,8 @@ pub fn process_mine<'a, 'info>(
let mut proof_data = proof_info.data.borrow_mut();
let proof = Proof::try_from_bytes_mut(&mut proof_data)?;
validate_hash(
proof.hash.into(),
args.hash.into(),
proof.hash.into(),
*signer.key,
u64::from_le_bytes(args.nonce),
treasury.difficulty.into(),
@@ -106,8 +107,8 @@ pub fn process_mine<'a, 'info>(
/// Validates the provided hash, ensursing it is equal to SHA3(current_hash, singer, nonce).
/// Fails if the provided hash is valid but does not satisfy the required difficulty.
pub(crate) fn validate_hash(
current_hash: KeccakHash,
hash: KeccakHash,
current_hash: KeccakHash,
signer: Pubkey,
nonce: u64,
difficulty: KeccakHash,
@@ -150,7 +151,7 @@ mod tests {
signer.to_bytes().as_slice(),
nonce.to_le_bytes().as_slice(),
]);
let res = validate_hash(h1, h2, signer, nonce, difficulty);
let res = validate_hash(h2, h1, signer, nonce, difficulty);
assert!(res.is_ok());
}
@@ -161,7 +162,7 @@ mod tests {
let nonce = 10u64;
let difficulty = Hash::new_from_array([255; HASH_BYTES]);
let h2 = Hash::new_from_array([2; HASH_BYTES]);
let res = validate_hash(h1, h2, signer, nonce, difficulty);
let res = validate_hash(h2, h1, signer, nonce, difficulty);
assert!(res.is_err());
}
@@ -176,7 +177,7 @@ mod tests {
signer.to_bytes().as_slice(),
nonce.to_le_bytes().as_slice(),
]);
let res = validate_hash(h1, h2, signer, nonce, difficulty);
let res = validate_hash(h2, h1, signer, nonce, difficulty);
assert!(res.is_err());
}
}

View File

@@ -18,14 +18,15 @@ use crate::{
/// 3. Top up the treasury token account to backup claims.
///
/// Safety requirements:
/// - Reset is a permissionless crank function and can be invoked by anyone.
/// - Reset is a permissionless crank function 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.
/// - The busses, mint, treasury, treasury token account, and token program must all be valid.
///
/// Discussion:
/// - It is critical that `reset` can only be invoked once per 60 second period to ensure the supply growth rate
/// - 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 (measured hashpower) to
/// - The reward rate is dynamically adjusted based on last epoch's actual reward rate (proxy hashpower) to
/// target an average supply growth rate of 1 ORE/min.
pub fn process_reset<'a, 'info>(
_program_id: &Pubkey,