Skip to content

Commit eddaba7

Browse files
committed
Revert "Cache transaction validation successes"
This reverts commit 17b1142.
1 parent 1369d69 commit eddaba7

File tree

3 files changed

+0
-150
lines changed

3 files changed

+0
-150
lines changed

src/main.cpp

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,9 +1277,6 @@ int GetSpendHeight(const CCoinsViewCache& inputs)
12771277
return pindexPrev->nHeight + 1;
12781278
}
12791279

1280-
static mrumap<uint256, unsigned int> cacheCheck(2 * MAX_BLOCK_SIZE / CTransaction().GetSerializeSize(SER_NETWORK, PROTOCOL_VERSION));
1281-
static boost::mutex cs_cacheCheck;
1282-
12831280
namespace Consensus {
12841281
bool CheckTxInputs(const CTransaction& tx, CValidationState& state, const CCoinsViewCache& inputs, int nSpendHeight)
12851282
{
@@ -1334,17 +1331,6 @@ bool CheckInputs(const CTransaction& tx, CValidationState &state, const CCoinsVi
13341331
{
13351332
if (!tx.IsCoinBase())
13361333
{
1337-
if (fScriptChecks) {
1338-
boost::unique_lock<boost::mutex> lock(cs_cacheCheck);
1339-
mrumap<uint256, unsigned int>::const_iterator iter = cacheCheck.find(tx.GetHash());
1340-
if (iter != cacheCheck.end()) {
1341-
// 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).
1342-
if ((iter->second & flags) == flags) {
1343-
return true;
1344-
}
1345-
}
1346-
}
1347-
13481334
if (!Consensus::CheckTxInputs(tx, state, inputs, GetSpendHeight(inputs)))
13491335
return false;
13501336

@@ -1395,11 +1381,6 @@ bool CheckInputs(const CTransaction& tx, CValidationState &state, const CCoinsVi
13951381
}
13961382
}
13971383

1398-
if (cacheStore && fScriptChecks && pvChecks == NULL) {
1399-
boost::unique_lock<boost::mutex> lock(cs_cacheCheck);
1400-
cacheCheck.insert(tx.GetHash(), flags);
1401-
}
1402-
14031384
return true;
14041385
}
14051386

@@ -2120,13 +2101,6 @@ bool static ConnectTip(CValidationState &state, CBlockIndex *pindexNew, CBlock *
21202101
BOOST_FOREACH(const CTransaction &tx, pblock->vtx) {
21212102
SyncWithWallets(tx, pblock);
21222103
}
2123-
// Erase block's transactions from the validation cache
2124-
{
2125-
boost::unique_lock<boost::mutex> lock(cs_cacheCheck);
2126-
BOOST_FOREACH(const CTransaction &tx, pblock->vtx) {
2127-
cacheCheck.erase(tx.GetHash());
2128-
}
2129-
}
21302104

21312105
int64_t nTime6 = GetTimeMicros(); nTimePostConnect += nTime6 - nTime5; nTimeTotal += nTime6 - nTime1;
21322106
LogPrint("bench", " - Connect postprocess: %.2fms [%.2fs]\n", (nTime6 - nTime5) * 0.001, nTimePostConnect * 0.000001);

src/mruset.h

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@
99
#include <vector>
1010
#include <utility>
1111

12-
#include <boost/multi_index_container.hpp>
13-
#include <boost/multi_index/ordered_index.hpp>
14-
#include <boost/multi_index/sequenced_index.hpp>
15-
1612
/** STL-like set container that only keeps the most recent N elements. */
1713
template <typename T>
1814
class mruset
@@ -66,60 +62,4 @@ class mruset
6662
size_type max_size() const { return nMaxSize; }
6763
};
6864

69-
/** STL-like map container that only keeps the most recent N elements. */
70-
template <typename K, typename V>
71-
class mrumap
72-
{
73-
private:
74-
struct key_extractor {
75-
typedef K result_type;
76-
const result_type& operator()(const std::pair<K, V>& e) const { return e.first; }
77-
result_type& operator()(std::pair<K, V>* e) const { return e->first; }
78-
};
79-
80-
typedef boost::multi_index_container<
81-
std::pair<K, V>,
82-
boost::multi_index::indexed_by<
83-
boost::multi_index::sequenced<>,
84-
boost::multi_index::ordered_unique<key_extractor>
85-
>
86-
> map_type;
87-
88-
public:
89-
typedef K key_type;
90-
typedef std::pair<K, V> value_type;
91-
typedef typename map_type::iterator iterator;
92-
typedef typename map_type::const_iterator const_iterator;
93-
typedef typename map_type::size_type size_type;
94-
95-
protected:
96-
map_type m_;
97-
size_type max_size_;
98-
99-
public:
100-
mrumap(size_type max_size_in = 1) { clear(max_size_in); }
101-
iterator begin() { return m_.begin(); }
102-
iterator end() { return m_.end(); }
103-
const_iterator begin() const { return m_.begin(); }
104-
const_iterator end() const { return m_.end(); }
105-
size_type size() const { return m_.size(); }
106-
bool empty() const { return m_.empty(); }
107-
iterator find(const key_type& key) { return m_.template project<0>(boost::get<1>(m_).find(key)); }
108-
const_iterator find(const key_type& key) const { return m_.template project<0>(boost::get<1>(m_).find(key)); }
109-
size_type count(const key_type& key) const { return boost::get<1>(m_).count(key); }
110-
void clear(size_type max_size_in) { m_.clear(); max_size_ = max_size_in; }
111-
std::pair<iterator, bool> insert(const K& key, const V& value)
112-
{
113-
std::pair<K, V> elem(key, value);
114-
std::pair<iterator, bool> p = m_.push_front(elem);
115-
if (p.second && m_.size() > max_size_) {
116-
m_.pop_back();
117-
}
118-
return p;
119-
}
120-
void erase(iterator it) { m_.erase(it); }
121-
void erase(const key_type& k) { boost::get<1>(m_).erase(k); }
122-
size_type max_size() const { return max_size_; }
123-
};
124-
12565
#endif // BITCOIN_MRUSET_H

src/test/mruset_tests.cpp

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -78,68 +78,4 @@ BOOST_AUTO_TEST_CASE(mruset_test)
7878
}
7979
}
8080

81-
BOOST_AUTO_TEST_CASE(mrumap_test)
82-
{
83-
// The mrumap being tested.
84-
mrumap<int, char> mru(5000);
85-
86-
// Run the test 10 times.
87-
for (int test = 0; test < 10; test++) {
88-
// Reset mru.
89-
mru.clear(5000);
90-
91-
// A deque + set to simulate the mruset.
92-
std::deque<int> rep;
93-
std::map<int, char> all;
94-
95-
// Insert 10000 random integers below 15000.
96-
for (int j=0; j<10000; j++) {
97-
int add = GetRandInt(15000);
98-
char val = (char)GetRandInt(256);
99-
mru.insert(add, val);
100-
101-
// Add the number to rep/all as well.
102-
if (all.count(add) == 0) {
103-
all.insert(std::make_pair<int, char>(add, val));
104-
rep.push_back(add);
105-
if (all.size() == 5001) {
106-
all.erase(rep.front());
107-
rep.pop_front();
108-
}
109-
}
110-
111-
if (GetRandInt(5) == 0) {
112-
// With 20% chance: remove an item
113-
int pos = GetRandInt(rep.size());
114-
std::deque<int>::iterator it = rep.begin();
115-
while (pos--) { it++; }
116-
int delval = *it;
117-
mru.erase(delval);
118-
all.erase(delval);
119-
rep.erase(it);
120-
}
121-
122-
// Do a full comparison between mru and the simulated mru every 1000 and every 5001 elements.
123-
if (j % 1000 == 0 || j % 5001 == 0) {
124-
// Check that all elements that should be in there, are in there.
125-
BOOST_FOREACH(int x, rep) {
126-
BOOST_CHECK(mru.count(x));
127-
BOOST_CHECK(mru.find(x)->second == all[x]);
128-
}
129-
130-
// Check that all elements that are in there, should be in there.
131-
for (mrumap<int, char>::iterator it = mru.begin(); it != mru.end(); it++) {
132-
BOOST_CHECK(all.count(it->first));
133-
BOOST_CHECK(all[it->first] == it->second);
134-
}
135-
136-
for (int t = 0; t < 10; t++) {
137-
int r = GetRandInt(15000);
138-
BOOST_CHECK(all.count(r) == mru.count(r));
139-
}
140-
}
141-
}
142-
}
143-
}
144-
14581
BOOST_AUTO_TEST_SUITE_END()

0 commit comments

Comments
 (0)