Skip to content

fix(wallet): use minimum value promise in VN reg output - #7460

Merged
SWvheerden merged 1 commit into
tari-project:developmentfrom
sdbondi:pay-to-self-minimum-value-promise
Sep 1, 2025
Merged

fix(wallet): use minimum value promise in VN reg output#7460
SWvheerden merged 1 commit into
tari-project:developmentfrom
sdbondi:pay-to-self-minimum-value-promise

Conversation

@sdbondi

@sdbondi sdbondi commented Sep 1, 2025

Copy link
Copy Markdown
Member

Description

fix(wallet): use minimum value promise in VN reg output

Motivation and Context

Base node validation for VN reg requires the minimum value promise to be >= deposit amount

Ref tari-project/tari-ootle#1560

How Has This Been Tested?

In PR tari-project/tari-ootle#1560

Summary by CodeRabbit

  • New Features
    • Added an optional "minimum value promise" for pay-to-self transactions and UTXO aggregation.
    • Propagated across wallet transaction flows and advanced transaction options so it's available where outputs are constructed.
    • Defaults to zero when not specified, preserving existing behavior and workflows.

@sdbondi
sdbondi requested a review from a team as a code owner September 1, 2025 10:33
@coderabbitai

coderabbitai Bot commented Sep 1, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

Adds a new minimum_value_promise: MicroMinotari field to pay-to-self and aggregate-UTXO flows; updates request enums, public handle/service method signatures, and propagates the value through service internals and call sites, defaulting to MicroMinotari::zero() where callers do not supply it.

Changes

Cohort / File(s) Summary
OutputManager Handle API
base_layer/wallet/src/output_manager_service/handle.rs
Added minimum_value_promise: MicroMinotari to OutputManagerRequest::EncumberAggregateUtxo and OutputManagerRequest::CreatePayToSelfTransaction. Updated OutputManagerHandle::create_pay_to_self_transaction signature and forwarded the new argument in the request.
OutputManager Service Logic
base_layer/wallet/src/output_manager_service/service.rs
Threaded minimum_value_promise through create_pay_to_self_transaction, encumber_aggregate_utxo, and output_to_self signatures and call sites. Removed local defaulting inside output_to_self; callers now supply the value. Paths that previously did not provide it pass MicroMinotari::zero().
Transaction Service Call Sites
base_layer/wallet/src/transaction_service/service.rs
Updated four call sites to create_pay_to_self_transaction to include the new 8th MicroMinotari argument (one uses amount, three use MicroMinotari::zero()).

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant TS as TransactionService
  participant OMH as OutputManagerHandle
  participant OMS as OutputManagerService
  participant Builder as Output/Tx Builder

  TS->>OMH: create_pay_to_self_transaction(..., payment_id, minimum_value_promise)
  OMH->>OMS: create_pay_to_self_transaction(..., payment_id, minimum_value_promise)
  OMS->>OMS: select inputs / encumber aggregate utxo (passes minimum_value_promise)
  OMS->>Builder: output_to_self(output_features, amount, covenant, payment_id, fee, minimum_value_promise)
  Builder-->>OMS: (DbWalletOutput, KeyId) [metadata includes minimum_value_promise]
  OMS->>OMS: assemble Transaction
  OMS-->>OMH: (fee, Transaction)
  OMH-->>TS: (fee, Transaction)
  note over OMS,Builder: minimum_value_promise is carried into output metadata and construction
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • fix!: payment id #6974 — Modifies the same Output Manager APIs and request variants (similar area of metadata/parameter changes).

Suggested reviewers

  • SWvheerden
  • MCozhusheck

Poem

A carrot of code in my tidy stash,
I hop through params—no need to dash.
A promise of value, snug and bright,
Threaded through burrows, sealed up tight.
With zeroes or sums, we nudge the chain—🥕🐇


📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between f50cd5a and 05a93a4.

📒 Files selected for processing (3)
  • base_layer/wallet/src/output_manager_service/handle.rs (3 hunks)
  • base_layer/wallet/src/output_manager_service/service.rs (8 hunks)
  • base_layer/wallet/src/transaction_service/service.rs (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • base_layer/wallet/src/output_manager_service/handle.rs
  • base_layer/wallet/src/output_manager_service/service.rs
  • base_layer/wallet/src/transaction_service/service.rs
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (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
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit 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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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.

@sdbondi
sdbondi force-pushed the pay-to-self-minimum-value-promise branch from f50cd5a to 05a93a4 Compare September 1, 2025 10:37

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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 (5)
base_layer/wallet/src/output_manager_service/handle.rs (1)

95-104: CreatePayToSelfTransaction now includes minimum_value_promise — good propagation

Field added in the request enum aligns with service changes and PR intent.

You may want to include this value in Display logging for easier traceability.

-            CreatePayToSelfTransaction { .. } => write!(f, "CreatePayToSelfTransaction",),
+            CreatePayToSelfTransaction { .. } => write!(f, "CreatePayToSelfTransaction"),
base_layer/wallet/src/transaction_service/service.rs (1)

2091-2104: VN registration sets minimum_value_promise = amount — matches base node requirement

This should satisfy “promise ≥ deposit” while remaining ≤ actual output amount.

Consider a short comment clarifying why amount is used here.

-            .create_pay_to_self_transaction(
+            .create_pay_to_self_transaction(
                 tx_id,
                 amount,
                 selection_criteria,
                 output_features,
                 fee_per_gram,
                 None,
                 payment_id.clone(),
-                amount,
+                amount, // minimum_value_promise set to deposit amount for BN validation
             )
base_layer/wallet/src/output_manager_service/service.rs (3)

366-387: Request handler threads minimum_value_promise — good

End-to-end propagation is correct.

Add a sanity check before forwarding (log or early error) to catch accidental promise > amount at call-time.


1690-1700: Pay-to-self uses caller-supplied promise — consider guarding invariant

Functional pass-through is correct. A defensive check that promise ≤ amount would prevent malformed outputs.

     pub async fn create_pay_to_self_transaction(
         &mut self,
@@
-        minimum_value_promise: MicroMinotari,
+        minimum_value_promise: MicroMinotari,
     ) -> Result<(MicroMinotari, Transaction), OutputManagerError> {
+        if minimum_value_promise > amount {
+            return Err(OutputManagerError::InvalidArgument(
+                "minimum_value_promise cannot exceed output amount".to_string(),
+            ));
+        }

2401-2410: output_to_self now accepts minimum_value_promise — bind it with a guard

Good inclusion and use in metadata preimage. Add a small invariant check here too since this is the central constructor.

     async fn output_to_self(
@@
-        minimum_value_promise: MicroMinotari,
+        minimum_value_promise: MicroMinotari,
     ) -> Result<(DbWalletOutput, TariKeyId), OutputManagerError> {
+        if minimum_value_promise > amount {
+            return Err(OutputManagerError::InvalidArgument(
+                "minimum_value_promise cannot exceed output amount".to_string(),
+            ));
+        }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 6fb8d66 and f50cd5a.

📒 Files selected for processing (3)
  • base_layer/wallet/src/output_manager_service/handle.rs (3 hunks)
  • base_layer/wallet/src/output_manager_service/service.rs (8 hunks)
  • base_layer/wallet/src/transaction_service/service.rs (4 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
base_layer/wallet/src/output_manager_service/handle.rs (1)
base_layer/transaction_components/src/transaction_components/covenants/fields.rs (1)
  • minimum_value_promise (262-264)
base_layer/wallet/src/output_manager_service/service.rs (1)
base_layer/transaction_components/src/transaction_components/covenants/fields.rs (1)
  • minimum_value_promise (262-264)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (9)
  • GitHub Check: test (testnet, esmeralda)
  • GitHub Check: ledger build tests
  • GitHub Check: test (mainnet, stagenet)
  • GitHub Check: test (nextnet, nextnet)
  • GitHub Check: Cucumber tests / Base Layer
  • GitHub Check: Cucumber tests / FFI
  • GitHub Check: ci
  • GitHub Check: wasm build tests
  • GitHub Check: cargo check with stable
🔇 Additional comments (7)
base_layer/wallet/src/output_manager_service/handle.rs (2)

924-933: Pass-through includes minimum_value_promise — LGTM

Correctly forwards the new parameter to the service.


910-921: All create_pay_to_self_transaction invocations updated Verified that every call site now passes the new eight parameters; no 7-argument calls remain.

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

2176-2189: Validator exit uses zero promise — consistent if no deposit check applies

Looks fine as long as BN doesn’t enforce a minimum for exits.

Please confirm that exit outputs have no minimum-value requirement in consensus.


2251-2264: Eviction proof uses zero promise — consistent with intent

No issues spotted.


2366-2379: Code template registration uses zero promise — appropriate for zero-amount output

This keeps behavior unchanged for template registration.

base_layer/wallet/src/output_manager_service/service.rs (2)

2171-2175: Coin-split-even sets promise to zero — OK

Explicit zero keeps prior semantics.


2332-2336: Coin-split sets promise to zero — OK

Consistent with existing flows.

@hansieodendaal hansieodendaal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

utACK

@SWvheerden
SWvheerden merged commit 213a0c5 into tari-project:development Sep 1, 2025
15 of 16 checks passed
@sdbondi
sdbondi deleted the pay-to-self-minimum-value-promise branch September 1, 2025 13:17
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.

3 participants