Re-add old cache tests
This commit is contained in:
parent
89df2b173e
commit
cb74187cfc
@ -51,9 +51,9 @@ pub enum Error {
|
|||||||
registry_len: usize,
|
registry_len: usize,
|
||||||
},
|
},
|
||||||
PreviousEpochCacheUninitialized,
|
PreviousEpochCacheUninitialized,
|
||||||
CurrentEpochCacheUnintialized,
|
CurrentEpochCacheUninitialized,
|
||||||
RelativeEpochError(RelativeEpochError),
|
RelativeEpochError(RelativeEpochError),
|
||||||
EpochCacheUnintialized(RelativeEpoch),
|
EpochCacheUninitialized(RelativeEpoch),
|
||||||
EpochCacheError(EpochCacheError),
|
EpochCacheError(EpochCacheError),
|
||||||
TreeHashCacheError(TreeHashCacheError),
|
TreeHashCacheError(TreeHashCacheError),
|
||||||
}
|
}
|
||||||
@ -706,8 +706,9 @@ impl<T: EthSpec> BeaconState<T> {
|
|||||||
pub fn get_attestation_duties(
|
pub fn get_attestation_duties(
|
||||||
&self,
|
&self,
|
||||||
validator_index: usize,
|
validator_index: usize,
|
||||||
|
relative_epoch: RelativeEpoch,
|
||||||
) -> Result<&Option<AttestationDuty>, Error> {
|
) -> Result<&Option<AttestationDuty>, Error> {
|
||||||
let cache = self.cache(RelativeEpoch::Current)?;
|
let cache = self.cache(relative_epoch)?;
|
||||||
|
|
||||||
Ok(cache
|
Ok(cache
|
||||||
.attestation_duties
|
.attestation_duties
|
||||||
@ -799,10 +800,15 @@ impl<T: EthSpec> BeaconState<T> {
|
|||||||
if cache.is_initialized_at(relative_epoch.into_epoch(self.current_epoch())) {
|
if cache.is_initialized_at(relative_epoch.into_epoch(self.current_epoch())) {
|
||||||
Ok(cache)
|
Ok(cache)
|
||||||
} else {
|
} else {
|
||||||
Err(Error::EpochCacheUnintialized(relative_epoch))
|
Err(Error::EpochCacheUninitialized(relative_epoch))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Drops the cache, leaving it in an uninitialized state.
|
||||||
|
fn drop_cache(&mut self, relative_epoch: RelativeEpoch) {
|
||||||
|
self.epoch_caches[Self::cache_index(relative_epoch)] = EpochCache::default();
|
||||||
|
}
|
||||||
|
|
||||||
// FIXME(sproul): drop_previous/current_epoch_cache
|
// FIXME(sproul): drop_previous/current_epoch_cache
|
||||||
|
|
||||||
/// Updates the pubkey cache, if required.
|
/// Updates the pubkey cache, if required.
|
||||||
|
@ -111,6 +111,8 @@ fn can_start_on_any_shard() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// This spec has more shards than slots in an epoch, permitting epochs where not all shards are
|
||||||
|
/// included in the committee.
|
||||||
#[derive(Clone, PartialEq, Debug, Default, Serialize, Deserialize)]
|
#[derive(Clone, PartialEq, Debug, Default, Serialize, Deserialize)]
|
||||||
pub struct ExcessShardsEthSpec;
|
pub struct ExcessShardsEthSpec;
|
||||||
|
|
||||||
|
@ -72,7 +72,6 @@ fn get_active_index_root_index() {
|
|||||||
test_active_index::<FoundationEthSpec>(slot);
|
test_active_index::<FoundationEthSpec>(slot);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
/// Test that
|
/// Test that
|
||||||
///
|
///
|
||||||
/// 1. Using the cache before it's built fails.
|
/// 1. Using the cache before it's built fails.
|
||||||
@ -89,14 +88,12 @@ fn test_cache_initialization<'a, T: EthSpec>(
|
|||||||
|
|
||||||
// Assuming the cache isn't already built, assert that a call to a cache-using function fails.
|
// Assuming the cache isn't already built, assert that a call to a cache-using function fails.
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
state.get_attestation_duties(0, spec),
|
state.get_attestation_duties(0, relative_epoch),
|
||||||
Err(BeaconStateError::EpochCacheUninitialized(relative_epoch))
|
Err(BeaconStateError::EpochCacheUninitialized(relative_epoch))
|
||||||
);
|
);
|
||||||
|
|
||||||
// Build the cache.
|
// Build the cache.
|
||||||
state
|
state.build_epoch_cache(relative_epoch, spec).unwrap();
|
||||||
.build_current_epoch_cache(relative_epoch, spec)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
// Assert a call to a cache-using function passes.
|
// Assert a call to a cache-using function passes.
|
||||||
let _ = state
|
let _ = state
|
||||||
@ -125,10 +122,8 @@ fn cache_initialization() {
|
|||||||
|
|
||||||
test_cache_initialization(&mut state, RelativeEpoch::Previous, &spec);
|
test_cache_initialization(&mut state, RelativeEpoch::Previous, &spec);
|
||||||
test_cache_initialization(&mut state, RelativeEpoch::Current, &spec);
|
test_cache_initialization(&mut state, RelativeEpoch::Current, &spec);
|
||||||
test_cache_initialization(&mut state, RelativeEpoch::NextWithRegistryChange, &spec);
|
test_cache_initialization(&mut state, RelativeEpoch::Next, &spec);
|
||||||
test_cache_initialization(&mut state, RelativeEpoch::NextWithoutRegistryChange, &spec);
|
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn tree_hash_cache() {
|
fn tree_hash_cache() {
|
||||||
@ -208,13 +203,23 @@ mod committees {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Loop through each validator in the committee.
|
// Loop through each validator in the committee.
|
||||||
for &i in cc.committee {
|
for (committee_i, validator_i) in cc.committee.iter().enumerate() {
|
||||||
// Assert the validators are assigned contiguously across committees.
|
// Assert the validators are assigned contiguously across committees.
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
i,
|
*validator_i,
|
||||||
*expected_indices_iter.next().unwrap(),
|
*expected_indices_iter.next().unwrap(),
|
||||||
"Non-sequential validators."
|
"Non-sequential validators."
|
||||||
);
|
);
|
||||||
|
// Assert a call to `get_attestation_duties` is consistent with a call to
|
||||||
|
// `get_crosslink_committees_at_slot`
|
||||||
|
let attestation_duty = state
|
||||||
|
.get_attestation_duties(*validator_i, relative_epoch)
|
||||||
|
.unwrap()
|
||||||
|
.unwrap();
|
||||||
|
assert_eq!(attestation_duty.slot, slot);
|
||||||
|
assert_eq!(attestation_duty.shard, cc.shard);
|
||||||
|
assert_eq!(attestation_duty.committee_index, committee_i);
|
||||||
|
assert_eq!(attestation_duty.committee_len, cc.committee.len());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user