Files
solana/sdk/src/storage_program.rs

130 lines
3.3 KiB
Rust
Raw Normal View History

2018-12-14 20:39:10 -08:00
use crate::hash::Hash;
use crate::pubkey::Pubkey;
2019-01-17 14:41:48 -08:00
use crate::signature::{Keypair, Signature};
2018-12-14 20:39:10 -08:00
use crate::transaction::Transaction;
2018-12-04 08:20:41 -08:00
2019-01-17 14:41:48 -08:00
pub const ENTRIES_PER_SEGMENT: u64 = 16;
pub fn get_segment_from_entry(entry_height: u64) -> usize {
(entry_height / ENTRIES_PER_SEGMENT) as usize
}
#[derive(Debug, Serialize, Deserialize, Clone)]
pub enum ProofStatus {
Valid,
NotValid,
Skipped,
}
#[derive(Default, Debug, Serialize, Deserialize, Clone)]
pub struct ProofInfo {
pub id: Pubkey,
pub signature: Signature,
pub sha_state: Hash,
}
#[derive(Default, Debug, Serialize, Deserialize, Clone)]
pub struct ValidationInfo {
pub id: Pubkey,
pub proof_mask: Vec<ProofStatus>,
}
#[derive(Default, Debug, Serialize, Deserialize)]
pub struct StorageProgramState {
pub entry_height: u64,
pub hash: Hash,
2019-01-17 14:41:48 -08:00
pub proofs: Vec<Vec<ProofInfo>>,
pub previous_proofs: Vec<Vec<ProofInfo>>,
pub lockout_validations: Vec<Vec<ValidationInfo>>,
pub reward_validations: Vec<Vec<ValidationInfo>>,
}
2018-12-04 08:20:41 -08:00
#[derive(Serialize, Deserialize, Debug, Clone)]
pub enum StorageProgram {
SubmitMiningProof {
sha_state: Hash,
entry_height: u64,
signature: Signature,
},
2019-03-02 10:25:16 -08:00
AdvertiseStorageRecentBlockhash {
hash: Hash,
2019-01-17 14:41:48 -08:00
entry_height: u64,
},
ClaimStorageReward {
entry_height: u64,
},
ProofValidation {
entry_height: u64,
proof_mask: Vec<ProofStatus>,
},
2018-12-04 08:20:41 -08:00
}
2019-03-02 18:17:17 -07:00
const STORAGE_PROGRAM_ID: [u8; 32] = [
2018-12-04 08:20:41 -08:00
130, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0,
];
pub fn check_id(program_id: &Pubkey) -> bool {
program_id.as_ref() == STORAGE_PROGRAM_ID
}
pub fn id() -> Pubkey {
Pubkey::new(&STORAGE_PROGRAM_ID)
}
pub struct StorageTransaction {}
2019-01-17 14:41:48 -08:00
impl StorageTransaction {
pub fn new_mining_proof(
from_keypair: &Keypair,
sha_state: Hash,
2019-03-02 10:25:16 -08:00
recent_blockhash: Hash,
entry_height: u64,
signature: Signature,
) -> Transaction {
let program = StorageProgram::SubmitMiningProof {
sha_state,
entry_height,
signature,
};
2019-03-02 10:25:16 -08:00
Transaction::new(from_keypair, &[], id(), &program, recent_blockhash, 0)
2019-01-17 14:41:48 -08:00
}
2019-03-02 10:25:16 -08:00
pub fn new_advertise_recent_blockhash(
2019-01-17 14:41:48 -08:00
from_keypair: &Keypair,
storage_hash: Hash,
2019-03-02 10:25:16 -08:00
recent_blockhash: Hash,
2019-01-17 14:41:48 -08:00
entry_height: u64,
) -> Transaction {
2019-03-02 10:25:16 -08:00
let program = StorageProgram::AdvertiseStorageRecentBlockhash {
hash: storage_hash,
2019-01-17 14:41:48 -08:00
entry_height,
};
2019-03-02 10:25:16 -08:00
Transaction::new(from_keypair, &[], id(), &program, recent_blockhash, 0)
2019-01-17 14:41:48 -08:00
}
pub fn new_proof_validation(
2019-01-17 14:41:48 -08:00
from_keypair: &Keypair,
2019-03-02 10:25:16 -08:00
recent_blockhash: Hash,
2019-01-17 14:41:48 -08:00
entry_height: u64,
proof_mask: Vec<ProofStatus>,
) -> Transaction {
2019-01-17 14:41:48 -08:00
let program = StorageProgram::ProofValidation {
entry_height,
proof_mask,
};
2019-03-02 10:25:16 -08:00
Transaction::new(from_keypair, &[], id(), &program, recent_blockhash, 0)
2019-01-17 14:41:48 -08:00
}
pub fn new_reward_claim(
from_keypair: &Keypair,
2019-03-02 10:25:16 -08:00
recent_blockhash: Hash,
entry_height: u64,
) -> Transaction {
2019-01-17 14:41:48 -08:00
let program = StorageProgram::ClaimStorageReward { entry_height };
2019-03-02 10:25:16 -08:00
Transaction::new(from_keypair, &[], id(), &program, recent_blockhash, 0)
2018-12-04 08:20:41 -08:00
}
}