Boot storage program from the SDK
This commit is contained in:
@ -15,6 +15,7 @@ serde = "1.0.89"
|
||||
serde_derive = "1.0.89"
|
||||
solana-logger = { path = "../../logger", version = "0.12.0" }
|
||||
solana-sdk = { path = "../../sdk", version = "0.12.0" }
|
||||
solana-storage-api = { path = "../storage_api", version = "0.12.0" }
|
||||
|
||||
[dev-dependencies]
|
||||
solana-runtime = { path = "../../runtime", version = "0.12.0" }
|
||||
|
@ -9,7 +9,7 @@ use solana_sdk::account::KeyedAccount;
|
||||
use solana_sdk::native_program::ProgramError;
|
||||
use solana_sdk::pubkey::Pubkey;
|
||||
use solana_sdk::solana_entrypoint;
|
||||
use solana_sdk::storage_program::*;
|
||||
use solana_storage_api::*;
|
||||
|
||||
pub const TOTAL_VALIDATOR_REWARDS: u64 = 1000;
|
||||
pub const TOTAL_REPLICATOR_REWARDS: u64 = 1000;
|
||||
@ -180,9 +180,8 @@ mod test {
|
||||
use solana_sdk::account::{create_keyed_accounts, Account};
|
||||
use solana_sdk::hash::Hash;
|
||||
use solana_sdk::signature::{Keypair, KeypairUtil, Signature};
|
||||
use solana_sdk::storage_program::ProofStatus;
|
||||
use solana_sdk::storage_program::StorageTransaction;
|
||||
use solana_sdk::transaction::{Instruction, Transaction};
|
||||
use solana_storage_api::{ProofStatus, StorageTransaction};
|
||||
|
||||
fn test_transaction(
|
||||
tx: &Transaction,
|
||||
|
@ -5,16 +5,15 @@ use solana_sdk::genesis_block::GenesisBlock;
|
||||
use solana_sdk::hash::{hash, Hash};
|
||||
use solana_sdk::pubkey::Pubkey;
|
||||
use solana_sdk::signature::{Keypair, KeypairUtil};
|
||||
use solana_sdk::storage_program;
|
||||
use solana_sdk::storage_program::{StorageTransaction, ENTRIES_PER_SEGMENT};
|
||||
use solana_sdk::system_transaction::SystemTransaction;
|
||||
use solana_storage_api::{StorageTransaction, ENTRIES_PER_SEGMENT};
|
||||
|
||||
fn get_storage_entry_height(bank: &Bank, account: Pubkey) -> u64 {
|
||||
match bank.get_account(&account) {
|
||||
Some(storage_system_account) => {
|
||||
let state = deserialize(&storage_system_account.userdata);
|
||||
if let Ok(state) = state {
|
||||
let state: storage_program::StorageProgramState = state;
|
||||
let state: solana_storage_api::StorageProgramState = state;
|
||||
return state.entry_height;
|
||||
}
|
||||
}
|
||||
@ -29,7 +28,7 @@ fn get_storage_blockhash(bank: &Bank, account: Pubkey) -> Hash {
|
||||
if let Some(storage_system_account) = bank.get_account(&account) {
|
||||
let state = deserialize(&storage_system_account.userdata);
|
||||
if let Ok(state) = state {
|
||||
let state: storage_program::StorageProgramState = state;
|
||||
let state: solana_storage_api::StorageProgramState = state;
|
||||
return state.hash;
|
||||
}
|
||||
}
|
||||
@ -63,7 +62,7 @@ fn test_bank_storage() {
|
||||
blockhash,
|
||||
1,
|
||||
4 * 1024,
|
||||
storage_program::id(),
|
||||
solana_storage_api::id(),
|
||||
0,
|
||||
);
|
||||
|
||||
|
19
programs/storage_api/Cargo.toml
Normal file
19
programs/storage_api/Cargo.toml
Normal file
@ -0,0 +1,19 @@
|
||||
[package]
|
||||
name = "solana-storage-api"
|
||||
version = "0.12.0"
|
||||
description = "Solana Storage program API"
|
||||
authors = ["Solana Maintainers <maintainers@solana.com>"]
|
||||
repository = "https://github.com/solana-labs/solana"
|
||||
license = "Apache-2.0"
|
||||
homepage = "https://solana.com/"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
bincode = "1.1.2"
|
||||
serde = "1.0.89"
|
||||
serde_derive = "1.0.89"
|
||||
solana-sdk = { path = "../../sdk", version = "0.12.0" }
|
||||
|
||||
[lib]
|
||||
name = "solana_storage_api"
|
||||
crate-type = ["lib"]
|
130
programs/storage_api/src/lib.rs
Normal file
130
programs/storage_api/src/lib.rs
Normal file
@ -0,0 +1,130 @@
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use solana_sdk::hash::Hash;
|
||||
use solana_sdk::pubkey::Pubkey;
|
||||
use solana_sdk::signature::{Keypair, Signature};
|
||||
use solana_sdk::transaction::Transaction;
|
||||
|
||||
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,
|
||||
|
||||
pub proofs: Vec<Vec<ProofInfo>>,
|
||||
pub previous_proofs: Vec<Vec<ProofInfo>>,
|
||||
|
||||
pub lockout_validations: Vec<Vec<ValidationInfo>>,
|
||||
pub reward_validations: Vec<Vec<ValidationInfo>>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub enum StorageProgram {
|
||||
SubmitMiningProof {
|
||||
sha_state: Hash,
|
||||
entry_height: u64,
|
||||
signature: Signature,
|
||||
},
|
||||
AdvertiseStorageRecentBlockhash {
|
||||
hash: Hash,
|
||||
entry_height: u64,
|
||||
},
|
||||
ClaimStorageReward {
|
||||
entry_height: u64,
|
||||
},
|
||||
ProofValidation {
|
||||
entry_height: u64,
|
||||
proof_mask: Vec<ProofStatus>,
|
||||
},
|
||||
}
|
||||
|
||||
const STORAGE_PROGRAM_ID: [u8; 32] = [
|
||||
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 {}
|
||||
|
||||
impl StorageTransaction {
|
||||
pub fn new_mining_proof(
|
||||
from_keypair: &Keypair,
|
||||
sha_state: Hash,
|
||||
recent_blockhash: Hash,
|
||||
entry_height: u64,
|
||||
signature: Signature,
|
||||
) -> Transaction {
|
||||
let program = StorageProgram::SubmitMiningProof {
|
||||
sha_state,
|
||||
entry_height,
|
||||
signature,
|
||||
};
|
||||
Transaction::new(from_keypair, &[], id(), &program, recent_blockhash, 0)
|
||||
}
|
||||
|
||||
pub fn new_advertise_recent_blockhash(
|
||||
from_keypair: &Keypair,
|
||||
storage_hash: Hash,
|
||||
recent_blockhash: Hash,
|
||||
entry_height: u64,
|
||||
) -> Transaction {
|
||||
let program = StorageProgram::AdvertiseStorageRecentBlockhash {
|
||||
hash: storage_hash,
|
||||
entry_height,
|
||||
};
|
||||
Transaction::new(from_keypair, &[], id(), &program, recent_blockhash, 0)
|
||||
}
|
||||
|
||||
pub fn new_proof_validation(
|
||||
from_keypair: &Keypair,
|
||||
recent_blockhash: Hash,
|
||||
entry_height: u64,
|
||||
proof_mask: Vec<ProofStatus>,
|
||||
) -> Transaction {
|
||||
let program = StorageProgram::ProofValidation {
|
||||
entry_height,
|
||||
proof_mask,
|
||||
};
|
||||
Transaction::new(from_keypair, &[], id(), &program, recent_blockhash, 0)
|
||||
}
|
||||
|
||||
pub fn new_reward_claim(
|
||||
from_keypair: &Keypair,
|
||||
recent_blockhash: Hash,
|
||||
entry_height: u64,
|
||||
) -> Transaction {
|
||||
let program = StorageProgram::ClaimStorageReward { entry_height };
|
||||
Transaction::new(from_keypair, &[], id(), &program, recent_blockhash, 0)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user