Several changes

* Fix state cache pruning of finalized state from block map
* Update to latest `milhouse`
* Check beacon state diffs in EF tests
This commit is contained in:
Michael Sproul
2022-03-01 15:49:40 +11:00
parent 143cf59504
commit 98629ce741
17 changed files with 115 additions and 50 deletions

View File

@@ -2,7 +2,7 @@ use super::*;
use compare_fields::{CompareFields, Comparison, FieldComparison};
use std::fmt::Debug;
use std::path::{Path, PathBuf};
use types::BeaconState;
use types::{beacon_state::BeaconStateDiff, milhouse::diff::Diff, BeaconState};
pub const MAX_VALUE_STRING_LEN: usize = 500;
@@ -118,6 +118,23 @@ where
}
}
pub fn check_state_diff<T: EthSpec>(
pre_state: &BeaconState<T>,
opt_post_state: &Option<BeaconState<T>>,
) -> Result<(), Error> {
if let Some(post_state) = opt_post_state {
let diff = BeaconStateDiff::compute_diff(pre_state, post_state)
.expect("BeaconStateDiff should compute");
let mut diffed_state = pre_state.clone();
diff.apply_diff(&mut diffed_state)
.expect("BeaconStateDiff should apply");
compare_result_detailed::<_, ()>(&Ok(diffed_state), opt_post_state)
} else {
Ok(())
}
}
fn fmt_val<T: Debug>(val: T) -> String {
let mut string = format!("{:?}", val);
string.truncate(MAX_VALUE_STRING_LEN);

View File

@@ -1,6 +1,6 @@
use super::*;
use crate::bls_setting::BlsSetting;
use crate::case_result::compare_beacon_state_results_without_caches;
use crate::case_result::{check_state_diff, compare_beacon_state_results_without_caches};
use crate::decode::{ssz_decode_state, yaml_decode_file};
use crate::type_name;
use crate::type_name::TypeName;
@@ -274,7 +274,7 @@ impl<E: EthSpec, T: EpochTransition<E>> Case for EpochProcessing<E, T> {
&& T::name() != "inactivity_updates"
&& T::name() != "participation_flag_updates"
}
ForkName::Altair | ForkName::Merge => true, // TODO: revisit when tests are out
ForkName::Altair | ForkName::Merge => true,
}
}
@@ -293,6 +293,7 @@ impl<E: EthSpec, T: EpochTransition<E>> Case for EpochProcessing<E, T> {
T::run(&mut state, spec).map(|_| state)
})();
compare_beacon_state_results_without_caches(&mut result, &mut expected)
compare_beacon_state_results_without_caches(&mut result, &mut expected)?;
check_state_diff(&self.pre, &self.post)
}
}

View File

@@ -1,6 +1,6 @@
use super::*;
use crate::bls_setting::BlsSetting;
use crate::case_result::compare_beacon_state_results_without_caches;
use crate::case_result::{check_state_diff, compare_beacon_state_results_without_caches};
use crate::decode::{ssz_decode_file, ssz_decode_file_with, ssz_decode_state, yaml_decode_file};
use crate::testing_spec;
use crate::type_name::TypeName;
@@ -335,6 +335,7 @@ impl<E: EthSpec, O: Operation<E>> Case for Operations<E, O> {
.apply_to(&mut state, spec, self)
.map(|()| state);
compare_beacon_state_results_without_caches(&mut result, &mut expected)
compare_beacon_state_results_without_caches(&mut result, &mut expected)?;
check_state_diff(&self.pre, &self.post)
}
}

View File

@@ -1,6 +1,6 @@
use super::*;
use crate::bls_setting::BlsSetting;
use crate::case_result::compare_beacon_state_results_without_caches;
use crate::case_result::{check_state_diff, compare_beacon_state_results_without_caches};
use crate::decode::{ssz_decode_file_with, ssz_decode_state, yaml_decode_file};
use serde_derive::Deserialize;
use state_processing::{
@@ -129,6 +129,9 @@ impl<E: EthSpec> Case for SanityBlocks<E> {
Ok(res) => (Ok(res.0), Ok(res.1)),
};
compare_beacon_state_results_without_caches(&mut indiv_result, &mut expected)?;
compare_beacon_state_results_without_caches(&mut bulk_result, &mut expected)
compare_beacon_state_results_without_caches(&mut bulk_result, &mut expected)?;
check_state_diff(&self.pre, &self.post)?;
Ok(())
}
}

View File

@@ -1,6 +1,6 @@
use super::*;
use crate::bls_setting::BlsSetting;
use crate::case_result::compare_beacon_state_results_without_caches;
use crate::case_result::{check_state_diff, compare_beacon_state_results_without_caches};
use crate::decode::{ssz_decode_state, yaml_decode_file};
use serde_derive::Deserialize;
use state_processing::per_slot_processing;
@@ -70,6 +70,7 @@ impl<E: EthSpec> Case for SanitySlots<E> {
.try_for_each(|_| per_slot_processing(&mut state, None, spec).map(|_| ()))
.map(|_| state);
compare_beacon_state_results_without_caches(&mut result, &mut expected)
compare_beacon_state_results_without_caches(&mut result, &mut expected)?;
check_state_diff(&self.pre, &self.post)
}
}