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

tari-project / tari / 15983436312

30 Jun 2025 08:52PM UTC coverage: 71.686% (-0.2%) from 71.908%
15983436312

push

github

web-flow
feat: auto zero value coinbase reward calculation (#7259)

Description
---
This adds way to auto use correct (max) coinbase value in case you pass
single coinbase with zero value.

Motivation and Context
---
This is hard to guess correct coinbase value to pass its check in
GetNewBlockWithCoinbases and GetNewBlockTemplateWithCoinbases GRPC
methods.

How Has This Been Tested?
---
Tested as part of RandomX-T pool implementation. Will add new
integration tests to this PR but I was not able to run them locally
since I can't find seed node setup environment.

What process can a PR reviewer use to test or verify this change?
---
Run new integration scenario: Verify gprc can create block with zero
value coinbase

<!-- Checklist -->
<!-- 1. Is the title of your PR in the form that would make nice release
notes? The title, excluding the conventional commit
tag, will be included exactly as is in the CHANGELOG, so please think
about it carefully. -->


Breaking Changes
---

- [x] None
- [ ] Requires data directory on base node to be deleted
- [ ] Requires hard fork
- [ ] Other - Please specify

<!-- Does this include a breaking change? If so, include this line as a
footer -->
<!-- BREAKING CHANGE: Description what the user should do, e.g. delete a
database, resync the chain -->


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **Bug Fixes**
- Improved handling of blocks with a single zero-value coinbase,
ensuring it is assigned a minimal or full block reward as appropriate.
- **Tests**
- Added integration tests to verify processing and submission of blocks
containing a single zero-value coinbase output.
- Introduced a test scenario validating block creation with a zero-value
coinbase via the gRPC interface.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: stringhandler <stringhandler@gmail.com>
Co-authored-by: SW van Heerden <swvheerden@gmail.com>

82866 of 115596 relevant lines covered (71.69%)

239780.82 hits per line

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

0.0
/base_layer/core/src/base_node/sync/block_sync/error.rs
1
//  Copyright 2020, 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::time::Duration;
24

25
use tari_common_types::types::FixedHashSizeError;
26
use tari_comms::{
27
    connectivity::ConnectivityError,
28
    peer_manager::NodeId,
29
    protocol::rpc::{RpcError, RpcStatus, RpcStatusCode},
30
};
31

32
use crate::{
33
    chain_storage::ChainStorageError,
34
    common::{BanPeriod, BanReason},
35
    validation::ValidationError,
36
};
37

38
#[derive(Debug, thiserror::Error)]
39
pub enum BlockSyncError {
40
    #[error("Async validation task failed: {0}")]
41
    AsyncTaskFailed(#[from] tokio::task::JoinError),
42
    #[error("RPC error: {0}")]
43
    RpcError(#[from] RpcError),
44
    #[error("RPC request failed: {0}")]
45
    RpcRequestError(#[from] RpcStatus),
46
    #[error("Chain storage error: {0}")]
47
    ChainStorageError(#[from] ChainStorageError),
48
    #[error("Peer sent a block that did not form a chain. Expected hash = {expected}, got = {got}")]
49
    BlockWithoutParent { expected: String, got: String },
50
    #[error("Connectivity Error: {0}")]
51
    ConnectivityError(#[from] ConnectivityError),
52
    #[error("No more sync peers available: {0}")]
53
    NoMoreSyncPeers(String),
54
    #[error("Block validation failed: {0}")]
55
    ValidationError(#[from] ValidationError),
56
    #[error("Failed to construct valid chain block")]
57
    FailedToConstructChainBlock,
58
    #[error("Peer sent unknown hash")]
59
    UnknownHeaderHash(String),
60
    #[error("Peer sent block with invalid block body")]
61
    InvalidBlockBody(String),
62
    #[error("Peer {peer} exceeded maximum permitted sync latency. latency: {latency:.2?}, max: {max_latency:.2?}")]
63
    MaxLatencyExceeded {
64
        peer: NodeId,
65
        latency: Duration,
66
        max_latency: Duration,
67
    },
68
    #[error("All sync peers exceeded max allowed latency")]
69
    AllSyncPeersExceedLatency,
70
    #[error("FixedHash size error: {0}")]
71
    FixedHashSizeError(#[from] FixedHashSizeError),
72
    #[error("This sync round failed")]
73
    SyncRoundFailed,
74
    #[error("Could not find peer info")]
75
    PeerNotFound,
76
    #[error("Peer did not supply all the blocks they claimed they had: {0}")]
77
    PeerDidNotSupplyAllClaimedBlocks(String),
78
}
79

80
impl BlockSyncError {
81
    pub fn to_short_str(&self) -> &'static str {
×
82
        match self {
×
83
            BlockSyncError::RpcError(_) => "RpcError",
×
84
            BlockSyncError::RpcRequestError(status) if status.as_status_code() == RpcStatusCode::Timeout => {
×
85
                "RpcTimeout"
×
86
            },
87
            BlockSyncError::RpcRequestError(_) => "RpcRequestError",
×
88
            BlockSyncError::AsyncTaskFailed(_) => "AsyncTaskFailed",
×
89
            BlockSyncError::ChainStorageError(_) => "ChainStorageError",
×
90
            BlockSyncError::BlockWithoutParent { .. } => "PeerSentBlockThatDidNotFormAChain",
×
91
            BlockSyncError::ConnectivityError(_) => "ConnectivityError",
×
92
            BlockSyncError::NoMoreSyncPeers(_) => "NoMoreSyncPeers",
×
93
            BlockSyncError::ValidationError(_) => "ValidationError",
×
94
            BlockSyncError::FailedToConstructChainBlock => "FailedToConstructChainBlock",
×
95
            BlockSyncError::UnknownHeaderHash(_) => "UnknownHeaderHash",
×
96
            BlockSyncError::InvalidBlockBody(_) => "InvalidBlockBody",
×
97
            BlockSyncError::MaxLatencyExceeded { .. } => "MaxLatencyExceeded",
×
98
            BlockSyncError::AllSyncPeersExceedLatency => "AllSyncPeersExceedLatency",
×
99
            BlockSyncError::FixedHashSizeError(_) => "FixedHashSizeError",
×
100
            BlockSyncError::SyncRoundFailed => "SyncRoundFailed",
×
101
            BlockSyncError::PeerNotFound => "PeerNotFound",
×
102
            BlockSyncError::PeerDidNotSupplyAllClaimedBlocks(_) => "PeerDidNotSupplyAllClaimedBlocks",
×
103
        }
104
    }
×
105
}
106

107
impl BlockSyncError {
108
    pub fn get_ban_reason(&self) -> Option<BanReason> {
×
109
        match self {
×
110
            // no ban
111
            BlockSyncError::AsyncTaskFailed(_) |
112
            BlockSyncError::ConnectivityError(_) |
113
            BlockSyncError::NoMoreSyncPeers(_) |
114
            BlockSyncError::AllSyncPeersExceedLatency |
115
            BlockSyncError::FailedToConstructChainBlock |
116
            BlockSyncError::PeerNotFound |
117
            BlockSyncError::SyncRoundFailed => None,
×
118
            BlockSyncError::ChainStorageError(e) => e.get_ban_reason(),
×
119
            // short ban
120
            err @ BlockSyncError::MaxLatencyExceeded { .. } |
×
121
            err @ BlockSyncError::PeerDidNotSupplyAllClaimedBlocks(_) |
×
122
            err @ BlockSyncError::RpcError(_) |
×
123
            err @ BlockSyncError::RpcRequestError(_) => Some(BanReason {
×
124
                reason: format!("{}", err),
×
125
                ban_duration: BanPeriod::Short,
×
126
            }),
×
127

128
            // long ban
129
            err @ BlockSyncError::BlockWithoutParent { .. } |
×
130
            err @ BlockSyncError::UnknownHeaderHash(_) |
×
131
            err @ BlockSyncError::InvalidBlockBody(_) |
×
132
            err @ BlockSyncError::FixedHashSizeError(_) => Some(BanReason {
×
133
                reason: format!("{}", err),
×
134
                ban_duration: BanPeriod::Long,
×
135
            }),
×
136

137
            BlockSyncError::ValidationError(err) => ValidationError::get_ban_reason(err),
×
138
        }
139
    }
×
140
}
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