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

tari-project / tari / 13026118674

29 Jan 2025 06:54AM UTC coverage: 73.945% (-0.05%) from 73.991%
13026118674

push

github

web-flow
feat: fix mempool sync start early (#6767)

Description
---
Mempool sync can only start when `is_synced` is set to `true`.
- An edge case was witnessed whereby mempool sync can start early if the
entire network is generally
slow to respond to pings. The `ChainMetadataEvent::NetworkSilence` event
is transmitted if 3x
consecutive ping cycles were started without corresponding pongs
received, which sets
`is_synced` to `true`. The moment that peer metadata is then received,
block sync and mempool sync
will occur at the same time. 
- Prolonged network silence is now detected in the `Starting` state. At
startup, the first successful metadata message received from a peer will
signal the transition to `Listening`, otherwise `Listening` will be
notified of the network silence, which can act accordingly.
- Additional debug logs were added to track all events that can set the
`is_synced` to `true`.
- Removed `log-mdc` from the dependencies as the relevant code is not
used.

The edge case warning message must be monitored to see if it is a real
issue:
```rust
warn!(
    target: LOG_TARGET,
    "Initial sync achieved based on event 'NetworkSilence'; this may not be true if the entire \
    network in general is slow to respond to pings"
);
```

Fixes #6766

Motivation and Context
---
Mempool sync _"started"_ before block sync was achieved.

How Has This Been Tested?
---
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... (continued)

33 of 70 new or added lines in 7 files covered. (47.14%)

59 existing lines in 15 files now uncovered.

83447 of 112850 relevant lines covered (73.95%)

276136.87 hits per line

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

0.0
/base_layer/core/src/base_node/comms_interface/comms_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
    fmt::{self, Display, Formatter},
25
    sync::Arc,
26
};
27

28
use tari_common_types::{
29
    chain_metadata::ChainMetadata,
30
    types::{CompressedPublicKey, HashOutput, PrivateKey},
31
};
32

33
use crate::{
34
    blocks::{Block, ChainHeader, HistoricalBlock, NewBlockTemplate},
35
    chain_storage::TemplateRegistrationEntry,
36
    proof_of_work::Difficulty,
37
    transactions::transaction_components::{Transaction, TransactionKernel, TransactionOutput},
38
};
39

40
/// API Response enum
41
#[allow(clippy::large_enum_variant)]
42
#[derive(Debug, Clone)]
43
pub enum NodeCommsResponse {
44
    ChainMetadata(ChainMetadata),
45
    TransactionKernels(Vec<TransactionKernel>),
46
    BlockHeaders(Vec<ChainHeader>),
47
    BlockHeader(Option<ChainHeader>),
48
    Block(Box<Option<Block>>),
49
    TransactionOutputs(Vec<TransactionOutput>),
50
    HistoricalBlocks(Vec<HistoricalBlock>),
51
    HistoricalBlock(Box<Option<HistoricalBlock>>),
52
    NewBlockTemplate(NewBlockTemplate),
53
    NewBlock {
54
        success: bool,
55
        error: Option<String>,
56
        block: Option<Block>,
57
    },
58
    TargetDifficulty(Difficulty),
59
    MmrNodes(Vec<HashOutput>, Vec<u8>),
60
    FetchMempoolTransactionsByExcessSigsResponse(FetchMempoolTransactionsResponse),
61
    FetchValidatorNodesKeysResponse(Vec<(CompressedPublicKey, [u8; 32])>),
62
    GetShardKeyResponse(Option<[u8; 32]>),
63
    FetchTemplateRegistrationsResponse(Vec<TemplateRegistrationEntry>),
64
}
65

66
impl Display for NodeCommsResponse {
UNCOV
67
    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
×
UNCOV
68
        #[allow(clippy::enum_glob_use)]
×
UNCOV
69
        use NodeCommsResponse::*;
×
UNCOV
70
        match self {
×
UNCOV
71
            ChainMetadata(_) => write!(f, "ChainMetadata"),
×
72
            TransactionKernels(_) => write!(f, "TransactionKernel"),
×
73
            BlockHeaders(_) => write!(f, "BlockHeaders"),
×
74
            BlockHeader(_) => write!(f, "BlockHeader"),
×
75
            Block(_) => write!(f, "Block"),
×
76
            HistoricalBlock(_) => write!(f, "HistoricalBlock"),
×
77
            TransactionOutputs(_) => write!(f, "TransactionOutputs"),
×
78
            HistoricalBlocks(_) => write!(f, "HistoricalBlocks"),
×
79
            NewBlockTemplate(_) => write!(f, "NewBlockTemplate"),
×
80
            NewBlock {
81
                success,
×
82
                error,
×
83
                block: _,
×
84
            } => write!(
×
85
                f,
×
86
                "NewBlock({},{},...)",
×
87
                success,
×
88
                error.as_ref().unwrap_or(&"Unspecified".to_string())
×
89
            ),
×
90
            TargetDifficulty(_) => write!(f, "TargetDifficulty"),
×
91
            MmrNodes(_, _) => write!(f, "MmrNodes"),
×
92
            FetchMempoolTransactionsByExcessSigsResponse(resp) => write!(
×
93
                f,
×
94
                "FetchMempoolTransactionsByExcessSigsResponse({} transaction(s), {} not found)",
×
95
                resp.transactions.len(),
×
96
                resp.not_found.len()
×
97
            ),
×
98
            FetchValidatorNodesKeysResponse(_) => write!(f, "FetchValidatorNodesKeysResponse"),
×
99
            GetShardKeyResponse(_) => write!(f, "GetShardKeyResponse"),
×
100
            FetchTemplateRegistrationsResponse(_) => write!(f, "FetchTemplateRegistrationsResponse"),
×
101
        }
UNCOV
102
    }
×
103
}
104

105
/// Container struct for mempool transaction responses
106
#[derive(Debug, Clone)]
107
pub struct FetchMempoolTransactionsResponse {
108
    pub transactions: Vec<Arc<Transaction>>,
109
    pub not_found: Vec<PrivateKey>,
110
}
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