[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. morcos cross-referenced this on May 4, 2017 from issue cost too many fees? by JokerCatz
  5. 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.

  6. instagibbs cross-referenced this on May 8, 2017 from issue [WIP] [Wallet] Target effective value during transaction creation by instagibbs
  7. laanwj added this to the milestone 0.15.0 on May 11, 2017
  8. instagibbs force-pushed on May 12, 2017
  9. 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.

  10. 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.

  11. laanwj added this to the "Blockers" column in a project

  12. instagibbs force-pushed on Jun 22, 2017
  13. CreateTransction fee fixes: always create change, adjust value, and prune later fd20e0bc89
  14. instagibbs force-pushed on Jun 22, 2017
  15. 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.

  16. 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

  17. 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?

  18. 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.

  19. instagibbs force-pushed on Jun 24, 2017
  20. 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
  21. instagibbs force-pushed on Jun 24, 2017
  22. instagibbs commented at 1:15 PM on June 24, 2017: member

    fixed issues, thanks @achow101

  23. gmaxwell commented at 6:18 PM on June 29, 2017: contributor

    Concept ACK

  24. morcos cross-referenced this on Jun 30, 2017 from issue Add change output if necessary to reduce excess fee by morcos
  25. morcos commented at 3:25 PM on July 5, 2017: member

    I think #10712 is preferable to this PR

  26. instagibbs commented at 3:31 PM on July 5, 2017: member

    closing in favor of #10712

  27. instagibbs closed this on Jul 5, 2017

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

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

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: 2026-05-19 06:54 UTC