Skip to content

Commit

Permalink
Use helper function for getting segment index, remove vote code
Browse files Browse the repository at this point in the history
  • Loading branch information
sakridge committed Dec 21, 2018
1 parent 2851613 commit e5d4cbf
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 106 deletions.
9 changes: 4 additions & 5 deletions programs/native/storage/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use solana_sdk::pubkey::Pubkey;
use solana_sdk::solana_entrypoint;
use solana_sdk::storage_program::*;

pub const ENTRIES_PER_SEGMENT: u64 = 16;
pub const TOTAL_VALIDATOR_REWARDS: u64 = 1000;
pub const TOTAL_REPLICATOR_REWARDS: u64 = 1000;

Expand Down Expand Up @@ -74,9 +73,9 @@ fn entrypoint(
entry_height,
signature,
} => {
let segment_index = (entry_height / ENTRIES_PER_SEGMENT) as usize;
let segment_index = get_segment_from_entry(entry_height);
let current_segment_index =
(storage_account_state.entry_height / ENTRIES_PER_SEGMENT) as usize;
get_segment_from_entry(storage_account_state.entry_height);
if segment_index >= current_segment_index {
return Err(ProgramError::InvalidArgument);
}
Expand Down Expand Up @@ -130,7 +129,7 @@ fn entrypoint(
return Err(ProgramError::InvalidArgument);
}

let segment_index = (entry_height / ENTRIES_PER_SEGMENT) as usize;
let segment_index = get_segment_from_entry(entry_height);
if storage_account_state.previous_proofs[segment_index].len() != proof_mask.len() {
return Err(ProgramError::InvalidArgument);
}
Expand All @@ -149,7 +148,7 @@ fn entrypoint(
storage_account_state.lockout_validations[segment_index].push(info);
}
StorageProgram::ClaimStorageReward { entry_height } => {
let claims_index = (entry_height / ENTRIES_PER_SEGMENT) as usize;
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;
Expand Down
6 changes: 6 additions & 0 deletions sdk/src/storage_program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ use crate::signature::Keypair;
use crate::signature::Signature;
use crate::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,
Expand Down
16 changes: 8 additions & 8 deletions src/chacha_cuda.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ use solana_sdk::hash::Hash;
use std::io;
use std::mem::size_of;

use crate::storage_stage::ENTRIES_PER_SEGMENT;
use solana_sdk::storage_program::ENTRIES_PER_SEGMENT;

// Encrypt a file with multiple starting IV states, determined by ivecs.len()
//
// Then sample each block at the offsets provided by samples argument with sha256
// and return the vec of sha states
pub fn chacha_cbc_encrypt_file_many_keys(
in_path: &str,
slice: u64,
segment: u64,
ivecs: &mut [u8],
samples: &[u64],
) -> io::Result<Vec<Hash>> {
Expand All @@ -36,7 +36,7 @@ pub fn chacha_cbc_encrypt_file_many_keys(
let mut sha_states = vec![0; num_keys * size_of::<Hash>()];
let mut int_sha_states = vec![0; num_keys * 112];
let keys: Vec<u8> = vec![0; num_keys * CHACHA_KEY_SIZE]; // keys not used ATM, uniqueness comes from IV
let mut entry = slice;
let mut entry = segment;
let mut total_entries = 0;
let mut total_entry_len = 0;
let mut time: f32 = 0.0;
Expand All @@ -51,8 +51,8 @@ pub fn chacha_cbc_encrypt_file_many_keys(
) {
Ok((num_entries, entry_len)) => {
info!(
"encrypting slice: {} num_entries: {} entry_len: {}",
slice, num_entries, entry_len
"encrypting segment: {} num_entries: {} entry_len: {}",
segment, num_entries, entry_len
);
let entry_len_usz = entry_len as usize;
unsafe {
Expand All @@ -74,10 +74,10 @@ pub fn chacha_cbc_encrypt_file_many_keys(
total_entries += num_entries;
entry += num_entries;
debug!(
"total entries: {} entry: {} slice: {} entries_per_slice: {}",
total_entries, entry, slice, ENTRIES_PER_SEGMENT
"total entries: {} entry: {} segment: {} entries_per_segment: {}",
total_entries, entry, segment, ENTRIES_PER_SEGMENT
);
if (entry - slice) >= ENTRIES_PER_SEGMENT {
if (entry - segment) >= ENTRIES_PER_SEGMENT {
break;
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/replicator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use crate::ledger::LEDGER_DATA_FILE;
use crate::result::Result;
use crate::rpc_request::{RpcClient, RpcRequest};
use crate::service::Service;
use crate::storage_stage::ENTRIES_PER_SEGMENT;
use crate::store_ledger_stage::StoreLedgerStage;
use crate::streamer::BlobReceiver;
use crate::thin_client::{retry_get_balance, ThinClient};
Expand All @@ -21,6 +20,7 @@ use solana_drone::drone::{request_airdrop_transaction, DRONE_PORT};
use solana_sdk::hash::{Hash, Hasher};
use solana_sdk::signature::{Keypair, KeypairUtil, Signature};
use solana_sdk::storage_program::StorageTransaction;
use solana_sdk::storage_program::{get_segment_from_entry, ENTRIES_PER_SEGMENT};
use solana_sdk::transaction::Transaction;
use std::fs::File;
use std::io;
Expand Down Expand Up @@ -93,8 +93,8 @@ fn get_entry_heights_from_last_id(
| (u64::from(signature_vec[1]) << 8)
| (u64::from(signature_vec[1]) << 16)
| (u64::from(signature_vec[2]) << 24);
let max_segment_index = storage_entry_height / ENTRIES_PER_SEGMENT;
segment_index %= max_segment_index;
let max_segment_index = get_segment_from_entry(storage_entry_height);
segment_index %= max_segment_index as u64;
let entry_height = segment_index * ENTRIES_PER_SEGMENT;
let max_entry_height = entry_height + ENTRIES_PER_SEGMENT;

Expand Down
Loading

0 comments on commit e5d4cbf

Please sign in to comment.