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

tari-project / tari / 15443674054

04 Jun 2025 01:30PM UTC coverage: 72.396% (+0.07%) from 72.329%
15443674054

push

github

web-flow
fix: remove code for deleting stale peers (#7184)

This code is no longer needed since the switch to sqlite

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

- **Refactor**
- Removed the automatic deletion of stale peers from the connectivity
and peer management processes. The system will no longer periodically
delete inactive or stale peers from the database.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

2 of 2 new or added lines in 1 file covered. (100.0%)

625 existing lines in 43 files now uncovered.

81294 of 112290 relevant lines covered (72.4%)

243381.89 hits per line

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

47.14
/base_layer/core/src/validation/mocks.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::sync::{
24
    atomic::{AtomicBool, Ordering},
25
    Arc,
26
};
27

28
use tari_common_types::{
29
    chain_metadata::ChainMetadata,
30
    types::{CompressedCommitment, FixedHash},
31
};
32
use tari_utilities::epoch_time::EpochTime;
33

34
use super::{
35
    traits::CandidateBlockValidator,
36
    BlockBodyValidator,
37
    HeaderChainLinkedValidator,
38
    InternalConsistencyValidator,
39
    TransactionValidator,
40
};
41
use crate::{
42
    blocks::{Block, BlockHeader, ChainBlock},
43
    chain_storage::BlockchainBackend,
44
    proof_of_work::{randomx_factory::RandomXFactory, AchievedTargetDifficulty, Difficulty},
45
    test_helpers::create_consensus_rules,
46
    transactions::transaction_components::Transaction,
47
    validation::{error::ValidationError, DifficultyCalculator, FinalHorizonStateValidation},
48
};
49

50
#[derive(Clone)]
51
pub struct MockValidator {
52
    is_valid: Arc<AtomicBool>,
53
}
54

55
pub struct SharedFlag(Arc<AtomicBool>);
56

57
impl SharedFlag {
58
    pub fn set(&self, v: bool) {
×
59
        self.0.store(v, Ordering::SeqCst);
×
60
    }
×
61
}
62

63
impl MockValidator {
64
    pub fn new(is_valid: bool) -> Self {
498✔
65
        Self {
498✔
66
            is_valid: Arc::new(AtomicBool::new(is_valid)),
498✔
67
        }
498✔
68
    }
498✔
69

70
    pub fn shared_flag(&self) -> SharedFlag {
×
71
        SharedFlag(self.is_valid.clone())
×
72
    }
×
73
}
74

75
impl<B: BlockchainBackend> BlockBodyValidator<B> for MockValidator {
UNCOV
76
    fn validate_body(&self, _: &B, block: &Block) -> Result<Block, ValidationError> {
×
UNCOV
77
        if self.is_valid.load(Ordering::SeqCst) {
×
UNCOV
78
            Ok(block.clone())
×
79
        } else {
80
            Err(ValidationError::ConsensusError(
×
81
                "This mock validator always returns an error".to_string(),
×
82
            ))
×
83
        }
UNCOV
84
    }
×
85
}
86

87
impl<B: BlockchainBackend> CandidateBlockValidator<B> for MockValidator {
88
    fn validate_body_with_metadata(&self, _: &B, _: &ChainBlock, _: &ChainMetadata) -> Result<(), ValidationError> {
349✔
89
        if self.is_valid.load(Ordering::SeqCst) {
349✔
90
            Ok(())
348✔
91
        } else {
92
            Err(ValidationError::ConsensusError(
1✔
93
                "This mock validator always returns an error".to_string(),
1✔
94
            ))
1✔
95
        }
96
    }
349✔
97
}
98

99
// #[async_trait]
100
impl InternalConsistencyValidator for MockValidator {
101
    fn validate_internal_consistency(&self, _item: &Block) -> Result<(), ValidationError> {
×
102
        if self.is_valid.load(Ordering::SeqCst) {
×
103
            Ok(())
×
104
        } else {
105
            Err(ValidationError::ConsensusError(
×
106
                "This mock validator always returns an error".to_string(),
×
107
            ))
×
108
        }
109
    }
×
110
}
111

112
impl<B: BlockchainBackend> HeaderChainLinkedValidator<B> for MockValidator {
113
    fn validate(
383✔
114
        &self,
383✔
115
        db: &B,
383✔
116
        header: &BlockHeader,
383✔
117
        _: &BlockHeader,
383✔
118
        _: &[EpochTime],
383✔
119
        _: Option<Difficulty>,
383✔
120
        _: FixedHash,
383✔
121
    ) -> Result<AchievedTargetDifficulty, ValidationError> {
383✔
122
        if self.is_valid.load(Ordering::SeqCst) {
383✔
123
            // this assumes consensus rules are the same as the test rules which is a little brittle
124
            let difficulty_calculator = DifficultyCalculator::new(create_consensus_rules(), RandomXFactory::default());
381✔
125
            let achieved_target_diff = difficulty_calculator.check_achieved_and_target_difficulty(db, header)?;
381✔
126
            Ok(achieved_target_diff)
381✔
127
        } else {
128
            Err(ValidationError::ConsensusError(
2✔
129
                "This mock validator always returns an error".to_string(),
2✔
130
            ))
2✔
131
        }
132
    }
383✔
133
}
134

135
impl TransactionValidator for MockValidator {
136
    fn validate(&self, _transaction: &Transaction) -> Result<(), ValidationError> {
29✔
137
        if self.is_valid.load(Ordering::SeqCst) {
29✔
138
            Ok(())
29✔
139
        } else {
140
            Err(ValidationError::ConsensusError(
×
141
                "This mock validator always returns an error".to_string(),
×
142
            ))
×
143
        }
144
    }
29✔
145
}
146

147
impl<B: BlockchainBackend> FinalHorizonStateValidation<B> for MockValidator {
148
    fn validate(
×
149
        &self,
×
150
        _backend: &B,
×
151
        _height: u64,
×
152
        _total_utxo_sum: &CompressedCommitment,
×
153
        _total_kernel_sum: &CompressedCommitment,
×
154
        _total_burned_sum: &CompressedCommitment,
×
155
    ) -> Result<(), ValidationError> {
×
156
        if self.is_valid.load(Ordering::SeqCst) {
×
157
            Ok(())
×
158
        } else {
159
            Err(ValidationError::ConsensusError(
×
160
                "This mock validator always returns an error".to_string(),
×
161
            ))
×
162
        }
163
    }
×
164
}
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