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

tari-project / tari / 15120110241

19 May 2025 06:08PM UTC coverage: 73.213% (-0.06%) from 73.269%
15120110241

push

github

web-flow
feat!: add second tari only randomx mining (#7057)

Description
---

Adds in a second randomx algo mining option, only mining tari.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
- Introduced distinct support for Monero RandomX and Tari RandomX
proof-of-work algorithms with separate difficulty tracking, hash rate
reporting, and block template caching.
- Added a new VM key field in block results to enhance mining and
validation processes.
- Extended miner configuration and mining logic to support multiple
proof-of-work algorithms including Tari RandomX.

- **Bug Fixes**
- Improved difficulty and hash rate accuracy by separating Monero and
Tari RandomX calculations and metrics.

- **Refactor**
- Renamed and split data structures, enums, protobuf messages, and
methods to differentiate between Monero and Tari RandomX.
- Updated consensus, validation, and chain strength comparison to handle
multiple RandomX variants.
- Migrated accumulated difficulty representations from 256-bit to
512-bit integers for enhanced precision.
- Generalized difficulty window handling to support multiple
proof-of-work algorithms dynamically.

- **Documentation**
- Clarified comments and field descriptions to reflect the distinction
between Monero and Tari RandomX algorithms.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

170 of 371 new or added lines in 26 files covered. (45.82%)

40 existing lines in 12 files now uncovered.

82064 of 112089 relevant lines covered (73.21%)

274996.0 hits per line

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

29.41
/base_layer/core/src/proof_of_work/proof_of_work_algorithm.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
use std::{
23
    convert::TryFrom,
24
    fmt::{Display, Formatter},
25
    str::FromStr,
26
};
27

28
use borsh::{BorshDeserialize, BorshSerialize};
29
use serde::{Deserialize, Serialize};
30
use thiserror::Error;
31

32
/// Indicates the algorithm used to mine a block
33
#[repr(u8)]
34
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Hash, Eq, BorshSerialize, BorshDeserialize)]
14,065✔
35
#[borsh(use_discriminant = true)]
36
pub enum PowAlgorithm {
37
    RandomXM = 0,
38
    Sha3x = 1,
39
    RandomXT = 2,
40
}
41

42
impl PowAlgorithm {
43
    /// Returns true if the PoW algorithm is merged mined monero RandomX
NEW
44
    pub fn is_merged_mined_randomx(&self) -> bool {
×
NEW
45
        matches!(self, Self::RandomXM)
×
NEW
46
    }
×
47

48
    /// Returns true if the PoW algorithm is solo tari RandomX
NEW
49
    pub fn is_tari_randomx(&self) -> bool {
×
NEW
50
        matches!(self, Self::RandomXT)
×
UNCOV
51
    }
×
52

53
    /// Returns true if the PoW algorithm is Sha3
54
    pub fn is_sha3(&self) -> bool {
×
55
        matches!(self, Self::Sha3x)
×
56
    }
×
57

58
    /// A convenience functions that returns the PoW algorithm as a u64
59
    pub fn as_u64(&self) -> u64 {
×
60
        *self as u64
×
61
    }
×
62
}
63

64
/// Parse error for `PowAlgorithm`
65
#[derive(Debug, Error)]
66
pub enum PowAlgorithmParseError {
67
    #[error("unknown pow algorithm type {0}")]
68
    UnknownType(String),
69
}
70

71
impl TryFrom<u64> for PowAlgorithm {
72
    type Error = String;
73

74
    fn try_from(v: u64) -> Result<Self, Self::Error> {
153✔
75
        match v {
153✔
NEW
76
            0 => Ok(PowAlgorithm::RandomXM),
×
77
            1 => Ok(PowAlgorithm::Sha3x),
153✔
NEW
78
            2 => Ok(PowAlgorithm::RandomXT),
×
UNCOV
79
            _ => Err("Invalid PoWAlgorithm".into()),
×
80
        }
81
    }
153✔
82
}
83

84
impl FromStr for PowAlgorithm {
85
    type Err = PowAlgorithmParseError;
86

87
    fn from_str(s: &str) -> Result<Self, Self::Err> {
×
88
        match s {
×
NEW
89
            "RandomX" | "randomx" | "random_x" | "RandomXM" | "randomxm" | "monero_random_x" => Ok(Self::RandomXM),
×
NEW
90
            "sha" | "sha3" | "SHA3" | "sha3X" | "Sha3X" | "SHA3X" => Ok(Self::Sha3x),
×
NEW
91
            "RandomXT" | "randomxt" | "tari_random_x" => Ok(Self::RandomXT),
×
UNCOV
92
            other => Err(PowAlgorithmParseError::UnknownType(other.into())),
×
93
        }
94
    }
×
95
}
96

97
impl Display for PowAlgorithm {
98
    fn fmt(&self, fmt: &mut Formatter<'_>) -> std::fmt::Result {
1✔
99
        let algo = match self {
1✔
NEW
100
            PowAlgorithm::RandomXM => "RandomXMonero",
×
101
            PowAlgorithm::Sha3x => "Sha3",
1✔
NEW
102
            PowAlgorithm::RandomXT => "RandomXTari",
×
103
        };
104
        fmt.write_str(algo)
1✔
105
    }
1✔
106
}
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