aboutsummaryrefslogtreecommitdiff
path: root/src/rpc/core_rpc_server.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/rpc/core_rpc_server.cpp')
-rw-r--r--src/rpc/core_rpc_server.cpp73
1 files changed, 37 insertions, 36 deletions
diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp
index dc7b6b30f..b55b1994b 100644
--- a/src/rpc/core_rpc_server.cpp
+++ b/src/rpc/core_rpc_server.cpp
@@ -226,47 +226,47 @@ namespace cryptonote
if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_GET_BLOCKS_FAST>(invoke_http_mode::BIN, "/getblocks.bin", req, res, r))
return r;
- std::list<std::pair<cryptonote::blobdata, std::list<cryptonote::blobdata> > > bs;
+ std::vector<std::pair<std::pair<cryptonote::blobdata, crypto::hash>, std::vector<std::pair<crypto::hash, cryptonote::blobdata> > > > bs;
- if(!m_core.find_blockchain_supplement(req.start_height, req.block_ids, bs, res.current_height, res.start_height, req.prune, COMMAND_RPC_GET_BLOCKS_FAST_MAX_COUNT))
+ if(!m_core.find_blockchain_supplement(req.start_height, req.block_ids, bs, res.current_height, res.start_height, req.prune, !req.no_miner_tx, COMMAND_RPC_GET_BLOCKS_FAST_MAX_COUNT))
{
res.status = "Failed";
return false;
}
size_t pruned_size = 0, unpruned_size = 0, ntxes = 0;
+ res.blocks.reserve(bs.size());
+ res.output_indices.reserve(bs.size());
for(auto& bd: bs)
{
res.blocks.resize(res.blocks.size()+1);
- res.blocks.back().block = bd.first;
- pruned_size += bd.first.size();
- unpruned_size += bd.first.size();
+ res.blocks.back().block = bd.first.first;
+ pruned_size += bd.first.first.size();
+ unpruned_size += bd.first.first.size();
res.output_indices.push_back(COMMAND_RPC_GET_BLOCKS_FAST::block_output_indices());
res.output_indices.back().indices.push_back(COMMAND_RPC_GET_BLOCKS_FAST::tx_output_indices());
- block b;
- if (!parse_and_validate_block_from_blob(bd.first, b))
+ if (!req.no_miner_tx)
{
- res.status = "Invalid block";
- return false;
- }
- bool r = m_core.get_tx_outputs_gindexs(get_transaction_hash(b.miner_tx), res.output_indices.back().indices.back().indices);
- if (!r)
- {
- res.status = "Failed";
- return false;
+ bool r = m_core.get_tx_outputs_gindexs(bd.first.second, res.output_indices.back().indices.back().indices);
+ if (!r)
+ {
+ res.status = "Failed";
+ return false;
+ }
}
- size_t txidx = 0;
ntxes += bd.second.size();
- for (std::list<cryptonote::blobdata>::iterator i = bd.second.begin(); i != bd.second.end(); ++i)
+ res.blocks.back().txs.reserve(bd.second.size());
+ res.output_indices.back().indices.reserve(bd.second.size());
+ for (std::vector<std::pair<crypto::hash, cryptonote::blobdata>>::iterator i = bd.second.begin(); i != bd.second.end(); ++i)
{
- unpruned_size += i->size();
- res.blocks.back().txs.push_back(std::move(*i));
- i->clear();
- i->shrink_to_fit();
+ unpruned_size += i->second.size();
+ res.blocks.back().txs.push_back(std::move(i->second));
+ i->second.clear();
+ i->second.shrink_to_fit();
pruned_size += res.blocks.back().txs.back().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);
+ bool r = m_core.get_tx_outputs_gindexs(i->first, res.output_indices.back().indices.back().indices);
if (!r)
{
res.status = "Failed";
@@ -286,7 +286,7 @@ namespace cryptonote
if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_GET_ALT_BLOCKS_HASHES>(invoke_http_mode::JON, "/get_alt_blocks_hashes", req, res, r))
return r;
- std::list<block> blks;
+ std::vector<block> blks;
if(!m_core.get_alternative_blocks(blks))
{
@@ -328,8 +328,8 @@ namespace cryptonote
res.status = "Error retrieving block at height " + std::to_string(height);
return true;
}
- std::list<transaction> txs;
- std::list<crypto::hash> missed_txs;
+ std::vector<transaction> txs;
+ std::vector<crypto::hash> missed_txs;
m_core.get_transactions(blk.tx_hashes, txs, missed_txs);
res.blocks.resize(res.blocks.size() + 1);
res.blocks.back().block = block_to_blob(blk);
@@ -544,8 +544,8 @@ namespace cryptonote
}
vh.push_back(*reinterpret_cast<const crypto::hash*>(b.data()));
}
- std::list<crypto::hash> missed_txs;
- std::list<transaction> txs;
+ std::vector<crypto::hash> missed_txs;
+ std::vector<transaction> txs;
bool r = m_core.get_transactions(vh, txs, missed_txs);
if(!r)
{
@@ -566,25 +566,26 @@ namespace cryptonote
if(r)
{
// sort to match original request
- std::list<transaction> sorted_txs;
+ std::vector<transaction> sorted_txs;
std::vector<tx_info>::const_iterator i;
+ unsigned txs_processed = 0;
for (const crypto::hash &h: vh)
{
if (std::find(missed_txs.begin(), missed_txs.end(), h) == missed_txs.end())
{
- if (txs.empty())
+ if (txs.size() == txs_processed)
{
res.status = "Failed: internal error - txs is empty";
return true;
}
// core returns the ones it finds in the right order
- if (get_transaction_hash(txs.front()) != h)
+ if (get_transaction_hash(txs[txs_processed]) != h)
{
res.status = "Failed: tx hash mismatch";
return true;
}
- sorted_txs.push_back(std::move(txs.front()));
- txs.pop_front();
+ sorted_txs.push_back(std::move(txs[txs_processed]));
+ ++txs_processed;
}
else if ((i = std::find_if(pool_tx_info.begin(), pool_tx_info.end(), [h](const tx_info &txi) { return epee::string_tools::pod_to_hex(h) == txi.id_hash; })) != pool_tx_info.end())
{
@@ -595,7 +596,7 @@ namespace cryptonote
return true;
}
sorted_txs.push_back(tx);
- missed_txs.remove(h);
+ missed_txs.erase(std::find(missed_txs.begin(), missed_txs.end(), h));
pool_tx_hashes.insert(h);
const std::string hash_string = epee::string_tools::pod_to_hex(h);
for (const auto &ti: pool_tx_info)
@@ -614,7 +615,7 @@ namespace cryptonote
LOG_PRINT_L2("Found " << found_in_pool << "/" << vh.size() << " transactions in the pool");
}
- std::list<std::string>::const_iterator txhi = req.txs_hashes.begin();
+ std::vector<std::string>::const_iterator txhi = req.txs_hashes.begin();
std::vector<crypto::hash>::const_iterator vhi = vh.begin();
for(auto& tx: txs)
{
@@ -1655,10 +1656,10 @@ namespace cryptonote
PERF_TIMER(on_flush_txpool);
bool failed = false;
- std::list<crypto::hash> txids;
+ std::vector<crypto::hash> txids;
if (req.txids.empty())
{
- std::list<transaction> pool_txs;
+ std::vector<transaction> pool_txs;
bool r = m_core.get_pool_transactions(pool_txs);
if (!r)
{