aboutsummaryrefslogtreecommitdiff
path: root/src/validation.h
diff options
context:
space:
mode:
authorMatt Corallo <git@bluematt.me>2017-04-11 16:46:39 -0400
committerMatt Corallo <git@bluematt.me>2017-06-07 11:02:36 -0400
commitb5fea8d0ccc8117644a4ea11256bc531b60fd9a3 (patch)
treefc7c8e2b82d0d7f3651fd1ddc314e36dc0f731bf /src/validation.h
parent6d22b2b17b7852bb3dc32dbbbf2f5dff4fb98648 (diff)
downloadbitcoin-b5fea8d0ccc8117644a4ea11256bc531b60fd9a3.tar.xz
Cache full script execution results in addition to signatures
This adds a new CuckooCache in validation, caching whether all of a transaction's scripts were valid with a given set of script flags. Unlike previous attempts at caching an entire transaction's validity, which have nearly universally introduced consensus failures, this only caches the validity of a transaction's scriptSigs. As these are pure functions of the transaction and data it commits to, this should be much safer. This is somewhat duplicative with the sigcache, as entries in the new cache will also have several entries in the sigcache. However, the sigcache is kept both as ATMP relies on it and because it prevents malleability-based DoS attacks on the new higher-level cache. Instead, the -sigcachesize option is re-used - cutting the sigcache size in half and using the newly freed memory for the script execution cache. Transactions which match the script execution cache never even have entries in the script check thread's workqueue created. Note that the cache is indexed only on the script execution flags and the transaction's witness hash. While this is sufficient to make the CScriptCheck() calls pure functions, this introduces dependancies on the mempool calculating things such as the PrecomputedTransactionData object, filling the CCoinsViewCache, etc in the exact same way as ConnectBlock. I belive this is a reasonable assumption, but should be noted carefully. In a rather naive benchmark (reindex-chainstate up to block 284k with cuckoocache always returning true for contains(), -assumevalid=0 and a very large dbcache), this connected blocks ~1.7x faster.
Diffstat (limited to 'src/validation.h')
-rw-r--r--src/validation.h3
1 files changed, 3 insertions, 0 deletions
diff --git a/src/validation.h b/src/validation.h
index 3a7f7cf1bc..d097343126 100644
--- a/src/validation.h
+++ b/src/validation.h
@@ -394,6 +394,9 @@ public:
ScriptError GetScriptError() const { return error; }
};
+/** Initializes the script-execution cache */
+void InitScriptExecutionCache();
+
/** Functions for disk access for blocks */
bool ReadBlockFromDisk(CBlock& block, const CDiskBlockPos& pos, const Consensus::Params& consensusParams);