mirror of
https://github.com/d0zingcat/ore.git
synced 2026-06-03 15:11:20 +00:00
Merge pull request #51 from regolith-labs/hardhat/miner-authority
Introduce miner authority
This commit is contained in:
@@ -214,12 +214,13 @@ pub fn reset(signer: Pubkey) -> Instruction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Builds an open instruction.
|
/// Builds an open instruction.
|
||||||
pub fn open(signer: Pubkey) -> Instruction {
|
pub fn open(signer: Pubkey, miner: Pubkey) -> Instruction {
|
||||||
let proof_pda = Pubkey::find_program_address(&[PROOF, signer.as_ref()], &crate::id());
|
let proof_pda = Pubkey::find_program_address(&[PROOF, signer.as_ref()], &crate::id());
|
||||||
Instruction {
|
Instruction {
|
||||||
program_id: crate::id(),
|
program_id: crate::id(),
|
||||||
accounts: vec![
|
accounts: vec![
|
||||||
AccountMeta::new(signer, true),
|
AccountMeta::new(signer, true),
|
||||||
|
AccountMeta::new(miner, true),
|
||||||
AccountMeta::new(proof_pda.0, false),
|
AccountMeta::new(proof_pda.0, false),
|
||||||
AccountMeta::new_readonly(solana_program::system_program::id(), false),
|
AccountMeta::new_readonly(solana_program::system_program::id(), false),
|
||||||
AccountMeta::new_readonly(sysvar::slot_hashes::id(), false),
|
AccountMeta::new_readonly(sysvar::slot_hashes::id(), false),
|
||||||
|
|||||||
@@ -158,6 +158,39 @@ pub fn load_proof<'a, 'info>(
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Errors if:
|
||||||
|
/// - Owner is not Ore program.
|
||||||
|
/// - Data is empty.
|
||||||
|
/// - Data cannot deserialize into a proof account.
|
||||||
|
/// - Proof miner does not match the expected address.
|
||||||
|
/// - Expected to be writable, but is not.
|
||||||
|
pub fn load_proof_with_miner<'a, 'info>(
|
||||||
|
info: &'a AccountInfo<'info>,
|
||||||
|
miner: &Pubkey,
|
||||||
|
is_writable: bool,
|
||||||
|
) -> Result<(), ProgramError> {
|
||||||
|
if info.owner.ne(&crate::id()) {
|
||||||
|
return Err(ProgramError::InvalidAccountOwner);
|
||||||
|
}
|
||||||
|
|
||||||
|
if info.data_is_empty() {
|
||||||
|
return Err(ProgramError::UninitializedAccount);
|
||||||
|
}
|
||||||
|
|
||||||
|
let proof_data = info.data.borrow();
|
||||||
|
let proof = Proof::try_from_bytes(&proof_data)?;
|
||||||
|
|
||||||
|
if proof.miner.ne(&miner) {
|
||||||
|
return Err(ProgramError::InvalidAccountData);
|
||||||
|
}
|
||||||
|
|
||||||
|
if is_writable && !info.is_writable {
|
||||||
|
return Err(ProgramError::InvalidAccountData);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
/// Errors if:
|
/// Errors if:
|
||||||
/// - Owner is not Ore program.
|
/// - Owner is not Ore program.
|
||||||
/// - Address does not match the expected address.
|
/// - Address does not match the expected address.
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ pub fn process_mine<'a, 'info>(
|
|||||||
load_signer(signer)?;
|
load_signer(signer)?;
|
||||||
load_any_bus(bus_info, true)?;
|
load_any_bus(bus_info, true)?;
|
||||||
load_config(config_info, false)?;
|
load_config(config_info, false)?;
|
||||||
load_proof(proof_info, signer.key, true)?;
|
load_proof_with_miner(proof_info, signer.key, true)?;
|
||||||
load_sysvar(instructions_sysvar, sysvar::instructions::id())?;
|
load_sysvar(instructions_sysvar, sysvar::instructions::id())?;
|
||||||
load_sysvar(slot_hashes_sysvar, sysvar::slot_hashes::id())?;
|
load_sysvar(slot_hashes_sysvar, sysvar::slot_hashes::id())?;
|
||||||
|
|
||||||
|
|||||||
@@ -39,10 +39,11 @@ pub fn process_open<'a, 'info>(
|
|||||||
let args = OpenArgs::try_from_bytes(data)?;
|
let args = OpenArgs::try_from_bytes(data)?;
|
||||||
|
|
||||||
// Load accounts
|
// Load accounts
|
||||||
let [signer, proof_info, system_program, slot_hashes_info] = accounts else {
|
let [signer, miner_info, proof_info, system_program, slot_hashes_info] = accounts else {
|
||||||
return Err(ProgramError::NotEnoughAccountKeys);
|
return Err(ProgramError::NotEnoughAccountKeys);
|
||||||
};
|
};
|
||||||
load_signer(signer)?;
|
load_signer(signer)?;
|
||||||
|
load_signer(miner_info)?;
|
||||||
load_uninitialized_pda(
|
load_uninitialized_pda(
|
||||||
proof_info,
|
proof_info,
|
||||||
&[PROOF, signer.key.as_ref()],
|
&[PROOF, signer.key.as_ref()],
|
||||||
@@ -75,6 +76,7 @@ pub fn process_open<'a, 'info>(
|
|||||||
proof.last_hash = [0; 32];
|
proof.last_hash = [0; 32];
|
||||||
proof.last_hash_at = clock.unix_timestamp;
|
proof.last_hash_at = clock.unix_timestamp;
|
||||||
proof.last_stake_at = clock.unix_timestamp;
|
proof.last_stake_at = clock.unix_timestamp;
|
||||||
|
proof.miner = *miner_info.key;
|
||||||
proof.total_hashes = 0;
|
proof.total_hashes = 0;
|
||||||
proof.total_rewards = 0;
|
proof.total_rewards = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -30,6 +30,9 @@ pub struct Proof {
|
|||||||
/// The last time stake was deposited into this account.
|
/// The last time stake was deposited into this account.
|
||||||
pub last_stake_at: i64,
|
pub last_stake_at: i64,
|
||||||
|
|
||||||
|
/// The keypair which has permission to submit hashes for mining.
|
||||||
|
pub miner: Pubkey,
|
||||||
|
|
||||||
/// The total lifetime hashes provided by this miner.
|
/// The total lifetime hashes provided by this miner.
|
||||||
pub total_hashes: u64,
|
pub total_hashes: u64,
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user