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

tari-project / tari / 15998966652

01 Jul 2025 12:13PM UTC coverage: 71.633% (-0.05%) from 71.686%
15998966652

push

github

web-flow
fix!: payref migration and indexes, add grpc query via output hash (#7266)

Description
---
- Added gRPC method to retrieve output information via output hash
- Updated the gRPC payref search to return spent and unspent output
information
- Added migration to rebuild payref indexes due to missing payrefs
(_added periodic call to `LMDBStore::resize_if_required`_)
- Fixed error in lmdb migration counter where it recorded a higher
version done than what it should

Fixes #7263 

Motivation and Context
---
- Payref information was deleted when the outputs were spent.
- With migrations, payref information was only created for the current
output set, not all outputs.
- Payref lookups for spent outputs were not possible.
- Output and payref information was not possible via output hash.

How Has This Been Tested?
---
- New lmdb migration tested at the system level for fresh and existing
base nodes.
- New gRPC method system-level testing [_tested with block explorer
upgrade_].
- General system-level testing.

Fresh base node with a restart afterwards
```rust
2025-06-27 09:09:24.013840800 [c::cs::lmdb_db::lmdb_db] INFO  [MIGRATIONS] Blockchain database is at v0 (required version: 5)
2025-06-27 09:09:24.013873800 [c::cs::lmdb_db::lmdb_db] INFO  [MIGRATIONS] v1: No accumulated difficulty found for block height 14999
2025-06-27 09:09:24.013877800 [c::cs::lmdb_db::lmdb_db] INFO  [MIGRATIONS] v1: No migration to perform for version network
2025-06-27 09:09:24.013883100 [c::cs::lmdb_db::lmdb_db] INFO  [MIGRATIONS] v2: Starting PayRef migration
2025-06-27 09:09:24.013899700 [c::cs::lmdb_db::lmdb_db] INFO  [MIGRATIONS] v2: Cleared PayRef index
2025-06-27 09:09:24.038671500 [c::cs::lmdb_db::lmdb_db] INFO  [MIGRATIONS] v2: PayRef index rebuild completed
2025-06-27 09:09:24.038693200 [c::cs::lmdb_db::lmdb_db] INFO  [MIGRATIONS] Migrated database from version 2 to version 3
2025-06-27 09:09:24.039646900 [c::cs::lmdb_db::lmdb_db] INFO  [MIGRATIONS] Migrated database from ver... (continued)

24 of 136 new or added lines in 11 files covered. (17.65%)

68 existing lines in 17 files now uncovered.

82832 of 115634 relevant lines covered (71.63%)

239334.93 hits per line

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

10.87
/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
    FixedHash,
34
    HashOutput,
35
    PrivateKey,
36
    Signature,
37
};
38
use tari_utilities::hex::Hex;
39

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

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

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

93
#[derive(Debug, Serialize, Deserialize)]
×
94
pub struct GetNewBlockTemplateRequest {
95
    pub algo: PowAlgorithm,
96
    pub max_weight: u64,
97
}
98

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