Skip to content

Conversation

achow101
Copy link
Member

@achow101 achow101 commented Mar 4, 2020

If we find a solution which has no waste, just use that. This solution
is what we would consider to be optimal, and other solutions we find
would have to also have 0 waste, so they are equivalent to the first
one with 0 waste. Thus we can optimize by just choosing the first one
with 0 waste.

Closes #18257

If we find a solution which has no waste, just use that. This solution
is what we would consider to be optimal, and other solutions we find
would have to also have 0 waste, so they are equivalent to the first
one with 0 waste. Thus we can optimize by just choosing the first one
with 0 waste.
@fanquake fanquake added the Wallet label Mar 4, 2020
@DrahtBot
Copy link
Contributor

DrahtBot commented Mar 4, 2020

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

Conflicts

Reviewers, this pull request conflicts with the following ones:

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.

@practicalswift
Copy link
Contributor

Concept ACK

@fjahr
Copy link
Contributor

fjahr commented Mar 4, 2020

Concept ACK on this as it is an improvement!

However, looking at this I had another thought: given we have two possible solutions with 0 waste, would we not want to minimize fees by selecting the one with fewer inputs? So, instead of stopping early we could still run through all the tries and select the best waste option with the least inputs. Actually this could be an additional breaker between any equal waste options.

@achow101
Copy link
Member Author

achow101 commented Mar 5, 2020

However, looking at this I had another thought: given we have two possible solutions with 0 waste, would we not want to minimize fees by selecting the one with fewer inputs? So, instead of stopping early we could still run through all the tries and select the best waste option with the least inputs. Actually this could be an additional breaker between any equal waste options.

Fewer inputs does not necessarily minimize fees. It depends on the exact scripts being used. Regardless, I don't think an explicit check for fees is needed. So long as fee > long_term_fee, the waste metric will include an amount that is proportional to the fee each input requires, so in the end, the selection that has the least waste also pays the least in transaction fees.

@instagibbs
Copy link
Member

So long as fee > long_term_fee, the waste metric will include an amount that is proportional to the fee each input requires, so in the end, the selection that has the least waste also pays the least in transaction fees.

just to nit, in this case, fee == long_term_fee, right? I think it could go either way, if the user expects long term fees to go up or down they might want to pick more or fewer inputs. In the absence of evidence, simply returning with first result seems optimal.

@instagibbs
Copy link
Member

aka concept ACK

@@ -176,8 +176,8 @@ BOOST_AUTO_TEST_CASE(bnb_search_test)
selection.clear();

// Select 5 Cent
add_coin(3 * CENT, 3, actual_selection);
add_coin(2 * CENT, 2, actual_selection);
add_coin(4 * CENT, 4, actual_selection);
Copy link
Member

Choose a reason for hiding this comment

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

why these changes?

Copy link
Member Author

Choose a reason for hiding this comment

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

There is an optimal result earlier in the selection so that changes the outcome here.

Copy link
Contributor

@yancyribbens yancyribbens left a comment

Choose a reason for hiding this comment

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

LGTM

@laanwj
Copy link
Member

laanwj commented Mar 6, 2020

Obvious concept ACK.
Is this a case that happens in practice though? I mean, is it worth special-casing, or doesn't it really matter to do a few more iterations in an unlikely 'optimal' case? I don't really have an intuition for this.

@yancyribbens
Copy link
Contributor

Is this a case that happens in practice though?

That's also a question I have. My intuition is it's very unlikely to have an exact match in practice. Also, I think If the cost of change is sufficiently small, its unlikely to have any match including an exact match.

@achow101
Copy link
Member Author

achow101 commented Mar 7, 2020

I think this condition is fairly hard to hit and probably doesn't make much of a difference. I think that most wallets will hit the iteration limit in BnB as we do search for more solutions after finding the first one, so exiting early probably isn't helping that much anyways.

@instagibbs
Copy link
Member

I think this extra logic is really easy to understand and maintainable, therefore should be merged(provided proper review) regardless or not how theoretical people find it.

@instagibbs
Copy link
Member

utACK 9b5950d

Copy link
Contributor

@meshcollider meshcollider left a comment

Choose a reason for hiding this comment

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

utACK 9b5950d

@meshcollider meshcollider merged commit 0856c15 into bitcoin:master Apr 17, 2020
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Apr 17, 2020
9b5950d bnb: exit selection when best_waste is 0 (Andrew Chow)

Pull request description:

  If we find a solution which has no waste, just use that. This solution
  is what we would consider to be optimal, and other solutions we find
  would have to also have 0 waste, so they are equivalent to the first
  one with 0 waste. Thus we can optimize by just choosing the first one
  with 0 waste.

  Closes bitcoin#18257

ACKs for top commit:
  instagibbs:
    utACK bitcoin@9b5950d
  meshcollider:
    utACK 9b5950d

Tree-SHA512: 59565ff4a3d8281e7bc0ce87065a34c8d8bf8a95f628ba96b4fe89f1274979165aea6312e5f1f21b418c8c484aafc5166d22d9eff9d127a8192498625d58c557
ComputerCraftr pushed a commit to ComputerCraftr/bitcoin that referenced this pull request Jun 10, 2020
9b5950d bnb: exit selection when best_waste is 0 (Andrew Chow)

Pull request description:

  If we find a solution which has no waste, just use that. This solution
  is what we would consider to be optimal, and other solutions we find
  would have to also have 0 waste, so they are equivalent to the first
  one with 0 waste. Thus we can optimize by just choosing the first one
  with 0 waste.

  Closes bitcoin#18257

ACKs for top commit:
  instagibbs:
    utACK bitcoin@9b5950d
  meshcollider:
    utACK 9b5950d

Tree-SHA512: 59565ff4a3d8281e7bc0ce87065a34c8d8bf8a95f628ba96b4fe89f1274979165aea6312e5f1f21b418c8c484aafc5166d22d9eff9d127a8192498625d58c557
jasonbcox pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Oct 23, 2020
Summary:
9b5950db8683f9b4be03f79ee0aae8a780b01a4b bnb: exit selection when best_waste is 0 (Andrew Chow)

Pull request description:

  If we find a solution which has no waste, just use that. This solution
  is what we would consider to be optimal, and other solutions we find
  would have to also have 0 waste, so they are equivalent to the first
  one with 0 waste. Thus we can optimize by just choosing the first one
  with 0 waste.

  Closes #18257

Backport of Core [[bitcoin/bitcoin#18262 | PR18262]]

Test Plan:
  ninja check

Reviewers: #bitcoin_abc, deadalnix

Reviewed By: #bitcoin_abc, deadalnix

Differential Revision: https://reviews.bitcoinabc.org/D8064
vijaydasmp added a commit to vijaydasmp/dash that referenced this pull request Aug 29, 2021
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Sep 17, 2021
9b5950d bnb: exit selection when best_waste is 0 (Andrew Chow)

Pull request description:

  If we find a solution which has no waste, just use that. This solution
  is what we would consider to be optimal, and other solutions we find
  would have to also have 0 waste, so they are equivalent to the first
  one with 0 waste. Thus we can optimize by just choosing the first one
  with 0 waste.

  Closes bitcoin#18257

ACKs for top commit:
  instagibbs:
    utACK bitcoin@9b5950d
  meshcollider:
    utACK 9b5950d

Tree-SHA512: 59565ff4a3d8281e7bc0ce87065a34c8d8bf8a95f628ba96b4fe89f1274979165aea6312e5f1f21b418c8c484aafc5166d22d9eff9d127a8192498625d58c557
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Sep 17, 2021
9b5950d bnb: exit selection when best_waste is 0 (Andrew Chow)

Pull request description:

  If we find a solution which has no waste, just use that. This solution
  is what we would consider to be optimal, and other solutions we find
  would have to also have 0 waste, so they are equivalent to the first
  one with 0 waste. Thus we can optimize by just choosing the first one
  with 0 waste.

  Closes bitcoin#18257

ACKs for top commit:
  instagibbs:
    utACK bitcoin@9b5950d
  meshcollider:
    utACK 9b5950d

Tree-SHA512: 59565ff4a3d8281e7bc0ce87065a34c8d8bf8a95f628ba96b4fe89f1274979165aea6312e5f1f21b418c8c484aafc5166d22d9eff9d127a8192498625d58c557
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Sep 18, 2021
9b5950d bnb: exit selection when best_waste is 0 (Andrew Chow)

Pull request description:

  If we find a solution which has no waste, just use that. This solution
  is what we would consider to be optimal, and other solutions we find
  would have to also have 0 waste, so they are equivalent to the first
  one with 0 waste. Thus we can optimize by just choosing the first one
  with 0 waste.

  Closes bitcoin#18257

ACKs for top commit:
  instagibbs:
    utACK bitcoin@9b5950d
  meshcollider:
    utACK 9b5950d

Tree-SHA512: 59565ff4a3d8281e7bc0ce87065a34c8d8bf8a95f628ba96b4fe89f1274979165aea6312e5f1f21b418c8c484aafc5166d22d9eff9d127a8192498625d58c557
thelazier pushed a commit to thelazier/dash that referenced this pull request Sep 25, 2021
9b5950d bnb: exit selection when best_waste is 0 (Andrew Chow)

Pull request description:

  If we find a solution which has no waste, just use that. This solution
  is what we would consider to be optimal, and other solutions we find
  would have to also have 0 waste, so they are equivalent to the first
  one with 0 waste. Thus we can optimize by just choosing the first one
  with 0 waste.

  Closes bitcoin#18257

ACKs for top commit:
  instagibbs:
    utACK bitcoin@9b5950d
  meshcollider:
    utACK 9b5950d

Tree-SHA512: 59565ff4a3d8281e7bc0ce87065a34c8d8bf8a95f628ba96b4fe89f1274979165aea6312e5f1f21b418c8c484aafc5166d22d9eff9d127a8192498625d58c557
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Feb 15, 2022
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.

Suggested BNB Search Optimization
9 participants