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

tari-project / tari / 17033178607

18 Aug 2025 06:45AM UTC coverage: 54.49% (-0.007%) from 54.497%
17033178607

push

github

stringhandler
Merge branch 'development' of github.com:tari-project/tari into odev

971 of 2923 new or added lines in 369 files covered. (33.22%)

5804 existing lines in 173 files now uncovered.

76688 of 140739 relevant lines covered (54.49%)

193850.18 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_service_framework::{reply_channel::SenderService, Service};
26
use tokio::sync::mpsc::UnboundedSender;
27

28
use crate::{
29
    base_node::comms_interface::{
30
        error::CommsInterfaceError,
31
        FetchMempoolTransactionsResponse,
32
        NodeCommsRequest,
33
        NodeCommsResponse,
34
    },
35
    blocks::{Block, NewBlock},
36
};
37

38
/// The OutboundNodeCommsInterface provides an interface to request information from remove nodes.
39
#[derive(Clone)]
40
pub struct OutboundNodeCommsInterface {
41
    request_sender: SenderService<(NodeCommsRequest, Option<NodeId>), Result<NodeCommsResponse, CommsInterfaceError>>,
42
    block_sender: UnboundedSender<(NewBlock, Vec<NodeId>)>,
43
}
44

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

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

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

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