Improve error handling

This commit is contained in:
Michael Sproul
2026-05-19 10:58:26 +10:00
parent 8ec0c4fe7e
commit a3bf75e9a1
5 changed files with 17 additions and 17 deletions

View File

@@ -254,6 +254,13 @@ pub enum BeaconChainError {
request_epoch: Epoch,
cache_epoch: Epoch,
},
AttesterCachePtcOutOfBounds {
slot: Slot,
epoch: Epoch,
},
AttesterCacheNoPtcPreGloas {
slot: Slot,
},
SkipProposerPreparation,
FailedColumnCustodyInfoUpdate,
}

View File

@@ -87,9 +87,8 @@ impl<T: BeaconChainTypes> VerifiedPayloadAttestationMessage<T> {
ctx.spec,
beacon_block_root,
message_epoch,
|cached_shuffling, _| Ok::<_, Error>(cached_shuffling.ptc_for_slot(slot).cloned()),
)?
.ok_or(Error::MissingPTC { slot })?;
|cached_shuffling, _| cached_shuffling.ptc_for_slot(slot),
)?;
// [REJECT] `validator_index` is within `get_ptc(state, data.slot)`.
if !ptc.0.contains(&(validator_index as usize)) {

View File

@@ -66,12 +66,6 @@ pub enum Error {
///
/// The peer has sent an invalid message.
NotInPTC { validator_index: u64, slot: Slot },
/// The shuffling cache entry did not contain a PTC for this slot.
///
/// ## Peer scoring
///
/// We were unable to process this message due to an internal error.
MissingPTC { slot: Slot },
/// The validator index is unknown.
///
/// ## Peer scoring

View File

@@ -72,15 +72,16 @@ impl<E: EthSpec> CachedShuffling<E> {
}
}
pub fn ptc_for_slot(&self, slot: Slot) -> Option<&PTC<E>> {
pub fn ptc_for_slot(&self, slot: Slot) -> Result<PTC<E>, BeaconChainError> {
match &self.ptcs {
CachedPTCs::PreGloas => None, // Should we error here?
CachedPTCs::PostGloas(ptcs, epoch) => {
if slot.epoch(E::slots_per_epoch()) != *epoch {
None // Also we should error here?
CachedPTCs::PreGloas => Err(BeaconChainError::AttesterCacheNoPtcPreGloas { slot }),
&CachedPTCs::PostGloas(ref ptcs, epoch) => {
if slot.epoch(E::slots_per_epoch()) != epoch {
Err(BeaconChainError::AttesterCachePtcOutOfBounds { slot, epoch })
} else {
// Note: This may return Option also if construction was buggy
ptcs.get(slot.as_usize() % E::slots_per_epoch() as usize)
.cloned()
.ok_or(BeaconChainError::AttesterCachePtcOutOfBounds { slot, epoch })
}
}
}