Code simplification: inline CTxInWitness inside CTxIn #8452

pull sipa wants to merge 2 commits into bitcoin:master from sipa:segwitinline changing 14 files +121 −185
  1. sipa commented at 2:23 am on August 4, 2016: member

    Based on #8451.

    This is a code change that was suggested early on, but not included in the segwit PR to not invalidate review. It turns out to be simpler than what I had expected, and actually shortens the code.

    Instead of a structure where all CTransaction’s witness data was encapsulated under CTransaction::wit, it is now inlined inside CTransaction::vin[x]. This also reduces memory usage for witness-bearing transactions (as no separate vector for all CTxInWitnesses is needed) and serialization/deserialization time as a result. For non-witness transactions with more than 1 input, it increases memory usage.

    I think it’s neat that it changes the verbose and often-repeated tx.wit.vtxinwit.size() > i ? &tx.wit.vtxinwit[i].scriptWitness : NULL pattern in VerifyScript calls to just &tx.vin[i].scriptWitness.

    This should have no effect on behaviour.

  2. Get rid of the const field in CTransaction 232529fbf1
  3. NicolasDorier commented at 2:38 am on August 4, 2016: contributor
    wow I want this one! Actually, this is the approach I am using already in NBitcoin, will test soon.
  4. dcousens commented at 2:52 am on August 4, 2016: contributor
    concept ACK
  5. sipa force-pushed on Aug 4, 2016
  6. Move CTxInWitness inside CTxIn 9f5e40d059
  7. in src/primitives/transaction.h: in bb6e238662 outdated
    298-};
    299-
    300 struct CMutableTransaction;
    301 
    302+template<typename TxType>
    303+bool HasWitness(const TxType& tx) {
    


    NicolasDorier commented at 3:18 am on August 4, 2016:
    nit: This is probably better suited as a member method of CTransaction.
  8. sipa force-pushed on Aug 4, 2016
  9. jonasschnelli added the label Refactoring on Aug 4, 2016
  10. NicolasDorier commented at 6:46 am on August 14, 2016: contributor
    utACK the commit 9f5e40d05970b6b82eb5315073c31f70cde9c0d8. I reviewed 232529fbf1af2261085e45407611c32f08d5f6f3 as well, but I don’t know enough in C++ to understand the subtleties of the change.
  11. sipa commented at 11:39 am on August 25, 2016: member
    Closing in favor of #8589. If #8580 is rejected I could reopen.
  12. sipa closed this on Aug 25, 2016

  13. 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: 2024-11-17 15:12 UTC

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