Skip to content

feat: auto zero value coinbase reward calculation#7259

Merged
SWvheerden merged 7 commits into
tari-project:developmentfrom
MoneroOcean:patch-3
Jun 30, 2025
Merged

feat: auto zero value coinbase reward calculation#7259
SWvheerden merged 7 commits into
tari-project:developmentfrom
MoneroOcean:patch-3

Conversation

@MoneroOcean

@MoneroOcean MoneroOcean commented Jun 24, 2025

Copy link
Copy Markdown
Contributor

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

Breaking Changes

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

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.

@coderabbitai

coderabbitai Bot commented Jun 24, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

This change updates the base node's gRPC server to handle cases where a block is created with a single coinbase of zero value, setting its value to a minimum or full block reward as appropriate. Two integration test steps are added to verify block creation and submission with a zero-value coinbase. A new test scenario validates this behavior via gRPC.

Changes

File(s) Change Summary
applications/minotari_node/src/grpc/base_node_grpc_server.rs Modifies block template methods to assign a minimal or full reward to a single zero-value coinbase.
integration_tests/tests/steps/node_steps.rs Adds two async test steps for generating and submitting blocks with a single zero-value coinbase.
integration_tests/tests/features/BlockTemplate.feature Adds a scenario to verify gRPC can create blocks with zero value coinbase.

Sequence Diagram(s)

sequenceDiagram
    participant TestStep as Integration Test Step
    participant Node as Tari Node (gRPC)
    TestStep->>Node: Request new block template with coinbases (zero value)
    Node->>Node: If single coinbase & value == 0, set to block reward (min or full)
    Node-->>TestStep: Return block with adjusted coinbase
    TestStep->>Node: Submit block
    Node-->>TestStep: Block submission result
Loading

Possibly related PRs

  • feat: check coinbase count #6880: Adds validation of coinbase counts in block creation, related to coinbase handling but focusing on count checks rather than value adjustment.

Suggested reviewers

  • SWvheerden

Poem

In the land of blocks where coinbase lies,
A zero now blooms, to no one's surprise.
If alone it stands, reward it shall claim,
Ensuring each block is never the same.
Testers rejoice, for rabbits approve,
Hopping through code with a coinbase groove! 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cea06f7 and 05a6fb4.

📒 Files selected for processing (2)
  • applications/minotari_node/src/grpc/base_node_grpc_server.rs (3 hunks)
  • integration_tests/tests/steps/node_steps.rs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • applications/minotari_node/src/grpc/base_node_grpc_server.rs
  • integration_tests/tests/steps/node_steps.rs
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (4)
applications/minotari_node/src/grpc/base_node_grpc_server.rs (1)

1388-1392: Consider standardizing the reward conversion approach.

The auto-coinbase logic is correct, but there's an inconsistency with the first method where reward as u64 is used versus reward.as_u64() here. While both work correctly with their respective types, consider using a consistent pattern for clarity.

-        if coinbases.len() == 1 && coinbases[0].value == 0 {
-            coinbases[0].value = reward.as_u64();
-        }
+        if coinbases.len() == 1 && coinbases[0].value == 0 {
+            coinbases[0].value = reward.as_u64();
+        }

This maintains the current functionality while keeping the conversion method consistent with the established pattern in this codebase.

integration_tests/tests/steps/node_steps.rs (3)

1013-1064: Remove debug print statement and consider using test constants for addresses.

The test logic is correct for validating the zero coinbase feature, but there are code quality improvements needed:

  1. The println! statement on line 1051 should be removed for production code
  2. The hardcoded wallet address reduces maintainability
-    println!("{}", body);

Consider extracting the hardcoded address to a test constant:

+const TEST_WALLET_ADDRESS: &str = "f4L8GRWsXqz26DM3qAGErLtVknYzmTe2fYP2yKFn4biFXYJMP61W9MeD726QJ7ytWhRGyewTZzTzjZ7tEPskDptwRub";

...

-                address: TariAddress::from_base58(
-                    "f4L8GRWsXqz26DM3qAGErLtVknYzmTe2fYP2yKFn4biFXYJMP61W9MeD726QJ7ytWhRGyewTZzTzjZ7tEPskDptwRub",
-                )
-                .unwrap()
-                .to_base58(),
+                address: TariAddress::from_base58(TEST_WALLET_ADDRESS)
+                    .unwrap()
+                    .to_base58(),

1081-1081: Remove unused variable.

The amount variable is calculated but never used, which appears to be leftover code from a copy-paste operation.

-    let amount = miner_data.reward + miner_data.total_fees;

1066-1122: Consider refactoring to reduce code duplication.

This function shares significant code with generate_block_as_single_request_with_zero_coinbase, including:

  • Hardcoded wallet address
  • Identical validation logic for coinbase counts
  • Identical block submission logic

Consider extracting common functionality:

const TEST_WALLET_ADDRESS: &str = "f4L8GRWsXqz26DM3qAGErLtVknYzmTe2fYP2yKFn4biFXYJMP61W9MeD726QJ7ytWhRGyewTZzTzjZ7tEPskDptwRub";

fn create_zero_coinbase() -> NewBlockCoinbase {
    NewBlockCoinbase {
        address: TariAddress::from_base58(TEST_WALLET_ADDRESS)
            .unwrap()
            .to_base58(),
        value: 0,
        stealth_payment: false,
        revealed_value_proof: true,
        coinbase_extra: Vec::new(),
    }
}

fn validate_and_submit_zero_coinbase_block(
    client: &mut grpc::base_node_client::BaseNodeClient<tonic::transport::Channel>,
    block: grpc::Block,
) {
    let mut coinbase_kernel_count = 0;
    let mut coinbase_utxo_count = 0;
    let body: AggregateBody = block.body.clone().unwrap().try_into().unwrap();
    
    for kernel in body.kernels() {
        if kernel.is_coinbase() {
            coinbase_kernel_count += 1;
        }
    }
    for utxo in body.outputs() {
        if utxo.is_coinbase() {
            coinbase_utxo_count += 1;
        }
    }
    
    assert_eq!(coinbase_kernel_count, 1);
    assert_eq!(coinbase_utxo_count, 1);

    match client.submit_block(block).await {
        Ok(_) => (),
        Err(e) => panic!("The block should have been valid, {}", e),
    }
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 86539c8 and 5d047c8.

📒 Files selected for processing (2)
  • applications/minotari_node/src/grpc/base_node_grpc_server.rs (3 hunks)
  • integration_tests/tests/steps/node_steps.rs (1 hunks)
🔇 Additional comments (1)
applications/minotari_node/src/grpc/base_node_grpc_server.rs (1)

1126-1130: LGTM! Auto-coinbase calculation implementation looks correct.

The logic appropriately handles the single zero-value coinbase case by setting it to the full block reward. The conditional check ensures this only applies when there's exactly one coinbase with zero value, which aligns with the PR objectives for mining pool convenience.

Comment thread integration_tests/tests/steps/node_steps.rs

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
integration_tests/tests/features/BlockTemplate.feature (1)

21-21: Fix typo in scenario name.

There's a spelling error in the scenario name: "gprc" should be "grpc".

Apply this diff to fix the typo:

-    Scenario: Verify gprc can create block with zero value coinbase
+    Scenario: Verify grpc can create block with zero value coinbase
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5d047c8 and 9e0f94a.

📒 Files selected for processing (1)
  • integration_tests/tests/features/BlockTemplate.feature (1 hunks)
🔇 Additional comments (1)
integration_tests/tests/features/BlockTemplate.feature (1)

20-26: Well-structured test scenario for zero value coinbase functionality.

The test scenario follows the established patterns in the file and appropriately tests both the separate request and single request approaches. The scenario is correctly marked as critical and maintains consistency with existing test naming conventions.

@MoneroOcean MoneroOcean changed the title Auto zero value coinbase reward calculation feat: auto zero value coinbase reward calculation Jun 24, 2025

@stringhandler stringhandler left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this!

Comment thread applications/minotari_node/src/grpc/base_node_grpc_server.rs Outdated
Co-authored-by: stringhandler <stringhandler@gmail.com>
@github-actions

github-actions Bot commented Jun 27, 2025

Copy link
Copy Markdown

Test Results (CI)

    3 files    126 suites   42m 49s ⏱️
1 353 tests 1 353 ✅ 0 💤 0 ❌
4 057 runs  4 057 ✅ 0 💤 0 ❌

Results for commit 05a6fb4.

♻️ This comment has been updated with latest results.

@github-actions

Copy link
Copy Markdown

Test Results (Integration tests)

 2 files  + 2  10 suites  +10   1h 9m 4s ⏱️ + 1h 9m 4s
33 tests +33  27 ✅ +27  3 💤 +3  3 ❌ +3 
39 runs  +39  27 ✅ +27  3 💤 +3  9 ❌ +9 

For more details on these failures, see this check.

Results for commit cea06f7. ± Comparison against base commit 86539c8.

@hansieodendaal hansieodendaal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please run

cargo +nightly-2025-01-01 fmt --all

otherwise looking good!

SWvheerden
SWvheerden previously approved these changes Jun 30, 2025
@SWvheerden SWvheerden merged commit 607729a into tari-project:development Jun 30, 2025
15 of 16 checks passed
sdbondi added a commit to sdbondi/tari that referenced this pull request Jul 4, 2025
* development:
  chore: fix regression bug (tari-project#7276)
  feat!: expand gRPC readiness status to contain current processed block info (tari-project#7262)
  fix!: payref migration and indexes, add grpc query via output hash (tari-project#7266)
  feat: auto zero value coinbase reward calculation (tari-project#7259)
  feat!: improve grpc token supply (tari-project#7261)
  chore: new release v4.7.0-pre.0 (tari-project#7268)
  fix: get_all_completed_transactions limit issues (tari-project#7267)
  fix: ledger builds (tari-project#7260)
  feat: offline signing (tari-project#7122)
  test: verify accumulated difficulty (tari-project#7243)
@metalaureate metalaureate added bounty bounty-S retro-bounty Retroactively awarded bounty and removed bounty labels May 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bounty-S retro-bounty Retroactively awarded bounty

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants