Surface the getVoteAccounts.epochCredits max-length constant in rpc-client-api

This commit is contained in:
Michael Vines 2022-09-26 16:28:29 -07:00
parent c893f92508
commit df5f9f698f
4 changed files with 16 additions and 12 deletions

View File

@ -3265,7 +3265,7 @@ each containing an array of JSON objects with the following sub fields:
- `epochVoteAccount: <bool>` - bool, whether the vote account is staked for this epoch - `epochVoteAccount: <bool>` - bool, whether the vote account is staked for this epoch
- `commission: <number>`, percentage (0-100) of rewards payout owed to the vote account - `commission: <number>`, percentage (0-100) of rewards payout owed to the vote account
- `lastVote: <u64>` - Most recent slot voted on by this vote account - `lastVote: <u64>` - Most recent slot voted on by this vote account
- `epochCredits: <array>` - History of how many credits earned by the end of each epoch, as an array of arrays containing: `[epoch, credits, previousCredits]` - `epochCredits: <array>` - Latest history of earned credits for up to five epochs, as an array of arrays containing: `[epoch, credits, previousCredits]`.
- `rootSlot: <u64>` - Current root slot for this vote account - `rootSlot: <u64>` - Current root slot for this vote account
#### Example: #### Example:

View File

@ -204,6 +204,10 @@ pub const NUM_LARGEST_ACCOUNTS: usize = 20;
pub const MAX_GET_PROGRAM_ACCOUNT_FILTERS: usize = 4; pub const MAX_GET_PROGRAM_ACCOUNT_FILTERS: usize = 4;
pub const MAX_GET_SLOT_LEADERS: usize = 5000; pub const MAX_GET_SLOT_LEADERS: usize = 5000;
// Limit the length of the `epoch_credits` array for each validator in a `get_vote_accounts`
// response
pub const MAX_RPC_VOTE_ACCOUNT_INFO_EPOCH_CREDITS_HISTORY: usize = 5;
// Validators that are this number of slots behind are considered delinquent // Validators that are this number of slots behind are considered delinquent
pub const DELINQUENT_VALIDATOR_SLOT_DISTANCE: u64 = 128; pub const DELINQUENT_VALIDATOR_SLOT_DISTANCE: u64 = 128;

View File

@ -374,7 +374,7 @@ pub struct RpcVoteAccountInfo {
/// Whether this account is staked for the current epoch /// Whether this account is staked for the current epoch
pub epoch_vote_account: bool, pub epoch_vote_account: bool,
/// History of how many credits earned by the end of each epoch /// Latest history of earned credits for up to `MAX_RPC_VOTE_ACCOUNT_INFO_EPOCH_CREDITS_HISTORY` epochs
/// each tuple is (Epoch, credits, prev_credits) /// each tuple is (Epoch, credits, prev_credits)
pub epoch_credits: Vec<(Epoch, u64, u64)>, pub epoch_credits: Vec<(Epoch, u64, u64)>,

View File

@ -35,7 +35,7 @@ use {
MAX_GET_CONFIRMED_BLOCKS_RANGE, MAX_GET_CONFIRMED_SIGNATURES_FOR_ADDRESS2_LIMIT, MAX_GET_CONFIRMED_BLOCKS_RANGE, MAX_GET_CONFIRMED_SIGNATURES_FOR_ADDRESS2_LIMIT,
MAX_GET_CONFIRMED_SIGNATURES_FOR_ADDRESS_SLOT_RANGE, MAX_GET_PROGRAM_ACCOUNT_FILTERS, MAX_GET_CONFIRMED_SIGNATURES_FOR_ADDRESS_SLOT_RANGE, MAX_GET_PROGRAM_ACCOUNT_FILTERS,
MAX_GET_SIGNATURE_STATUSES_QUERY_ITEMS, MAX_GET_SLOT_LEADERS, MAX_MULTIPLE_ACCOUNTS, MAX_GET_SIGNATURE_STATUSES_QUERY_ITEMS, MAX_GET_SLOT_LEADERS, MAX_MULTIPLE_ACCOUNTS,
NUM_LARGEST_ACCOUNTS, MAX_RPC_VOTE_ACCOUNT_INFO_EPOCH_CREDITS_HISTORY, NUM_LARGEST_ACCOUNTS,
}, },
response::{Response as RpcResponse, *}, response::{Response as RpcResponse, *},
}, },
@ -115,10 +115,6 @@ type RpcCustomResult<T> = std::result::Result<T, RpcCustomError>;
pub const MAX_REQUEST_BODY_SIZE: usize = 50 * (1 << 10); // 50kB pub const MAX_REQUEST_BODY_SIZE: usize = 50 * (1 << 10); // 50kB
pub const PERFORMANCE_SAMPLES_LIMIT: usize = 720; pub const PERFORMANCE_SAMPLES_LIMIT: usize = 720;
// Limit the length of the `epoch_credits` array for each validator in a `get_vote_accounts`
// response
const MAX_RPC_EPOCH_CREDITS_HISTORY: usize = 5;
fn new_response<T>(bank: &Bank, value: T) -> RpcResponse<T> { fn new_response<T>(bank: &Bank, value: T) -> RpcResponse<T> {
RpcResponse { RpcResponse {
context: RpcResponseContext::new(bank.slot()), context: RpcResponseContext::new(bank.slot()),
@ -958,10 +954,12 @@ impl JsonRpcRequestProcessor {
}; };
let epoch_credits = vote_state.epoch_credits(); let epoch_credits = vote_state.epoch_credits();
let epoch_credits = if epoch_credits.len() > MAX_RPC_EPOCH_CREDITS_HISTORY { let epoch_credits = if epoch_credits.len()
> MAX_RPC_VOTE_ACCOUNT_INFO_EPOCH_CREDITS_HISTORY
{
epoch_credits epoch_credits
.iter() .iter()
.skip(epoch_credits.len() - MAX_RPC_EPOCH_CREDITS_HISTORY) .skip(epoch_credits.len() - MAX_RPC_VOTE_ACCOUNT_INFO_EPOCH_CREDITS_HISTORY)
.cloned() .cloned()
.collect() .collect()
} else { } else {
@ -7241,9 +7239,11 @@ pub mod tests {
} }
} }
// Overflow the epoch credits history and ensure only `MAX_RPC_EPOCH_CREDITS_HISTORY` // Overflow the epoch credits history and ensure only `MAX_RPC_VOTE_ACCOUNT_INFO_EPOCH_CREDITS_HISTORY`
// results are returned // results are returned
for _ in 0..(TEST_SLOTS_PER_EPOCH * (MAX_RPC_EPOCH_CREDITS_HISTORY) as u64) { for _ in
0..(TEST_SLOTS_PER_EPOCH * (MAX_RPC_VOTE_ACCOUNT_INFO_EPOCH_CREDITS_HISTORY) as u64)
{
advance_bank(); advance_bank();
} }
@ -7263,7 +7263,7 @@ pub mod tests {
assert!(!vote_account_status assert!(!vote_account_status
.current .current
.iter() .iter()
.any(|x| x.epoch_credits.len() != MAX_RPC_EPOCH_CREDITS_HISTORY)); .any(|x| x.epoch_credits.len() != MAX_RPC_VOTE_ACCOUNT_INFO_EPOCH_CREDITS_HISTORY));
// Advance bank with no voting // Advance bank with no voting
rpc.advance_bank_to_confirmed_slot(bank.slot() + TEST_SLOTS_PER_EPOCH); rpc.advance_bank_to_confirmed_slot(bank.slot() + TEST_SLOTS_PER_EPOCH);