VC: accept unknown fields in chain spec (#2277)

## Issue Addressed

Closes #2274

## Proposed Changes

* Modify the `YamlConfig` to collect unknown fields into an `extra_fields` map, instead of failing hard.
* Log a debug message if there are extra fields returned to the VC from one of its BNs.

This restores Lighthouse's compatibility with Teku beacon nodes (and therefore Infura)
This commit is contained in:
Michael Sproul
2021-03-26 04:53:57 +00:00
parent 9a71a7e486
commit f9d60f5436
23 changed files with 102 additions and 54 deletions

View File

@@ -1,6 +1,7 @@
#![cfg(feature = "ef_tests")]
use ef_tests::*;
use std::collections::HashMap;
use std::path::PathBuf;
use types::*;
@@ -17,6 +18,11 @@ fn config_test<E: EthSpec + TypeName>() {
let yaml_from_spec = YamlConfig::from_spec::<E>(&spec);
assert_eq!(yaml_config.apply_to_chain_spec::<E>(&spec), Some(spec));
assert_eq!(yaml_from_spec, yaml_config);
assert_eq!(
yaml_config.extra_fields,
HashMap::new(),
"not all config fields read"
);
}
#[test]

View File

@@ -7,7 +7,7 @@ use state_processing::test_utils::BlockProcessingBuilder;
use std::env;
use std::fs::{self, File};
use std::io::Write;
use std::path::PathBuf;
use std::path::{Path, PathBuf};
use std::process::exit;
use types::MainnetEthSpec;
use types::{BeaconState, ChainSpec, EthSpec, SignedBeaconBlock};
@@ -91,12 +91,12 @@ fn write_vectors_to_file(title: &str, vectors: &[TestVector]) -> Result<(), Stri
}
/// Write some SSZ object to file.
fn write_to_ssz_file<T: Encode>(path: &PathBuf, item: &T) -> Result<(), String> {
fn write_to_ssz_file<T: Encode>(path: &Path, item: &T) -> Result<(), String> {
write_to_file(path, &item.as_ssz_bytes())
}
/// Write some bytes to file.
fn write_to_file(path: &PathBuf, item: &[u8]) -> Result<(), String> {
fn write_to_file(path: &Path, item: &[u8]) -> Result<(), String> {
File::create(path)
.map_err(|e| format!("Unable to create {:?}: {:?}", path, e))
.and_then(|mut file| {