Skip to content

feat: get all completed txs with pagination#7113

Merged
SWvheerden merged 5 commits intotari-project:developmentfrom
mmrrnn:mp_get_all_completed_transactions_with_pagination
May 27, 2025
Merged

feat: get all completed txs with pagination#7113
SWvheerden merged 5 commits intotari-project:developmentfrom
mmrrnn:mp_get_all_completed_transactions_with_pagination

Conversation

@mmrrnn
Copy link
Copy Markdown
Contributor

@mmrrnn mmrrnn commented May 27, 2025

Description

Motivation and Context

We need a non-streamed method that returns non-cancelled and cancelled completed txs, sorted by timestamp(pending txs on top) that handles pagination.

How Has This Been Tested?

Locally, using grpc client(limit 2, offset: 1):

{
  transactions: [
    {
      tx_id: '9349838054423223005',
      source_address: <Buffer 00 01 e4 07 de be 8a 2b 22 25 3b 58 e5 b5 06 61 2c de fa bf 54 1a b2 c9 4a f0 32 f5 81 21 fb 9e 38 03 36 f8 71 b4 cc c3 22 ba 79 7e d0 78 1c ef 03 2e ... 17 more bytes>,
      dest_address: <Buffer 00 01 16 d3 07 be ad 71 e9 47 e1 42 5c a6 f7 86 0f 62 f4 41 6f a6 99 1c e9 06 d5 86 4b 00 83 8a e0 29 12 4e d2 9c 9e 11 91 b5 08 fa 62 ca 0b 5c c9 6d ... 17 more bytes>,
      status: 'TRANSACTION_STATUS_MINED_CONFIRMED',
      direction: 'TRANSACTION_DIRECTION_OUTBOUND',
      amount: '11000',
      fee: '660',
      is_cancelled: false,
      excess_sig: <Buffer ae 4d 1f e8 a1 9d 91 7e bd 4a b9 37 ba 30 79 38 ca c0 d7 34 ba 90 7d d3 ab 8b 5a 6c 4e 5b 89 0d>,
      timestamp: '1748340511',
      raw_payment_id: <Buffer 03 f8 2a 00 00 00 00 00 00 00 00 00 05 80 00 01 e4 07 de be 8a 2b 22 25 3b 58 e5 b5 06 61 2c de fa bf 54 1a b2 c9 4a f0 32 f5 81 21 fb 9e 38 03 36 f8 ... 43 more bytes>,
      mined_in_block_height: '15589',
      user_payment_id: <Buffer 54 6f 20 4d 6f 62 69 6c 65 20 23 31>
    },
    {
      tx_id: '3694656493490439735',
      source_address: <Buffer 00 01 e4 07 de be 8a 2b 22 25 3b 58 e5 b5 06 61 2c de fa bf 54 1a b2 c9 4a f0 32 f5 81 21 fb 9e 38 03 36 f8 71 b4 cc c3 22 ba 79 7e d0 78 1c ef 03 2e ... 17 more bytes>,
      dest_address: <Buffer 00 01 c2 d6 4e 45 6c 1b 85 4e ed be ed 6c 47 b0 da 70 e9 a0 dd f7 7f 5e 42 f9 b4 b4 0d 2c 1d eb cf 33 3a bd b9 35 e5 2d 35 6a 3c 72 01 64 c6 b6 40 af ... 17 more bytes>,
      status: 'TRANSACTION_STATUS_MINED_CONFIRMED',
      direction: 'TRANSACTION_DIRECTION_OUTBOUND',
      amount: '10000',
      fee: '700',
      is_cancelled: false,
      excess_sig: <Buffer 5a 8e c8 1e 44 b9 61 de 5f 25 6e e4 99 9e e4 07 f4 b7 d3 72 d4 31 f9 5c 94 67 32 08 ae 28 ac 02>,
      timestamp: '1748335375',
      raw_payment_id: <Buffer 03 10 27 00 00 00 00 00 00 00 00 00 05 80 00 01 e4 07 de be 8a 2b 22 25 3b 58 e5 b5 06 61 2c de fa bf 54 1a b2 c9 4a f0 32 f5 81 21 fb 9e 38 03 36 f8 ... 45 more bytes>,
      mined_in_block_height: '15548',
      user_payment_id: <Buffer 53 65 6e 64 20 74 6f 20 6d 61 63 20 23 31>
    }
  ]
}

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

Breaking Changes

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

Summary by CodeRabbit

  • New Features
    • Added the ability to retrieve all completed transactions, including cancelled ones, through a new gRPC endpoint. This feature supports pagination and returns transactions sorted by timestamp.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented May 27, 2025

"""

Walkthrough

A new gRPC method, GetAllCompletedTransactions, was introduced to the wallet service. This method enables clients to retrieve all completed and cancelled transactions with support for pagination. The server implementation collects, sorts, and paginates the transactions before returning them in the response.

Changes

File(s) Change Summary
applications/minotari_app_grpc/proto/wallet.proto Added GetAllCompletedTransactions RPC, request/response messages for paginated retrieval of transactions.
applications/minotari_console_wallet/src/grpc/wallet_grpc_server.rs Implemented get_all_completed_transactions method to fetch, combine, sort, and paginate transactions.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant WalletGrpcServer
    participant WalletDB

    Client->>WalletGrpcServer: GetAllCompletedTransactionsRequest(offset, limit)
    WalletGrpcServer->>WalletDB: get_completed_transactions(None, None, None)
    WalletDB-->>WalletGrpcServer: completed_transactions
    WalletGrpcServer->>WalletDB: get_cancelled_completed_transactions()
    WalletDB-->>WalletGrpcServer: cancelled_transactions
    WalletGrpcServer->>WalletGrpcServer: Combine, sort, paginate transactions
    WalletGrpcServer-->>Client: GetAllCompletedTransactionsResponse(transactions)
Loading

Suggested reviewers

  • SWvheerden

Poem

In the warren of code, a new path appears,
Fetching completed trades from over the years.
With cancelled and finished, all neatly combined,
Paginated and sorted, for users to find.
A hop and a skip, the server replies—
All your transactions, right before your eyes! 🐇
"""


📜 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 192061e and 7d85d29.

📒 Files selected for processing (1)
  • applications/minotari_console_wallet/src/grpc/wallet_grpc_server.rs (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • applications/minotari_console_wallet/src/grpc/wallet_grpc_server.rs
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: test (mainnet, stagenet)
  • GitHub Check: test (testnet, esmeralda)
  • GitHub Check: test (nextnet, nextnet)
  • GitHub Check: cargo check with stable
  • GitHub Check: ci
✨ 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: 0

🧹 Nitpick comments (2)
applications/minotari_console_wallet/src/grpc/wallet_grpc_server.rs (2)

1061-1130: Implementation is correct but consider performance optimizations for large datasets.

The method implementation follows established patterns and correctly:

  • Fetches both completed and cancelled transactions
  • Sorts by timestamp in descending order
  • Applies pagination with offset/limit
  • Maps to TransactionInfo consistently

However, consider these improvements:

Performance consideration: The current approach loads all transactions into memory before applying pagination, which could be memory-intensive for wallets with large transaction histories. For production systems with thousands of transactions, consider implementing database-level pagination.

Minor improvements:

- completed_transactions.sort_by(|a, b| {
-     b.timestamp
-         .partial_cmp(&a.timestamp)
-         .expect("Should be able to compare timestamps")
- });
+ completed_transactions.sort_by(|a, b| {
+     b.timestamp.cmp(&a.timestamp)
+ });

This change uses cmp instead of partial_cmp with expect, which is more appropriate for timestamps and avoids potential panics.


1099-1105: Pagination logic is correct and safe.

The implementation properly handles pagination with reasonable defaults:

  • offset defaults to 0
  • limit defaults to usize::MAX (effectively unlimited)
  • Safe usage of skip() and take()

Optional enhancement: Consider adding validation for pagination parameters to provide better error messages for unreasonable values:

+ let offset = req.offset.unwrap_or(0) as usize;
+ let limit = req.limit.map(|l| l as usize);
+ 
+ // Optional: Add validation
+ if offset > completed_transactions.len() {
+     return Err(Status::invalid_argument("Offset exceeds total number of transactions"));
+ }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2a6fa94 and 1d696ab.

📒 Files selected for processing (2)
  • applications/minotari_app_grpc/proto/wallet.proto (2 hunks)
  • applications/minotari_console_wallet/src/grpc/wallet_grpc_server.rs (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: Cucumber tests / FFI
  • GitHub Check: Cucumber tests / Base Layer
  • GitHub Check: test (testnet, esmeralda)
  • GitHub Check: test (nextnet, nextnet)
  • GitHub Check: ci
🔇 Additional comments (3)
applications/minotari_app_grpc/proto/wallet.proto (2)

1051-1052: LGTM! Well-designed RPC method for paginated transaction retrieval.

The new RPC method follows established patterns and includes proper pagination support through optional offset and limit parameters.


1423-1430: LGTM! Clean message definitions with proper pagination support.

The request and response messages are well-designed:

  • Optional pagination fields provide flexibility
  • Reuses existing TransactionInfo type for consistency
  • Follows protobuf naming conventions
applications/minotari_console_wallet/src/grpc/wallet_grpc_server.rs (1)

52-53: LGTM! Properly imported required protobuf types.

The new imports are correctly added and follow the existing import patterns in the file.

@github-actions
Copy link
Copy Markdown

github-actions bot commented May 27, 2025

Test Results (Integration tests)

0 tests   0 ✅  0s ⏱️
0 suites  0 💤
0 files    0 ❌

Results for commit 25f7e4f.

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Copy Markdown

github-actions bot commented May 27, 2025

Test Results (CI)

1 331 tests   1 328 ✅  19m 15s ⏱️
   42 suites      0 💤
    1 files        3 ❌

For more details on these failures, see this check.

Results for commit 7d85d29.

♻️ This comment has been updated with latest results.

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