Add max retransmit and shred insert slot (#15475)
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
use crate::{
|
||||
cluster_info::ClusterInfo,
|
||||
contact_info::ContactInfo,
|
||||
max_slots::MaxSlots,
|
||||
non_circulating_supply::calculate_non_circulating_supply,
|
||||
optimistically_confirmed_bank_tracker::OptimisticallyConfirmedBank,
|
||||
rpc_health::*,
|
||||
@@ -138,6 +139,7 @@ pub struct JsonRpcRequestProcessor {
|
||||
bigtable_ledger_storage: Option<solana_storage_bigtable::LedgerStorage>,
|
||||
optimistically_confirmed_bank: Arc<RwLock<OptimisticallyConfirmedBank>>,
|
||||
largest_accounts_cache: Arc<RwLock<LargestAccountsCache>>,
|
||||
max_slots: Arc<MaxSlots>,
|
||||
}
|
||||
impl Metadata for JsonRpcRequestProcessor {}
|
||||
|
||||
@@ -221,6 +223,7 @@ impl JsonRpcRequestProcessor {
|
||||
bigtable_ledger_storage: Option<solana_storage_bigtable::LedgerStorage>,
|
||||
optimistically_confirmed_bank: Arc<RwLock<OptimisticallyConfirmedBank>>,
|
||||
largest_accounts_cache: Arc<RwLock<LargestAccountsCache>>,
|
||||
max_slots: Arc<MaxSlots>,
|
||||
) -> (Self, Receiver<TransactionInfo>) {
|
||||
let (sender, receiver) = channel();
|
||||
(
|
||||
@@ -239,6 +242,7 @@ impl JsonRpcRequestProcessor {
|
||||
bigtable_ledger_storage,
|
||||
optimistically_confirmed_bank,
|
||||
largest_accounts_cache,
|
||||
max_slots,
|
||||
},
|
||||
receiver,
|
||||
)
|
||||
@@ -279,6 +283,7 @@ impl JsonRpcRequestProcessor {
|
||||
bank: bank.clone(),
|
||||
})),
|
||||
largest_accounts_cache: Arc::new(RwLock::new(LargestAccountsCache::new(30))),
|
||||
max_slots: Arc::new(MaxSlots::default()),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -485,6 +490,14 @@ impl JsonRpcRequestProcessor {
|
||||
self.bank(commitment).slot()
|
||||
}
|
||||
|
||||
fn get_max_retransmit_slot(&self) -> Slot {
|
||||
self.max_slots.retransmit.load(Ordering::Relaxed)
|
||||
}
|
||||
|
||||
fn get_max_shred_insert_slot(&self) -> Slot {
|
||||
self.max_slots.shred_insert.load(Ordering::Relaxed)
|
||||
}
|
||||
|
||||
fn get_slot_leader(&self, commitment: Option<CommitmentConfig>) -> String {
|
||||
self.bank(commitment).collector_id().to_string()
|
||||
}
|
||||
@@ -1915,6 +1928,12 @@ pub trait RpcSol {
|
||||
#[rpc(meta, name = "getSlot")]
|
||||
fn get_slot(&self, meta: Self::Metadata, commitment: Option<CommitmentConfig>) -> Result<Slot>;
|
||||
|
||||
#[rpc(meta, name = "getMaxRetransmitSlot")]
|
||||
fn get_max_retransmit_slot(&self, meta: Self::Metadata) -> Result<Slot>;
|
||||
|
||||
#[rpc(meta, name = "getMaxShredInsertSlot")]
|
||||
fn get_max_shred_insert_slot(&self, meta: Self::Metadata) -> Result<Slot>;
|
||||
|
||||
#[rpc(meta, name = "getTransactionCount")]
|
||||
fn get_transaction_count(
|
||||
&self,
|
||||
@@ -2505,6 +2524,16 @@ impl RpcSol for RpcSolImpl {
|
||||
Ok(meta.get_slot(commitment))
|
||||
}
|
||||
|
||||
fn get_max_retransmit_slot(&self, meta: Self::Metadata) -> Result<Slot> {
|
||||
debug!("get_max_retransmit_slot rpc request received");
|
||||
Ok(meta.get_max_retransmit_slot())
|
||||
}
|
||||
|
||||
fn get_max_shred_insert_slot(&self, meta: Self::Metadata) -> Result<Slot> {
|
||||
debug!("get_max_shred_insert_slot rpc request received");
|
||||
Ok(meta.get_max_shred_insert_slot())
|
||||
}
|
||||
|
||||
fn get_transaction_count(
|
||||
&self,
|
||||
meta: Self::Metadata,
|
||||
@@ -3206,6 +3235,10 @@ pub mod tests {
|
||||
.write_perf_sample(0, &sample1)
|
||||
.expect("write to blockstore");
|
||||
|
||||
let max_slots = Arc::new(MaxSlots::default());
|
||||
max_slots.retransmit.store(42, Ordering::Relaxed);
|
||||
max_slots.shred_insert.store(43, Ordering::Relaxed);
|
||||
|
||||
let (meta, receiver) = JsonRpcRequestProcessor::new(
|
||||
JsonRpcConfig {
|
||||
enable_rpc_transaction_history: true,
|
||||
@@ -3224,6 +3257,7 @@ pub mod tests {
|
||||
None,
|
||||
OptimisticallyConfirmedBank::locked_from_bank_forks_root(&bank_forks),
|
||||
Arc::new(RwLock::new(LargestAccountsCache::new(30))),
|
||||
max_slots,
|
||||
);
|
||||
SendTransactionService::new(tpu_address, &bank_forks, None, receiver, 1000, 1);
|
||||
|
||||
@@ -4634,6 +4668,7 @@ pub mod tests {
|
||||
None,
|
||||
OptimisticallyConfirmedBank::locked_from_bank_forks_root(&bank_forks),
|
||||
Arc::new(RwLock::new(LargestAccountsCache::new(30))),
|
||||
Arc::new(MaxSlots::default()),
|
||||
);
|
||||
SendTransactionService::new(tpu_address, &bank_forks, None, receiver, 1000, 1);
|
||||
|
||||
@@ -4831,6 +4866,7 @@ pub mod tests {
|
||||
None,
|
||||
OptimisticallyConfirmedBank::locked_from_bank_forks_root(&bank_forks),
|
||||
Arc::new(RwLock::new(LargestAccountsCache::new(30))),
|
||||
Arc::new(MaxSlots::default()),
|
||||
);
|
||||
SendTransactionService::new(tpu_address, &bank_forks, None, receiver, 1000, 1);
|
||||
assert_eq!(request_processor.validator_exit(), false);
|
||||
@@ -4865,6 +4901,7 @@ pub mod tests {
|
||||
None,
|
||||
OptimisticallyConfirmedBank::locked_from_bank_forks_root(&bank_forks),
|
||||
Arc::new(RwLock::new(LargestAccountsCache::new(30))),
|
||||
Arc::new(MaxSlots::default()),
|
||||
);
|
||||
SendTransactionService::new(tpu_address, &bank_forks, None, receiver, 1000, 1);
|
||||
assert_eq!(request_processor.validator_exit(), true);
|
||||
@@ -4892,6 +4929,24 @@ pub mod tests {
|
||||
assert_eq!(expected, result);
|
||||
}
|
||||
|
||||
fn test_basic_slot(method: &str, expected: Slot) {
|
||||
let bob_pubkey = solana_sdk::pubkey::new_rand();
|
||||
let RpcHandler { io, meta, .. } = start_rpc_handler_with_tx(&bob_pubkey);
|
||||
|
||||
let req = format!("{{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"{}\"}}", method);
|
||||
let res = io.handle_request_sync(&req, meta);
|
||||
|
||||
let json: Value = serde_json::from_str(&res.unwrap()).unwrap();
|
||||
let slot: Slot = serde_json::from_value(json["result"].clone()).unwrap();
|
||||
assert_eq!(slot, expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_rpc_get_max_slots() {
|
||||
test_basic_slot("getMaxRetransmitSlot", 42);
|
||||
test_basic_slot("getMaxShredInsertSlot", 43);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_rpc_get_version() {
|
||||
let bob_pubkey = solana_sdk::pubkey::new_rand();
|
||||
@@ -4958,6 +5013,7 @@ pub mod tests {
|
||||
None,
|
||||
OptimisticallyConfirmedBank::locked_from_bank_forks_root(&bank_forks),
|
||||
Arc::new(RwLock::new(LargestAccountsCache::new(30))),
|
||||
Arc::new(MaxSlots::default()),
|
||||
);
|
||||
SendTransactionService::new(tpu_address, &bank_forks, None, receiver, 1000, 1);
|
||||
assert_eq!(
|
||||
@@ -6188,6 +6244,7 @@ pub mod tests {
|
||||
None,
|
||||
optimistically_confirmed_bank.clone(),
|
||||
Arc::new(RwLock::new(LargestAccountsCache::new(30))),
|
||||
Arc::new(MaxSlots::default()),
|
||||
);
|
||||
|
||||
let mut io = MetaIoHandler::default();
|
||||
|
Reference in New Issue
Block a user