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

tari-project / tari / 12808840268

16 Jan 2025 12:26PM UTC coverage: 65.465% (+0.003%) from 65.462%
12808840268

push

github

web-flow
feat: new grpc method (#6742)

Description
---
Creates a new grpc method to get the reward of the nextblock, the sha +
rx estimate hash rates and metadata tip info
Adds caching to grpc calls

Motivation and Context
---
Currently, universe calls get_template to just read the reward which is
an expensive operation.
It also streams up to 100 headers to calculate the estimated hash rate. 

Both of these operations can be made much simpler and faster. This PR
provides a call to do just that.
This Pr also adds cahcing to the calls to only update if an update is
required.

0 of 39 new or added lines in 5 files covered. (0.0%)

8 existing lines in 2 files now uncovered.

73018 of 111538 relevant lines covered (65.46%)

273554.43 hits per line

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

17.5
/base_layer/core/src/base_node/comms_interface/comms_request.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::{Display, Error, Formatter},
25
    ops::RangeInclusive,
26
};
27

28
use serde::{Deserialize, Serialize};
29
use tari_common_types::types::{BlockHash, Commitment, HashOutput, PrivateKey, PublicKey, Signature};
30
use tari_utilities::hex::Hex;
31

32
use crate::{blocks::NewBlockTemplate, chain_storage::MmrTree, proof_of_work::PowAlgorithm};
33

34
/// A container for the parameters required for a FetchMmrState request.
35
#[derive(Debug, Serialize, Deserialize)]
×
36
pub struct MmrStateRequest {
37
    pub tree: MmrTree,
38
    pub index: u64,
39
    pub count: u64,
40
}
41

42
/// API Request enum
43
#[derive(Debug, Serialize, Deserialize)]
×
44
pub enum NodeCommsRequest {
45
    GetChainMetadata,
46
    GetTargetDifficultyNextBlock(PowAlgorithm),
47
    FetchHeaders(RangeInclusive<u64>),
48
    FetchHeadersByHashes(Vec<HashOutput>),
49
    FetchMatchingUtxos(Vec<HashOutput>),
50
    FetchMatchingBlocks { range: RangeInclusive<u64>, compact: bool },
51
    FetchBlocksByKernelExcessSigs(Vec<Signature>),
52
    FetchBlocksByUtxos(Vec<Commitment>),
53
    GetHeaderByHash(HashOutput),
54
    GetBlockByHash(HashOutput),
55
    GetNewBlockTemplate(GetNewBlockTemplateRequest),
56
    GetNewBlock(NewBlockTemplate),
57
    GetBlockFromAllChains(HashOutput),
58
    FetchKernelByExcessSig(Signature),
59
    FetchMempoolTransactionsByExcessSigs { excess_sigs: Vec<PrivateKey> },
60
    FetchValidatorNodesKeys { height: u64 },
61
    GetShardKey { height: u64, public_key: PublicKey },
62
    FetchTemplateRegistrations { start_height: u64, end_height: u64 },
63
    FetchUnspentUtxosInBlock { block_hash: BlockHash },
64
}
65

66
#[derive(Debug, Serialize, Deserialize)]
×
67
pub struct GetNewBlockTemplateRequest {
68
    pub algo: PowAlgorithm,
69
    pub max_weight: u64,
70
}
71

72
impl Display for NodeCommsRequest {
73
    fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
8✔
74
        #[allow(clippy::enum_glob_use)]
8✔
75
        use NodeCommsRequest::*;
8✔
76
        match self {
8✔
77
            GetChainMetadata => write!(f, "GetChainMetadata"),
×
NEW
78
            GetTargetDifficultyNextBlock(algo) => write!(f, "GetTargetDifficultyNextBlock ({:?})", algo),
×
79
            FetchHeaders(range) => {
×
80
                write!(f, "FetchHeaders ({:?})", range)
×
81
            },
82
            FetchHeadersByHashes(v) => write!(f, "FetchHeadersByHashes (n={})", v.len()),
×
83
            FetchMatchingUtxos(v) => write!(f, "FetchMatchingUtxos (n={})", v.len()),
×
84
            FetchMatchingBlocks { range, compact } => {
×
85
                write!(f, "FetchMatchingBlocks ({:?}, {})", range, compact)
×
86
            },
87
            FetchBlocksByKernelExcessSigs(v) => write!(f, "FetchBlocksByKernelExcessSigs (n={})", v.len()),
×
88
            FetchBlocksByUtxos(v) => write!(f, "FetchBlocksByUtxos (n={})", v.len()),
×
89
            GetHeaderByHash(v) => write!(f, "GetHeaderByHash({})", v),
×
90
            GetBlockByHash(v) => write!(f, "GetBlockByHash({})", v),
×
91
            GetNewBlockTemplate(v) => write!(f, "GetNewBlockTemplate ({}) with weight {}", v.algo, v.max_weight),
×
92
            GetNewBlock(b) => write!(f, "GetNewBlock (Block Height={})", b.header.height),
×
93
            GetBlockFromAllChains(v) => write!(f, "GetBlockFromAllChains({})", v),
4✔
94
            FetchKernelByExcessSig(s) => write!(
×
95
                f,
×
96
                "FetchKernelByExcessSig (signature=({}, {}))",
×
97
                s.get_public_nonce().to_hex(),
×
98
                s.get_signature().to_hex()
×
99
            ),
×
100
            FetchMempoolTransactionsByExcessSigs { .. } => {
101
                write!(f, "FetchMempoolTransactionsByExcessSigs")
4✔
102
            },
103
            FetchValidatorNodesKeys { height } => {
×
104
                write!(f, "FetchValidatorNodesKeys ({})", height)
×
105
            },
106
            GetShardKey { height, public_key } => {
×
107
                write!(f, "GetShardKey height ({}), public key ({:?})", height, public_key)
×
108
            },
109
            FetchTemplateRegistrations {
110
                start_height: start,
×
111
                end_height: end,
×
112
            } => {
×
113
                write!(f, "FetchTemplateRegistrations ({}..={})", start, end)
×
114
            },
115
            FetchUnspentUtxosInBlock { block_hash } => {
×
116
                write!(f, "FetchUnspentUtxosInBlock ({})", block_hash)
×
117
            },
118
        }
119
    }
8✔
120
}
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