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

tari-project / tari / 17033178607

18 Aug 2025 06:45AM UTC coverage: 54.49% (-0.007%) from 54.497%
17033178607

push

github

stringhandler
Merge branch 'development' of github.com:tari-project/tari into odev

971 of 2923 new or added lines in 369 files covered. (33.22%)

5804 existing lines in 173 files now uncovered.

76688 of 140739 relevant lines covered (54.49%)

193850.18 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/block_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 tari_common_types::types::FixedHashSizeError;
26
use tari_comms::{
27
    connectivity::ConnectivityError,
28
    peer_manager::NodeId,
29
    protocol::rpc::{RpcError, RpcStatus, RpcStatusCode},
30
};
31

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

38
#[derive(Debug, thiserror::Error)]
39
pub enum BlockSyncError {
40
    #[error("Async validation task failed: {0}")]
41
    AsyncTaskFailed(#[from] tokio::task::JoinError),
42
    #[error("RPC error: {0}")]
43
    RpcError(#[from] RpcError),
44
    #[error("RPC request failed: {0}")]
45
    RpcRequestError(#[from] RpcStatus),
46
    #[error("Chain storage error: {0}")]
47
    ChainStorageError(#[from] ChainStorageError),
48
    #[error("Peer sent a block that did not form a chain. Expected hash = {expected}, got = {got}")]
49
    BlockWithoutParent { expected: String, got: String },
50
    #[error("Connectivity Error: {0}")]
51
    ConnectivityError(#[from] ConnectivityError),
52
    #[error("No more sync peers available: {0}")]
53
    NoMoreSyncPeers(String),
54
    #[error("Block validation failed: {0}")]
55
    ValidationError(#[from] ValidationError),
56
    #[error("Failed to construct valid chain block")]
57
    FailedToConstructChainBlock,
58
    #[error("Peer sent unknown hash")]
59
    UnknownHeaderHash(String),
60
    #[error("Peer sent block with invalid block body")]
61
    InvalidBlockBody(String),
62
    #[error("Peer {peer} exceeded maximum permitted sync latency. latency: {latency:.2?}, max: {max_latency:.2?}")]
63
    MaxLatencyExceeded {
64
        peer: NodeId,
65
        latency: Duration,
66
        max_latency: Duration,
67
    },
68
    #[error("All sync peers exceeded max allowed latency")]
69
    AllSyncPeersExceedLatency,
70
    #[error("FixedHash size error: {0}")]
71
    FixedHashSizeError(#[from] FixedHashSizeError),
72
    #[error("This sync round failed")]
73
    SyncRoundFailed,
74
    #[error("Could not find peer info")]
75
    PeerNotFound,
76
    #[error("Peer did not supply all the blocks they claimed they had: {0}")]
77
    PeerDidNotSupplyAllClaimedBlocks(String),
78
}
79

80
impl BlockSyncError {
81
    pub fn to_short_str(&self) -> &'static str {
×
82
        match self {
×
83
            BlockSyncError::RpcError(_) => "RpcError",
×
84
            BlockSyncError::RpcRequestError(status) if status.as_status_code() == RpcStatusCode::Timeout => {
×
85
                "RpcTimeout"
×
86
            },
87
            BlockSyncError::RpcRequestError(_) => "RpcRequestError",
×
88
            BlockSyncError::AsyncTaskFailed(_) => "AsyncTaskFailed",
×
89
            BlockSyncError::ChainStorageError(_) => "ChainStorageError",
×
90
            BlockSyncError::BlockWithoutParent { .. } => "PeerSentBlockThatDidNotFormAChain",
×
91
            BlockSyncError::ConnectivityError(_) => "ConnectivityError",
×
92
            BlockSyncError::NoMoreSyncPeers(_) => "NoMoreSyncPeers",
×
93
            BlockSyncError::ValidationError(_) => "ValidationError",
×
94
            BlockSyncError::FailedToConstructChainBlock => "FailedToConstructChainBlock",
×
95
            BlockSyncError::UnknownHeaderHash(_) => "UnknownHeaderHash",
×
96
            BlockSyncError::InvalidBlockBody(_) => "InvalidBlockBody",
×
97
            BlockSyncError::MaxLatencyExceeded { .. } => "MaxLatencyExceeded",
×
98
            BlockSyncError::AllSyncPeersExceedLatency => "AllSyncPeersExceedLatency",
×
99
            BlockSyncError::FixedHashSizeError(_) => "FixedHashSizeError",
×
100
            BlockSyncError::SyncRoundFailed => "SyncRoundFailed",
×
101
            BlockSyncError::PeerNotFound => "PeerNotFound",
×
102
            BlockSyncError::PeerDidNotSupplyAllClaimedBlocks(_) => "PeerDidNotSupplyAllClaimedBlocks",
×
103
        }
104
    }
×
105
}
106

107
impl BlockSyncError {
108
    pub fn get_ban_reason(&self) -> Option<BanReason> {
×
109
        match self {
×
110
            // no ban
111
            BlockSyncError::AsyncTaskFailed(_) |
112
            BlockSyncError::ConnectivityError(_) |
113
            BlockSyncError::NoMoreSyncPeers(_) |
114
            BlockSyncError::AllSyncPeersExceedLatency |
115
            BlockSyncError::FailedToConstructChainBlock |
116
            BlockSyncError::PeerNotFound |
117
            BlockSyncError::SyncRoundFailed => None,
×
118
            BlockSyncError::ChainStorageError(e) => e.get_ban_reason(),
×
119
            // short ban
120
            err @ BlockSyncError::MaxLatencyExceeded { .. } |
×
121
            err @ BlockSyncError::PeerDidNotSupplyAllClaimedBlocks(_) |
×
122
            err @ BlockSyncError::RpcError(_) |
×
123
            err @ BlockSyncError::RpcRequestError(_) => Some(BanReason {
×
NEW
124
                reason: format!("{err}"),
×
125
                ban_duration: BanPeriod::Short,
×
126
            }),
×
127

128
            // long ban
129
            err @ BlockSyncError::BlockWithoutParent { .. } |
×
130
            err @ BlockSyncError::UnknownHeaderHash(_) |
×
131
            err @ BlockSyncError::InvalidBlockBody(_) |
×
132
            err @ BlockSyncError::FixedHashSizeError(_) => Some(BanReason {
×
NEW
133
                reason: format!("{err}"),
×
134
                ban_duration: BanPeriod::Long,
×
135
            }),
×
136

137
            BlockSyncError::ValidationError(err) => ValidationError::get_ban_reason(err),
×
138
        }
139
    }
×
140
}
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