Add get_finality request and use it from multinode test (#941)

This commit is contained in:
Pankaj Garg
2018-08-13 08:55:13 -07:00
committed by GitHub
parent 288ed7a8ea
commit bf15cad36b
6 changed files with 73 additions and 2 deletions

33
src/thin_client.rs Normal file → Executable file
View File

@@ -29,6 +29,7 @@ pub struct ThinClient {
transaction_count: u64,
balances: HashMap<Pubkey, i64>,
signature_status: bool,
finality: Option<usize>,
}
impl ThinClient {
@@ -50,6 +51,7 @@ impl ThinClient {
transaction_count: 0,
balances: HashMap::new(),
signature_status: false,
finality: None,
}
}
@@ -83,6 +85,10 @@ impl ThinClient {
trace!("Response signature not found");
}
}
Response::Finality { time } => {
trace!("Response finality {:?}", time);
self.finality = Some(time);
}
}
}
@@ -143,6 +149,33 @@ impl ThinClient {
.ok_or_else(|| io::Error::new(io::ErrorKind::Other, "nokey"))
}
/// Request the finality from the leader node
pub fn get_finality(&mut self) -> usize {
trace!("get_finality");
let req = Request::GetFinality;
let data = serialize(&req).expect("serialize GetFinality in pub fn get_finality");
let mut done = false;
while !done {
debug!("get_finality send_to {}", &self.requests_addr);
self.requests_socket
.send_to(&data, &self.requests_addr)
.expect("buffer error in pub fn get_finality");
match self.recv_response() {
Ok(resp) => {
if let Response::Finality { .. } = resp {
done = true;
}
self.process_response(&resp);
}
Err(e) => {
debug!("thin_client get_finality error: {}", e);
}
}
}
self.finality.expect("some finality")
}
/// Request the transaction count. If the response packet is dropped by the network,
/// this method will hang.
pub fn transaction_count(&mut self) -> u64 {