Skip to content

feat: add block hash to grpc method#7025

Merged
SWvheerden merged 5 commits intotari-project:developmentfrom
hansieodendaal:ho_competed_transactions_grpc
May 6, 2025
Merged

feat: add block hash to grpc method#7025
SWvheerden merged 5 commits intotari-project:developmentfrom
hansieodendaal:ho_competed_transactions_grpc

Conversation

@hansieodendaal
Copy link
Copy Markdown
Contributor

@hansieodendaal hansieodendaal commented May 5, 2025

Description

Added optional block hash to grpc method GetCompletedTransactionsRequest

Motivation and Context

Some clients maw want to filter completed transactions by block hash.

How Has This Been Tested?

System-level testing running thre grpc call.

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

Code review
System-level testing

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 filtering completed wallet transactions by block hash alongside payment ID.
  • Tests

    • Updated test cases and integration tests to accommodate the new block hash filter parameter when retrieving completed transactions.
  • Chores

    • Enhanced internal request structures, gRPC service, and database queries to support filtering by block hash.

No changes to user interface or existing transaction retrieval behavior unless the new filter is applied.

Added optional block hash to grpc method GetCompletedTransactionsRequest
@hansieodendaal hansieodendaal requested a review from a team as a code owner May 5, 2025 16:19
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented May 5, 2025

Walkthrough

This change extends the wallet's completed transactions query functionality by introducing an optional block hash filter alongside the existing payment ID filter. The gRPC API, backend storage, service layer, and all relevant method signatures are updated to accept and process this new parameter. Supporting logic in the SQLite backend, FFI, UI state, and tests is adjusted to accommodate the additional argument. The gRPC request message and Rust service interfaces now support querying completed transactions filtered by either or both payment ID and block hash.

Changes

File(s) Change Summary
applications/minotari_app_grpc/proto/wallet.proto Added optional block_hash field to GetCompletedTransactionsRequest and defined new BlockHashHex message.
applications/minotari_console_wallet/src/grpc/wallet_grpc_server.rs Updated get_completed_transactions to parse and handle optional block_hash from requests.
applications/minotari_console_wallet/src/ui/state/app_state.rs Updated call to get_completed_transactions to include two arguments (both None in this context).
base_layer/wallet/src/transaction_service/handle.rs Changed GetCompletedTransactions variant to struct with payment_id and block_hash; updated method signatures and calls accordingly.
base_layer/wallet/src/transaction_service/service.rs Modified service request handling to accept and forward optional block_hash to storage.
base_layer/wallet/src/transaction_service/storage/database.rs Extended backend and database methods to support filtering by both payment_id and block_hash.
base_layer/wallet/src/transaction_service/storage/sqlite_db.rs Updated SQL query logic to conditionally filter by payment_id and/or block_hash if provided.
base_layer/wallet/tests/transaction_service_tests/service.rs
base_layer/wallet/tests/transaction_service_tests/storage.rs
base_layer/wallet/tests/transaction_service_tests/transaction_protocols.rs
Updated test calls to get_completed_transactions to include the new optional argument.
base_layer/wallet_ffi/src/lib.rs Updated FFI function calls to get_completed_transactions to include the new parameter.
integration_tests/tests/steps/wallet_steps.rs Updated integration test requests to include block_hash: None in GetCompletedTransactionsRequest.
.license.ignore Added new file path entry to exclude ./base_layer/core/src/blocks/gen_block/Tari.Manifesto from license checks.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant gRPC_Server
    participant WalletService
    participant StorageBackend

    Client->>gRPC_Server: GetCompletedTransactionsRequest(payment_id, block_hash)
    gRPC_Server->>WalletService: get_completed_transactions(payment_id, block_hash)
    WalletService->>StorageBackend: get_completed_transactions(payment_id, block_hash)
    StorageBackend-->>WalletService: [CompletedTransaction...]
    WalletService-->>gRPC_Server: [CompletedTransaction...]
    gRPC_Server-->>Client: [CompletedTransaction...]
Loading

Possibly related PRs

Poem

In the warren of code, a new tunnel’s been made,
Where hashes and payments together cascade.
Now bunnies can search with a block or an ID,
For completed transactions, as quick as can be!
With queries more nimble, our wallets delight—
Hopping through filters, from morning to night.
🐇✨


📜 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 4812466 and 728fbc3.

📒 Files selected for processing (2)
  • .license.ignore (1 hunks)
  • base_layer/wallet/src/transaction_service/storage/sqlite_db.rs (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • .license.ignore
🚧 Files skipped from review as they are similar to previous changes (1)
  • base_layer/wallet/src/transaction_service/storage/sqlite_db.rs
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: test (mainnet, stagenet)
  • GitHub Check: test (testnet, esmeralda)
  • GitHub Check: test (nextnet, nextnet)
  • GitHub Check: cargo check with stable
✨ 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.

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

🧹 Nitpick comments (3)
integration_tests/tests/steps/wallet_steps.rs (1)

551-554: Consistent import usage for request type.
Here you’re using grpc::GetCompletedTransactionsRequest instead of the directly imported GetCompletedTransactionsRequest. Consider unifying to the same imported type across all calls for clarity and consistency.

base_layer/wallet_ffi/src/lib.rs (1)

8596-8601: The call to get_completed_transactions has been properly updated.

This change correctly implements the new method signature. Consider adding a comment to document what the parameters represent for improved readability.

 let completed_transactions = (*wallet).runtime.block_on(
     (*wallet)
         .wallet
         .transaction_service
-        .get_completed_transactions(None, None),
+        .get_completed_transactions(None, None), // (payment_id, block_hash)
 );
applications/minotari_console_wallet/src/grpc/wallet_grpc_server.rs (1)

933-940: Implementation correctly handles optional block hash parameter.

The code properly extracts and parses the optional block hash from the gRPC request, converting it from hex string to a BlockHash type with appropriate error handling.

However, the error message refers to an "Output hash" when it should refer to a "Block hash".

- BlockHash::from_hex(&hash.hash)
-     .map_err(|_| Status::internal("Output hash is malformed".to_string()))?,
+ BlockHash::from_hex(&hash.hash)
+     .map_err(|_| Status::internal("Block hash is malformed".to_string()))?,
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 510f6be and d04d6df.

📒 Files selected for processing (12)
  • applications/minotari_app_grpc/proto/wallet.proto (22 hunks)
  • applications/minotari_console_wallet/src/grpc/wallet_grpc_server.rs (1 hunks)
  • applications/minotari_console_wallet/src/ui/state/app_state.rs (1 hunks)
  • base_layer/wallet/src/transaction_service/handle.rs (3 hunks)
  • base_layer/wallet/src/transaction_service/service.rs (1 hunks)
  • base_layer/wallet/src/transaction_service/storage/database.rs (6 hunks)
  • base_layer/wallet/src/transaction_service/storage/sqlite_db.rs (2 hunks)
  • base_layer/wallet/tests/transaction_service_tests/service.rs (5 hunks)
  • base_layer/wallet/tests/transaction_service_tests/storage.rs (2 hunks)
  • base_layer/wallet/tests/transaction_service_tests/transaction_protocols.rs (8 hunks)
  • base_layer/wallet_ffi/src/lib.rs (6 hunks)
  • integration_tests/tests/steps/wallet_steps.rs (9 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (5)
base_layer/wallet_ffi/src/lib.rs (2)
applications/minotari_console_wallet/src/ui/state/app_state.rs (3)
  • completed_transactions (773-779)
  • wallet (725-731)
  • wallet (734-740)
base_layer/wallet/src/transaction_service/storage/sqlite_db.rs (10)
  • completed_transactions (845-851)
  • completed_transactions (902-910)
  • completed_transactions (941-941)
  • completed_transactions (942-942)
  • completed_transactions (943-943)
  • completed_transactions (1746-1746)
  • completed_transactions (1802-1804)
  • completed_transactions (1851-1854)
  • completed_transactions (1939-1942)
  • completed_transactions (2189-2218)
base_layer/wallet/tests/transaction_service_tests/storage.rs (1)
base_layer/wallet/src/transaction_service/storage/database.rs (2)
  • get_cancelled_completed_transactions (611-613)
  • get_cancelled_completed_transaction (424-429)
base_layer/wallet/src/transaction_service/storage/sqlite_db.rs (3)
base_layer/wallet/src/transaction_service/storage/database.rs (1)
  • find_completed_transactions_filter_payment_id_block_hash (159-163)
base_layer/core/src/transactions/transaction_components/transaction_output.rs (1)
  • hash (207-224)
base_layer/core/src/blocks/block_header.rs (1)
  • hash (148-155)
applications/minotari_console_wallet/src/grpc/wallet_grpc_server.rs (1)
base_layer/core/src/transactions/transaction_components/encrypted_data.rs (1)
  • from_hex (756-759)
base_layer/wallet/src/transaction_service/storage/database.rs (1)
base_layer/wallet/src/transaction_service/storage/sqlite_db.rs (1)
  • find_completed_transactions_filter_payment_id_block_hash (1051-1081)
⏰ 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: ci
  • GitHub Check: cargo check with stable
  • GitHub Check: Cucumber tests / Base Layer
  • GitHub Check: Cucumber tests / FFI
🔇 Additional comments (32)
base_layer/wallet/tests/transaction_service_tests/storage.rs (2)

361-361: Updated method call with new block_hash parameter.

The get_completed_transactions method call has been updated to include a second None parameter for the new optional block hash filter, aligning with the PR's feature to allow filtering completed transactions by block hash.


419-419: Method calls consistently updated with new parameter.

All calls to get_completed_transactions throughout the test file have been properly updated to include the new optional block hash parameter, maintaining consistency with the updated method signature.

Also applies to: 427-427

applications/minotari_console_wallet/src/ui/state/app_state.rs (1)

754-759: Method call updated to support block hash filtering.

The UI state's call to get_completed_transactions has been correctly updated to include the new optional block hash parameter (None). This ensures the application state layer properly integrates with the updated transaction service interface.

base_layer/wallet/tests/transaction_service_tests/transaction_protocols.rs (1)

858-858: Method calls consistently updated with block hash parameter.

All calls to get_completed_transactions throughout the transaction protocols test file have been properly updated to include the new optional block hash parameter. This comprehensive update ensures test compatibility with the modified method signature.

Also applies to: 893-893, 946-946, 1039-1039, 1084-1084, 1105-1105, 1275-1275, 1392-1392

integration_tests/tests/steps/wallet_steps.rs (8)

162-165: Approve default block_hash parameter.
The addition of block_hash: None alongside payment_id: None here correctly preserves existing behavior by not filtering on block hash.


499-502: Approve default block_hash in request builder.
Updating the GetCompletedTransactionsRequest to include block_hash: None is necessary to match the new method signature and keeps the filter inactive by default.


971-974: Approve default block_hash parameter.
This insertion of block_hash: None correctly aligns with the updated method signature and maintains the prior behavior.


1030-1033: Approve default block_hash parameter.
Adding the new block_hash field with None ensures backward compatibility and satisfies the extended API.


1249-1252: Approve default block_hash parameter.
Including block_hash: None here properly updates the call to the new signature without altering existing semantics.


2663-2666: Approve default block_hash parameter.
The request now matches the extended signature by setting block_hash: None, preserving previous behavior.


2817-2820: Approve default block_hash parameter.
This update correctly passes block_hash: None to the new gRPC method, keeping the original filter semantics.


2843-2846: Approve default block_hash parameter.
Adding block_hash: None aligns with the updated signature and ensures no unintended filtering.

base_layer/wallet/tests/transaction_service_tests/service.rs (1)

2307-2307: Updated method calls correctly match new API signature

All calls to get_completed_transactions() have been properly updated to match the new method signature that now requires two optional parameters: payment_id and block_hash. The changes maintain the original behavior by passing None for both parameters, effectively requesting all completed transactions without any filtering.

Also applies to: 2412-2412, 2416-2416, 2421-2421, 5591-5591, 5699-5699, 6335-6335

base_layer/wallet_ffi/src/lib.rs (5)

8296-8301: The call to get_completed_transactions has been properly updated.

The method signature has been correctly updated to include the new optional block_hash parameter, aligning with the PR's goal of allowing filtering by block hash in the transaction service.


8367-8372: The call to get_completed_transactions has been properly updated.

This change correctly implements the second None parameter for the block_hash, consistent with the updated method signature across the codebase.


8439-8444: The call to get_completed_transactions has been properly updated.

The method call has been correctly updated to include the block_hash parameter, maintaining consistency with other similar calls in this file.


8660-8665: The call to get_completed_transactions has been properly updated.

This change correctly adds the second None parameter for the block_hash, maintaining consistency with the updated method signature.


8736-8741: The call to get_completed_transactions has been properly updated.

The method call has been properly updated to align with the new signature that accepts an optional block_hash parameter, consistent with the PR objectives.

applications/minotari_console_wallet/src/grpc/wallet_grpc_server.rs (1)

944-944: Implementation correctly passes the block hash to the service layer.

The updated method call passes both the existing payment_id parameter and the new block_hash parameter to the transaction service, which aligns with the PR objective to enable filtering by block hash.

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

894-898: Implementation correctly adds block hash filtering capability.

The transaction service request handler now properly accepts and forwards the block_hash parameter to the database layer, enabling filtering completed transactions by block hash alongside the existing payment_id filter.

base_layer/wallet/src/transaction_service/handle.rs (3)

82-85: LGTM! Good implementation of the optional block hash filter.

The change from a tuple variant to a struct variant with named fields improves readability and makes it clear what each parameter represents.


214-214: LGTM on the simplified format string.

The display implementation has been properly updated to handle the new struct variant.


969-974: LGTM! Method signature and implementation properly updated.

The method signature now includes the new optional block_hash parameter, and the call to the service correctly passes both parameters in the new struct variant.

base_layer/wallet/src/transaction_service/storage/sqlite_db.rs (3)

43-43: LGTM! Correctly imported FixedHash.

The necessary FixedHash type has been imported to support the new block hash filtering functionality.


1051-1055: LGTM! Method renamed and signature updated appropriately.

The method has been clearly renamed to reflect its new purpose and the signature has been updated to accept the additional block_hash parameter.


1059-1074: LGTM! Well-implemented query building based on provided filters.

The implementation correctly handles all four possible combinations of the optional parameters:

  1. Both payment_id and block_hash provided
  2. Only payment_id provided
  3. Only block_hash provided
  4. Neither provided

The dynamic query building follows good practices and is consistent with the rest of the codebase.

base_layer/wallet/src/transaction_service/storage/database.rs (6)

34-34: Import update for new functionality

The import was correctly updated to include BlockHash and FixedHash types, which are necessary for the new block hash filtering capability.


159-163: Properly renamed and expanded trait method

The trait method has been appropriately renamed from find_completed_transactions_for_payment_id to find_completed_transactions_filter_payment_id_block_hash and now accepts two optional parameters: payment_id and block_hash. This clearly indicates the expanded filtering capability and maintains a consistent API design.


486-494: Updated implementation matches trait method

The implementation method has been updated to match the expanded trait method, correctly passing both optional parameters to the backend method. This ensures proper propagation of the new filtering capability.


603-609: Public method now supports block hash filtering

The public method get_completed_transactions has been properly updated to accept an optional block_hash parameter and passes it to the underlying implementation, which enables clients to filter completed transactions by block hash as specified in the PR objectives.


611-613: Maintained backward compatibility

The get_cancelled_completed_transactions method was updated to explicitly pass None for the new block_hash parameter, preserving its existing behavior while maintaining API consistency with the other changes.


634-663: Correctly implemented filtering logic

The get_completed_transactions_by_cancelled method was properly updated to:

  1. Accept an optional block_hash parameter
  2. Match on both payment_id.is_none() and block_hash.is_none() to determine the appropriate query path
  3. Call the backend method with both filter parameters when either is provided

The implementation correctly handles all combinations of the optional parameters, maintaining existing behavior when no filters are provided and enabling more specific queries when filters are specified.

@github-actions
Copy link
Copy Markdown

github-actions bot commented May 5, 2025

Test Results (CI)

    3 files     90 suites   40m 14s ⏱️
1 096 tests 1 090 ✅ 0 💤  6 ❌
3 242 runs  3 227 ✅ 0 💤 15 ❌

For more details on these failures, see this check.

Results for commit b4688f5.

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Copy Markdown

github-actions bot commented May 5, 2025

Test Results (Integration tests)

 2 files  11 suites   1h 15m 35s ⏱️
36 tests 31 ✅ 0 💤  5 ❌
45 runs  33 ✅ 0 💤 12 ❌

For more details on these failures, see this check.

Results for commit b4688f5.

♻️ This comment has been updated with latest results.

SWvheerden
SWvheerden previously approved these changes May 6, 2025
@SWvheerden SWvheerden merged commit 161bdf7 into tari-project:development May 6, 2025
9 of 12 checks passed
@hansieodendaal hansieodendaal deleted the ho_competed_transactions_grpc branch May 7, 2025 09:05
@coderabbitai coderabbitai bot mentioned this pull request May 7, 2025
4 tasks
@coderabbitai coderabbitai bot mentioned this pull request Jun 4, 2025
4 tasks
@coderabbitai coderabbitai bot mentioned this pull request Jun 20, 2025
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