Make room for more fields in JsonRpcConfig
This commit is contained in:
@ -211,7 +211,6 @@ impl Drop for LocalCluster {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::rpc::JsonRpcConfig;
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_local_cluster_start_and_exit() {
|
fn test_local_cluster_start_and_exit() {
|
||||||
@ -224,7 +223,7 @@ mod test {
|
|||||||
fn test_local_cluster_start_and_exit_with_config() {
|
fn test_local_cluster_start_and_exit_with_config() {
|
||||||
solana_logger::setup();
|
solana_logger::setup();
|
||||||
let mut fullnode_exit = FullnodeConfig::default();
|
let mut fullnode_exit = FullnodeConfig::default();
|
||||||
fullnode_exit.rpc_config = JsonRpcConfig::TestOnlyAllowRpcFullnodeExit;
|
fullnode_exit.rpc_config.enable_fullnode_exit = true;
|
||||||
let cluster = LocalCluster::new_with_config(1, 100, 3, &fullnode_exit);
|
let cluster = LocalCluster::new_with_config(1, 100, 3, &fullnode_exit);
|
||||||
drop(cluster)
|
drop(cluster)
|
||||||
}
|
}
|
||||||
|
@ -22,14 +22,15 @@ use std::thread::sleep;
|
|||||||
use std::time::{Duration, Instant};
|
use std::time::{Duration, Instant};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub enum JsonRpcConfig {
|
pub struct JsonRpcConfig {
|
||||||
DefaultConfig,
|
pub enable_fullnode_exit: bool, // Enable the 'fullnodeExit' command
|
||||||
TestOnlyAllowRpcFullnodeExit,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for JsonRpcConfig {
|
impl Default for JsonRpcConfig {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
JsonRpcConfig::DefaultConfig
|
Self {
|
||||||
|
enable_fullnode_exit: false,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,16 +111,13 @@ impl JsonRpcRequestProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn fullnode_exit(&self) -> Result<bool> {
|
pub fn fullnode_exit(&self) -> Result<bool> {
|
||||||
match self.config {
|
if self.config.enable_fullnode_exit {
|
||||||
JsonRpcConfig::DefaultConfig => {
|
warn!("fullnode_exit request...");
|
||||||
debug!("default config, fullnode_exit ignored");
|
|
||||||
Ok(false)
|
|
||||||
}
|
|
||||||
JsonRpcConfig::TestOnlyAllowRpcFullnodeExit => {
|
|
||||||
warn!("TEST_ONLY JsonRPC fullnode_exit request...");
|
|
||||||
self.fullnode_exit.store(true, Ordering::Relaxed);
|
self.fullnode_exit.store(true, Ordering::Relaxed);
|
||||||
Ok(true)
|
Ok(true)
|
||||||
}
|
} else {
|
||||||
|
debug!("fullnode_exit ignored");
|
||||||
|
Ok(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -714,26 +712,14 @@ mod tests {
|
|||||||
assert_eq!(request_processor.fullnode_exit(), Ok(false));
|
assert_eq!(request_processor.fullnode_exit(), Ok(false));
|
||||||
assert_eq!(exit.load(Ordering::Relaxed), false);
|
assert_eq!(exit.load(Ordering::Relaxed), false);
|
||||||
}
|
}
|
||||||
#[test]
|
|
||||||
fn test_rpc_request_processor_default_config_fullnode_exit_fails() {
|
|
||||||
let exit = Arc::new(AtomicBool::new(false));
|
|
||||||
let request_processor = JsonRpcRequestProcessor::new(
|
|
||||||
StorageState::default(),
|
|
||||||
JsonRpcConfig::DefaultConfig,
|
|
||||||
&exit,
|
|
||||||
);
|
|
||||||
assert_eq!(request_processor.fullnode_exit(), Ok(false));
|
|
||||||
assert_eq!(exit.load(Ordering::Relaxed), false);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_rpc_request_processor_allow_fullnode_exit_config() {
|
fn test_rpc_request_processor_allow_fullnode_exit_config() {
|
||||||
let exit = Arc::new(AtomicBool::new(false));
|
let exit = Arc::new(AtomicBool::new(false));
|
||||||
let request_processor = JsonRpcRequestProcessor::new(
|
let mut config = JsonRpcConfig::default();
|
||||||
StorageState::default(),
|
config.enable_fullnode_exit = true;
|
||||||
JsonRpcConfig::TestOnlyAllowRpcFullnodeExit,
|
let request_processor =
|
||||||
&exit,
|
JsonRpcRequestProcessor::new(StorageState::default(), config, &exit);
|
||||||
);
|
|
||||||
assert_eq!(request_processor.fullnode_exit(), Ok(true));
|
assert_eq!(request_processor.fullnode_exit(), Ok(true));
|
||||||
assert_eq!(exit.load(Ordering::Relaxed), true);
|
assert_eq!(exit.load(Ordering::Relaxed), true);
|
||||||
}
|
}
|
||||||
|
@ -217,7 +217,7 @@ fn main() {
|
|||||||
let use_only_bootstrap_leader = matches.is_present("no_leader_rotation");
|
let use_only_bootstrap_leader = matches.is_present("no_leader_rotation");
|
||||||
|
|
||||||
if matches.is_present("enable_rpc_exit") {
|
if matches.is_present("enable_rpc_exit") {
|
||||||
fullnode_config.rpc_config = solana::rpc::JsonRpcConfig::TestOnlyAllowRpcFullnodeExit;
|
fullnode_config.rpc_config.enable_fullnode_exit = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
let gossip_addr = {
|
let gossip_addr = {
|
||||||
|
@ -3,7 +3,6 @@ extern crate solana;
|
|||||||
use solana::cluster_tests;
|
use solana::cluster_tests;
|
||||||
use solana::fullnode::FullnodeConfig;
|
use solana::fullnode::FullnodeConfig;
|
||||||
use solana::local_cluster::LocalCluster;
|
use solana::local_cluster::LocalCluster;
|
||||||
use solana::rpc::JsonRpcConfig;
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_spend_and_verify_all_nodes_1() {
|
fn test_spend_and_verify_all_nodes_1() {
|
||||||
@ -54,18 +53,18 @@ fn test_fullnode_exit_default_config_should_panic() {
|
|||||||
fn test_fullnode_exit_2() {
|
fn test_fullnode_exit_2() {
|
||||||
solana_logger::setup();
|
solana_logger::setup();
|
||||||
let num_nodes = 2;
|
let num_nodes = 2;
|
||||||
let mut fullnode_exit = FullnodeConfig::default();
|
let mut fullnode_config = FullnodeConfig::default();
|
||||||
fullnode_exit.rpc_config = JsonRpcConfig::TestOnlyAllowRpcFullnodeExit;
|
fullnode_config.rpc_config.enable_fullnode_exit = true;
|
||||||
let local = LocalCluster::new_with_config(num_nodes, 10_000, 100, &fullnode_exit);
|
let local = LocalCluster::new_with_config(num_nodes, 10_000, 100, &fullnode_config);
|
||||||
cluster_tests::fullnode_exit(&local.entry_point_info, num_nodes);
|
cluster_tests::fullnode_exit(&local.entry_point_info, num_nodes);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_leader_failure_2() {
|
fn test_leader_failure_2() {
|
||||||
let num_nodes = 2;
|
let num_nodes = 2;
|
||||||
let mut fullnode_exit = FullnodeConfig::default();
|
let mut fullnode_config = FullnodeConfig::default();
|
||||||
fullnode_exit.rpc_config = JsonRpcConfig::TestOnlyAllowRpcFullnodeExit;
|
fullnode_config.rpc_config.enable_fullnode_exit = true;
|
||||||
let local = LocalCluster::new_with_config(num_nodes, 10_000, 100, &fullnode_exit);
|
let local = LocalCluster::new_with_config(num_nodes, 10_000, 100, &fullnode_config);
|
||||||
cluster_tests::kill_entry_and_spend_and_verify_rest(
|
cluster_tests::kill_entry_and_spend_and_verify_rest(
|
||||||
&local.entry_point_info,
|
&local.entry_point_info,
|
||||||
&local.funding_keypair,
|
&local.funding_keypair,
|
||||||
@ -76,9 +75,9 @@ fn test_leader_failure_2() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_leader_failure_3() {
|
fn test_leader_failure_3() {
|
||||||
let num_nodes = 3;
|
let num_nodes = 3;
|
||||||
let mut fullnode_exit = FullnodeConfig::default();
|
let mut fullnode_config = FullnodeConfig::default();
|
||||||
fullnode_exit.rpc_config = JsonRpcConfig::TestOnlyAllowRpcFullnodeExit;
|
fullnode_config.rpc_config.enable_fullnode_exit = true;
|
||||||
let local = LocalCluster::new_with_config(num_nodes, 10_000, 100, &fullnode_exit);
|
let local = LocalCluster::new_with_config(num_nodes, 10_000, 100, &fullnode_config);
|
||||||
cluster_tests::kill_entry_and_spend_and_verify_rest(
|
cluster_tests::kill_entry_and_spend_and_verify_rest(
|
||||||
&local.entry_point_info,
|
&local.entry_point_info,
|
||||||
&local.funding_keypair,
|
&local.funding_keypair,
|
||||||
|
Reference in New Issue
Block a user