Move key generation and signing from transaction benchmark
Key generation, signing and verification are not the performance bottleneck. Something is probably wrong here.
This commit is contained in:
parent
8871bb2d8e
commit
d8c50b150c
|
@ -42,11 +42,15 @@ impl AccountantSkel {
|
||||||
pub fn process_request(self: &mut Self, msg: Request) -> Option<Response> {
|
pub fn process_request(self: &mut Self, msg: Request) -> Option<Response> {
|
||||||
match msg {
|
match msg {
|
||||||
Request::Deposit { key, val, sig } => {
|
Request::Deposit { key, val, sig } => {
|
||||||
let _ = self.obj.deposit_signed(key, val, sig);
|
if let Err(err) = self.obj.deposit_signed(key, val, sig) {
|
||||||
|
println!("Deposit error: {:?}", err);
|
||||||
|
}
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
Request::Transfer { from, to, val, sig } => {
|
Request::Transfer { from, to, val, sig } => {
|
||||||
let _ = self.obj.transfer_signed(from, to, val, sig);
|
if let Err(err) = self.obj.transfer_signed(from, to, val, sig) {
|
||||||
|
println!("Transfer error: {:?}", err);
|
||||||
|
}
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
Request::GetBalance { key } => {
|
Request::GetBalance { key } => {
|
||||||
|
|
|
@ -23,7 +23,7 @@ impl AccountantStub {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn deposit_signed(
|
pub fn deposit_signed(
|
||||||
self: &mut Self,
|
self: &Self,
|
||||||
key: PublicKey,
|
key: PublicKey,
|
||||||
val: u64,
|
val: u64,
|
||||||
sig: Signature,
|
sig: Signature,
|
||||||
|
@ -33,7 +33,7 @@ impl AccountantStub {
|
||||||
self.socket.send_to(&data, &self.addr)
|
self.socket.send_to(&data, &self.addr)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn deposit(self: &mut Self, n: u64, keypair: &Ed25519KeyPair) -> io::Result<Signature> {
|
pub fn deposit(self: &Self, n: u64, keypair: &Ed25519KeyPair) -> io::Result<Signature> {
|
||||||
use event::{get_pubkey, sign_claim_data};
|
use event::{get_pubkey, sign_claim_data};
|
||||||
let key = get_pubkey(keypair);
|
let key = get_pubkey(keypair);
|
||||||
let sig = sign_claim_data(&n, keypair);
|
let sig = sign_claim_data(&n, keypair);
|
||||||
|
@ -41,7 +41,7 @@ impl AccountantStub {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn transfer_signed(
|
pub fn transfer_signed(
|
||||||
self: &mut Self,
|
self: &Self,
|
||||||
from: PublicKey,
|
from: PublicKey,
|
||||||
to: PublicKey,
|
to: PublicKey,
|
||||||
val: u64,
|
val: u64,
|
||||||
|
@ -53,7 +53,7 @@ impl AccountantStub {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn transfer(
|
pub fn transfer(
|
||||||
self: &mut Self,
|
self: &Self,
|
||||||
n: u64,
|
n: u64,
|
||||||
keypair: &Ed25519KeyPair,
|
keypair: &Ed25519KeyPair,
|
||||||
to: PublicKey,
|
to: PublicKey,
|
||||||
|
@ -64,7 +64,7 @@ impl AccountantStub {
|
||||||
self.transfer_signed(from, to, n, sig).map(|_| sig)
|
self.transfer_signed(from, to, n, sig).map(|_| sig)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_balance(self: &mut Self, pubkey: &PublicKey) -> io::Result<u64> {
|
pub fn get_balance(self: &Self, pubkey: &PublicKey) -> io::Result<u64> {
|
||||||
let req = Request::GetBalance { key: *pubkey };
|
let req = Request::GetBalance { key: *pubkey };
|
||||||
let data = serialize(&req).expect("serialize GetBalance");
|
let data = serialize(&req).expect("serialize GetBalance");
|
||||||
self.socket.send_to(&data, &self.addr)?;
|
self.socket.send_to(&data, &self.addr)?;
|
||||||
|
@ -78,7 +78,7 @@ impl AccountantStub {
|
||||||
Ok(0)
|
Ok(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn wait_on_signature(self: &mut Self, wait_sig: &Signature) -> io::Result<()> {
|
pub fn wait_on_signature(self: &Self, wait_sig: &Signature) -> io::Result<()> {
|
||||||
let req = Request::Wait { sig: *wait_sig };
|
let req = Request::Wait { sig: *wait_sig };
|
||||||
let data = serialize(&req).unwrap();
|
let data = serialize(&req).unwrap();
|
||||||
self.socket.send_to(&data, &self.addr).map(|_| ())?;
|
self.socket.send_to(&data, &self.addr).map(|_| ())?;
|
||||||
|
@ -117,7 +117,7 @@ mod tests {
|
||||||
sleep(Duration::from_millis(30));
|
sleep(Duration::from_millis(30));
|
||||||
|
|
||||||
let socket = UdpSocket::bind(send_addr).unwrap();
|
let socket = UdpSocket::bind(send_addr).unwrap();
|
||||||
let mut acc = AccountantStub::new(addr, socket);
|
let acc = AccountantStub::new(addr, socket);
|
||||||
let alice_keypair = generate_keypair();
|
let alice_keypair = generate_keypair();
|
||||||
let bob_keypair = generate_keypair();
|
let bob_keypair = generate_keypair();
|
||||||
acc.deposit(10_000, &alice_keypair).unwrap();
|
acc.deposit(10_000, &alice_keypair).unwrap();
|
||||||
|
|
|
@ -4,12 +4,12 @@ fn main() {
|
||||||
use silk::accountant_stub::AccountantStub;
|
use silk::accountant_stub::AccountantStub;
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
use std::net::UdpSocket;
|
use std::net::UdpSocket;
|
||||||
use silk::event::{generate_keypair, get_pubkey};
|
use silk::event::{generate_keypair, get_pubkey, sign_transaction_data};
|
||||||
|
|
||||||
let addr = "127.0.0.1:8000";
|
let addr = "127.0.0.1:8000";
|
||||||
let send_addr = "127.0.0.1:8001";
|
let send_addr = "127.0.0.1:8001";
|
||||||
let socket = UdpSocket::bind(send_addr).unwrap();
|
let socket = UdpSocket::bind(send_addr).unwrap();
|
||||||
let mut acc = AccountantStub::new(addr, socket);
|
let acc = AccountantStub::new(addr, socket);
|
||||||
let alice_keypair = generate_keypair();
|
let alice_keypair = generate_keypair();
|
||||||
let alice_pubkey = get_pubkey(&alice_keypair);
|
let alice_pubkey = get_pubkey(&alice_keypair);
|
||||||
let txs = 2_000;
|
let txs = 2_000;
|
||||||
|
@ -19,13 +19,30 @@ fn main() {
|
||||||
assert_eq!(acc.get_balance(&alice_pubkey).unwrap(), txs);
|
assert_eq!(acc.get_balance(&alice_pubkey).unwrap(), txs);
|
||||||
println!("Done.");
|
println!("Done.");
|
||||||
|
|
||||||
|
let one = 1;
|
||||||
|
println!("Signing transactions...");
|
||||||
|
let now = Instant::now();
|
||||||
|
let sigs = (0..txs).map(|_| {
|
||||||
|
let rando_keypair = generate_keypair();
|
||||||
|
let rando_pubkey = get_pubkey(&rando_keypair);
|
||||||
|
let sig = sign_transaction_data(&one, &alice_keypair, &rando_pubkey);
|
||||||
|
(rando_pubkey, sig)
|
||||||
|
});
|
||||||
|
let duration = now.elapsed();
|
||||||
|
let ns = duration.as_secs() * 1_000_000_000 + duration.subsec_nanos() as u64;
|
||||||
|
let bsps = txs as f64 / ns as f64;
|
||||||
|
let nsps = ns as f64 / txs as f64;
|
||||||
|
println!(
|
||||||
|
"Done. {} billion signatures per second, {}ns per signature",
|
||||||
|
bsps, nsps
|
||||||
|
);
|
||||||
|
|
||||||
println!("Transferring 1 unit {} times...", txs);
|
println!("Transferring 1 unit {} times...", txs);
|
||||||
let now = Instant::now();
|
let now = Instant::now();
|
||||||
let mut sig = sig;
|
let mut sig = sig;
|
||||||
for _ in 0..txs {
|
for (k, s) in sigs {
|
||||||
let bob_keypair = generate_keypair();
|
acc.transfer_signed(alice_pubkey, k, one, s).unwrap();
|
||||||
let bob_pubkey = get_pubkey(&bob_keypair);
|
sig = s;
|
||||||
sig = acc.transfer(1, &alice_keypair, bob_pubkey).unwrap();
|
|
||||||
}
|
}
|
||||||
println!("Waiting for last transaction to be confirmed...",);
|
println!("Waiting for last transaction to be confirmed...",);
|
||||||
acc.wait_on_signature(&sig).unwrap();
|
acc.wait_on_signature(&sig).unwrap();
|
||||||
|
|
Loading…
Reference in New Issue