Dash Core Source Documentation (0.16.0.1)

Find detailed information regarding the Dash Core source code.

mempool_eviction.cpp
Go to the documentation of this file.
1 // Copyright (c) 2011-2015 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.
4 
5 #include <bench/bench.h>
6 #include <policy/policy.h>
7 #include <txmempool.h>
8 
9 #include <list>
10 #include <vector>
11 
12 static void AddTx(const CTransaction& tx, const CAmount& nFee, CTxMemPool& pool)
13 {
14  int64_t nTime = 0;
15  unsigned int nHeight = 1;
16  bool spendsCoinbase = false;
17  unsigned int sigOpCost = 4;
18  LockPoints lp;
20  MakeTransactionRef(tx), nFee, nTime, nHeight,
21  spendsCoinbase, sigOpCost, lp));
22 }
23 
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)
28 {
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;
35 
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;
42 
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;
50 
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;
62 
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;
74 
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;
86 
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;
98 
99  CTxMemPool pool;
100 
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);
111  }
112 }
113 
Definition: script.h:62
size_t DynamicMemoryUsage() const
Definition: txmempool.cpp:1389
std::vector< CTxIn > vin
Definition: transaction.h:293
size_t GetSerializeSize(const T &t, int nType, int nVersion=0)
Definition: serialize.h:1295
static const CAmount COIN
Definition: amount.h:14
Definition: script.h:60
Definition: script.h:61
bool KeepRunning()
Definition: bench.cpp:39
void TrimToSize(size_t sizelimit, std::vector< COutPoint > *pvNoSpendsRemaining=nullptr)
Remove transactions from the mempool until its dynamic size is <= sizelimit.
Definition: txmempool.cpp:1502
CTxMemPoolEntry stores data about the corresponding transaction, as well as data about all in-mempool...
Definition: txmempool.h:69
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
Definition: script.h:63
static CTransactionRef MakeTransactionRef()
Definition: transaction.h:346
const uint256 & GetHash() const
Definition: transaction.h:256
Definition: script.h:65
Definition: script.h:58
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: transaction.h:26
std::vector< CTxOut > vout
Definition: transaction.h:294
BENCHMARK(MempoolEviction)
static void AddTx(const CTransaction &tx, const CAmount &nFee, CTxMemPool &pool)
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Definition: txmempool.h:442
static void MempoolEviction(benchmark::State &state)
uint256 GetHash() const
Compute the hash of this CMutableTransaction.
Definition: transaction.cpp:66
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:389
static const int PROTOCOL_VERSION
network protocol versioning
Definition: version.h:14
Definition: script.h:64
A mutable version of CTransaction.
Definition: transaction.h:291
bool addUnchecked(const uint256 &hash, const CTxMemPoolEntry &entry, bool validFeeEstimate=true)
Definition: txmempool.cpp:1424
The basic transaction that is broadcasted on the network and contained in blocks. ...
Definition: transaction.h:198
Released under the MIT license