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

tari-project / tari / 17275382059

27 Aug 2025 06:28PM UTC coverage: 60.14% (-0.1%) from 60.274%
17275382059

push

github

web-flow
chore: new release v5.0.0-pre.8 (#7446)

Description
---
new release

71505 of 118897 relevant lines covered (60.14%)

536444.51 hits per line

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

0.0
/base_layer/core/src/base_node/comms_interface/error.rs
1
// Copyright 2019. 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 tari_common_types::types::FixedHash;
24
use tari_comms_dht::outbound::DhtOutboundError;
25
use tari_node_components::blocks::BlockHeaderValidationError;
26
use tari_service_framework::reply_channel::TransportChannelError;
27
use tari_transaction_components::{
28
    consensus::ConsensusManagerError,
29
    tari_proof_of_work::DifficultyError,
30
    transaction_components::TransactionError,
31
    BanPeriod,
32
    BanReason,
33
};
34
use thiserror::Error;
35

36
use crate::{
37
    blocks::BlockError,
38
    chain_storage::ChainStorageError,
39
    mempool::MempoolError,
40
    proof_of_work::{cuckaroo_pow::CuckarooVerificationError, monero_rx::MergeMineError},
41
};
42

43
#[derive(Debug, Error)]
44
pub enum CommsInterfaceError {
45
    #[error("Received an unexpected response from a remote peer")]
46
    UnexpectedApiResponse,
47
    #[error("Request timed out")]
48
    RequestTimedOut,
49
    #[error("No bootstrap nodes have been configured")]
50
    NoBootstrapNodesConfigured,
51
    #[error("Transport channel error: {0}")]
52
    TransportChannelError(#[from] TransportChannelError),
53
    #[error("Chain storage error: {0}")]
54
    ChainStorageError(#[from] ChainStorageError),
55
    #[error("Failed to send outbound message: {0}")]
56
    OutboundMessageError(#[from] DhtOutboundError),
57
    #[error("Mempool error: {0}")]
58
    MempoolError(#[from] MempoolError),
59
    #[error("Failed to broadcast message")]
60
    BroadcastFailed,
61
    #[error("Internal channel error: {0}")]
62
    InternalChannelError(String),
63
    #[error("Difficulty adjustment error: {0}")]
64
    DifficultyAdjustmentManagerError(#[from] ConsensusManagerError),
65
    #[error("Invalid peer response: {0}")]
66
    InvalidPeerResponse(String),
67
    #[error("Invalid Block Header: {0}")]
68
    InvalidBlockHeader(#[from] BlockHeaderValidationError),
69
    #[error("Internal error:{0}")]
70
    InternalError(String),
71
    #[error("API responded with an error: {0}")]
72
    ApiError(String),
73
    #[error("Block error: {0}")]
74
    BlockError(#[from] BlockError),
75
    #[error("Invalid request for {request}: {details}")]
76
    InvalidRequest { request: &'static str, details: String },
77
    #[error("Peer sent invalid full block {hash}: {details}")]
78
    InvalidFullBlock { hash: FixedHash, details: String },
79
    #[error("Invalid merge mined block: {0}")]
80
    MergeMineError(#[from] MergeMineError),
81
    #[error("Invalid difficulty: {0}")]
82
    DifficultyError(#[from] DifficultyError),
83
    #[error("Transaction error: {0}")]
84
    TransactionError(#[from] TransactionError),
85
    #[error("Cuckaroo verification error: {0}")]
86
    CuckarooVerificationError(#[from] CuckarooVerificationError),
87
}
88

89
impl CommsInterfaceError {
90
    pub fn get_ban_reason(&self) -> Option<BanReason> {
×
91
        match self {
×
92
            err @ CommsInterfaceError::UnexpectedApiResponse |
×
93
            err @ CommsInterfaceError::RequestTimedOut |
×
94
            err @ CommsInterfaceError::TransportChannelError(_) => Some(BanReason {
×
95
                reason: err.to_string(),
×
96
                ban_duration: BanPeriod::Short,
×
97
            }),
×
98
            err @ CommsInterfaceError::InvalidPeerResponse(_) |
×
99
            err @ CommsInterfaceError::InvalidBlockHeader(_) |
×
100
            err @ CommsInterfaceError::TransactionError(_) |
×
101
            err @ CommsInterfaceError::CuckarooVerificationError(_) |
×
102
            err @ CommsInterfaceError::InvalidFullBlock { .. } |
×
103
            err @ CommsInterfaceError::InvalidRequest { .. } => Some(BanReason {
×
104
                reason: err.to_string(),
×
105
                ban_duration: BanPeriod::Long,
×
106
            }),
×
107
            CommsInterfaceError::MempoolError(e) => e.get_ban_reason(),
×
108
            CommsInterfaceError::ChainStorageError(e) => e.get_ban_reason(),
×
109
            CommsInterfaceError::MergeMineError(e) => e.get_ban_reason(),
×
110
            CommsInterfaceError::NoBootstrapNodesConfigured |
111
            CommsInterfaceError::OutboundMessageError(_) |
112
            CommsInterfaceError::BroadcastFailed |
113
            CommsInterfaceError::InternalChannelError(_) |
114
            CommsInterfaceError::DifficultyAdjustmentManagerError(_) |
115
            CommsInterfaceError::InternalError(_) |
116
            CommsInterfaceError::ApiError(_) |
117
            CommsInterfaceError::BlockError(_) |
118
            // CommsInterfaceError::Other(_) |
119
            CommsInterfaceError::DifficultyError(_) => None,
×
120
        }
121
    }
×
122
}
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