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

tari-project / tari / 19227006544

10 Nov 2025 09:31AM UTC coverage: 51.608% (-7.9%) from 59.471%
19227006544

push

github

web-flow
feat: add deterministic transaction id (#7541)

Description
---
Added deterministic transaction IDs, which are an 8-byte (u64) hash
based on the transaction output hash in question and the wallet view
key.
- Any scanned or recovered wallet output will have the same transaction
ID across view or spend wallets.
- Sender wallets will be able to calculate the transaction ID for
receiver wallets if they need to, for that specific output.
- Sender wallets will use their change output as the determining output
hash for the transaction; this will result in the same transaction ID
being allocated upon wallet recovery. In the case of no change output,
the hash of the first ordered output will be used for the transaction
ID.
- For coin split transactions, the hash of the first ordered output will
be used for the transaction ID.

Fixed the issue with the Windows test build target link:
```
: error LNK2019: unresolved external symbol __imp_InitializeSecurityDescriptor referenced in function mdb_env_setup_locks
: error LNK2019: unresolved external symbol __imp_SetSecurityDescriptorDacl referenced in function mdb_env_setup_lock
```

Fixes #7485.

Motivation and Context
---
See #7485.

How Has This Been Tested?
---
Added unit tests.
Performed system-level testing.

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

<!-- 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 comm... (continued)

52 of 1260 new or added lines in 14 files covered. (4.13%)

9213 existing lines in 93 files now uncovered.

59188 of 114687 relevant lines covered (51.61%)

8172.79 hits per line

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

6.67
/base_layer/transaction_components/src/tari_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)]
×
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)
×
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)
×
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
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),
×
72
            3 => Ok(PowAlgorithm::Cuckaroo),
×
73
            _ => Err("Invalid PoWAlgorithm".into()),
×
74
        }
75
    }
×
76
}
77

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

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

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

107
#[cfg(test)]
108
mod tests {
109
    use serde_json;
110

111
    use super::*;
112

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

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

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

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