Skip to content

Conversation

furszy
Copy link
Member

@furszy furszy commented Dec 4, 2023

Solves #28918. Coming from #28918 (comment) discussion.

The intention is to decouple only the bugfix relevant commits from #28985, allowing them to be included in the 26.x release. This way, we can avoid disabling the coin selection fuzzing test for an entire release.

Note:
Have introduced few changes to the bug fix commit so that the unit tests pass without the additional burden introduced in #28985.

@DrahtBot
Copy link
Contributor

DrahtBot commented Dec 4, 2023

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Code Coverage

For detailed information about the code coverage, see the test coverage report.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK josibake, murchandamus, achow101

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #28985 (Avoid changeless input sets when SFFO is active by murchandamus)
  • #25665 (refactor: Add util::Result failure values, multiple error and warning messages by ryanofsky)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@DrahtBot DrahtBot added the Wallet label Dec 4, 2023
Copy link
Contributor

@murchandamus murchandamus left a comment

Choose a reason for hiding this comment

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

Approach ACK: 233a07a

@@ -345,6 +348,7 @@ BOOST_AUTO_TEST_CASE(bnb_search_test)

CoinsResult available_coins;

coin_selection_params_bnb.m_effective_feerate = CFeeRate(0);
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: This test was already a bit weird to me, because it is categorized as belonging to "BnB", but the composition of preset inputs and the selection of additional inputs is a SelectCoins-level functionality that has little to do with specific coin selection algorithms. Composability should be tested at SelectCoins level (which it is in spend_tests and wallet_fundrawtransaction.py, although it could probably be more extensive). Since we already tested whether we can select two UTXOs that exactly match an amount in absence of fees above, I expect that we could remove this test altogether without losing coverage.

Copy link
Member

@achow101 achow101 left a comment

Choose a reason for hiding this comment

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

Approach ACK

@furszy
Copy link
Member Author

furszy commented Dec 4, 2023

Updated per feedback. Thanks everyone.

Test wise; replaced the logs debugger approach for a low level function call (per #28994 (comment)). And applied
the test variables naming suggestions.

Copy link
Member

@josibake josibake left a comment

Choose a reason for hiding this comment

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

Looks good! I am uncomfortable with adding the log message in a4c3294 as it has nothing to do with the bug fix and I think it could confuse (or worse, alarm) users to see "Waste" in their logs in the context of coin selection when waste is a not well-documented, implementation-specific term. Can we drop a4c3294 for now and revisit debug logging in a separate PR, unrelated to the v26 release?

@furszy
Copy link
Member Author

furszy commented Dec 5, 2023

I am uncomfortable with adding the log message as it has nothing to do with the bug fix and I think it could confuse (or worse, alarm) users to see "Waste" in their logs in the context of coin selection when waste is a not well-documented, implementation-specific term. Can we drop this commit for now and revisit debug logging in a separate PR, unrelated to the v26 release?

Logs aren't meant for end users; logs are useful for us to understand what is going on internally. Debug issues and provide better feedback to our users. This is not different to what we do for the fee calculation. And there is more documentation about the selection waste than doc about each of the logged fee reasons actually.

Right now, the transaction creation process lacks of outputting this information (thus why we are forced to call a low level function to test the bug). Moreover, as coin selection isn't a deterministic process, the lack of this info makes debugging and helping users harder than what it should.

That being said, if you and others agree on removing the logging after reading the rationale I just wrote, could drop it too. I'm not that hard on it.

@josibake
Copy link
Member

josibake commented Dec 5, 2023

Logs aren't meant for end users

Strongly disagree with this statement, and regardless of who they are intended for, users (people who run nodes) have access to these logs and do look at them.

This is not different to what we do for the fee calculation. And there is more documentation about the selection waste than doc about each of the logged fee reasons actually.

This is irrelevant to my point that this is not a bug fix and shouldn't be included in a bug fix PR. I also don't agree with the justification and claim that coin selection is well-documented, but I'd rather leave that discussion for a PR related to improving wallet logging and keep this one focused on the bug fix for v26 :)

@furszy
Copy link
Member Author

furszy commented Dec 5, 2023

This is irrelevant to my point that this is not a bug fix and shouldn't be included in a bug fix PR. I also don't agree with the justification and claim that coin selection is well-documented.

Where did I claim that coin selection is well-documented? I said that it is more documented than fee estimation. And fee estimation is being logged.

Strongly disagree with this statement, and regardless of who they are intended for, users (people who run nodes) have access to these logs and do look at them.

Everyone have access. That doesn't mean that they are meant for everyone. Thus why we have logging domains and levels. Moreover, most logging domains are disabled by default. Including the wallet one.

@josibake
Copy link
Member

josibake commented Dec 5, 2023

Where did I claim that coin selection is well-documented?

Sorry, my comment should say s/well-documented/more documented/

@furszy
Copy link
Member Author

furszy commented Dec 5, 2023

Where did I claim that coin selection is well-documented?

Sorry, my comment should say s/well-documented/more documented/

np. Happens on any convo.

I'm not that strong on the new logging introduction, still, sharing the change rationale and opening the convo helps moving forward.

@furszy furszy force-pushed the 2023_wallet_sffo_skip_bnb branch from 7e1bf0d to efb54a2 Compare December 5, 2023 13:55
Copy link
Contributor

@murchandamus murchandamus left a comment

Choose a reason for hiding this comment

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

I realized that we need to add the input fee to each UTXO rather than deducting it from the target for the two input set options to have the same waste score.

murchandamus and others added 2 commits December 7, 2023 21:47
Co-authored-by: furszy <matiasfurszyfer@protonmail.com>
Useful for understanding what is going on internally
when the software is running. Debug issues, and provide
more accurate feedback to users.
@furszy furszy force-pushed the 2023_wallet_sffo_skip_bnb branch from efb54a2 to 1d3bc77 Compare December 8, 2023 00:52
@furszy
Copy link
Member Author

furszy commented Dec 8, 2023

Updated per feedback. Thanks.
Applied @murchandamus suggestion of adding inputs fee to each UTXO rather than deduct them from the target. The latter one was breaking the equivalence of the input sets.

Note:
I did not improve the test code organization on purpose. Made the smallest change-set possible to not interfere with #28985. (I just reused the hardcoded number for the p2wpkh input size, just like we do in several other places inside the coinselector_tests file).

Note 2:
Haven't introduced the "BnB never produces change" assertion because it requires further restructuring.
The responsibility of asserting that a certain coin selection algorithm did not produce change shouldn't lie at the wallet's tx creation level. Instead, it should be internal to the selection algorithm. However, to achieve this, we need to modify the way the "create change" decision is made. For instance, it would be good to introduce a field inside SelectionResult that expresses the coin selection algo's expectation in terms of producing change or not.

Copy link
Member

@josibake josibake left a comment

Choose a reason for hiding this comment

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

ACK 1d3bc77

Applied @murchandamus suggestion of adding inputs fee to each UTXO rather than deduct them from the target. The latter one was breaking the equivalence of the input sets.

Wasn't the test still passing before, when you were deducting them from the target? If so, I would suggest we take a closer look at this test in #28985 to ensure it's testing the thing it's supposed to be testing.

@furszy furszy force-pushed the 2023_wallet_sffo_skip_bnb branch from 18669d7 to 576bee8 Compare December 12, 2023 02:40
Copy link
Contributor

@murchandamus murchandamus left a comment

Choose a reason for hiding this comment

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

ACK 18669d7

Edit:
ACK 576bee8

Comment on lines +483 to +487
add_coin(available_coins, *wallet, COIN + params.m_cost_of_change, /*feerate=*/params.m_effective_feerate, /*nAge=*/6, /*fIsFromMe=*/true, /*nInput=*/0, /*spendable=*/true);
add_coin(available_coins, *wallet, 0.5 * COIN + params.m_cost_of_change, /*feerate=*/params.m_effective_feerate, /*nAge=*/6, /*fIsFromMe=*/true, /*nInput=*/0, /*spendable=*/true);
add_coin(available_coins, *wallet, 0.5 * COIN, /*feerate=*/params.m_effective_feerate, /*nAge=*/6, /*fIsFromMe=*/true, /*nInput=*/0, /*spendable=*/true);
// Knapsack will only find a changeless solution on an exact match to the satoshi, SRD doesn’t look for changeless
// If BnB were run, it would produce a single input solution with the best waste score
Copy link
Contributor

Choose a reason for hiding this comment

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

Good, now I’d expect:

  • SRD randomly returning two or three of the inputs
  • Knapsack return { COIN+coc, 0.5×COIN }
  • BnB return { COIN+coc }

Since the feerate is higher than the LFTR, two or three inputs with change are worse than one input without change, even when dropping coc into fees. Ergo, BnB not being the first solution proves that BnB wasn’t run.

@josibake
Copy link
Member

ACK 576bee8

@DrahtBot DrahtBot requested review from murchandamus and removed request for josibake December 12, 2023 09:20
@josibake
Copy link
Member

ACK 18669d7

guessing you meant to ack 576bee8 ? 😉

@murchandamus
Copy link
Contributor

Yes, ACK 576bee8

@DrahtBot DrahtBot removed the request for review from murchandamus December 12, 2023 13:31
@achow101
Copy link
Member

ACK 576bee8

@DrahtBot DrahtBot removed the request for review from achow101 December 12, 2023 15:38
@achow101 achow101 merged commit d646ca3 into bitcoin:master Dec 12, 2023
@fanquake fanquake added this to the 26.1 milestone Dec 12, 2023
@fanquake fanquake mentioned this pull request Dec 12, 2023
fanquake pushed a commit to fanquake/bitcoin that referenced this pull request Dec 12, 2023
Co-authored-by: furszy <matiasfurszyfer@protonmail.com>

Github-Pull: bitcoin#28994
Rebased-From: 5cea25b
fanquake pushed a commit to fanquake/bitcoin that referenced this pull request Dec 12, 2023
Useful for understanding what is going on internally
when the software is running. Debug issues, and provide
more accurate feedback to users.

Github-Pull: bitcoin#28994
Rebased-From: 0c57557
fanquake pushed a commit to fanquake/bitcoin that referenced this pull request Dec 12, 2023
Verify the transaction creation process does not produce
a BnB solution when SFFO is enabled.
This is currently problematic because it could require a
change output. And BnB is specialized on changeless solutions.

Co-authored-by: Andrew Chow <achow101@gmail.com>
Co-authored-by: Murch <murch@murch.one>

Github-Pull: bitcoin#28994
Rebased-From: 05e5ff1
fanquake pushed a commit to fanquake/bitcoin that referenced this pull request Dec 12, 2023
@fanquake
Copy link
Member

Added this to #29011 for backporting to 26.x.

@furszy furszy deleted the 2023_wallet_sffo_skip_bnb branch December 12, 2023 16:33
@fanquake
Copy link
Member

See #28918 (comment). This doesn't seem to have fixed the fuzzer.

@furszy
Copy link
Member Author

furszy commented Dec 13, 2023

See #28918 (comment). This doesn't seem to have fixed the fuzzer.

It fixed the initially reported one (#28918 (comment)). The latest one is different.

fanquake pushed a commit to fanquake/bitcoin that referenced this pull request Jan 4, 2024
Co-authored-by: furszy <matiasfurszyfer@protonmail.com>

Github-Pull: bitcoin#28994
Rebased-From: 5cea25b
fanquake pushed a commit to fanquake/bitcoin that referenced this pull request Jan 4, 2024
Useful for understanding what is going on internally
when the software is running. Debug issues, and provide
more accurate feedback to users.

Github-Pull: bitcoin#28994
Rebased-From: 0c57557
fanquake pushed a commit to fanquake/bitcoin that referenced this pull request Jan 4, 2024
Verify the transaction creation process does not produce
a BnB solution when SFFO is enabled.
This is currently problematic because it could require a
change output. And BnB is specialized on changeless solutions.

Co-authored-by: Andrew Chow <achow101@gmail.com>
Co-authored-by: Murch <murch@murch.one>

Github-Pull: bitcoin#28994
Rebased-From: 05e5ff1
fanquake pushed a commit to fanquake/bitcoin that referenced this pull request Jan 4, 2024
glozow added a commit that referenced this pull request Jan 9, 2024
7b79e54 doc: update release notes for 26.x (fanquake)
ccf00b1 wallet: Fix use-after-free in WalletBatch::EraseRecords (MarcoFalke)
40252e1 ci: Set `HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK` to avoid failures (Hennadii Stepanov)
b06b14e rpc: getwalletinfo, return wallet 'birthtime' (furszy)
1283401 test: coverage for wallet birth time interaction with -reindex (furszy)
0fa47e2 wallet: fix legacy spkm default birth time (furszy)
84f4a6c wallet: birth time update during tx scanning (furszy)
074296d refactor: rename FirstKeyTimeChanged to MaybeUpdateBirthTime (furszy)
35039ac fuzz: disable BnB when SFFO is enabled (furszy)
903b462 test: add coverage for BnB-SFFO restriction (furszy)
05d0576 wallet: create tx, log resulting coin selection info (furszy)
5493ebb wallet: skip BnB when SFFO is active (Murch)
b15e2e2 test: add regression test for the getrawtransaction segfault (Martin Zumsande)
5097bb3 rpc: fix getrawtransaction segfault (Martin Zumsande)
81e744a ci: Use Ubuntu 24.04 Noble for asan (MarcoFalke)
69e53d1 ci: Use Ubuntu 24.04 Noble for tsan,tidy,fuzz (MarcoFalke)
d2c80b6 doc: Missing additions to 26.0 release notes (fanquake)
8dc2c75 doc: add historical release notes for 26.0 (fanquake)

Pull request description:

  Backports for `26.x`. Currently:
  * #28920
  * #28992
  * #28994
  * #29003
  * #29023
  * #29080
  * #29176

ACKs for top commit:
  TheCharlatan:
    ACK 7b79e54
  glozow:
    ACK 7b79e54, matches mine

Tree-SHA512: 898aec76ed3ad35e0edd0980af5bcc21bd60003bbf69e0b4f473ed2aa38c4e3b360b930bc3747cf798195906a8f9fe66417524f5e5ef40fa68f1c1aaceebdeb0
@bitcoin bitcoin locked and limited conversation to collaborators Dec 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants