Skip to content

feat: overrride coinbase payment_id if included in wallet payment address#7038

Merged
SWvheerden merged 2 commits intotari-project:developmentfrom
hansieodendaal:ho_coinbase_payment_id
May 9, 2025
Merged

feat: overrride coinbase payment_id if included in wallet payment address#7038
SWvheerden merged 2 commits intotari-project:developmentfrom
hansieodendaal:ho_coinbase_payment_id

Conversation

@hansieodendaal
Copy link
Copy Markdown
Contributor

@hansieodendaal hansieodendaal commented May 8, 2025

Description

Added coinbase payment_id to the coinbase from the wallet payment address if it exists.

Motivation and Context

This functionality can be used by pool operators.

How Has This Been Tested?

Added new unit test - test_generate_coinbase_with_payment_id_from_address

What process can a PR reviewer use to test or verify this change?

Code review

Breaking Changes

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

Summary by CodeRabbit

  • New Features

    • Added support for a new "Coinbase" transaction type.
    • Enhanced coinbase transaction creation to embed payment ID user data directly from wallet addresses.
  • Bug Fixes

    • Improved extraction and handling of payment ID user data from addresses when sending transactions.
    • Extended transaction handling logic to treat "Coinbase" transactions consistently with other special types.
  • Tests

    • Added test verifying coinbase creation with embedded payment ID user data.
  • Refactor

    • Renamed several address and payment ID methods for improved clarity and consistency.

@hansieodendaal hansieodendaal requested a review from a team as a code owner May 8, 2025 14:29
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented May 8, 2025

"""

Walkthrough

This update refactors payment ID handling across several modules by renaming methods to clarify their association with user data. It introduces a new Coinbase transaction type, updates logic to support payment ID overrides from address user data, and adds tests for this functionality. Multiple coinbase generation calls now use an open payment ID with the Coinbase transaction type. No public API signatures are removed; only method names and internal logic are updated.

Changes

File(s) Change Summary
base_layer/common_types/src/tari_address/dual_address.rs,
base_layer/common_types/src/tari_address/mod.rs
Renamed payment ID methods to emphasize user data (add_payment_idadd_payment_id_user_data, get_payment_id_bytesget_payment_id_user_data_bytes). Updated internal calls accordingly.
applications/minotari_console_wallet/src/grpc/wallet_grpc_server.rs Updated gRPC handler to use renamed address methods (with_payment_id_user_data) for payment ID incorporation, replacing previous create_payment_id_address calls.
base_layer/core/src/transactions/coinbase_builder.rs Enhanced coinbase builder to override payment ID with address-embedded user data if present. Added an async test verifying this override logic. Adjusted imports for new functionality.
base_layer/core/src/transactions/transaction_components/encrypted_data.rs Added Coinbase variant to TxType enum. Updated serialization, deserialization, display, and tests to support the new variant.
base_layer/wallet/src/transaction_service/service.rs Modified transaction sending logic to extract payment ID from user data bytes using renamed methods in three locations. Added Coinbase tx type alongside HtlcAtomicSwapRefund in transaction direction and address logic.
applications/minotari_merge_mining_proxy/src/block_template_manager.rs,
applications/minotari_miner/src/run_miner.rs,
applications/minotari_node/src/grpc/base_node_grpc_server.rs,
base_layer/core/src/test_helpers/mod.rs,
base_layer/tari_mining_helper_ffi/src/lib.rs,
integration_tests/src/miner.rs
Changed coinbase generation calls to use PaymentId::Open with empty user data and TxType::Coinbase instead of PaymentId::Empty. Updated imports to include TxType.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant WalletAddress
    participant CoinbaseBuilder

    Caller->>WalletAddress: get_payment_id_user_data_bytes()
    alt If user data is present
        WalletAddress-->>Caller: payment_id_bytes
        Caller->>CoinbaseBuilder: generate_coinbase_with_wallet_output(..., payment_id=empty)
        CoinbaseBuilder->>WalletAddress: get_payment_id_user_data_bytes()
        CoinbaseBuilder-->>Caller: Output with payment_id = user data
    else No user data
        WalletAddress-->>Caller: empty
        Caller->>CoinbaseBuilder: generate_coinbase_with_wallet_output(..., payment_id)
        CoinbaseBuilder-->>Caller: Output with provided payment_id
    end
Loading

Possibly related PRs

  • fix: payment id tari address usage #7002: Renames and updates method calls related to payment ID handling on Tari addresses, directly modifying the same TariAddress methods and their usage as addressed in this PR.

Suggested reviewers

  • SWvheerden

Poem

In fields of code where rabbits hop,
Payment IDs now wear a user-data top.
Coinbase shines with a brand new face,
As methods are renamed with elegant grace.
Tests nibble through to verify the way—
A carrot for each bug kept at bay!
🥕
"""

Tip

⚡️ Faster reviews with caching
  • CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.

Enjoy the performance boost—your workflow just got faster.


📜 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 8778fee and f6250af.

📒 Files selected for processing (1)
  • base_layer/core/src/transactions/coinbase_builder.rs (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • base_layer/core/src/transactions/coinbase_builder.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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

@github-actions
Copy link
Copy Markdown

github-actions bot commented May 8, 2025

Test Results (Integration tests)

 2 files  11 suites   1h 38m 39s ⏱️
36 tests 30 ✅ 0 💤  6 ❌
46 runs  32 ✅ 0 💤 14 ❌

For more details on these failures, see this check.

Results for commit f6250af.

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Copy Markdown

github-actions bot commented May 8, 2025

Test Results (CI)

1 083 tests   1 078 ✅  15m 58s ⏱️
   30 suites      0 💤
    1 files        5 ❌

For more details on these failures, see this check.

Results for commit f6250af.

♻️ This comment has been updated with latest results.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

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)
base_layer/core/src/transactions/coinbase_builder.rs (1)

452-460: New feature to override payment ID from wallet address.

This is the core functionality change that checks if the wallet address contains a payment ID user data and uses it to override the provided payment ID for coinbase transactions. This will be useful for pool operators as mentioned in the PR description.

There's a minor typo in the comment on line 452: "pyment" should be "payment".

-    // Override payment id if the wallet address contains a pyment id
+    // Override payment id if the wallet address contains a payment id
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0c83469 and d662466.

📒 Files selected for processing (6)
  • applications/minotari_console_wallet/src/grpc/wallet_grpc_server.rs (1 hunks)
  • base_layer/common_types/src/tari_address/dual_address.rs (2 hunks)
  • base_layer/common_types/src/tari_address/mod.rs (1 hunks)
  • base_layer/core/src/transactions/coinbase_builder.rs (5 hunks)
  • base_layer/core/src/transactions/transaction_components/encrypted_data.rs (7 hunks)
  • base_layer/wallet/src/transaction_service/service.rs (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
base_layer/wallet/src/transaction_service/service.rs (1)
base_layer/core/src/transactions/transaction_components/encrypted_data.rs (1)
  • open (566-571)
base_layer/common_types/src/tari_address/dual_address.rs (1)
base_layer/common_types/src/tari_address/mod.rs (1)
  • get_payment_id_user_data_bytes (242-247)
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: Cucumber tests / Base Layer
  • GitHub Check: Cucumber tests / FFI
  • GitHub Check: ci
  • GitHub Check: test (mainnet, stagenet)
  • GitHub Check: test (nextnet, nextnet)
  • GitHub Check: test (testnet, esmeralda)
🔇 Additional comments (18)
applications/minotari_console_wallet/src/grpc/wallet_grpc_server.rs (2)

275-276: Method name update for consistency.

The method name change from create_payment_id_address to with_payment_id_user_data reflects a more accurate description of the functionality and maintains consistent naming across the codebase.


283-284: Method name update for consistency.

Similar to the change above, this method name change improves clarity by explicitly indicating that the payment ID is being stored as user data in the address.

base_layer/wallet/src/transaction_service/service.rs (2)

1209-1209: Method rename to clarify user data context.

The method has been renamed from get_payment_id_bytes() to get_payment_id_user_data_bytes() to better describe that these bytes come from user data embedded in the address.


1764-1764: Method rename to clarify user data context.

The method has been renamed from get_payment_id_bytes() to get_payment_id_user_data_bytes() to better describe that these bytes come from user data embedded in the address. This change is consistent with the update in send_transaction().

base_layer/common_types/src/tari_address/dual_address.rs (2)

92-99: Method name change clarifies purpose.

The method rename from add_payment_id to add_payment_id_user_data better reflects that this method deals with user data related to payment IDs rather than payment IDs themselves. This naming is more precise and consistent with the overall payment ID refactoring.


129-131: Method name change clarifies purpose.

Renaming get_payment_id_bytes to get_payment_id_user_data_bytes improves clarity by explicitly stating that the method returns user data bytes associated with a payment ID, not the payment ID itself. This change aligns with the corresponding method renamed in the TariAddress enum.

base_layer/core/src/transactions/transaction_components/encrypted_data.rs (7)

96-96: New Coinbase transaction type added.

The addition of a Coinbase variant with bit pattern 0b1011 supports the PR objective of enhancing coinbase transaction generation by providing a dedicated transaction type.


116-116: Coinbase variant properly implemented in from_u16 method.

The new Coinbase transaction type is correctly handled in the conversion from u16 values, maintaining consistency with the type system.


133-133: Coinbase variant properly implemented in as_u8 method.

The serialization of the Coinbase transaction type is correctly implemented to return its binary representation 0b1011.


155-155: Display implementation for Coinbase transaction type.

The Display trait implementation is properly updated to handle the new Coinbase variant, ensuring consistent string representation.


1105-1106: Test cases updated for Coinbase transaction type.

The test cases have been properly updated to include the new Coinbase transaction type, ensuring proper test coverage for the new functionality.


1227-1228: Coinbase variant included in serialization tests.

The Coinbase transaction type is correctly included in the serialization/deserialization tests, ensuring that it works properly with the existing serialization mechanisms.


1372-1388: Fee handling tests updated for Coinbase transaction type.

Tests for metadata handling with overflow conditions have been updated to use the new Coinbase transaction type, ensuring consistency throughout the test suite.

base_layer/common_types/src/tari_address/mod.rs (2)

242-247: Method name change for consistency.

Renaming get_payment_id_bytes to get_payment_id_user_data_bytes in the TariAddress enum maintains consistency with the underlying DualAddress implementation and clarifies the method purpose. The implementation correctly delegates to the renamed method in DualAddress.


249-258: Method name change improves clarity.

Renaming create_payment_id_address to with_payment_id_user_data better describes the method's functionality as adding user data to an existing address rather than creating a new address. The implementation correctly calls the renamed method in DualAddress.

base_layer/core/src/transactions/coinbase_builder.rs (3)

44-44: Update to import dependencies for payment ID handling.

This change adds the import of TxType enum which is needed for the new payment ID override functionality.


794-814: Updated imports for test module.

Added necessary imports to support the new test function.


1234-1281: Good test coverage for the new payment ID override functionality.

This test thoroughly verifies that when a wallet address with an embedded payment ID is used, the coinbase transaction adopts that payment ID instead of the empty one provided as an argument. The test creates an address with custom payment ID user data, then confirms the generated coinbase output contains that same data.

Added coinbase payment_id to thre coinbase from the wallet payment address
if it exists.
@hansieodendaal hansieodendaal force-pushed the ho_coinbase_payment_id branch from d662466 to 8778fee Compare May 8, 2025 15:11
@SWvheerden SWvheerden merged commit 3c6683a into tari-project:development May 9, 2025
12 of 17 checks passed
@hansieodendaal hansieodendaal deleted the ho_coinbase_payment_id branch May 13, 2025 14:54
@coderabbitai coderabbitai bot mentioned this pull request Jul 17, 2025
4 tasks
@coderabbitai coderabbitai bot mentioned this pull request Aug 1, 2025
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants