Improve error messages when a vote account is rejected for delegation (#5407)

This commit is contained in:
Michael Vines 2019-08-02 10:09:09 -07:00 committed by GitHub
parent eb3991b9ba
commit 6f269e5a0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 5 deletions

View File

@ -602,7 +602,12 @@ fn process_delegate_stake(
// Sanity check the vote account to ensure it is attached to a validator that has recently
// voted at the tip of the ledger
let vote_account_data = rpc_client.get_account_data(vote_account_pubkey)?;
let vote_account_data = rpc_client
.get_account_data(vote_account_pubkey)
.map_err(|_| {
WalletError::RpcRequestError(format!("Vote account not found: {}", vote_account_pubkey))
})?;
let vote_state = VoteState::deserialize(&vote_account_data).map_err(|_| {
WalletError::RpcRequestError(
"Account data could not be deserialized to vote state".to_string(),
@ -610,14 +615,16 @@ fn process_delegate_stake(
})?;
let sanity_check_result = match vote_state.root_slot {
None => Err(WalletError::DynamicProgramError(
"Vote account has no root slot".to_string(),
None => Err(WalletError::BadParameter(
"Unable to delegate. Vote account has no root slot".to_string(),
)),
Some(root_slot) => {
let slot = rpc_client.get_slot()?;
if root_slot + solana_sdk::timing::DEFAULT_SLOTS_PER_TURN < slot {
Err(WalletError::DynamicProgramError(
"Vote account root slot is too old".to_string(),
Err(WalletError::BadParameter(
format!(
"Unable to delegate. Vote account root slot ({}) is too old, the current slot is {}", root_slot, slot
)
))
} else {
Ok(())