Spent per txout #123

pull sipa wants to merge 2 commits into bitcoin:master from sipa:spentpertxout changing 2 files +208 −88
  1. sipa commented at 9:59 PM on March 17, 2011: member

    This patch changes some internal structures to keep track of spentness of each wallet transaction output separately, to support partially-spent transactions. It contains:

    • an update to the data structures (vfSpent in CWalletTx instead of fSpent)
    • a backward-compatible update to the wallet disk format (written by Satoshi, Gavin knows). Old clients reading back an updated wallet will ignore partially spent transactions when creating new ones, and may report a wrong balance, though.
    • some helper functions (CWalletTx: IsSpent, MarkSpent, MarkDirty to reset cached values, GetAvailableCredit which only counts unredeemed outputs)
    • update to SelectCoins and CreateTransaction to select source transaction outputs separately instead of per whole transaction. This fixes the issue mentioned in http://www.bitcoin.org/smf/index.php?topic=3759.0

    The reason for writing this patch: i'm also working on an import/export wallet patch, where situations with partially spent transactions become hard to avoid.

    Everything except loading a new wallet into an old client is tested on the testnet, including crafted situations with partially-spent transactions.

  2. jhyslop commented at 11:51 PM on March 20, 2011: none

    I haven't reviewed the code thoroughly, but it looks reasonable.

    In order to ease future changes to the wallet format, how about adding a key/value pair into the wallet indicating its data format version number?

  3. sipa commented at 11:59 PM on March 20, 2011: member

    That's certainly a possibility, which may be useful in the future, but it's not really necessary now. The old format used a dedicated byte for specifying spentness, while the new code uses a key-value entry (using the dedicated byte if not present) and keeps the spent-byte updated as well.

  4. sipa closed this on Mar 20, 2011

  5. sipa reopened this on Mar 20, 2011

  6. jhyslop commented at 12:15 AM on March 21, 2011: none

    Well, I mildly disagree that it's not necessary now. The time to implement versioning is now, before it's needed, so that when it is needed clients will have the version-checking code in place. But on reflection, that's what the nVersion parameter to the Serialize family of functions is for, isn't it?

  7. sipa commented at 12:53 AM on March 21, 2011: member

    Don't get me wrong - I merely mean that for this particular issue there shouldn't be a problem.

  8. gavinandresen commented at 2:06 AM on April 6, 2011: contributor

    I pulled this and ran it against a testnet-in-a-box, and there's something seriously wrong-- look at this getinfo output: { "version" : 32100, "balance" : 103514.73287496, "blocks" : 1479, "connections" : 1, "proxy" : "", "generate" : false, "genproclimit" : 3, "difficulty" : 1.00000000, "hashespersec" : 0, "testnet" : true, "keypoololdest" : 1302017341, "paytxfee" : 0.00000000, "errors" : "" }

    balance is greater than 50*blocks, which should be impossible!

    I uploaded the pre-conversion -testnet wallet and block index to: http://www.skypaint.com/bitcoin/spentpertxout.zip

  9. sipa commented at 3:21 PM on April 6, 2011: member

    Sounds like you have a lot of (used) high-value transactions whose output is yourself, but are for some reason not marked spent. I'm not sure how that is possible but I'll check the wallet in that zip file.

  10. gavinandresen commented at 8:49 PM on April 6, 2011: contributor

    FYI: Wallet is from a 3-node "testnet-in-a-box" that I ran a bunch of ClearCoin escrow unit tests against. Typical use was Sending wallet -> escrow wallet -> receiver wallet, then between tests send coins from receiver wallet back to sending wallet. Sending wallet is the one I posted.

    I haven't tried the much simpler test of just taking a testnet-in-a-box wallet and running it against your patch; that might be a good place to start (see if balance is correct to start).

  11. sipa commented at 9:35 AM on April 12, 2011: member

    I tried running a testnet-in-a-box with your wallet and block database, but everything runs fine here. Could you post your corrupted wallet/blockdb as well?

  12. gavinandresen commented at 12:43 PM on April 12, 2011: contributor

    I just tried again after cloning and compling directly from your git branch and got similar results. Bad "after" wallet is at: http://www.skypaint.com/bitcoin/spentpertxout_after.zip

    (this one is the entire datadir in a directory called 'd')

  13. gavinandresen commented at 12:44 PM on April 12, 2011: contributor

    Interesting, though: balance is different from first time I tried:

    { "version" : 32100, "balance" : 60605705932.90255737, "blocks" : 1455, "connections" : 0, "proxy" : "", "generate" : false, "genproclimit" : 3, "difficulty" : 1.00000000, "hashespersec" : 0, "testnet" : true, "keypoololdest" : 1301969525, "paytxfee" : 0.00000000, "errors" : "" }

  14. sipa commented at 5:13 PM on April 12, 2011: member

    Bug fixed - fAvailableCreditCached was not initialized, causing arbitrary reported numbers on some systems

  15. Spent per txout
    Change some internal data structures to keep track of spentness of each wallet transaction output separately, to support partially-spent transactions:
    * an update to the data structures (vfSpent in CWalletTx instead of fSpent)
    * a backward-compatible update to the wallet disk format. Old clients reading back an updated wallet will ignore partially spent transactions when creating new ones, and may report a wrong balance, though.
    * some helper functions (CWalletTx: IsSpent, MarkSpent, MarkDirty to reset cached values, GetAvailableCredit which only counts unredeemed outputs)
    335e878be8
  16. select transaction outputs separately
    Update to SelectCoins and CreateTransaction to select source transaction outputs separately instead of per whole transaction.
    aca3f961db
  17. gavinandresen merged this on Apr 12, 2011
  18. gavinandresen closed this on Apr 12, 2011

  19. glv2 referenced this in commit fd2da0e406 on Oct 12, 2014
  20. sipa referenced this in commit 94ca214e3d on Dec 18, 2014
  21. sipa referenced this in commit 855f50ab33 on Dec 23, 2014
  22. sipa referenced this in commit 7873633b57 on Jan 5, 2015
  23. dexX7 referenced this in commit f0e1600dc9 on Jul 9, 2015
  24. TheBlueMatt referenced this in commit 582b2934e6 on Oct 20, 2015
  25. dgenr8 referenced this in commit fc0dc5d262 on Mar 2, 2016
  26. laanwj referenced this in commit 6a3fe5d413 on Jun 17, 2016
  27. rebroad referenced this in commit fd178e1e63 on Dec 7, 2016
  28. deadalnix referenced this in commit e99c4c461c on Jan 19, 2017
  29. jtimon referenced this in commit e737219816 on Apr 20, 2017
  30. classesjack referenced this in commit c7f32acb5f on Jan 2, 2018
  31. attilaaf referenced this in commit 735d3ace94 on Jan 13, 2020
  32. rajarshimaitra referenced this in commit 0e3dfaf1cd on Mar 23, 2021
  33. rajarshimaitra referenced this in commit 9c1608fe55 on Aug 5, 2021
  34. DrahtBot 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-13 21:16 UTC

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