• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

tari-project / tari / 16990089413

15 Aug 2025 12:36PM UTC coverage: 54.497% (+0.06%) from 54.441%
16990089413

push

github

web-flow
chore: cleanup indexes (#7411)

Description
---
Forces clean indexs

970 of 2919 new or added lines in 369 files covered. (33.23%)

60 existing lines in 33 files now uncovered.

76698 of 140739 relevant lines covered (54.5%)

193749.86 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/base_layer/core/src/base_node/sync/header_sync/error.rs
1
//  Copyright 2020, The Tari Project
2
//
3
//  Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
4
//  following conditions are met:
5
//
6
//  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following
7
//  disclaimer.
8
//
9
//  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
10
//  following disclaimer in the documentation and/or other materials provided with the distribution.
11
//
12
//  3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote
13
//  products derived from this software without specific prior written permission.
14
//
15
//  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
16
//  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17
//  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
18
//  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19
//  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
20
//  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
21
//  USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22

23
use std::time::Duration;
24

25
use primitive_types::U512;
26
use tari_comms::{
27
    connectivity::ConnectivityError,
28
    peer_manager::NodeId,
29
    protocol::rpc::{RpcError, RpcStatus},
30
};
31

32
use crate::{
33
    blocks::BlockError,
34
    chain_storage::ChainStorageError,
35
    common::{BanPeriod, BanReason},
36
    validation::ValidationError,
37
};
38

39
#[derive(Debug, thiserror::Error)]
40
pub enum BlockHeaderSyncError {
41
    #[error("No more sync peers available: {0}")]
42
    NoMoreSyncPeers(String),
43
    #[error("Could not find peer info")]
44
    PeerNotFound,
45
    #[error("RPC error: {0}")]
46
    RpcError(#[from] RpcError),
47
    #[error("RPC request failed: {0}")]
48
    RpcRequestError(#[from] RpcStatus),
49
    #[error("Peer sent invalid header: {0}")]
50
    ReceivedInvalidHeader(String),
51
    #[error("Chain storage error: {0}")]
52
    ChainStorageError(#[from] ChainStorageError),
53
    #[error("Validation failed: {0}")]
54
    ValidationFailed(#[from] ValidationError),
55
    #[error("Sync failed for all peers")]
56
    SyncFailedAllPeers,
57
    #[error("Peer sent a found hash index that was out of range (Expected less than {0}, Found: {1})")]
58
    FoundHashIndexOutOfRange(u64, u64),
59
    #[error("Failed to ban peer: {0}")]
60
    FailedToBan(ConnectivityError),
61
    #[error("Connectivity Error: {0}")]
62
    ConnectivityError(#[from] ConnectivityError),
63
    #[error("Node is still not in sync. Sync will be retried with another peer if possible.")]
64
    NotInSync,
65
    #[error("Unable to locate start hash `{0}`")]
66
    StartHashNotFound(String),
67
    #[error("Expected header height {expected} got {actual}")]
68
    InvalidBlockHeight { expected: u64, actual: u64 },
69
    #[error("Unable to find chain split from peer `{0}`")]
70
    ChainSplitNotFound(NodeId),
71
    #[error("Invalid protocol response: {0}")]
72
    InvalidProtocolResponse(String),
73
    #[error("Header at height {height} did not form a chain. Expected {actual} to equal the previous hash {expected}")]
74
    ChainLinkBroken {
75
        height: u64,
76
        actual: String,
77
        expected: String,
78
    },
79
    #[error("Block error: {0}")]
80
    BlockError(#[from] BlockError),
81
    #[error(
82
        "Peer claimed a stronger chain than they were able to provide. Claimed {claimed}, Actual: {actual:?}, local: \
83
         {local}"
84
    )]
85
    PeerSentInaccurateChainMetadata {
86
        claimed: U512,
87
        actual: Option<U512>,
88
        local: U512,
89
    },
90
    #[error("This peer sent too many headers ({0}) in response to a chain split request")]
91
    PeerSentTooManyHeaders(usize),
92
    #[error("Peer {peer} exceeded maximum permitted sync latency. latency: {latency:.2?}s, max: {max_latency:.2?}s")]
93
    MaxLatencyExceeded {
94
        peer: NodeId,
95
        latency: Duration,
96
        max_latency: Duration,
97
    },
98
    #[error("All sync peers exceeded max allowed latency")]
99
    AllSyncPeersExceedLatency,
100
    #[error("Unable to get TargetDifficulties: ({0})")]
101
    TargetDifficultiesError(String),
102
}
103

104
impl BlockHeaderSyncError {
105
    pub fn get_ban_reason(&self) -> Option<BanReason> {
×
106
        match self {
×
107
            // no ban
108
            BlockHeaderSyncError::NoMoreSyncPeers(_) |
109
            BlockHeaderSyncError::SyncFailedAllPeers |
110
            BlockHeaderSyncError::FailedToBan(_) |
111
            BlockHeaderSyncError::AllSyncPeersExceedLatency |
112
            BlockHeaderSyncError::ConnectivityError(_) |
113
            BlockHeaderSyncError::NotInSync |
114
            BlockHeaderSyncError::TargetDifficultiesError(_) |
115
            BlockHeaderSyncError::PeerNotFound => None,
×
116
            BlockHeaderSyncError::ChainStorageError(e) => e.get_ban_reason(),
×
117

118
            // short ban
119
            err @ BlockHeaderSyncError::MaxLatencyExceeded { .. } |
×
120
            err @ BlockHeaderSyncError::RpcError { .. } |
×
121
            err @ BlockHeaderSyncError::RpcRequestError { .. } => Some(BanReason {
×
NEW
122
                reason: format!("{err}"),
×
123
                ban_duration: BanPeriod::Short,
×
124
            }),
×
125

126
            // long ban
127
            err @ BlockHeaderSyncError::ReceivedInvalidHeader(_) |
×
128
            err @ BlockHeaderSyncError::FoundHashIndexOutOfRange(_, _) |
×
129
            err @ BlockHeaderSyncError::StartHashNotFound(_) |
×
130
            err @ BlockHeaderSyncError::InvalidBlockHeight { .. } |
×
131
            err @ BlockHeaderSyncError::ChainSplitNotFound(_) |
×
132
            err @ BlockHeaderSyncError::InvalidProtocolResponse(_) |
×
133
            err @ BlockHeaderSyncError::ChainLinkBroken { .. } |
×
134
            err @ BlockHeaderSyncError::BlockError(_) |
×
135
            err @ BlockHeaderSyncError::PeerSentInaccurateChainMetadata { .. } |
×
136
            err @ BlockHeaderSyncError::PeerSentTooManyHeaders(_) => Some(BanReason {
×
NEW
137
                reason: format!("{err}"),
×
138
                ban_duration: BanPeriod::Long,
×
139
            }),
×
140

141
            BlockHeaderSyncError::ValidationFailed(err) => ValidationError::get_ban_reason(err),
×
142
        }
143
    }
×
144
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc