Improve error messages when a vote account is rejected for delegation (#5407)
This commit is contained in:
parent
eb3991b9ba
commit
6f269e5a0e
|
@ -602,7 +602,12 @@ fn process_delegate_stake(
|
||||||
|
|
||||||
// Sanity check the vote account to ensure it is attached to a validator that has recently
|
// Sanity check the vote account to ensure it is attached to a validator that has recently
|
||||||
// voted at the tip of the ledger
|
// 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(|_| {
|
let vote_state = VoteState::deserialize(&vote_account_data).map_err(|_| {
|
||||||
WalletError::RpcRequestError(
|
WalletError::RpcRequestError(
|
||||||
"Account data could not be deserialized to vote state".to_string(),
|
"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 {
|
let sanity_check_result = match vote_state.root_slot {
|
||||||
None => Err(WalletError::DynamicProgramError(
|
None => Err(WalletError::BadParameter(
|
||||||
"Vote account has no root slot".to_string(),
|
"Unable to delegate. Vote account has no root slot".to_string(),
|
||||||
)),
|
)),
|
||||||
Some(root_slot) => {
|
Some(root_slot) => {
|
||||||
let slot = rpc_client.get_slot()?;
|
let slot = rpc_client.get_slot()?;
|
||||||
if root_slot + solana_sdk::timing::DEFAULT_SLOTS_PER_TURN < slot {
|
if root_slot + solana_sdk::timing::DEFAULT_SLOTS_PER_TURN < slot {
|
||||||
Err(WalletError::DynamicProgramError(
|
Err(WalletError::BadParameter(
|
||||||
"Vote account root slot is too old".to_string(),
|
format!(
|
||||||
|
"Unable to delegate. Vote account root slot ({}) is too old, the current slot is {}", root_slot, slot
|
||||||
|
)
|
||||||
))
|
))
|
||||||
} else {
|
} else {
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
Loading…
Reference in New Issue