Skip to content

Conversation

TheBlueMatt
Copy link
Contributor

We currently calculate PrecomputedTransactionData for all transactitons that appear in blocks, but this is entirely uneccessary on the vast majority of transactions near the tip due to the script cache. Thus, we move the calculation into CheckInputs after the script cache check. I played around with a number of refactors to CheckInputs to do this a bit cleaner but it seems rather difficult to do so, so I just stuck with the obvious version

fScriptChecks = false just short-circuits the entire function, so
passing it in is entirely useless.
@@ -1343,83 +1343,72 @@ void InitScriptExecutionCache() {
*
* Non-static (and re-declared) in src/test/txvalidationcache_tests.cpp
*/
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)
bool CheckInputs(const CTransaction& tx, CValidationState &state, const CCoinsViewCache &inputs, unsigned int flags, bool cacheSigStore, bool cacheFullScriptStore, PrecomputedTransactionData& txdata, std::vector<CScriptCheck> *pvChecks)
{
if (!tx.IsCoinBase())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I also prefer early return in these cases.

Copy link
Contributor

@promag promag left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, concept ACK.

@@ -1343,83 +1343,72 @@ void InitScriptExecutionCache() {
*
* Non-static (and re-declared) in src/test/txvalidationcache_tests.cpp
*/
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)
bool CheckInputs(const CTransaction& tx, CValidationState &state, const CCoinsViewCache &inputs, unsigned int flags, bool cacheSigStore, bool cacheFullScriptStore, PrecomputedTransactionData& txdata, std::vector<CScriptCheck> *pvChecks)
{
if (!tx.IsCoinBase())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I also prefer early return in these cases.

{
// Cache is calculated only for transactions with witness
if (txTo.HasWitness()) {
if (!ready && txTo.HasWitness()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should not be possible to call ComputeHashes with different transactions right? I have verified that currently it's the case, but maybe we should prevent invalid usage?

@gmaxwell
Copy link
Contributor

No benchmarks?

fanquake added a commit that referenced this pull request Sep 2, 2019
9b92538 Remove unused fScriptChecks parameter from CheckInputs (Matt Corallo)

Pull request description:

  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

ACKs for top commit:
  TheBlueMatt:
    utACK 9b92538. Checked diff had no functional change and new comment copy looks correct.
  kallewoof:
    ACK 9b92538
  ajtowns:
    ACK 9b92538 ; 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());`.
  fanquake:
    ACK 9b92538 - Notes / testing below.

Tree-SHA512: add253a3e8cf4b33eddbc49efcec333c14b5ea61c7d34e43230351d40cff6adc919a75b91c72c4de8647a395284db74a61639f4c67848d4b2fec3a705b557790
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Sep 3, 2019
…Inputs

9b92538 Remove unused fScriptChecks parameter from CheckInputs (Matt Corallo)

Pull request description:

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

  This is extracted from bitcoin#13233 /cc TheBlueMatt.

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

ACKs for top commit:
  TheBlueMatt:
    utACK 9b92538. Checked diff had no functional change and new comment copy looks correct.
  kallewoof:
    ACK 9b92538
  ajtowns:
    ACK 9b92538 ; 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());`.
  fanquake:
    ACK 9b92538 - Notes / testing below.

Tree-SHA512: add253a3e8cf4b33eddbc49efcec333c14b5ea61c7d34e43230351d40cff6adc919a75b91c72c4de8647a395284db74a61639f4c67848d4b2fec3a705b557790
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Dec 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants