Skip to content

feat: update base node proto to search bytes#7201

Merged
SWvheerden merged 1 commit intotari-project:developmentfrom
SWvheerden:sw_update_bn_grpc
Jun 11, 2025
Merged

feat: update base node proto to search bytes#7201
SWvheerden merged 1 commit intotari-project:developmentfrom
SWvheerden:sw_update_bn_grpc

Conversation

@SWvheerden
Copy link
Copy Markdown
Collaborator

@SWvheerden SWvheerden commented Jun 11, 2025

Description

updates base node proto to allow search via bytes and hex

update config settings to allow search method

Summary by CodeRabbit

  • New Features
    • Enhanced search functionality to support payment references in both hex string and raw byte formats.
  • Chores
    • Updated configuration to allow the use of the enhanced payment reference search method.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Jun 11, 2025

Walkthrough

A new repeated bytes field was added to the SearchPaymentReferencesRequest message in the gRPC protocol, allowing payment references to be supplied in raw byte format. The server logic was updated to handle both hex and byte formats uniformly. Configuration files were updated to reflect the new or allowed method.

Changes

File(s) Change Summary
applications/minotari_app_grpc/proto/base_node.proto Added repeated bytes payment_reference_bytes to SearchPaymentReferencesRequest; shifted field numbers.
applications/minotari_node/src/grpc/base_node_grpc_server.rs Refactored search_payment_references to process both hex and byte payment references uniformly.
common/config/presets/c_base_node_b_mining_allow_methods.toml Added "search_payment_references" to the allowed gRPC methods list.
common/config/presets/c_base_node_b_non_mining_allow_methods.toml Added commented-out entry for "search_payment_references" in allowed gRPC methods.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant gRPC_Server
    participant NodeService

    Client->>gRPC_Server: SearchPaymentReferencesRequest (hex and/or bytes)
    gRPC_Server->>gRPC_Server: Validate and convert all payment references
    loop For each valid payment reference
        gRPC_Server->>NodeService: get_output_for_payment_reference(payref)
        NodeService-->>gRPC_Server: Output info or error
        gRPC_Server->>gRPC_Server: Build response with payref as hex
    end
    gRPC_Server-->>Client: Stream responses for each found output
Loading

Poem

In the warren of code, a new path appears,
Bytes and hex together, hopping past old frontiers.
Now payment refs in any form may hop,
Through configs and servers, they never will stop.
With every request, a carrot byte shines bright—
Rabbits rejoice in this byteful delight! 🥕

✨ 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.

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: 1

🔭 Outside diff range comments (2)
applications/minotari_node/src/grpc/base_node_grpc_server.rs (2)

2965-2994: 🛠️ Refactor suggestion

Use HashSet<FixedHash> to pre-deduplicate payment references

payrefs is built as a Vec by first walking payment_reference_hex and then payment_reference_bytes.
If a caller supplies the same pay-ref in both formats (or duplicates inside one format) the node will:

  1. Waste time looking the same output up multiple times.
  2. Emit duplicate PaymentReferenceResponses.

A HashSet removes both issues with negligible cost and conveys intent.

-use std::collections::HashSet;      // add at top of file
-
-let mut payrefs = Vec::new();
+use std::collections::HashSet;
+
+let mut payrefs: HashSet<FixedHash> = HashSet::new();
 ...
-    payrefs.push(payref_bytes);
+    payrefs.insert(payref_bytes);
 ...
-    payrefs.push(payref_fixed_hash);
+    payrefs.insert(payref_fixed_hash);
 ...
-for payref in payrefs {
+for payref in payrefs.into_iter() {

This keeps the public API unchanged, eliminates duplicates, and slightly improves throughput.


3025-3034: 💡 Verification agent

🧩 Analysis chain

include_spent flag in proto is ignored

SearchPaymentReferencesRequest exposes an include_spent boolean, yet the server always performs a spent-status check and returns it.
Respecting the flag can avoid an expensive DB lookup when the client does not care.

if request.include_spent {
    // existing spent check
} else {
    is_spent = false;
    spent_height = 0;
    spent_block_hash = vec![];
}

Please verify the intended semantics; ignoring the field now risks confusing API consumers.


🏁 Script executed:

#!/bin/bash
# Show the handler signature and its surrounding context
rg -n "SearchPaymentReferencesRequest" -C5 applications/minotari_node/src/grpc/base_node_grpc_server.rs

# Check for any use of the include_spent flag
rg -n "include_spent" -C5 applications/minotari_node/src/grpc/base_node_grpc_server.rs

# Inspect how is_spent, spent_height, and spent_block_hash are set
rg -n "is_spent" -C5 applications/minotari_node/src/grpc/base_node_grpc_server.rs
rg -n "spent_height" -C5 applications/minotari_node/src/grpc/base_node_grpc_server.rs

Length of output: 3849


Respect include_spent flag to avoid unnecessary spent‐status lookups

The handler for SearchPaymentReferencesRequest always calls

node_service.check_output_spent_status(output_hash).await

regardless of request.include_spent, which defeats the purpose of the flag and adds an expensive database query when the client doesn’t need spent status.

Suggested change in applications/minotari_node/src/grpc/base_node_grpc_server.rs (around lines 3016–3023):

- let (is_spent, spent_height, spent_block_hash) = match node_service
-     .check_output_spent_status(output_hash)
-     .await
- {
-     Ok(Some(input_info)) => (true, input_info.spent_height, input_info.header_hash.to_vec()),
-     Ok(None) | Err(_)      => (false, 0, vec![]),
- };
+ let (is_spent, spent_height, spent_block_hash) = if request.include_spent {
+     match node_service.check_output_spent_status(output_hash).await {
+         Ok(Some(input_info)) => (true, input_info.spent_height, input_info.header_hash.to_vec()),
+         Ok(None) | Err(_)    => (false, 0, vec![]),
+     }
+ } else {
+     // Skip spent lookup when client does not request it
+     (false, 0, vec![])
+ };

Please confirm that this aligns with the intended API semantics.

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

2995-3010: Avoid cloning large byte vectors unnecessarily

FixedHash::try_from(payref_bytes.clone()) incurs an extra allocation for each element.
try_from(&payref_bytes[..]) (or iterating by value and calling into()) achieves the same goal without the clone.

-let payref_fixed_hash = match FixedHash::try_from(payref_bytes.clone()) {
+let payref_fixed_hash = match FixedHash::try_from(&payref_bytes[..]) {

Minor, but worth it if thousands of references are streamed.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ea038a4 and 298f59f.

📒 Files selected for processing (4)
  • applications/minotari_app_grpc/proto/base_node.proto (1 hunks)
  • applications/minotari_node/src/grpc/base_node_grpc_server.rs (4 hunks)
  • common/config/presets/c_base_node_b_mining_allow_methods.toml (1 hunks)
  • common/config/presets/c_base_node_b_non_mining_allow_methods.toml (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: test (testnet, esmeralda)
  • GitHub Check: test (nextnet, nextnet)
  • GitHub Check: test (mainnet, stagenet)
  • GitHub Check: cargo check with stable
  • GitHub Check: ci
  • GitHub Check: Cucumber tests / FFI
  • GitHub Check: Cucumber tests / Base Layer
🔇 Additional comments (2)
common/config/presets/c_base_node_b_non_mining_allow_methods.toml (1)

54-54: New gRPC method entry added (commented).

Consistent with other commented methods in the non-mining preset. Ensure to document this new option in the configuration guide if non-mining nodes plan to enable it in the future.

common/config/presets/c_base_node_b_mining_allow_methods.toml (1)

54-54: Enabled new gRPC method search_payment_references.

This addition aligns with the updated server implementation and mining preset usage.

@SWvheerden SWvheerden merged commit af1203a into tari-project:development Jun 11, 2025
15 checks passed
@SWvheerden SWvheerden deleted the sw_update_bn_grpc branch June 11, 2025 10:11
sdbondi added a commit to sdbondi/tari that referenced this pull request Jun 18, 2025
* development: (607 commits)
  Wallet GRPC port comment fix from 18142 to 18143 (tari-project#7221)
  feat: integrated address support for Ledger (tari-project#7198)
  chore: new release v4.1.1-pre.0 (tari-project#7211)
  fix: migration can now correctly resume after stopping (tari-project#7210)
  fix: only revalidated rejected transactions on startup (tari-project#7209)
  fix: add filtering flag back (tari-project#7208)
  feat: improve wallet balance checks from external clients (tari-project#7207)
  feat!: update grpc supply query (tari-project#7137)
  docs: Updated API GRPC and Exchange Guide (tari-project#7205)
  chore: new release v4.4.0-pre.0 (tari-project#7202)
  feat: update base node proto to search bytes (tari-project#7201)
  feat: full PayRef implementation (tari-project#7154)
  test: add ffi cucumber wallet balance test (tari-project#7189)
  chore: fix tests (tari-project#7196)
  fix(network-discovery): add back idle event handling (tari-project#7194)
  Update SECURITY.md (tari-project#7193)
  fix: transaction manager service unmined lookup (tari-project#7192)
  fix: wallet ffi database name mismatch for mobile wallet (tari-project#7191)
  fix: payment_id deserialize (tari-project#7187)
  fix: remove code for deleting stale peers (tari-project#7184)
  ...
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.

1 participant