2018-03-28 15:51:18 -07:00
|
|
|
extern crate rayon;
|
2018-03-05 14:34:15 -08:00
|
|
|
extern crate serde_json;
|
2018-03-27 15:24:05 -07:00
|
|
|
extern crate solana;
|
2018-02-28 09:07:54 -08:00
|
|
|
|
2018-03-27 15:24:05 -07:00
|
|
|
use solana::accountant_stub::AccountantStub;
|
|
|
|
use solana::mint::Mint;
|
|
|
|
use solana::signature::{KeyPair, KeyPairUtil};
|
|
|
|
use solana::transaction::Transaction;
|
2018-03-05 14:34:15 -08:00
|
|
|
use std::io::stdin;
|
2018-03-27 13:45:04 -07:00
|
|
|
use std::net::{TcpStream, UdpSocket};
|
2018-03-26 21:03:26 -07:00
|
|
|
use std::time::Instant;
|
2018-03-28 15:51:18 -07:00
|
|
|
use rayon::prelude::*;
|
2018-03-04 00:21:40 -08:00
|
|
|
|
2018-02-28 09:07:54 -08:00
|
|
|
fn main() {
|
2018-02-28 13:16:50 -08:00
|
|
|
let addr = "127.0.0.1:8000";
|
2018-03-01 11:23:27 -08:00
|
|
|
let send_addr = "127.0.0.1:8001";
|
2018-03-03 20:15:42 -08:00
|
|
|
|
2018-03-07 16:08:12 -08:00
|
|
|
let mint: Mint = serde_json::from_reader(stdin()).unwrap();
|
|
|
|
let mint_keypair = mint.keypair();
|
|
|
|
let mint_pubkey = mint.pubkey();
|
2018-02-28 09:07:54 -08:00
|
|
|
|
2018-03-03 20:15:42 -08:00
|
|
|
let socket = UdpSocket::bind(send_addr).unwrap();
|
2018-03-28 13:40:58 -07:00
|
|
|
let stream = TcpStream::connect(addr).unwrap();
|
|
|
|
stream.set_nonblocking(true).expect("nonblocking");
|
|
|
|
|
2018-03-28 15:51:18 -07:00
|
|
|
let acc = AccountantStub::new(addr, socket, stream);
|
2018-03-05 11:48:09 -08:00
|
|
|
let last_id = acc.get_last_id().unwrap();
|
2018-03-05 14:34:15 -08:00
|
|
|
|
2018-03-28 13:40:58 -07:00
|
|
|
let mint_balance = acc.get_balance(&mint_pubkey).unwrap().unwrap();
|
|
|
|
println!("Mint's Initial Balance {}", mint_balance);
|
2018-03-05 14:34:15 -08:00
|
|
|
|
2018-03-03 09:23:31 -08:00
|
|
|
println!("Signing transactions...");
|
2018-03-28 15:51:18 -07:00
|
|
|
let txs = 10_000;
|
2018-03-03 09:23:31 -08:00
|
|
|
let now = Instant::now();
|
2018-03-06 15:34:14 -08:00
|
|
|
let transactions: Vec<_> = (0..txs)
|
2018-03-28 15:51:18 -07:00
|
|
|
.into_par_iter()
|
2018-03-03 10:45:21 -08:00
|
|
|
.map(|_| {
|
2018-03-07 14:32:22 -08:00
|
|
|
let rando_pubkey = KeyPair::new().pubkey();
|
2018-03-07 16:08:12 -08:00
|
|
|
Transaction::new(&mint_keypair, rando_pubkey, 1, last_id)
|
2018-03-03 10:45:21 -08:00
|
|
|
})
|
|
|
|
.collect();
|
2018-03-03 09:23:31 -08:00
|
|
|
let duration = now.elapsed();
|
2018-03-22 13:15:29 -07:00
|
|
|
let ns = duration.as_secs() * 1_000_000_000 + u64::from(duration.subsec_nanos());
|
2018-03-03 09:23:31 -08:00
|
|
|
let bsps = txs as f64 / ns as f64;
|
|
|
|
let nsps = ns as f64 / txs as f64;
|
|
|
|
println!(
|
2018-03-03 10:52:46 -08:00
|
|
|
"Done. {} thousand signatures per second, {}us per signature",
|
|
|
|
bsps * 1_000_000_f64,
|
|
|
|
nsps / 1_000_f64
|
2018-03-03 09:23:31 -08:00
|
|
|
);
|
|
|
|
|
2018-03-03 10:59:34 -08:00
|
|
|
println!("Verify signatures...");
|
|
|
|
let now = Instant::now();
|
2018-03-28 15:51:18 -07:00
|
|
|
transactions.par_iter().for_each(|tr| assert!(tr.verify()));
|
2018-03-03 10:59:34 -08:00
|
|
|
let duration = now.elapsed();
|
2018-03-22 13:15:29 -07:00
|
|
|
let ns = duration.as_secs() * 1_000_000_000 + u64::from(duration.subsec_nanos());
|
2018-03-03 10:59:34 -08:00
|
|
|
let bsvps = txs as f64 / ns as f64;
|
|
|
|
let nspsv = ns as f64 / txs as f64;
|
|
|
|
println!(
|
|
|
|
"Done. {} thousand signature verifications per second, {}us per signature verification",
|
|
|
|
bsvps * 1_000_000_f64,
|
|
|
|
nspsv / 1_000_f64
|
|
|
|
);
|
|
|
|
|
2018-02-28 18:33:28 -08:00
|
|
|
println!("Transferring 1 unit {} times...", txs);
|
2018-03-01 11:23:27 -08:00
|
|
|
let now = Instant::now();
|
2018-03-28 15:51:18 -07:00
|
|
|
let mut _sig = Default::default();
|
2018-03-06 15:34:14 -08:00
|
|
|
for tr in transactions {
|
2018-03-28 15:51:18 -07:00
|
|
|
_sig = tr.sig;
|
2018-03-06 15:34:14 -08:00
|
|
|
acc.transfer_signed(tr).unwrap();
|
2018-02-28 18:33:28 -08:00
|
|
|
}
|
2018-03-01 11:23:27 -08:00
|
|
|
println!("Waiting for last transaction to be confirmed...",);
|
2018-03-28 15:51:18 -07:00
|
|
|
let mut val = mint_balance;
|
|
|
|
while val > mint_balance - txs {
|
|
|
|
val = acc.get_balance(&mint_pubkey).unwrap().unwrap();
|
2018-03-28 13:40:58 -07:00
|
|
|
}
|
2018-03-28 15:51:18 -07:00
|
|
|
//if txs > 0 {
|
|
|
|
// acc.wait_on_signature(&sig, &last_id).unwrap();
|
|
|
|
//}
|
2018-02-28 09:07:54 -08:00
|
|
|
|
2018-03-01 11:23:27 -08:00
|
|
|
let duration = now.elapsed();
|
2018-03-22 13:15:29 -07:00
|
|
|
let ns = duration.as_secs() * 1_000_000_000 + u64::from(duration.subsec_nanos());
|
2018-03-01 11:23:27 -08:00
|
|
|
let tps = (txs * 1_000_000_000) as f64 / ns as f64;
|
|
|
|
println!("Done. {} tps!", tps);
|
2018-03-07 16:08:12 -08:00
|
|
|
println!("Mint's Final Balance {}", val);
|
2018-03-28 13:40:58 -07:00
|
|
|
assert_eq!(val, mint_balance - txs);
|
2018-03-28 15:51:18 -07:00
|
|
|
|
|
|
|
// Force the ledger to print on the server.
|
|
|
|
acc.get_last_id().unwrap();
|
2018-02-28 09:07:54 -08:00
|
|
|
}
|