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

test: coinselection edge cases #24580

Closed
wants to merge 1 commit into from
Closed

Conversation

S3RK
Copy link
Contributor

@S3RK S3RK commented Mar 16, 2022

This PR adds tests for some edge cases in coin selection.

There are 4 sections by the type of utxo pool:

  1. a few small inputs of equal value
  2. one big input and many small inputs
  3. just one input
  4. one big and one small input

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.

Cool! Concept ACK. Did a light review, haven't reproduced all the numbers.

test/functional/wallet_coinselection.py Show resolved Hide resolved
test/functional/wallet_coinselection.py Outdated Show resolved Hide resolved
test/functional/wallet_coinselection.py Outdated Show resolved Hide resolved
test/functional/wallet_coinselection.py Outdated Show resolved Hide resolved
test/functional/wallet_coinselection.py Outdated Show resolved Hide resolved
test/functional/wallet_coinselection.py Outdated Show resolved Hide resolved
test/functional/wallet_coinselection.py Outdated Show resolved Hide resolved
test/functional/wallet_coinselection.py Outdated Show resolved Hide resolved
test/functional/wallet_coinselection.py Show resolved Hide resolved
assert_equal(len(tx['vin']), 1)
assert_equal(len(tx['vout']), 2)

# if small coins > MIN_CHANGE than we just add one small coin to the big one and create change
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment confuses me. After paying the fees, the big coin doesn't have enough funds to pay fees and create the output here, so we would always need both coins.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops. The idea was that you have more than 1 small coin. If small coins > MIN_CHANGE that the tests in test_one_big_and_many_small_coins doesn't work. Any idea how to improve that? For now, added more than one small coin in this test case

@S3RK
Copy link
Contributor Author

S3RK commented Mar 22, 2022

Retouched comments to address Xekyo's feedback.

@murchandamus
Copy link
Contributor

Looks good. What is the next step you plan for this PR? How can one help?

@S3RK
Copy link
Contributor Author

S3RK commented Mar 24, 2022

I thought this PR can be merged roughly as it is (addressing all the concerns of course), as I believe the test is valuable in itself.

As a follow up I'd like to fix some of the inefficiencies of coin selection by increasing BnB upper limit. But for that we need to improve how we drop change for fees. I tried one approach in #23367 but it doesn't work that well. So I'm going splitting #23367 into parts that could be merged independently (the first one -> #24649).

Let's talk on the next wallet meeting.

@S3RK
Copy link
Contributor Author

S3RK commented Mar 29, 2022

There is probably a conflict with #24494.

@achow101
Copy link
Member

While I appreciate more tests, these tests seem to be extremely specific to the way that coin selection currently works and look like they would start failing as soon as we change something, such as removing knapsack. So I'm not sure if we actually want to have these tests if they are going to be removed and/or require a ton of recalculation for future coin selection changes.

If we do want these tests, then I don't think it should use legacy addresses so much as hopefully we won't make those by default soon.

@S3RK
Copy link
Contributor Author

S3RK commented Apr 19, 2022

While I appreciate more tests, these tests seem to be extremely specific to the way that coin selection currently works and look like they would start failing as soon as we change something, such as removing knapsack. So I'm not sure if we actually want to have these tests if they are going to be removed and/or require a ton of recalculation for future coin selection changes.

Agree, these are not your normal tests, primarily because it's hard to define the "right" or "expected" outcome. I created these tests to expose some shortcomings of current coin selection and justify increasing BnB limit (#24752). It'd be nice to have them around in some form to avoid regressions, maybe we can incorporate them somehow into simulations. wdyt?

If we do want these tests, then I don't think it should use legacy addresses so much as hopefully we won't make those by default soon.

@instagibbs
Copy link
Member

To throw my relatively unproductive opinion into the mix, this is a staggeringly large number of magic numbers. Ideally all numbers in tests are "obvious" or programmatic. It's a nightmare to maintain otherwise.

Didn't read or think enough about overall thrust of the tests.

@S3RK
Copy link
Contributor Author

S3RK commented May 23, 2022

Thanks for the feedback. Maybe a better way to verify coin selection would to integrate some simulation/benchmark into this repo.

@S3RK S3RK closed this May 23, 2022
@bitcoin bitcoin locked and limited conversation to collaborators May 23, 2023
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.

None yet

6 participants