mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-31 13:17:09 +00:00
Clean up shuffling cache leftovers from PR #9305
- Remove unused `BeaconChainError::MissingPtcForGloasShuffling` variant (no producers remained after the earlier cleanup). - Drop the `Result<(), BeaconChainError>` return type from `ShufflingCache::insert_committee_cache`; both match arms are infallible. Update callers in `beacon_chain.rs`, `state_advance_timer.rs`, `shuffling_cache.rs` and the unit tests accordingly. - Trim stale "Replace the committee if it's not present" comment in `insert_committee_cache`; the Committee arm is now a no-op so only the `Promise(_) | None` whimsy line remains.
This commit is contained in:
@@ -4929,7 +4929,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
|
|||||||
let cached_shuffling = CachedShuffling::new(committee_cache.clone(), ptcs);
|
let cached_shuffling = CachedShuffling::new(committee_cache.clone(), ptcs);
|
||||||
self.shuffling_cache
|
self.shuffling_cache
|
||||||
.write()
|
.write()
|
||||||
.insert_committee_cache(shuffling_id, cached_shuffling)?;
|
.insert_committee_cache(shuffling_id, cached_shuffling);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -135,9 +135,6 @@ pub enum BeaconChainError {
|
|||||||
state_epoch: Epoch,
|
state_epoch: Epoch,
|
||||||
shuffling_epoch: Epoch,
|
shuffling_epoch: Epoch,
|
||||||
},
|
},
|
||||||
MissingPtcForGloasShuffling {
|
|
||||||
shuffling_epoch: Epoch,
|
|
||||||
},
|
|
||||||
SyncDutiesError(BeaconStateError),
|
SyncDutiesError(BeaconStateError),
|
||||||
InconsistentForwardsIter {
|
InconsistentForwardsIter {
|
||||||
request_slot: Slot,
|
request_slot: Slot,
|
||||||
|
|||||||
@@ -209,18 +209,16 @@ impl<E: EthSpec> ShufflingCache<E> {
|
|||||||
&mut self,
|
&mut self,
|
||||||
key: AttestationShufflingId,
|
key: AttestationShufflingId,
|
||||||
cached_shuffling: CachedShuffling<E>,
|
cached_shuffling: CachedShuffling<E>,
|
||||||
) -> Result<(), BeaconChainError> {
|
) {
|
||||||
match self.cache.get(&key) {
|
match self.cache.get(&key) {
|
||||||
Some(CacheItem::Committee(_)) => {
|
Some(CacheItem::Committee(_)) => {
|
||||||
// Calculation is deterministic, so no need to replace the existing entry.
|
// Calculation is deterministic, so no need to replace the existing entry.
|
||||||
}
|
}
|
||||||
// Replace the committee if it's not present or if it's a promise. A bird in the hand is
|
// A bird in the hand is worth two in the promise-bush!
|
||||||
// worth two in the promise-bush!
|
|
||||||
Some(CacheItem::Promise(_)) | None => {
|
Some(CacheItem::Promise(_)) | None => {
|
||||||
self.insert_cache_item(key, CacheItem::Committee(cached_shuffling));
|
self.insert_cache_item(key, CacheItem::Committee(cached_shuffling));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Prunes the cache first before inserting a new cache item.
|
/// Prunes the cache first before inserting a new cache item.
|
||||||
@@ -444,7 +442,7 @@ where
|
|||||||
|
|
||||||
shuffling_cache_lock
|
shuffling_cache_lock
|
||||||
.write()
|
.write()
|
||||||
.insert_committee_cache(shuffling_id, cached_shuffling.clone())?;
|
.insert_committee_cache(shuffling_id, cached_shuffling.clone());
|
||||||
|
|
||||||
metrics::stop_timer(committee_building_timer);
|
metrics::stop_timer(committee_building_timer);
|
||||||
|
|
||||||
@@ -714,9 +712,7 @@ mod test {
|
|||||||
let mut cache = new_shuffling_cache();
|
let mut cache = new_shuffling_cache();
|
||||||
let id_a = shuffling_id(1);
|
let id_a = shuffling_id(1);
|
||||||
let committee_cache_a = Arc::new(CommitteeCache::default());
|
let committee_cache_a = Arc::new(CommitteeCache::default());
|
||||||
cache
|
cache.insert_committee_cache(id_a.clone(), cached_shuffling(committee_cache_a.clone()));
|
||||||
.insert_committee_cache(id_a.clone(), cached_shuffling(committee_cache_a.clone()))
|
|
||||||
.unwrap();
|
|
||||||
assert!(
|
assert!(
|
||||||
matches!(cache.get(&id_a).unwrap(), CacheItem::Committee(cached_shuffling) if cached_shuffling.committee_cache == committee_cache_a),
|
matches!(cache.get(&id_a).unwrap(), CacheItem::Committee(cached_shuffling) if cached_shuffling.committee_cache == committee_cache_a),
|
||||||
"should insert committee cache"
|
"should insert committee cache"
|
||||||
@@ -731,12 +727,10 @@ mod test {
|
|||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
for (shuffling_id, committee_cache) in shuffling_id_and_committee_caches.iter() {
|
for (shuffling_id, committee_cache) in shuffling_id_and_committee_caches.iter() {
|
||||||
cache
|
cache.insert_committee_cache(
|
||||||
.insert_committee_cache(
|
shuffling_id.clone(),
|
||||||
shuffling_id.clone(),
|
cached_shuffling(committee_cache.clone()),
|
||||||
cached_shuffling(committee_cache.clone()),
|
);
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for i in 1..(TEST_CACHE_SIZE + 1) {
|
for i in 1..(TEST_CACHE_SIZE + 1) {
|
||||||
@@ -769,9 +763,7 @@ mod test {
|
|||||||
shuffling_epoch: (current_epoch + 1).into(),
|
shuffling_epoch: (current_epoch + 1).into(),
|
||||||
shuffling_decision_block: Hash256::from_low_u64_be(current_epoch + i as u64),
|
shuffling_decision_block: Hash256::from_low_u64_be(current_epoch + i as u64),
|
||||||
};
|
};
|
||||||
cache
|
cache.insert_committee_cache(shuffling_id, cached_shuffling(committee_cache.clone()));
|
||||||
.insert_committee_cache(shuffling_id, cached_shuffling(committee_cache.clone()))
|
|
||||||
.unwrap();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now, update the head shuffling ids
|
// Now, update the head shuffling ids
|
||||||
@@ -784,24 +776,18 @@ mod test {
|
|||||||
cache.update_head_shuffling_ids(head_shuffling_ids.clone());
|
cache.update_head_shuffling_ids(head_shuffling_ids.clone());
|
||||||
|
|
||||||
// Insert head state shuffling ids. Should not be overridden by other shuffling ids.
|
// Insert head state shuffling ids. Should not be overridden by other shuffling ids.
|
||||||
cache
|
cache.insert_committee_cache(
|
||||||
.insert_committee_cache(
|
head_shuffling_ids.current.clone(),
|
||||||
head_shuffling_ids.current.clone(),
|
cached_shuffling(committee_cache.clone()),
|
||||||
cached_shuffling(committee_cache.clone()),
|
);
|
||||||
)
|
cache.insert_committee_cache(
|
||||||
.unwrap();
|
head_shuffling_ids.next.clone(),
|
||||||
cache
|
cached_shuffling(committee_cache.clone()),
|
||||||
.insert_committee_cache(
|
);
|
||||||
head_shuffling_ids.next.clone(),
|
cache.insert_committee_cache(
|
||||||
cached_shuffling(committee_cache.clone()),
|
head_shuffling_ids.previous.clone().unwrap(),
|
||||||
)
|
cached_shuffling(committee_cache.clone()),
|
||||||
.unwrap();
|
);
|
||||||
cache
|
|
||||||
.insert_committee_cache(
|
|
||||||
head_shuffling_ids.previous.clone().unwrap(),
|
|
||||||
cached_shuffling(committee_cache.clone()),
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
// Insert a few entries for older epochs.
|
// Insert a few entries for older epochs.
|
||||||
for i in 0..TEST_CACHE_SIZE {
|
for i in 0..TEST_CACHE_SIZE {
|
||||||
@@ -809,9 +795,7 @@ mod test {
|
|||||||
shuffling_epoch: Epoch::from(i),
|
shuffling_epoch: Epoch::from(i),
|
||||||
shuffling_decision_block: Hash256::from_low_u64_be(i as u64),
|
shuffling_decision_block: Hash256::from_low_u64_be(i as u64),
|
||||||
};
|
};
|
||||||
cache
|
cache.insert_committee_cache(shuffling_id, cached_shuffling(committee_cache.clone()));
|
||||||
.insert_committee_cache(shuffling_id, cached_shuffling(committee_cache.clone()))
|
|
||||||
.unwrap();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
assert!(
|
assert!(
|
||||||
|
|||||||
@@ -415,7 +415,7 @@ fn advance_head<T: BeaconChainTypes>(beacon_chain: &Arc<BeaconChain<T>>) -> Resu
|
|||||||
beacon_chain
|
beacon_chain
|
||||||
.shuffling_cache
|
.shuffling_cache
|
||||||
.write()
|
.write()
|
||||||
.insert_committee_cache(shuffling_id.clone(), cached_shuffling)?;
|
.insert_committee_cache(shuffling_id.clone(), cached_shuffling);
|
||||||
|
|
||||||
debug!(
|
debug!(
|
||||||
?head_block_root,
|
?head_block_root,
|
||||||
|
|||||||
Reference in New Issue
Block a user