Skip to content

fix: fix scanner service when connectivity offline#7223

Merged
SWvheerden merged 2 commits intotari-project:developmentfrom
hansieodendaal:ho_fix_unit_test
Jun 17, 2025
Merged

fix: fix scanner service when connectivity offline#7223
SWvheerden merged 2 commits intotari-project:developmentfrom
hansieodendaal:ho_fix_unit_test

Conversation

@hansieodendaal
Copy link
Copy Markdown
Contributor

@hansieodendaal hansieodendaal commented Jun 17, 2025

Description

Fixed the scanner service when connectivity is offline - the connectivity status will now be queried to start scanning, instead of relying on a based node change to initiate the process. The logical error was introduced in a recent PR.

Motivation and Context

Unit test async fn test_utxo_scanner_one_sided_payments() failed due to logic implementation error.

How Has This Been Tested?

Unit test async fn test_utxo_scanner_one_sided_payments() pass.

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

  • Refactor

    • Improved internal logic for connectivity checks and status handling in the UTXO scanning service.
    • Converted certain recovery mode methods from asynchronous to synchronous for more efficient execution.
    • Simplified transaction status filtering logic for better performance.
  • Tests

    • Enhanced test setup and logging for better debugging and reliability.

No changes to user-facing features or functionality.

@hansieodendaal hansieodendaal requested a review from a team as a code owner June 17, 2025 09:25
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Jun 17, 2025

Walkthrough

This update refactors several wallet-related modules. It removes an unnecessary .clone() in a transaction status filter, changes UTXO scanner connectivity checks to use direct status queries, and converts several UTXO scanner task methods from asynchronous to synchronous. Test code is updated for improved logging and correct mock connectivity handling.

Changes

File(s) Change Summary
applications/minotari_console_wallet/src/grpc/wallet_grpc_server.rs Removed redundant .clone() in transaction status filter condition.
base_layer/wallet/src/utxo_scanner_service/service.rs Connectivity check now directly queries status; removed is_base_node_connected() method and related logic.
base_layer/wallet/src/utxo_scanner_service/utxo_scanner_task.rs Converted set_recovery_mode, check_recovery_mode, and clear_recovery_mode from async to sync methods.
base_layer/wallet/tests/utxo_scanner/mod.rs Improved logger setup in tests, explicitly set mock connectivity status, and cloned mock argument for builder function.

Sequence Diagram(s)

sequenceDiagram
    participant UtxoScannerService
    participant CommsConnectivity

    UtxoScannerService->>CommsConnectivity: get_connectivity_status().await
    CommsConnectivity-->>UtxoScannerService: ConnectivityStatus (Online/Offline)
    alt If Offline
        UtxoScannerService->>UtxoScannerService: Log "Waiting for connectivity"
        UtxoScannerService->>UtxoScannerService: Sleep 5 seconds
        UtxoScannerService->>CommsConnectivity: Retry get_connectivity_status().await
    end
Loading

Possibly related PRs

Suggested reviewers

  • SWvheerden

Poem

A bunny hopped through wallet code,
Tidying async where sync bestowed.
No more clones in status land,
Connectivity checked just as planned.
With logs that trace and mocks that shine,
This patch brings code in perfect line!
🐇✨


📜 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 2a5c612 and de7e226.

📒 Files selected for processing (1)
  • base_layer/wallet/src/utxo_scanner_service/service.rs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • base_layer/wallet/src/utxo_scanner_service/service.rs
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: ci
  • 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.
    • 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

🧹 Nitpick comments (6)
base_layer/wallet/src/utxo_scanner_service/service.rs (1)

160-161: Polling-sleep loop could be replaced by connectivity events

A fixed 5 s sleep introduces unnecessary latency once the node comes back online.
Consider subscribing to the connectivity event stream (ConnectivityEvent::ConnectivityStateOnline) and using tokio::select! so the scanner is resumed immediately.

base_layer/wallet/tests/utxo_scanner/mod.rs (2)

142-144: Potentially redundant connectivity status update

add_active_connection(..) already bumps the mock into an online state.
The explicit set_connectivity_status(ConnectivityStatus::Online(1)) immediately after it is usually unnecessary and could diverge from the real implementation if the behaviour of add_active_connection changes.

-    comms_connectivity_mock_state
-        .set_connectivity_status(ConnectivityStatus::Online(1))
-        .await;
+    // Probably not needed – `add_active_connection` sets the state to `Online`.

307-308: Remove commented-out logger initialisation

The commented env_logger lines add noise and are unlikely to be re-enabled once committed.
If verbose logging is occasionally useful, prefer gating it behind an env-flag (e.g. RUST_LOG) rather than leaving commented code around.

Also applies to: 864-865

base_layer/wallet/src/utxo_scanner_service/utxo_scanner_task.rs (3)

92-95: Blocking DB write performed on the async executor

set_recovery_mode() is now synchronous, but it still performs a write against the wallet DB.
Invoking it directly from the async context can block the reactor thread for slow back-ends (e.g. SQLite on a busy FS).

-        if self.mode == UtxoScannerMode::Recovery {
-            self.set_recovery_mode()?;
-        }
+        if self.mode == UtxoScannerMode::Recovery {
+            // Off-load potential blocking I/O
+            tokio::task::spawn_blocking({
+                let this = self.clone();            // or Arc-clone the DB handle
+                move || this.set_recovery_mode()
+            })
+            .await??;
+        }

291-294: Repeated DB look-ups inside tight scanning loop

check_recovery_mode() hits the DB every iteration while scanning blocks.
During large syncs this executes thousands of times per minute and needlessly increases contention.

Cache the result for the current run or throttle the check (e.g. once every N blocks).


703-721: Public interface now synchronous – clarify intent & naming

set_recovery_mode, check_recovery_mode, clear_recovery_mode are now sync, but they still interact with the DB.
Consider:

  1. Renaming check_recovery_modeis_recovery_in_progress to reflect the boolean return.
  2. Documenting that the methods are expected to be cheap / non-blocking, or wrap DB work in spawn_blocking as noted above.

No functional issue, but tightening semantics helps future maintainers.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1148073 and 2a5c612.

📒 Files selected for processing (4)
  • applications/minotari_console_wallet/src/grpc/wallet_grpc_server.rs (1 hunks)
  • base_layer/wallet/src/utxo_scanner_service/service.rs (1 hunks)
  • base_layer/wallet/src/utxo_scanner_service/utxo_scanner_task.rs (4 hunks)
  • base_layer/wallet/tests/utxo_scanner/mod.rs (5 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: test (mainnet, stagenet)
  • GitHub Check: test (nextnet, nextnet)
  • GitHub Check: test (testnet, esmeralda)
  • GitHub Check: file licenses
  • GitHub Check: ci
  • GitHub Check: cargo check with stable
  • GitHub Check: Cucumber tests / Base Layer
  • GitHub Check: Cucumber tests / FFI
🔇 Additional comments (1)
applications/minotari_console_wallet/src/grpc/wallet_grpc_server.rs (1)

1235-1236: Removed .clone() is correct and preferable

TransactionStatus is Copy, so using it directly avoids an unnecessary heap copy and simplifies the expression without altering semantics.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Jun 17, 2025

Test Results (CI)

    3 files    126 suites   39m 44s ⏱️
1 340 tests 1 340 ✅ 0 💤 0 ❌
4 018 runs  4 018 ✅ 0 💤 0 ❌

Results for commit de7e226.

♻️ This comment has been updated with latest results.

SWvheerden
SWvheerden previously approved these changes Jun 17, 2025
@github-actions
Copy link
Copy Markdown

Test Results (Integration tests)

 2 files  10 suites   2h 20m 59s ⏱️
27 tests 20 ✅ 1 💤  6 ❌
39 runs  21 ✅ 1 💤 17 ❌

For more details on these failures, see this check.

Results for commit de7e226.

@SWvheerden SWvheerden merged commit e0ab8d1 into tari-project:development Jun 17, 2025
17 of 18 checks passed
@hansieodendaal hansieodendaal deleted the ho_fix_unit_test branch June 17, 2025 13:01
sdbondi added a commit to sdbondi/tari that referenced this pull request Jun 18, 2025
* development:
  chore: new release v4.5.0-pre.0 (tari-project#7228)
  chore: better logging (tari-project#7226)
  feat!: ensure payref persists during recovery (tari-project#7225)
  chore(ci): split out amd64 and arm64 docker builds into native runners (tari-project#7206)
  fix: fix scanner service when connectivity offline (tari-project#7223)
  feat: add payref to grpc outputs (tari-project#7216)
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