Skip to content

fix: only revalidated rejected transactions on startup#7209

Merged
SWvheerden merged 1 commit intotari-project:developmentfrom
SWvheerden:sw_fix_revalidation_on_startup
Jun 12, 2025
Merged

fix: only revalidated rejected transactions on startup#7209
SWvheerden merged 1 commit intotari-project:developmentfrom
SWvheerden:sw_fix_revalidation_on_startup

Conversation

@SWvheerden
Copy link
Copy Markdown
Collaborator

@SWvheerden SWvheerden commented Jun 12, 2025

Description

We should only revalidate rejected transactions on startup, and not all transactions

Summary by CodeRabbit

  • New Features
    • Added the ability to revalidate only rejected transactions, rather than all transactions, in the wallet.
  • Bug Fixes
    • Improved handling and status resetting for rejected transactions, ensuring more accurate transaction validation.
  • Chores
    • Updated error messages and streamlined transaction validation steps for better reliability.

@SWvheerden SWvheerden requested a review from a team as a code owner June 12, 2025 12:29
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Jun 12, 2025

Walkthrough

This change introduces a new capability to revalidate only rejected transactions in the wallet's transaction service, rather than all transactions. It adds new API methods, request variants, and database logic to support marking rejected transactions as unvalidated and triggering their revalidation, updating both the service and storage layers accordingly.

Changes

File(s) Change Summary
applications/minotari_console_wallet/src/init/mod.rs Modified wallet startup logic to revalidate only rejected transactions and removed a general validation step.
base_layer/wallet/src/transaction_service/handle.rs Added ReValidateRejectedTransactions request, display variant, and revalidate_rejected_transactions method.
base_layer/wallet/src/transaction_service/service.rs Added logic to handle ReValidateRejectedTransactions and method to start rejected transaction revalidation.
base_layer/wallet/src/transaction_service/storage/database.rs Added trait and struct methods to mark all rejected transactions as unvalidated.
base_layer/wallet/src/transaction_service/storage/sqlite_db.rs Implemented method to update all rejected transactions to unvalidated in the SQLite backend.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ConsoleWallet
    participant TransactionServiceHandle
    participant TransactionService
    participant TransactionDatabase

    User->>ConsoleWallet: Start Wallet
    ConsoleWallet->>TransactionServiceHandle: revalidate_rejected_transactions()
    TransactionServiceHandle->>TransactionService: ReValidateRejectedTransactions request
    TransactionService->>TransactionDatabase: mark_all_rejected_transactions_as_unvalidated()
    TransactionDatabase-->>TransactionService: Result
    TransactionService->>TransactionService: start_transaction_validation_protocol()
    TransactionService-->>TransactionServiceHandle: ValidationStarted
    TransactionServiceHandle-->>ConsoleWallet: Ok / Error
Loading

Suggested reviewers

  • hansieodendaal

Poem

A hop and a skip, a wallet anew,
Only rejected, not all, we now review!
With nimble code and storage keen,
Revalidation’s scope is now more lean.
The burrow is tidy, the carrots aligned—
Transaction errors left behind!
🥕✨

✨ 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 (4)
applications/minotari_console_wallet/src/init/mod.rs (1)

618-620: Update log message to reflect new behaviour

Logging still says "revalidating all transactions", but the code now revalidates only rejected transactions.
Keeping the message in sync avoids misleading operators during troubleshooting.

-        debug!("revalidating all transactions");
+        debug!("revalidating rejected transactions");
base_layer/wallet/src/transaction_service/handle.rs (2)

399-400: Minor: keep Display arms alphabetically grouped

For long match chains the project typically keeps the arms alphabetically (or thematically) grouped.
Consider moving ReValidateRejectedTransactions next to ReValidateTransactions for quicker scanning.


1163-1172: Factor out duplicated validation helper

revalidate_rejected_transactions repeats the same three-line pattern that revalidate_all_transactions already implements.
A tiny helper would avoid the duplication:

+async fn send_validation_request(
+    handle: &mut Self,
+    req: TransactionServiceRequest,
+) -> Result<(), TransactionServiceError> {
+    match handle.handle.call(req).await?? {
+        TransactionServiceResponse::ValidationStarted(_) => Ok(()),
+        _ => Err(TransactionServiceError::UnexpectedApiResponse),
+    }
+}

 pub async fn revalidate_all_transactions(&mut self) -> Result<(), TransactionServiceError> {
-    match self
-        .handle
-        .call(TransactionServiceRequest::ReValidateTransactions)
-        .await??
-    {
-        TransactionServiceResponse::ValidationStarted(_) => Ok(()),
-        _ => Err(TransactionServiceError::UnexpectedApiResponse),
-    }
+    Self::send_validation_request(self, TransactionServiceRequest::ReValidateTransactions).await
 }

 pub async fn revalidate_rejected_transactions(&mut self) -> Result<(), TransactionServiceError> {
-    match self
-        .handle
-        .call(TransactionServiceRequest::ReValidateRejectedTransactions)
-        .await??
-    {
-        TransactionServiceResponse::ValidationStarted(_) => Ok(()),
-        _ => Err(TransactionServiceError::UnexpectedApiResponse),
-    }
+    Self::send_validation_request(self, TransactionServiceRequest::ReValidateRejectedTransactions).await
 }

Not critical, but trims repetition and eases future maintenance.

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

1015-1018: New request variant wired in correctly – minor naming nit

The new ReValidateRejectedTransactions branch cleanly mirrors the existing ReValidateTransactions case and re-uses the same response type, so behaviour looks sound.

Small nit: consider pluralising the helper method (start_rejected_transactions_revalidation) to align with the (plural) enum variant and to match the existing start_transaction_revalidation naming scheme for consistency.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 58c3e41 and 710245a.

📒 Files selected for processing (5)
  • applications/minotari_console_wallet/src/init/mod.rs (1 hunks)
  • base_layer/wallet/src/transaction_service/handle.rs (3 hunks)
  • base_layer/wallet/src/transaction_service/service.rs (2 hunks)
  • base_layer/wallet/src/transaction_service/storage/database.rs (2 hunks)
  • base_layer/wallet/src/transaction_service/storage/sqlite_db.rs (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
base_layer/wallet/src/transaction_service/storage/database.rs (1)
base_layer/wallet/src/transaction_service/storage/sqlite_db.rs (1)
  • mark_all_rejected_transactions_as_unvalidated (976-999)
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: Cucumber tests / FFI
  • GitHub Check: Cucumber tests / Base Layer
  • GitHub Check: test (mainnet, stagenet)
  • GitHub Check: ci
  • GitHub Check: test (testnet, esmeralda)
  • GitHub Check: test (nextnet, nextnet)
  • GitHub Check: cargo check with stable
🔇 Additional comments (4)
base_layer/wallet/src/transaction_service/storage/database.rs (2)

144-145: Trait extension may break other back-ends – verify all implementations

mark_all_rejected_transactions_as_unvalidated was added to TransactionBackend.
Every struct implementing this trait must now implement the new method, otherwise the crate will fail to compile.
sqlite_db.rs was updated, but memory_db.rs / any other back-end were not shown in this diff.

Please confirm all concrete back-ends compile with the new signature or add a default unimplemented!() stub behind a feature-gate.


792-794: Thin wrapper LGTM

The database façade simply delegates to the backend; no additional logic introduced.

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

973-999: Reuse existing helper, fix log label, preserve cancellation reason

The added method works but:

  • Code duplicated from mark_all_non_coinbases_transactions_as_unvalidated. Consider a private helper that takes the status filter as an argument to avoid maintenance drift.
  • Trace label still says set_transactions_to_be_revalidated. This now fires in two places and is misleading.
  • Clearing the cancelled column discards the original rejection reason. If that information is still valuable (e.g. telemetry or manual troubleshooting) keep it and rely solely on the status column for the protocol to decide what to re-validate.

Minimal fix for the confusing log text:

-                target: LOG_TARGET,
-                "sqlite profile - set_transactions_to_be_revalidated: lock {} + db_op {} = {} ms",
+                target: LOG_TARGET,
+                "sqlite profile - revalidate_rejected_tx: lock {} + db_op {} = {} ms",

A small helper would further DRY the two nearly-identical update blocks:

fn mark_transactions_as_unvalidated<F>(
    &self,
    filter: F,
) -> Result<(), TransactionStorageError>
where
    F: FnOnce(completed_transactions::BoxedQuery<'_, _>) 
        -> completed_transactions::BoxedQuery<'_, _>,
{
    // shared body...
}

[ suggest_optional_refactor ]

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

207-208: Validate that every layer recognises the new ReValidateRejectedTransactions request

Adding a new enum variant is straightforward here, but please double-check that:

  1. All switch / match statements in the service layer (service.rs) and storage back-end are updated.
  2. FFI, JSON-RPC, GRPC, or IPC endpoints that serialise TransactionServiceRequest are regenerated if required.

Failing to propagate the variant will surface as a runtime UnexpectedApiResponse or silent no-op.

@github-actions
Copy link
Copy Markdown

Test Results (CI)

    3 files    126 suites   54m 34s ⏱️
1 333 tests 1 332 ✅ 0 💤 1 ❌
3 997 runs  3 994 ✅ 0 💤 3 ❌

For more details on these failures, see this check.

Results for commit 710245a.

@github-actions
Copy link
Copy Markdown

Test Results (Integration tests)

 2 files  1 errors  1 suites   24m 22s ⏱️
 8 tests 7 ✅ 0 💤 1 ❌
10 runs  7 ✅ 0 💤 3 ❌

For more details on these parsing errors and failures, see this check.

Results for commit 710245a.

@SWvheerden SWvheerden merged commit 65af015 into tari-project:development Jun 12, 2025
12 of 17 checks passed
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)
  ...
@SWvheerden SWvheerden deleted the sw_fix_revalidation_on_startup branch June 18, 2025 11:13
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