From bf90ea282ac7b442b669f97c2bb1e222a141f027 Mon Sep 17 00:00:00 2001 From: Trent Nelson Date: Fri, 2 Jul 2021 23:51:41 -0600 Subject: [PATCH] rpc: more params for `GetVoteAccountsConfig` --- client/src/rpc_config.rs | 2 ++ docs/src/developing/clients/jsonrpc-api.md | 2 ++ rpc/src/rpc.rs | 25 +++++++++++++++------- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/client/src/rpc_config.rs b/client/src/rpc_config.rs index 5597384e30..9d236794e1 100644 --- a/client/src/rpc_config.rs +++ b/client/src/rpc_config.rs @@ -81,6 +81,8 @@ pub struct RpcGetVoteAccountsConfig { pub vote_pubkey: Option, // validator vote address, as a base-58 encoded string #[serde(flatten)] pub commitment: Option, + pub keep_unstaked_delinquents: Option, + pub delinquent_slot_distance: Option, } #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] diff --git a/docs/src/developing/clients/jsonrpc-api.md b/docs/src/developing/clients/jsonrpc-api.md index 1ee7d5ebe6..aebdfb8570 100644 --- a/docs/src/developing/clients/jsonrpc-api.md +++ b/docs/src/developing/clients/jsonrpc-api.md @@ -3028,6 +3028,8 @@ Returns the account info and associated stake for all the voting accounts in the - `` - (optional) Configuration object containing the following field: - (optional) [Commitment](jsonrpc-api.md#configuring-state-commitment) - (optional) `votePubkey: ` - Only return results for this validator vote address (base-58 encoded) + - (optional) `keepUnstakedDelinquents: ` - Do not filter out delinquent validators with no stake + - (optional) `delinquentSlotDistance: ` - Specify the number of slots behind the tip that a validator must fall to be considered delinquent. **NOTE:** For the sake of consistency between ecosystem products, _it is **not** recommended that this argument be specified._ #### Results: diff --git a/rpc/src/rpc.rs b/rpc/src/rpc.rs index 33c1e2904a..103891b7d5 100644 --- a/rpc/src/rpc.rs +++ b/rpc/src/rpc.rs @@ -794,6 +794,9 @@ impl JsonRpcRequestProcessor { .epoch_vote_accounts(bank.get_epoch_and_slot_index(bank.slot()).0) .ok_or_else(Error::invalid_request)?; let default_vote_state = VoteState::default(); + let delinquent_validator_slot_distance = config + .delinquent_slot_distance + .unwrap_or(DELINQUENT_VALIDATOR_SLOT_DISTANCE); let (current_vote_accounts, delinquent_vote_accounts): ( Vec, Vec, @@ -837,22 +840,27 @@ impl JsonRpcRequestProcessor { }) }) .partition(|vote_account_info| { - if bank.slot() >= DELINQUENT_VALIDATOR_SLOT_DISTANCE as u64 { + if bank.slot() >= delinquent_validator_slot_distance as u64 { vote_account_info.last_vote - > bank.slot() - DELINQUENT_VALIDATOR_SLOT_DISTANCE as u64 + > bank.slot() - delinquent_validator_slot_distance as u64 } else { vote_account_info.last_vote > 0 } }); - let delinquent_staked_vote_accounts = delinquent_vote_accounts - .into_iter() - .filter(|vote_account_info| vote_account_info.activated_stake > 0) - .collect::>(); + let keep_unstaked_delinquents = config.keep_unstaked_delinquents.unwrap_or_default(); + let delinquent_vote_accounts = if !keep_unstaked_delinquents { + delinquent_vote_accounts + .into_iter() + .filter(|vote_account_info| vote_account_info.activated_stake > 0) + .collect::>() + } else { + delinquent_vote_accounts + }; Ok(RpcVoteAccountStatus { current: current_vote_accounts, - delinquent: delinquent_staked_vote_accounts, + delinquent: delinquent_vote_accounts, }) } @@ -6621,7 +6629,8 @@ pub mod tests { r#"{{"jsonrpc":"2.0","id":1,"method":"getVoteAccounts","params":{}}}"#, json!([RpcGetVoteAccountsConfig { vote_pubkey: Some(leader_vote_keypair.pubkey().to_string()), - commitment: Some(CommitmentConfig::processed()) + commitment: Some(CommitmentConfig::processed()), + ..RpcGetVoteAccountsConfig::default() }]) );