-
Notifications
You must be signed in to change notification settings - Fork 37.8k
Skip PrecomputedTransactionData hashing for cache hits. #13233
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Skip PrecomputedTransactionData hashing for cache hits. #13233
Conversation
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()) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this 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()) |
There was a problem hiding this comment.
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()) { |
There was a problem hiding this comment.
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?
No benchmarks? |
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
…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
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