mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-07 00:42:42 +00:00
Add flag to enable/disable BP in HTTP API
This commit is contained in:
@@ -126,6 +126,7 @@ pub struct Config {
|
|||||||
pub allow_sync_stalled: bool,
|
pub allow_sync_stalled: bool,
|
||||||
pub spec_fork_name: Option<ForkName>,
|
pub spec_fork_name: Option<ForkName>,
|
||||||
pub data_dir: PathBuf,
|
pub data_dir: PathBuf,
|
||||||
|
pub enable_beacon_processor: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Config {
|
impl Default for Config {
|
||||||
@@ -139,6 +140,7 @@ impl Default for Config {
|
|||||||
allow_sync_stalled: false,
|
allow_sync_stalled: false,
|
||||||
spec_fork_name: None,
|
spec_fork_name: None,
|
||||||
data_dir: PathBuf::from(DEFAULT_ROOT_DIR),
|
data_dir: PathBuf::from(DEFAULT_ROOT_DIR),
|
||||||
|
enable_beacon_processor: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -488,7 +490,10 @@ pub fn serve<T: BeaconChainTypes>(
|
|||||||
let app_start_filter = warp::any().map(move || app_start);
|
let app_start_filter = warp::any().map(move || app_start);
|
||||||
|
|
||||||
// Create a `warp` filter that provides access the `TaskSpawner`.
|
// Create a `warp` filter that provides access the `TaskSpawner`.
|
||||||
let beacon_processor_send = ctx.beacon_processor_send.clone();
|
let beacon_processor_send = ctx
|
||||||
|
.beacon_processor_send
|
||||||
|
.clone()
|
||||||
|
.filter(|_| config.enable_beacon_processor);
|
||||||
let task_spawner_filter =
|
let task_spawner_filter =
|
||||||
warp::any().map(move || TaskSpawner::new(beacon_processor_send.clone()));
|
warp::any().map(move || TaskSpawner::new(beacon_processor_send.clone()));
|
||||||
|
|
||||||
|
|||||||
@@ -220,6 +220,7 @@ pub async fn create_api_server_on_port<T: BeaconChainTypes>(
|
|||||||
allow_sync_stalled: false,
|
allow_sync_stalled: false,
|
||||||
data_dir: std::path::PathBuf::from(DEFAULT_ROOT_DIR),
|
data_dir: std::path::PathBuf::from(DEFAULT_ROOT_DIR),
|
||||||
spec_fork_name: None,
|
spec_fork_name: None,
|
||||||
|
enable_beacon_processor: true,
|
||||||
},
|
},
|
||||||
chain: Some(chain),
|
chain: Some(chain),
|
||||||
network_senders: Some(network_senders),
|
network_senders: Some(network_senders),
|
||||||
|
|||||||
@@ -382,6 +382,16 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
|
|||||||
stalled. This is useful for very small testnets. TESTING ONLY. DO NOT USE ON \
|
stalled. This is useful for very small testnets. TESTING ONLY. DO NOT USE ON \
|
||||||
MAINNET.")
|
MAINNET.")
|
||||||
)
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("http-enable-beacon-processor")
|
||||||
|
.long("http-enable-beacon-processor")
|
||||||
|
.help("The beacon processor is a scheduler which provides quality-of-service and \
|
||||||
|
DoS protection. When set to \"true\", HTTP API requests will queued and scheduled \
|
||||||
|
alongside other tasks. When set to \"false\", HTTP API responses will be executed \
|
||||||
|
immediately.")
|
||||||
|
.takes_value(true)
|
||||||
|
.default_value("true")
|
||||||
|
)
|
||||||
/* Prometheus metrics HTTP server related arguments */
|
/* Prometheus metrics HTTP server related arguments */
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("metrics")
|
Arg::with_name("metrics")
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ use beacon_chain::chain_config::{
|
|||||||
};
|
};
|
||||||
use clap::ArgMatches;
|
use clap::ArgMatches;
|
||||||
use clap_utils::flags::DISABLE_MALLOC_TUNING_FLAG;
|
use clap_utils::flags::DISABLE_MALLOC_TUNING_FLAG;
|
||||||
|
use clap_utils::parse_required;
|
||||||
use client::{ClientConfig, ClientGenesis};
|
use client::{ClientConfig, ClientGenesis};
|
||||||
use directory::{DEFAULT_BEACON_NODE_DIR, DEFAULT_NETWORK_DIR, DEFAULT_ROOT_DIR};
|
use directory::{DEFAULT_BEACON_NODE_DIR, DEFAULT_NETWORK_DIR, DEFAULT_ROOT_DIR};
|
||||||
use environment::RuntimeContext;
|
use environment::RuntimeContext;
|
||||||
@@ -148,6 +149,9 @@ pub fn get_config<E: EthSpec>(
|
|||||||
client_config.http_api.allow_sync_stalled = true;
|
client_config.http_api.allow_sync_stalled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
client_config.http_api.enable_beacon_processor =
|
||||||
|
parse_required(cli_args, "http-enable-beacon-processor")?;
|
||||||
|
|
||||||
if let Some(cache_size) = clap_utils::parse_optional(cli_args, "shuffling-cache-size")? {
|
if let Some(cache_size) = clap_utils::parse_optional(cli_args, "shuffling-cache-size")? {
|
||||||
client_config.chain.shuffling_cache_size = cache_size;
|
client_config.chain.shuffling_cache_size = cache_size;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1464,6 +1464,22 @@ fn http_allow_sync_stalled_flag() {
|
|||||||
.with_config(|config| assert_eq!(config.http_api.allow_sync_stalled, true));
|
.with_config(|config| assert_eq!(config.http_api.allow_sync_stalled, true));
|
||||||
}
|
}
|
||||||
#[test]
|
#[test]
|
||||||
|
fn http_enable_beacon_processor() {
|
||||||
|
CommandLineTest::new()
|
||||||
|
.run_with_zero_port()
|
||||||
|
.with_config(|config| assert_eq!(config.http_api.enable_beacon_processor, true));
|
||||||
|
|
||||||
|
CommandLineTest::new()
|
||||||
|
.flag("http-enable-beacon-processor", Some("true"))
|
||||||
|
.run_with_zero_port()
|
||||||
|
.with_config(|config| assert_eq!(config.http_api.enable_beacon_processor, true));
|
||||||
|
|
||||||
|
CommandLineTest::new()
|
||||||
|
.flag("http-enable-beacon-processor", Some("false"))
|
||||||
|
.run_with_zero_port()
|
||||||
|
.with_config(|config| assert_eq!(config.http_api.enable_beacon_processor, false));
|
||||||
|
}
|
||||||
|
#[test]
|
||||||
fn http_tls_flags() {
|
fn http_tls_flags() {
|
||||||
let dir = TempDir::new().expect("Unable to create temporary directory");
|
let dir = TempDir::new().expect("Unable to create temporary directory");
|
||||||
CommandLineTest::new()
|
CommandLineTest::new()
|
||||||
|
|||||||
Reference in New Issue
Block a user