mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-30 04:37:13 +00:00
Improve error handling
This commit is contained in:
@@ -254,6 +254,13 @@ pub enum BeaconChainError {
|
||||
request_epoch: Epoch,
|
||||
cache_epoch: Epoch,
|
||||
},
|
||||
AttesterCachePtcOutOfBounds {
|
||||
slot: Slot,
|
||||
epoch: Epoch,
|
||||
},
|
||||
AttesterCacheNoPtcPreGloas {
|
||||
slot: Slot,
|
||||
},
|
||||
SkipProposerPreparation,
|
||||
FailedColumnCustodyInfoUpdate,
|
||||
}
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4254,8 +4254,7 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
|
||||
"payload_attn_invalid_sig",
|
||||
);
|
||||
}
|
||||
PayloadAttestationError::MissingPTC { .. }
|
||||
| PayloadAttestationError::BeaconChainError(_) => {
|
||||
PayloadAttestationError::BeaconChainError(_) => {
|
||||
debug!(
|
||||
%peer_id,
|
||||
%message_slot,
|
||||
|
||||
Reference in New Issue
Block a user