• 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

0.0
/base_layer/core/src/base_node/proto/response.rs
1
// Copyright 2019, 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, TryInto},
25
    iter::FromIterator,
26
    sync::Arc,
27
};
28

29
use tari_common_types::types::PrivateKey;
30
use tari_utilities::ByteArray;
31

32
pub use crate::proto::base_node::base_node_service_response::Response as ProtoNodeCommsResponse;
33
use crate::{
34
    base_node::comms_interface::{FetchMempoolTransactionsResponse, NodeCommsResponse},
35
    blocks::{Block, BlockHeader},
36
    proto,
37
};
38

39
impl TryInto<NodeCommsResponse> for ProtoNodeCommsResponse {
40
    type Error = String;
41

42
    fn try_into(self) -> Result<NodeCommsResponse, Self::Error> {
×
43
        use ProtoNodeCommsResponse::{BlockResponse, FetchMempoolTransactionsByExcessSigsResponse};
44
        let response = match self {
×
45
            BlockResponse(block) => NodeCommsResponse::Block(Box::new(block.try_into()?)),
×
46
            FetchMempoolTransactionsByExcessSigsResponse(response) => {
×
47
                let transactions = response
×
48
                    .transactions
×
UNCOV
49
                    .into_iter()
×
50
                    .map(|tx| tx.try_into().map(Arc::new))
×
51
                    .collect::<Result<_, _>>()?;
×
52
                let not_found = response
×
53
                    .not_found
×
54
                    .into_iter()
×
55
                    .map(|bytes| {
×
56
                        PrivateKey::from_canonical_bytes(&bytes).map_err(|_| "Malformed excess signature".to_string())
×
57
                    })
×
58
                    .collect::<Result<_, _>>()?;
×
59
                NodeCommsResponse::FetchMempoolTransactionsByExcessSigsResponse(
×
60
                    self::FetchMempoolTransactionsResponse {
×
61
                        transactions,
×
62
                        not_found,
×
63
                    },
×
64
                )
×
65
            },
66
        };
67

68
        Ok(response)
×
UNCOV
69
    }
×
70
}
71

72
impl TryFrom<NodeCommsResponse> for ProtoNodeCommsResponse {
73
    type Error = String;
74

UNCOV
75
    fn try_from(response: NodeCommsResponse) -> Result<Self, Self::Error> {
×
76
        use NodeCommsResponse::FetchMempoolTransactionsByExcessSigsResponse;
UNCOV
77
        match response {
×
UNCOV
78
            NodeCommsResponse::Block(block) => Ok(ProtoNodeCommsResponse::BlockResponse((*block).try_into()?)),
×
79
            FetchMempoolTransactionsByExcessSigsResponse(resp) => {
×
UNCOV
80
                let transactions = resp
×
81
                    .transactions
×
82
                    .into_iter()
×
83
                    .map(|tx| tx.try_into())
×
84
                    .collect::<Result<_, _>>()?;
×
85
                Ok(ProtoNodeCommsResponse::FetchMempoolTransactionsByExcessSigsResponse(
×
86
                    proto::base_node::FetchMempoolTransactionsResponse {
×
87
                        transactions,
×
88
                        not_found: resp.not_found.into_iter().map(|s| s.to_vec()).collect(),
×
89
                    },
×
90
                ))
×
91
            },
92
            // This would only occur if a programming error sent out the unsupported response
93
            resp => Err(format!("Response not supported {:?}", resp)),
×
94
        }
95
    }
×
96
}
97

98
impl From<Option<BlockHeader>> for proto::base_node::BlockHeaderResponse {
99
    fn from(v: Option<BlockHeader>) -> Self {
×
100
        Self {
×
101
            header: v.map(Into::into),
×
102
        }
×
103
    }
×
104
}
105

106
impl TryInto<Option<BlockHeader>> for proto::base_node::BlockHeaderResponse {
107
    type Error = String;
108

UNCOV
109
    fn try_into(self) -> Result<Option<BlockHeader>, Self::Error> {
×
UNCOV
110
        match self.header {
×
UNCOV
111
            Some(header) => {
×
112
                let header = header.try_into()?;
×
113
                Ok(Some(header))
×
114
            },
115
            None => Ok(None),
×
116
        }
UNCOV
117
    }
×
118
}
119
impl TryFrom<Option<Block>> for proto::base_node::BlockResponse {
120
    type Error = String;
121

122
    fn try_from(v: Option<Block>) -> Result<Self, Self::Error> {
×
123
        Ok(Self {
×
124
            block: v.map(TryInto::try_into).transpose()?,
×
125
        })
126
    }
×
127
}
128

129
impl TryInto<Option<Block>> for proto::base_node::BlockResponse {
130
    type Error = String;
131

UNCOV
132
    fn try_into(self) -> Result<Option<Block>, Self::Error> {
×
UNCOV
133
        match self.block {
×
UNCOV
134
            Some(block) => {
×
UNCOV
135
                let block = block.try_into()?;
×
136
                Ok(Some(block))
×
137
            },
138
            None => Ok(None),
×
139
        }
140
    }
×
141
}
142

143
//---------------------------------- Collection impls --------------------------------------------//
144

145
// The following allow `Iterator::collect` to collect into these repeated types
146

147
impl FromIterator<proto::types::TransactionKernel> for proto::base_node::TransactionKernels {
148
    fn from_iter<T: IntoIterator<Item = proto::types::TransactionKernel>>(iter: T) -> Self {
×
149
        Self {
×
150
            kernels: iter.into_iter().collect(),
×
UNCOV
151
        }
×
152
    }
×
153
}
154

155
impl FromIterator<proto::core::BlockHeader> for proto::base_node::BlockHeaders {
UNCOV
156
    fn from_iter<T: IntoIterator<Item = proto::core::BlockHeader>>(iter: T) -> Self {
×
UNCOV
157
        Self {
×
UNCOV
158
            headers: iter.into_iter().collect(),
×
UNCOV
159
        }
×
160
    }
×
161
}
162

163
impl FromIterator<proto::types::TransactionOutput> for proto::base_node::TransactionOutputs {
164
    fn from_iter<T: IntoIterator<Item = proto::types::TransactionOutput>>(iter: T) -> Self {
×
UNCOV
165
        Self {
×
UNCOV
166
            outputs: iter.into_iter().collect(),
×
UNCOV
167
        }
×
UNCOV
168
    }
×
169
}
170

171
impl FromIterator<proto::core::HistoricalBlock> for proto::base_node::HistoricalBlocks {
172
    fn from_iter<T: IntoIterator<Item = proto::core::HistoricalBlock>>(iter: T) -> Self {
×
173
        Self {
×
174
            blocks: iter.into_iter().collect(),
×
UNCOV
175
        }
×
176
    }
×
177
}
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