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

tari-project / tari / 15141300802

20 May 2025 03:12PM UTC coverage: 73.198% (-0.02%) from 73.213%
15141300802

push

github

web-flow
chore: new release v3.0.0-pre.0 (#7071)

Description
---
new release esme

82074 of 112126 relevant lines covered (73.2%)

274087.29 hits per line

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

0.0
/base_layer/core/src/proof_of_work/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 thiserror::Error;
24

25
#[cfg(feature = "base_node")]
26
use crate::proof_of_work::monero_rx::MergeMineError;
27
use crate::{
28
    common::{BanPeriod, BanReason},
29
    proof_of_work::Difficulty,
30
};
31

32
/// Errors that can occur when validating a proof of work
33
#[derive(Debug, Error)]
34
pub enum PowError {
35
    #[error("ProofOfWorkFailed")]
36
    InvalidProofOfWork,
37
    #[error("Achieved difficulty is below the minimum")]
38
    AchievedDifficultyBelowMin,
39
    #[error("Proof of work data must be empty for Sha3 blocks")]
40
    Sha3HeaderNonEmptyPowBytes,
41
    #[error("Proof of work data is too long. Max allowed is 32 bytes")]
42
    RandomxTPowDataTooLong,
43
    #[error("Target difficulty {target} not achieved. Achieved difficulty: {achieved}")]
44
    AchievedDifficultyTooLow { target: Difficulty, achieved: Difficulty },
45
    #[error("Invalid target difficulty (expected: {expected}, got: {got})")]
46
    InvalidTargetDifficulty { expected: Difficulty, got: Difficulty },
47
    #[cfg(feature = "base_node")]
48
    #[error("Invalid merge mining data or operation: {0}")]
49
    MergeMineError(#[from] MergeMineError),
50
}
51

52
impl PowError {
53
    pub fn get_ban_reason(&self) -> Option<BanReason> {
×
54
        match self {
×
55
            err @ PowError::InvalidProofOfWork |
×
56
            err @ PowError::AchievedDifficultyBelowMin |
×
57
            err @ PowError::Sha3HeaderNonEmptyPowBytes |
×
58
            err @ PowError::RandomxTPowDataTooLong |
×
59
            err @ PowError::AchievedDifficultyTooLow { .. } |
×
60
            err @ PowError::InvalidTargetDifficulty { .. } => Some(BanReason {
×
61
                reason: err.to_string(),
×
62
                ban_duration: BanPeriod::Long,
×
63
            }),
×
64
            #[cfg(feature = "base_node")]
65
            PowError::MergeMineError(e) => e.get_ban_reason(),
×
66
        }
67
    }
×
68
}
69

70
/// Errors that can occur when adjusting the difficulty
71
#[derive(Debug, Error, Clone, PartialEq, Eq)]
72
pub enum DifficultyAdjustmentError {
73
    #[error("Accumulated difficulty values can only strictly increase")]
74
    DecreasingAccumulatedDifficulty,
75
    #[error("Other difficulty algorithm error")]
76
    Other,
77
}
78

79
/// Errors that can occur when converting a difficulty
80
#[derive(Debug, Error)]
81
pub enum DifficultyError {
82
    #[error("Difficulty conversion less than the minimum difficulty")]
83
    InvalidDifficulty,
84
    #[error("Maximum block time overflowed u64")]
85
    MaxBlockTimeOverflow,
86
    #[error("Divide by zero")]
87
    DivideByZero,
88
    #[error("Overflow")]
89
    Overflow,
90
}
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