Add storage space constant (#4366)

automerge
This commit is contained in:
Sagar Dhawan 2019-05-21 11:07:13 -07:00 committed by Grimes
parent f877fb8c8f
commit c9ba9e4eb7
6 changed files with 27 additions and 31 deletions

View File

@ -24,7 +24,6 @@ use solana_sdk::genesis_block::GenesisBlock;
use solana_sdk::hash::{Hash, Hasher};
use solana_sdk::message::Message;
use solana_sdk::signature::{Keypair, KeypairUtil, Signature};
use solana_sdk::system_transaction;
use solana_sdk::timing::timestamp;
use solana_sdk::transaction::Transaction;
use solana_sdk::transport::TransportError;
@ -415,14 +414,13 @@ impl Replicator {
let bal = client.poll_get_balance(&storage_keypair.pubkey());
if bal.is_err() || bal.unwrap() == 0 {
let (blockhash, _fee_calculator) = client.get_recent_blockhash().expect("blockhash");
let tx = system_transaction::create_account(
keypair,
let ix = vec![storage_instruction::create_account(
&keypair.pubkey(),
&storage_keypair.pubkey(),
blockhash,
1,
1024 * 4, // TODO the account space needs to be well defined somewhere
&solana_storage_api::id(),
);
)];
let tx = Transaction::new_signed_instructions(&[keypair], ix, blockhash);
let signature = client.async_send_transaction(tx)?;
client
.poll_for_signature(&signature)

View File

@ -17,7 +17,6 @@ use solana_sdk::instruction::Instruction;
use solana_sdk::message::Message;
use solana_sdk::pubkey::Pubkey;
use solana_sdk::signature::{Keypair, KeypairUtil, Signature};
use solana_sdk::system_instruction;
use solana_sdk::transaction::Transaction;
use solana_storage_api::storage_instruction::StorageInstruction;
use solana_storage_api::{get_segment_from_slot, storage_instruction};
@ -245,12 +244,10 @@ impl StorageStage {
.get_account(&storage_keypair.pubkey())
.is_none()
{
let create_instruction = system_instruction::create_account(
let create_instruction = storage_instruction::create_account(
&keypair.pubkey(),
&storage_keypair.pubkey(),
1,
1024 * 4, // TODO the account space needs to be well defined somewhere
&solana_storage_api::id(),
);
instructions.push(create_instruction);
info!("storage account requested");

View File

@ -25,6 +25,7 @@ use solana_sdk::signature::{read_keypair, KeypairUtil};
use solana_sdk::system_program;
use solana_sdk::timing;
use solana_stake_api::stake_state;
use solana_storage_api::storage_contract::STORAGE_ACCOUNT_SPACE;
use solana_vote_api::vote_state;
use std::error;
use std::time::{Duration, Instant};
@ -215,7 +216,7 @@ fn main() -> Result<(), Box<dyn error::Error>> {
// storage account
(
bootstrap_storage_keypair.pubkey(),
Account::new(1, 1024 * 4, &solana_storage_api::id()),
Account::new(1, STORAGE_ACCOUNT_SPACE as usize, &solana_storage_api::id()),
),
],
&[

View File

@ -11,6 +11,8 @@ use std::collections::HashMap;
pub const TOTAL_VALIDATOR_REWARDS: u64 = 1;
pub const TOTAL_REPLICATOR_REWARDS: u64 = 1;
// Todo Tune this for actual use cases when replicators are feature complete
pub const STORAGE_ACCOUNT_SPACE: u64 = 1024 * 4;
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub enum ProofStatus {

View File

@ -1,12 +1,12 @@
use crate::id;
use crate::storage_contract::CheckedProof;
use crate::storage_contract::{CheckedProof, STORAGE_ACCOUNT_SPACE};
use serde_derive::{Deserialize, Serialize};
use solana_sdk::hash::Hash;
use solana_sdk::instruction::{AccountMeta, Instruction};
use solana_sdk::pubkey::Pubkey;
use solana_sdk::signature::Signature;
use solana_sdk::system_instruction;
// TODO maybe split this into StorageReplicator and StorageValidator
#[derive(Serialize, Deserialize, Debug, Clone)]
pub enum StorageInstruction {
SubmitMiningProof {
@ -27,6 +27,10 @@ pub enum StorageInstruction {
},
}
pub fn create_account(from: &Pubkey, to: &Pubkey, lamports: u64) -> Instruction {
system_instruction::create_account(&from, to, lamports, STORAGE_ACCOUNT_SPACE, &id())
}
pub fn mining_proof(
from_pubkey: &Pubkey,
sha_state: Hash,

View File

@ -86,7 +86,9 @@ pub fn process_instruction(
mod tests {
use super::*;
use crate::id;
use crate::storage_contract::{CheckedProof, Proof, ProofStatus, StorageContract};
use crate::storage_contract::{
CheckedProof, Proof, ProofStatus, StorageContract, STORAGE_ACCOUNT_SPACE,
};
use crate::storage_instruction;
use crate::SLOTS_PER_SEGMENT;
use bincode::deserialize;
@ -99,7 +101,6 @@ mod tests {
use solana_sdk::instruction::Instruction;
use solana_sdk::pubkey::Pubkey;
use solana_sdk::signature::{Keypair, KeypairUtil, Signature};
use solana_sdk::system_instruction;
use std::sync::Arc;
const TICKS_IN_SEGMENT: u64 = SLOTS_PER_SEGMENT * DEFAULT_TICKS_PER_SLOT;
@ -127,7 +128,7 @@ mod tests {
fn test_proof_bounds() {
let pubkey = Pubkey::new_rand();
let account = Account {
data: vec![0; 16 * 1024],
data: vec![0; STORAGE_ACCOUNT_SPACE as usize],
..Account::default()
};
@ -195,8 +196,8 @@ mod tests {
solana_logger::setup();
let pubkey = Pubkey::new_rand();
let mut accounts = [Account::default(), Account::default()];
accounts[0].data.resize(16 * 1024, 0);
accounts[1].data.resize(16 * 1024, 0);
accounts[0].data.resize(STORAGE_ACCOUNT_SPACE as usize, 0);
accounts[1].data.resize(STORAGE_ACCOUNT_SPACE as usize, 0);
let ix =
storage_instruction::mining_proof(&pubkey, Hash::default(), 0, Signature::default());
@ -210,7 +211,7 @@ mod tests {
solana_logger::setup();
let pubkey = Pubkey::new_rand();
let mut accounts = [Account::default(), Account::default()];
accounts[0].data.resize(16 * 1024, 0);
accounts[0].data.resize(STORAGE_ACCOUNT_SPACE as usize, 0);
let ix =
storage_instruction::mining_proof(&pubkey, Hash::default(), 0, Signature::default());
@ -236,10 +237,10 @@ mod tests {
let slot = 0;
let bank_client = BankClient::new_shared(&bank);
let ix = system_instruction::create_account(&mint_pubkey, &validator, 10, 4 * 1042, &id());
let ix = storage_instruction::create_account(&mint_pubkey, &validator, 10);
bank_client.send_instruction(&mint_keypair, ix).unwrap();
let ix = system_instruction::create_account(&mint_pubkey, &replicator, 10, 4 * 1042, &id());
let ix = storage_instruction::create_account(&mint_pubkey, &replicator, 10);
bank_client.send_instruction(&mint_keypair, ix).unwrap();
// tick the bank up until it's moved into storage segment 2 because the next advertise is for segment 1
@ -398,18 +399,11 @@ mod tests {
.transfer(10, &mint_keypair, &replicator_pubkey)
.unwrap();
let ix = system_instruction::create_account(
&mint_pubkey,
&replicator_pubkey,
1,
4 * 1024,
&id(),
);
let ix = storage_instruction::create_account(&mint_pubkey, &replicator_pubkey, 1);
bank_client.send_instruction(&mint_keypair, ix).unwrap();
let ix =
system_instruction::create_account(&mint_pubkey, &validator_pubkey, 1, 4 * 1024, &id());
let ix = storage_instruction::create_account(&mint_pubkey, &validator_pubkey, 1);
bank_client.send_instruction(&mint_keypair, ix).unwrap();