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:
dapplion
2026-05-21 05:59:50 +02:00
parent 52115542c1
commit 60472329e9
4 changed files with 24 additions and 43 deletions

View File

@@ -4929,7 +4929,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
let cached_shuffling = CachedShuffling::new(committee_cache.clone(), ptcs);
self.shuffling_cache
.write()
.insert_committee_cache(shuffling_id, cached_shuffling)?;
.insert_committee_cache(shuffling_id, cached_shuffling);
}
}
Ok(())

View File

@@ -135,9 +135,6 @@ pub enum BeaconChainError {
state_epoch: Epoch,
shuffling_epoch: Epoch,
},
MissingPtcForGloasShuffling {
shuffling_epoch: Epoch,
},
SyncDutiesError(BeaconStateError),
InconsistentForwardsIter {
request_slot: Slot,

View File

@@ -209,18 +209,16 @@ impl<E: EthSpec> ShufflingCache<E> {
&mut self,
key: AttestationShufflingId,
cached_shuffling: CachedShuffling<E>,
) -> Result<(), BeaconChainError> {
) {
match self.cache.get(&key) {
Some(CacheItem::Committee(_)) => {
// 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
// worth two in the promise-bush!
// A bird in the hand is worth two in the promise-bush!
Some(CacheItem::Promise(_)) | None => {
self.insert_cache_item(key, CacheItem::Committee(cached_shuffling));
}
}
Ok(())
}
/// Prunes the cache first before inserting a new cache item.
@@ -444,7 +442,7 @@ where
shuffling_cache_lock
.write()
.insert_committee_cache(shuffling_id, cached_shuffling.clone())?;
.insert_committee_cache(shuffling_id, cached_shuffling.clone());
metrics::stop_timer(committee_building_timer);
@@ -714,9 +712,7 @@ mod test {
let mut cache = new_shuffling_cache();
let id_a = shuffling_id(1);
let committee_cache_a = Arc::new(CommitteeCache::default());
cache
.insert_committee_cache(id_a.clone(), cached_shuffling(committee_cache_a.clone()))
.unwrap();
cache.insert_committee_cache(id_a.clone(), cached_shuffling(committee_cache_a.clone()));
assert!(
matches!(cache.get(&id_a).unwrap(), CacheItem::Committee(cached_shuffling) if cached_shuffling.committee_cache == committee_cache_a),
"should insert committee cache"
@@ -731,12 +727,10 @@ mod test {
.collect::<Vec<_>>();
for (shuffling_id, committee_cache) in shuffling_id_and_committee_caches.iter() {
cache
.insert_committee_cache(
shuffling_id.clone(),
cached_shuffling(committee_cache.clone()),
)
.unwrap();
cache.insert_committee_cache(
shuffling_id.clone(),
cached_shuffling(committee_cache.clone()),
);
}
for i in 1..(TEST_CACHE_SIZE + 1) {
@@ -769,9 +763,7 @@ mod test {
shuffling_epoch: (current_epoch + 1).into(),
shuffling_decision_block: Hash256::from_low_u64_be(current_epoch + i as u64),
};
cache
.insert_committee_cache(shuffling_id, cached_shuffling(committee_cache.clone()))
.unwrap();
cache.insert_committee_cache(shuffling_id, cached_shuffling(committee_cache.clone()));
}
// Now, update the head shuffling ids
@@ -784,24 +776,18 @@ mod test {
cache.update_head_shuffling_ids(head_shuffling_ids.clone());
// Insert head state shuffling ids. Should not be overridden by other shuffling ids.
cache
.insert_committee_cache(
head_shuffling_ids.current.clone(),
cached_shuffling(committee_cache.clone()),
)
.unwrap();
cache
.insert_committee_cache(
head_shuffling_ids.next.clone(),
cached_shuffling(committee_cache.clone()),
)
.unwrap();
cache
.insert_committee_cache(
head_shuffling_ids.previous.clone().unwrap(),
cached_shuffling(committee_cache.clone()),
)
.unwrap();
cache.insert_committee_cache(
head_shuffling_ids.current.clone(),
cached_shuffling(committee_cache.clone()),
);
cache.insert_committee_cache(
head_shuffling_ids.next.clone(),
cached_shuffling(committee_cache.clone()),
);
cache.insert_committee_cache(
head_shuffling_ids.previous.clone().unwrap(),
cached_shuffling(committee_cache.clone()),
);
// Insert a few entries for older epochs.
for i in 0..TEST_CACHE_SIZE {
@@ -809,9 +795,7 @@ mod test {
shuffling_epoch: Epoch::from(i),
shuffling_decision_block: Hash256::from_low_u64_be(i as u64),
};
cache
.insert_committee_cache(shuffling_id, cached_shuffling(committee_cache.clone()))
.unwrap();
cache.insert_committee_cache(shuffling_id, cached_shuffling(committee_cache.clone()));
}
assert!(

View File

@@ -415,7 +415,7 @@ fn advance_head<T: BeaconChainTypes>(beacon_chain: &Arc<BeaconChain<T>>) -> Resu
beacon_chain
.shuffling_cache
.write()
.insert_committee_cache(shuffling_id.clone(), cached_shuffling)?;
.insert_committee_cache(shuffling_id.clone(), cached_shuffling);
debug!(
?head_block_root,