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

tari-project / tari / 16123384529

07 Jul 2025 05:11PM UTC coverage: 64.327% (-7.6%) from 71.89%
16123384529

push

github

web-flow
chore: new release v4.9.0-pre.0 (#7289)

Description
---
new release esmeralda

77151 of 119935 relevant lines covered (64.33%)

227108.34 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_service_framework::reply_channel::TransportChannelError;
26
use thiserror::Error;
27

28
use crate::{
29
    blocks::{BlockError, BlockHeaderValidationError},
30
    chain_storage::ChainStorageError,
31
    common::{BanPeriod, BanReason},
32
    consensus::ConsensusManagerError,
33
    mempool::MempoolError,
34
    proof_of_work::{monero_rx::MergeMineError, DifficultyError},
35
    transactions::transaction_components::TransactionError,
36
};
37

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

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