diff options
author | Riccardo Spagni <ric@spagni.net> | 2017-08-26 23:33:40 +0200 |
---|---|---|
committer | Riccardo Spagni <ric@spagni.net> | 2017-08-26 23:33:40 +0200 |
commit | 8ee10e707baf19d127159b72c43db81d8f009a00 (patch) | |
tree | a268488cc37674da8160705ebc6bfcd34bb96958 | |
parent | Merge pull request #2350 (diff) | |
parent | blockchain: cap memory size of retrieved blocks (diff) | |
download | monero-8ee10e707baf19d127159b72c43db81d8f009a00.tar.xz |
Merge pull request #2352
2d8a6a6f blockchain: cap memory size of retrieved blocks (moneromooo-monero)
20bedf32 rpc: decrease memory usage a bit in getblocks.bin (moneromooo-monero)
-rw-r--r-- | src/cryptonote_core/blockchain.cpp | 9 | ||||
-rw-r--r-- | src/rpc/core_rpc_server.cpp | 11 |
2 files changed, 14 insertions, 6 deletions
diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp index e00908125..7ecdae48c 100644 --- a/src/cryptonote_core/blockchain.cpp +++ b/src/cryptonote_core/blockchain.cpp @@ -59,6 +59,8 @@ #undef MONERO_DEFAULT_LOG_CATEGORY #define MONERO_DEFAULT_LOG_CATEGORY "blockchain" +#define FIND_BLOCKCHAIN_SUPPLEMENT_MAX_SIZE (100*1024*1024) // 100 MB + //#include "serialization/json_archive.h" /* TODO: @@ -2075,8 +2077,8 @@ bool Blockchain::find_blockchain_supplement(const uint64_t req_start_block, cons m_db->block_txn_start(true); total_height = get_current_blockchain_height(); - size_t count = 0; - for(size_t i = start_height; i < total_height && count < max_count; i++, count++) + size_t count = 0, size = 0; + for(size_t i = start_height; i < total_height && count < max_count && (size < FIND_BLOCKCHAIN_SUPPLEMENT_MAX_SIZE || count < 3); i++, count++) { blocks.resize(blocks.size()+1); blocks.back().first = m_db->get_block_blob_from_height(i); @@ -2085,6 +2087,9 @@ bool Blockchain::find_blockchain_supplement(const uint64_t req_start_block, cons std::list<crypto::hash> mis; get_transactions_blobs(b.tx_hashes, blocks.back().second, mis); CHECK_AND_ASSERT_MES(!mis.size(), false, "internal error, transaction from block not found"); + size += blocks.back().first.size(); + for (const auto &t: blocks.back().second) + size += t.size(); } m_db->block_txn_stop(); return true; diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp index a5de36118..1d3d31c74 100644 --- a/src/rpc/core_rpc_server.cpp +++ b/src/rpc/core_rpc_server.cpp @@ -205,14 +205,17 @@ namespace cryptonote } size_t txidx = 0; ntxes += bd.second.size(); - for(const auto& t: bd.second) + for (std::list<cryptonote::blobdata>::iterator i = bd.second.begin(); i != bd.second.end(); ++i) { + unpruned_size += i->size(); if (req.prune) - res.blocks.back().txs.push_back(get_pruned_tx_blob(t)); + res.blocks.back().txs.push_back(get_pruned_tx_blob(std::move(*i))); else - res.blocks.back().txs.push_back(t); + res.blocks.back().txs.push_back(std::move(*i)); + i->clear(); + i->shrink_to_fit(); pruned_size += res.blocks.back().txs.back().size(); - unpruned_size += t.size(); + res.output_indices.back().indices.push_back(COMMAND_RPC_GET_BLOCKS_FAST::tx_output_indices()); bool r = m_core.get_tx_outputs_gindexs(b.tx_hashes[txidx++], res.output_indices.back().indices.back().indices); if (!r) |