rpc: more params for `GetVoteAccountsConfig`

This commit is contained in:
Trent Nelson 2021-07-02 23:51:41 -06:00 committed by mergify[bot]
parent 8eda152d33
commit bf90ea282a
3 changed files with 21 additions and 8 deletions

View File

@ -81,6 +81,8 @@ pub struct RpcGetVoteAccountsConfig {
pub vote_pubkey: Option<String>, // validator vote address, as a base-58 encoded string
#[serde(flatten)]
pub commitment: Option<CommitmentConfig>,
pub keep_unstaked_delinquents: Option<bool>,
pub delinquent_slot_distance: Option<u64>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]

View File

@ -3028,6 +3028,8 @@ Returns the account info and associated stake for all the voting accounts in the
- `<object>` - (optional) Configuration object containing the following field:
- (optional) [Commitment](jsonrpc-api.md#configuring-state-commitment)
- (optional) `votePubkey: <string>` - Only return results for this validator vote address (base-58 encoded)
- (optional) `keepUnstakedDelinquents: <bool>` - Do not filter out delinquent validators with no stake
- (optional) `delinquentSlotDistance: <u64>` - 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:

View File

@ -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<RpcVoteAccountInfo>,
Vec<RpcVoteAccountInfo>,
@ -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::<Vec<_>>();
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::<Vec<_>>()
} 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()
}])
);