Merge pull request #88 from garious/revert-tcp-client
Revert TCP sync of ledger
This commit is contained in:
commit
f6ca176fc8
|
@ -7,7 +7,7 @@ use serde_json;
|
||||||
use signature::PublicKey;
|
use signature::PublicKey;
|
||||||
use std::default::Default;
|
use std::default::Default;
|
||||||
use std::io::{ErrorKind, Write};
|
use std::io::{ErrorKind, Write};
|
||||||
use std::net::{TcpListener, TcpStream, UdpSocket};
|
use std::net::{TcpStream, UdpSocket};
|
||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
use std::sync::mpsc::channel;
|
use std::sync::mpsc::channel;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
|
@ -162,16 +162,6 @@ impl<W: Write + Send + 'static> AccountantSkel<W> {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let listener = TcpListener::bind(addr)?;
|
Ok(vec![t_receiver, t_responder, t_server])
|
||||||
let t_listener = spawn(move || {
|
|
||||||
for stream in listener.incoming() {
|
|
||||||
match stream {
|
|
||||||
Ok(stream) => obj.lock().unwrap().subscribers.push(stream),
|
|
||||||
Err(_) => break,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Ok(vec![t_receiver, t_responder, t_server, t_listener])
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,26 +3,24 @@
|
||||||
//! transfer funds to other users.
|
//! transfer funds to other users.
|
||||||
|
|
||||||
use accountant_skel::{Request, Response};
|
use accountant_skel::{Request, Response};
|
||||||
use bincode::{deserialize, serialize, serialized_size};
|
use bincode::{deserialize, serialize};
|
||||||
use entry::Entry;
|
use entry::Entry;
|
||||||
use hash::Hash;
|
use hash::Hash;
|
||||||
use signature::{KeyPair, PublicKey, Signature};
|
use signature::{KeyPair, PublicKey, Signature};
|
||||||
use std::io::{self, Read};
|
use std::io;
|
||||||
use std::net::{TcpStream, UdpSocket};
|
use std::net::UdpSocket;
|
||||||
use transaction::Transaction;
|
use transaction::Transaction;
|
||||||
|
|
||||||
pub struct AccountantStub {
|
pub struct AccountantStub {
|
||||||
pub addr: String,
|
pub addr: String,
|
||||||
pub socket: UdpSocket,
|
pub socket: UdpSocket,
|
||||||
pub stream: TcpStream,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AccountantStub {
|
impl AccountantStub {
|
||||||
pub fn new(addr: &str, socket: UdpSocket, stream: TcpStream) -> Self {
|
pub fn new(addr: &str, socket: UdpSocket) -> Self {
|
||||||
AccountantStub {
|
AccountantStub {
|
||||||
addr: addr.to_string(),
|
addr: addr.to_string(),
|
||||||
socket,
|
socket,
|
||||||
stream,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,53 +72,6 @@ impl AccountantStub {
|
||||||
pub fn get_last_id(&self) -> io::Result<Hash> {
|
pub fn get_last_id(&self) -> io::Result<Hash> {
|
||||||
self.get_id(true)
|
self.get_id(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn check_on_signature(
|
|
||||||
&mut self,
|
|
||||||
wait_sig: &Signature,
|
|
||||||
last_id: &Hash,
|
|
||||||
) -> io::Result<(bool, Hash)> {
|
|
||||||
let mut last_id = *last_id;
|
|
||||||
let mut buf = vec![0u8; 65_535];
|
|
||||||
let mut buf_offset = 0;
|
|
||||||
let mut found = false;
|
|
||||||
if let Ok(_bytes) = self.stream.read(&mut buf) {
|
|
||||||
loop {
|
|
||||||
match deserialize::<Entry>(&buf[buf_offset..]) {
|
|
||||||
Ok(entry) => {
|
|
||||||
buf_offset += serialized_size(&entry).unwrap() as usize;
|
|
||||||
last_id = entry.id;
|
|
||||||
if !found {
|
|
||||||
for event in entry.events {
|
|
||||||
if let Some(sig) = event.get_signature() {
|
|
||||||
if sig == *wait_sig {
|
|
||||||
found = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(_) => break,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok((found, last_id))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn wait_on_signature(&mut self, wait_sig: &Signature, last_id: &Hash) -> io::Result<Hash> {
|
|
||||||
let mut found = false;
|
|
||||||
let mut last_id = *last_id;
|
|
||||||
while !found {
|
|
||||||
let ret = self.check_on_signature(wait_sig, &last_id)?;
|
|
||||||
found = ret.0;
|
|
||||||
last_id = ret.1;
|
|
||||||
|
|
||||||
// Clunky way to force a sync in the skel.
|
|
||||||
self.get_last_id()?;
|
|
||||||
}
|
|
||||||
Ok(last_id)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -150,15 +101,11 @@ mod tests {
|
||||||
sleep(Duration::from_millis(300));
|
sleep(Duration::from_millis(300));
|
||||||
|
|
||||||
let socket = UdpSocket::bind(send_addr).unwrap();
|
let socket = UdpSocket::bind(send_addr).unwrap();
|
||||||
let stream = TcpStream::connect(addr).expect("tcp connect");
|
|
||||||
stream.set_nonblocking(true).expect("nonblocking");
|
|
||||||
|
|
||||||
//let mut acc = AccountantStub::new(addr, socket, stream);
|
let acc = AccountantStub::new(addr, socket);
|
||||||
let acc = AccountantStub::new(addr, socket, stream);
|
|
||||||
let last_id = acc.get_last_id().unwrap();
|
let last_id = acc.get_last_id().unwrap();
|
||||||
let _sig = acc.transfer(500, &alice.keypair(), bob_pubkey, &last_id)
|
let _sig = acc.transfer(500, &alice.keypair(), bob_pubkey, &last_id)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
//acc.wait_on_signature(&sig, &last_id).unwrap();
|
|
||||||
assert_eq!(acc.get_balance(&bob_pubkey).unwrap().unwrap(), 500);
|
assert_eq!(acc.get_balance(&bob_pubkey).unwrap().unwrap(), 500);
|
||||||
exit.store(true, Ordering::Relaxed);
|
exit.store(true, Ordering::Relaxed);
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ use solana::mint::Mint;
|
||||||
use solana::signature::{KeyPair, KeyPairUtil};
|
use solana::signature::{KeyPair, KeyPairUtil};
|
||||||
use solana::transaction::Transaction;
|
use solana::transaction::Transaction;
|
||||||
use std::io::stdin;
|
use std::io::stdin;
|
||||||
use std::net::{TcpStream, UdpSocket};
|
use std::net::UdpSocket;
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
use rayon::prelude::*;
|
use rayon::prelude::*;
|
||||||
|
|
||||||
|
@ -20,10 +20,7 @@ fn main() {
|
||||||
let mint_pubkey = mint.pubkey();
|
let mint_pubkey = mint.pubkey();
|
||||||
|
|
||||||
let socket = UdpSocket::bind(send_addr).unwrap();
|
let socket = UdpSocket::bind(send_addr).unwrap();
|
||||||
let stream = TcpStream::connect(addr).unwrap();
|
let acc = AccountantStub::new(addr, socket);
|
||||||
stream.set_nonblocking(true).expect("nonblocking");
|
|
||||||
|
|
||||||
let acc = AccountantStub::new(addr, socket, stream);
|
|
||||||
let last_id = acc.get_last_id().unwrap();
|
let last_id = acc.get_last_id().unwrap();
|
||||||
|
|
||||||
let mint_balance = acc.get_balance(&mint_pubkey).unwrap().unwrap();
|
let mint_balance = acc.get_balance(&mint_pubkey).unwrap().unwrap();
|
||||||
|
@ -74,9 +71,6 @@ fn main() {
|
||||||
while val > mint_balance - txs {
|
while val > mint_balance - txs {
|
||||||
val = acc.get_balance(&mint_pubkey).unwrap().unwrap();
|
val = acc.get_balance(&mint_pubkey).unwrap().unwrap();
|
||||||
}
|
}
|
||||||
//if txs > 0 {
|
|
||||||
// acc.wait_on_signature(&sig, &last_id).unwrap();
|
|
||||||
//}
|
|
||||||
|
|
||||||
let duration = now.elapsed();
|
let duration = now.elapsed();
|
||||||
let ns = duration.as_secs() * 1_000_000_000 + u64::from(duration.subsec_nanos());
|
let ns = duration.as_secs() * 1_000_000_000 + u64::from(duration.subsec_nanos());
|
||||||
|
|
Loading…
Reference in New Issue