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

tari-project / tari / 16933396277

13 Aug 2025 09:35AM UTC coverage: 54.463% (+0.2%) from 54.254%
16933396277

push

github

web-flow
feat: add seed peer exclusion to the proactive dialer (#7396)

Description
---
Added seed peer exclusion to proactive dialing when selecting available
candidates from the peer_db.

Motivation and Context
---
Seed peers are known entities; they have been dialled during initial
seed_strap, and a well-connected network should try to learn about and
connect to other peers as well.

How Has This Been Tested?
---
System-level testing.

What process can a PR reviewer use to test or verify this change?
---
Code review.

<!-- Checklist -->
<!-- 1. Is the title of your PR in the form that would make nice release
notes? The title, excluding the conventional commit
tag, will be included exactly as is in the CHANGELOG, so please think
about it carefully. -->


Breaking Changes
---

- [x] None
- [ ] Requires data directory on base node to be deleted
- [ ] Requires hard fork
- [ ] Other - Please specify

<!-- Does this include a breaking change? If so, include this line as a
footer -->
<!-- BREAKING CHANGE: Description what the user should do, e.g. delete a
database, resync the chain -->


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

* **Bug Fixes**
* Improved connection management by excluding seed peers from proactive
dialing candidates, enhancing network stability and reducing unnecessary
connection attempts and failed dials.

* **Documentation**
* Added a brief doc comment describing how to retrieve the list of seed
peers.

* **Tests**
* Expanded test coverage to validate discovery and syncing behavior when
seed peers are present and when filtering by external addresses.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

41 of 42 new or added lines in 3 files covered. (97.62%)

1673 existing lines in 28 files now uncovered.

76415 of 140305 relevant lines covered (54.46%)

194087.6 hits per line

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

71.79
/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

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

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

48
    /// Returns true if the PoW algorithm is solo tari RandomX
49
    pub fn is_tari_randomx(&self) -> bool {
×
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)
×
UNCOV
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
×
UNCOV
61
    }
×
62
}
63

64
impl TryFrom<u64> for PowAlgorithm {
65
    type Error = String;
66

67
    fn try_from(v: u64) -> Result<Self, Self::Error> {
×
68
        match v {
×
69
            0 => Ok(PowAlgorithm::RandomXM),
×
70
            1 => Ok(PowAlgorithm::Sha3x),
×
71
            2 => Ok(PowAlgorithm::RandomXT),
×
UNCOV
72
            _ => Err("Invalid PoWAlgorithm".into()),
×
73
        }
UNCOV
74
    }
×
75
}
76

77
impl FromStr for PowAlgorithm {
78
    type Err = anyhow::Error;
79

80
    fn from_str(s: &str) -> Result<Self, Self::Err> {
21✔
81
        let s_trimmed = s.replace("\"", "").replace("\'", "").replace(" ", "").to_uppercase();
21✔
82
        match s_trimmed.as_str() {
21✔
83
            "RANDOMXM" | "RANDOM_XM" | "MONERO_RANDOM_X" | "RANDOMX" | "RANDOM_X" | "RANDOMXMONERO" => {
21✔
84
                Ok(Self::RandomXM)
7✔
85
            },
86
            "SHA" | "SHA3" | "SHA3X" => Ok(Self::Sha3x),
14✔
87
            "RANDOMXT" | "RANDOM_XT" | "TARI_RANDOM_X" | "RANDOMXTARI" => Ok(Self::RandomXT),
4✔
UNCOV
88
            _ => Err(anyhow::Error::msg(format!("Unknown pow algorithm type: {}", s))),
×
89
        }
90
    }
21✔
91
}
92

93
impl Display for PowAlgorithm {
94
    fn fmt(&self, fmt: &mut Formatter<'_>) -> std::fmt::Result {
2✔
95
        let algo = match self {
2✔
UNCOV
96
            PowAlgorithm::RandomXM => "RandomXMonero",
×
97
            PowAlgorithm::Sha3x => "Sha3",
1✔
98
            PowAlgorithm::RandomXT => "RandomXTari",
1✔
UNCOV
99
            PowAlgorithm::Cuckaroo => "Cuckaroo",
×
100
        };
101
        fmt.write_str(algo)
2✔
102
    }
2✔
103
}
104

105
#[cfg(test)]
106
mod tests {
107
    use serde_json;
108

109
    use super::*;
110

111
    #[test]
112
    fn test_pow_algorithm_from_str_variants() {
1✔
113
        // Test valid variants for RandomXM
1✔
114
        let randomxm_variants = vec![
1✔
115
            "RandomXM",
1✔
116
            "RandomX",
1✔
117
            "randomx",
1✔
118
            "random_x",
1✔
119
            "randomxm",
1✔
120
            "RANDOM_XM",
1✔
121
            "monero_random_x",
1✔
122
        ];
1✔
123
        for variant in randomxm_variants {
8✔
124
            let algo = PowAlgorithm::from_str(variant).expect("Failed to parse RandomXM variant");
7✔
125
            assert_eq!(algo, PowAlgorithm::RandomXM);
7✔
126
        }
127

128
        // Test valid variants for Sha3x
129
        let sha3x_variants = vec![
1✔
130
            "Sha3x",
1✔
131
            "\"Sha3x\"",
1✔
132
            "\'Sha3x\'",
1✔
133
            "Sha 3 x",
1✔
134
            "sha",
1✔
135
            "sha3",
1✔
136
            "SHA3",
1✔
137
            "sha3X",
1✔
138
            "Sha3X",
1✔
139
            "SHA3X",
1✔
140
        ];
1✔
141
        for variant in sha3x_variants {
11✔
142
            let algo = PowAlgorithm::from_str(variant).expect("Failed to parse Sha3x variant");
10✔
143
            assert_eq!(algo, PowAlgorithm::Sha3x);
10✔
144
        }
145

146
        // Test valid variants for RandomXT
147
        let randomxt_variants = vec!["RandomXT", "randomxt", "tari_random_x", "RANDOM_XT"];
1✔
148
        for variant in randomxt_variants {
5✔
149
            let algo = PowAlgorithm::from_str(variant).expect("Failed to parse RandomXT variant");
4✔
150
            assert_eq!(algo, PowAlgorithm::RandomXT);
4✔
151
        }
152
    }
1✔
153

154
    #[test]
155
    fn test_pow_algorithm_serialization() {
1✔
156
        for algo in [PowAlgorithm::Sha3x, PowAlgorithm::RandomXM, PowAlgorithm::RandomXT] {
3✔
157
            let serialized = serde_json::to_string(&algo).expect("Failed to serialize PowAlgorithm");
3✔
158
            let deserialized: PowAlgorithm =
3✔
159
                serde_json::from_str(&serialized).expect("Failed to deserialize PowAlgorithm");
3✔
160
            assert_eq!(deserialized, algo);
3✔
161
        }
162
    }
1✔
163
}
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