• 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/horizon_state_sync/error.rs
1
//  Copyright 2022, 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::{num::TryFromIntError, 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},
30
};
31
use tari_crypto::errors::RangeProofError;
32
use tari_mmr::error::MerkleMountainRangeError;
33
use tari_utilities::ByteArrayError;
34
use thiserror::Error;
35
use tokio::task;
36

37
use crate::{
38
    chain_storage::ChainStorageError,
39
    common::{BanPeriod, BanReason},
40
    transactions::transaction_components::TransactionError,
41
    validation::ValidationError,
42
    MrHashError,
43
};
44

45
#[derive(Debug, Error)]
46
pub enum HorizonSyncError {
47
    #[error("Peer sent an invalid response: {0}")]
48
    IncorrectResponse(String),
49
    #[error("Chain storage error: {0}")]
50
    ChainStorageError(#[from] ChainStorageError),
51
    #[error("Final state validation failed: {0}")]
52
    FinalStateValidationFailed(ValidationError),
53
    #[error("Join error: {0}")]
54
    JoinError(#[from] task::JoinError),
55
    #[error("A range proof verification has produced an error: {0}")]
56
    RangeProofError(String),
57
    #[error("An invalid transaction has been encountered: {0}")]
58
    TransactionError(#[from] TransactionError),
59
    #[error(
60
        "Merkle root did not match for {mr_tree} at height {at_height}. Expected {actual_hex} to equal {expected_hex}"
61
    )]
62
    InvalidMrRoot {
63
        mr_tree: String,
64
        at_height: u64,
65
        expected_hex: String,
66
        actual_hex: String,
67
    },
68
    #[error("Invalid MMR position {mmr_position} at height {at_height}")]
69
    InvalidMmrPosition { at_height: u64, mmr_position: u64 },
70
    #[error("RPC error: {0}")]
71
    RpcError(#[from] RpcError),
72
    #[error("RPC status: {0}")]
73
    RpcStatus(#[from] RpcStatus),
74
    #[error("Could not convert data:{0}")]
75
    ConversionError(String),
76
    #[error("MerkleMountainRangeError: {0}")]
77
    MerkleMountainRangeError(#[from] MerkleMountainRangeError),
78
    #[error("Connectivity error: {0}")]
79
    ConnectivityError(#[from] ConnectivityError),
80
    #[error("Validation error: {0}")]
81
    ValidationError(#[from] ValidationError),
82
    #[error("No sync peers")]
83
    NoSyncPeers,
84
    #[error("Sync failed for all peers")]
85
    FailedSyncAllPeers,
86
    #[error("Peer {peer} exceeded maximum permitted sync latency. latency: {latency:.2?}s, max: {max_latency:.2?}s")]
87
    MaxLatencyExceeded {
88
        peer: NodeId,
89
        latency: Duration,
90
        max_latency: Duration,
91
    },
92
    #[error("All sync peers exceeded max allowed latency")]
93
    AllSyncPeersExceedLatency,
94
    #[error("FixedHash size error: {0}")]
95
    FixedHashSizeError(#[from] FixedHashSizeError),
96
    #[error("No more sync peers available: {0}")]
97
    NoMoreSyncPeers(String),
98
    #[error("Could not find peer info")]
99
    PeerNotFound,
100
    #[error("Sparse Merkle Tree error: {0}")]
101
    SMTError(anyhow::Error),
102
    #[error("ByteArrayError error: {0}")]
103
    ByteArrayError(String),
104
    #[error("FixedHash size error: {0}")]
105
    MrHashError(#[from] MrHashError),
106
}
107

108
impl From<ByteArrayError> for HorizonSyncError {
109
    fn from(e: ByteArrayError) -> Self {
×
110
        HorizonSyncError::ByteArrayError(e.to_string())
×
111
    }
×
112
}
113

114
impl From<TryFromIntError> for HorizonSyncError {
115
    fn from(err: TryFromIntError) -> Self {
×
116
        HorizonSyncError::ConversionError(err.to_string())
×
117
    }
×
118
}
119

120
impl From<RangeProofError> for HorizonSyncError {
121
    fn from(e: RangeProofError) -> Self {
×
122
        HorizonSyncError::RangeProofError(e.to_string())
×
123
    }
×
124
}
125

126
impl HorizonSyncError {
127
    pub fn get_ban_reason(&self) -> Option<BanReason> {
×
128
        match self {
×
129
            // no ban
130
            HorizonSyncError::ChainStorageError(e) => e.get_ban_reason(),
×
131
            HorizonSyncError::NoSyncPeers |
132
            HorizonSyncError::FailedSyncAllPeers |
133
            HorizonSyncError::AllSyncPeersExceedLatency |
134
            HorizonSyncError::ConnectivityError(_) |
135
            HorizonSyncError::NoMoreSyncPeers(_) |
136
            HorizonSyncError::PeerNotFound |
137
            HorizonSyncError::JoinError(_) |
138
            HorizonSyncError::MrHashError(_) => None,
×
139

140
            // short ban
141
            err @ HorizonSyncError::MaxLatencyExceeded { .. } |
×
142
            err @ HorizonSyncError::RpcError { .. } |
×
143
            err @ HorizonSyncError::RpcStatus { .. } => Some(BanReason {
×
NEW
144
                reason: format!("{err}"),
×
145
                ban_duration: BanPeriod::Short,
×
146
            }),
×
147

148
            // long ban
149
            err @ HorizonSyncError::IncorrectResponse(_) |
×
150
            err @ HorizonSyncError::FinalStateValidationFailed(_) |
×
151
            err @ HorizonSyncError::RangeProofError(_) |
×
152
            err @ HorizonSyncError::InvalidMrRoot { .. } |
×
153
            err @ HorizonSyncError::SMTError(_) |
×
154
            err @ HorizonSyncError::InvalidMmrPosition { .. } |
×
155
            err @ HorizonSyncError::ConversionError(_) |
×
156
            err @ HorizonSyncError::MerkleMountainRangeError(_) |
×
157
            err @ HorizonSyncError::FixedHashSizeError(_) |
×
158
            err @ HorizonSyncError::TransactionError(_) |
×
159
            err @ HorizonSyncError::ByteArrayError(_) => Some(BanReason {
×
NEW
160
                reason: format!("{err}"),
×
161
                ban_duration: BanPeriod::Long,
×
162
            }),
×
163

164
            HorizonSyncError::ValidationError(err) => ValidationError::get_ban_reason(err),
×
165
        }
166
    }
×
167
}
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