aboutsummaryrefslogtreecommitdiff
path: root/src/cryptonote_core/blockchain.cpp
diff options
context:
space:
mode:
authormoneromooo-monero <moneromooo-monero@users.noreply.github.com>2020-02-26 18:06:00 +0000
committermoneromooo-monero <moneromooo-monero@users.noreply.github.com>2020-02-27 15:05:34 +0000
commit8958b4e7aa24d7f7de6667360b3558e52780e66f (patch)
tree0fca62135738b6ef82e4f8dcd14e975af469a4fe /src/cryptonote_core/blockchain.cpp
parentMerge pull request #6048 (diff)
downloadmonero-8958b4e7aa24d7f7de6667360b3558e52780e66f.tar.xz
blockchain_db: faster fetching of consecutive txes
Useful for wallet refresh or node sync
Diffstat (limited to 'src/cryptonote_core/blockchain.cpp')
-rw-r--r--src/cryptonote_core/blockchain.cpp32
1 files changed, 2 insertions, 30 deletions
diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp
index 78893fdf2..38743c6a1 100644
--- a/src/cryptonote_core/blockchain.cpp
+++ b/src/cryptonote_core/blockchain.cpp
@@ -2488,38 +2488,10 @@ bool Blockchain::find_blockchain_supplement(const uint64_t req_start_block, cons
}
db_rtxn_guard rtxn_guard(m_db);
- total_height = get_current_blockchain_height();
- size_t count = 0, size = 0;
blocks.reserve(std::min(std::min(max_count, (size_t)10000), (size_t)(total_height - start_height)));
- for(uint64_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.first = m_db->get_block_blob_from_height(i);
- block b;
- CHECK_AND_ASSERT_MES(parse_and_validate_block_from_blob(blocks.back().first.first, b), false, "internal error, invalid block");
- blocks.back().first.second = get_miner_tx_hash ? cryptonote::get_transaction_hash(b.miner_tx) : crypto::null_hash;
- std::vector<cryptonote::blobdata> txs;
- if (pruned)
- {
- CHECK_AND_ASSERT_MES(m_db->get_pruned_tx_blobs_from(b.tx_hashes.front(), b.tx_hashes.size(), txs), false, "Failed to retrieve all transactions needed");
- }
- else
- {
- std::vector<crypto::hash> mis;
- get_transactions_blobs(b.tx_hashes, txs, mis, pruned);
- CHECK_AND_ASSERT_MES(!mis.size(), false, "internal error, transaction from block not found");
- }
- size += blocks.back().first.first.size();
- for (const auto &t: txs)
- size += t.size();
+ CHECK_AND_ASSERT_MES(m_db->get_blocks_from(start_height, 3, max_count, FIND_BLOCKCHAIN_SUPPLEMENT_MAX_SIZE, blocks, pruned, true, get_miner_tx_hash),
+ false, "Error getting blocks");
- CHECK_AND_ASSERT_MES(txs.size() == b.tx_hashes.size(), false, "mismatched sizes of b.tx_hashes and txs");
- blocks.back().second.reserve(txs.size());
- for (size_t i = 0; i < txs.size(); ++i)
- {
- blocks.back().second.push_back(std::make_pair(b.tx_hashes[i], std::move(txs[i])));
- }
- }
return true;
}
//------------------------------------------------------------------