Remove unused fScriptChecks parameter from CheckInputs #13868

pull Empact wants to merge 1 commits into bitcoin:master from Empact:check-inputs-script-checks changing 2 files +91 −95
  1. Empact commented at 5:59 pm on August 3, 2018: member

    fScriptChecks = false just short-circuits the entire function, so passing it in is entirely useless.

    This is extracted from #13233 /cc TheBlueMatt.

    Recommend reviewing with git show --ignore-all-space, i.e.: https://github.com/bitcoin/bitcoin/pull/13868/files?w=1

  2. in src/validation.cpp:1398 in b161464d6e outdated
    1391@@ -1392,7 +1392,7 @@ void InitScriptExecutionCache() {
    1392  *
    1393  * Non-static (and re-declared) in src/test/txvalidationcache_tests.cpp
    1394  */
    1395-bool CheckInputs(const CTransaction& tx, CValidationState &state, const CCoinsViewCache &inputs, bool fScriptChecks, unsigned int flags, bool cacheSigStore, bool cacheFullScriptStore, PrecomputedTransactionData& txdata, std::vector<CScriptCheck> *pvChecks)
    1396+bool CheckInputs(const CTransaction& tx, CValidationState &state, const CCoinsViewCache &inputs, unsigned int flags, bool cacheSigStore, bool cacheFullScriptStore, PrecomputedTransactionData& txdata, std::vector<CScriptCheck> *pvChecks)
    1397 {
    1398     if (!tx.IsCoinBase())
    1399     {
    


    MarcoFalke commented at 6:05 pm on August 3, 2018:
    nit: since you re-indent the whole function body you might also remove this scope and put a if (tx.IsCoinBase()) return true; in the first line.
  3. Empact force-pushed on Aug 3, 2018
  4. DrahtBot commented at 7:35 pm on August 3, 2018: member

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

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #16658 ([WIP] validation: Rename CheckInputs to CheckInputScripts by jnewbery)
    • #16486 ([consensus] skip bip30 checks when assumevalid is set for the block by pstratem)
    • #13204 (Faster sigcache nonce 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.

  5. in src/validation.cpp:1382 in 1d7cc705ea outdated
    1422-            CSHA256().Write(scriptExecutionCacheNonce.begin(), 55 - sizeof(flags) - 32).Write(tx.GetWitnessHash().begin(), 32).Write((unsigned char*)&flags, sizeof(flags)).Finalize(hashCacheEntry.begin());
    1423-            AssertLockHeld(cs_main); //TODO: Remove this requirement by making CuckooCache not require external locks
    1424-            if (scriptExecutionCache.contains(hashCacheEntry, !cacheFullScriptStore)) {
    1425-                return true;
    1426-            }
    1427+    if (tx.IsCoinBase()) {
    


    promag commented at 9:03 pm on August 3, 2018:
    nit, single line?
  6. promag commented at 9:03 pm on August 3, 2018: member

    utACK 1d7cc70.

    Recommend reviewing with git show –ignore-all-space

    Also view with&w=1.

  7. fanquake added the label Refactoring on Aug 4, 2018
  8. fanquake added the label Validation on Aug 4, 2018
  9. Empact commented at 6:01 am on August 4, 2018: member
    @practicalswift @TheBlueMatt deserves the credit. :)
  10. DrahtBot added the label Needs rebase on Aug 7, 2018
  11. Empact force-pushed on Aug 7, 2018
  12. Empact commented at 3:32 pm on August 7, 2018: member
    Rebased for #13527
  13. DrahtBot removed the label Needs rebase on Aug 7, 2018
  14. DrahtBot added the label Needs rebase on Aug 25, 2018
  15. Empact force-pushed on Aug 27, 2018
  16. Empact commented at 4:54 pm on August 27, 2018: member
    Rebased for #13083
  17. DrahtBot removed the label Needs rebase on Aug 27, 2018
  18. DrahtBot added the label Needs rebase on Dec 12, 2018
  19. Empact force-pushed on Dec 12, 2018
  20. Empact commented at 10:34 pm on December 12, 2018: member
    Rebased for #14908, updated to single line coinbase check.
  21. DrahtBot removed the label Needs rebase on Dec 12, 2018
  22. jnewbery commented at 7:11 pm on February 22, 2019: member

    Concept ACK, but this removes the quite useful comment about how assume valid works:

    0        // Skip script verification when connecting blocks under the	
    1         // assumevalid block. Assuming the assumevalid block is valid this
    2        // is safe because block merkle hashes are still computed and checked,
    3        // Of course, if an assumed valid block is invalid due to false scriptSigs
    4        // this optimization would allow an invalid chain to be accepted.
    

    Perhaps you can incorporate that information after the line:

    https://github.com/bitcoin/bitcoin/blob/169dced9a42bd741b3265adee23e6a8d1f852227/src/validation.cpp#L1850

  23. DrahtBot added the label Needs rebase on Mar 2, 2019
  24. Empact force-pushed on Mar 4, 2019
  25. Empact force-pushed on Mar 4, 2019
  26. Empact commented at 9:12 am on March 4, 2019: member
    Rebased for #15118, restored & relocated the comment as suggested by John.
  27. DrahtBot removed the label Needs rebase on Mar 4, 2019
  28. jnewbery commented at 5:22 pm on March 21, 2019: member
    utACK d99bb14972bd1c3be73843b1d2ba4d367f5a528d
  29. DrahtBot added the label Needs rebase on May 4, 2019
  30. Empact force-pushed on May 17, 2019
  31. Empact commented at 3:33 am on May 17, 2019: member

    Rebased and I split the coinbase change into another commit.

    Once again: https://github.com/bitcoin/bitcoin/pull/13868/files?w=1

  32. DrahtBot removed the label Needs rebase on May 17, 2019
  33. jnewbery commented at 1:47 pm on May 17, 2019: member
    Fails tx_validationcache_tests/checkinputs_test (both on travis and locally)
  34. Empact force-pushed on May 17, 2019
  35. DrahtBot added the label Needs rebase on Aug 15, 2019
  36. Empact force-pushed on Aug 19, 2019
  37. Empact force-pushed on Aug 19, 2019
  38. Empact commented at 6:04 am on August 19, 2019: member
    Rebased, and squashed the minor coinbase change. https://github.com/bitcoin/bitcoin/pull/13868/files?w=1
  39. DrahtBot removed the label Needs rebase on Aug 19, 2019
  40. jnewbery commented at 3:05 pm on August 19, 2019: member
    utACK 5b994675ce6134f4f684c339106688b8cfa40186
  41. fanquake commented at 1:04 pm on August 23, 2019: member
    @TheBlueMatt @BugTheBlueMatt want to take a look here given it’s your change.
  42. in src/validation.cpp:1309 in 5b994675ce outdated
    1378+
    1379+    if (pvChecks) {
    1380+        pvChecks->reserve(tx.vin.size());
    1381+    }
    1382+
    1383+    // The first loop above does all the inexpensive checks.
    


    TheBlueMatt commented at 10:00 pm on August 26, 2019:
    I mean if you’re gonna fix things, also remove this comment (or move it to ATMP, where it belongs).
  43. TheBlueMatt commented at 10:01 pm on August 26, 2019: member
    Concept ACK.
  44. Remove unused fScriptChecks parameter from CheckInputs
    fScriptChecks = false just short-circuits the entire function, so
    passing it in is entirely useless.
    9b92538ade
  45. Empact force-pushed on Aug 26, 2019
  46. Empact commented at 11:39 pm on August 26, 2019: member
    @TheBlueMatt thanks for pointing that out. Comment moved to AcceptToMemoryPoolWorker.
  47. TheBlueMatt commented at 7:38 pm on August 31, 2019: member
    utACK 9b92538adebd30353ffc1a427bc20ab0c3fc75f1. Checked diff had no functional change and new comment copy looks correct.
  48. fanquake approved
  49. fanquake commented at 2:45 am on September 1, 2019: member

    ACK 9b92538adebd30353ffc1a427bc20ab0c3fc75f1 - Notes / testing below.

    CheckInputs() is called from:

    1. CheckInputsFromMempoolAndCache() - fScriptChecks was true

    2. AcceptToMemoryPoolWorker() - 3 times and fScriptChecks was always true

    3. CChainState::ConnectBlock() - fScriptChecks is true unless

      1. we have an assumeValid hash and
      2. GetBlockProofEquivalentTime() is <= 1’209’600 seconds ( 2 weeks)

    Changes to CheckInputs():

    1. Drop the fScriptChecks parameter.
    2. IsCoinBase() check is now clearer. i.e
    0if (!tx.IsCoinBase()) {
    1    // do input checking
    2}
    3return true
    

    is now:

    0if (tx.IsCoinBase()) return true;
    1// do input checking
    2return true
    
    1. Brackets around the pvChecks check.
    2. Moved the “The first loop above does..” comment to AcceptToMemoryPoolWorker.
    3. Moved “Skip script verification..” to ConnectBlock.

    Added some logging and tested:

    • Given a garbage -assumevalid=garbage hash fScriptChecks was true (early IBD).
    • Modified CheckInputs() to return false - checked that we drop into the ConnectBlock error.
    • Modified CheckInputs() to return false and ran with -assumevalid=garbage - checked that we drop into the ConnectBlock error.

    Other thought. It looks like everywhere we call CheckInputs() we are already checking prior that the tx is not a coinbase. Although I cannot see a downside to a belt-and-suspenders check inside CheckInputs(). @jnewbery can you re-review here?

  50. kallewoof commented at 3:30 am on September 1, 2019: member

    ACK 9b92538adebd30353ffc1a427bc20ab0c3fc75f1

    Verified that function does essentially nothing if the flag is false.

  51. ajtowns commented at 6:46 am on September 2, 2019: member
    ACK 9b92538adebd30353ffc1a427bc20ab0c3fc75f1 ; code review, checked tests work. Looks right to me, and fanquake’s notes make sense. Could change the coinbase early exit to assert(!tx.IsCoinBase());.
  52. fanquake commented at 7:44 am on September 2, 2019: member

    Could change the coinbase early exit to assert(!tx.IsCoinBase());

    I think that can be discussed / done in a follow up. We’ve got ACKs, so I’m merging this.

    Thanks to those of you that I harassed for review for following up. Post-merge ACKs still welcome.

  53. fanquake referenced this in commit 6519be6054 on Sep 2, 2019
  54. fanquake merged this on Sep 2, 2019
  55. fanquake closed this on Sep 2, 2019

  56. laanwj commented at 9:14 am on September 2, 2019: member
    Posthumous ACK 9b92538adebd30353ffc1a427bc20ab0c3fc75f1
  57. in src/validation.cpp:776 in 9b92538ade
    772@@ -773,15 +773,17 @@ static bool AcceptToMemoryPoolWorker(const CChainParams& chainparams, CTxMemPool
    773         constexpr unsigned int scriptVerifyFlags = STANDARD_SCRIPT_VERIFY_FLAGS;
    774 
    775         // Check against previous transactions
    776-        // This is done last to help prevent CPU exhaustion denial-of-service attacks.
    777+        // The first loop above does all the inexpensive checks.
    


    jnewbery commented at 2:45 pm on September 2, 2019:

    This is a really confusing comment here. “The first loop” refers to the checks inside CheckTxInputs() call on L566, which has been moved around since the comment was first written.

    I’ll fix this comment in a follow-up PR.


    fanquake commented at 0:18 am on September 3, 2019:
    Being addressed in #16658.
  58. jnewbery commented at 2:50 pm on September 2, 2019: member
    post-merge ACK 9b92538adebd30353ffc1a427bc20ab0c3fc75f1 with one comment nit.
  59. sidhujag referenced this in commit aa78f3d3fe on Sep 3, 2019
  60. jasonbcox referenced this in commit e980324851 on Sep 29, 2020
  61. 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: 2024-12-19 00:12 UTC

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