[wallet] fee fixes: always create change, adjust value, and p… #10333

pull instagibbs wants to merge 2 commits into bitcoin:master from instagibbs:fixfeefinal changing 1 files +102 −85
  1. instagibbs commented at 9:13 pm on May 3, 2017: member

    …rune later

    This PR is an attempt to solve some of #10247 , first and foremost the case:

    // TODO: The case where there is no change output remains // to be addressed so we avoid creating too small an output

    This is resolved by always assuming a change output exists, and rebalancing that value by the fee excess, and deleting when necessary. The logic is also simpler to me.

  2. instagibbs renamed this:
    CreateTransction fee fixes: always create change, adjust value, and p…
    [wallet] fee fixes: always create change, adjust value, and p…
    on May 3, 2017
  3. jonasschnelli added the label Wallet on May 4, 2017
  4. instagibbs commented at 5:33 pm on May 8, 2017: member

    Note: This is a “regression” due to MIN_FINAL_CHANGE being taken out of the calculation: https://github.com/bitcoin/bitcoin/pull/10333/files#diff-b2bb174788c7409b671c46ccc86034bdL2647

    A bit confusing since the change is dropped when IsDust as before… this would be a good time to sync this behavior.

  5. laanwj added this to the milestone 0.15.0 on May 11, 2017
  6. instagibbs force-pushed on May 12, 2017
  7. instagibbs commented at 2:18 pm on May 12, 2017: member
    rebased, and included logic to attempt change larger than MIN_FINAL_CHANGE when possible. In the end some cases cannot be avoided, and just-over-dust change may be kept.
  8. instagibbs commented at 1:57 pm on June 21, 2017: member
    suggested new strategy: instead of “trying one more time” when change is in middle-ground, cache the current transaction, increase the amount you’re attempting to send, and try again. If you then run out of available coins, you simply return the cached version of the transaction.
  9. laanwj added this to the "Blockers" column in a project

  10. instagibbs force-pushed on Jun 22, 2017
  11. CreateTransction fee fixes: always create change, adjust value, and prune later fd20e0bc89
  12. instagibbs force-pushed on Jun 22, 2017
  13. instagibbs commented at 4:48 am on June 23, 2017: member
    Implemented the previously mentioned idea. Instead of doing “one more try” to get acceptable change, it caches the successful yet small change transaction and slowly grows the amount of coins it grabs until it creates an acceptable transaction, given reasonable chosen inputs this will result in a transaction with change larger than MIN_FINAL_CHANGE. If it fails and runs out of coins it returns the cached transaction.
  14. in src/wallet/wallet.cpp:2745 in 405cf1032c outdated
    2757+                        reservekey.ReturnKey();
    2758+                    // If larger than dust, but still small, increase fee target and try again
    2759+                    } else if (txNew.vout[nChangePosInOut].nValue < MIN_FINAL_CHANGE) {
    2760+                        // Save this transaction, use if we cannot get large-enough change
    2761+                        if (!have_cached_txn) {
    2762+                            tx_cached = txNew;
    


    achow101 commented at 7:28 pm on June 23, 2017:
    have_cached_txn should probably be set to true here as it is never actually set anywhere
  15. in src/wallet/wallet.cpp:2510 in 405cf1032c outdated
    2505+    // falling between uneconomical dust and MIN_FINAL_CHANGE. If the wallet
    2506+    // runs out of funds trying to find a transaction that has pruneable
    2507+    // change dust or change larger than MIN_FINAL_CHANGE, it will
    2508+    // return this transaction.
    2509+    CMutableTransaction tx_cached;
    2510+    bool have_cached_txn;
    


    achow101 commented at 7:28 pm on June 23, 2017:
    Shouldn’t you assign have_cached_txn to false here as it is not assiged before it is used down below?
  16. in src/wallet/wallet.cpp:2654 in 405cf1032c outdated
    2702+                if (nChangePosInOut == -1)
    2703+                {
    2704+                    // Insert change txn at random position:
    2705+                    nChangePosInOut = GetRandInt(txNew.vout.size()+1);
    2706+                }
    2707+                else if ((unsigned int)nChangePosInOut > txNew.vout.size())
    


    achow101 commented at 7:30 pm on June 23, 2017:
    I don’t see how this case matters. Wouldn’t nChangePosInOut never be set to an out of range index?

    instagibbs commented at 7:36 pm on June 23, 2017:
    Caller may request a too-high change position. This is also a simple code move, not going to change this logic.
  17. instagibbs force-pushed on Jun 24, 2017
  18. cache the first transaction that has change smaller than MIN_FINAL_CHANGE
    Raise the target fee, then try again. If the wallet has insufficient funds
    to reach MIN_FINAL_CHANGE then use the cached transaction.
    f8415fcc03
  19. instagibbs force-pushed on Jun 24, 2017
  20. instagibbs commented at 1:15 pm on June 24, 2017: member
    fixed issues, thanks @achow101
  21. gmaxwell commented at 6:18 pm on June 29, 2017: contributor
    Concept ACK
  22. morcos commented at 3:25 pm on July 5, 2017: member
    I think #10712 is preferable to this PR
  23. instagibbs commented at 3:31 pm on July 5, 2017: member
    closing in favor of #10712
  24. instagibbs closed this on Jul 5, 2017

  25. laanwj removed this from the "Blockers" column in a project

  26. laanwj referenced this in commit e8b95239ee on Jul 11, 2017
  27. PastaPastaPasta referenced this in commit 2122416793 on Aug 6, 2019
  28. PastaPastaPasta referenced this in commit f9ca5db82c on Aug 6, 2019
  29. PastaPastaPasta referenced this in commit b501fae48f on Aug 6, 2019
  30. PastaPastaPasta referenced this in commit b5b7868c15 on Aug 7, 2019
  31. PastaPastaPasta referenced this in commit a76e442f95 on Aug 8, 2019
  32. PastaPastaPasta referenced this in commit 00ceca6216 on Aug 12, 2019
  33. barrystyle referenced this in commit 4f15dfe35d on Jan 22, 2020
  34. MarcoFalke locked this on Sep 8, 2021


instagibbs achow101 gmaxwell morcos

Labels
Wallet

Milestone
0.15.0


github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-12-18 15:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me