Add CMutableTransaction and make CTransaction immutable. #4309

pull sipa wants to merge 2 commits into bitcoin:master from sipa:nodoublehash3 changing 27 files +248 −184
  1. sipa commented at 8:34 PM on June 8, 2014: member

    This is an alternative to #4283 and #4292.

    It introduces a CMutableTransaction (which is just a struct, and only has GetHash() as utility method (which does not cache), next to CTransaction (which becomes immutable with a cached hash).

    To keep the diff small, there are implicit conversions between CMutableTransaction and CTransaction. That may lead to unexpected low performance perhaps, but CMutableTransaction is only ever used in places that don't require performance (block building, wallet, tests); in particular, note that there is no CMutableTransaction anywhere in main.

  2. sipa commented at 9:29 PM on June 8, 2014: member

    Ping @pstratem.

  3. pstratem commented at 11:38 PM on June 8, 2014: contributor

    This effectively reduces duplicate calls to CTransaction::GetHash() to zero.

    There are a few duplicates but I believe those to be the coinbase transactions which are actually identical.

    I have not reviewed for correctness.

  4. pstratem commented at 11:43 PM on June 8, 2014: contributor

    Actually those appear to be something to do with the genesis block.

    Either way it's a trivial number of duplicate calls.

  5. sipa commented at 8:04 AM on June 9, 2014: member

    Added a commit that removes all function arguments that were hashes of a CTransaction that is already passed, resulting in simpler code in many places.

  6. laanwj commented at 8:09 AM on June 9, 2014: member

    Very nice!

  7. gavinandresen commented at 2:15 PM on June 9, 2014: contributor

    Spiffy! I like it! Untested ACK

  8. sipa commented at 11:23 AM on June 12, 2014: member

    @pstratem What were your benchmark results? I remember something like 17% faster reindex to block 180k or so?

  9. pstratem commented at 2:29 AM on June 14, 2014: contributor

    @sipa benchmarks show a ~15% faster reindex to block 150k

  10. laanwj commented at 3:49 PM on June 21, 2014: member

    I've been testing this on my nodes for ~2 weeks with no problems.

  11. petertodd commented at 4:34 PM on June 21, 2014: contributor

    ACK

    Code reviewed and some testing.

  12. gmaxwell commented at 8:43 PM on June 21, 2014: contributor

    ACK.

  13. Add CMutableTransaction and make CTransaction immutable.
    In addition, introduce a cached hash inside CTransaction, to prevent
    recalculating it over and over again.
    4949004d68
  14. Code simplifications after CTransaction::GetHash() caching d38da59bf6
  15. sipa commented at 12:18 AM on June 22, 2014: member

    @gavinandresen Can you make some space for pulltester?

  16. BitcoinPullTester commented at 6:36 PM on June 22, 2014: none

    Automatic sanity-testing: PASSED, see http://jenkins.bluematt.me/pull-tester/p4309_d38da59bf68fbb37535e2579bfb7355a16baed0e/ 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.

  17. sipa merged this on Jun 22, 2014
  18. sipa closed this on Jun 22, 2014

  19. sipa referenced this in commit d4e4e05435 on Jun 22, 2014
  20. jgarzik commented at 2:44 AM on June 24, 2014: contributor

    This change seems unnecessary? As a grep of all CMutableTransaction uses helpfully highlights, there is never a case where a TX is accessed in parallel or stored in a parallel-access container while also being mutated.

    As such, you may apply the common "I'm done mutating this data structure, update cached data" pattern without needing a new class.

    ETA: I'm posting this on a closed issue because I'm updating the bitcoin-tx code for this change :)

     - CTransaction tx;
     - DecodeHexTx(tx, strHexTx);
     + CTransaction txDecodeTmp;
     + DecodeHexTx(txDecodeTmp, strHexTx);
     + CMutableTransaction tx(txDecodeTmp);
    
  21. wtogami referenced this in commit 3f6df7aa07 on Sep 10, 2014
  22. wtogami referenced this in commit 258b1dcf54 on Sep 11, 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-19 09:15 UTC

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