WIP: Make CScript addition concatenative #18613

pull JeremyRubin wants to merge 1 commits into bitcoin:master from JeremyRubin:fix-testing-cscript changing 1 files +5 −3
  1. JeremyRubin commented at 11:10 PM on April 12, 2020: contributor

    This has come up in some testing related stuff I've been working on... Opening as a WIP because a lot of stuff fails as a result and trying to decide if it's worth fixing or if I should ignore it...

    Currently:

    CScript(["hello", "world"]) != CScript(["hello"]) + CScript(["world"])
    
    CScript(["hello"]) + CScript(["world"]) == CScript(["hello", "\x06\x05world") == CScript(["hello", CScript(["world"]))
    

    It doesn't seem like there's a way to reach CScript(["hello", "world"]) other than by chaining the iterators together, which is clunky.

    This patch redefines addition of scripts such that:

    CScript(["hello", "world"]) == CScript(["hello"]) + CScript(["world"])
    
    CScript(["hello"]) + CScript(["world"]) != (CScript(["hello", "\x06\x05world") == CScript(["hello", CScript(["world"])))
    

    Note that adding a raw bytes to a CScript preserves the old behavior, e.g., CScript(["hello"]) + "world" == CScript(["hello", "world"]).

    An alternative to this is to get rid of the nested parameter to __coerce_instance and always leave CScript as concatenative -- e.g., CScript([a,CScript([b])]) == CScript([a,b]) == CScript([a]) + CScript([a,b]) and you have to coerce to bytes first to get a push. This breaks fewer tests, but seems a bit more subtle?

  2. Make CScript addition concatenative, rather than pushing the script as bytes 5922d17b3e
  3. MarcoFalke commented at 11:27 PM on April 12, 2020: member

    Tests should be easy to write, and easy to read. Why can't this nonsensical operator on scripts be marked deleted in favour of self-documenting ones like def push_data(self, vch), def push_opcode(self, op) or so? This way, script operations are easier to follow, but byte operations are not ruled out because (if needed) they can still be done by casting to bytes first.

  4. DrahtBot added the label Tests on Apr 13, 2020
  5. JeremyRubin commented at 1:04 AM on April 13, 2020: contributor

    I'm open to whatever, I just think this is a bit too much non WYSIWYG of an idiom so happy for any replacement.

  6. MarcoFalke commented at 1:12 AM on April 13, 2020: member

    I've replaced the implementation with raise NotImplementedError and only one test fails. So instead of changing the implementation and having reviewers go through that painful review, with the goal of keeping it around long term, doesn't seem ideal to me. I think it can be replaced by something simpler in the one test that uses it and then ditched once and for all.

  7. chanhosuh commented at 4:00 AM on April 13, 2020: none

    For future reference, @MarcoFalke is referring to the line

    tx1b.vout = [CTxOut(1 * COIN, DUMMY_P2WPKH_SCRIPT + b'a')]
    

    in test_simple_doublespend of test/functional/feature_rbf.py.

    So I guess this can be replaced by a "pushdata" method, e.g. DUMMY_P2WPKH_SCRIPT.push_data(b'a') ?

    Or better, since I think it would be natural to assume push_data mutates:

    too_long_script = DUMMY_P2WPKH_SCRIPT.copy()
    too_long_script.push_data(b'a')
    
  8. DrahtBot commented at 8:45 PM on April 22, 2020: member

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #18732 (test: Remove unused, undocumented and misleading CScript.add by MarcoFalke)

    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.

  9. JeremyRubin commented at 8:54 PM on November 10, 2021: contributor

    closing since #18612 and #18732 got merged

  10. JeremyRubin closed this on Nov 10, 2021

  11. DrahtBot locked this on Nov 10, 2022

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

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