Skip to content

Commit

Permalink
feat: remove duplicate errors (#5009)
Browse files Browse the repository at this point in the history
Description
---
Remove duplicate error

Motivation and Context
---
We have the same error that's logged under a different name

How Has This Been Tested?
---
Unit tests

Fixes: https://github.com/orgs/tari-project/projects/3/views/1
  • Loading branch information
SWvheerden authored Dec 8, 2022
1 parent a0f1d95 commit 0c9477b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 28 deletions.
5 changes: 0 additions & 5 deletions base_layer/core/src/base_node/sync/header_sync/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@ pub enum BlockHeaderSyncError {
FailedToBan(ConnectivityError),
#[error("Connectivity Error: {0}")]
ConnectivityError(#[from] ConnectivityError),
#[error(
"Peer could not provide a stronger chain than the local chain. Claimed was {claimed} but validated was \
{actual} (local: {local})"
)]
WeakerChain { claimed: u128, actual: u128, local: u128 },
#[error("Node is still not in sync. Sync will be retried with another peer if possible.")]
NotInSync,
#[error("Unable to locate start hash `{0}`")]
Expand Down
27 changes: 4 additions & 23 deletions base_layer/core/src/base_node/sync/header_sync/synchronizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,20 +208,6 @@ impl<'a, B: BlockchainBackend + 'static> HeaderSynchronizer<'a, B> {
warn!(target: LOG_TARGET, "Chain link broken: {}", reason);
self.ban_peer_long(node_id, reason).await?;
},
Err(ref err @ BlockHeaderSyncError::WeakerChain { claimed, actual, local }) => {
warn!(target: LOG_TARGET, "{}", err);
self.ban_peer_long(node_id, BanReason::PeerCouldNotProvideStrongerChain {
claimed,
actual,
local,
})
.await?;
},
Err(err @ BlockHeaderSyncError::InvalidBlockHeight { .. }) => {
warn!(target: LOG_TARGET, "{}", err);
self.ban_peer_long(node_id, BanReason::GeneralHeaderSyncFailure(err))
.await?;
},
Err(err @ BlockHeaderSyncError::RpcError(RpcError::ReplyTimeout)) |
Err(err @ BlockHeaderSyncError::MaxLatencyExceeded { .. }) => {
warn!(target: LOG_TARGET, "{}", err);
Expand Down Expand Up @@ -604,9 +590,9 @@ impl<'a, B: BlockchainBackend + 'static> HeaderSynchronizer<'a, B> {
// headers.
debug!(target: LOG_TARGET, "No further headers to download");
if !has_better_pow {
return Err(BlockHeaderSyncError::WeakerChain {
return Err(BlockHeaderSyncError::PeerSentInaccurateChainMetadata {
claimed: sync_peer.claimed_chain_metadata().accumulated_difficulty(),
actual: total_accumulated_difficulty,
actual: Some(total_accumulated_difficulty),
local: split_info
.local_tip_header
.accumulated_data()
Expand Down Expand Up @@ -702,13 +688,12 @@ impl<'a, B: BlockchainBackend + 'static> HeaderSynchronizer<'a, B> {
}

if !has_switched_to_new_chain {
return Err(BlockHeaderSyncError::WeakerChain {
return Err(BlockHeaderSyncError::PeerSentInaccurateChainMetadata {
claimed: sync_peer.claimed_chain_metadata().accumulated_difficulty(),
actual: self
.header_validator
.current_valid_chain_tip_header()
.map(|h| h.accumulated_data().total_accumulated_difficulty)
.unwrap_or(0),
.map(|h| h.accumulated_data().total_accumulated_difficulty),
local: split_info
.local_tip_header
.accumulated_data()
Expand Down Expand Up @@ -821,10 +806,6 @@ enum BanReason {
GeneralHeaderSyncFailure(BlockHeaderSyncError),
#[error("Peer did not respond timeously during RPC negotiation")]
RpcNegotiationTimedOut,
#[error(
"Peer claimed an accumulated difficulty of {claimed} but validated difficulty was {actual} <= local: {local}"
)]
PeerCouldNotProvideStrongerChain { claimed: u128, actual: u128, local: u128 },
#[error("Header at height {height} did not form a chain. Expected {actual} to equal the previous hash {expected}")]
ChainLinkBroken {
height: u64,
Expand Down

0 comments on commit 0c9477b

Please sign in to comment.