optimization

This commit is contained in:
Hardhat Chad
2024-02-13 23:24:57 +00:00
parent 7cba1ff1da
commit 54b7a35433
15 changed files with 495 additions and 58 deletions

View File

@@ -8,12 +8,14 @@ use solana_program::keccak::{Hash as KeccakHash, HASH_BYTES};
pub struct Hash(pub [u8; HASH_BYTES]);
impl From<KeccakHash> for Hash {
#[inline(always)]
fn from(value: KeccakHash) -> Self {
unsafe { transmute(value) }
}
}
impl From<Hash> for KeccakHash {
#[inline(always)]
fn from(value: Hash) -> Self {
unsafe { transmute(value) }
}

View File

@@ -1,7 +1,9 @@
mod bus;
mod hash;
mod proof;
mod treasury;
pub use bus::*;
pub use hash::*;
pub use proof::*;
pub use treasury::*;

32
src/state/proof.rs Normal file
View File

@@ -0,0 +1,32 @@
use bytemuck::{Pod, Zeroable};
use solana_program::pubkey::Pubkey;
use super::Hash;
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
pub struct Proof {
/// The bump of the proof account PDA.
pub bump: u64,
/// The account (i.e. miner) authorized to use this proof.
pub authority: Pubkey,
/// The quantity of tokens this miner may claim from the treasury.
pub claimable_rewards: u64,
/// The proof's current hash.
pub hash: Hash,
/// The total lifetime hashes provided by this miner.
pub total_hashes: u64,
/// The total lifetime rewards distributed to this miner.
pub total_rewards: u64,
}
impl Proof {
pub fn to_bytes(&self) -> &[u8] {
bytemuck::bytes_of(self)
}
}