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

tari-project / tari / 13012261930

28 Jan 2025 02:09PM UTC coverage: 73.991% (+8.6%) from 65.396%
13012261930

push

github

web-flow
feat: keep keys in compressed form (#6753)

Description
---
Keeps all crypto public keys in compressed form, and only uncompressing
when needed.

Motivation and Context
---
This should improve speed and reduce the compression of keys. Comparing
unit test speeds this PR is roughly the same as before. But unit test
almost always do crypto operations to ensure everything is correct.
Where this PR increases performance is when only reading something and
providing it. For example, just reading the mainnet gen block in its
current form on avg it takes 56 seconds. With this pr this time is taken
down to on avg 15 seconds. Thats a 370% speed improvement.

How Has This Been Tested?
---
unit tests

1623 of 2110 new or added lines in 123 files covered. (76.92%)

335 existing lines in 28 files now uncovered.

83511 of 112867 relevant lines covered (73.99%)

273339.14 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::{
30
    BlockHash,
31
    CompressedCommitment,
32
    CompressedPublicKey,
33
    HashOutput,
34
    PrivateKey,
35
    Signature,
36
};
37
use tari_utilities::hex::Hex;
38

39
use crate::{blocks::NewBlockTemplate, chain_storage::MmrTree, proof_of_work::PowAlgorithm};
40

41
/// A container for the parameters required for a FetchMmrState request.
42
#[derive(Debug, Serialize, Deserialize)]
×
43
pub struct MmrStateRequest {
44
    pub tree: MmrTree,
45
    pub index: u64,
46
    pub count: u64,
47
}
48

49
/// API Request enum
50
#[derive(Debug, Serialize, Deserialize)]
×
51
pub enum NodeCommsRequest {
52
    GetChainMetadata,
53
    GetTargetDifficultyNextBlock(PowAlgorithm),
54
    FetchHeaders(RangeInclusive<u64>),
55
    FetchHeadersByHashes(Vec<HashOutput>),
56
    FetchMatchingUtxos(Vec<HashOutput>),
57
    FetchMatchingBlocks {
58
        range: RangeInclusive<u64>,
59
        compact: bool,
60
    },
61
    FetchBlocksByKernelExcessSigs(Vec<Signature>),
62
    FetchBlocksByUtxos(Vec<CompressedCommitment>),
63
    GetHeaderByHash(HashOutput),
64
    GetBlockByHash(HashOutput),
65
    GetNewBlockTemplate(GetNewBlockTemplateRequest),
66
    GetNewBlock(NewBlockTemplate),
67
    GetBlockFromAllChains(HashOutput),
68
    FetchKernelByExcessSig(Signature),
69
    FetchMempoolTransactionsByExcessSigs {
70
        excess_sigs: Vec<PrivateKey>,
71
    },
72
    FetchValidatorNodesKeys {
73
        height: u64,
74
    },
75
    GetShardKey {
76
        height: u64,
77
        public_key: CompressedPublicKey,
78
    },
79
    FetchTemplateRegistrations {
80
        start_height: u64,
81
        end_height: u64,
82
    },
83
    FetchUnspentUtxosInBlock {
84
        block_hash: BlockHash,
85
    },
86
}
87

88
#[derive(Debug, Serialize, Deserialize)]
×
89
pub struct GetNewBlockTemplateRequest {
90
    pub algo: PowAlgorithm,
91
    pub max_weight: u64,
92
}
93

94
impl Display for NodeCommsRequest {
95
    fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
8✔
96
        #[allow(clippy::enum_glob_use)]
8✔
97
        use NodeCommsRequest::*;
8✔
98
        match self {
8✔
99
            GetChainMetadata => write!(f, "GetChainMetadata"),
×
100
            GetTargetDifficultyNextBlock(algo) => write!(f, "GetTargetDifficultyNextBlock ({:?})", algo),
×
101
            FetchHeaders(range) => {
×
102
                write!(f, "FetchHeaders ({:?})", range)
×
103
            },
104
            FetchHeadersByHashes(v) => write!(f, "FetchHeadersByHashes (n={})", v.len()),
×
105
            FetchMatchingUtxos(v) => write!(f, "FetchMatchingUtxos (n={})", v.len()),
×
106
            FetchMatchingBlocks { range, compact } => {
×
107
                write!(f, "FetchMatchingBlocks ({:?}, {})", range, compact)
×
108
            },
109
            FetchBlocksByKernelExcessSigs(v) => write!(f, "FetchBlocksByKernelExcessSigs (n={})", v.len()),
×
110
            FetchBlocksByUtxos(v) => write!(f, "FetchBlocksByUtxos (n={})", v.len()),
×
111
            GetHeaderByHash(v) => write!(f, "GetHeaderByHash({})", v),
×
112
            GetBlockByHash(v) => write!(f, "GetBlockByHash({})", v),
×
113
            GetNewBlockTemplate(v) => write!(f, "GetNewBlockTemplate ({}) with weight {}", v.algo, v.max_weight),
×
114
            GetNewBlock(b) => write!(f, "GetNewBlock (Block Height={})", b.header.height),
×
115
            GetBlockFromAllChains(v) => write!(f, "GetBlockFromAllChains({})", v),
4✔
116
            FetchKernelByExcessSig(s) => write!(
×
117
                f,
×
118
                "FetchKernelByExcessSig (signature=({}, {}))",
×
NEW
119
                s.get_compressed_public_nonce().to_hex(),
×
120
                s.get_signature().to_hex()
×
121
            ),
×
122
            FetchMempoolTransactionsByExcessSigs { .. } => {
123
                write!(f, "FetchMempoolTransactionsByExcessSigs")
4✔
124
            },
125
            FetchValidatorNodesKeys { height } => {
×
126
                write!(f, "FetchValidatorNodesKeys ({})", height)
×
127
            },
128
            GetShardKey { height, public_key } => {
×
129
                write!(f, "GetShardKey height ({}), public key ({:?})", height, public_key)
×
130
            },
131
            FetchTemplateRegistrations {
132
                start_height: start,
×
133
                end_height: end,
×
134
            } => {
×
135
                write!(f, "FetchTemplateRegistrations ({}..={})", start, end)
×
136
            },
137
            FetchUnspentUtxosInBlock { block_hash } => {
×
138
                write!(f, "FetchUnspentUtxosInBlock ({})", block_hash)
×
139
            },
140
        }
141
    }
8✔
142
}
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