[Wallet] Improve ReorderTransactions(..) #4697

pull cozz wants to merge 1 commits into bitcoin:master from cozz:cozz5 changing 1 files +7 −2
  1. cozz commented at 5:16 PM on August 13, 2014: contributor

    ReorderTransactions is never called, unless someone would load a very old wallet. I couldnt even trigger ReorderTransactions by experimenting with zapwallettxs. And if it gets triggered somehow, it causes problems, see #3894. The function doesnt even write back txs to disk, if they have nOrderPos == -1, looks like a bug to me.

    The worst thing that could happen, is that some txs/entries have nOrderPos = -1. But I dont see any problems with this, even if happen. At least those old transactions would always appear behind new ones.

  2. laanwj commented at 8:33 AM on August 14, 2014: member

    Not sure about this. For wallets it's extremely important to keep compatibility, even with the oldest possible ones. But if you say that multiple transactions having the same orderpos (or an orderpos<0) doesn't give problems then it may not be so important to keep ReorderTransactions around, especially if the current implementation makes it even more broken.

  3. laanwj added the label Wallet on Aug 14, 2014
  4. luke-jr commented at 8:44 AM on August 14, 2014: member

    This worked when I wrote it. Maybe there's a bug introduced by the zap wallet stuff, but that shouldn't be "fixed" by breaking compatibility with old wallets.

  5. cozz commented at 8:48 AM on August 14, 2014: contributor

    I will do some more testing and report back.

  6. laanwj commented at 8:50 AM on August 14, 2014: member

    In principle ReorderTransactions is a quite simple function. Not some Satoshi monster code that we have to get rid of asap. So my preference would go to fixing it as well.

  7. [Wallet] Improve ReorderTransactions(..) da2ede2aa6
  8. cozz renamed this:
    [Wallet] Remove ReorderTransactions(..)
    [Wallet] Improve ReorderTransactions(..)
    on Aug 14, 2014
  9. cozz commented at 2:50 PM on August 14, 2014: contributor

    Updated the title from "Remove" to "Improve" now.

    I think we should write all changes to nOrderPos back to the database. Currently txs and nOrderPosNext are not written back, only in-memory. This means that ReorderTransactions(..) is run everytime you start the wallet and have -1 ids.

    If you only had AccEntrys with -1, this could result in a bug, because they are written back with higher ids, but nOrderPosNext is not written back. If you restart now, you would start with the lower nOrderPosNext from before. Though this bug is not really a real world scenario, because someone would have txs with -1 as well. @luke-jr Could you take a look at the code changes?

  10. luke-jr commented at 2:52 PM on August 14, 2014: member

    I think that looks safe, but it's been a while... Writing nOrderPosNext should be sufficient to fix it, no?

  11. cozz commented at 3:03 PM on August 14, 2014: contributor

    Yes,

    but if we dont write the txs back, they have nOrderPos=-1 again, next time you start the wallet. Unless you trigger a wtx.WriteToDisk() somehow else, through rescan for example.

    This means that ReorderTransactions(..) is called everytime you load the wallet. But it should be a one time thing.

    I am fine with closing this pull request too, if you prefer that, as this code is 2 years old now.

  12. luke-jr commented at 3:09 PM on August 14, 2014: member

    @cozz It's okay to redo it every time: the results should be the same. :)

    But writing it back should be harmless too.

  13. cozz commented at 3:28 PM on August 14, 2014: contributor

    Closing in that case, thanks for helping here anyway.

  14. cozz closed this on Aug 14, 2014

  15. laanwj commented at 3:30 PM on August 14, 2014: member

    I don't think it makes sense to do it every time. Fixing an old wallet should be a one-time thing - after that it should behave like a new wallet.

  16. cozz commented at 3:38 PM on August 14, 2014: contributor

    Reopening in that case.

  17. cozz reopened this on Aug 14, 2014

  18. BitcoinPullTester commented at 5:48 PM on August 18, 2014: none

    Automatic sanity-testing: PASSED, see http://jenkins.bluematt.me/pull-tester/p4697_da2ede2aa68ba14e1228b61e41a5840669560eee/ for binaries and test log. This test script verifies pulls every time they are updated. It, however, dies sometimes and fails to test properly. If you are waiting on a test, please check timestamps to verify that the test.log is moving at http://jenkins.bluematt.me/pull-tester/current/ Contact BlueMatt on freenode if something looks broken.

  19. laanwj commented at 9:05 AM on September 8, 2014: member

    ACK

  20. laanwj merged this on Sep 8, 2014
  21. laanwj closed this on Sep 8, 2014

  22. laanwj referenced this in commit 297998808a on Sep 8, 2014
  23. 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-21 15:15 UTC

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