Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mint refactor #1515

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Mint refactor #1515

wants to merge 3 commits into from

Conversation

levonpetrosyan93
Copy link
Contributor

Copy link

coderabbitai bot commented Dec 26, 2024

Walkthrough

The pull request introduces a new configuration option for splitting coins during the minting process in the Bitcoin wallet. This feature is implemented across multiple files in the Qt interface, options model, wallet model, and core wallet functionality. The changes add a new checkbox in the options dialog, update the options model to persist the setting, and modify various wallet methods to support the new fSplit parameter when creating Spark mint transactions.

Changes

File Change Summary
src/qt/forms/optionsdialog.ui Added new fSplit checkbox in wallet options
src/qt/optionsdialog.cpp Added mapping for fSplit UI element to options model
src/qt/optionsmodel.h Added Split enum, getter method, and private member variable
src/qt/optionsmodel.cpp Implemented fSplit setting with default value and persistence
src/qt/walletmodel.cpp Updated prepareMintSparkTransaction to use fSplit option
src/spark/sparkwallet.h/cpp Modified CreateSparkMintTransactions to accept fSplit parameter
src/wallet/wallet.h/cpp Updated wallet methods to support fSplit parameter
src/rpc/client.cpp Added RPC parameter conversion for "mintspark" method
Test files Updated test cases to accommodate new fSplit parameter

Sequence Diagram

sequenceDiagram
    participant User
    participant OptionsDialog
    participant OptionsModel
    participant WalletModel
    participant SparkWallet

    User->>OptionsDialog: Toggle fSplit checkbox
    OptionsDialog->>OptionsModel: Save fSplit setting
    OptionsModel-->>User: Persist setting
    
    User->>WalletModel: Initiate Spark Mint
    WalletModel->>SparkWallet: CreateSparkMintTransactions(fSplit)
    SparkWallet-->>WalletModel: Process transactions
    WalletModel-->>User: Complete minting
Loading

Poem

🐰 A Rabbit's Ode to Coin Splitting

With a hop and a click, a new option appears,
Splitting coins with precision, calming minting fears.
A checkbox so tiny, yet powerful indeed,
Spark transactions now dance with algorithmic creed!
🍃 Hop-tastic control, just a toggle away! 🔧

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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. (Beta)
  • @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

@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 (12)
src/wallet/rpcwallet.cpp (2)

Line range hint 3673-3681: Handle 'from' addresses carefully.

This new block selectively reads the third parameter (request.params[2]) for specifying the coin control addresses in mintspark. Consider adding explicit error checks or fallback for cases of malformed or empty arrays, preventing silent failures if the user inputs invalid addresses.


3755-3755: Check for error propagation.

The returned strError should be logged or thrown to ensure that silent failures don't occur. If it’s critical for the user to know, consider a JSONRPCError for more direct feedback.

src/qt/optionsmodel.h (1)

77-77: Getter method for fSplit.

Exposing getfSplit() is consistent with other getters. Consider adding a short comment explaining what 'splitting' does in the minting context.

src/wallet/test/spark_tests.cpp (3)

210-210: Reusable pattern for minted coins.

The second mint reuses the same mintedCoins vector. Confirm that resetting or re-initializing mintedCoins between tests is consistent, preventing hidden state issues.


213-213: Multiple mints in quick succession.

Calling MintAndStoreSpark twice checks multiple transaction creation. Ensure test also inspects final wallet balance or mint states to catch concurrency or stateful race conditions.


322-322: Large-value mint coverage.

600 FIRO is a bigger test. It's good for boundary checks (e.g., large transactions). Ensure all minted outputs are recognized, and the test checks for memory usage or splitting across multiple transactions.

src/qt/forms/optionsdialog.ui (1)

192-197: UI addition for enabling splitting
The new checkbox and label for splitting enhances user functionality. Ensure that help text, accessibility labels, and translations are properly updated so users understand the purpose of enabling splitting when minting.

src/wallet/wallet.h (1)

Line range hint 1050-1097: Add documentation for the new fSplit parameter.
It's recommended to include a brief explanation in the function comments (e.g., doxygen) describing how the fSplit parameter affects Spark mint transactions. This will help future maintainers and developers understand the purpose of the parameter and any implications for callers.

src/qt/optionsmodel.cpp (2)

286-287: Expose and test the new Split case.
Returning fSplit provides the correct integration for the UI. Make sure there is enough test coverage to confirm that the UI properly reads and applies this setting in all relevant flows.


438-441: Emit signals or notify changes when fSplit is updated.
Currently, there is no separate signal emission for the fSplit state change. If the code needs real-time updates in other components, consider adding a custom signal (e.g., fSplitChanged) to notify interested parts of the UI.

src/spark/sparkwallet.cpp (2)

765-765: Provide a high-level comment for CreateSparkMintTransactions usage.
Since this function grew to incorporate the fSplit logic, it would be helpful to add a short comment describing what “split” does at a functional level, especially given how the function’s branching logic changes the UTXO selection strategy.


794-804: Extract or refactor to improve maintainability.
The if-else branching for fSplit vs. non-split paths is readable but fairly large. Consider splitting each approach into its own helper method or reorganizing for clarity, especially if more conditions accumulate in the future.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 6da96d8 and d911072.

📒 Files selected for processing (14)
  • src/qt/forms/optionsdialog.ui (1 hunks)
  • src/qt/optionsdialog.cpp (1 hunks)
  • src/qt/optionsmodel.cpp (3 hunks)
  • src/qt/optionsmodel.h (3 hunks)
  • src/qt/walletmodel.cpp (1 hunks)
  • src/rpc/client.cpp (1 hunks)
  • src/spark/sparkwallet.cpp (2 hunks)
  • src/spark/sparkwallet.h (1 hunks)
  • src/test/evospork_tests.cpp (1 hunks)
  • src/test/fixtures.cpp (1 hunks)
  • src/wallet/rpcwallet.cpp (6 hunks)
  • src/wallet/test/spark_tests.cpp (7 hunks)
  • src/wallet/wallet.cpp (3 hunks)
  • src/wallet/wallet.h (2 hunks)
🔇 Additional comments (23)
src/wallet/rpcwallet.cpp (5)

34-34: Header inclusion check.

Including "wallet/coincontrol.h" is proper for accessing coin control functionality.


3657-3657: Validate request parameter counts in mintspark.

Good to see the function checks for valid parameter counts. Consider explicitly handling cases where the user might pass fewer/more parameters with a clear error message suggesting the expected usage.


3731-3732: Clarify usage of wtxAndFee structure.

A new vector of <CWalletTx, CAmount> is introduced. This approach nicely bundles each minted transaction with its fee. Ensure consistent usage and correct fee aggregation across all call sites.


3733-3753: Refine parameter flow and error handling.

Within this block, the logic for calling MintAndStoreSpark with various arguments is introduced, including coin control. Verify that any errors from the method are properly logged/relayed back (e.g., strError usage) and that partial failures (if any) are handled gracefully.


5804-5804: Registering the mintspark command.

Adding the new RPC command to CRPCCommand is correct. Double-check that the function pointer and argument count align with the changes (additional parameters) introduced in mintspark.

src/qt/optionsmodel.h (2)

52-52: Introducing Split option.

The new Split enum entry clarifies the feature for future readers. Ensure it’s documented in the associated settings help text.


94-94: New private member fSplit.

Storing the split setting in OptionsModel is consistent with the approach for other wallet options. Ensure it has a default initialization that matches user expectations.

src/spark/sparkwallet.h (1)

125-125: fSplit parameter in CreateSparkMintTransactions.

Adding the bool fSplit parameter clarifies that splitting behavior is controlled externally. Be mindful to document its effects on mint transaction creation, especially for testers and maintainers.

src/rpc/client.cpp (1)

201-202: JSON conversion for additional mintspark parameters.

Enabling JSON parsing for the second and third arguments simplifies usage of arrays/objects. Confirm that the server-side code robustly handles this parsed data (e.g., for coin control addresses).

src/wallet/test/spark_tests.cpp (5)

79-79: Extended MintAndStoreSpark call in mint_and_store_spark.

The added true parameter indicates the splitting behavior is tested here. Ensure the test covers scenarios where no splitting is expected vs. splitting is active.


122-122: Test for subtract-fee with splitting.

Passing true for both subtractFeeFromAmount and fSplit is valuable for coverage. Confirm that fees are deducted correctly in combined scenarios.


311-311: Testing 10 FIRO mint.

Passing false, true ensures that the test scenario with no fee subtraction but splitting is validated. Confirm that the resulting minted sum matches expectations.


333-333: Automint check.

Empty mintedCoins triggers auto mint. Setting false, true, true clarifies the test for automatically minting all available funds while splitting. Ensure that leftover UTXOs are accounted for if partial failures happen.


347-347: Unique change script test.

Verifying that each minted transaction uses a unique change script is a good approach to detect collisions or unexpected merges. Confirm no accidental script reuse.

src/test/fixtures.cpp (1)

372-372: Ensure proper handling of the newly added split parameter
Including the fSplit parameter (true in this call) changes the transaction behavior. Confirm that relevant code paths handle this scenario by verifying the returned error string and ensuring all usage sites of MintAndStoreSpark are updated accordingly.

src/qt/optionsdialog.cpp (1)

191-191: Mapping fSplit to the model is consistent
This addition correctly reflects the new fSplit option in the user interface, allowing the setting to be saved and restored by the OptionsModel.

src/test/evospork_tests.cpp (1)

607-607: Propagate and check the fSplit parameter usage
Similarly to other calls, this addition includes fSplit=true. Make sure all test scenarios and downstream code properly handle this parameter, especially related to splitting logic in Spark transactions.

src/qt/optionsmodel.cpp (1)

88-91: Confirm the default for fSplit.
Right now, the default is set to true. If the user might expect otherwise (e.g., keep the existing behavior of not splitting), consider double-checking or adding a tooltip or label clarifying the default.

src/qt/walletmodel.cpp (1)

1410-1410: Verify fSplit usage in prepareMintSparkTransaction.
You're directly passing optionsModel->getfSplit() to CreateSparkMintTransactions. Confirm that all callers and UI paths that rely on non-splitting behavior now explicitly handle the scenario when fSplit is false.

src/wallet/wallet.cpp (4)

5660-5660: New parameter added to CreateSparkMintTransactions signature

The addition of the fSplit boolean parameter appears to be for controlling transaction splitting behavior in Spark mint transactions.


5687-5687: Parameter properly passed through to sparkWallet implementation

The fSplit parameter is correctly forwarded to the sparkWallet's CreateSparkMintTransactions method.


8224-8228: Parameter added to method declaration and passed through

The fSplit parameter is properly added to the method declaration and passed through to the underlying implementation.


Line range hint 5660-8228: Verify consistent usage of new fSplit parameter

The changes look good but we should verify the parameter is used consistently throughout the codebase.

✅ Verification successful

Let me check the implementation in sparkwallet.cpp to verify the parameter is used correctly.


Let me check how the fSplit parameter is used in the implementation.


Let me check the header file to verify the parameter is documented correctly.


Let me check one final thing - the usage in the Qt wallet code.


The fSplit parameter is used consistently across the codebase

Based on the verification:

  1. The parameter is correctly passed through in wallet.cpp to sparkWallet->CreateSparkMintTransactions()
  2. The implementation in sparkwallet.cpp properly uses fSplit to control coin selection behavior:
    • When fSplit is true, it uses AvailableCoinsForLMint() and shuffles the outputs
    • When false, it uses regular AvailableCoins()
  3. The Qt wallet correctly passes the user's split preference via optionsModel->getfSplit()
  4. The parameter is properly declared in all relevant header files
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for any other usages of CreateSparkMintTransactions to ensure they're updated
rg "CreateSparkMintTransactions" --type cpp

Length of output: 948


Script:

#!/bin/bash
# Check implementation in sparkwallet.cpp
rg -A 20 "bool CSparkWallet::CreateSparkMintTransactions" src/spark/sparkwallet.cpp

Length of output: 734


Script:

#!/bin/bash
# Search for fSplit usage in sparkwallet.cpp
rg -A 50 "fSplit" src/spark/sparkwallet.cpp

Length of output: 3093


Script:

#!/bin/bash
# Check header file documentation
rg -A 10 "CreateSparkMintTransactions" src/spark/sparkwallet.h

Length of output: 508


Script:

#!/bin/bash
# Check Qt wallet implementation context
rg -B 5 -A 10 "CreateSparkMintTransactions.*optionsModel" src/qt/walletmodel.cpp

Length of output: 787

Copy link

@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 (1)
src/wallet/rpcwallet.cpp (1)

Line range hint 3657-3673: Help text needs to be updated

The help text should be updated to reflect the new sendFrom parameter and its usage.

-    if (request.fHelp || request.params.size() == 0 || request.params.size() > 3)
+    if (request.fHelp || request.params.size() == 0 || request.params.size() > 4)
         throw std::runtime_error(
-            "mintspark {\"address\":{amount,memo...}}\n"
+            "mintspark {\"address\":{amount,memo...}} ( subtractfeefromamount [\"fromaddress\",...] )\n"
             + HelpRequiringPassphrase(pwallet) + "\n"
                                                 "\nArguments:\n"
                                                 "    {\n"
                                                 "      \"address\":amount   (numeric or string) The Spark address is the key, the numeric amount (can be string) in " + CURRENCY_UNIT +
                                                 " is the value\n"
                                                 "      ,...\n"
                                                 "    }\n"
+                                                "2. subtractfeefromamount  (boolean, optional) Subtract fee from amount\n"
+                                                "3. fromaddresses          (array, optional) A json array with addresses to spend from\n"
+                                                "    [\"address\",...]     (string) The addresses to spend from\n"
                                                 "\nResult:\n"
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d911072 and 8dec351.

📒 Files selected for processing (1)
  • src/wallet/rpcwallet.cpp (6 hunks)
🔇 Additional comments (4)
src/wallet/rpcwallet.cpp (4)

34-34: LGTM!

Added include for coin control functionality which is needed for the new sendFrom parameter.


3731-3753: LGTM!

The implementation of the new sendFrom functionality using CCoinControl looks correct:

  1. Creates coin control instance
  2. Gets available coins
  3. Filters coins by provided addresses
  4. Selects matching outputs for spending

3755-3755: LGTM!

Updated MintAndStoreSpark call to pass the new coin control parameter.


5804-5804: LGTM!

Added registration for the new mintspark RPC command with correct permissions.

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