Boot unused confirmation-time from Bank
This broken metric is already submitted to influx. Why make it available via RPC too? If so, why store it in the bank and not in the RPC service?
This commit is contained in:
parent
4467d5eb4c
commit
7981865fd2
22
src/bank.rs
22
src/bank.rs
|
@ -35,7 +35,6 @@ use solana_sdk::transaction::Transaction;
|
||||||
use solana_sdk::vote_program;
|
use solana_sdk::vote_program;
|
||||||
use std;
|
use std;
|
||||||
use std::result;
|
use std::result;
|
||||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
|
||||||
use std::sync::{Arc, RwLock};
|
use std::sync::{Arc, RwLock};
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
|
|
||||||
|
@ -102,9 +101,6 @@ pub struct Bank {
|
||||||
/// FIFO queue of `last_id` items
|
/// FIFO queue of `last_id` items
|
||||||
last_id_queue: RwLock<LastIdQueue>,
|
last_id_queue: RwLock<LastIdQueue>,
|
||||||
|
|
||||||
// The latest confirmation time for the network
|
|
||||||
confirmation_time: AtomicUsize,
|
|
||||||
|
|
||||||
/// Tracks and updates the leader schedule based on the votes and account stakes
|
/// Tracks and updates the leader schedule based on the votes and account stakes
|
||||||
/// processed by the bank
|
/// processed by the bank
|
||||||
pub leader_scheduler: Arc<RwLock<LeaderScheduler>>,
|
pub leader_scheduler: Arc<RwLock<LeaderScheduler>>,
|
||||||
|
@ -118,7 +114,6 @@ impl Default for Bank {
|
||||||
accounts: Accounts::default(),
|
accounts: Accounts::default(),
|
||||||
last_id_queue: RwLock::new(LastIdQueue::default()),
|
last_id_queue: RwLock::new(LastIdQueue::default()),
|
||||||
status_cache: RwLock::new(BankStatusCache::default()),
|
status_cache: RwLock::new(BankStatusCache::default()),
|
||||||
confirmation_time: AtomicUsize::new(std::usize::MAX),
|
|
||||||
leader_scheduler: Arc::new(RwLock::new(LeaderScheduler::default())),
|
leader_scheduler: Arc::new(RwLock::new(LeaderScheduler::default())),
|
||||||
subscriptions: RwLock::new(None),
|
subscriptions: RwLock::new(None),
|
||||||
}
|
}
|
||||||
|
@ -154,7 +149,6 @@ impl Bank {
|
||||||
accounts: self.accounts.copy_for_tpu(),
|
accounts: self.accounts.copy_for_tpu(),
|
||||||
status_cache: RwLock::new(status_cache),
|
status_cache: RwLock::new(status_cache),
|
||||||
last_id_queue: RwLock::new(self.last_id_queue.read().unwrap().clone()),
|
last_id_queue: RwLock::new(self.last_id_queue.read().unwrap().clone()),
|
||||||
confirmation_time: AtomicUsize::new(self.confirmation_time()),
|
|
||||||
leader_scheduler: self.leader_scheduler.clone(),
|
leader_scheduler: self.leader_scheduler.clone(),
|
||||||
subscriptions: RwLock::new(None),
|
subscriptions: RwLock::new(None),
|
||||||
}
|
}
|
||||||
|
@ -792,15 +786,6 @@ impl Bank {
|
||||||
self.accounts.hash_internal_state()
|
self.accounts.hash_internal_state()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn confirmation_time(&self) -> usize {
|
|
||||||
self.confirmation_time.load(Ordering::Relaxed)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_confirmation_time(&self, confirmation: usize) {
|
|
||||||
self.confirmation_time
|
|
||||||
.store(confirmation, Ordering::Relaxed);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn send_account_notifications(
|
fn send_account_notifications(
|
||||||
&self,
|
&self,
|
||||||
txs: &[Transaction],
|
txs: &[Transaction],
|
||||||
|
@ -1208,13 +1193,6 @@ 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_time() {
|
|
||||||
let def_bank = Bank::default();
|
|
||||||
assert_eq!(def_bank.confirmation_time(), std::usize::MAX);
|
|
||||||
def_bank.set_confirmation_time(90);
|
|
||||||
assert_eq!(def_bank.confirmation_time(), 90);
|
|
||||||
}
|
|
||||||
#[test]
|
|
||||||
fn test_interleaving_locks() {
|
fn test_interleaving_locks() {
|
||||||
let (genesis_block, mint_keypair) = GenesisBlock::new(3);
|
let (genesis_block, mint_keypair) = GenesisBlock::new(3);
|
||||||
let bank = Bank::new(&genesis_block);
|
let bank = Bank::new(&genesis_block);
|
||||||
|
|
|
@ -105,7 +105,6 @@ 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_time(confirmation_ms as usize);
|
|
||||||
|
|
||||||
submit(
|
submit(
|
||||||
influxdb::Point::new(&"leader-confirmation")
|
influxdb::Point::new(&"leader-confirmation")
|
||||||
|
@ -215,7 +214,6 @@ pub mod tests {
|
||||||
genesis_block.bootstrap_leader_id,
|
genesis_block.bootstrap_leader_id,
|
||||||
&mut last_confirmation_time,
|
&mut last_confirmation_time,
|
||||||
);
|
);
|
||||||
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 voting_keypair = &vote_accounts[7].0;
|
let voting_keypair = &vote_accounts[7].0;
|
||||||
|
@ -227,7 +225,6 @@ pub mod tests {
|
||||||
genesis_block.bootstrap_leader_id,
|
genesis_block.bootstrap_leader_id,
|
||||||
&mut last_confirmation_time,
|
&mut last_confirmation_time,
|
||||||
);
|
);
|
||||||
assert!(bank.confirmation_time() != std::usize::MAX);
|
|
||||||
assert!(last_confirmation_time > 0);
|
assert!(last_confirmation_time > 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
28
src/rpc.rs
28
src/rpc.rs
|
@ -155,9 +155,6 @@ pub trait RpcSol {
|
||||||
#[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 = "getConfirmationTime")]
|
|
||||||
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>;
|
||||||
|
|
||||||
|
@ -210,13 +207,6 @@ impl RpcSol for RpcSolImpl {
|
||||||
let pubkey = verify_pubkey(id)?;
|
let pubkey = verify_pubkey(id)?;
|
||||||
meta.request_processor.read().unwrap().get_balance(pubkey)
|
meta.request_processor.read().unwrap().get_balance(pubkey)
|
||||||
}
|
}
|
||||||
fn get_confirmation_time(&self, meta: Self::Metadata) -> Result<usize> {
|
|
||||||
info!("get_confirmation_time rpc request received");
|
|
||||||
meta.request_processor
|
|
||||||
.read()
|
|
||||||
.unwrap()
|
|
||||||
.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");
|
||||||
meta.request_processor.read().unwrap().get_last_id()
|
meta.request_processor.read().unwrap().get_last_id()
|
||||||
|
@ -378,9 +368,6 @@ impl JsonRpcRequestProcessor {
|
||||||
let val = self.bank.get_balance(&pubkey);
|
let val = self.bank.get_balance(&pubkey);
|
||||||
Ok(val)
|
Ok(val)
|
||||||
}
|
}
|
||||||
fn get_confirmation_time(&self) -> Result<usize> {
|
|
||||||
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();
|
||||||
Ok(bs58::encode(id).into_string())
|
Ok(bs58::encode(id).into_string())
|
||||||
|
@ -662,21 +649,6 @@ mod tests {
|
||||||
assert_eq!(expected, result);
|
assert_eq!(expected, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_rpc_get_confirmation() {
|
|
||||||
let bob_pubkey = Keypair::new().pubkey();
|
|
||||||
let (io, meta, _last_id, _alice) = start_rpc_handler_with_tx(bob_pubkey);
|
|
||||||
|
|
||||||
let req = format!(r#"{{"jsonrpc":"2.0","id":1,"method":"getConfirmationTime"}}"#);
|
|
||||||
let res = io.handle_request_sync(&req, meta);
|
|
||||||
let expected = format!(r#"{{"jsonrpc":"2.0","result":18446744073709551615,"id":1}}"#);
|
|
||||||
let expected: Response =
|
|
||||||
serde_json::from_str(&expected).expect("expected response deserialization");
|
|
||||||
let result: Response = serde_json::from_str(&res.expect("actual response"))
|
|
||||||
.expect("actual response deserialization");
|
|
||||||
assert_eq!(expected, result);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_rpc_get_last_id() {
|
fn test_rpc_get_last_id() {
|
||||||
let bob_pubkey = Keypair::new().pubkey();
|
let bob_pubkey = Keypair::new().pubkey();
|
||||||
|
|
|
@ -193,28 +193,6 @@ impl ThinClient {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Request the confirmation time from the leader node
|
|
||||||
pub fn get_confirmation_time(&mut self) -> usize {
|
|
||||||
trace!("get_confirmation_time");
|
|
||||||
loop {
|
|
||||||
debug!("get_confirmation_time send_to {}", &self.rpc_addr);
|
|
||||||
|
|
||||||
let response =
|
|
||||||
self.rpc_client
|
|
||||||
.make_rpc_request(1, RpcRequest::GetConfirmationTime, None);
|
|
||||||
|
|
||||||
match response {
|
|
||||||
Ok(value) => {
|
|
||||||
let confirmation = value.as_u64().unwrap() as usize;
|
|
||||||
return confirmation;
|
|
||||||
}
|
|
||||||
Err(error) => {
|
|
||||||
debug!("thin_client get_confirmation_time error: {:?}", error);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 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,
|
||||||
/// this method will try again 5 times.
|
/// this method will try again 5 times.
|
||||||
pub fn transaction_count(&mut self) -> u64 {
|
pub fn transaction_count(&mut self) -> u64 {
|
||||||
|
@ -531,9 +509,6 @@ mod tests {
|
||||||
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_time();
|
|
||||||
assert_eq!(confirmation, 18446744073709551615);
|
|
||||||
|
|
||||||
let last_id = client.get_last_id();
|
let last_id = client.get_last_id();
|
||||||
info!("test_thin_client last_id: {:?}", last_id);
|
info!("test_thin_client last_id: {:?}", last_id);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue