block based sha256 mining

This commit is contained in:
Hardhat Chad
2025-05-10 10:36:37 -07:00
parent 3492feef67
commit ae53d0e829
7 changed files with 136 additions and 896 deletions

View File

@@ -3,7 +3,7 @@ use steel::*;
use crate::{
consts::*,
instruction::*,
state::{bus_pda, config_pda, proof_pda, treasury_pda},
state::{config_pda, proof_pda, treasury_pda},
};
/// Builds an auth instruction.
@@ -97,21 +97,14 @@ pub fn open(signer: Pubkey, miner: Pubkey, payer: Pubkey) -> Instruction {
}
/// Builds a reset instruction.
pub fn reset(signer: Pubkey) -> Instruction {
pub fn reset(signer: Pubkey, best_proof: Pubkey) -> Instruction {
Instruction {
program_id: crate::ID,
accounts: vec![
AccountMeta::new(signer, true),
AccountMeta::new(BUS_ADDRESSES[0], false),
AccountMeta::new(BUS_ADDRESSES[1], false),
AccountMeta::new(BUS_ADDRESSES[2], false),
AccountMeta::new(BUS_ADDRESSES[3], false),
AccountMeta::new(BUS_ADDRESSES[4], false),
AccountMeta::new(BUS_ADDRESSES[5], false),
AccountMeta::new(BUS_ADDRESSES[6], false),
AccountMeta::new(BUS_ADDRESSES[7], false),
AccountMeta::new(CONFIG_ADDRESS, false),
AccountMeta::new(MINT_ADDRESS, false),
AccountMeta::new(best_proof, false),
AccountMeta::new(TREASURY_ADDRESS, false),
AccountMeta::new(TREASURY_TOKENS_ADDRESS, false),
AccountMeta::new_readonly(spl_token::ID, false),
@@ -134,52 +127,52 @@ pub fn update(signer: Pubkey, miner: Pubkey) -> Instruction {
}
}
/// Builds an initialize instruction.
pub fn initialize(signer: Pubkey) -> Instruction {
let bus_pdas = [
bus_pda(0),
bus_pda(1),
bus_pda(2),
bus_pda(3),
bus_pda(4),
bus_pda(5),
bus_pda(6),
bus_pda(7),
];
let config_pda = config_pda();
let mint_pda = Pubkey::find_program_address(&[MINT, MINT_NOISE.as_slice()], &crate::ID);
let treasury_pda = treasury_pda();
let metadata_pda = Pubkey::find_program_address(
&[
METADATA,
mpl_token_metadata::ID.as_ref(),
mint_pda.0.as_ref(),
],
&mpl_token_metadata::ID,
);
Instruction {
program_id: crate::ID,
accounts: vec![
AccountMeta::new(signer, true),
AccountMeta::new(bus_pdas[0].0, false),
AccountMeta::new(bus_pdas[1].0, false),
AccountMeta::new(bus_pdas[2].0, false),
AccountMeta::new(bus_pdas[3].0, false),
AccountMeta::new(bus_pdas[4].0, false),
AccountMeta::new(bus_pdas[5].0, false),
AccountMeta::new(bus_pdas[6].0, false),
AccountMeta::new(bus_pdas[7].0, false),
AccountMeta::new(config_pda.0, false),
AccountMeta::new(metadata_pda.0, false),
AccountMeta::new(mint_pda.0, false),
AccountMeta::new(treasury_pda.0, false),
AccountMeta::new(TREASURY_TOKENS_ADDRESS, false),
AccountMeta::new_readonly(system_program::ID, false),
AccountMeta::new_readonly(spl_token::ID, false),
AccountMeta::new_readonly(spl_associated_token_account::ID, false),
AccountMeta::new_readonly(mpl_token_metadata::ID, false),
AccountMeta::new_readonly(sysvar::rent::ID, false),
],
data: Initialize {}.to_bytes(),
}
}
// Builds an initialize instruction.
// pub fn initialize(signer: Pubkey) -> Instruction {
// let bus_pdas = [
// bus_pda(0),
// bus_pda(1),
// bus_pda(2),
// bus_pda(3),
// bus_pda(4),
// bus_pda(5),
// bus_pda(6),
// bus_pda(7),
// ];
// let config_pda = config_pda();
// let mint_pda = Pubkey::find_program_address(&[MINT, MINT_NOISE.as_slice()], &crate::ID);
// let treasury_pda = treasury_pda();
// let metadata_pda = Pubkey::find_program_address(
// &[
// METADATA,
// mpl_token_metadata::ID.as_ref(),
// mint_pda.0.as_ref(),
// ],
// &mpl_token_metadata::ID,
// );
// Instruction {
// program_id: crate::ID,
// accounts: vec![
// AccountMeta::new(signer, true),
// AccountMeta::new(bus_pdas[0].0, false),
// AccountMeta::new(bus_pdas[1].0, false),
// AccountMeta::new(bus_pdas[2].0, false),
// AccountMeta::new(bus_pdas[3].0, false),
// AccountMeta::new(bus_pdas[4].0, false),
// AccountMeta::new(bus_pdas[5].0, false),
// AccountMeta::new(bus_pdas[6].0, false),
// AccountMeta::new(bus_pdas[7].0, false),
// AccountMeta::new(config_pda.0, false),
// AccountMeta::new(metadata_pda.0, false),
// AccountMeta::new(mint_pda.0, false),
// AccountMeta::new(treasury_pda.0, false),
// AccountMeta::new(TREASURY_TOKENS_ADDRESS, false),
// AccountMeta::new_readonly(system_program::ID, false),
// AccountMeta::new_readonly(spl_token::ID, false),
// AccountMeta::new_readonly(spl_associated_token_account::ID, false),
// AccountMeta::new_readonly(mpl_token_metadata::ID, false),
// AccountMeta::new_readonly(sysvar::rent::ID, false),
// ],
// data: Initialize {}.to_bytes(),
// }
// }

View File

@@ -1,25 +0,0 @@
use steel::*;
use super::OreAccount;
/// Bus accounts are responsible for distributing mining rewards. There are 8 busses total
/// to minimize write-lock contention and allow Solana to process mine instructions in parallel.
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
pub struct Bus {
/// The ID of the bus account.
pub id: u64,
/// The remaining rewards this bus has left to payout in the current epoch.
pub rewards: u64,
/// The rewards this bus would have paid out in the current epoch if there no limit.
/// This is used to calculate the updated reward rate.
pub theoretical_rewards: u64,
/// The largest known stake balance seen by the bus this epoch.
#[deprecated(since = "2.8.0", note = "Top balance is no longer tracked or used")]
pub top_balance: u64,
}
account!(OreAccount, Bus);

View File

@@ -6,17 +6,20 @@ use super::OreAccount;
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
pub struct Config {
/// The base reward rate paid out for a hash of minimum difficulty.
pub base_reward_rate: u64,
/// The timestamp of the last reset.
pub last_reset_at: i64,
/// The minimum accepted difficulty.
pub min_difficulty: u64,
/// The best difficulty score of this epoch.
pub best_difficulty: u64,
/// The proof of the best submitted hash of this epoch.
pub best_proof: Pubkey,
/// The challenge of this epoch.
pub challenge: [u8; 32],
/// The target emissions rate in ORE/min.
pub target_emmissions_rate: u64,
pub block_reward: u64,
}
account!(OreAccount, Config);

View File

@@ -1,9 +1,7 @@
mod bus;
mod config;
mod proof;
mod treasury;
pub use bus::*;
pub use config::*;
pub use proof::*;
pub use treasury::*;
@@ -15,17 +13,11 @@ use crate::consts::*;
#[repr(u8)]
#[derive(Clone, Copy, Debug, Eq, PartialEq, IntoPrimitive, TryFromPrimitive)]
pub enum OreAccount {
Bus = 100,
Config = 101,
Proof = 102,
Treasury = 103,
}
/// Fetch the PDA of a bus account.
pub fn bus_pda(id: u8) -> (Pubkey, u8) {
Pubkey::find_program_address(&[BUS, &[id]], &crate::id())
}
/// Derive the PDA of the config account.
pub fn config_pda() -> (Pubkey, u8) {
Pubkey::find_program_address(&[CONFIG], &crate::id())