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

tari-project / tari / 16272458029

14 Jul 2025 04:32PM UTC coverage: 57.167% (-0.9%) from 58.047%
16272458029

push

github

web-flow
feat: modify soft disconnect criteria (#7307)

Description
---
We can be more efficient with soft disconnects when we compare against
expected RPC sessions and substream counts. This PR adds finer
discernment when doing soft peer disconnects.

Motivation and Context
---
The health check opens 2 substreams and 0 PRC sessions - that should
result in a disconnect if those are the only opened resources.

How Has This Been Tested?
---
System-level testing
```rust
2025-07-11 13:52:26.703289300 [comms::connection_manager::peer_connection] TRACE Hard disconnect - requester: 'Health check', peer: `d7c289e9e3c8377705ce599a96`, RPC clients: 0, substreams 2
2025-07-11 13:52:26.705658100 [comms::connection_manager::peer_connection] TRACE Soft disconnect - requester: 'Health check', peer: `0984896e74022c442c1034852c`, RPC clients: 1, substreams 3, NOT disconnecting
2025-07-11 13:52:26.705735900 [comms::connection_manager::peer_connection] TRACE Hard disconnect - requester: 'Health check', peer: `d025bc9e4bd423a9b304c491b8`, RPC clients: 0, substreams 2
2025-07-11 13:52:26.707647400 [comms::connection_manager::peer_connection] TRACE Hard disconnect - requester: 'Health check', peer: `51af08aff11f7129b4681d9950`, RPC clients: 0, substreams 2
```

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

31 of 46 new or added lines in 6 files covered. (67.39%)

1102 existing lines in 27 files now uncovered.

68701 of 120177 relevant lines covered (57.17%)

226749.69 hits per line

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

73.24
/base_layer/common_types/src/types/fixed_hash.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 std::{
24
    convert::TryFrom,
25
    fmt::{Display, Formatter},
26
    ops::{Deref, DerefMut},
27
};
28

29
use borsh::{BorshDeserialize, BorshSerialize};
30
use digest::{consts::U32, generic_array};
31
use serde::{Deserialize, Serialize};
32
use tari_utilities::hex::{Hex, HexError};
33
use utoipa::ToSchema;
34

35
const ZERO_HASH: [u8; FixedHash::byte_size()] = [0u8; FixedHash::byte_size()];
36

37
#[derive(thiserror::Error, Debug)]
38
#[error("Invalid size")]
39
pub struct FixedHashSizeError;
40

41
#[derive(
42
    Clone,
43
    Copy,
44
    PartialEq,
45
    Eq,
46
    PartialOrd,
47
    Ord,
48
    Debug,
49
    Default,
50
    Hash,
51
    Deserialize,
8,499✔
52
    Serialize,
53
    BorshSerialize,
×
54
    BorshDeserialize,
×
55
    ToSchema,
×
56
)]
57
#[serde(transparent)]
58
pub struct FixedHash([u8; FixedHash::byte_size()]);
59

60
impl FixedHash {
61
    pub const fn new(hash: [u8; FixedHash::byte_size()]) -> Self {
×
62
        Self(hash)
×
63
    }
×
64

65
    pub const fn byte_size() -> usize {
1,025✔
66
        32
1,025✔
67
    }
1,025✔
68

69
    pub const fn zero() -> Self {
9,689✔
70
        Self(ZERO_HASH)
9,689✔
71
    }
9,689✔
72

73
    pub const fn into_array(self) -> [u8; 32] {
4✔
74
        self.0
4✔
75
    }
4✔
76

77
    pub fn as_slice(&self) -> &[u8] {
28,319✔
78
        &self.0
28,319✔
79
    }
28,319✔
80
}
81

82
impl From<[u8; FixedHash::byte_size()]> for FixedHash {
83
    fn from(hash: [u8; FixedHash::byte_size()]) -> Self {
10,977✔
84
        Self(hash)
10,977✔
85
    }
10,977✔
86
}
87

88
impl TryFrom<Vec<u8>> for FixedHash {
89
    type Error = FixedHashSizeError;
90

91
    fn try_from(value: Vec<u8>) -> Result<Self, Self::Error> {
400✔
92
        TryFrom::try_from(value.as_slice())
400✔
93
    }
400✔
94
}
95

96
impl TryFrom<&[u8]> for FixedHash {
97
    type Error = FixedHashSizeError;
98

99
    fn try_from(bytes: &[u8]) -> Result<Self, Self::Error> {
516✔
100
        if bytes.len() != FixedHash::byte_size() {
516✔
101
            return Err(FixedHashSizeError);
×
102
        }
516✔
103

516✔
104
        let mut buf = [0u8; FixedHash::byte_size()];
516✔
105
        buf.copy_from_slice(bytes);
516✔
106
        Ok(Self(buf))
516✔
107
    }
516✔
108
}
109

110
impl From<generic_array::GenericArray<u8, U32>> for FixedHash {
111
    fn from(hash: generic_array::GenericArray<u8, U32>) -> Self {
53,069✔
112
        Self(hash.into())
53,069✔
113
    }
53,069✔
114
}
115

116
impl PartialEq<[u8]> for FixedHash {
UNCOV
117
    fn eq(&self, other: &[u8]) -> bool {
×
UNCOV
118
        self.0[..].eq(other)
×
UNCOV
119
    }
×
120
}
121

122
impl PartialEq<FixedHash> for [u8] {
123
    fn eq(&self, other: &FixedHash) -> bool {
×
124
        self[..].eq(&other.0)
×
125
    }
×
126
}
127

128
impl PartialEq<Vec<u8>> for FixedHash {
UNCOV
129
    fn eq(&self, other: &Vec<u8>) -> bool {
×
UNCOV
130
        self == other.as_slice()
×
UNCOV
131
    }
×
132
}
133
impl PartialEq<FixedHash> for Vec<u8> {
134
    fn eq(&self, other: &FixedHash) -> bool {
×
135
        self == other.as_slice()
×
136
    }
×
137
}
138

139
impl AsRef<[u8]> for FixedHash {
140
    fn as_ref(&self) -> &[u8] {
2,261✔
141
        self.as_slice()
2,261✔
142
    }
2,261✔
143
}
144

145
impl Hex for FixedHash {
146
    fn from_hex(hex: &str) -> Result<Self, HexError>
589✔
147
    where Self: Sized {
589✔
148
        let hash = <[u8; FixedHash::byte_size()] as Hex>::from_hex(hex)?;
589✔
149
        Ok(Self(hash))
589✔
150
    }
589✔
151

152
    fn to_hex(&self) -> String {
124✔
153
        self.0.to_hex()
124✔
154
    }
124✔
155
}
156

157
impl Deref for FixedHash {
158
    type Target = [u8; FixedHash::byte_size()];
159

160
    fn deref(&self) -> &Self::Target {
14,476✔
161
        &self.0
14,476✔
162
    }
14,476✔
163
}
164

165
impl DerefMut for FixedHash {
166
    fn deref_mut(&mut self) -> &mut Self::Target {
1✔
167
        &mut self.0
1✔
168
    }
1✔
169
}
170

171
impl Display for FixedHash {
172
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
59✔
173
        for b in self.0 {
1,947✔
174
            write!(f, "{:02x}", b)?;
1,888✔
175
        }
176
        Ok(())
59✔
177
    }
59✔
178
}
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