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, request_epoch: Epoch,
cache_epoch: Epoch, cache_epoch: Epoch,
}, },
AttesterCachePtcOutOfBounds {
slot: Slot,
epoch: Epoch,
},
AttesterCacheNoPtcPreGloas {
slot: Slot,
},
SkipProposerPreparation, SkipProposerPreparation,
FailedColumnCustodyInfoUpdate, FailedColumnCustodyInfoUpdate,
} }

View File

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

View File

@@ -66,12 +66,6 @@ pub enum Error {
/// ///
/// The peer has sent an invalid message. /// The peer has sent an invalid message.
NotInPTC { validator_index: u64, slot: Slot }, 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. /// The validator index is unknown.
/// ///
/// ## Peer scoring /// ## 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 { match &self.ptcs {
CachedPTCs::PreGloas => None, // Should we error here? CachedPTCs::PreGloas => Err(BeaconChainError::AttesterCacheNoPtcPreGloas { slot }),
CachedPTCs::PostGloas(ptcs, epoch) => { &CachedPTCs::PostGloas(ref ptcs, epoch) => {
if slot.epoch(E::slots_per_epoch()) != *epoch { if slot.epoch(E::slots_per_epoch()) != epoch {
None // Also we should error here? Err(BeaconChainError::AttesterCachePtcOutOfBounds { slot, epoch })
} else { } else {
// Note: This may return Option also if construction was buggy
ptcs.get(slot.as_usize() % E::slots_per_epoch() as usize) ptcs.get(slot.as_usize() % E::slots_per_epoch() as usize)
.cloned()
.ok_or(BeaconChainError::AttesterCachePtcOutOfBounds { slot, epoch })
} }
} }
} }

View File

@@ -4254,8 +4254,7 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
"payload_attn_invalid_sig", "payload_attn_invalid_sig",
); );
} }
PayloadAttestationError::MissingPTC { .. } PayloadAttestationError::BeaconChainError(_) => {
| PayloadAttestationError::BeaconChainError(_) => {
debug!( debug!(
%peer_id, %peer_id,
%message_slot, %message_slot,