mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-06 18:21:45 +00:00
Serve Bellatrix preset in BN API (#3425)
## Issue Addressed Resolves #3388 Resolves #2638 ## Proposed Changes - Return the `BellatrixPreset` on `/eth/v1/config/spec` by default. - Allow users to opt out of this by providing `--http-spec-fork=altair` (unless there's a Bellatrix fork epoch set). - Add the Altair constants from #2638 and make serving the constants non-optional (the `http-disable-legacy-spec` flag is deprecated). - Modify the VC to only read the `Config` and not to log extra fields. This prevents it from having to muck around parsing the `ConfigAndPreset` fields it doesn't need. ## Additional Info This change is backwards-compatible for the VC and the BN, but is marked as a breaking change for the removal of `--http-disable-legacy-spec`. I tried making `Config` a `superstruct` too, but getting the automatic decoding to work was a huge pain and was going to require a lot of hacks, so I gave up in favour of keeping the default-based approach we have now.
This commit is contained in:
@@ -104,9 +104,9 @@ pub struct Config {
|
||||
pub listen_addr: IpAddr,
|
||||
pub listen_port: u16,
|
||||
pub allow_origin: Option<String>,
|
||||
pub serve_legacy_spec: bool,
|
||||
pub tls_config: Option<TlsConfig>,
|
||||
pub allow_sync_stalled: bool,
|
||||
pub spec_fork_name: Option<ForkName>,
|
||||
}
|
||||
|
||||
impl Default for Config {
|
||||
@@ -116,9 +116,9 @@ impl Default for Config {
|
||||
listen_addr: IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)),
|
||||
listen_port: 5052,
|
||||
allow_origin: None,
|
||||
serve_legacy_spec: true,
|
||||
tls_config: None,
|
||||
allow_sync_stalled: false,
|
||||
spec_fork_name: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1534,18 +1534,15 @@ pub fn serve<T: BeaconChainTypes>(
|
||||
});
|
||||
|
||||
// GET config/spec
|
||||
let serve_legacy_spec = ctx.config.serve_legacy_spec;
|
||||
let spec_fork_name = ctx.config.spec_fork_name;
|
||||
let get_config_spec = config_path
|
||||
.and(warp::path("spec"))
|
||||
.and(warp::path::end())
|
||||
.and(chain_filter.clone())
|
||||
.and_then(move |chain: Arc<BeaconChain<T>>| {
|
||||
blocking_json_task(move || {
|
||||
let mut config_and_preset =
|
||||
ConfigAndPreset::from_chain_spec::<T::EthSpec>(&chain.spec);
|
||||
if serve_legacy_spec {
|
||||
config_and_preset.make_backwards_compat(&chain.spec);
|
||||
}
|
||||
let config_and_preset =
|
||||
ConfigAndPreset::from_chain_spec::<T::EthSpec>(&chain.spec, spec_fork_name);
|
||||
Ok(api_types::GenericResponse::from(config_and_preset))
|
||||
})
|
||||
});
|
||||
|
||||
@@ -141,9 +141,9 @@ pub async fn create_api_server_on_port<T: BeaconChainTypes>(
|
||||
listen_addr: IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)),
|
||||
listen_port: port,
|
||||
allow_origin: None,
|
||||
serve_legacy_spec: true,
|
||||
tls_config: None,
|
||||
allow_sync_stalled: false,
|
||||
spec_fork_name: None,
|
||||
},
|
||||
chain: Some(chain.clone()),
|
||||
network_tx: Some(network_tx),
|
||||
|
||||
@@ -1253,10 +1253,13 @@ impl ApiTester {
|
||||
}
|
||||
|
||||
pub async fn test_get_config_spec(self) -> Self {
|
||||
let result = self.client.get_config_spec().await.unwrap().data;
|
||||
|
||||
let mut expected = ConfigAndPreset::from_chain_spec::<E>(&self.chain.spec);
|
||||
expected.make_backwards_compat(&self.chain.spec);
|
||||
let result = self
|
||||
.client
|
||||
.get_config_spec::<ConfigAndPresetBellatrix>()
|
||||
.await
|
||||
.map(|res| ConfigAndPreset::Bellatrix(res.data))
|
||||
.unwrap();
|
||||
let expected = ConfigAndPreset::from_chain_spec::<E>(&self.chain.spec, None);
|
||||
|
||||
assert_eq!(result, expected);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user