RPC: add caching to getLargestAccounts (#15154) (#15271)

* introduce get largest accounts cache

* remove cache size and change hash key

* remove eq and hash derivation from commitment config

* add slot to the cache

(cherry picked from commit 4013f91dbe)

Co-authored-by: Josh <josh.hundley@gmail.com>
This commit is contained in:
mergify[bot]
2021-02-11 21:13:09 +00:00
committed by GitHub
parent 067871cc39
commit 03ac807756
5 changed files with 138 additions and 16 deletions

View File

@@ -16,6 +16,7 @@ use jsonrpc_http_server::{
RequestMiddlewareAction, ServerBuilder,
};
use regex::Regex;
use solana_client::rpc_cache::LargestAccountsCache;
use solana_ledger::blockstore::Blockstore;
use solana_metrics::inc_new_counter_info;
use solana_runtime::{
@@ -34,6 +35,8 @@ use std::{
};
use tokio::runtime;
const LARGEST_ACCOUNTS_CACHE_DURATION: u64 = 60 * 60 * 2;
pub struct JsonRpcService {
thread_hdl: JoinHandle<()>,
@@ -282,6 +285,10 @@ impl JsonRpcService {
override_health_check,
));
let largest_accounts_cache = Arc::new(RwLock::new(LargestAccountsCache::new(
LARGEST_ACCOUNTS_CACHE_DURATION,
)));
let tpu_address = cluster_info.my_contact_info().tpu;
let mut runtime = runtime::Builder::new()
.threaded_scheduler()
@@ -341,6 +348,7 @@ impl JsonRpcService {
&runtime,
bigtable_ledger_storage,
optimistically_confirmed_bank,
largest_accounts_cache,
);
let leader_info =