Clean up delinquency slot distance computation
This commit is contained in:
parent
d59fd7d512
commit
8e2745c2a2
|
@ -12,7 +12,7 @@ use crate::{
|
||||||
};
|
};
|
||||||
use clap::{App, Arg, ArgGroup, ArgMatches, SubCommand};
|
use clap::{App, Arg, ArgGroup, ArgMatches, SubCommand};
|
||||||
use solana_clap_utils::{input_parsers::*, input_validators::*, offline::*, ArgConstant};
|
use solana_clap_utils::{input_parsers::*, input_validators::*, offline::*, ArgConstant};
|
||||||
use solana_client::rpc_client::RpcClient;
|
use solana_client::{rpc_client::RpcClient, rpc_request::DELINQUENT_VALIDATOR_SLOT_DISTANCE};
|
||||||
use solana_remote_wallet::remote_wallet::RemoteWalletManager;
|
use solana_remote_wallet::remote_wallet::RemoteWalletManager;
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
account_utils::StateMut,
|
account_utils::StateMut,
|
||||||
|
@ -1461,13 +1461,15 @@ pub fn process_delegate_stake(
|
||||||
"Unable to delegate. 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 min_root_slot = rpc_client
|
||||||
if root_slot + solana_sdk::clock::DEFAULT_SLOTS_PER_TURN < slot {
|
.get_slot()?
|
||||||
Err(CliError::BadParameter(
|
.saturating_sub(DELINQUENT_VALIDATOR_SLOT_DISTANCE);
|
||||||
format!(
|
if root_slot < min_root_slot {
|
||||||
"Unable to delegate. Vote account root slot ({}) is too old, the current slot is {}", root_slot, slot
|
Err(CliError::DynamicProgramError(format!(
|
||||||
)
|
"Unable to delegate. Vote account appears delinquent \
|
||||||
))
|
because its current root slot, {}, is less than {}",
|
||||||
|
root_slot, min_root_slot
|
||||||
|
)))
|
||||||
} else {
|
} else {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -103,6 +103,9 @@ pub const NUM_LARGEST_ACCOUNTS: usize = 20;
|
||||||
pub const MAX_GET_SIGNATURE_STATUSES_QUERY_ITEMS: usize = 256;
|
pub const MAX_GET_SIGNATURE_STATUSES_QUERY_ITEMS: usize = 256;
|
||||||
pub const MAX_GET_CONFIRMED_SIGNATURES_FOR_ADDRESS_SLOT_RANGE: u64 = 10_000;
|
pub const MAX_GET_CONFIRMED_SIGNATURES_FOR_ADDRESS_SLOT_RANGE: u64 = 10_000;
|
||||||
|
|
||||||
|
// Validators that are this number of slots behind are considered delinquent
|
||||||
|
pub const DELINQUENT_VALIDATOR_SLOT_DISTANCE: u64 = 128;
|
||||||
|
|
||||||
impl RpcRequest {
|
impl RpcRequest {
|
||||||
pub(crate) fn build_request_json(self, id: u64, params: Value) -> Value {
|
pub(crate) fn build_request_json(self, id: u64, params: Value) -> Value {
|
||||||
let jsonrpc = "2.0";
|
let jsonrpc = "2.0";
|
||||||
|
|
|
@ -16,7 +16,7 @@ use jsonrpc_derive::rpc;
|
||||||
use solana_client::{
|
use solana_client::{
|
||||||
rpc_config::*,
|
rpc_config::*,
|
||||||
rpc_request::{
|
rpc_request::{
|
||||||
MAX_GET_CONFIRMED_SIGNATURES_FOR_ADDRESS_SLOT_RANGE,
|
DELINQUENT_VALIDATOR_SLOT_DISTANCE, MAX_GET_CONFIRMED_SIGNATURES_FOR_ADDRESS_SLOT_RANGE,
|
||||||
MAX_GET_SIGNATURE_STATUSES_QUERY_ITEMS, NUM_LARGEST_ACCOUNTS,
|
MAX_GET_SIGNATURE_STATUSES_QUERY_ITEMS, NUM_LARGEST_ACCOUNTS,
|
||||||
},
|
},
|
||||||
rpc_response::*,
|
rpc_response::*,
|
||||||
|
@ -420,8 +420,9 @@ impl JsonRpcRequestProcessor {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.partition(|vote_account_info| {
|
.partition(|vote_account_info| {
|
||||||
if bank.slot() >= MAX_LOCKOUT_HISTORY as u64 {
|
if bank.slot() >= DELINQUENT_VALIDATOR_SLOT_DISTANCE as u64 {
|
||||||
vote_account_info.last_vote > bank.slot() - MAX_LOCKOUT_HISTORY as u64
|
vote_account_info.last_vote
|
||||||
|
> bank.slot() - DELINQUENT_VALIDATOR_SLOT_DISTANCE as u64
|
||||||
} else {
|
} else {
|
||||||
vote_account_info.last_vote > 0
|
vote_account_info.last_vote > 0
|
||||||
}
|
}
|
||||||
|
@ -1588,7 +1589,7 @@ pub mod tests {
|
||||||
};
|
};
|
||||||
|
|
||||||
const TEST_MINT_LAMPORTS: u64 = 1_000_000;
|
const TEST_MINT_LAMPORTS: u64 = 1_000_000;
|
||||||
const TEST_SLOTS_PER_EPOCH: u64 = 50;
|
const TEST_SLOTS_PER_EPOCH: u64 = DELINQUENT_VALIDATOR_SLOT_DISTANCE + 1;
|
||||||
|
|
||||||
struct RpcHandler {
|
struct RpcHandler {
|
||||||
io: MetaIoHandler<JsonRpcRequestProcessor>,
|
io: MetaIoHandler<JsonRpcRequestProcessor>,
|
||||||
|
|
|
@ -22,9 +22,6 @@ pub const TICKS_PER_DAY: u64 = DEFAULT_TICKS_PER_SECOND * SECONDS_PER_DAY;
|
||||||
// 1 Epoch ~= 2 days
|
// 1 Epoch ~= 2 days
|
||||||
pub const DEFAULT_SLOTS_PER_EPOCH: u64 = 2 * TICKS_PER_DAY / DEFAULT_TICKS_PER_SLOT;
|
pub const DEFAULT_SLOTS_PER_EPOCH: u64 = 2 * TICKS_PER_DAY / DEFAULT_TICKS_PER_SLOT;
|
||||||
|
|
||||||
// 4 times longer than the max_lockout to allow enough time for PoRep (128 slots)
|
|
||||||
pub const DEFAULT_SLOTS_PER_TURN: u64 = 32 * 4;
|
|
||||||
|
|
||||||
// leader schedule is governed by this
|
// leader schedule is governed by this
|
||||||
pub const NUM_CONSECUTIVE_LEADER_SLOTS: u64 = 4;
|
pub const NUM_CONSECUTIVE_LEADER_SLOTS: u64 = 4;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue