Revert TCP sync of ledger
The feature was too rushed. We technically don't need it until we implement consensus. It'll come back another day (with many more tests!)
This commit is contained in:
parent
04f30710c5
commit
0bec360a31
|
@ -7,7 +7,7 @@ use serde_json;
|
|||
use signature::PublicKey;
|
||||
use std::default::Default;
|
||||
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::mpsc::channel;
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
@ -162,16 +162,6 @@ impl<W: Write + Send + 'static> AccountantSkel<W> {
|
|||
}
|
||||
});
|
||||
|
||||
let listener = TcpListener::bind(addr)?;
|
||||
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])
|
||||
Ok(vec![t_receiver, t_responder, t_server])
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,26 +3,24 @@
|
|||
//! transfer funds to other users.
|
||||
|
||||
use accountant_skel::{Request, Response};
|
||||
use bincode::{deserialize, serialize, serialized_size};
|
||||
use bincode::{deserialize, serialize};
|
||||
use entry::Entry;
|
||||
use hash::Hash;
|
||||
use signature::{KeyPair, PublicKey, Signature};
|
||||
use std::io::{self, Read};
|
||||
use std::net::{TcpStream, UdpSocket};
|
||||
use std::io;
|
||||
use std::net::UdpSocket;
|
||||
use transaction::Transaction;
|
||||
|
||||
pub struct AccountantStub {
|
||||
pub addr: String,
|
||||
pub socket: UdpSocket,
|
||||
pub stream: TcpStream,
|
||||
}
|
||||
|
||||
impl AccountantStub {
|
||||
pub fn new(addr: &str, socket: UdpSocket, stream: TcpStream) -> Self {
|
||||
pub fn new(addr: &str, socket: UdpSocket) -> Self {
|
||||
AccountantStub {
|
||||
addr: addr.to_string(),
|
||||
socket,
|
||||
stream,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -74,53 +72,6 @@ impl AccountantStub {
|
|||
pub fn get_last_id(&self) -> io::Result<Hash> {
|
||||
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)]
|
||||
|
@ -150,15 +101,11 @@ mod tests {
|
|||
sleep(Duration::from_millis(300));
|
||||
|
||||
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, stream);
|
||||
let acc = AccountantStub::new(addr, socket);
|
||||
let last_id = acc.get_last_id().unwrap();
|
||||
let _sig = acc.transfer(500, &alice.keypair(), bob_pubkey, &last_id)
|
||||
.unwrap();
|
||||
//acc.wait_on_signature(&sig, &last_id).unwrap();
|
||||
assert_eq!(acc.get_balance(&bob_pubkey).unwrap().unwrap(), 500);
|
||||
exit.store(true, Ordering::Relaxed);
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ use solana::mint::Mint;
|
|||
use solana::signature::{KeyPair, KeyPairUtil};
|
||||
use solana::transaction::Transaction;
|
||||
use std::io::stdin;
|
||||
use std::net::{TcpStream, UdpSocket};
|
||||
use std::net::UdpSocket;
|
||||
use std::time::Instant;
|
||||
use rayon::prelude::*;
|
||||
|
||||
|
@ -20,10 +20,7 @@ fn main() {
|
|||
let mint_pubkey = mint.pubkey();
|
||||
|
||||
let socket = UdpSocket::bind(send_addr).unwrap();
|
||||
let stream = TcpStream::connect(addr).unwrap();
|
||||
stream.set_nonblocking(true).expect("nonblocking");
|
||||
|
||||
let acc = AccountantStub::new(addr, socket, stream);
|
||||
let acc = AccountantStub::new(addr, socket);
|
||||
let last_id = acc.get_last_id().unwrap();
|
||||
|
||||
let mint_balance = acc.get_balance(&mint_pubkey).unwrap().unwrap();
|
||||
|
@ -74,9 +71,6 @@ fn main() {
|
|||
while val > mint_balance - txs {
|
||||
val = acc.get_balance(&mint_pubkey).unwrap().unwrap();
|
||||
}
|
||||
//if txs > 0 {
|
||||
// acc.wait_on_signature(&sig, &last_id).unwrap();
|
||||
//}
|
||||
|
||||
let duration = now.elapsed();
|
||||
let ns = duration.as_secs() * 1_000_000_000 + u64::from(duration.subsec_nanos());
|
||||
|
|
Loading…
Reference in New Issue