Make CWallet::FundTransaction atomic #11864

pull promag wants to merge 2 commits into bitcoin:master from promag:2017-12-atomic-fundtransaction changing 1 files +19 −18
  1. promag commented at 3:19 PM on December 11, 2017: member

    This PR fixes a race for setLockedCoins when lockUnspents is true. For instance, it should not be possible to use the same unspent in concurrent fundrawtransaction calls.

    Now the cs_main and cs_wallet locks are held during CreateTransaction and LockCoin(s). Also added some style nits around the change.

  2. promag force-pushed on Dec 11, 2017
  3. promag renamed this:
    wallet: Make fund transaction atomic
    wallet: Make FundTransaction atomic
    on Dec 11, 2017
  4. in src/wallet/wallet.cpp:2610 in 051aa180c0 outdated
    2606 | -    for (const CTxIn& txin : tx.vin)
    2607 | +    for (const CTxIn& txin : tx.vin) {
    2608 |          coinControl.Select(txin.prevout);
    2609 | +    }
    2610 | +
    2611 | +    LOCK2(cs_main, cs_wallet);
    


    ryanofsky commented at 3:44 PM on December 11, 2017:

    Would be good for a comment to explaining the lock. If I understand the PR description correctly, this is preventing concurrent fundraw transactions from spending the same outputs due to the delay between CreateTransaction and LockCoin below?


    promag commented at 3:47 PM on December 11, 2017:

    Yes, or concurrent fundrawtransaction and lockunspent. The problem may not be the delay, but when one releases the lock and the other acquires, for instance.

    I'll add the comment.


    promag commented at 7:49 AM on December 12, 2017:

    Done.


    TheBlueMatt commented at 7:03 PM on December 12, 2017:

    Can you drop cs_main from it? I don't think cs_main is required, only cs_wallet.


    promag commented at 4:16 PM on December 13, 2017:

    Won't that change the lock order? CreateTransaction locks both cs_main and cs_wallet.


    TheBlueMatt commented at 4:35 PM on December 13, 2017:

    Oops, indeed, yes, needs both.

  5. laanwj added the label Wallet on Dec 11, 2017
  6. MarcoFalke deleted a comment on Dec 13, 2017
  7. MarcoFalke deleted a comment on Dec 13, 2017
  8. ryanofsky commented at 7:05 PM on December 13, 2017: member

    utACK a3c92f4f459a385fccf13eb28f18b48009324fa5, looks good to me.

    Just to complain a little, though, the change seems pretty drowned out by reformatting. In the future I'd maybe suggest doing this in another commit.

  9. promag commented at 8:01 PM on December 13, 2017: member

    @ryanofsky actually I was thinking removing the nits. But I can do that once I push again since atm needs squash.

  10. promag renamed this:
    wallet: Make FundTransaction atomic
    Make CWallet::FundTransaction atomic
    on Dec 14, 2017
  11. [wallet] Tidy up CWallet::FundTransaction 95d4450a41
  12. [wallet] Make CWallet::FundTransaction atomic 03a5dc9c3c
  13. promag force-pushed on Dec 14, 2017
  14. promag commented at 3:22 AM on December 14, 2017: member

    @ryanofsky split in 2 commits, same patch.

  15. laanwj commented at 9:38 AM on December 14, 2017: member

    LGTM, this is definitely better as two separate commits utACK 03a5dc9

  16. laanwj merged this on Dec 14, 2017
  17. laanwj closed this on Dec 14, 2017

  18. laanwj referenced this in commit 2ae58d5bfb on Dec 14, 2017
  19. in src/wallet/wallet.cpp:2596 in 95d4450a41 outdated
    2591 | @@ -2592,18 +2592,18 @@ bool CWallet::FundTransaction(CMutableTransaction& tx, CAmount& nFeeRet, int& nC
    2592 |  {
    2593 |      std::vector<CRecipient> vecSend;
    2594 |  
    2595 | -    // Turn the txout set into a CRecipient vector
    2596 | -    for (size_t idx = 0; idx < tx.vout.size(); idx++)
    2597 | -    {
    2598 | +    // Turn the txout set into a CRecipient vector.
    2599 | +    for (size_t idx = 0; idx < tx.vout.size(); idx++) {
    


    promag commented at 9:40 AM on December 14, 2017:

    Err, ++idx..

  20. in src/wallet/wallet.cpp:2623 in 95d4450a41 outdated
    2622 |  
    2623 | -    // Copy output sizes from new transaction; they may have had the fee subtracted from them
    2624 | -    for (unsigned int idx = 0; idx < tx.vout.size(); idx++)
    2625 | +    // Copy output sizes from new transaction; they may have had the fee
    2626 | +    // subtracted from them.
    2627 | +    for (unsigned int idx = 0; idx < tx.vout.size(); idx++) {
    


    promag commented at 9:41 AM on December 14, 2017:

    Err, ++idx..

  21. PastaPastaPasta referenced this in commit 46c66f5a82 on Feb 13, 2020
  22. PastaPastaPasta referenced this in commit 82acaed5e9 on Feb 27, 2020
  23. PastaPastaPasta referenced this in commit e077cfd010 on Feb 27, 2020
  24. random-zebra referenced this in commit 32db35fb08 on Mar 11, 2021
  25. random-zebra referenced this in commit f2827ea6c5 on Mar 12, 2021
  26. random-zebra referenced this in commit 59f27ed3b5 on Mar 18, 2021
  27. random-zebra referenced this in commit 7aa3a2158a on Mar 22, 2021
  28. random-zebra referenced this in commit 284c5a7524 on Mar 25, 2021
  29. random-zebra referenced this in commit ca3cd7df5e on Mar 25, 2021
  30. random-zebra referenced this in commit 4337b0e802 on Mar 25, 2021
  31. random-zebra referenced this in commit dd660df590 on Mar 25, 2021
  32. random-zebra referenced this in commit c0f64c91de on Mar 25, 2021
  33. random-zebra referenced this in commit fcf958ff1c on Mar 26, 2021
  34. random-zebra referenced this in commit f92b17d375 on Mar 26, 2021
  35. ckti referenced this in commit 9e723549b9 on Mar 28, 2021
  36. random-zebra referenced this in commit 6479d21886 on Mar 31, 2021
  37. random-zebra referenced this in commit 3c7b524873 on Mar 31, 2021
  38. random-zebra referenced this in commit fad741a624 on Apr 5, 2021
  39. random-zebra referenced this in commit 9f31559c82 on Apr 6, 2021
  40. random-zebra referenced this in commit 286a35e590 on Apr 7, 2021
  41. 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-21 15:15 UTC

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