Cache transaction validation successes

Conflicts:
	src/main.cpp
	src/test/test_bitcoin.cpp

Github-Pull: #6077
Rebased-From: 17b11428c135203342aff38cabc8047e673f38ac 517e6dd25618522c716e64859554b0f29c6e65d0
This commit is contained in:
Pieter Wuille
2015-04-28 10:27:16 -07:00
committed by Wladimir J. van der Laan
parent 92401c2d90
commit bc484ef8db
8 changed files with 331 additions and 6 deletions

View File

@@ -1397,10 +1397,24 @@ bool CScriptCheck::operator()() {
return true;
}
static mrumap<uint256, unsigned int> cacheCheck(2 * MAX_BLOCK_SIZE / CTransaction().GetSerializeSize(SER_NETWORK, PROTOCOL_VERSION));
static boost::mutex cs_cacheCheck;
bool CheckInputs(const CTransaction& tx, CValidationState &state, const CCoinsViewCache &inputs, bool fScriptChecks, unsigned int flags, bool cacheStore, std::vector<CScriptCheck> *pvChecks)
{
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 (pvChecks)
pvChecks->reserve(tx.vin.size());
@@ -1496,6 +1510,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;
}
@@ -2210,6 +2229,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);