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

tari-project / tari / 15484013348

06 Jun 2025 06:08AM UTC coverage: 72.04% (+0.3%) from 71.789%
15484013348

push

github

web-flow
fix(network-discovery): add back idle event handling (#7194)

Description
---
fix(network-discovery): add back idle event handling

Motivation and Context
---
network discovery was spinning at full speed because the Idle event
transition was removed. Network logs would rotate < 1s.

```
[comms::dht::network_discovery::ready] [Thread:123190302967360] DEBUG NetworkDiscovery::Ready: Peer list contains 759 entries. Current discovery rounds in this cycle: 0.
[comms::dht::network_discovery::ready] [Thread:123190302967360] DEBUG First active round (current_num_rounds = 0) and num_peers (759) >= min_desired_peers (16). Forcing DHT discovery.
 [comms::dht::network_discovery::ready] [Thread:123190302967360] DEBUG Selecting 5 random peers for discovery (last round info available: false, new peers in last round: false).
[comms::dht::network_discovery::ready] [Thread:123190302967360] DEBUG No suitable peers found for the forced DHT discovery round (current_num_rounds = 0 path). Transitioning to Idle.
 [comms::dht::network_discovery] [Thread:123190302967360] DEBUG Transition triggered from current state `Ready` by event `Idle`
comms::dht::network_discovery] [Thread:123190302967360] DEBUG No state transition for event `Idle`. The current state is `Ready`

...instant rinse and repeat...
```

This PR adds the idle state transition back. Note that idle will idle
for 30 minutes so should only transition when all work is done and we
have downloaded sufficient peers.

How Has This Been Tested?
---
Manually - console wallet with empty peer db

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

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

3 of 4 new or added lines in 2 files covered. (75.0%)

412 existing lines in 30 files now uncovered.

80882 of 112274 relevant lines covered (72.04%)

242938.65 hits per line

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

19.05
/base_layer/core/src/base_node/comms_interface/error.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 tari_common_types::types::FixedHash;
24
use tari_comms_dht::outbound::DhtOutboundError;
25
use tari_service_framework::reply_channel::TransportChannelError;
26
use thiserror::Error;
27

28
use crate::{
29
    blocks::{BlockError, BlockHeaderValidationError},
30
    chain_storage::ChainStorageError,
31
    common::{BanPeriod, BanReason},
32
    consensus::ConsensusManagerError,
33
    mempool::MempoolError,
34
    proof_of_work::{monero_rx::MergeMineError, DifficultyError},
35
    transactions::transaction_components::TransactionError,
36
};
37

38
#[derive(Debug, Error)]
39
pub enum CommsInterfaceError {
40
    #[error("Received an unexpected response from a remote peer")]
41
    UnexpectedApiResponse,
42
    #[error("Request timed out")]
43
    RequestTimedOut,
44
    #[error("No bootstrap nodes have been configured")]
45
    NoBootstrapNodesConfigured,
46
    #[error("Transport channel error: {0}")]
47
    TransportChannelError(#[from] TransportChannelError),
48
    #[error("Chain storage error: {0}")]
49
    ChainStorageError(#[from] ChainStorageError),
50
    #[error("Failed to send outbound message: {0}")]
51
    OutboundMessageError(#[from] DhtOutboundError),
52
    #[error("Mempool error: {0}")]
53
    MempoolError(#[from] MempoolError),
54
    #[error("Failed to broadcast message")]
55
    BroadcastFailed,
56
    #[error("Internal channel error: {0}")]
57
    InternalChannelError(String),
58
    #[error("Difficulty adjustment error: {0}")]
59
    DifficultyAdjustmentManagerError(#[from] ConsensusManagerError),
60
    #[error("Invalid peer response: {0}")]
61
    InvalidPeerResponse(String),
62
    #[error("Invalid Block Header: {0}")]
63
    InvalidBlockHeader(#[from] BlockHeaderValidationError),
64
    #[error("Internal error:{0}")]
65
    InternalError(String),
66
    #[error("API responded with an error: {0}")]
67
    ApiError(String),
68
    #[error("Block error: {0}")]
69
    BlockError(#[from] BlockError),
70
    #[error("Invalid request for {request}: {details}")]
71
    InvalidRequest { request: &'static str, details: String },
72
    #[error("Peer sent invalid full block {hash}: {details}")]
73
    InvalidFullBlock { hash: FixedHash, details: String },
74
    #[error("Invalid merge mined block: {0}")]
75
    MergeMineError(#[from] MergeMineError),
76
    #[error("Invalid difficulty: {0}")]
77
    DifficultyError(#[from] DifficultyError),
78
    #[error("Transaction error: {0}")]
79
    TransactionError(#[from] TransactionError),
80
}
81

82
impl CommsInterfaceError {
83
    pub fn get_ban_reason(&self) -> Option<BanReason> {
2✔
84
        match self {
2✔
85
            err @ CommsInterfaceError::UnexpectedApiResponse |
×
86
            err @ CommsInterfaceError::RequestTimedOut |
×
87
            err @ CommsInterfaceError::TransportChannelError(_) => Some(BanReason {
×
88
                reason: err.to_string(),
×
89
                ban_duration: BanPeriod::Short,
×
90
            }),
×
UNCOV
91
            err @ CommsInterfaceError::InvalidPeerResponse(_) |
×
92
            err @ CommsInterfaceError::InvalidBlockHeader(_) |
×
93
            err @ CommsInterfaceError::TransactionError(_) |
×
94
            err @ CommsInterfaceError::InvalidFullBlock { .. } |
×
UNCOV
95
            err @ CommsInterfaceError::InvalidRequest { .. } => Some(BanReason {
×
UNCOV
96
                reason: err.to_string(),
×
UNCOV
97
                ban_duration: BanPeriod::Long,
×
UNCOV
98
            }),
×
99
            CommsInterfaceError::MempoolError(e) => e.get_ban_reason(),
×
100
            CommsInterfaceError::ChainStorageError(e) => e.get_ban_reason(),
2✔
101
            CommsInterfaceError::MergeMineError(e) => e.get_ban_reason(),
×
102
            CommsInterfaceError::NoBootstrapNodesConfigured |
103
            CommsInterfaceError::OutboundMessageError(_) |
104
            CommsInterfaceError::BroadcastFailed |
105
            CommsInterfaceError::InternalChannelError(_) |
106
            CommsInterfaceError::DifficultyAdjustmentManagerError(_) |
107
            CommsInterfaceError::InternalError(_) |
108
            CommsInterfaceError::ApiError(_) |
109
            CommsInterfaceError::BlockError(_) |
110
            CommsInterfaceError::DifficultyError(_) => None,
×
111
        }
112
    }
2✔
113
}
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