diff --git a/beacon_node/beacon_chain/src/errors.rs b/beacon_node/beacon_chain/src/errors.rs index 19e0c693c2..99ee82acb3 100644 --- a/beacon_node/beacon_chain/src/errors.rs +++ b/beacon_node/beacon_chain/src/errors.rs @@ -254,6 +254,13 @@ pub enum BeaconChainError { request_epoch: Epoch, cache_epoch: Epoch, }, + AttesterCachePtcOutOfBounds { + slot: Slot, + epoch: Epoch, + }, + AttesterCacheNoPtcPreGloas { + slot: Slot, + }, SkipProposerPreparation, FailedColumnCustodyInfoUpdate, } diff --git a/beacon_node/beacon_chain/src/payload_attestation_verification/gossip_verified_payload_attestation.rs b/beacon_node/beacon_chain/src/payload_attestation_verification/gossip_verified_payload_attestation.rs index f0f410554e..ec7d7121bd 100644 --- a/beacon_node/beacon_chain/src/payload_attestation_verification/gossip_verified_payload_attestation.rs +++ b/beacon_node/beacon_chain/src/payload_attestation_verification/gossip_verified_payload_attestation.rs @@ -87,9 +87,8 @@ impl VerifiedPayloadAttestationMessage { 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)) { diff --git a/beacon_node/beacon_chain/src/payload_attestation_verification/mod.rs b/beacon_node/beacon_chain/src/payload_attestation_verification/mod.rs index 3c0efce6ed..89ae1bbbdd 100644 --- a/beacon_node/beacon_chain/src/payload_attestation_verification/mod.rs +++ b/beacon_node/beacon_chain/src/payload_attestation_verification/mod.rs @@ -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 diff --git a/beacon_node/beacon_chain/src/shuffling_cache.rs b/beacon_node/beacon_chain/src/shuffling_cache.rs index 01513a41fd..129291587f 100644 --- a/beacon_node/beacon_chain/src/shuffling_cache.rs +++ b/beacon_node/beacon_chain/src/shuffling_cache.rs @@ -72,15 +72,16 @@ impl CachedShuffling { } } - pub fn ptc_for_slot(&self, slot: Slot) -> Option<&PTC> { + pub fn ptc_for_slot(&self, slot: Slot) -> Result, 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 }) } } } diff --git a/beacon_node/network/src/network_beacon_processor/gossip_methods.rs b/beacon_node/network/src/network_beacon_processor/gossip_methods.rs index 71ee6b7ec2..e4291bd8d9 100644 --- a/beacon_node/network/src/network_beacon_processor/gossip_methods.rs +++ b/beacon_node/network/src/network_beacon_processor/gossip_methods.rs @@ -4254,8 +4254,7 @@ impl NetworkBeaconProcessor { "payload_attn_invalid_sig", ); } - PayloadAttestationError::MissingPTC { .. } - | PayloadAttestationError::BeaconChainError(_) => { + PayloadAttestationError::BeaconChainError(_) => { debug!( %peer_id, %message_slot,