Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add consistent ban reason for sync #5729

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions base_layer/core/src/base_node/sync/block_sync/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ impl BlockSyncError {
impl BlockSyncError {
pub fn get_ban_reason(&self, short_ban: Duration, long_ban: Duration) -> Option<BanReason> {
match self {
// no ban
BlockSyncError::AsyncTaskFailed(_) |
BlockSyncError::RpcError(_) |
BlockSyncError::RpcRequestError(_) |
Expand All @@ -107,11 +108,13 @@ impl BlockSyncError {
BlockSyncError::FailedToConstructChainBlock |
BlockSyncError::SyncRoundFailed => None,

// short ban
err @ BlockSyncError::MaxLatencyExceeded { .. } => Some(BanReason {
reason: format!("{}", err),
ban_duration: short_ban,
}),

// long ban
err @ BlockSyncError::BlockWithoutParent { .. } |
err @ BlockSyncError::UnknownHeaderHash(_) |
err @ BlockSyncError::InvalidBlockBody(_) |
Expand Down
3 changes: 2 additions & 1 deletion base_layer/core/src/base_node/sync/header_sync/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ impl BlockHeaderSyncError {

// long ban
err @ BlockHeaderSyncError::ReceivedInvalidHeader(_) |
err @ BlockHeaderSyncError::ValidationFailed(_) |
err @ BlockHeaderSyncError::FoundHashIndexOutOfRange(_, _) |
err @ BlockHeaderSyncError::StartHashNotFound(_) |
err @ BlockHeaderSyncError::InvalidBlockHeight { .. } |
Expand All @@ -126,6 +125,8 @@ impl BlockHeaderSyncError {
reason: format!("{}", err),
ban_duration: long_ban,
}),

BlockHeaderSyncError::ValidationFailed(err) => ValidationError::get_ban_reason(err, Some(long_ban)),
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,13 @@ impl HorizonSyncError {
err @ HorizonSyncError::InvalidMmrPosition { .. } |
err @ HorizonSyncError::ConversionError(_) |
err @ HorizonSyncError::MerkleMountainRangeError(_) |
err @ HorizonSyncError::ValidationError(_) |
err @ HorizonSyncError::FixedHashSizeError(_) |
err @ HorizonSyncError::TransactionError(_) => Some(BanReason {
reason: format!("{}", err),
ban_duration: long_ban,
}),

HorizonSyncError::ValidationError(err) => ValidationError::get_ban_reason(err, Some(long_ban)),
}
}
}
5 changes: 4 additions & 1 deletion comms/dht/src/store_forward/saf_handler/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,10 @@ where S: Service<DecryptedDhtMessage, Response = (), Error = PipelineError>
.validate_and_decrypt_incoming_stored_message(Arc::clone(&source_peer), msg)
.await;

let Some(result) = self.process_saf_message_validation_result(&source_peer.public_key, result).await else {
let Some(result) = self
.process_saf_message_validation_result(&source_peer.public_key, result)
.await
else {
// Logging of problems and banning are done inside process_saf_message. We can simply continue
continue;
};
Expand Down