Rename finality to confirmation (#2250)

* Rename finality to confirmation

* fix cargo fmt errors
This commit is contained in:
Pankaj Garg
2018-12-20 15:47:48 -08:00
parent 70559253ee
commit f9d8a1d6c0
11 changed files with 127 additions and 119 deletions

View File

@ -56,24 +56,24 @@ launchTestnet() {
WHERE time > now() - 300s GROUP BY time(1s) WHERE time > now() - 300s GROUP BY time(1s)
)' )'
declare q_mean_finality=' declare q_mean_confirmation='
SELECT round(mean("duration_ms")) as "mean_finality" SELECT round(mean("duration_ms")) as "mean_confirmation"
FROM "testnet-automation"."autogen"."leader-finality" FROM "testnet-automation"."autogen"."leader-confirmation"
WHERE time > now() - 300s' WHERE time > now() - 300s'
declare q_max_finality=' declare q_max_confirmation='
SELECT round(max("duration_ms")) as "max_finality" SELECT round(max("duration_ms")) as "max_confirmation"
FROM "testnet-automation"."autogen"."leader-finality" FROM "testnet-automation"."autogen"."leader-confirmation"
WHERE time > now() - 300s' WHERE time > now() - 300s'
declare q_99th_finality=' declare q_99th_confirmation='
SELECT round(percentile("duration_ms", 99)) as "99th_finality" SELECT round(percentile("duration_ms", 99)) as "99th_confirmation"
FROM "testnet-automation"."autogen"."leader-finality" FROM "testnet-automation"."autogen"."leader-confirmation"
WHERE time > now() - 300s' WHERE time > now() - 300s'
curl -G "https://metrics.solana.com:8086/query?u=${INFLUX_USERNAME}&p=${INFLUX_PASSWORD}" \ curl -G "https://metrics.solana.com:8086/query?u=${INFLUX_USERNAME}&p=${INFLUX_PASSWORD}" \
--data-urlencode "db=$INFLUX_DATABASE" \ --data-urlencode "db=$INFLUX_DATABASE" \
--data-urlencode "q=$q_mean_tps;$q_max_tps;$q_mean_finality;$q_max_finality;$q_99th_finality" | --data-urlencode "q=$q_mean_tps;$q_max_tps;$q_mean_confirmation;$q_max_confirmation;$q_99th_confirmation" |
python ci/testnet-automation-json-parser.py >>TPS"$nodeCount".log python ci/testnet-automation-json-parser.py >>TPS"$nodeCount".log
upload-ci-artifact TPS"$nodeCount".log upload-ci-artifact TPS"$nodeCount".log

View File

@ -722,7 +722,7 @@
], ],
"orderByTime": "ASC", "orderByTime": "ASC",
"policy": "default", "policy": "default",
"query": "SELECT mean(\"duration_ms\") FROM \"$testnet\".\"autogen\".\"leader-finality\" WHERE $timeFilter \n\n\n", "query": "SELECT mean(\"duration_ms\") FROM \"$testnet\".\"autogen\".\"leader-confirmation\" WHERE $timeFilter \n\n\n",
"rawQuery": true, "rawQuery": true,
"refId": "A", "refId": "A",
"resultFormat": "time_series", "resultFormat": "time_series",
@ -744,7 +744,7 @@
} }
], ],
"thresholds": "", "thresholds": "",
"title": "Mean Finality", "title": "Mean Confirmation",
"type": "singlestat", "type": "singlestat",
"valueFontSize": "70%", "valueFontSize": "70%",
"valueMaps": [ "valueMaps": [
@ -833,7 +833,7 @@
], ],
"orderByTime": "ASC", "orderByTime": "ASC",
"policy": "default", "policy": "default",
"query": "SELECT median(\"duration_ms\") FROM \"$testnet\".\"autogen\".\"leader-finality\" WHERE $timeFilter \n\n\n", "query": "SELECT median(\"duration_ms\") FROM \"$testnet\".\"autogen\".\"leader-confirmation\" WHERE $timeFilter \n\n\n",
"rawQuery": true, "rawQuery": true,
"refId": "A", "refId": "A",
"resultFormat": "time_series", "resultFormat": "time_series",
@ -855,7 +855,7 @@
} }
], ],
"thresholds": "", "thresholds": "",
"title": "Median Finality", "title": "Median Confirmation",
"type": "singlestat", "type": "singlestat",
"valueFontSize": "70%", "valueFontSize": "70%",
"valueMaps": [ "valueMaps": [
@ -944,7 +944,7 @@
], ],
"orderByTime": "ASC", "orderByTime": "ASC",
"policy": "default", "policy": "default",
"query": "SELECT min(\"duration_ms\") FROM \"$testnet\".\"autogen\".\"leader-finality\" WHERE $timeFilter \n\n\n", "query": "SELECT min(\"duration_ms\") FROM \"$testnet\".\"autogen\".\"leader-confirmation\" WHERE $timeFilter \n\n\n",
"rawQuery": true, "rawQuery": true,
"refId": "A", "refId": "A",
"resultFormat": "time_series", "resultFormat": "time_series",
@ -966,7 +966,7 @@
} }
], ],
"thresholds": "", "thresholds": "",
"title": "Min Finality", "title": "Min Confirmation",
"type": "singlestat", "type": "singlestat",
"valueFontSize": "70%", "valueFontSize": "70%",
"valueMaps": [ "valueMaps": [
@ -1055,7 +1055,7 @@
], ],
"orderByTime": "ASC", "orderByTime": "ASC",
"policy": "default", "policy": "default",
"query": "SELECT max(\"duration_ms\") FROM \"$testnet\".\"autogen\".\"leader-finality\" WHERE $timeFilter \n\n\n", "query": "SELECT max(\"duration_ms\") FROM \"$testnet\".\"autogen\".\"leader-confirmation\" WHERE $timeFilter \n\n\n",
"rawQuery": true, "rawQuery": true,
"refId": "A", "refId": "A",
"resultFormat": "time_series", "resultFormat": "time_series",
@ -1077,7 +1077,7 @@
} }
], ],
"thresholds": "", "thresholds": "",
"title": "Max Finality", "title": "Max Confirmation",
"type": "singlestat", "type": "singlestat",
"valueFontSize": "70%", "valueFontSize": "70%",
"valueMaps": [ "valueMaps": [
@ -1166,7 +1166,7 @@
], ],
"orderByTime": "ASC", "orderByTime": "ASC",
"policy": "default", "policy": "default",
"query": "SELECT percentile(\"duration_ms\", 99) FROM \"$testnet\".\"autogen\".\"leader-finality\" WHERE $timeFilter \n\n\n", "query": "SELECT percentile(\"duration_ms\", 99) FROM \"$testnet\".\"autogen\".\"leader-confirmation\" WHERE $timeFilter \n\n\n",
"rawQuery": true, "rawQuery": true,
"refId": "A", "refId": "A",
"resultFormat": "time_series", "resultFormat": "time_series",
@ -1188,7 +1188,7 @@
} }
], ],
"thresholds": "", "thresholds": "",
"title": "Finality (99th percentile)", "title": "Confirmation (99th percentile)",
"type": "singlestat", "type": "singlestat",
"valueFontSize": "70%", "valueFontSize": "70%",
"valueMaps": [ "valueMaps": [
@ -1651,7 +1651,7 @@
"measurement": "counter-cluster_info-vote-count", "measurement": "counter-cluster_info-vote-count",
"orderByTime": "ASC", "orderByTime": "ASC",
"policy": "autogen", "policy": "autogen",
"query": "SELECT mean(\"duration_ms\") FROM \"$testnet\".\"autogen\".\"leader-finality\" WHERE $timeFilter GROUP BY time(1s) FILL(0)\n", "query": "SELECT mean(\"duration_ms\") FROM \"$testnet\".\"autogen\".\"leader-confirmation\" WHERE $timeFilter GROUP BY time(1s) FILL(0)\n",
"rawQuery": true, "rawQuery": true,
"refId": "A", "refId": "A",
"resultFormat": "time_series", "resultFormat": "time_series",
@ -1675,7 +1675,7 @@
"thresholds": [], "thresholds": [],
"timeFrom": null, "timeFrom": null,
"timeShift": null, "timeShift": null,
"title": "Finality", "title": "Time since last Confirmation",
"tooltip": { "tooltip": {
"shared": true, "shared": true,
"sort": 0, "sort": 0,

View File

@ -94,8 +94,8 @@ pub struct Bank {
/// FIFO queue of `last_id` items /// FIFO queue of `last_id` items
last_ids: RwLock<StatusDeque<Result<()>>>, last_ids: RwLock<StatusDeque<Result<()>>>,
// The latest finality time for the network // The latest confirmation time for the network
finality_time: AtomicUsize, confirmation_time: AtomicUsize,
// Mapping of account ids to Subscriber ids and sinks to notify on userdata update // Mapping of account ids to Subscriber ids and sinks to notify on userdata update
account_subscriptions: RwLock<HashMap<Pubkey, HashMap<Pubkey, Sink<Account>>>>, account_subscriptions: RwLock<HashMap<Pubkey, HashMap<Pubkey, Sink<Account>>>>,
@ -115,7 +115,7 @@ impl Default for Bank {
Bank { Bank {
accounts: Accounts::default(), accounts: Accounts::default(),
last_ids: RwLock::new(StatusDeque::default()), last_ids: RwLock::new(StatusDeque::default()),
finality_time: AtomicUsize::new(std::usize::MAX), confirmation_time: AtomicUsize::new(std::usize::MAX),
account_subscriptions: RwLock::new(HashMap::new()), account_subscriptions: RwLock::new(HashMap::new()),
signature_subscriptions: RwLock::new(HashMap::new()), signature_subscriptions: RwLock::new(HashMap::new()),
leader_scheduler: Arc::new(RwLock::new(LeaderScheduler::default())), leader_scheduler: Arc::new(RwLock::new(LeaderScheduler::default())),
@ -316,14 +316,14 @@ impl Bank {
} }
/// Looks through a list of tick heights and stakes, and finds the latest /// Looks through a list of tick heights and stakes, and finds the latest
/// tick that has achieved finality /// tick that has achieved confirmation
pub fn get_finality_timestamp( pub fn get_confirmation_timestamp(
&self, &self,
ticks_and_stakes: &mut [(u64, u64)], ticks_and_stakes: &mut [(u64, u64)],
supermajority_stake: u64, supermajority_stake: u64,
) -> Option<u64> { ) -> Option<u64> {
let last_ids = self.last_ids.read().unwrap(); let last_ids = self.last_ids.read().unwrap();
last_ids.get_finality_timestamp(ticks_and_stakes, supermajority_stake) last_ids.get_confirmation_timestamp(ticks_and_stakes, supermajority_stake)
} }
/// Tell the bank which Entry IDs exist on the ledger. This function /// Tell the bank which Entry IDs exist on the ledger. This function
@ -871,12 +871,13 @@ impl Bank {
self.accounts.hash_internal_state() self.accounts.hash_internal_state()
} }
pub fn finality(&self) -> usize { pub fn confirmation(&self) -> usize {
self.finality_time.load(Ordering::Relaxed) self.confirmation_time.load(Ordering::Relaxed)
} }
pub fn set_finality(&self, finality: usize) { pub fn set_confirmation(&self, confirmation: usize) {
self.finality_time.store(finality, Ordering::Relaxed); self.confirmation_time
.store(confirmation, Ordering::Relaxed);
} }
fn send_account_notifications( fn send_account_notifications(
@ -1403,11 +1404,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_finality() { fn test_confirmation() {
let def_bank = Bank::default(); let def_bank = Bank::default();
assert_eq!(def_bank.finality(), std::usize::MAX); assert_eq!(def_bank.confirmation(), std::usize::MAX);
def_bank.set_finality(90); def_bank.set_confirmation(90);
assert_eq!(def_bank.finality(), 90); assert_eq!(def_bank.confirmation(), 90);
} }
#[test] #[test]
fn test_interleaving_locks() { fn test_interleaving_locks() {

View File

@ -3,7 +3,7 @@
//! can do its processing in parallel with signature verification on the GPU. //! can do its processing in parallel with signature verification on the GPU.
use crate::bank::Bank; use crate::bank::Bank;
use crate::compute_leader_finality_service::ComputeLeaderFinalityService; use crate::compute_leader_confirmation_service::ComputeLeaderConfirmationService;
use crate::counter::Counter; use crate::counter::Counter;
use crate::entry::Entry; use crate::entry::Entry;
use crate::packet::Packets; use crate::packet::Packets;
@ -40,7 +40,7 @@ pub struct BankingStage {
/// Handle to the stage's thread. /// Handle to the stage's thread.
bank_thread_hdls: Vec<JoinHandle<Option<BankingStageReturnType>>>, bank_thread_hdls: Vec<JoinHandle<Option<BankingStageReturnType>>>,
poh_service: PohService, poh_service: PohService,
compute_finality_service: ComputeLeaderFinalityService, compute_confirmation_service: ComputeLeaderConfirmationService,
} }
impl BankingStage { impl BankingStage {
@ -64,8 +64,8 @@ impl BankingStage {
// Once an entry has been recorded, its last_id is registered with the bank. // Once an entry has been recorded, its last_id is registered with the bank.
let poh_service = PohService::new(poh_recorder.clone(), config); let poh_service = PohService::new(poh_recorder.clone(), config);
// Single thread to compute finality // Single thread to compute confirmation
let compute_finality_service = ComputeLeaderFinalityService::new( let compute_confirmation_service = ComputeLeaderConfirmationService::new(
bank.clone(), bank.clone(),
leader_id, leader_id,
poh_service.poh_exit.clone(), poh_service.poh_exit.clone(),
@ -120,7 +120,7 @@ impl BankingStage {
Self { Self {
bank_thread_hdls, bank_thread_hdls,
poh_service, poh_service,
compute_finality_service, compute_confirmation_service,
}, },
entry_receiver, entry_receiver,
) )
@ -239,7 +239,7 @@ impl Service for BankingStage {
} }
} }
self.compute_finality_service.join()?; self.compute_confirmation_service.join()?;
let poh_return_value = self.poh_service.join()?; let poh_return_value = self.poh_service.join()?;
match poh_return_value { match poh_return_value {

View File

@ -1,5 +1,5 @@
//! The `compute_leader_finality_service` module implements the tools necessary //! The `compute_leader_confirmation_service` module implements the tools necessary
//! to generate a thread which regularly calculates the last finality times //! to generate a thread which regularly calculates the last confirmation times
//! observed by the leader //! observed by the leader
use crate::bank::Bank; use crate::bank::Bank;
@ -17,23 +17,23 @@ use std::thread::{self, Builder, JoinHandle};
use std::time::Duration; use std::time::Duration;
#[derive(Debug, PartialEq, Eq)] #[derive(Debug, PartialEq, Eq)]
pub enum FinalityError { pub enum ConfirmationError {
NoValidSupermajority, NoValidSupermajority,
} }
pub const COMPUTE_FINALITY_MS: u64 = 100; pub const COMPUTE_CONFIRMATION_MS: u64 = 100;
pub struct ComputeLeaderFinalityService { pub struct ComputeLeaderConfirmationService {
compute_finality_thread: JoinHandle<()>, compute_confirmation_thread: JoinHandle<()>,
} }
impl ComputeLeaderFinalityService { impl ComputeLeaderConfirmationService {
fn get_last_supermajority_timestamp( fn get_last_supermajority_timestamp(
bank: &Arc<Bank>, bank: &Arc<Bank>,
leader_id: Pubkey, leader_id: Pubkey,
now: u64, now: u64,
last_valid_validator_timestamp: u64, last_valid_validator_timestamp: u64,
) -> result::Result<u64, FinalityError> { ) -> result::Result<u64, ConfirmationError> {
let mut total_stake = 0; let mut total_stake = 0;
let mut ticks_and_stakes: Vec<(u64, u64)> = { let mut ticks_and_stakes: Vec<(u64, u64)> = {
@ -72,14 +72,14 @@ impl ComputeLeaderFinalityService {
let super_majority_stake = (2 * total_stake) / 3; let super_majority_stake = (2 * total_stake) / 3;
if let Some(last_valid_validator_timestamp) = if let Some(last_valid_validator_timestamp) =
bank.get_finality_timestamp(&mut ticks_and_stakes, super_majority_stake) bank.get_confirmation_timestamp(&mut ticks_and_stakes, super_majority_stake)
{ {
return Ok(last_valid_validator_timestamp); return Ok(last_valid_validator_timestamp);
} }
if last_valid_validator_timestamp != 0 { if last_valid_validator_timestamp != 0 {
submit( submit(
influxdb::Point::new(&"leader-finality") influxdb::Point::new(&"leader-confirmation")
.add_field( .add_field(
"duration_ms", "duration_ms",
influxdb::Value::Integer((now - last_valid_validator_timestamp) as i64), influxdb::Value::Integer((now - last_valid_validator_timestamp) as i64),
@ -88,10 +88,10 @@ impl ComputeLeaderFinalityService {
); );
} }
Err(FinalityError::NoValidSupermajority) Err(ConfirmationError::NoValidSupermajority)
} }
pub fn compute_finality( pub fn compute_confirmation(
bank: &Arc<Bank>, bank: &Arc<Bank>,
leader_id: Pubkey, leader_id: Pubkey,
last_valid_validator_timestamp: &mut u64, last_valid_validator_timestamp: &mut u64,
@ -103,53 +103,60 @@ impl ComputeLeaderFinalityService {
now, now,
*last_valid_validator_timestamp, *last_valid_validator_timestamp,
) { ) {
let finality_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_finality((now - *last_valid_validator_timestamp) as usize); bank.set_confirmation((now - *last_valid_validator_timestamp) as usize);
submit( submit(
influxdb::Point::new(&"leader-finality") influxdb::Point::new(&"leader-confirmation")
.add_field("duration_ms", influxdb::Value::Integer(finality_ms as i64)) .add_field(
"duration_ms",
influxdb::Value::Integer(confirmation_ms as i64),
)
.to_owned(), .to_owned(),
); );
} }
} }
/// Create a new ComputeLeaderFinalityService for computing finality. /// Create a new ComputeLeaderConfirmationService for computing confirmation.
pub fn new(bank: Arc<Bank>, leader_id: Pubkey, exit: Arc<AtomicBool>) -> Self { pub fn new(bank: Arc<Bank>, leader_id: Pubkey, exit: Arc<AtomicBool>) -> Self {
let compute_finality_thread = Builder::new() let compute_confirmation_thread = Builder::new()
.name("solana-leader-finality-stage".to_string()) .name("solana-leader-confirmation-stage".to_string())
.spawn(move || { .spawn(move || {
let mut last_valid_validator_timestamp = 0; let mut last_valid_validator_timestamp = 0;
loop { loop {
if exit.load(Ordering::Relaxed) { if exit.load(Ordering::Relaxed) {
break; break;
} }
Self::compute_finality(&bank, leader_id, &mut last_valid_validator_timestamp); Self::compute_confirmation(
sleep(Duration::from_millis(COMPUTE_FINALITY_MS)); &bank,
leader_id,
&mut last_valid_validator_timestamp,
);
sleep(Duration::from_millis(COMPUTE_CONFIRMATION_MS));
} }
}) })
.unwrap(); .unwrap();
(ComputeLeaderFinalityService { (ComputeLeaderConfirmationService {
compute_finality_thread, compute_confirmation_thread,
}) })
} }
} }
impl Service for ComputeLeaderFinalityService { impl Service for ComputeLeaderConfirmationService {
type JoinReturnType = (); type JoinReturnType = ();
fn join(self) -> thread::Result<()> { fn join(self) -> thread::Result<()> {
self.compute_finality_thread.join() self.compute_confirmation_thread.join()
} }
} }
#[cfg(test)] #[cfg(test)]
pub mod tests { pub mod tests {
use crate::bank::Bank; use crate::bank::Bank;
use crate::compute_leader_finality_service::ComputeLeaderFinalityService; use crate::compute_leader_confirmation_service::ComputeLeaderConfirmationService;
use crate::create_vote_account::*; use crate::create_vote_account::*;
use crate::mint::Mint; use crate::mint::Mint;
@ -164,7 +171,7 @@ pub mod tests {
use std::time::Duration; use std::time::Duration;
#[test] #[test]
fn test_compute_finality() { fn test_compute_confirmation() {
solana_logger::setup(); solana_logger::setup();
let mint = Mint::new(1234); let mint = Mint::new(1234);
@ -206,14 +213,14 @@ pub mod tests {
}) })
.collect(); .collect();
// There isn't 2/3 consensus, so the bank's finality value should be the default // There isn't 2/3 consensus, so the bank's confirmation value should be the default
let mut last_finality_time = 0; let mut last_confirmation_time = 0;
ComputeLeaderFinalityService::compute_finality( ComputeLeaderConfirmationService::compute_confirmation(
&bank, &bank,
dummy_leader_id, dummy_leader_id,
&mut last_finality_time, &mut last_confirmation_time,
); );
assert_eq!(bank.finality(), std::usize::MAX); assert_eq!(bank.confirmation(), 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];
@ -221,12 +228,12 @@ pub mod tests {
let vote_tx = Transaction::vote_new(&vote_account, vote, ids[6], 0); let vote_tx = Transaction::vote_new(&vote_account, vote, ids[6], 0);
bank.process_transaction(&vote_tx).unwrap(); bank.process_transaction(&vote_tx).unwrap();
ComputeLeaderFinalityService::compute_finality( ComputeLeaderConfirmationService::compute_confirmation(
&bank, &bank,
dummy_leader_id, dummy_leader_id,
&mut last_finality_time, &mut last_confirmation_time,
); );
assert!(bank.finality() != std::usize::MAX); assert!(bank.confirmation() != std::usize::MAX);
assert!(last_finality_time > 0); assert!(last_confirmation_time > 0);
} }
} }

View File

@ -32,7 +32,7 @@ pub mod create_vote_account;
#[macro_use] #[macro_use]
pub mod contact_info; pub mod contact_info;
pub mod cluster_info; pub mod cluster_info;
pub mod compute_leader_finality_service; pub mod compute_leader_confirmation_service;
pub mod db_ledger; pub mod db_ledger;
pub mod db_window; pub mod db_window;
pub mod entry; pub mod entry;

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 = "getFinality")] #[rpc(meta, name = "getConfirmation")]
fn get_finality(&self, Self::Metadata) -> Result<usize>; fn get_confirmation(&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_finality(&self, meta: Self::Metadata) -> Result<usize> { fn get_confirmation(&self, meta: Self::Metadata) -> Result<usize> {
info!("get_finality rpc request received"); info!("get_confirmation rpc request received");
meta.request_processor.get_finality() meta.request_processor.get_confirmation()
} }
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_finality(&self) -> Result<usize> { fn get_confirmation(&self) -> Result<usize> {
Ok(self.bank.finality()) Ok(self.bank.confirmation())
} }
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();
@ -612,11 +612,11 @@ mod tests {
} }
#[test] #[test]
fn test_rpc_get_finality() { fn test_rpc_get_confirmation() {
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":"getFinality"}}"#); let req = format!(r#"{{"jsonrpc":"2.0","id":1,"method":"getConfirmation"}}"#);
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,
GetFinality, GetConfirmation,
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::GetFinality => "getFinality", RpcRequest::GetConfirmation => "getConfirmation",
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::GetFinality; let test_request = RpcRequest::GetConfirmation;
let request = test_request.build_request_json(1, None); let request = test_request.build_request_json(1, None);
assert_eq!(request["method"], "getFinality"); assert_eq!(request["method"], "getConfirmation");
assert_eq!(request["params"], json!(null)); assert_eq!(request["params"], json!(null));
let test_request = RpcRequest::GetLastId; let test_request = RpcRequest::GetLastId;

View File

@ -44,7 +44,7 @@ struct StatusEntry<T> {
/// when the id was registered, according to network time /// when the id was registered, according to network time
tick_height: u64, tick_height: u64,
/// timestamp when this id was registered, used for stats/finality /// timestamp when this id was registered, used for stats/confirmation
timestamp: u64, timestamp: u64,
/// a map of signature status, used for duplicate detection /// a map of signature status, used for duplicate detection
@ -183,8 +183,8 @@ impl<T: Clone> StatusDeque<T> {
} }
/// Looks through a list of tick heights and stakes, and finds the latest /// Looks through a list of tick heights and stakes, and finds the latest
/// tick that has achieved finality /// tick that has achieved confirmation
pub fn get_finality_timestamp( pub fn get_confirmation_timestamp(
&self, &self,
ticks_and_stakes: &mut [(u64, u64)], ticks_and_stakes: &mut [(u64, u64)],
supermajority_stake: u64, supermajority_stake: u64,

View File

@ -41,7 +41,7 @@ pub struct ThinClient {
transaction_count: u64, transaction_count: u64,
balances: HashMap<Pubkey, Account>, balances: HashMap<Pubkey, Account>,
signature_status: bool, signature_status: bool,
finality: Option<usize>, confirmation: Option<usize>,
rpc_client: RpcClient, rpc_client: RpcClient,
} }
@ -87,7 +87,7 @@ impl ThinClient {
transaction_count: 0, transaction_count: 0,
balances: HashMap::new(), balances: HashMap::new(),
signature_status: false, signature_status: false,
finality: None, confirmation: None,
} }
} }
@ -187,23 +187,23 @@ impl ThinClient {
.ok_or_else(|| io::Error::new(io::ErrorKind::Other, "AccountNotFound")) .ok_or_else(|| io::Error::new(io::ErrorKind::Other, "AccountNotFound"))
} }
/// Request the finality from the leader node /// Request the confirmation from the leader node
pub fn get_finality(&mut self) -> usize { pub fn get_confirmation(&mut self) -> usize {
trace!("get_finality"); trace!("get_confirmation");
let mut done = false; let mut done = false;
while !done { while !done {
debug!("get_finality send_to {}", &self.rpc_addr); debug!("get_confirmation send_to {}", &self.rpc_addr);
let resp = RpcRequest::GetFinality.make_rpc_request(&self.rpc_client, 1, None); let resp = RpcRequest::GetConfirmation.make_rpc_request(&self.rpc_client, 1, None);
if let Ok(value) = resp { if let Ok(value) = resp {
done = true; done = true;
let finality = value.as_u64().unwrap() as usize; let confirmation = value.as_u64().unwrap() as usize;
self.finality = Some(finality); self.confirmation = Some(confirmation);
} else { } else {
debug!("thin_client get_finality error: {:?}", resp); debug!("thin_client get_confirmation error: {:?}", resp);
} }
} }
self.finality.expect("some finality") self.confirmation.expect("some confirmation")
} }
/// Request the transaction count. If the response packet is dropped by the network, /// Request the transaction count. If the response packet is dropped by the network,
@ -477,8 +477,8 @@ 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 finality = client.get_finality(); let confirmation = client.get_confirmation();
assert_eq!(finality, 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
.transfer(500, &alice.keypair(), bob_pubkey, &last_id) .transfer(500, &alice.keypair(), bob_pubkey, &last_id)

View File

@ -714,8 +714,8 @@ 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_finality = client.get_finality(); let mut last_confirmation = client.get_confirmation();
info!("Last finality {}", last_finality); info!("Last confirmation {}", last_confirmation);
let start = Instant::now(); let start = Instant::now();
let mut consecutive_success = 0; let mut consecutive_success = 0;
let mut expected_balance = leader_balance; let mut expected_balance = leader_balance;
@ -738,28 +738,28 @@ 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 finality = client.get_finality(); let mut confirmation = client.get_confirmation();
// Need this to make sure the finality 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_finality == finality { while last_confirmation == confirmation {
finality = client.get_finality(); confirmation = client.get_confirmation();
} }
while duration_as_ms(&now.elapsed()) < finality as u64 { while duration_as_ms(&now.elapsed()) < confirmation as u64 {
sleep(Duration::from_millis(100)); sleep(Duration::from_millis(100));
finality = client.get_finality() confirmation = client.get_confirmation()
} }
last_finality = finality; last_confirmation = confirmation;
let balance = retry_get_balance(&mut client, &bob_pubkey, Some(expected_balance)); let balance = retry_get_balance(&mut client, &bob_pubkey, Some(expected_balance));
assert_eq!(balance, Some(expected_balance)); assert_eq!(balance, Some(expected_balance));
consecutive_success += 1; consecutive_success += 1;
info!( info!(
"SUCCESS[{}] balance: {}, finality: {} ms", "SUCCESS[{}] balance: {}, confirmation: {} ms",
i, expected_balance, last_finality, i, expected_balance, last_confirmation,
); );
if consecutive_success == 10 { if consecutive_success == 10 {