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:
@@ -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
|
||||
|
@@ -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);
|
||||
}
|
||||
|
@@ -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();
|
||||
|
Reference in New Issue
Block a user