aboutsummaryrefslogtreecommitdiff
path: root/src/cryptonote_core
diff options
context:
space:
mode:
authorRiccardo Spagni <ric@spagni.net>2017-08-27 18:13:50 +0200
committerRiccardo Spagni <ric@spagni.net>2017-08-27 18:13:50 +0200
commite00238a355f55e8292978297a2a659ab3137f9f3 (patch)
tree9f2686b749595a2cc8f328a104cfc74c2b7bbf34 /src/cryptonote_core
parentMerge pull request #2320 (diff)
parentblockchain: cap memory size of retrieved blocks (diff)
downloadmonero-e00238a355f55e8292978297a2a659ab3137f9f3.tar.xz
Merge pull request #2347
5807529e blockchain: cap memory size of retrieved blocks (moneromooo-monero) c1b10381 rpc: decrease memory usage a bit in getblocks.bin (moneromooo-monero)
Diffstat (limited to 'src/cryptonote_core')
-rw-r--r--src/cryptonote_core/blockchain.cpp9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp
index d4a7831dc..c1faa703f 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;