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

tari-project / tari / 17275382059

27 Aug 2025 06:28PM UTC coverage: 60.14% (-0.1%) from 60.274%
17275382059

push

github

web-flow
chore: new release v5.0.0-pre.8 (#7446)

Description
---
new release

71505 of 118897 relevant lines covered (60.14%)

536444.51 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/outbound_interface.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::{BlockHash, PrivateKey};
24
use tari_comms::peer_manager::NodeId;
25
use tari_node_components::blocks::{Block, NewBlock};
26
use tari_service_framework::{reply_channel::SenderService, Service};
27
use tokio::sync::mpsc::UnboundedSender;
28

29
use crate::base_node::comms_interface::{
30
    error::CommsInterfaceError,
31
    FetchMempoolTransactionsResponse,
32
    NodeCommsRequest,
33
    NodeCommsResponse,
34
};
35
/// The OutboundNodeCommsInterface provides an interface to request information from remove nodes.
36
#[derive(Clone)]
37
pub struct OutboundNodeCommsInterface {
38
    request_sender: SenderService<(NodeCommsRequest, Option<NodeId>), Result<NodeCommsResponse, CommsInterfaceError>>,
39
    block_sender: UnboundedSender<(NewBlock, Vec<NodeId>)>,
40
}
41

42
impl OutboundNodeCommsInterface {
43
    /// Construct a new OutboundNodeCommsInterface with the specified SenderService.
44
    pub fn new(
×
45
        request_sender: SenderService<
×
46
            (NodeCommsRequest, Option<NodeId>),
×
47
            Result<NodeCommsResponse, CommsInterfaceError>,
×
48
        >,
×
49
        block_sender: UnboundedSender<(NewBlock, Vec<NodeId>)>,
×
50
    ) -> Self {
×
51
        Self {
×
52
            request_sender,
×
53
            block_sender,
×
54
        }
×
55
    }
×
56

57
    /// Fetch the Blocks corresponding to the provided block hashes from a specific base node.
58
    pub async fn request_blocks_by_hashes_from_peer(
×
59
        &mut self,
×
60
        hash: BlockHash,
×
61
        node_id: Option<NodeId>,
×
62
    ) -> Result<Option<Block>, CommsInterfaceError> {
×
63
        if let NodeCommsResponse::Block(block) = self
×
64
            .request_sender
×
65
            .call((NodeCommsRequest::GetBlockFromAllChains(hash), node_id))
×
66
            .await??
×
67
        {
68
            Ok(*block)
×
69
        } else {
70
            Err(CommsInterfaceError::UnexpectedApiResponse)
×
71
        }
72
    }
×
73

74
    /// Fetch the transactions corresponding to the provided excess_sigs from the given peer `NodeId`.
75
    pub async fn request_transactions_by_excess_sig(
×
76
        &mut self,
×
77
        node_id: NodeId,
×
78
        excess_sigs: Vec<PrivateKey>,
×
79
    ) -> Result<FetchMempoolTransactionsResponse, CommsInterfaceError> {
×
80
        if let NodeCommsResponse::FetchMempoolTransactionsByExcessSigsResponse(resp) = self
×
81
            .request_sender
×
82
            .call((
×
83
                NodeCommsRequest::FetchMempoolTransactionsByExcessSigs { excess_sigs },
×
84
                Some(node_id),
×
85
            ))
×
86
            .await??
×
87
        {
88
            Ok(resp)
×
89
        } else {
90
            Err(CommsInterfaceError::UnexpectedApiResponse)
×
91
        }
92
    }
×
93

94
    /// Transmit a block to remote base nodes, excluding the provided peers.
95
    pub async fn propagate_block(
×
96
        &self,
×
97
        new_block: NewBlock,
×
98
        exclude_peers: Vec<NodeId>,
×
99
    ) -> Result<(), CommsInterfaceError> {
×
100
        self.block_sender
×
101
            .send((new_block, exclude_peers))
×
102
            .map_err(|err| CommsInterfaceError::InternalChannelError(format!("Failed to send on block_sender: {err}")))
×
103
    }
×
104
}
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