aboutsummaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2015-04-28 10:27:16 -0700
committerPieter Wuille <pieter.wuille@gmail.com>2015-07-27 15:28:43 +0200
commit17b11428c135203342aff38cabc8047e673f38ac (patch)
tree9a4634eaa35696916ead713371895bddef9acddf /src/main.cpp
parentca37e0f33980a1fe96ac4ed08fd7d692a7a592a5 (diff)
downloadbitcoin-17b11428c135203342aff38cabc8047e673f38ac.tar.xz
Cache transaction validation successes
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/main.cpp b/src/main.cpp
index fefeabeb64..7477d08b18 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1277,6 +1277,9 @@ int GetSpendHeight(const CCoinsViewCache& inputs)
return pindexPrev->nHeight + 1;
}
+static mrumap<uint256, unsigned int> cacheCheck(2 * MAX_BLOCK_SIZE / CTransaction().GetSerializeSize(SER_NETWORK, PROTOCOL_VERSION));
+static boost::mutex cs_cacheCheck;
+
namespace Consensus {
bool CheckTxInputs(const CTransaction& tx, CValidationState& state, const CCoinsViewCache& inputs, int nSpendHeight)
{
@@ -1331,6 +1334,17 @@ bool CheckInputs(const CTransaction& tx, CValidationState &state, const CCoinsVi
{
if (!tx.IsCoinBase())
{
+ if (fScriptChecks) {
+ boost::unique_lock<boost::mutex> lock(cs_cacheCheck);
+ mrumap<uint256, unsigned int>::const_iterator iter = cacheCheck.find(tx.GetHash());
+ if (iter != cacheCheck.end()) {
+ // The following test relies on the fact that all script validation flags are softforks (i.e. an extra bit set cannot cause a false result to become true).
+ if ((iter->second & flags) == flags) {
+ return true;
+ }
+ }
+ }
+
if (!Consensus::CheckTxInputs(tx, state, inputs, GetSpendHeight(inputs)))
return false;
@@ -1381,6 +1395,11 @@ bool CheckInputs(const CTransaction& tx, CValidationState &state, const CCoinsVi
}
}
+ if (cacheStore && fScriptChecks && pvChecks == NULL) {
+ boost::unique_lock<boost::mutex> lock(cs_cacheCheck);
+ cacheCheck.insert(tx.GetHash(), flags);
+ }
+
return true;
}
@@ -2101,6 +2120,13 @@ bool static ConnectTip(CValidationState &state, CBlockIndex *pindexNew, CBlock *
BOOST_FOREACH(const CTransaction &tx, pblock->vtx) {
SyncWithWallets(tx, pblock);
}
+ // Erase block's transactions from the validation cache
+ {
+ boost::unique_lock<boost::mutex> lock(cs_cacheCheck);
+ BOOST_FOREACH(const CTransaction &tx, pblock->vtx) {
+ cacheCheck.erase(tx.GetHash());
+ }
+ }
int64_t nTime6 = GetTimeMicros(); nTimePostConnect += nTime6 - nTime5; nTimeTotal += nTime6 - nTime1;
LogPrint("bench", " - Connect postprocess: %.2fms [%.2fs]\n", (nTime6 - nTime5) * 0.001, nTimePostConnect * 0.000001);