Merge #12079: Improve prioritisetransaction test coverage
[bitcoinplatinum.git] / src / bench / mempool_eviction.cpp
blobcdda0bd9be997c35aff7af2504246d0dd144a35d
1 // Copyright (c) 2011-2017 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 #include <bench/bench.h>
6 #include <policy/policy.h>
7 #include <txmempool.h>
9 #include <list>
10 #include <vector>
12 static void AddTx(const CTransaction& tx, const CAmount& nFee, CTxMemPool& pool)
14 int64_t nTime = 0;
15 unsigned int nHeight = 1;
16 bool spendsCoinbase = false;
17 unsigned int sigOpCost = 4;
18 LockPoints lp;
19 pool.addUnchecked(tx.GetHash(), CTxMemPoolEntry(
20 MakeTransactionRef(tx), nFee, nTime, nHeight,
21 spendsCoinbase, sigOpCost, lp));
24 // Right now this is only testing eviction performance in an extremely small
25 // mempool. Code needs to be written to generate a much wider variety of
26 // unique transactions for a more meaningful performance measurement.
27 static void MempoolEviction(benchmark::State& state)
29 CMutableTransaction tx1 = CMutableTransaction();
30 tx1.vin.resize(1);
31 tx1.vin[0].scriptSig = CScript() << OP_1;
32 tx1.vout.resize(1);
33 tx1.vout[0].scriptPubKey = CScript() << OP_1 << OP_EQUAL;
34 tx1.vout[0].nValue = 10 * COIN;
36 CMutableTransaction tx2 = CMutableTransaction();
37 tx2.vin.resize(1);
38 tx2.vin[0].scriptSig = CScript() << OP_2;
39 tx2.vout.resize(1);
40 tx2.vout[0].scriptPubKey = CScript() << OP_2 << OP_EQUAL;
41 tx2.vout[0].nValue = 10 * COIN;
43 CMutableTransaction tx3 = CMutableTransaction();
44 tx3.vin.resize(1);
45 tx3.vin[0].prevout = COutPoint(tx2.GetHash(), 0);
46 tx3.vin[0].scriptSig = CScript() << OP_2;
47 tx3.vout.resize(1);
48 tx3.vout[0].scriptPubKey = CScript() << OP_3 << OP_EQUAL;
49 tx3.vout[0].nValue = 10 * COIN;
51 CMutableTransaction tx4 = CMutableTransaction();
52 tx4.vin.resize(2);
53 tx4.vin[0].prevout.SetNull();
54 tx4.vin[0].scriptSig = CScript() << OP_4;
55 tx4.vin[1].prevout.SetNull();
56 tx4.vin[1].scriptSig = CScript() << OP_4;
57 tx4.vout.resize(2);
58 tx4.vout[0].scriptPubKey = CScript() << OP_4 << OP_EQUAL;
59 tx4.vout[0].nValue = 10 * COIN;
60 tx4.vout[1].scriptPubKey = CScript() << OP_4 << OP_EQUAL;
61 tx4.vout[1].nValue = 10 * COIN;
63 CMutableTransaction tx5 = CMutableTransaction();
64 tx5.vin.resize(2);
65 tx5.vin[0].prevout = COutPoint(tx4.GetHash(), 0);
66 tx5.vin[0].scriptSig = CScript() << OP_4;
67 tx5.vin[1].prevout.SetNull();
68 tx5.vin[1].scriptSig = CScript() << OP_5;
69 tx5.vout.resize(2);
70 tx5.vout[0].scriptPubKey = CScript() << OP_5 << OP_EQUAL;
71 tx5.vout[0].nValue = 10 * COIN;
72 tx5.vout[1].scriptPubKey = CScript() << OP_5 << OP_EQUAL;
73 tx5.vout[1].nValue = 10 * COIN;
75 CMutableTransaction tx6 = CMutableTransaction();
76 tx6.vin.resize(2);
77 tx6.vin[0].prevout = COutPoint(tx4.GetHash(), 1);
78 tx6.vin[0].scriptSig = CScript() << OP_4;
79 tx6.vin[1].prevout.SetNull();
80 tx6.vin[1].scriptSig = CScript() << OP_6;
81 tx6.vout.resize(2);
82 tx6.vout[0].scriptPubKey = CScript() << OP_6 << OP_EQUAL;
83 tx6.vout[0].nValue = 10 * COIN;
84 tx6.vout[1].scriptPubKey = CScript() << OP_6 << OP_EQUAL;
85 tx6.vout[1].nValue = 10 * COIN;
87 CMutableTransaction tx7 = CMutableTransaction();
88 tx7.vin.resize(2);
89 tx7.vin[0].prevout = COutPoint(tx5.GetHash(), 0);
90 tx7.vin[0].scriptSig = CScript() << OP_5;
91 tx7.vin[1].prevout = COutPoint(tx6.GetHash(), 0);
92 tx7.vin[1].scriptSig = CScript() << OP_6;
93 tx7.vout.resize(2);
94 tx7.vout[0].scriptPubKey = CScript() << OP_7 << OP_EQUAL;
95 tx7.vout[0].nValue = 10 * COIN;
96 tx7.vout[1].scriptPubKey = CScript() << OP_7 << OP_EQUAL;
97 tx7.vout[1].nValue = 10 * COIN;
99 CTxMemPool pool;
101 while (state.KeepRunning()) {
102 AddTx(tx1, 10000LL, pool);
103 AddTx(tx2, 5000LL, pool);
104 AddTx(tx3, 20000LL, pool);
105 AddTx(tx4, 7000LL, pool);
106 AddTx(tx5, 1000LL, pool);
107 AddTx(tx6, 1100LL, pool);
108 AddTx(tx7, 9000LL, pool);
109 pool.TrimToSize(pool.DynamicMemoryUsage() * 3 / 4);
110 pool.TrimToSize(GetVirtualTransactionSize(tx1));
114 BENCHMARK(MempoolEviction, 41000);