speed up get_output_distribution (and precalc common case)

This commit is contained in:
moneromooo-monero
2018-05-16 22:41:50 +01:00
parent 2f5506daf8
commit 5f8ffca34d
10 changed files with 183 additions and 23 deletions

View File

@@ -47,6 +47,7 @@ using namespace epee;
#include "rpc/rpc_args.h"
#include "core_rpc_server_error_codes.h"
#include "p2p/net_node.h"
#include "get_output_distribution_cache.h"
#include "version.h"
#undef MONERO_DEFAULT_LOG_CATEGORY
@@ -2103,9 +2104,23 @@ namespace cryptonote
continue;
}
// this is a slow operation, so we have precomputed caches of common cases
bool found = false;
for (const auto &slot: get_output_distribution_cache)
{
if (slot.amount == amount && slot.from_height == req.from_height && slot.to_height == req.to_height)
{
res.distributions.push_back({amount, slot.start_height, slot.distribution, slot.base});
found = true;
break;
}
}
if (found)
continue;
std::vector<uint64_t> distribution;
uint64_t start_height, base;
if (!m_core.get_output_distribution(amount, req.from_height, start_height, distribution, base))
if (!m_core.get_output_distribution(amount, req.from_height, req.to_height, start_height, distribution, base))
{
error_resp.code = CORE_RPC_ERROR_CODE_INTERNAL_ERROR;
error_resp.message = "Failed to get rct distribution";