Skip to content

fix: remove long timeout in interactive_tx till tx is persisted into db#7252

Merged
SWvheerden merged 4 commits intotari-project:developmentfrom
SWvheerden:sw_remove_time_out
Jun 24, 2025
Merged

fix: remove long timeout in interactive_tx till tx is persisted into db#7252
SWvheerden merged 4 commits intotari-project:developmentfrom
SWvheerden:sw_remove_time_out

Conversation

@SWvheerden
Copy link
Copy Markdown
Collaborator

@SWvheerden SWvheerden commented Jun 23, 2025

Description

fixes: #7251

Summary by CodeRabbit

  • Bug Fixes
    • Improved transaction handling to ensure pending outbound transactions are added at the correct stage and with accurate status and fee information.
    • Adjusted transaction size checks to cancel oversized transactions earlier in the process.
    • Reduced the timeout when waiting for transaction persistence, resulting in faster feedback during transfers.
  • Tests
    • Added a new test scenario to validate handling of multiple consecutive interactive transactions between wallets.
    • Introduced a test step to support sending multiple interactive transactions with specified fees in sequence.

@SWvheerden SWvheerden requested a review from a team as a code owner June 23, 2025 17:35
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Jun 23, 2025

"""

Walkthrough

The changes update transaction persistence timing and timeout handling in the wallet. Transactions are now stored immediately upon initiation rather than after a broadcast attempt. The timeout for waiting on transaction persistence in the gRPC server is reduced from 30 seconds to 100 milliseconds, and related logic is refactored accordingly.

Changes

File(s) Change Summary
applications/minotari_console_wallet/src/grpc/wallet_grpc_server.rs Reduced transaction persistence wait timeout from 30 seconds to 100 milliseconds; updated Duration import.
base_layer/wallet/src/transaction_service/protocols/transaction_send_protocol.rs Moved and consolidated logic to store pending outbound transactions immediately, before broadcast attempts.
integration_tests/tests/features/WalletTransactions.feature Added a new test scenario sending multiple interactive transactions and verifying block heights.
integration_tests/tests/steps/wallet_steps.rs Added async step to send multiple interactive transactions consecutively with fee, including status polling.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant WalletGrpcServer
    participant TransactionService

    User->>WalletGrpcServer: Initiate transfer
    WalletGrpcServer->>TransactionService: Add pending outbound transaction
    WalletGrpcServer->>TransactionService: Check transaction size
    alt Oversized
        TransactionService-->>WalletGrpcServer: Cancel transaction
        WalletGrpcServer-->>User: Return error
    else Valid size
        WalletGrpcServer->>TransactionService: Attempt broadcast
        WalletGrpcServer->>TransactionService: Query transaction by ID (loop, up to 100ms)
        alt Transaction found
            WalletGrpcServer-->>User: Confirm transfer
        else Timeout
            WalletGrpcServer-->>User: Return timeout error
        end
    end
Loading

Assessment against linked issues

Objective Addressed Explanation
Store transactions immediately, not after broadcast (#7251)
Remove requirement for long timeout on transaction persistence (#7251)

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes found.

Possibly related PRs

Suggested reviewers

  • SWvheerden

Poem

A whisk of code, a hop of cheer,
Transactions saved as soon as they're here!
No more waiting—just a blink,
Stored right away, faster than you think.
🐇✨
Hop, hop, hooray—
The wallet’s quicker every day!
"""

✨ 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 (1)
base_layer/wallet/src/transaction_service/protocols/transaction_send_protocol.rs (1)

341-356: Remove redundant transaction size check

This size check is unreachable because the transaction size is already validated at lines 335-338. If the transaction is oversized, cancel_oversized_transaction() is called which returns early.

Apply this diff to remove the dead code:

-        if let Err(e) = check_transaction_size(&outbound_tx, self.id) {
-            info!(
-                target: LOG_TARGET,
-                "Initial Transaction TxId: {:?} will not be sent due to it being oversize ({:?})", self.id, e
-            );
-        } else {
-            match self.send_transaction(msg).await {
-                Ok(val) => initial_send = val,
-                Err(e) => {
-                    warn!(
-                        target: LOG_TARGET,
-                        "Problem sending Outbound Transaction TxId: {:?}: {:?}", self.id, e
-                    );
-                },
-            }
-        };
+        match self.send_transaction(msg).await {
+            Ok(val) => initial_send = val,
+            Err(e) => {
+                warn!(
+                    target: LOG_TARGET,
+                    "Problem sending Outbound Transaction TxId: {:?}: {:?}", self.id, e
+                );
+            },
+        }
🧹 Nitpick comments (1)
applications/minotari_console_wallet/src/grpc/wallet_grpc_server.rs (1)

27-27: Unnecessary import change

The change from tokio::time::Duration to std::time::Duration is not required for this fix. The tokio::time::Duration re-exports std::time::Duration, so they are functionally equivalent in this context.

Consider reverting this import change to minimize the diff:

-    time::Duration,
+    time::Duration,

Or keep using tokio's Duration:

-use std::{
+use tokio::time::Duration;
+use std::{
     convert::{TryFrom, TryInto},
     str::FromStr,
     sync::Arc,
-    time::Duration,
 };
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e95e181 and d0215c4.

📒 Files selected for processing (2)
  • applications/minotari_console_wallet/src/grpc/wallet_grpc_server.rs (3 hunks)
  • base_layer/wallet/src/transaction_service/protocols/transaction_send_protocol.rs (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: test (nextnet, nextnet)
  • GitHub Check: test (testnet, esmeralda)
  • GitHub Check: ci
  • GitHub Check: cargo check with stable
  • GitHub Check: test (mainnet, stagenet)
  • GitHub Check: Cucumber tests / Base Layer
  • GitHub Check: Cucumber tests / FFI
🔇 Additional comments (1)
base_layer/wallet/src/transaction_service/protocols/transaction_send_protocol.rs (1)

319-339: Good improvement to transaction persistence timing!

Moving the transaction persistence earlier in the flow ensures that transactions are saved even if subsequent send operations fail. This addresses the issue where transactions could be lost if the process was interrupted after preparation but before persistence.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Jun 23, 2025

Test Results (CI)

    3 files    126 suites   42m 48s ⏱️
1 351 tests 1 351 ✅ 0 💤 0 ❌
4 051 runs  4 051 ✅ 0 💤 0 ❌

Results for commit fdf1a21.

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Copy Markdown

Test Results (Integration tests)

 2 files  10 suites   1h 2m 44s ⏱️
30 tests 25 ✅ 1 💤  4 ❌
37 runs  26 ✅ 1 💤 10 ❌

For more details on these failures, see this check.

Results for commit 7a59048.

hansieodendaal
hansieodendaal previously approved these changes Jun 24, 2025
Copy link
Copy Markdown
Contributor

@hansieodendaal hansieodendaal left a comment

Choose a reason for hiding this comment

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

ACK

This provides a better transaction flow.

I also tested this by removing the wait loop in the grpc server method altogether, like it was before the original PR #7234 changed it, but then it still breaks in cucumber test Scenario: Wallet imports pre_mine UTXO although not on the first but at the 2nd interactive transaction not persisted, which means the changed transaction flow improves matters a bit but does not fix it. We still need the wait loop to ensure the transaction is persisted.

Copy link
Copy Markdown
Contributor

@hansieodendaal hansieodendaal left a comment

Choose a reason for hiding this comment

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

ACK

The additional cucumber test Scenario: Wallet sends many interactive transactions to another wallet proves that the grpc timeout is adequate for the wallet to handle many interactive transactions.

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 (1)
integration_tests/tests/steps/wallet_steps.rs (1)

1086-1216: Consider refactoring to reduce code duplication.

This function shares significant logic with send_interactive_amount_from_wallet_to_wallet_at_fee. Consider extracting common functionality into helper functions to improve maintainability.

Potential refactoring approach:

  1. Extract transaction creation logic into a helper function
  2. Extract broadcast waiting logic into a reusable function
  3. Create a unified function that handles both single and multiple transaction scenarios

This would reduce the current ~130 lines of duplicated code and make the codebase more maintainable.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7a59048 and fdf1a21.

📒 Files selected for processing (2)
  • integration_tests/tests/features/WalletTransactions.feature (1 hunks)
  • integration_tests/tests/steps/wallet_steps.rs (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: test (nextnet, nextnet)
  • GitHub Check: test (mainnet, stagenet)
  • GitHub Check: test (testnet, esmeralda)
  • GitHub Check: ci
  • GitHub Check: cargo check with stable
  • GitHub Check: Cucumber tests / Base Layer
  • GitHub Check: Cucumber tests / FFI
🔇 Additional comments (2)
integration_tests/tests/features/WalletTransactions.feature (1)

183-195: Well-structured test scenario for validating interactive transaction performance improvements.

This new test scenario effectively validates the PR's objective of fixing timeout issues in interactive transactions by testing 40 sequential transactions. The scenario structure follows established patterns, and the balance calculations are appropriate (40M uT + fees vs 10B uT available balance).

Please verify that the new test step send 40 interactive transactions of 1000000 uT from wallet WALLET_A to wallet WALLET_B at fee 100 has been properly implemented in the corresponding step definitions.

#!/bin/bash
# Description: Verify the implementation of the new test step for sending multiple interactive transactions

# Search for the step definition implementation
rg -A 10 "send.*interactive transactions.*from wallet.*to wallet.*at fee" --type rust
integration_tests/tests/steps/wallet_steps.rs (1)

1161-1162: Timeout configuration aligns with PR objectives.

The reduced polling interval (100ms) and total timeout (30 seconds with 300 retries) effectively addresses the PR objective of removing long timeouts in interactive transactions until they're persisted.

@SWvheerden SWvheerden merged commit 3a78aba into tari-project:development Jun 24, 2025
16 checks passed
@SWvheerden SWvheerden deleted the sw_remove_time_out branch June 24, 2025 06:33
sdbondi added a commit to sdbondi/tari that referenced this pull request Jun 24, 2025
* development:
  fix: remove long timeout in interactive_tx till tx is persisted into db (tari-project#7252)
  chore: new release v4.6.1-pre.0 (tari-project#7248)
  fix: minotari_merge_mining_proxy returns Tari block hash even if submit_to_origin is disabled (tari-project#7242)
  chore(ci): windows binary audit fix and more code-signing verification (tari-project#7245)
  fix: database cannot resize on jmt write (tari-project#7244)
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.

Tx should be stored imeaditly, not after broadcast

2 participants