[WIP] Cache segwit signature hash components inside CTransactionRef to optimize validation performance #9709

pull sdaftuar wants to merge 7 commits into bitcoin:master from sdaftuar:2017-02-segwit-cache-3 changing 10 files +129 −56
  1. sdaftuar commented at 4:10 PM on February 7, 2017: member

    @sipa This was the alternate approach to #9700 that I came up with.

    Here I tried to create a new wrapper class around CTransaction that would hold the validation-specific information, and then made CTransactionRef refer to that wrapper. However, because blocks contain a vector of CTransactionRef's, I didn't see a way to avoid this validation-specific wrapper from being in primitives/.

    Also, the last commit here is designed to make sure that CTransactionRef remains thread-safe, by using std::call_once to calculate the segwit cache on demand. I really dislike adding synchronization primitives here but felt I needed to include something to address thread-safety concerns. However it occurred to me that the solution I tried to use in #9700 was to add a deserialization flag to control whether the cache was populated on construction, and perhaps that would be a better approach here as well? I'm open to whatever suggestions people have to make caching these hashes workable...

  2. Move PrecomputedTransactionData into transaction.h
    This is preparation for making the precomputed hashes part of the
    transaction itself.
    5445f7d02a
  3. Change CTransactionRef to contain a shared_ptr
    This is preparation for adding more (memory-only) data that will
    be attached to a transaction, but not necessarily at construction.
    200c885036
  4. Add another container around CTransaction in CTransactionRef
    This container will be used for the in-memory, extra data that we'll
    keep with each transaction.
    c95637cd24
  5. Allow PrecomputedTransactionData to be computed after construction dbe4cfe36d
  6. Move PrecomputedTransactionData inside CHashedTransaction
    We now cache the segwit hashes inside each CTransactionRef. In ConnectBlock,
    if the cache has already been populated, no re-hashing is done.
    41347d95ae
  7. Pass const PrecomputedTransactionData references around 195fff3b55
  8. Don't require callers to populate PrecomputedTransactionData 4a0e33a772
  9. sdaftuar commented at 6:17 PM on February 7, 2017: member

    Apparently travis agrees that this std::call_once thing is a bad idea!

  10. fanquake added the label Validation on Feb 8, 2017
  11. sdaftuar closed this on Mar 29, 2017

  12. 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-14 12:15 UTC

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