Rename getConfirmation -> getConfirmationTime

This commit is contained in:
Michael Vines 2018-12-21 08:25:07 -08:00
parent 371cb4f0f3
commit 2c9607d5da
6 changed files with 32 additions and 32 deletions

View File

@ -898,11 +898,11 @@ impl Bank {
self.accounts.hash_internal_state() self.accounts.hash_internal_state()
} }
pub fn confirmation(&self) -> usize { pub fn confirmation_time(&self) -> usize {
self.confirmation_time.load(Ordering::Relaxed) self.confirmation_time.load(Ordering::Relaxed)
} }
pub fn set_confirmation(&self, confirmation: usize) { pub fn set_confirmation_time(&self, confirmation: usize) {
self.confirmation_time self.confirmation_time
.store(confirmation, Ordering::Relaxed); .store(confirmation, Ordering::Relaxed);
} }
@ -1432,11 +1432,11 @@ mod tests {
assert_eq!(bank0.hash_internal_state(), bank1.hash_internal_state()); assert_eq!(bank0.hash_internal_state(), bank1.hash_internal_state());
} }
#[test] #[test]
fn test_confirmation() { fn test_confirmation_time() {
let def_bank = Bank::default(); let def_bank = Bank::default();
assert_eq!(def_bank.confirmation(), std::usize::MAX); assert_eq!(def_bank.confirmation_time(), std::usize::MAX);
def_bank.set_confirmation(90); def_bank.set_confirmation_time(90);
assert_eq!(def_bank.confirmation(), 90); assert_eq!(def_bank.confirmation_time(), 90);
} }
#[test] #[test]
fn test_interleaving_locks() { fn test_interleaving_locks() {

View File

@ -106,7 +106,7 @@ impl ComputeLeaderConfirmationService {
let confirmation_ms = now - super_majority_timestamp; let confirmation_ms = now - super_majority_timestamp;
*last_valid_validator_timestamp = super_majority_timestamp; *last_valid_validator_timestamp = super_majority_timestamp;
bank.set_confirmation((now - *last_valid_validator_timestamp) as usize); bank.set_confirmation_time((now - *last_valid_validator_timestamp) as usize);
submit( submit(
influxdb::Point::new(&"leader-confirmation") influxdb::Point::new(&"leader-confirmation")
@ -220,7 +220,7 @@ pub mod tests {
dummy_leader_id, dummy_leader_id,
&mut last_confirmation_time, &mut last_confirmation_time,
); );
assert_eq!(bank.confirmation(), std::usize::MAX); assert_eq!(bank.confirmation_time(), std::usize::MAX);
// Get another validator to vote, so we now have 2/3 consensus // Get another validator to vote, so we now have 2/3 consensus
let vote_account = &vote_accounts[7]; let vote_account = &vote_accounts[7];
@ -233,7 +233,7 @@ pub mod tests {
dummy_leader_id, dummy_leader_id,
&mut last_confirmation_time, &mut last_confirmation_time,
); );
assert!(bank.confirmation() != std::usize::MAX); assert!(bank.confirmation_time() != std::usize::MAX);
assert!(last_confirmation_time > 0); assert!(last_confirmation_time > 0);
} }
} }

View File

@ -135,8 +135,8 @@ build_rpc_trait! {
#[rpc(meta, name = "getBalance")] #[rpc(meta, name = "getBalance")]
fn get_balance(&self, Self::Metadata, String) -> Result<u64>; fn get_balance(&self, Self::Metadata, String) -> Result<u64>;
#[rpc(meta, name = "getConfirmation")] #[rpc(meta, name = "getConfirmationTime")]
fn get_confirmation(&self, Self::Metadata) -> Result<usize>; fn get_confirmation_time(&self, Self::Metadata) -> Result<usize>;
#[rpc(meta, name = "getLastId")] #[rpc(meta, name = "getLastId")]
fn get_last_id(&self, Self::Metadata) -> Result<String>; fn get_last_id(&self, Self::Metadata) -> Result<String>;
@ -184,9 +184,9 @@ impl RpcSol for RpcSolImpl {
let pubkey = verify_pubkey(id)?; let pubkey = verify_pubkey(id)?;
meta.request_processor.get_balance(pubkey) meta.request_processor.get_balance(pubkey)
} }
fn get_confirmation(&self, meta: Self::Metadata) -> Result<usize> { fn get_confirmation_time(&self, meta: Self::Metadata) -> Result<usize> {
info!("get_confirmation rpc request received"); info!("get_confirmation_time rpc request received");
meta.request_processor.get_confirmation() meta.request_processor.get_confirmation_time()
} }
fn get_last_id(&self, meta: Self::Metadata) -> Result<String> { fn get_last_id(&self, meta: Self::Metadata) -> Result<String> {
info!("get_last_id rpc request received"); info!("get_last_id rpc request received");
@ -329,8 +329,8 @@ impl JsonRpcRequestProcessor {
let val = self.bank.get_balance(&pubkey); let val = self.bank.get_balance(&pubkey);
Ok(val) Ok(val)
} }
fn get_confirmation(&self) -> Result<usize> { fn get_confirmation_time(&self) -> Result<usize> {
Ok(self.bank.confirmation()) Ok(self.bank.confirmation_time())
} }
fn get_last_id(&self) -> Result<String> { fn get_last_id(&self) -> Result<String> {
let id = self.bank.last_id(); let id = self.bank.last_id();
@ -616,7 +616,7 @@ mod tests {
let bob_pubkey = Keypair::new().pubkey(); let bob_pubkey = Keypair::new().pubkey();
let (io, meta, _last_id, _alice_keypair) = start_rpc_handler_with_tx(bob_pubkey); let (io, meta, _last_id, _alice_keypair) = start_rpc_handler_with_tx(bob_pubkey);
let req = format!(r#"{{"jsonrpc":"2.0","id":1,"method":"getConfirmation"}}"#); let req = format!(r#"{{"jsonrpc":"2.0","id":1,"method":"getConfirmationTime"}}"#);
let res = io.handle_request_sync(&req, meta); let res = io.handle_request_sync(&req, meta);
let expected = format!(r#"{{"jsonrpc":"2.0","result":18446744073709551615,"id":1}}"#); let expected = format!(r#"{{"jsonrpc":"2.0","result":18446744073709551615,"id":1}}"#);
let expected: Response = let expected: Response =

View File

@ -44,7 +44,7 @@ pub enum RpcRequest {
ConfirmTransaction, ConfirmTransaction,
GetAccountInfo, GetAccountInfo,
GetBalance, GetBalance,
GetConfirmation, GetConfirmationTime,
GetLastId, GetLastId,
GetSignatureStatus, GetSignatureStatus,
GetTransactionCount, GetTransactionCount,
@ -89,7 +89,7 @@ impl RpcRequest {
RpcRequest::ConfirmTransaction => "confirmTransaction", RpcRequest::ConfirmTransaction => "confirmTransaction",
RpcRequest::GetAccountInfo => "getAccountInfo", RpcRequest::GetAccountInfo => "getAccountInfo",
RpcRequest::GetBalance => "getBalance", RpcRequest::GetBalance => "getBalance",
RpcRequest::GetConfirmation => "getConfirmation", RpcRequest::GetConfirmationTime => "getConfirmationTime",
RpcRequest::GetLastId => "getLastId", RpcRequest::GetLastId => "getLastId",
RpcRequest::GetSignatureStatus => "getSignatureStatus", RpcRequest::GetSignatureStatus => "getSignatureStatus",
RpcRequest::GetTransactionCount => "getTransactionCount", RpcRequest::GetTransactionCount => "getTransactionCount",
@ -166,9 +166,9 @@ mod tests {
); );
assert_eq!(request["method"], "getBalance"); assert_eq!(request["method"], "getBalance");
let test_request = RpcRequest::GetConfirmation; let test_request = RpcRequest::GetConfirmationTime;
let request = test_request.build_request_json(1, None); let request = test_request.build_request_json(1, None);
assert_eq!(request["method"], "getConfirmation"); assert_eq!(request["method"], "getConfirmationTime");
assert_eq!(request["params"], json!(null)); assert_eq!(request["params"], json!(null));
let test_request = RpcRequest::GetLastId; let test_request = RpcRequest::GetLastId;

View File

@ -187,20 +187,20 @@ impl ThinClient {
.ok_or_else(|| io::Error::new(io::ErrorKind::Other, "AccountNotFound")) .ok_or_else(|| io::Error::new(io::ErrorKind::Other, "AccountNotFound"))
} }
/// Request the confirmation from the leader node /// Request the confirmation time from the leader node
pub fn get_confirmation(&mut self) -> usize { pub fn get_confirmation_time(&mut self) -> usize {
trace!("get_confirmation"); trace!("get_confirmation_time");
let mut done = false; let mut done = false;
while !done { while !done {
debug!("get_confirmation send_to {}", &self.rpc_addr); debug!("get_confirmation_time send_to {}", &self.rpc_addr);
let resp = RpcRequest::GetConfirmation.make_rpc_request(&self.rpc_client, 1, None); let resp = RpcRequest::GetConfirmationTime.make_rpc_request(&self.rpc_client, 1, None);
if let Ok(value) = resp { if let Ok(value) = resp {
done = true; done = true;
let confirmation = value.as_u64().unwrap() as usize; let confirmation = value.as_u64().unwrap() as usize;
self.confirmation = Some(confirmation); self.confirmation = Some(confirmation);
} else { } else {
debug!("thin_client get_confirmation error: {:?}", resp); debug!("thin_client get_confirmation_time error: {:?}", resp);
} }
} }
self.confirmation.expect("some confirmation") self.confirmation.expect("some confirmation")
@ -477,7 +477,7 @@ mod tests {
let mut client = ThinClient::new(leader_data.rpc, leader_data.tpu, transactions_socket); let mut client = ThinClient::new(leader_data.rpc, leader_data.tpu, transactions_socket);
let transaction_count = client.transaction_count(); let transaction_count = client.transaction_count();
assert_eq!(transaction_count, 0); assert_eq!(transaction_count, 0);
let confirmation = client.get_confirmation(); let confirmation = client.get_confirmation_time();
assert_eq!(confirmation, 18446744073709551615); assert_eq!(confirmation, 18446744073709551615);
let last_id = client.get_last_id(); let last_id = client.get_last_id();
let signature = client let signature = client

View File

@ -714,7 +714,7 @@ fn test_multi_node_dynamic_network() {
let mut validators: Vec<_> = t2.into_iter().map(|t| t.join().unwrap()).collect(); let mut validators: Vec<_> = t2.into_iter().map(|t| t.join().unwrap()).collect();
let mut client = mk_client(&leader_data); let mut client = mk_client(&leader_data);
let mut last_confirmation = client.get_confirmation(); let mut last_confirmation = client.get_confirmation_time();
info!("Last confirmation {}", last_confirmation); info!("Last confirmation {}", last_confirmation);
let start = Instant::now(); let start = Instant::now();
let mut consecutive_success = 0; let mut consecutive_success = 0;
@ -738,17 +738,17 @@ fn test_multi_node_dynamic_network() {
assert!(e.is_ok(), "err: {:?}", e); assert!(e.is_ok(), "err: {:?}", e);
let now = Instant::now(); let now = Instant::now();
let mut confirmation = client.get_confirmation(); let mut confirmation = client.get_confirmation_time();
// Need this to make sure the confirmation is updated // Need this to make sure the confirmation is updated
// (i.e. the node is not returning stale value) // (i.e. the node is not returning stale value)
while last_confirmation == confirmation { while last_confirmation == confirmation {
confirmation = client.get_confirmation(); confirmation = client.get_confirmation_time();
} }
while duration_as_ms(&now.elapsed()) < confirmation as u64 { while duration_as_ms(&now.elapsed()) < confirmation as u64 {
sleep(Duration::from_millis(100)); sleep(Duration::from_millis(100));
confirmation = client.get_confirmation() confirmation = client.get_confirmation_time()
} }
last_confirmation = confirmation; last_confirmation = confirmation;