Sort pending wallet transactions before reaccepting #5511

pull dexX7 wants to merge 1 commits into bitcoin:master from dexX7:reaccept-sorted-wtx changing 1 files +14 −5
  1. dexX7 commented at 4:36 PM on December 19, 2014: contributor

    During startup, when adding pending wallet transactions, which spend outputs of other pending wallet transactions, back to the memory pool, and when they are added out of order, it appears as if they are orphans with missing inputs.

    Those transactions are then rejected and flagged as "conflicting" (= not in the memory pool, not in the block chain).

    To prevent this, transactions are explicitly sorted.

  2. gmaxwell commented at 4:39 PM on December 19, 2014: contributor

    oh erp. Yea, good find.

  3. gmaxwell commented at 6:33 PM on December 19, 2014: contributor

    I don't believe that chrnological order (really nOrderPos order in your patch) always means dependency order, however. Do you have a way to reproduce the behavior you're fixing?

  4. dexX7 commented at 7:51 AM on December 20, 2014: contributor

    I assumed that transactions are not added out of order to the wallet, because it appears as if they have to pass certain checks to be added to the wallet in the first place, and that nOrderPos reflects correct dependency order. If this is questionable, then this approach might not cover all situations.

    A simple test to check, if a client adds unconfirmed transactions back to the memory pool in correct order:

    1. Send n transactions
    2. Node should have n transactions in the mempool
    3. Shutdown and restart client
    4. Node should reaccept all transactions and have n transactions in the mempool

    As RPC test: https://gist.github.com/dexX7/06df91d1a7f99190d8d6

  5. laanwj added the label Wallet on Jan 2, 2015
  6. laanwj commented at 11:54 AM on January 29, 2015: member

    I'd say that transactions generated by the wallet itself, which are the ones useful to insert into the mempool, are always in dependency order by nOrderPos, so this makes sense.

  7. dexX7 force-pushed on Feb 11, 2015
  8. dexX7 commented at 3:42 AM on February 11, 2015: contributor

    @zander: I did not move the lock, but I believe both should work.

    I reworded the comment from "chronological order" to "based on initial wallet insertion order". Hope this is more accurate.

  9. [Wallet] sort pending wallet transactions before reaccepting
    During startup, when adding pending wallet transactions, which spend outputs of
    other pending wallet transactions, back to the memory pool, and when they are
    added out of order, it appears as if they are orphans with missing inputs.
    
    Those transactions are then rejected and flagged as "conflicting" (= not in the
    memory pool, not in the block chain).
    
    To prevent this, transactions are explicitly sorted.
    e9c3215b77
  10. dexX7 force-pushed on Mar 21, 2015
  11. dexX7 commented at 1:50 PM on March 21, 2015: contributor

    Rebased (src/wallet.cpp -> src/wallet/wallet.cpp).

    Tested with the above linked test a few hundred times, although I can't say in which case nOrderPos might actually not reflect dependency order, and the test only shows it works well under those specific test conditions. It can be used to show the current failure though: sample log output and comparison

  12. sipa commented at 12:57 PM on March 24, 2015: member

    utACK

  13. gavinandresen commented at 2:47 PM on March 24, 2015: contributor

    utACK

  14. laanwj merged this on Apr 29, 2015
  15. laanwj closed this on Apr 29, 2015

  16. laanwj referenced this in commit 23c998d811 on Apr 29, 2015
  17. willstg commented at 3:53 PM on June 13, 2015: none

    As a wallet user who has this issue and a lot of BTC in this status what can be done to get them back?

  18. dexX7 commented at 4:30 PM on June 13, 2015: contributor

    Hey @willstg,

    fortunally this is only a local issue, and your BTC are not lost.

    Please create a backup of the wallet nevertheless.

    Shutdown Bitcoin Core before continuing.

    Depending on the OS, the default wallet locations are:

    • On Unix systems: $HOME/.bitcoin/wallet.dat
    • On OS X: $HOME/Library/Application Support/Bitcoin/wallet.dat
    • On Windows: %APPDATA%/Bitcoin/wallet.dat

    To clear the conflicted transactions, start bitcoind or bitcoin-qt with the command-line option -zapwallettxes.

    Alternatively, zapwallettxes=1 can be added to the bitcoin.conf, but should be removed after the first startup.

    zapwallettxes clears the wallet transactions, and then scans the blockchain to find and add only those, which are actually in the chain (the non-conflicted ones).

    If you had a bunch of unconfirmed transactions, then it could be that not all, but only some, or maybe even none, are going to be confirmed. This depends on whether other nodes received the transactions (and ultimately the miners).

    There is also a chance that other nodes received the unconfirmed transactions, but your local client doesn't know anything about them after zapping, so please wait some time, ideally a few blocks, until you resend the transactions, which didn't go through.

  19. willstg commented at 1:47 AM on June 14, 2015: none

    Thumbs up @dexX7 thanks.

  20. random-zebra referenced this in commit 0f1764a3db on Oct 9, 2019
  21. MarcoFalke 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-04-14 18:15 UTC

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