refactor: Change * to & in MutableTransactionSignatureCreator #19426

pull MarcoFalke wants to merge 1 commits into bitcoin:master from MarcoFalke:2007-refactorSign changing 10 files +28 −26
  1. MarcoFalke commented at 5:30 pm on July 1, 2020: member

    The MutableTransactionSignatureCreator constructor takes in a pointer to a mutable transaction. This is problematic for several reasons:

    • It would be undefined behaviour to pass in a nullptr because for signature creation, the memory of the mutable transaction is accessed
    • No caller currently passes in a nullptr, so passing a reference as a pointer is confusing

    Fix all issues by replacing * with & in MutableTransactionSignatureCreator

  2. sipa commented at 5:34 pm on July 1, 2020: member

    IIRC this was actually intentional (and maybe even in response to a review comment); it being a pointer makes it more clear that the object will store the passed-in argument, making it less likely that someone would accidentally pass in a temporary that would not outlive the constructed object.

    Maybe this deserves the use of lifetimebound as introduced by #19387.

  3. DrahtBot added the label Refactoring on Jul 1, 2020
  4. DrahtBot added the label RPC/REST/ZMQ on Jul 1, 2020
  5. DrahtBot added the label Tests on Jul 1, 2020
  6. theuni commented at 6:32 pm on July 1, 2020: member
    The nonnull attribute could be helpful as well, if this is kept as a pointer.
  7. MarcoFalke removed the label RPC/REST/ZMQ on Jul 1, 2020
  8. MarcoFalke removed the label Tests on Jul 1, 2020
  9. practicalswift commented at 10:06 pm on July 1, 2020: contributor

    Concept ACK for making the implicit precondition (non-null mut-tx) explicit by the suggested change.

    Concept super ACK for also adding lifetime annotations as suggested by @sipa to make the currently not entirely obvious lifetime hint explicit :)

    Rationale in both cases:

    • explicit is better than implicit
    • compiler enforced is better than “try to remember”-enforced
  10. MarcoFalke marked this as a draft on Jul 1, 2020
  11. sipa commented at 1:18 am on July 2, 2020: member
    See this list of similar cases that we may want to convert if reference + lifetimebound attribute is the direction we’re going in: #19387 (comment)
  12. DrahtBot commented at 1:41 am on July 2, 2020: contributor

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #22793 (Simplify BaseSignatureChecker virtual functions and GenericTransactionSignatureChecker constructors by achow101)
    • #21702 (Implement BIP-119 Validation (CheckTemplateVerify) by JeremyRubin)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

  13. MarcoFalke force-pushed on Nov 25, 2020
  14. MarcoFalke marked this as ready for review on Nov 25, 2020
  15. MarcoFalke commented at 2:29 pm on November 25, 2020: member

    Maybe this deserves the use of lifetimebound

    thx, done

  16. MarcoFalke force-pushed on Dec 21, 2020
  17. MarcoFalke commented at 12:44 pm on December 21, 2020: member
    Rebased
  18. MarcoFalke commented at 12:45 pm on December 21, 2020: member
    Closing for now due to lack of interest
  19. MarcoFalke closed this on Dec 21, 2020

  20. MarcoFalke deleted the branch on Dec 21, 2020
  21. bitcoin locked this on Feb 15, 2022
  22. MarcoFalke restored the branch on May 4, 2022
  23. bitcoin unlocked this on May 4, 2022
  24. refactor: Change * to & in MutableTransactionSignatureCreator fac6cfc50f
  25. MarcoFalke reopened this on May 4, 2022

  26. MarcoFalke force-pushed on May 4, 2022
  27. MarcoFalke commented at 9:51 am on May 4, 2022: member
    Rebased
  28. theStack approved
  29. theStack commented at 11:59 am on May 4, 2022: contributor

    Code-review ACK fac6cfc50f65c610f2df9af3ec2efff5eade6661

    Checked that the newly introduced [[clang::lifetimebound]] attribute for the first parameter applies by compiling with clang 13.0.0 and the following patch:

     0diff --git a/src/test/txvalidationcache_tests.cpp b/src/test/txvalidationcache_tests.cpp
     1index d41b54af2..dd995a445 100644
     2--- a/src/test/txvalidationcache_tests.cpp
     3+++ b/src/test/txvalidationcache_tests.cpp
     4@@ -361,6 +361,8 @@ BOOST_FIXTURE_TEST_CASE(checkinputs_test, Dersig100Setup)
     5             UpdateInput(tx.vin[i], sigdata);
     6         }
     7
     8+        auto mtxsig = MutableTransactionSignatureCreator(CMutableTransaction(), 0, 0, SIGHASH_ALL);
     9+
    10         // This should be valid under all script flags
    11         ValidateCheckInputsForAllFlags(CTransaction(tx), 0, true, m_node.chainman->ActiveChainstate().CoinsTip());
    

    leading to the following warning:

    0  CXX      test/test_bitcoin-txvalidationcache_tests.o
    1test/txvalidationcache_tests.cpp:364:58: warning: temporary whose address is used as value of local variable 'mtxsig' will be destroyed at the end of the full-expression [-Wdangling]
    2        auto mtxsig = MutableTransactionSignatureCreator(CMutableTransaction(), 0, 0, SIGHASH_ALL);
    3                                                         ^~~~~~~~~~~~~~~~~~~~~
    41 warning generated.
    
  30. jonatack commented at 8:27 am on May 5, 2022: contributor
    ACK fac6cfc50f65c610f2df9af3ec2efff5eade6661
  31. MarcoFalke merged this on May 6, 2022
  32. MarcoFalke closed this on May 6, 2022

  33. MarcoFalke deleted the branch on May 6, 2022
  34. sidhujag referenced this in commit 072bb30765 on May 9, 2022
  35. bitcoin locked this on Jul 22, 2023

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 03:12 UTC

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