Fix bug in storage processor and remove duplicate Constant (#4294)

* Fix bug in storage processor and remove duplicate Constant

* Add test

* Bump replicator timeout
This commit is contained in:
Sagar Dhawan 2019-05-15 13:28:56 -07:00 committed by GitHub
parent 2bef1b0433
commit 4576250342
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 28 additions and 13 deletions

View File

@ -1,12 +1,11 @@
use crate::blocktree::Blocktree;
use solana_storage_api::SLOTS_PER_SEGMENT;
use std::fs::File;
use std::io;
use std::io::{BufWriter, Write};
use std::path::Path;
use std::sync::Arc;
use crate::storage_stage::SLOTS_PER_SEGMENT;
pub const CHACHA_BLOCK_SIZE: usize = 64;
pub const CHACHA_KEY_SIZE: usize = 32;

View File

@ -7,12 +7,11 @@ use crate::sigverify::{
chacha_cbc_encrypt_many_sample, chacha_end_sha_state, chacha_init_sha_state,
};
use solana_sdk::hash::Hash;
use solana_storage_api::SLOTS_PER_SEGMENT;
use std::io;
use std::mem::size_of;
use std::sync::Arc;
use crate::storage_stage::SLOTS_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

View File

@ -9,7 +9,6 @@ use crate::packet::to_shared_blob;
use crate::repair_service::{RepairSlotRange, RepairStrategy};
use crate::result::Result;
use crate::service::Service;
use crate::storage_stage::SLOTS_PER_SEGMENT;
use crate::streamer::receiver;
use crate::streamer::responder;
use crate::window_service::WindowService;
@ -29,7 +28,7 @@ use solana_sdk::signature::{Keypair, KeypairUtil, Signature};
use solana_sdk::system_transaction;
use solana_sdk::transaction::Transaction;
use solana_sdk::transport::TransportError;
use solana_storage_api::{get_segment_from_slot, storage_instruction};
use solana_storage_api::{get_segment_from_slot, storage_instruction, SLOTS_PER_SEGMENT};
use std::fs::File;
use std::io;
use std::io::BufReader;
@ -530,7 +529,7 @@ impl Replicator {
if get_segment_from_slot(storage_slot) != 0 {
return Ok((storage_blockhash, storage_slot));
}
sleep(Duration::from_secs(3));
sleep(Duration::from_secs(5));
}
Err(Error::new(
ErrorKind::Other,

View File

@ -60,7 +60,6 @@ pub const STORAGE_ROTATE_TEST_COUNT: u64 = 2;
// TODO: some way to dynamically size NUM_IDENTITIES
const NUM_IDENTITIES: usize = 1024;
pub const NUM_STORAGE_SAMPLES: usize = 4;
pub const SLOTS_PER_SEGMENT: u64 = 16;
const KEY_SIZE: usize = 64;
type InstructionSender = Sender<Instruction>;
@ -463,6 +462,7 @@ mod tests {
use solana_sdk::hash::{Hash, Hasher};
use solana_sdk::pubkey::Pubkey;
use solana_sdk::signature::{Keypair, KeypairUtil};
use solana_storage_api::SLOTS_PER_SEGMENT;
use std::cmp::{max, min};
use std::fs::remove_dir_all;
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
@ -547,7 +547,7 @@ mod tests {
let mut result = storage_state.get_mining_result(&signature);
assert_eq!(result, Hash::default());
for i in slot..slot + 3 {
for i in slot..slot + SLOTS_PER_SEGMENT + 1 {
blocktree
.write_entries(i, 0, 0, ticks_per_slot, &entries)
.unwrap();

View File

@ -2,7 +2,7 @@ pub mod storage_contract;
pub mod storage_instruction;
pub mod storage_processor;
pub const SLOTS_PER_SEGMENT: u64 = 2;
pub const SLOTS_PER_SEGMENT: u64 = 16;
pub fn get_segment_from_slot(slot: u64) -> usize {
(slot / SLOTS_PER_SEGMENT) as usize

View File

@ -81,11 +81,11 @@ impl<'a> StorageAccount<'a> {
if let StorageContract::ReplicatorStorage { proofs, .. } = &mut storage_contract {
let segment_index = get_segment_from_slot(slot);
if segment_index > proofs.len() || proofs.is_empty() {
proofs.resize(cmp::max(1, segment_index), Proof::default());
if segment_index >= proofs.len() || proofs.is_empty() {
proofs.resize(cmp::max(1, segment_index + 1), Proof::default());
}
if segment_index > proofs.len() {
if segment_index >= proofs.len() {
// only possible if usize max < u64 max
return Err(InstructionError::InvalidArgument);
}

View File

@ -108,6 +108,24 @@ mod tests {
ret
}
#[test]
fn test_proof_bounds() {
let pubkey = Pubkey::new_rand();
let account = Account {
data: vec![0; 16 * 1024],
..Account::default()
};
let ix = storage_instruction::mining_proof(
&pubkey,
Hash::default(),
SLOTS_PER_SEGMENT,
Signature::default(),
);
assert_eq!(test_instruction(&ix, &mut [account]), Ok(()));
}
#[test]
fn test_storage_tx() {
let pubkey = Pubkey::new_rand();