Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Warn validators about stake deactivation #5955

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ tokio-io = "0.1"
untrusted = "0.7.0"
solana-rayon-threadlimit = { path = "../rayon-threadlimit", version = "0.20.0" }
reed-solomon-erasure = { package = "solana-reed-solomon-erasure", version = "4.0.1-3", features = ["simd-accel"] }
ctrlc = "3.1.3"

[dev-dependencies]
hex-literal = "0.2.1"
Expand Down
37 changes: 34 additions & 3 deletions core/src/validator.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! The `validator` module hosts all the validator microservices.
//! The `fullnode` module hosts all the fullnode microservices.

use crate::broadcast_stage::BroadcastStageType;
use crate::cluster_info::{ClusterInfo, Node};
Expand Down Expand Up @@ -29,11 +29,15 @@ use solana_sdk::poh_config::PohConfig;
use solana_sdk::pubkey::Pubkey;
use solana_sdk::signature::{Keypair, KeypairUtil};
use solana_sdk::timing::timestamp;
use solana_vote_api::vote_state::VoteState;
use ctrlc::set_handler;



use std::fs;
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
use std::path::{Path, PathBuf};
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
use std::sync::mpsc::Receiver;
use std::sync::{Arc, Mutex, RwLock};
use std::thread::Result;
Expand All @@ -51,6 +55,7 @@ pub struct ValidatorConfig {
pub snapshot_config: Option<SnapshotConfig>,
pub max_ledger_slots: Option<u64>,
pub broadcast_stage_type: BroadcastStageType,
pub enable_ctrl_c_handler: bool,
}

impl Default for ValidatorConfig {
Expand All @@ -67,6 +72,7 @@ impl Default for ValidatorConfig {
rpc_config: JsonRpcConfig::default(),
snapshot_config: None,
broadcast_stage_type: BroadcastStageType::Standard,
enable_ctrl_c_handler: false,
}
}
}
Expand Down Expand Up @@ -176,7 +182,32 @@ impl Validator {
config.storage_slots_per_turn,
bank.slots_per_segment(),
);

if config. enable_ctrl_c_handler {
let bank_forks = bank_forks.clone();
let counter = Arc::new(AtomicUsize::new(0));
set_handler(move || {
if counter.fetch_add(1, Ordering::Relaxed) > 0 {
warn!("Validator aborting on second ^C");
std::process::exit(1);
}
let bank = bank_forks.read().unwrap().working_bank();
let stake: Option<u64> = bank
.epoch_vote_accounts(bank.get_epoch_and_slot_index(bank.slot()).0) //Option<&HashMap<Pubkey, (u64, Account)>>
.and_then(|account| {
account.iter().find(|(pubkey, (stake, account))| {
**pubkey == id
&& *stake > 0
&& VoteState::deserialize(&account.data).is_ok()
})
})
.map(|(_, (n, _))| *n);
match stake {
Some(_val) => warn!("Validator with stake is exiting on first ^C"),
None => std::process::exit(1),
}
})
.expect("Error setting Ctrl-C handler");
}
let rpc_service = if node.info.rpc.port() == 0 {
None
} else {
Expand Down
108 changes: 108 additions & 0 deletions programs/bpf/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions validator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,10 @@ pub fn main() {

validator_config.voting_disabled = matches.is_present("no_voting");

validator_config.rpc_config.enable_fullnode_exit = matches.is_present("enable_rpc_exit");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line looks like a minor rebase error, it shouldn't be modified.


validator_config.rpc_config.enable_validator_exit = matches.is_present("enable_rpc_exit");
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed rebase error here

validator_config.enable_ctrl_c_handler = true;

validator_config.rpc_config.drone_addr = matches.value_of("rpc_drone_addr").map(|address| {
solana_netutil::parse_host_port(address).expect("failed to parse drone address")
Expand Down
Loading