Actually submit the storage mining proof

Get an aidrop so replicator can submit mining transaction

Some other minor type cleanup.
This commit is contained in:
Stephen Akridge 2018-10-02 16:10:56 -07:00 committed by sakridge
parent 76076d6fad
commit c30b605047
5 changed files with 66 additions and 14 deletions

View File

@ -8,11 +8,16 @@ extern crate solana;
use clap::{App, Arg}; use clap::{App, Arg};
use solana::chacha::chacha_cbc_encrypt_files; use solana::chacha::chacha_cbc_encrypt_files;
use solana::cluster_info::Node; use solana::cluster_info::Node;
use solana::client::mk_client;
use solana::drone::DRONE_PORT;
use solana::fullnode::Config; use solana::fullnode::Config;
use solana::ledger::LEDGER_DATA_FILE; use solana::ledger::LEDGER_DATA_FILE;
use solana::logger; use solana::logger;
use solana::replicator::{sample_file, Replicator}; use solana::replicator::{sample_file, Replicator};
use solana::signature::{Keypair, KeypairUtil}; use solana::signature::{Keypair, KeypairUtil};
use solana::storage_transaction::StorageTransaction;
use solana::transaction::Transaction;
use solana::wallet::request_airdrop;
use std::fs::File; use std::fs::File;
use std::net::{Ipv4Addr, SocketAddr}; use std::net::{Ipv4Addr, SocketAddr};
use std::path::Path; use std::path::Path;
@ -90,7 +95,7 @@ fn main() {
// TODO: ask network what slice we should store // TODO: ask network what slice we should store
let entry_height = 0; let entry_height = 0;
let replicator = Replicator::new( let (replicator, leader_info) = Replicator::new(
entry_height, entry_height,
5, 5,
&exit, &exit,
@ -124,8 +129,22 @@ fn main() {
let sampling_offsets = [0, 1, 2, 3]; let sampling_offsets = [0, 1, 2, 3];
let mut client = mk_client(&leader_info);
let mut drone_addr = leader_info.contact_info.tpu;
drone_addr.set_port(DRONE_PORT);
let airdrop_amount = 5;
if let Err(e) = request_airdrop(&drone_addr, &keypair.pubkey(), airdrop_amount) {
panic!("couldn't get airdrop {}: {}!", airdrop_amount, e);
}
match sample_file(&ledger_data_file_encrypted, &sampling_offsets) { match sample_file(&ledger_data_file_encrypted, &sampling_offsets) {
Ok(hash) => println!("sampled hash: {}", hash), Ok(hash) => {
let last_id = client.get_last_id();
println!("sampled hash: {}", hash);
let tx = Transaction::storage_new_mining_proof(&keypair, hash, last_id);
client.transfer_signed(&tx).expect("transfer didn't work!");
}
Err(e) => println!("Error occurred while sampling: {:?}", e), Err(e) => println!("Error occurred while sampling: {:?}", e),
} }

View File

@ -61,6 +61,7 @@ pub mod signature;
pub mod sigverify; pub mod sigverify;
pub mod sigverify_stage; pub mod sigverify_stage;
pub mod storage_program; pub mod storage_program;
pub mod storage_transaction;
pub mod store_ledger_stage; pub mod store_ledger_stage;
pub mod streamer; pub mod streamer;
pub mod system_program; pub mod system_program;

View File

@ -22,6 +22,7 @@ use std::thread::JoinHandle;
use std::time::Duration; use std::time::Duration;
use store_ledger_stage::StoreLedgerStage; use store_ledger_stage::StoreLedgerStage;
use streamer::BlobReceiver; use streamer::BlobReceiver;
use thin_client::poll_gossip_for_leader;
use window; use window;
use window_service::window_service; use window_service::window_service;
@ -49,7 +50,7 @@ pub fn sample_file(in_path: &Path, sample_offsets: &[u64]) -> io::Result<Hash> {
return Err(Error::new(ErrorKind::Other, "offset too large")); return Err(Error::new(ErrorKind::Other, "offset too large"));
} }
buffer_file.seek(SeekFrom::Start(*offset * sample_size64))?; buffer_file.seek(SeekFrom::Start(*offset * sample_size64))?;
info!("sampling @ {} ", *offset); trace!("sampling @ {} ", *offset);
match buffer_file.read(&mut buf) { match buffer_file.read(&mut buf) {
Ok(size) => { Ok(size) => {
assert_eq!(size, buf.len()); assert_eq!(size, buf.len());
@ -74,7 +75,7 @@ impl Replicator {
node: Node, node: Node,
network_addr: Option<SocketAddr>, network_addr: Option<SocketAddr>,
done: Arc<AtomicBool>, done: Arc<AtomicBool>,
) -> Replicator { ) -> (Replicator, NodeInfo) {
let window = window::new_window_from_entries(&[], entry_height, &node.info); let window = window::new_window_from_entries(&[], entry_height, &node.info);
let shared_window = Arc::new(RwLock::new(window)); let shared_window = Arc::new(RwLock::new(window));
@ -126,13 +127,19 @@ impl Replicator {
exit.clone(), exit.clone(),
); );
Replicator { let leader =
ncp, poll_gossip_for_leader(network_addr.unwrap(), Some(10)).expect("couldn't reach leader");
fetch_stage,
store_ledger_stage, (
t_window, Replicator {
retransmit_receiver, ncp,
} fetch_stage,
store_ledger_stage,
t_window,
retransmit_receiver,
},
leader,
)
} }
pub fn join(self) { pub fn join(self) {
@ -213,7 +220,7 @@ mod tests {
info!("starting replicator node"); info!("starting replicator node");
let replicator_node = Node::new_localhost_with_pubkey(replicator_keypair.pubkey()); let replicator_node = Node::new_localhost_with_pubkey(replicator_keypair.pubkey());
let replicator = Replicator::new( let (replicator, _leader_info) = Replicator::new(
entry_height, entry_height,
1, 1,
&exit, &exit,

View File

@ -3,13 +3,14 @@
//! and give reward for good proofs. //! and give reward for good proofs.
use bincode::deserialize; use bincode::deserialize;
use hash::Hash;
use solana_program_interface::account::Account; use solana_program_interface::account::Account;
use solana_program_interface::pubkey::Pubkey; use solana_program_interface::pubkey::Pubkey;
use transaction::Transaction; use transaction::Transaction;
#[derive(Serialize, Deserialize, Debug, Clone)] #[derive(Serialize, Deserialize, Debug, Clone)]
pub enum StorageProgram { pub enum StorageProgram {
SubmitMiningProof { sha_state: [u8; 32] }, SubmitMiningProof { sha_state: Hash },
} }
pub enum StorageError { pub enum StorageError {
@ -39,7 +40,7 @@ impl StorageProgram {
if let Ok(syscall) = deserialize(tx.userdata(pix)) { if let Ok(syscall) = deserialize(tx.userdata(pix)) {
match syscall { match syscall {
StorageProgram::SubmitMiningProof { sha_state } => { StorageProgram::SubmitMiningProof { sha_state } => {
info!("Mining proof submitted with state {}", sha_state[0]); info!("Mining proof submitted with state {:?}", sha_state);
return Ok(()); return Ok(());
} }
} }

View File

@ -0,0 +1,24 @@
use bincode::serialize;
use hash::Hash;
use signature::{Keypair, KeypairUtil};
use storage_program::StorageProgram;
use transaction::Transaction;
pub trait StorageTransaction {
fn storage_new_mining_proof(from_keypair: &Keypair, sha_state: Hash, last_id: Hash) -> Self;
}
impl StorageTransaction for Transaction {
fn storage_new_mining_proof(from_keypair: &Keypair, sha_state: Hash, last_id: Hash) -> Self {
let program = StorageProgram::SubmitMiningProof { sha_state };
let userdata = serialize(&program).unwrap();
Transaction::new(
from_keypair,
&[from_keypair.pubkey()],
StorageProgram::id(),
userdata,
last_id,
0,
)
}
}