Skip to content

Commit aa6a1bc

Browse files
committed
Create a custom penalize_sync_peer method for clarity
1 parent 27195ca commit aa6a1bc

File tree

4 files changed

+44
-21
lines changed

4 files changed

+44
-21
lines changed

beacon_node/beacon_chain/src/block_verification.rs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ pub enum ExecutionPayloadError {
418418
}
419419

420420
impl ExecutionPayloadError {
421-
pub fn penalize_peer(&self) -> bool {
421+
pub fn penalize_gossip_peer(&self) -> bool {
422422
// This match statement should never have a default case so that we are
423423
// always forced to consider here whether or not to penalize a peer when
424424
// we add a new error condition.
@@ -447,6 +447,39 @@ impl ExecutionPayloadError {
447447
ExecutionPayloadError::UnverifiedNonOptimisticCandidate => false,
448448
}
449449
}
450+
451+
pub fn penalize_sync_peer(&self) -> bool {
452+
// This match statement should never have a default case so that we are
453+
// always forced to consider here whether or not to penalize a peer when
454+
// we add a new error condition.
455+
match self {
456+
// The peer has nothing to do with this error, do not penalize them.
457+
ExecutionPayloadError::NoExecutionConnection => false,
458+
// The peer has nothing to do with this error, do not penalize them.
459+
ExecutionPayloadError::RequestFailed(_) => false,
460+
// For the sync case, we do not want a peer to keep sending us blocks that our
461+
// execution engine considers invalid.
462+
//
463+
// Also, we ask peers for blocks over sync/rpc only when they indicate
464+
// that they have fully validated a given block (using their status message).
465+
//
466+
// Hence, we should penalize for this error in the sync case.
467+
ExecutionPayloadError::RejectedByExecutionEngine { .. } => true,
468+
// There is no reason for an honest peer to propagate a block with an invalid
469+
// payload time stamp.
470+
ExecutionPayloadError::InvalidPayloadTimestamp { .. } => true,
471+
// We do not want to receive these blocks over rpc even though the gossip
472+
// case is still allowed.
473+
ExecutionPayloadError::InvalidTerminalPoWBlock { .. } => true,
474+
// We should penalize RPC blocks, since even an optimistic node shouldn't
475+
// verify this block.
476+
ExecutionPayloadError::InvalidActivationEpoch { .. } => true,
477+
// As per `Self::InvalidActivationEpoch`.
478+
ExecutionPayloadError::InvalidTerminalBlockHash { .. } => true,
479+
// Do not penalize the peer since it's not their fault that *we're* optimistic.
480+
ExecutionPayloadError::UnverifiedNonOptimisticCandidate => false,
481+
}
482+
}
450483
}
451484

452485
impl From<execution_layer::Error> for ExecutionPayloadError {

beacon_node/network/src/network_beacon_processor/gossip_methods.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1330,7 +1330,9 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
13301330
self.propagate_validation_result(message_id, peer_id, MessageAcceptance::Ignore);
13311331
return None;
13321332
}
1333-
Err(ref e @ BlockError::ExecutionPayloadError(ref epe)) if !epe.penalize_peer() => {
1333+
Err(ref e @ BlockError::ExecutionPayloadError(ref epe))
1334+
if !epe.penalize_gossip_peer() =>
1335+
{
13341336
debug!(error = %e, "Could not verify block for gossip. Ignoring the block");
13351337
self.propagate_validation_result(message_id, peer_id, MessageAcceptance::Ignore);
13361338
return None;
@@ -1562,7 +1564,7 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
15621564
"Block with unknown parent attempted to be processed"
15631565
);
15641566
}
1565-
Err(e @ BlockError::ExecutionPayloadError(epe)) if !epe.penalize_peer() => {
1567+
Err(e @ BlockError::ExecutionPayloadError(epe)) if !epe.penalize_gossip_peer() => {
15661568
debug!(
15671569
error = %e,
15681570
"Failed to verify execution payload"

beacon_node/network/src/network_beacon_processor/sync_methods.rs

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ use beacon_chain::data_availability_checker::AvailabilityCheckError;
1111
use beacon_chain::data_availability_checker::MaybeAvailableBlock;
1212
use beacon_chain::{
1313
AvailabilityProcessingStatus, BeaconChainTypes, BlockError, ChainSegmentResult,
14-
ExecutionPayloadError, HistoricalBlockError, NotifyExecutionLayer,
15-
validator_monitor::get_slot_delay_ms,
14+
HistoricalBlockError, NotifyExecutionLayer, validator_monitor::get_slot_delay_ms,
1615
};
1716
use beacon_processor::{
1817
AsyncFn, BlockingFn, DuplicateCache,
@@ -773,7 +772,7 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
773772
Err(ChainSegmentFailed {
774773
message: format!("Block has an unknown parent: {}", parent_root),
775774
// Peers are faulty if they send non-sequential blocks.
776-
peer_action: Some(PeerAction::LowToleranceError), // todo(pawan): revise this
775+
peer_action: Some(PeerAction::LowToleranceError),
777776
faulty_component: Some(FaultyComponent::Blocks),
778777
})
779778
}
@@ -852,20 +851,7 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
852851
})
853852
}
854853
ref err @ BlockError::ExecutionPayloadError(ref epe) => {
855-
if matches!(epe, ExecutionPayloadError::RejectedByExecutionEngine { .. }) {
856-
debug!(
857-
error = ?err,
858-
"Invalid execution payload rejected by EE"
859-
);
860-
Err(ChainSegmentFailed {
861-
message: format!(
862-
"Peer sent a block containing invalid execution payload. Reason: {:?}",
863-
err
864-
),
865-
peer_action: Some(PeerAction::LowToleranceError),
866-
faulty_component: Some(FaultyComponent::Blocks), // todo(pawan): recheck this
867-
})
868-
} else if !epe.penalize_peer() {
854+
if !epe.penalize_sync_peer() {
869855
// These errors indicate an issue with the EL and not the `ChainSegment`.
870856
// Pause the syncing while the EL recovers
871857
debug!(

beacon_node/network/src/sync/block_lookups/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,9 @@ impl<T: BeaconChainTypes> BlockLookups<T> {
617617
request_state.revert_to_awaiting_processing()?;
618618
Action::ParentUnknown { parent_root }
619619
}
620-
ref e @ BlockError::ExecutionPayloadError(ref epe) if !epe.penalize_peer() => {
620+
ref e @ BlockError::ExecutionPayloadError(ref epe)
621+
if !epe.penalize_sync_peer() =>
622+
{
621623
// These errors indicate that the execution layer is offline
622624
// and failed to validate the execution payload. Do not downscore peer.
623625
debug!(

0 commit comments

Comments
 (0)