Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

Commit

Permalink
Merge pull request #188 from garious/add-tpu
Browse files Browse the repository at this point in the history
AccountantSkel -> Tpu
  • Loading branch information
garious authored May 9, 2018
2 parents 2bfa20f + 1dca17f commit 3236be7
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 96 deletions.
6 changes: 3 additions & 3 deletions src/bin/client-demo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ use futures::Future;
use getopts::Options;
use isatty::stdin_isatty;
use rayon::prelude::*;
use solana::accountant_stub::AccountantStub;
use solana::mint::MintDemo;
use solana::signature::{KeyPair, KeyPairUtil};
use solana::thin_client::ThinClient;
use solana::transaction::Transaction;
use std::env;
use std::io::{stdin, Read};
Expand Down Expand Up @@ -87,7 +87,7 @@ fn main() {
println!("Binding to {}", client_addr);
let socket = UdpSocket::bind(&client_addr).unwrap();
socket.set_read_timeout(Some(Duration::new(5, 0))).unwrap();
let mut acc = AccountantStub::new(addr.parse().unwrap(), socket);
let mut acc = ThinClient::new(addr.parse().unwrap(), socket);

println!("Get last ID...");
let last_id = acc.get_last_id().wait().unwrap();
Expand Down Expand Up @@ -129,7 +129,7 @@ fn main() {
let mut client_addr: SocketAddr = client_addr.parse().unwrap();
client_addr.set_port(0);
let socket = UdpSocket::bind(client_addr).unwrap();
let acc = AccountantStub::new(addr.parse().unwrap(), socket);
let acc = ThinClient::new(addr.parse().unwrap(), socket);
for tr in trs {
acc.transfer_signed(tr.clone()).unwrap();
}
Expand Down
8 changes: 4 additions & 4 deletions src/bin/testnode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ extern crate solana;
use getopts::Options;
use isatty::stdin_isatty;
use solana::accountant::Accountant;
use solana::accountant_skel::AccountantSkel;
use solana::crdt::ReplicatedData;
use solana::entry::Entry;
use solana::event::Event;
use solana::historian::Historian;
use solana::signature::{KeyPair, KeyPairUtil};
use solana::tpu::Tpu;
use std::env;
use std::io::{stdin, stdout, Read};
use std::net::UdpSocket;
Expand Down Expand Up @@ -119,7 +119,7 @@ fn main() {
let (input, event_receiver) = sync_channel(10_000);
let historian = Historian::new(event_receiver, &last_id, Some(1000));
let exit = Arc::new(AtomicBool::new(false));
let skel = Arc::new(AccountantSkel::new(acc, input, historian));
let tpu = Arc::new(Tpu::new(acc, input, historian));
let serve_sock = UdpSocket::bind(&serve_addr).unwrap();
let gossip_sock = UdpSocket::bind(&gossip_addr).unwrap();
let replicate_sock = UdpSocket::bind(&replicate_addr).unwrap();
Expand All @@ -132,8 +132,8 @@ fn main() {
serve_sock.local_addr().unwrap(),
);
eprintln!("starting server...");
let threads = AccountantSkel::serve(
&skel,
let threads = Tpu::serve(
&tpu,
d,
serve_sock,
skinny_sock,
Expand Down
2 changes: 1 addition & 1 deletion src/ecdsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,11 @@ pub fn ed25519_verify(batches: &Vec<SharedPackets>) -> Vec<Vec<u8>> {

#[cfg(test)]
mod tests {
use accountant_skel::Request;
use bincode::serialize;
use ecdsa;
use packet::{Packet, Packets, SharedPackets};
use std::sync::RwLock;
use tpu::Request;
use transaction::test_tx;
use transaction::Transaction;

Expand Down
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#![cfg_attr(feature = "unstable", feature(test))]
pub mod accountant;
pub mod accountant_skel;
pub mod accountant_stub;
pub mod crdt;
pub mod ecdsa;
pub mod entry;
Expand All @@ -19,8 +17,10 @@ pub mod recorder;
pub mod result;
pub mod signature;
pub mod streamer;
pub mod transaction;
pub mod thin_client;
pub mod timing;
pub mod tpu;
pub mod transaction;
extern crate bincode;
extern crate byteorder;
extern crate chrono;
Expand Down
53 changes: 26 additions & 27 deletions src/accountant_stub.rs → src/thin_client.rs
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
//! The `accountant_stub` module is a client-side object that interfaces with a server-side Accountant
//! object via the network interface exposed by AccountantSkel. Client code should use
//! this object instead of writing messages to the network directly. The binary
//! encoding of its messages are unstable and may change in future releases.
//! The `thin_client` module is a client-side object that interfaces with
//! a server-side TPU. Client code should use this object instead of writing
//! messages to the network directly. The binary encoding of its messages are
//! unstable and may change in future releases.
use accountant_skel::{Request, Response, Subscription};
use bincode::{deserialize, serialize};
use futures::future::{ok, FutureResult};
use hash::Hash;
use signature::{KeyPair, PublicKey, Signature};
use std::collections::HashMap;
use std::io;
use std::net::{SocketAddr, UdpSocket};
use tpu::{Request, Response, Subscription};
use transaction::Transaction;

pub struct AccountantStub {
pub struct ThinClient {
pub addr: SocketAddr,
pub socket: UdpSocket,
last_id: Option<Hash>,
num_events: u64,
balances: HashMap<PublicKey, Option<i64>>,
}

impl AccountantStub {
/// Create a new AccountantStub that will interface with AccountantSkel
impl ThinClient {
/// Create a new ThinClient that will interface with Tpu
/// over `socket`. To receive responses, the caller must bind `socket`
/// to a public address before invoking AccountantStub methods.
/// to a public address before invoking ThinClient methods.
pub fn new(addr: SocketAddr, socket: UdpSocket) -> Self {
let stub = AccountantStub {
let client = ThinClient {
addr: addr,
socket,
last_id: None,
num_events: 0,
balances: HashMap::new(),
};
stub.init();
stub
client.init();
client
}

pub fn init(&self) {
Expand Down Expand Up @@ -119,7 +119,7 @@ impl AccountantStub {
}

/// Return the number of transactions the server processed since creating
/// this stub instance.
/// this client instance.
pub fn transaction_count(&mut self) -> u64 {
// Wait for at least one EntryInfo.
let mut done = false;
Expand Down Expand Up @@ -148,7 +148,6 @@ impl AccountantStub {
mod tests {
use super::*;
use accountant::Accountant;
use accountant_skel::AccountantSkel;
use crdt::{Crdt, ReplicatedData};
use futures::Future;
use historian::Historian;
Expand All @@ -162,10 +161,11 @@ mod tests {
use std::thread::sleep;
use std::time::Duration;
use std::time::Instant;
use tpu::Tpu;

// TODO: Figure out why this test sometimes hangs on TravisCI.
#[test]
fn test_accountant_stub() {
fn test_thin_client() {
logger::setup();
let gossip = UdpSocket::bind("0.0.0.0:0").unwrap();
let serve = UdpSocket::bind("0.0.0.0:0").unwrap();
Expand All @@ -185,14 +185,13 @@ mod tests {
let exit = Arc::new(AtomicBool::new(false));
let (input, event_receiver) = sync_channel(10);
let historian = Historian::new(event_receiver, &alice.last_id(), Some(30));
let acc = Arc::new(AccountantSkel::new(acc, input, historian));
let threads =
AccountantSkel::serve(&acc, d, serve, skinny, gossip, exit.clone(), sink()).unwrap();
let acc = Arc::new(Tpu::new(acc, input, historian));
let threads = Tpu::serve(&acc, d, serve, skinny, gossip, exit.clone(), sink()).unwrap();
sleep(Duration::from_millis(300));

let socket = UdpSocket::bind("0.0.0.0:0").unwrap();

let mut acc = AccountantStub::new(addr, socket);
let mut acc = ThinClient::new(addr, socket);
let last_id = acc.get_last_id().wait().unwrap();
let _sig = acc.transfer(500, &alice.keypair(), bob_pubkey, &last_id)
.unwrap();
Expand Down Expand Up @@ -230,9 +229,9 @@ mod tests {
}

#[test]
fn test_multi_accountant_stub() {
fn test_multi_node() {
logger::setup();
info!("test_multi_accountant_stub");
info!("test_multi_node");
let leader = test_node();
let replicant = test_node();
let alice = Mint::new(10_000);
Expand All @@ -243,17 +242,17 @@ mod tests {
let (input, event_receiver) = sync_channel(10);
let historian = Historian::new(event_receiver, &alice.last_id(), Some(30));
let acc = Accountant::new(&alice);
Arc::new(AccountantSkel::new(acc, input, historian))
Arc::new(Tpu::new(acc, input, historian))
};

let replicant_acc = {
let (input, event_receiver) = sync_channel(10);
let historian = Historian::new(event_receiver, &alice.last_id(), Some(30));
let acc = Accountant::new(&alice);
Arc::new(AccountantSkel::new(acc, input, historian))
Arc::new(Tpu::new(acc, input, historian))
};

let leader_threads = AccountantSkel::serve(
let leader_threads = Tpu::serve(
&leader_acc,
leader.0.clone(),
leader.2,
Expand All @@ -262,7 +261,7 @@ mod tests {
exit.clone(),
sink(),
).unwrap();
let replicant_threads = AccountantSkel::replicate(
let replicant_threads = Tpu::replicate(
&replicant_acc,
replicant.0.clone(),
replicant.1,
Expand Down Expand Up @@ -314,7 +313,7 @@ mod tests {
let socket = UdpSocket::bind("0.0.0.0:0").unwrap();
socket.set_read_timeout(Some(Duration::new(1, 0))).unwrap();

let mut acc = AccountantStub::new(leader.0.serve_addr, socket);
let mut acc = ThinClient::new(leader.0.serve_addr, socket);
info!("getting leader last_id");
let last_id = acc.get_last_id().wait().unwrap();
info!("executing leader transer");
Expand All @@ -330,7 +329,7 @@ mod tests {
let socket = UdpSocket::bind("0.0.0.0:0").unwrap();
socket.set_read_timeout(Some(Duration::new(1, 0))).unwrap();

let mut acc = AccountantStub::new(replicant.0.serve_addr, socket);
let mut acc = ThinClient::new(replicant.0.serve_addr, socket);
info!("getting replicant balance");
if let Ok(bal) = acc.get_balance(&bob_pubkey) {
replicant_balance = bal;
Expand Down
2 changes: 1 addition & 1 deletion src/timing.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::time::{SystemTime, UNIX_EPOCH};
use std::time::Duration;
use std::time::{SystemTime, UNIX_EPOCH};

pub fn duration_as_ms(d: &Duration) -> u64 {
return (d.as_secs() * 1000) + (d.subsec_nanos() as u64 / 1_000_000);
Expand Down
Loading

0 comments on commit 3236be7

Please sign in to comment.