mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-11 18:04:18 +00:00
Address clippy lints in tree-states (#4414)
* Address some clippy lints * Box errors to fix error size lint * Add Default impl for Validator * Address more clippy lints * Re-implement `check_state_diff` * Fix misc test compile errors
This commit is contained in:
@@ -2,7 +2,8 @@ use super::*;
|
||||
use compare_fields::{CompareFields, Comparison, FieldComparison};
|
||||
use std::fmt::Debug;
|
||||
use std::path::{Path, PathBuf};
|
||||
use types::{beacon_state::BeaconStateDiff, milhouse::diff::Diff, BeaconState};
|
||||
use store::hdiff::{HDiff, HDiffBuffer};
|
||||
use types::BeaconState;
|
||||
|
||||
pub const MAX_VALUE_STRING_LEN: usize = 500;
|
||||
|
||||
@@ -121,15 +122,28 @@ where
|
||||
pub fn check_state_diff<T: EthSpec>(
|
||||
pre_state: &BeaconState<T>,
|
||||
opt_post_state: &Option<BeaconState<T>>,
|
||||
spec: &ChainSpec,
|
||||
) -> 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");
|
||||
// Produce a diff between the pre- and post-states.
|
||||
let pre_state_buf = HDiffBuffer::from_state(pre_state.clone());
|
||||
let post_state_buf = HDiffBuffer::from_state(post_state.clone());
|
||||
let diff = HDiff::compute(&pre_state_buf, &post_state_buf).expect("HDiff should compute");
|
||||
|
||||
compare_result_detailed::<_, ()>(&Ok(diffed_state), opt_post_state)
|
||||
// Apply the diff to the pre-state, ensuring the same post-state is
|
||||
// regenerated.
|
||||
let mut reconstructed_buf = HDiffBuffer::from_state(pre_state.clone());
|
||||
diff.apply(&mut reconstructed_buf)
|
||||
.expect("HDiff should apply");
|
||||
let diffed_state = reconstructed_buf
|
||||
.into_state(spec)
|
||||
.expect("HDiffDiffer should convert to state");
|
||||
|
||||
// Drop the caches on the post-state to assist with equality checking.
|
||||
let mut post_state_without_caches = post_state.clone();
|
||||
post_state_without_caches.drop_all_caches().unwrap();
|
||||
|
||||
compare_result_detailed::<_, ()>(&Ok(diffed_state), &Some(post_state_without_caches))
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -328,7 +328,7 @@ impl<E: EthSpec, T: EpochTransition<E>> Case for EpochProcessing<E, T> {
|
||||
|
||||
let mut result = T::run(&mut state, spec).map(|_| state);
|
||||
|
||||
check_state_diff(&pre_state, &expected)?;
|
||||
check_state_diff(&pre_state, &expected, spec)?;
|
||||
compare_beacon_state_results_without_caches(&mut result, &mut expected)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -458,7 +458,7 @@ impl<E: EthSpec, O: Operation<E>> Case for Operations<E, O> {
|
||||
// NOTE: some of the withdrawals tests have 0 active validators, do not try
|
||||
// to build the commitee cache in this case.
|
||||
if O::handler_name() != "withdrawals" {
|
||||
state.build_all_committee_caches(spec).unwrap();
|
||||
pre_state.build_all_committee_caches(spec).unwrap();
|
||||
}
|
||||
|
||||
let mut state = pre_state.clone();
|
||||
@@ -475,7 +475,7 @@ impl<E: EthSpec, O: Operation<E>> Case for Operations<E, O> {
|
||||
.apply_to(&mut state, spec, self)
|
||||
.map(|()| state);
|
||||
|
||||
check_state_diff(&pre_state, &expected)?;
|
||||
check_state_diff(&pre_state, &expected, spec)?;
|
||||
compare_beacon_state_results_without_caches(&mut result, &mut expected)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,7 +137,7 @@ impl<E: EthSpec> Case for SanityBlocks<E> {
|
||||
post.build_all_committee_caches(spec).unwrap();
|
||||
post
|
||||
});
|
||||
check_state_diff(&pre, &post)?;
|
||||
check_state_diff(&pre, &post, spec)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,6 +76,6 @@ impl<E: EthSpec> Case for SanitySlots<E> {
|
||||
post.build_all_committee_caches(spec).unwrap();
|
||||
post
|
||||
});
|
||||
check_state_diff(&pre, &post)
|
||||
check_state_diff(&pre, &post, spec)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user