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

backport: partial bitcoin#25507; fix selection of fully mixed coins, disable BnB #6600

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

Conversation

UdjinM6
Copy link

@UdjinM6 UdjinM6 commented Feb 26, 2025

Issue being fixed or feature implemented

Coin selection is a bit broken on develop rn, there are few issues:

  • we should never use BnB because it has no idea about mixing;
  • the target value should not be altered in cases when the tx fee is subtracted from outputs or no change is created at all.

Issues were introduced via recent wallet backports, so it's on develop only, no released versions are affected.

What was done?

How Has This Been Tested?

Run ./src/test/test_dash -t spend_tests and ./test/functional/wallet_basic.py

develop + 5544542 - > failure
This branch -> success

Breaking Changes

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have made corresponding changes to the documentation
  • I have assigned this pull request to a milestone (for repository code-owners and collaborators only)

@UdjinM6 UdjinM6 added this to the 23 milestone Feb 26, 2025
achow101 and others added 3 commits February 27, 2025 00:21
…f subtracting fees from output

140d942 wallet: don't add change fee to target if subtracting fees from output (S3RK)

Pull request description:

  Change fee is payed by the recipient, so we don't need to add it to our target for coin selection.

ACKs for top commit:
  achow101:
    ACK 140d942
  ishaanam:
    ACK 140d942
  furszy:
    Code review ACK 140d942

Tree-SHA512: b5efd0264c47ecee9204a3fd039bad24c69f9e614c6e1d9bb240ee5be6356b175aa074f3be123e6cfb8becd4d7bd1028eebe18801662cc69d19413d8d5a9dd5c
@UdjinM6 UdjinM6 force-pushed the fix_wallet_backports branch from 5544542 to 0c32cf4 Compare February 26, 2025 21:21
@UdjinM6 UdjinM6 changed the title backport: bitcoin#25507; fix selection of fully mixed coins, disable BnB backport: partial bitcoin#25507; fix selection of fully mixed coins, disable BnB Feb 26, 2025
Copy link

coderabbitai bot commented Feb 26, 2025

Walkthrough

The changes modify the coin selection logic used in wallet transactions. In the updated implementation, the BnB coin selection method is effectively disabled by placing it behind an always-false condition. Instead, a new variable, target_with_change, is introduced and initialized with the original target value. This variable is then adjusted to include a change fee when specific conditions are met. The adjusted target value is subsequently passed to the knapsack solver, replacing the previous logic that directly added the change fee to the target. No changes have been made to any exported or public interfaces.


📜 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 4ad371b and 0c32cf4.

📒 Files selected for processing (1)
  • src/wallet/spend.cpp (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (9)
  • GitHub Check: linux64_tsan-build / Build source
  • GitHub Check: linux64_multiprocess-build / Build source
  • GitHub Check: linux64_ubsan-build / Build source
  • GitHub Check: linux64_sqlite-build / Build source
  • GitHub Check: linux64_fuzz-build / Build source
  • GitHub Check: linux64-build / Build source
  • GitHub Check: linux64_nowallet-build / Build source
  • GitHub Check: win64-build / Build source
  • GitHub Check: arm-linux-build / Build source
🔇 Additional comments (4)
src/wallet/spend.cpp (4)

376-379: Disabled BnB selection algorithm

The PR intentionally disables the BnB (Branch and Bound) coin selection algorithm by adding a false && condition, effectively preventing this code path from executing. This is appropriate since the BnB algorithm does not account for coin mixing, as mentioned in the PR objectives.


383-383: Added new target_with_change variable

This new variable properly separates the original target value from the potentially adjusted value that accounts for change fees.


386-389: Added conditional logic for including change fee

This change correctly implements the logic to only add the change fee to the target value when we're not subtracting fees from outputs and not working with fully mixed coins. This addresses the issue mentioned in the PR objectives where the target value was incorrectly altered when transaction fees were deducted from outputs or when no change was produced.


392-392: Updated KnapsackSolver to use the new target_with_change variable

The KnapsackSolver now uses the conditionally adjusted target value instead of always adding the change fee. This ensures that the target value calculation is correct for all scenarios, particularly when working with fully mixed coins or when subtracting fees from outputs.

✨ Finishing Touches
  • 📝 Generate Docstrings

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.
  • @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.

@@ -373,7 +373,7 @@ bool CWallet::AttemptSelection(const CAmount& nTargetValue, const CoinEligibilit
std::vector<OutputGroup> positive_groups = GroupOutputs(coins, coin_selection_params, eligibility_filter, true /* positive_only */);
std::set<CInputCoin> bnb_coins;
CAmount bnb_value;
if (SelectCoinsBnB(positive_groups, nTargetValue, coin_selection_params.m_cost_of_change, bnb_coins, bnb_value)) {
if (false && SelectCoinsBnB(positive_groups, nTargetValue, coin_selection_params.m_cost_of_change, bnb_coins, bnb_value)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

should it be always disabled or only in case of CJ?

Copy link
Author

Choose a reason for hiding this comment

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

yes, we should avoid spending cj-related coins via regular send

@UdjinM6 UdjinM6 requested review from PastaPastaPasta and kwvg March 4, 2025 16:28
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