aboutsummaryrefslogtreecommitdiff
path: root/src/rpc/core_rpc_server.cpp
diff options
context:
space:
mode:
authormoneromooo-monero <moneromooo-monero@users.noreply.github.com>2018-05-16 22:41:50 +0100
committermoneromooo-monero <moneromooo-monero@users.noreply.github.com>2018-05-21 19:51:58 +0100
commit5f8ffca34d87e46b7a44964e61733bfe5a85c028 (patch)
tree0236964fb6c1b7116e81ce9686e661d264a620d6 /src/rpc/core_rpc_server.cpp
parentMerge pull request #3830 (diff)
downloadmonero-5f8ffca34d87e46b7a44964e61733bfe5a85c028.tar.xz
speed up get_output_distribution (and precalc common case)
Diffstat (limited to 'src/rpc/core_rpc_server.cpp')
-rw-r--r--src/rpc/core_rpc_server.cpp17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp
index 3645c494e..e28914d96 100644
--- a/src/rpc/core_rpc_server.cpp
+++ b/src/rpc/core_rpc_server.cpp
@@ -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";