mirror of
https://github.com/dashpay/dash.git
synced 2024-12-26 04:22:55 +01:00
Merge pull request #4638
6f2c26a
Closely track mempool byte total. Add "getmempoolinfo" RPC. (Jeff Garzik)
This commit is contained in:
commit
984ff68c67
@ -531,3 +531,27 @@ Value getchaintips(const Array& params, bool fHelp)
|
|||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Value getmempoolinfo(const Array& params, bool fHelp)
|
||||||
|
{
|
||||||
|
if (fHelp || params.size() != 0)
|
||||||
|
throw runtime_error(
|
||||||
|
"getmempoolinfo\n"
|
||||||
|
"\nReturns details on the active state of the TX memory pool.\n"
|
||||||
|
"\nResult:\n"
|
||||||
|
"{\n"
|
||||||
|
" \"size\": xxxxx (numeric) Current tx count\n"
|
||||||
|
" \"bytes\": xxxxx (numeric) Sum of all tx sizes\n"
|
||||||
|
"}\n"
|
||||||
|
"\nExamples:\n"
|
||||||
|
+ HelpExampleCli("getmempoolinfo", "")
|
||||||
|
+ HelpExampleRpc("getmempoolinfo", "")
|
||||||
|
);
|
||||||
|
|
||||||
|
Object ret;
|
||||||
|
ret.push_back(Pair("size", (int64_t) mempool.size()));
|
||||||
|
ret.push_back(Pair("bytes", (int64_t) mempool.GetTotalTxSize()));
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -256,6 +256,7 @@ static const CRPCCommand vRPCCommands[] =
|
|||||||
{ "blockchain", "getblockhash", &getblockhash, true, false, false },
|
{ "blockchain", "getblockhash", &getblockhash, true, false, false },
|
||||||
{ "blockchain", "getchaintips", &getchaintips, true, false, false },
|
{ "blockchain", "getchaintips", &getchaintips, true, false, false },
|
||||||
{ "blockchain", "getdifficulty", &getdifficulty, true, false, false },
|
{ "blockchain", "getdifficulty", &getdifficulty, true, false, false },
|
||||||
|
{ "blockchain", "getmempoolinfo", &getmempoolinfo, true, true, false },
|
||||||
{ "blockchain", "getrawmempool", &getrawmempool, true, false, false },
|
{ "blockchain", "getrawmempool", &getrawmempool, true, false, false },
|
||||||
{ "blockchain", "gettxout", &gettxout, true, false, false },
|
{ "blockchain", "gettxout", &gettxout, true, false, false },
|
||||||
{ "blockchain", "gettxoutsetinfo", &gettxoutsetinfo, true, false, false },
|
{ "blockchain", "gettxoutsetinfo", &gettxoutsetinfo, true, false, false },
|
||||||
|
@ -200,6 +200,7 @@ extern json_spirit::Value getblockcount(const json_spirit::Array& params, bool f
|
|||||||
extern json_spirit::Value getbestblockhash(const json_spirit::Array& params, bool fHelp);
|
extern json_spirit::Value getbestblockhash(const json_spirit::Array& params, bool fHelp);
|
||||||
extern json_spirit::Value getdifficulty(const json_spirit::Array& params, bool fHelp);
|
extern json_spirit::Value getdifficulty(const json_spirit::Array& params, bool fHelp);
|
||||||
extern json_spirit::Value settxfee(const json_spirit::Array& params, bool fHelp);
|
extern json_spirit::Value settxfee(const json_spirit::Array& params, bool fHelp);
|
||||||
|
extern json_spirit::Value getmempoolinfo(const json_spirit::Array& params, bool fHelp);
|
||||||
extern json_spirit::Value getrawmempool(const json_spirit::Array& params, bool fHelp);
|
extern json_spirit::Value getrawmempool(const json_spirit::Array& params, bool fHelp);
|
||||||
extern json_spirit::Value getblockhash(const json_spirit::Array& params, bool fHelp);
|
extern json_spirit::Value getblockhash(const json_spirit::Array& params, bool fHelp);
|
||||||
extern json_spirit::Value getblock(const json_spirit::Array& params, bool fHelp);
|
extern json_spirit::Value getblock(const json_spirit::Array& params, bool fHelp);
|
||||||
|
@ -402,6 +402,7 @@ bool CTxMemPool::addUnchecked(const uint256& hash, const CTxMemPoolEntry &entry)
|
|||||||
for (unsigned int i = 0; i < tx.vin.size(); i++)
|
for (unsigned int i = 0; i < tx.vin.size(); i++)
|
||||||
mapNextTx[tx.vin[i].prevout] = CInPoint(&tx, i);
|
mapNextTx[tx.vin[i].prevout] = CInPoint(&tx, i);
|
||||||
nTransactionsUpdated++;
|
nTransactionsUpdated++;
|
||||||
|
totalTxSize += entry.GetTxSize();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -426,6 +427,8 @@ void CTxMemPool::remove(const CTransaction &tx, std::list<CTransaction>& removed
|
|||||||
removed.push_front(tx);
|
removed.push_front(tx);
|
||||||
BOOST_FOREACH(const CTxIn& txin, tx.vin)
|
BOOST_FOREACH(const CTxIn& txin, tx.vin)
|
||||||
mapNextTx.erase(txin.prevout);
|
mapNextTx.erase(txin.prevout);
|
||||||
|
|
||||||
|
totalTxSize -= mapTx[hash].GetTxSize();
|
||||||
mapTx.erase(hash);
|
mapTx.erase(hash);
|
||||||
nTransactionsUpdated++;
|
nTransactionsUpdated++;
|
||||||
}
|
}
|
||||||
@ -477,6 +480,7 @@ void CTxMemPool::clear()
|
|||||||
LOCK(cs);
|
LOCK(cs);
|
||||||
mapTx.clear();
|
mapTx.clear();
|
||||||
mapNextTx.clear();
|
mapNextTx.clear();
|
||||||
|
totalTxSize = 0;
|
||||||
++nTransactionsUpdated;
|
++nTransactionsUpdated;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -487,9 +491,12 @@ void CTxMemPool::check(CCoinsViewCache *pcoins) const
|
|||||||
|
|
||||||
LogPrint("mempool", "Checking mempool with %u transactions and %u inputs\n", (unsigned int)mapTx.size(), (unsigned int)mapNextTx.size());
|
LogPrint("mempool", "Checking mempool with %u transactions and %u inputs\n", (unsigned int)mapTx.size(), (unsigned int)mapNextTx.size());
|
||||||
|
|
||||||
|
uint64_t checkTotal = 0;
|
||||||
|
|
||||||
LOCK(cs);
|
LOCK(cs);
|
||||||
for (std::map<uint256, CTxMemPoolEntry>::const_iterator it = mapTx.begin(); it != mapTx.end(); it++) {
|
for (std::map<uint256, CTxMemPoolEntry>::const_iterator it = mapTx.begin(); it != mapTx.end(); it++) {
|
||||||
unsigned int i = 0;
|
unsigned int i = 0;
|
||||||
|
checkTotal += it->second.GetTxSize();
|
||||||
const CTransaction& tx = it->second.GetTx();
|
const CTransaction& tx = it->second.GetTx();
|
||||||
BOOST_FOREACH(const CTxIn &txin, tx.vin) {
|
BOOST_FOREACH(const CTxIn &txin, tx.vin) {
|
||||||
// Check that every mempool transaction's inputs refer to available coins, or other mempool tx's.
|
// Check that every mempool transaction's inputs refer to available coins, or other mempool tx's.
|
||||||
@ -518,6 +525,8 @@ void CTxMemPool::check(CCoinsViewCache *pcoins) const
|
|||||||
assert(tx.vin.size() > it->second.n);
|
assert(tx.vin.size() > it->second.n);
|
||||||
assert(it->first == it->second.ptx->vin[it->second.n].prevout);
|
assert(it->first == it->second.ptx->vin[it->second.n].prevout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assert(totalTxSize == checkTotal);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CTxMemPool::queryHashes(vector<uint256>& vtxid)
|
void CTxMemPool::queryHashes(vector<uint256>& vtxid)
|
||||||
|
@ -68,6 +68,7 @@ private:
|
|||||||
CMinerPolicyEstimator* minerPolicyEstimator;
|
CMinerPolicyEstimator* minerPolicyEstimator;
|
||||||
|
|
||||||
CFeeRate minRelayFee; // Passed to constructor to avoid dependency on main
|
CFeeRate minRelayFee; // Passed to constructor to avoid dependency on main
|
||||||
|
uint64_t totalTxSize; // sum of all mempool tx' byte sizes
|
||||||
|
|
||||||
public:
|
public:
|
||||||
mutable CCriticalSection cs;
|
mutable CCriticalSection cs;
|
||||||
@ -108,6 +109,11 @@ public:
|
|||||||
LOCK(cs);
|
LOCK(cs);
|
||||||
return mapTx.size();
|
return mapTx.size();
|
||||||
}
|
}
|
||||||
|
uint64_t GetTotalTxSize()
|
||||||
|
{
|
||||||
|
LOCK(cs);
|
||||||
|
return totalTxSize;
|
||||||
|
}
|
||||||
|
|
||||||
bool exists(uint256 hash)
|
bool exists(uint256 hash)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user