Boot StorageTransaction
This commit is contained in:
parent
dcf2337e58
commit
c49e84c75b
@ -22,7 +22,8 @@ use solana_client::thin_client::{create_client, ThinClient};
|
|||||||
use solana_drone::drone::{request_airdrop_transaction, DRONE_PORT};
|
use solana_drone::drone::{request_airdrop_transaction, DRONE_PORT};
|
||||||
use solana_sdk::hash::{Hash, Hasher};
|
use solana_sdk::hash::{Hash, Hasher};
|
||||||
use solana_sdk::signature::{Keypair, KeypairUtil, Signature};
|
use solana_sdk::signature::{Keypair, KeypairUtil, Signature};
|
||||||
use solana_storage_api::storage_transaction::StorageTransaction;
|
use solana_sdk::transaction::Transaction;
|
||||||
|
use solana_storage_api::storage_instruction::StorageInstruction;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::io::BufReader;
|
use std::io::BufReader;
|
||||||
@ -403,14 +404,13 @@ impl Replicator {
|
|||||||
);
|
);
|
||||||
Self::get_airdrop_lamports(&client, &self.keypair, &self.cluster_entrypoint);
|
Self::get_airdrop_lamports(&client, &self.keypair, &self.cluster_entrypoint);
|
||||||
|
|
||||||
let blockhash = client.get_recent_blockhash().expect("blockhash");
|
let ix = StorageInstruction::new_mining_proof(
|
||||||
let mut tx = StorageTransaction::new_mining_proof(
|
&self.keypair.pubkey(),
|
||||||
&self.keypair,
|
|
||||||
self.hash,
|
self.hash,
|
||||||
blockhash,
|
|
||||||
self.slot,
|
self.slot,
|
||||||
Signature::new(self.signature.as_ref()),
|
Signature::new(self.signature.as_ref()),
|
||||||
);
|
);
|
||||||
|
let mut tx = Transaction::new(vec![ix]);
|
||||||
client
|
client
|
||||||
.retry_transfer(&self.keypair, &mut tx, 10)
|
.retry_transfer(&self.keypair, &mut tx, 10)
|
||||||
.expect("transfer didn't work!");
|
.expect("transfer didn't work!");
|
||||||
|
@ -15,10 +15,9 @@ use rand_chacha::ChaChaRng;
|
|||||||
use solana_client::thin_client::create_client_with_timeout;
|
use solana_client::thin_client::create_client_with_timeout;
|
||||||
use solana_sdk::hash::Hash;
|
use solana_sdk::hash::Hash;
|
||||||
use solana_sdk::pubkey::Pubkey;
|
use solana_sdk::pubkey::Pubkey;
|
||||||
use solana_sdk::signature::{Keypair, Signature};
|
use solana_sdk::signature::{Keypair, KeypairUtil, Signature};
|
||||||
use solana_sdk::transaction::Transaction;
|
use solana_sdk::transaction::Transaction;
|
||||||
use solana_storage_api::storage_instruction::StorageInstruction;
|
use solana_storage_api::storage_instruction::StorageInstruction;
|
||||||
use solana_storage_api::storage_transaction::StorageTransaction;
|
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::mem::size_of;
|
use std::mem::size_of;
|
||||||
@ -278,7 +277,7 @@ impl StorageStage {
|
|||||||
Err(io::Error::new(io::ErrorKind::Other, "other failure"))
|
Err(io::Error::new(io::ErrorKind::Other, "other failure"))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn process_entry_crossing(
|
fn process_entry_crossing(
|
||||||
state: &Arc<RwLock<StorageStateInner>>,
|
state: &Arc<RwLock<StorageStateInner>>,
|
||||||
keypair: &Arc<Keypair>,
|
keypair: &Arc<Keypair>,
|
||||||
_blocktree: &Arc<Blocktree>,
|
_blocktree: &Arc<Blocktree>,
|
||||||
@ -289,12 +288,12 @@ impl StorageStage {
|
|||||||
let mut seed = [0u8; 32];
|
let mut seed = [0u8; 32];
|
||||||
let signature = keypair.sign(&entry_id.as_ref());
|
let signature = keypair.sign(&entry_id.as_ref());
|
||||||
|
|
||||||
let tx = StorageTransaction::new_advertise_recent_blockhash(
|
let ix = StorageInstruction::new_advertise_recent_blockhash(
|
||||||
keypair,
|
&keypair.pubkey(),
|
||||||
entry_id,
|
entry_id,
|
||||||
Hash::default(),
|
|
||||||
entry_height,
|
entry_height,
|
||||||
);
|
);
|
||||||
|
let tx = Transaction::new(vec![ix]);
|
||||||
tx_sender.send(tx)?;
|
tx_sender.send(tx)?;
|
||||||
|
|
||||||
seed.copy_from_slice(&signature.as_ref()[..32]);
|
seed.copy_from_slice(&signature.as_ref()[..32]);
|
||||||
@ -355,7 +354,7 @@ impl StorageStage {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn process_entries(
|
fn process_entries(
|
||||||
keypair: &Arc<Keypair>,
|
keypair: &Arc<Keypair>,
|
||||||
storage_state: &Arc<RwLock<StorageStateInner>>,
|
storage_state: &Arc<RwLock<StorageStateInner>>,
|
||||||
entry_receiver: &EntryReceiver,
|
entry_receiver: &EntryReceiver,
|
||||||
@ -604,16 +603,17 @@ mod tests {
|
|||||||
reference_keys = vec![0; keys.len()];
|
reference_keys = vec![0; keys.len()];
|
||||||
reference_keys.copy_from_slice(keys);
|
reference_keys.copy_from_slice(keys);
|
||||||
}
|
}
|
||||||
let mut mining_txs: Vec<_> = Vec::new();
|
|
||||||
let keypair = Keypair::new();
|
let keypair = Keypair::new();
|
||||||
let mining_proof_tx = StorageTransaction::new_mining_proof(
|
let mining_proof_ix = StorageInstruction::new_mining_proof(
|
||||||
&keypair,
|
&keypair.pubkey(),
|
||||||
Hash::default(),
|
|
||||||
Hash::default(),
|
Hash::default(),
|
||||||
0,
|
0,
|
||||||
keypair.sign_message(b"test"),
|
keypair.sign_message(b"test"),
|
||||||
);
|
);
|
||||||
mining_txs.push(mining_proof_tx);
|
let mining_proof_tx = Transaction::new(vec![mining_proof_ix]);
|
||||||
|
let mining_txs = vec![mining_proof_tx];
|
||||||
|
|
||||||
let proof_entries = vec![Entry::new(&Hash::default(), 1, mining_txs)];
|
let proof_entries = vec![Entry::new(&Hash::default(), 1, mining_txs)];
|
||||||
storage_entry_sender.send(proof_entries).unwrap();
|
storage_entry_sender.send(proof_entries).unwrap();
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
pub mod storage_contract;
|
pub mod storage_contract;
|
||||||
pub mod storage_instruction;
|
pub mod storage_instruction;
|
||||||
pub mod storage_processor;
|
pub mod storage_processor;
|
||||||
pub mod storage_transaction;
|
|
||||||
|
|
||||||
use solana_sdk::pubkey::Pubkey;
|
use solana_sdk::pubkey::Pubkey;
|
||||||
|
|
||||||
|
@ -2,9 +2,9 @@ use crate::id;
|
|||||||
use crate::storage_contract::ProofStatus;
|
use crate::storage_contract::ProofStatus;
|
||||||
use serde_derive::{Deserialize, Serialize};
|
use serde_derive::{Deserialize, Serialize};
|
||||||
use solana_sdk::hash::Hash;
|
use solana_sdk::hash::Hash;
|
||||||
|
use solana_sdk::instruction::{AccountMeta, Instruction};
|
||||||
use solana_sdk::pubkey::Pubkey;
|
use solana_sdk::pubkey::Pubkey;
|
||||||
use solana_sdk::signature::Signature;
|
use solana_sdk::signature::Signature;
|
||||||
use solana_sdk::transaction::{AccountMeta, Instruction};
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||||
pub enum StorageInstruction {
|
pub enum StorageInstruction {
|
||||||
|
@ -171,195 +171,160 @@ mod tests {
|
|||||||
use super::*;
|
use super::*;
|
||||||
use crate::id;
|
use crate::id;
|
||||||
use crate::storage_contract::ProofStatus;
|
use crate::storage_contract::ProofStatus;
|
||||||
use crate::storage_transaction::StorageTransaction;
|
|
||||||
use crate::ENTRIES_PER_SEGMENT;
|
use crate::ENTRIES_PER_SEGMENT;
|
||||||
use bincode::deserialize;
|
use bincode::deserialize;
|
||||||
use solana_runtime::bank::Bank;
|
use solana_runtime::bank::Bank;
|
||||||
|
use solana_runtime::bank_client::BankClient;
|
||||||
use solana_sdk::account::{create_keyed_accounts, Account};
|
use solana_sdk::account::{create_keyed_accounts, Account};
|
||||||
use solana_sdk::genesis_block::GenesisBlock;
|
use solana_sdk::genesis_block::GenesisBlock;
|
||||||
use solana_sdk::hash::{hash, Hash};
|
use solana_sdk::hash::{hash, Hash};
|
||||||
use solana_sdk::instruction::CompiledInstruction;
|
use solana_sdk::instruction::Instruction;
|
||||||
use solana_sdk::pubkey::Pubkey;
|
use solana_sdk::pubkey::Pubkey;
|
||||||
use solana_sdk::signature::{Keypair, KeypairUtil, Signature};
|
use solana_sdk::signature::{Keypair, KeypairUtil, Signature};
|
||||||
use solana_sdk::system_transaction::SystemTransaction;
|
use solana_sdk::system_instruction::SystemInstruction;
|
||||||
use solana_sdk::transaction::Transaction;
|
|
||||||
|
|
||||||
fn test_transaction(
|
fn test_instruction(
|
||||||
tx: &Transaction,
|
ix: &Instruction,
|
||||||
program_accounts: &mut [Account],
|
program_accounts: &mut [Account],
|
||||||
) -> Result<(), InstructionError> {
|
) -> Result<(), InstructionError> {
|
||||||
assert_eq!(tx.instructions.len(), 1);
|
let mut keyed_accounts: Vec<_> = ix
|
||||||
let CompiledInstruction {
|
.accounts
|
||||||
ref accounts,
|
|
||||||
ref data,
|
|
||||||
..
|
|
||||||
} = tx.instructions[0];
|
|
||||||
|
|
||||||
info!("accounts: {:?}", accounts);
|
|
||||||
|
|
||||||
let mut keyed_accounts: Vec<_> = accounts
|
|
||||||
.iter()
|
.iter()
|
||||||
.map(|&index| {
|
|
||||||
let index = index as usize;
|
|
||||||
let key = &tx.account_keys[index];
|
|
||||||
(key, index < tx.signatures.len())
|
|
||||||
})
|
|
||||||
.zip(program_accounts.iter_mut())
|
.zip(program_accounts.iter_mut())
|
||||||
.map(|((key, is_signer), account)| KeyedAccount::new(key, is_signer, account))
|
.map(|(account_meta, account)| {
|
||||||
|
KeyedAccount::new(&account_meta.pubkey, account_meta.is_signer, account)
|
||||||
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let ret = process_instruction(&id(), &mut keyed_accounts, &data, 42);
|
let ret = process_instruction(&id(), &mut keyed_accounts, &ix.data, 42);
|
||||||
info!("ret: {:?}", ret);
|
info!("ret: {:?}", ret);
|
||||||
ret
|
ret
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_storage_tx() {
|
fn test_storage_tx() {
|
||||||
let keypair = Keypair::new();
|
let pubkey = Keypair::new().pubkey();
|
||||||
let mut accounts = [(keypair.pubkey(), Account::default())];
|
let mut accounts = [(pubkey, Account::default())];
|
||||||
let mut keyed_accounts = create_keyed_accounts(&mut accounts);
|
let mut keyed_accounts = create_keyed_accounts(&mut accounts);
|
||||||
assert!(process_instruction(&id(), &mut keyed_accounts, &[], 42).is_err());
|
assert!(process_instruction(&id(), &mut keyed_accounts, &[], 42).is_err());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_serialize_overflow() {
|
fn test_serialize_overflow() {
|
||||||
let keypair = Keypair::new();
|
let pubkey = Keypair::new().pubkey();
|
||||||
let mut keyed_accounts = Vec::new();
|
let mut keyed_accounts = Vec::new();
|
||||||
let mut user_account = Account::default();
|
let mut user_account = Account::default();
|
||||||
let pubkey = keypair.pubkey();
|
|
||||||
keyed_accounts.push(KeyedAccount::new(&pubkey, true, &mut user_account));
|
keyed_accounts.push(KeyedAccount::new(&pubkey, true, &mut user_account));
|
||||||
|
|
||||||
let tx = StorageTransaction::new_advertise_recent_blockhash(
|
let ix = StorageInstruction::new_advertise_recent_blockhash(
|
||||||
&keypair,
|
&pubkey,
|
||||||
Hash::default(),
|
|
||||||
Hash::default(),
|
Hash::default(),
|
||||||
ENTRIES_PER_SEGMENT,
|
ENTRIES_PER_SEGMENT,
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
process_instruction(&id(), &mut keyed_accounts, &tx.instructions[0].data, 42),
|
process_instruction(&id(), &mut keyed_accounts, &ix.data, 42),
|
||||||
Err(InstructionError::AccountDataTooSmall)
|
Err(InstructionError::AccountDataTooSmall)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_invalid_accounts_len() {
|
fn test_invalid_accounts_len() {
|
||||||
let keypair = Keypair::new();
|
let pubkey = Keypair::new().pubkey();
|
||||||
let mut accounts = [Account::default()];
|
let mut accounts = [Account::default()];
|
||||||
|
|
||||||
let tx = StorageTransaction::new_mining_proof(
|
let ix =
|
||||||
&keypair,
|
StorageInstruction::new_mining_proof(&pubkey, Hash::default(), 0, Signature::default());
|
||||||
Hash::default(),
|
assert!(test_instruction(&ix, &mut accounts).is_err());
|
||||||
Hash::default(),
|
|
||||||
0,
|
|
||||||
Signature::default(),
|
|
||||||
);
|
|
||||||
assert!(test_transaction(&tx, &mut accounts).is_err());
|
|
||||||
|
|
||||||
let mut accounts = [Account::default(), Account::default(), Account::default()];
|
let mut accounts = [Account::default(), Account::default(), Account::default()];
|
||||||
|
|
||||||
assert!(test_transaction(&tx, &mut accounts).is_err());
|
assert!(test_instruction(&ix, &mut accounts).is_err());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_submit_mining_invalid_entry_height() {
|
fn test_submit_mining_invalid_entry_height() {
|
||||||
solana_logger::setup();
|
solana_logger::setup();
|
||||||
let keypair = Keypair::new();
|
let pubkey = Keypair::new().pubkey();
|
||||||
let mut accounts = [Account::default(), Account::default()];
|
let mut accounts = [Account::default(), Account::default()];
|
||||||
accounts[1].data.resize(16 * 1024, 0);
|
accounts[1].data.resize(16 * 1024, 0);
|
||||||
|
|
||||||
let tx = StorageTransaction::new_mining_proof(
|
let ix =
|
||||||
&keypair,
|
StorageInstruction::new_mining_proof(&pubkey, Hash::default(), 0, Signature::default());
|
||||||
Hash::default(),
|
|
||||||
Hash::default(),
|
|
||||||
0,
|
|
||||||
Signature::default(),
|
|
||||||
);
|
|
||||||
|
|
||||||
// Haven't seen a transaction to roll over the epoch, so this should fail
|
// Haven't seen a transaction to roll over the epoch, so this should fail
|
||||||
assert!(test_transaction(&tx, &mut accounts).is_err());
|
assert!(test_instruction(&ix, &mut accounts).is_err());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_submit_mining_ok() {
|
fn test_submit_mining_ok() {
|
||||||
solana_logger::setup();
|
solana_logger::setup();
|
||||||
let keypair = Keypair::new();
|
let pubkey = Keypair::new().pubkey();
|
||||||
let mut accounts = [Account::default(), Account::default()];
|
let mut accounts = [Account::default(), Account::default()];
|
||||||
accounts[0].data.resize(16 * 1024, 0);
|
accounts[0].data.resize(16 * 1024, 0);
|
||||||
|
|
||||||
let tx = StorageTransaction::new_advertise_recent_blockhash(
|
let ix = StorageInstruction::new_advertise_recent_blockhash(
|
||||||
&keypair,
|
&pubkey,
|
||||||
Hash::default(),
|
|
||||||
Hash::default(),
|
Hash::default(),
|
||||||
ENTRIES_PER_SEGMENT,
|
ENTRIES_PER_SEGMENT,
|
||||||
);
|
);
|
||||||
|
|
||||||
test_transaction(&tx, &mut accounts).unwrap();
|
test_instruction(&ix, &mut accounts).unwrap();
|
||||||
|
|
||||||
let tx = StorageTransaction::new_mining_proof(
|
let ix =
|
||||||
&keypair,
|
StorageInstruction::new_mining_proof(&pubkey, Hash::default(), 0, Signature::default());
|
||||||
Hash::default(),
|
|
||||||
Hash::default(),
|
|
||||||
0,
|
|
||||||
Signature::default(),
|
|
||||||
);
|
|
||||||
|
|
||||||
test_transaction(&tx, &mut accounts).unwrap();
|
test_instruction(&ix, &mut accounts).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_validate_mining() {
|
fn test_validate_mining() {
|
||||||
solana_logger::setup();
|
solana_logger::setup();
|
||||||
let keypair = Keypair::new();
|
let pubkey = Keypair::new().pubkey();
|
||||||
let mut accounts = [Account::default(), Account::default()];
|
let mut accounts = [Account::default(), Account::default()];
|
||||||
accounts[0].data.resize(16 * 1024, 0);
|
accounts[0].data.resize(16 * 1024, 0);
|
||||||
|
|
||||||
let entry_height = 0;
|
let entry_height = 0;
|
||||||
|
|
||||||
let tx = StorageTransaction::new_advertise_recent_blockhash(
|
let ix = StorageInstruction::new_advertise_recent_blockhash(
|
||||||
&keypair,
|
&pubkey,
|
||||||
Hash::default(),
|
|
||||||
Hash::default(),
|
Hash::default(),
|
||||||
ENTRIES_PER_SEGMENT,
|
ENTRIES_PER_SEGMENT,
|
||||||
);
|
);
|
||||||
|
|
||||||
test_transaction(&tx, &mut accounts).unwrap();
|
test_instruction(&ix, &mut accounts).unwrap();
|
||||||
|
|
||||||
let tx = StorageTransaction::new_mining_proof(
|
let ix = StorageInstruction::new_mining_proof(
|
||||||
&keypair,
|
&pubkey,
|
||||||
Hash::default(),
|
|
||||||
Hash::default(),
|
Hash::default(),
|
||||||
entry_height,
|
entry_height,
|
||||||
Signature::default(),
|
Signature::default(),
|
||||||
);
|
);
|
||||||
test_transaction(&tx, &mut accounts).unwrap();
|
test_instruction(&ix, &mut accounts).unwrap();
|
||||||
|
|
||||||
let tx = StorageTransaction::new_advertise_recent_blockhash(
|
let ix = StorageInstruction::new_advertise_recent_blockhash(
|
||||||
&keypair,
|
&pubkey,
|
||||||
Hash::default(),
|
|
||||||
Hash::default(),
|
Hash::default(),
|
||||||
ENTRIES_PER_SEGMENT * 2,
|
ENTRIES_PER_SEGMENT * 2,
|
||||||
);
|
);
|
||||||
test_transaction(&tx, &mut accounts).unwrap();
|
test_instruction(&ix, &mut accounts).unwrap();
|
||||||
|
|
||||||
let tx = StorageTransaction::new_proof_validation(
|
let ix = StorageInstruction::new_proof_validation(
|
||||||
&keypair,
|
&pubkey,
|
||||||
Hash::default(),
|
|
||||||
entry_height,
|
entry_height,
|
||||||
vec![ProofStatus::Valid],
|
vec![ProofStatus::Valid],
|
||||||
);
|
);
|
||||||
test_transaction(&tx, &mut accounts).unwrap();
|
test_instruction(&ix, &mut accounts).unwrap();
|
||||||
|
|
||||||
let tx = StorageTransaction::new_advertise_recent_blockhash(
|
let ix = StorageInstruction::new_advertise_recent_blockhash(
|
||||||
&keypair,
|
&pubkey,
|
||||||
Hash::default(),
|
|
||||||
Hash::default(),
|
Hash::default(),
|
||||||
ENTRIES_PER_SEGMENT * 3,
|
ENTRIES_PER_SEGMENT * 3,
|
||||||
);
|
);
|
||||||
test_transaction(&tx, &mut accounts).unwrap();
|
test_instruction(&ix, &mut accounts).unwrap();
|
||||||
|
|
||||||
let tx = StorageTransaction::new_reward_claim(&keypair, Hash::default(), entry_height);
|
let ix = StorageInstruction::new_reward_claim(&pubkey, entry_height);
|
||||||
test_transaction(&tx, &mut accounts).unwrap();
|
test_instruction(&ix, &mut accounts).unwrap();
|
||||||
|
|
||||||
assert!(accounts[0].lamports == TOTAL_VALIDATOR_REWARDS);
|
assert!(accounts[0].lamports == TOTAL_VALIDATOR_REWARDS);
|
||||||
}
|
}
|
||||||
@ -393,15 +358,18 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_bank_storage() {
|
fn test_bank_storage() {
|
||||||
let (mut genesis_block, alice) = GenesisBlock::new(1000);
|
let (mut genesis_block, mint_keypair) = GenesisBlock::new(1000);
|
||||||
genesis_block
|
genesis_block
|
||||||
.native_programs
|
.native_programs
|
||||||
.push(("solana_storage_program".to_string(), id()));
|
.push(("solana_storage_program".to_string(), id()));
|
||||||
let bank = Bank::new(&genesis_block);
|
let bank = Bank::new(&genesis_block);
|
||||||
|
let alice_client = BankClient::new(&bank, mint_keypair);
|
||||||
let bob = Keypair::new();
|
let alice_pubkey = alice_client.pubkey();
|
||||||
let jack = Keypair::new();
|
let bob_keypair = Keypair::new();
|
||||||
let jill = Keypair::new();
|
let bob_client = BankClient::new(&bank, bob_keypair);
|
||||||
|
let bob_pubkey = bob_client.pubkey();
|
||||||
|
let jack_pubkey = Keypair::new().pubkey();
|
||||||
|
let jill_pubkey = Keypair::new().pubkey();
|
||||||
|
|
||||||
let x = 42;
|
let x = 42;
|
||||||
let blockhash = genesis_block.hash();
|
let blockhash = genesis_block.hash();
|
||||||
@ -410,51 +378,36 @@ mod tests {
|
|||||||
|
|
||||||
bank.register_tick(&blockhash);
|
bank.register_tick(&blockhash);
|
||||||
|
|
||||||
bank.transfer(10, &alice, &jill.pubkey(), blockhash)
|
alice_client.transfer(10, &jill_pubkey).unwrap();
|
||||||
.unwrap();
|
alice_client.transfer(10, &bob_pubkey).unwrap();
|
||||||
|
alice_client.transfer(10, &jack_pubkey).unwrap();
|
||||||
|
|
||||||
bank.transfer(10, &alice, &bob.pubkey(), blockhash).unwrap();
|
let ix =
|
||||||
bank.transfer(10, &alice, &jack.pubkey(), blockhash)
|
SystemInstruction::new_program_account(&alice_pubkey, &bob_pubkey, 1, 4 * 1024, &id());
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let tx = SystemTransaction::new_program_account(
|
alice_client.process_instruction(ix).unwrap();
|
||||||
&alice,
|
|
||||||
&bob.pubkey(),
|
|
||||||
blockhash,
|
|
||||||
1,
|
|
||||||
4 * 1024,
|
|
||||||
&id(),
|
|
||||||
0,
|
|
||||||
);
|
|
||||||
|
|
||||||
bank.process_transaction(&tx).unwrap();
|
let ix = StorageInstruction::new_advertise_recent_blockhash(
|
||||||
|
&bob_pubkey,
|
||||||
let tx = StorageTransaction::new_advertise_recent_blockhash(
|
|
||||||
&bob,
|
|
||||||
storage_blockhash,
|
storage_blockhash,
|
||||||
blockhash,
|
|
||||||
ENTRIES_PER_SEGMENT,
|
ENTRIES_PER_SEGMENT,
|
||||||
);
|
);
|
||||||
|
|
||||||
bank.process_transaction(&tx).unwrap();
|
bob_client.process_instruction(ix).unwrap();
|
||||||
|
|
||||||
let entry_height = 0;
|
let entry_height = 0;
|
||||||
let tx = StorageTransaction::new_mining_proof(
|
let ix = StorageInstruction::new_mining_proof(
|
||||||
&bob,
|
&bob_pubkey,
|
||||||
Hash::default(),
|
Hash::default(),
|
||||||
blockhash,
|
|
||||||
entry_height,
|
entry_height,
|
||||||
Signature::default(),
|
Signature::default(),
|
||||||
);
|
);
|
||||||
let _result = bank.process_transaction(&tx).unwrap();
|
let _result = bob_client.process_instruction(ix).unwrap();
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
get_storage_entry_height(&bank, &bob.pubkey()),
|
get_storage_entry_height(&bank, &bob_pubkey),
|
||||||
ENTRIES_PER_SEGMENT
|
ENTRIES_PER_SEGMENT
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(get_storage_blockhash(&bank, &bob_pubkey), storage_blockhash);
|
||||||
get_storage_blockhash(&bank, &bob.pubkey()),
|
|
||||||
storage_blockhash
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,63 +0,0 @@
|
|||||||
use crate::storage_contract::ProofStatus;
|
|
||||||
use crate::storage_instruction::StorageInstruction;
|
|
||||||
use solana_sdk::hash::Hash;
|
|
||||||
use solana_sdk::signature::{Keypair, KeypairUtil, Signature};
|
|
||||||
use solana_sdk::transaction::Transaction;
|
|
||||||
|
|
||||||
pub struct StorageTransaction {}
|
|
||||||
|
|
||||||
impl StorageTransaction {
|
|
||||||
pub fn new_mining_proof(
|
|
||||||
from_keypair: &Keypair,
|
|
||||||
sha_state: Hash,
|
|
||||||
recent_blockhash: Hash,
|
|
||||||
entry_height: u64,
|
|
||||||
signature: Signature,
|
|
||||||
) -> Transaction {
|
|
||||||
let from_pubkey = from_keypair.pubkey();
|
|
||||||
let storage_instruction =
|
|
||||||
StorageInstruction::new_mining_proof(&from_pubkey, sha_state, entry_height, signature);
|
|
||||||
let instructions = vec![storage_instruction];
|
|
||||||
Transaction::new_signed_instructions(&[from_keypair], instructions, recent_blockhash, 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn new_advertise_recent_blockhash(
|
|
||||||
from_keypair: &Keypair,
|
|
||||||
storage_hash: Hash,
|
|
||||||
recent_blockhash: Hash,
|
|
||||||
entry_height: u64,
|
|
||||||
) -> Transaction {
|
|
||||||
let from_pubkey = from_keypair.pubkey();
|
|
||||||
let storage_instruction = StorageInstruction::new_advertise_recent_blockhash(
|
|
||||||
&from_pubkey,
|
|
||||||
storage_hash,
|
|
||||||
entry_height,
|
|
||||||
);
|
|
||||||
let instructions = vec![storage_instruction];
|
|
||||||
Transaction::new_signed_instructions(&[from_keypair], instructions, recent_blockhash, 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn new_proof_validation(
|
|
||||||
from_keypair: &Keypair,
|
|
||||||
recent_blockhash: Hash,
|
|
||||||
entry_height: u64,
|
|
||||||
proof_mask: Vec<ProofStatus>,
|
|
||||||
) -> Transaction {
|
|
||||||
let from_pubkey = from_keypair.pubkey();
|
|
||||||
let storage_instruction =
|
|
||||||
StorageInstruction::new_proof_validation(&from_pubkey, entry_height, proof_mask);
|
|
||||||
let instructions = vec![storage_instruction];
|
|
||||||
Transaction::new_signed_instructions(&[from_keypair], instructions, recent_blockhash, 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn new_reward_claim(
|
|
||||||
from_keypair: &Keypair,
|
|
||||||
recent_blockhash: Hash,
|
|
||||||
entry_height: u64,
|
|
||||||
) -> Transaction {
|
|
||||||
let from_pubkey = from_keypair.pubkey();
|
|
||||||
let storage_instruction = StorageInstruction::new_reward_claim(&from_pubkey, entry_height);
|
|
||||||
let instructions = vec![storage_instruction];
|
|
||||||
Transaction::new_signed_instructions(&[from_keypair], instructions, recent_blockhash, 0)
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user