• 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

67.2
/base_layer/core/src/base_node/metrics.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 once_cell::sync::Lazy;
24
use tari_common_types::types::FixedHash;
25
use tari_metrics::{IntCounter, IntCounterVec, IntGauge, IntGaugeVec};
26
use tari_utilities::hex::Hex;
27

28
pub fn tip_height() -> &'static IntGauge {
38✔
29
    static METER: Lazy<IntGauge> = Lazy::new(|| {
1✔
30
        tari_metrics::register_int_gauge("base_node::blockchain::tip_height", "The current tip height").unwrap()
1✔
31
    });
1✔
32

33
    &METER
38✔
34
}
38✔
35

36
pub fn target_difficulty_sha() -> &'static IntGauge {
30✔
37
    static METER: Lazy<IntGauge> = Lazy::new(|| {
1✔
38
        tari_metrics::register_int_gauge(
1✔
39
            "base_node::blockchain::target_difficulty_sha",
1✔
40
            "The current miner target difficulty for the sha3 PoW algo",
1✔
41
        )
1✔
42
        .unwrap()
1✔
43
    });
1✔
44

45
    &METER
30✔
46
}
30✔
47

NEW
48
pub fn target_difficulty_monero_randomx() -> &'static IntGauge {
×
49
    static METER: Lazy<IntGauge> = Lazy::new(|| {
×
50
        tari_metrics::register_int_gauge(
×
51
            "base_node::blockchain::target_difficulty_monero",
×
52
            "The current miner target difficulty for the monero PoW algo",
×
53
        )
×
54
        .unwrap()
×
55
    });
×
56

57
    &METER
×
58
}
×
NEW
59
pub fn target_difficulty_tari_randomx() -> &'static IntGauge {
×
NEW
60
    static METER: Lazy<IntGauge> = Lazy::new(|| {
×
NEW
61
        tari_metrics::register_int_gauge(
×
NEW
62
            "base_node::blockchain::target_difficulty_tari_rx",
×
NEW
63
            "The current miner target difficulty for the tari rx PoW algo",
×
NEW
64
        )
×
NEW
65
        .unwrap()
×
NEW
66
    });
×
67

NEW
68
    &METER
×
NEW
69
}
×
70

71
pub fn reorg(fork_height: u64, num_added: usize, num_removed: usize) -> IntGauge {
1✔
72
    static METER: Lazy<IntGaugeVec> = Lazy::new(|| {
1✔
73
        tari_metrics::register_int_gauge_vec("base_node::blockchain::reorgs", "Reorg stats", &[
1✔
74
            "fork_height",
1✔
75
            "num_added",
1✔
76
            "num_removed",
1✔
77
        ])
1✔
78
        .unwrap()
1✔
79
    });
1✔
80

81
    METER.with_label_values(&[
1✔
82
        &fork_height.to_string(),
1✔
83
        &num_added.to_string(),
1✔
84
        &num_removed.to_string(),
1✔
85
    ])
1✔
86
}
1✔
87

88
pub fn compact_block_tx_misses(height: u64) -> IntGauge {
4✔
89
    static METER: Lazy<IntGaugeVec> = Lazy::new(|| {
1✔
90
        tari_metrics::register_int_gauge_vec(
1✔
91
            "base_node::blockchain::compact_block_unknown_transactions",
1✔
92
            "Number of unknown transactions from the incoming compact block",
1✔
93
            &["height"],
1✔
94
        )
1✔
95
        .unwrap()
1✔
96
    });
1✔
97

98
    METER.with_label_values(&[&height.to_string()])
4✔
99
}
4✔
100

101
pub fn compact_block_full_misses(height: u64) -> IntCounter {
4✔
102
    static METER: Lazy<IntCounterVec> = Lazy::new(|| {
1✔
103
        tari_metrics::register_int_counter_vec(
1✔
104
            "base_node::blockchain::compact_block_miss",
1✔
105
            "Number of full blocks that had to be requested",
1✔
106
            &["height"],
1✔
107
        )
1✔
108
        .unwrap()
1✔
109
    });
1✔
110

111
    METER.with_label_values(&[&height.to_string()])
4✔
112
}
4✔
113

114
pub fn compact_block_mmr_mismatch(height: u64) -> IntCounter {
×
115
    static METER: Lazy<IntCounterVec> = Lazy::new(|| {
×
116
        tari_metrics::register_int_counter_vec(
×
117
            "base_node::blockchain::compact_block_mmr_mismatch",
×
118
            "Number of full blocks that had to be requested because of MMR mismatch",
×
119
            &["height"],
×
120
        )
×
121
        .unwrap()
×
122
    });
×
123

124
    METER.with_label_values(&[&height.to_string()])
×
125
}
×
126

127
pub fn orphaned_blocks() -> IntCounter {
×
128
    static METER: Lazy<IntCounter> = Lazy::new(|| {
×
129
        tari_metrics::register_int_counter(
×
130
            "base_node::blockchain::orphaned_blocks",
×
131
            "Number of valid orphan blocks accepted by the base node",
×
132
        )
×
133
        .unwrap()
×
134
    });
×
135

136
    METER.clone()
×
137
}
×
138

139
pub fn rejected_blocks(height: u64, hash: &FixedHash) -> IntCounter {
2✔
140
    static METER: Lazy<IntCounterVec> = Lazy::new(|| {
1✔
141
        tari_metrics::register_int_counter_vec(
1✔
142
            "base_node::blockchain::rejected_blocks",
1✔
143
            "Number of block rejected by the base node",
1✔
144
            &["height", "block_hash"],
1✔
145
        )
1✔
146
        .unwrap()
1✔
147
    });
1✔
148

149
    METER.with_label_values(&[&height.to_string(), &hash.to_hex()])
2✔
150
}
2✔
151

152
pub fn active_sync_peers() -> &'static IntGauge {
24✔
153
    static METER: Lazy<IntGauge> = Lazy::new(|| {
2✔
154
        tari_metrics::register_int_gauge(
2✔
155
            "base_node::sync::active_peers",
2✔
156
            "Number of active peers syncing from this node",
2✔
157
        )
2✔
158
        .unwrap()
2✔
159
    });
2✔
160

161
    &METER
24✔
162
}
24✔
163

164
pub fn utxo_set_size() -> &'static IntGauge {
30✔
165
    static METER: Lazy<IntGauge> = Lazy::new(|| {
1✔
166
        tari_metrics::register_int_gauge(
1✔
167
            "base_node::blockchain::utxo_set_size",
1✔
168
            "The number of UTXOs in the current UTXO set",
1✔
169
        )
1✔
170
        .unwrap()
1✔
171
    });
1✔
172

173
    &METER
30✔
174
}
30✔
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