mempool size and number added to MempoolStatus

This commit is contained in:
moneroexamples 2017-06-02 10:34:27 +08:00
parent 7b4953f964
commit 3c2cc62feb
3 changed files with 19 additions and 27 deletions

View File

@ -86,6 +86,8 @@ MempoolStatus::read_mempool()
// if dont have tx_blob member, construct tx
// from json obtained from the rpc call
uint64_t mempool_size_kB {0};
for (size_t i = 0; i < mempool_tx_info.size(); ++i)
{
// get transaction info of the tx in the mempool
@ -114,12 +116,16 @@ MempoolStatus::read_mempool()
return false;
}
mempool_size_kB += _tx_info.blob_size;
local_copy_of_mempool_txs.emplace_back(tx_hash_reconstructed, _tx_info, tx);
} // if (hex_to_pod(_tx_info.id_hash, mem_tx_hash))
} // for (size_t i = 0; i < mempool_tx_info.size(); ++i)
std::lock_guard<std::mutex> lck (mempool_mutx);
// clear current mempool txs vector
@ -127,6 +133,9 @@ MempoolStatus::read_mempool()
// not very efficient but good enough for now.
mempool_txs = std::move(local_copy_of_mempool_txs);
mempool_no = local_copy_of_mempool_txs.size();
mempool_size = mempool_size_kB;
return true;
}
@ -152,5 +161,7 @@ boost::thread MempoolStatus::m_thread;
Blockchain* MempoolStatus::core_storage {nullptr};
xmreg::MicroCore* MempoolStatus::mcore {nullptr};
vector<MempoolStatus::mempool_tx> MempoolStatus::mempool_txs;
atomic<uint64_t> MempoolStatus::mempool_no {0}; // no of txs
atomic<uint64_t> MempoolStatus::mempool_size {0}; // size in bytes.
mutex MempoolStatus::mempool_mutx;
}

View File

@ -43,6 +43,9 @@ struct MempoolStatus
static atomic<bool> is_running;
static atomic<uint64_t> mempool_no; // no of txs
static atomic<uint64_t> mempool_size; // size in bytes.
static bf::path blockchain_path;
static string deamon_url;
static bool testnet;

View File

@ -897,6 +897,9 @@ namespace xmreg
std::vector<MempoolStatus::mempool_tx> mempool_txs
= MempoolStatus::get_mempool_txs();
// size of mempool in bytes
uint64_t mempool_size_bytes = MempoolStatus::mempool_size;
// initalise page tempate map with basic info about mempool
mstch::map context {
{"mempool_size" , mempool_txs.size()},
@ -1101,14 +1104,6 @@ namespace xmreg
}
// calculate mempool size using all txs in mempool.
// not only those shown on the front page
uint64_t mempool_size_bytes {0};
for (const MempoolStatus::mempool_tx& mempool_tx: mempool_txs)
{
mempool_size_bytes += mempool_tx.info.blob_size;
}
context.insert({"mempool_size_kB",
fmt::format("{:0.2f}",
@ -4867,25 +4862,8 @@ namespace xmreg
j_info["fee_per_kb"] = fee_estimated;
// // get mempool size in kB.
// std::vector<tx_info> mempool_txs;
//
// if (!rpc.get_mempool(mempool_txs))
// {
// j_response["status"] = "error";
// j_response["message"] = "Cant get mempool transactions";
// return j_response;
// }
//
// uint64_t tx_pool_size_kbytes {0};
//
// for (const tx_info& tx_i: mempool_txs)
// {
// tx_pool_size_kbytes += tx_i.blob_size;
// }
//
// j_info["tx_pool_size"] = mempool_txs.size();
// j_info["tx_pool_size_kbytes"] = tx_pool_size_kbytes;
j_info["tx_pool_size"] = MempoolStatus::mempool_no.load();
j_info["tx_pool_size_kbytes"] = MempoolStatus::mempool_size.load();
j_data = j_info;