2019-03-22 06:47:05 -06:00
|
|
|
//! storage program
|
|
|
|
//! Receive mining proofs from miners, validate the answers
|
|
|
|
//! and give reward for good proofs.
|
|
|
|
|
2019-03-22 20:16:44 -06:00
|
|
|
use crate::storage_contract::{ProofInfo, ProofStatus, StorageContract, ValidationInfo};
|
2019-03-22 14:30:18 -06:00
|
|
|
use crate::storage_instruction::StorageInstruction;
|
|
|
|
use crate::{get_segment_from_entry, ENTRIES_PER_SEGMENT};
|
2019-03-22 06:47:05 -06:00
|
|
|
use log::*;
|
|
|
|
use solana_sdk::account::KeyedAccount;
|
2019-03-23 21:12:27 -06:00
|
|
|
use solana_sdk::instruction::InstructionError;
|
2019-03-22 06:47:05 -06:00
|
|
|
use solana_sdk::pubkey::Pubkey;
|
|
|
|
|
|
|
|
pub const TOTAL_VALIDATOR_REWARDS: u64 = 1000;
|
|
|
|
pub const TOTAL_REPLICATOR_REWARDS: u64 = 1000;
|
|
|
|
|
|
|
|
fn count_valid_proofs(proofs: &[ProofStatus]) -> u64 {
|
|
|
|
let mut num = 0;
|
|
|
|
for proof in proofs {
|
|
|
|
if let ProofStatus::Valid = proof {
|
|
|
|
num += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
num
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn process_instruction(
|
|
|
|
_program_id: &Pubkey,
|
|
|
|
keyed_accounts: &mut [KeyedAccount],
|
|
|
|
data: &[u8],
|
|
|
|
_tick_height: u64,
|
|
|
|
) -> Result<(), InstructionError> {
|
|
|
|
solana_logger::setup();
|
|
|
|
|
|
|
|
if keyed_accounts.len() != 1 {
|
|
|
|
// keyed_accounts[1] should be the main storage key
|
|
|
|
// to access its data
|
|
|
|
Err(InstructionError::InvalidArgument)?;
|
|
|
|
}
|
|
|
|
|
|
|
|
// accounts_keys[0] must be signed
|
|
|
|
if keyed_accounts[0].signer_key().is_none() {
|
|
|
|
info!("account[0] is unsigned");
|
|
|
|
Err(InstructionError::GenericError)?;
|
|
|
|
}
|
|
|
|
|
|
|
|
if let Ok(syscall) = bincode::deserialize(data) {
|
2019-03-22 20:16:44 -06:00
|
|
|
let mut storage_contract =
|
|
|
|
if let Ok(storage_contract) = bincode::deserialize(&keyed_accounts[0].account.data) {
|
|
|
|
storage_contract
|
|
|
|
} else {
|
|
|
|
StorageContract::default()
|
|
|
|
};
|
2019-03-22 06:47:05 -06:00
|
|
|
|
|
|
|
debug!(
|
2019-03-22 20:16:44 -06:00
|
|
|
"deserialized contract height: {}",
|
|
|
|
storage_contract.entry_height
|
2019-03-22 06:47:05 -06:00
|
|
|
);
|
|
|
|
match syscall {
|
2019-03-22 14:30:18 -06:00
|
|
|
StorageInstruction::SubmitMiningProof {
|
2019-03-22 06:47:05 -06:00
|
|
|
sha_state,
|
|
|
|
entry_height,
|
|
|
|
signature,
|
|
|
|
} => {
|
|
|
|
let segment_index = get_segment_from_entry(entry_height);
|
2019-03-22 20:16:44 -06:00
|
|
|
let current_segment_index = get_segment_from_entry(storage_contract.entry_height);
|
2019-03-22 06:47:05 -06:00
|
|
|
if segment_index >= current_segment_index {
|
|
|
|
return Err(InstructionError::InvalidArgument);
|
|
|
|
}
|
|
|
|
|
|
|
|
debug!(
|
2019-03-22 20:16:44 -06:00
|
|
|
"Mining proof submitted with contract {:?} entry_height: {}",
|
2019-03-22 06:47:05 -06:00
|
|
|
sha_state, entry_height
|
|
|
|
);
|
|
|
|
|
|
|
|
let proof_info = ProofInfo {
|
|
|
|
id: *keyed_accounts[0].signer_key().unwrap(),
|
|
|
|
sha_state,
|
|
|
|
signature,
|
|
|
|
};
|
2019-03-22 20:16:44 -06:00
|
|
|
storage_contract.proofs[segment_index].push(proof_info);
|
2019-03-22 06:47:05 -06:00
|
|
|
}
|
2019-03-22 14:30:18 -06:00
|
|
|
StorageInstruction::AdvertiseStorageRecentBlockhash { hash, entry_height } => {
|
2019-03-22 20:16:44 -06:00
|
|
|
let original_segments = storage_contract.entry_height / ENTRIES_PER_SEGMENT;
|
2019-03-22 06:47:05 -06:00
|
|
|
let segments = entry_height / ENTRIES_PER_SEGMENT;
|
|
|
|
debug!(
|
|
|
|
"advertise new last id segments: {} orig: {}",
|
|
|
|
segments, original_segments
|
|
|
|
);
|
|
|
|
if segments <= original_segments {
|
|
|
|
return Err(InstructionError::InvalidArgument);
|
|
|
|
}
|
|
|
|
|
2019-03-22 20:16:44 -06:00
|
|
|
storage_contract.entry_height = entry_height;
|
|
|
|
storage_contract.hash = hash;
|
2019-03-22 06:47:05 -06:00
|
|
|
|
|
|
|
// move the proofs to previous_proofs
|
2019-03-22 20:16:44 -06:00
|
|
|
storage_contract.previous_proofs = storage_contract.proofs.clone();
|
|
|
|
storage_contract.proofs.clear();
|
|
|
|
storage_contract
|
2019-03-22 06:47:05 -06:00
|
|
|
.proofs
|
|
|
|
.resize(segments as usize, Vec::new());
|
|
|
|
|
|
|
|
// move lockout_validations to reward_validations
|
2019-03-22 20:16:44 -06:00
|
|
|
storage_contract.reward_validations = storage_contract.lockout_validations.clone();
|
|
|
|
storage_contract.lockout_validations.clear();
|
|
|
|
storage_contract
|
2019-03-22 06:47:05 -06:00
|
|
|
.lockout_validations
|
|
|
|
.resize(segments as usize, Vec::new());
|
|
|
|
}
|
2019-03-22 14:30:18 -06:00
|
|
|
StorageInstruction::ProofValidation {
|
2019-03-22 06:47:05 -06:00
|
|
|
entry_height,
|
|
|
|
proof_mask,
|
|
|
|
} => {
|
2019-03-22 20:16:44 -06:00
|
|
|
if entry_height >= storage_contract.entry_height {
|
2019-03-22 06:47:05 -06:00
|
|
|
return Err(InstructionError::InvalidArgument);
|
|
|
|
}
|
|
|
|
|
|
|
|
let segment_index = get_segment_from_entry(entry_height);
|
2019-03-22 20:16:44 -06:00
|
|
|
if storage_contract.previous_proofs[segment_index].len() != proof_mask.len() {
|
2019-03-22 06:47:05 -06:00
|
|
|
return Err(InstructionError::InvalidArgument);
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Check that each proof mask matches the signature
|
|
|
|
/*for (i, entry) in proof_mask.iter().enumerate() {
|
2019-03-22 20:16:44 -06:00
|
|
|
if storage_contract.previous_proofs[segment_index][i] != signature.as_ref[0] {
|
2019-03-22 06:47:05 -06:00
|
|
|
return Err(InstructionError::InvalidArgument);
|
|
|
|
}
|
|
|
|
}*/
|
|
|
|
|
|
|
|
let info = ValidationInfo {
|
|
|
|
id: *keyed_accounts[0].signer_key().unwrap(),
|
|
|
|
proof_mask,
|
|
|
|
};
|
2019-03-22 20:16:44 -06:00
|
|
|
storage_contract.lockout_validations[segment_index].push(info);
|
2019-03-22 06:47:05 -06:00
|
|
|
}
|
2019-03-22 14:30:18 -06:00
|
|
|
StorageInstruction::ClaimStorageReward { entry_height } => {
|
2019-03-22 06:47:05 -06:00
|
|
|
let claims_index = get_segment_from_entry(entry_height);
|
|
|
|
let account_key = keyed_accounts[0].signer_key().unwrap();
|
|
|
|
let mut num_validations = 0;
|
|
|
|
let mut total_validations = 0;
|
2019-03-22 20:16:44 -06:00
|
|
|
for validation in &storage_contract.reward_validations[claims_index] {
|
2019-03-22 06:47:05 -06:00
|
|
|
if *account_key == validation.id {
|
|
|
|
num_validations += count_valid_proofs(&validation.proof_mask);
|
|
|
|
} else {
|
|
|
|
total_validations += count_valid_proofs(&validation.proof_mask);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
total_validations += num_validations;
|
|
|
|
if total_validations > 0 {
|
|
|
|
keyed_accounts[0].account.lamports +=
|
|
|
|
(TOTAL_VALIDATOR_REWARDS * num_validations) / total_validations;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-22 20:16:44 -06:00
|
|
|
if bincode::serialize_into(&mut keyed_accounts[0].account.data[..], &storage_contract)
|
|
|
|
.is_err()
|
2019-03-22 06:47:05 -06:00
|
|
|
{
|
|
|
|
return Err(InstructionError::AccountDataTooSmall);
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
} else {
|
|
|
|
info!("Invalid instruction data: {:?}", data);
|
|
|
|
Err(InstructionError::InvalidInstructionData)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use super::*;
|
2019-03-22 14:30:18 -06:00
|
|
|
use crate::id;
|
2019-03-22 20:16:44 -06:00
|
|
|
use crate::storage_contract::ProofStatus;
|
2019-03-22 14:30:18 -06:00
|
|
|
use crate::ENTRIES_PER_SEGMENT;
|
2019-03-22 06:47:05 -06:00
|
|
|
use bincode::deserialize;
|
|
|
|
use solana_runtime::bank::Bank;
|
2019-03-22 22:02:00 -06:00
|
|
|
use solana_runtime::bank_client::BankClient;
|
2019-03-22 06:47:05 -06:00
|
|
|
use solana_sdk::account::{create_keyed_accounts, Account};
|
|
|
|
use solana_sdk::genesis_block::GenesisBlock;
|
|
|
|
use solana_sdk::hash::{hash, Hash};
|
2019-03-22 22:02:00 -06:00
|
|
|
use solana_sdk::instruction::Instruction;
|
2019-03-22 06:47:05 -06:00
|
|
|
use solana_sdk::pubkey::Pubkey;
|
|
|
|
use solana_sdk::signature::{Keypair, KeypairUtil, Signature};
|
2019-03-22 22:02:00 -06:00
|
|
|
use solana_sdk::system_instruction::SystemInstruction;
|
2019-03-22 06:47:05 -06:00
|
|
|
|
2019-03-22 22:02:00 -06:00
|
|
|
fn test_instruction(
|
|
|
|
ix: &Instruction,
|
2019-03-22 06:47:05 -06:00
|
|
|
program_accounts: &mut [Account],
|
|
|
|
) -> Result<(), InstructionError> {
|
2019-03-22 22:02:00 -06:00
|
|
|
let mut keyed_accounts: Vec<_> = ix
|
|
|
|
.accounts
|
2019-03-22 06:47:05 -06:00
|
|
|
.iter()
|
|
|
|
.zip(program_accounts.iter_mut())
|
2019-03-22 22:02:00 -06:00
|
|
|
.map(|(account_meta, account)| {
|
|
|
|
KeyedAccount::new(&account_meta.pubkey, account_meta.is_signer, account)
|
|
|
|
})
|
2019-03-22 06:47:05 -06:00
|
|
|
.collect();
|
|
|
|
|
2019-03-22 22:02:00 -06:00
|
|
|
let ret = process_instruction(&id(), &mut keyed_accounts, &ix.data, 42);
|
2019-03-22 06:47:05 -06:00
|
|
|
info!("ret: {:?}", ret);
|
|
|
|
ret
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_storage_tx() {
|
2019-03-30 21:37:33 -06:00
|
|
|
let pubkey = Pubkey::new_rand();
|
2019-03-22 22:02:00 -06:00
|
|
|
let mut accounts = [(pubkey, Account::default())];
|
2019-03-22 06:47:05 -06:00
|
|
|
let mut keyed_accounts = create_keyed_accounts(&mut accounts);
|
|
|
|
assert!(process_instruction(&id(), &mut keyed_accounts, &[], 42).is_err());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_serialize_overflow() {
|
2019-03-30 21:37:33 -06:00
|
|
|
let pubkey = Pubkey::new_rand();
|
2019-03-22 06:47:05 -06:00
|
|
|
let mut keyed_accounts = Vec::new();
|
|
|
|
let mut user_account = Account::default();
|
|
|
|
keyed_accounts.push(KeyedAccount::new(&pubkey, true, &mut user_account));
|
|
|
|
|
2019-03-22 22:02:00 -06:00
|
|
|
let ix = StorageInstruction::new_advertise_recent_blockhash(
|
|
|
|
&pubkey,
|
2019-03-22 06:47:05 -06:00
|
|
|
Hash::default(),
|
|
|
|
ENTRIES_PER_SEGMENT,
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(
|
2019-03-22 22:02:00 -06:00
|
|
|
process_instruction(&id(), &mut keyed_accounts, &ix.data, 42),
|
2019-03-22 06:47:05 -06:00
|
|
|
Err(InstructionError::AccountDataTooSmall)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_invalid_accounts_len() {
|
2019-03-30 21:37:33 -06:00
|
|
|
let pubkey = Pubkey::new_rand();
|
2019-03-22 06:47:05 -06:00
|
|
|
let mut accounts = [Account::default()];
|
|
|
|
|
2019-03-22 22:02:00 -06:00
|
|
|
let ix =
|
|
|
|
StorageInstruction::new_mining_proof(&pubkey, Hash::default(), 0, Signature::default());
|
|
|
|
assert!(test_instruction(&ix, &mut accounts).is_err());
|
2019-03-22 06:47:05 -06:00
|
|
|
|
|
|
|
let mut accounts = [Account::default(), Account::default(), Account::default()];
|
|
|
|
|
2019-03-22 22:02:00 -06:00
|
|
|
assert!(test_instruction(&ix, &mut accounts).is_err());
|
2019-03-22 06:47:05 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_submit_mining_invalid_entry_height() {
|
|
|
|
solana_logger::setup();
|
2019-03-30 21:37:33 -06:00
|
|
|
let pubkey = Pubkey::new_rand();
|
2019-03-22 06:47:05 -06:00
|
|
|
let mut accounts = [Account::default(), Account::default()];
|
|
|
|
accounts[1].data.resize(16 * 1024, 0);
|
|
|
|
|
2019-03-22 22:02:00 -06:00
|
|
|
let ix =
|
|
|
|
StorageInstruction::new_mining_proof(&pubkey, Hash::default(), 0, Signature::default());
|
2019-03-22 06:47:05 -06:00
|
|
|
|
|
|
|
// Haven't seen a transaction to roll over the epoch, so this should fail
|
2019-03-22 22:02:00 -06:00
|
|
|
assert!(test_instruction(&ix, &mut accounts).is_err());
|
2019-03-22 06:47:05 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_submit_mining_ok() {
|
|
|
|
solana_logger::setup();
|
2019-03-30 21:37:33 -06:00
|
|
|
let pubkey = Pubkey::new_rand();
|
2019-03-22 06:47:05 -06:00
|
|
|
let mut accounts = [Account::default(), Account::default()];
|
|
|
|
accounts[0].data.resize(16 * 1024, 0);
|
|
|
|
|
2019-03-22 22:02:00 -06:00
|
|
|
let ix = StorageInstruction::new_advertise_recent_blockhash(
|
|
|
|
&pubkey,
|
2019-03-22 06:47:05 -06:00
|
|
|
Hash::default(),
|
|
|
|
ENTRIES_PER_SEGMENT,
|
|
|
|
);
|
|
|
|
|
2019-03-22 22:02:00 -06:00
|
|
|
test_instruction(&ix, &mut accounts).unwrap();
|
2019-03-22 06:47:05 -06:00
|
|
|
|
2019-03-22 22:02:00 -06:00
|
|
|
let ix =
|
|
|
|
StorageInstruction::new_mining_proof(&pubkey, Hash::default(), 0, Signature::default());
|
2019-03-22 06:47:05 -06:00
|
|
|
|
2019-03-22 22:02:00 -06:00
|
|
|
test_instruction(&ix, &mut accounts).unwrap();
|
2019-03-22 06:47:05 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_validate_mining() {
|
|
|
|
solana_logger::setup();
|
2019-03-30 21:37:33 -06:00
|
|
|
let pubkey = Pubkey::new_rand();
|
2019-03-22 06:47:05 -06:00
|
|
|
let mut accounts = [Account::default(), Account::default()];
|
|
|
|
accounts[0].data.resize(16 * 1024, 0);
|
|
|
|
|
|
|
|
let entry_height = 0;
|
|
|
|
|
2019-03-22 22:02:00 -06:00
|
|
|
let ix = StorageInstruction::new_advertise_recent_blockhash(
|
|
|
|
&pubkey,
|
2019-03-22 06:47:05 -06:00
|
|
|
Hash::default(),
|
|
|
|
ENTRIES_PER_SEGMENT,
|
|
|
|
);
|
|
|
|
|
2019-03-22 22:02:00 -06:00
|
|
|
test_instruction(&ix, &mut accounts).unwrap();
|
2019-03-22 06:47:05 -06:00
|
|
|
|
2019-03-22 22:02:00 -06:00
|
|
|
let ix = StorageInstruction::new_mining_proof(
|
|
|
|
&pubkey,
|
2019-03-22 06:47:05 -06:00
|
|
|
Hash::default(),
|
|
|
|
entry_height,
|
|
|
|
Signature::default(),
|
|
|
|
);
|
2019-03-22 22:02:00 -06:00
|
|
|
test_instruction(&ix, &mut accounts).unwrap();
|
2019-03-22 06:47:05 -06:00
|
|
|
|
2019-03-22 22:02:00 -06:00
|
|
|
let ix = StorageInstruction::new_advertise_recent_blockhash(
|
|
|
|
&pubkey,
|
2019-03-22 06:47:05 -06:00
|
|
|
Hash::default(),
|
|
|
|
ENTRIES_PER_SEGMENT * 2,
|
|
|
|
);
|
2019-03-22 22:02:00 -06:00
|
|
|
test_instruction(&ix, &mut accounts).unwrap();
|
2019-03-22 06:47:05 -06:00
|
|
|
|
2019-03-22 22:02:00 -06:00
|
|
|
let ix = StorageInstruction::new_proof_validation(
|
|
|
|
&pubkey,
|
2019-03-22 06:47:05 -06:00
|
|
|
entry_height,
|
|
|
|
vec![ProofStatus::Valid],
|
|
|
|
);
|
2019-03-22 22:02:00 -06:00
|
|
|
test_instruction(&ix, &mut accounts).unwrap();
|
2019-03-22 06:47:05 -06:00
|
|
|
|
2019-03-22 22:02:00 -06:00
|
|
|
let ix = StorageInstruction::new_advertise_recent_blockhash(
|
|
|
|
&pubkey,
|
2019-03-22 06:47:05 -06:00
|
|
|
Hash::default(),
|
|
|
|
ENTRIES_PER_SEGMENT * 3,
|
|
|
|
);
|
2019-03-22 22:02:00 -06:00
|
|
|
test_instruction(&ix, &mut accounts).unwrap();
|
2019-03-22 06:47:05 -06:00
|
|
|
|
2019-03-22 22:02:00 -06:00
|
|
|
let ix = StorageInstruction::new_reward_claim(&pubkey, entry_height);
|
|
|
|
test_instruction(&ix, &mut accounts).unwrap();
|
2019-03-22 06:47:05 -06:00
|
|
|
|
|
|
|
assert!(accounts[0].lamports == TOTAL_VALIDATOR_REWARDS);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn get_storage_entry_height(bank: &Bank, account: &Pubkey) -> u64 {
|
|
|
|
match bank.get_account(&account) {
|
|
|
|
Some(storage_system_account) => {
|
2019-03-22 20:16:44 -06:00
|
|
|
let contract = deserialize(&storage_system_account.data);
|
|
|
|
if let Ok(contract) = contract {
|
|
|
|
let contract: StorageContract = contract;
|
|
|
|
return contract.entry_height;
|
2019-03-22 06:47:05 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
None => {
|
|
|
|
info!("error in reading entry_height");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
0
|
|
|
|
}
|
|
|
|
|
|
|
|
fn get_storage_blockhash(bank: &Bank, account: &Pubkey) -> Hash {
|
|
|
|
if let Some(storage_system_account) = bank.get_account(&account) {
|
2019-03-22 20:16:44 -06:00
|
|
|
let contract = deserialize(&storage_system_account.data);
|
|
|
|
if let Ok(contract) = contract {
|
|
|
|
let contract: StorageContract = contract;
|
|
|
|
return contract.hash;
|
2019-03-22 06:47:05 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
Hash::default()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_bank_storage() {
|
2019-03-27 09:15:37 -06:00
|
|
|
let (genesis_block, alice_keypair) = GenesisBlock::new(1000);
|
2019-03-27 07:34:01 -06:00
|
|
|
let alice_pubkey = alice_keypair.pubkey();
|
2019-03-22 22:02:00 -06:00
|
|
|
let bob_keypair = Keypair::new();
|
2019-03-27 07:34:01 -06:00
|
|
|
let bob_pubkey = bob_keypair.pubkey();
|
2019-03-30 21:37:33 -06:00
|
|
|
let jack_pubkey = Pubkey::new_rand();
|
|
|
|
let jill_pubkey = Pubkey::new_rand();
|
2019-03-22 06:47:05 -06:00
|
|
|
|
2019-03-27 09:15:37 -06:00
|
|
|
let mut bank = Bank::new(&genesis_block);
|
|
|
|
bank.add_instruction_processor(id(), process_instruction);
|
2019-03-27 07:34:01 -06:00
|
|
|
let bank_client = BankClient::new(&bank);
|
|
|
|
|
2019-03-22 06:47:05 -06:00
|
|
|
let x = 42;
|
|
|
|
let blockhash = genesis_block.hash();
|
|
|
|
let x2 = x * 2;
|
|
|
|
let storage_blockhash = hash(&[x2]);
|
|
|
|
|
|
|
|
bank.register_tick(&blockhash);
|
|
|
|
|
2019-03-27 07:34:01 -06:00
|
|
|
bank_client
|
|
|
|
.transfer(10, &alice_keypair, &jill_pubkey)
|
|
|
|
.unwrap();
|
|
|
|
bank_client
|
|
|
|
.transfer(10, &alice_keypair, &bob_pubkey)
|
|
|
|
.unwrap();
|
|
|
|
bank_client
|
|
|
|
.transfer(10, &alice_keypair, &jack_pubkey)
|
|
|
|
.unwrap();
|
2019-03-22 06:47:05 -06:00
|
|
|
|
2019-03-22 22:02:00 -06:00
|
|
|
let ix =
|
|
|
|
SystemInstruction::new_program_account(&alice_pubkey, &bob_pubkey, 1, 4 * 1024, &id());
|
2019-03-22 06:47:05 -06:00
|
|
|
|
2019-03-27 07:34:01 -06:00
|
|
|
bank_client.process_instruction(&alice_keypair, ix).unwrap();
|
2019-03-22 22:02:00 -06:00
|
|
|
|
|
|
|
let ix = StorageInstruction::new_advertise_recent_blockhash(
|
|
|
|
&bob_pubkey,
|
2019-03-22 06:47:05 -06:00
|
|
|
storage_blockhash,
|
|
|
|
ENTRIES_PER_SEGMENT,
|
|
|
|
);
|
|
|
|
|
2019-03-27 07:34:01 -06:00
|
|
|
bank_client.process_instruction(&bob_keypair, ix).unwrap();
|
2019-03-22 06:47:05 -06:00
|
|
|
|
|
|
|
let entry_height = 0;
|
2019-03-22 22:02:00 -06:00
|
|
|
let ix = StorageInstruction::new_mining_proof(
|
|
|
|
&bob_pubkey,
|
2019-03-22 06:47:05 -06:00
|
|
|
Hash::default(),
|
|
|
|
entry_height,
|
|
|
|
Signature::default(),
|
|
|
|
);
|
2019-03-27 07:34:01 -06:00
|
|
|
let _result = bank_client.process_instruction(&bob_keypair, ix).unwrap();
|
2019-03-22 06:47:05 -06:00
|
|
|
|
|
|
|
assert_eq!(
|
2019-03-22 22:02:00 -06:00
|
|
|
get_storage_entry_height(&bank, &bob_pubkey),
|
2019-03-22 06:47:05 -06:00
|
|
|
ENTRIES_PER_SEGMENT
|
|
|
|
);
|
2019-03-22 22:02:00 -06:00
|
|
|
assert_eq!(get_storage_blockhash(&bank, &bob_pubkey), storage_blockhash);
|
2019-03-22 06:47:05 -06:00
|
|
|
}
|
|
|
|
}
|