Delete error-prone CScript constructor only used with FindAndDelete #16128

pull instagibbs wants to merge 1 commits into bitcoin:master from instagibbs:cscript_construct changing 3 files +9 −5
  1. instagibbs commented at 2:07 PM on May 31, 2019: member

    The behavior of this constructor is not the expected behavior compared to the other constructors which directly interpret the vector as a CScript, rather than serialize it into a new CScript. It has only four uses in the entire codebase. Delete this constructor and replace its four uses with the more clear serialization construction.

  2. fanquake added the label Refactoring on May 31, 2019
  3. fanquake commented at 2:16 PM on May 31, 2019: member

    There is some related IRC discussion here (line 582).

    <instagibbs> CScript(byte_vector) vs CScript(byte_vector.begin(), byte_vector.end()) whyyyy
    <gwillen> I suspect because certain overloads didn't used to exist or something
    <instagibbs> I don't think anyone actually tries using the former?
    <instagibbs> intentionally*
    <kanzure> also, i'm still seeking topics for amsterdam meeting
    <instagibbs> just my nth time running into it, in case my annoyance is justified
    <kanzure> and also, does anyone want to take over luke-jr things and be a substitute luke-jr?
    <gwillen> instagibbs: wait I'm confused now, which of these do you consider preferable
    <gwillen> I can't tell why you'd ever want to use the longer form
    <instagibbs> gwillen, the former gives you a script with the first byte being the size of the vector, IIRC
    <instagibbs> the latter gives you what you'd expect :D
    <gwillen> oh, that seems like a horrifying bug that should be fixed
    <instagibbs> CScript is a prevectoryadayada
    <gwillen> it's not even clear to me how that would happen
    <sipa> gwillen: CScript(vector) is the same as CScript() << vector
    <sipa> it's the script that consists of pushing vector onto the stack
    <sipa> the confusion is because CScript (used to be) a subclass of vector
    <sipa> so CScript(script) would be the script that pushes script onto the stack
    <gwillen> mmm, that seems really confusing and errorprone
    <sipa> gwillen: yes
    <sipa> i've tried to touch the CScript API once and almost introduced a consensus bug
    <gwillen> ahhhhhhh, heh. I see.
    <gwillen> are those constructors ever used intentionally, do you know?
    <gwillen> (specifically the ones I would describe as ambiguous, and used directly and not via << or the like)
    <sipa> if they're actually unused we should just get rid of them
    <sipa> feel free to try and remove them, but i suspect we'd have caught them already
    <gwillen> yeah, understood, I am going to go poke around but you've made me afraid to touch it much now ;-)
    <sipa> i also don't want to imply we're forever stuck with this confusing convention; just that yoi really need to be careful about it
    <gwillen> yeah, that makes total sense and I appreciate the clarification
    
  4. fanquake commented at 6:36 PM on May 31, 2019: member

    Me and some of Travis are seeing:

      CXX      qt/libbitcoinqt_a-recentrequeststablemodel.o
      CXX      qt/libbitcoinqt_a-sendcoinsdialog.o
    qt/coincontroldialog.cpp:425:34: error: static_cast from 'std::vector<unsigned char>' to 'CScript' uses deleted function
                CTxOut txout(amount, static_cast<CScript>(std::vector<unsigned char>(24, 0)));
                                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ./script/script.h:440:14: note: candidate constructor has been explicitly deleted
        explicit CScript(const std::vector<unsigned char>& b) = delete;
                 ^
    qt/coincontroldialog.cpp:516:39: error: static_cast from 'std::vector<unsigned char>' to 'CScript' uses deleted function
                    CTxOut txout(nChange, static_cast<CScript>(std::vector<unsigned char>(24, 0)));
                                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ./script/script.h:440:14: note: candidate constructor has been explicitly deleted
        explicit CScript(const std::vector<unsigned char>& b) = delete;
                 ^
    2 errors generated.
    make[2]: *** [qt/libbitcoinqt_a-coincontroldialog.o] Error 1
    make[2]: *** Waiting for unfinished jobs....
    make[1]: *** [check-recursive] Error 1
    make: *** [check-recursive] Error 1
    
  5. Jacekdaa approved
  6. instagibbs commented at 6:41 PM on May 31, 2019: member

    @fanquake oof forgot to check QT. Will fix.

  7. instagibbs force-pushed on May 31, 2019
  8. instagibbs force-pushed on May 31, 2019
  9. instagibbs commented at 9:12 PM on May 31, 2019: member

    Fixed, all completing-in-time builds are passing.

  10. Empact commented at 5:43 AM on June 1, 2019: member

    ~Could just drop the constructor declaration, right? “= delete” is only strictly necessary to remove a default / implicitly defined constructor.~

  11. JeremyRubin commented at 5:51 AM on June 1, 2019: contributor

    I think that because it's inheriting from prevector, it's a good practice to delete it so that we don't accidentally re-gain it.

  12. instagibbs commented at 12:12 PM on June 1, 2019: member

    Exactly.

    On Sat, Jun 1, 2019, 1:54 AM Jeremy Rubin notifications@github.com wrote:

    I think that because it's inheriting from prevector, it's a good practice to delete it so that we don't accidentally re-gain it.

    — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/bitcoin/bitcoin/pull/16128?email_source=notifications&email_token=ABMAFUZGWBAN2O4QDV5QSWLPYIFIPA5CNFSM4HR3BYYKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODWWZQWI#issuecomment-497915993, or mute the thread https://github.com/notifications/unsubscribe-auth/ABMAFU2UJNXSGZA7OPLTG4LPYIFIPANCNFSM4HR3BYYA .

  13. MarcoFalke added the label Consensus on Jun 2, 2019
  14. MarcoFalke commented at 8:50 AM on June 9, 2019: member

    utACK e6915d9b0bdc1d081a8cdcd8d313de42c6b58fb3

  15. promag commented at 9:49 AM on June 9, 2019: member

    The behavior of this constructor is not the expected behavior compared to the other constructors

    Could explain what isn't expected in the OP?

    ACK e6915d9.

  16. instagibbs commented at 9:57 AM on June 9, 2019: member

    @promag attempted to do so

  17. Empact commented at 2:09 AM on June 10, 2019: member

    How about a comment to explain that the explicitly deleted constructor does not exist, and the deletion is preventative? I confirmed as much by deleting the constructor line only, and seeing that the build failed for lack of it.

  18. instagibbs commented at 4:02 PM on June 12, 2019: member

    @Empact something like:

    +    // We explicitly delete this constructor to reduce the confusion
    +    // between prevector-inhereted version and the begin/end iterator
    +    // and pointer based versions of the constructor.
    

    ?

  19. Empact commented at 4:24 PM on June 12, 2019: member

    ACK https://github.com/bitcoin/bitcoin/pull/16128/commits/e6915d9b0bdc1d081a8cdcd8d313de42c6b58fb3

    Sure, here's an alternative below. Main interest is in disavowing the implication that the constructor exists prior to deletion. I think the rest could be sussed out via blame.

      // delete non-existent constructor to defend against future introduction e.g. via prevector
    
  20. jtimon commented at 11:20 AM on June 13, 2019: contributor

    ACK e6915d9b0bdc1d081a8cdcd8d313de42c6b58fb3

  21. Delete error-prone CScript constructor e1a55690e6
  22. instagibbs force-pushed on Jun 13, 2019
  23. instagibbs commented at 1:28 PM on June 13, 2019: member

    at the risk of c-combo breaking all these ACKs, I force pushed the comment as @Empact suggested. Less future guessing by contributors :)

  24. laanwj commented at 2:46 PM on June 18, 2019: member

    As this changes consensus code I'd like some more review here @gmaxwell @sipa @sdaftuar @morcos maybe

  25. sipa commented at 7:16 AM on June 19, 2019: member

    Concept and code review ACK e1a55690e66ca962179bc8170695b92af8a3caa8, but I'd like to make sure we have tests covering the FindAndDelete usage.

  26. instagibbs commented at 12:50 PM on June 19, 2019: member

    src/test/data/tx_(in)valid.json has script evaluation based testing of FindAndDelete

  27. laanwj merged this on Jul 8, 2019
  28. laanwj closed this on Jul 8, 2019

  29. laanwj referenced this in commit c799976c86 on Jul 8, 2019
  30. laanwj commented at 6:50 PM on July 8, 2019: member

    code-review ACK e1a55690e66ca962179bc8170695b92af8a3caa8

  31. sidhujag referenced this in commit dce2caf655 on Jul 9, 2019
  32. jasonbcox referenced this in commit b1cbd1e298 on Oct 7, 2020
  33. PastaPastaPasta referenced this in commit c04f2dab73 on Jun 27, 2021
  34. PastaPastaPasta referenced this in commit 33c49b04de on Jun 28, 2021
  35. PastaPastaPasta referenced this in commit aaa16e9940 on Jun 29, 2021
  36. PastaPastaPasta referenced this in commit 4ea47e7d0b on Jul 1, 2021
  37. PastaPastaPasta referenced this in commit ef8aedde0a on Jul 1, 2021
  38. PastaPastaPasta referenced this in commit 2d26c51bc9 on Jul 12, 2021
  39. PastaPastaPasta referenced this in commit de61840a0f on Jul 13, 2021
  40. MarcoFalke locked this on Dec 16, 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-22 09:14 UTC

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