From 872c7eb26abec64478e8c2f68e13f12b93b7ed46 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Tue, 6 Nov 2018 11:02:27 +0000 Subject: Revert "blockchain: simplify output distribution code" This reverts commit b2bb9312a75781e714acf3c406634b3d4cded418. --- src/cryptonote_core/blockchain.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp index f3105114e..030798ad7 100644 --- a/src/cryptonote_core/blockchain.cpp +++ b/src/cryptonote_core/blockchain.cpp @@ -1831,10 +1831,15 @@ bool Blockchain::get_output_distribution(uint64_t amount, uint64_t from_height, { std::vector heights; heights.reserve(to_height + 1 - start_height); - for (uint64_t h = start_height; h <= to_height; ++h) + uint64_t real_start_height = start_height > 0 ? start_height-1 : start_height; + for (uint64_t h = real_start_height; h <= to_height; ++h) heights.push_back(h); distribution = m_db->get_block_cumulative_rct_outputs(heights); - base = 0; + if (start_height > 0) + { + base = distribution[0]; + distribution.erase(distribution.begin()); + } return true; } else -- cgit v1.2.3 From 0936dae8a4efc62f4ca54c4872ee2562961372df Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Tue, 6 Nov 2018 14:21:57 +0000 Subject: blockchain: remove "0 is height" shortcut from get_output_distribution This prevents asking for just 0, and the RPC layer already does this --- src/cryptonote_core/blockchain.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'src') diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp index 030798ad7..798f67e09 100644 --- a/src/cryptonote_core/blockchain.cpp +++ b/src/cryptonote_core/blockchain.cpp @@ -1823,8 +1823,6 @@ bool Blockchain::get_output_distribution(uint64_t amount, uint64_t from_height, uint64_t db_height = m_db->height(); if (db_height == 0) return false; - if (to_height == 0) - to_height = db_height - 1; if (start_height >= db_height || to_height >= db_height) return false; if (amount == 0) -- cgit v1.2.3 From 31d80027b5cc59b48205334a9e361c6a75099592 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Tue, 6 Nov 2018 14:23:26 +0000 Subject: tests: add unit tests for get_output_distribution --- src/cryptonote_core/blockchain.cpp | 1 + src/rpc/core_rpc_server.cpp | 2 +- src/rpc/daemon_handler.cpp | 2 +- src/rpc/rpc_handler.cpp | 4 ++-- src/rpc/rpc_handler.h | 2 +- 5 files changed, 6 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp index 798f67e09..e80e3f66c 100644 --- a/src/cryptonote_core/blockchain.cpp +++ b/src/cryptonote_core/blockchain.cpp @@ -1805,6 +1805,7 @@ bool Blockchain::get_output_distribution(uint64_t amount, uint64_t from_height, case STAGENET: start_height = stagenet_hard_forks[3].height; break; case TESTNET: start_height = testnet_hard_forks[3].height; break; case MAINNET: start_height = mainnet_hard_forks[3].height; break; + case FAKECHAIN: start_height = 0; break; default: return false; } } diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp index c2e71bef8..df9eee781 100644 --- a/src/rpc/core_rpc_server.cpp +++ b/src/rpc/core_rpc_server.cpp @@ -2125,7 +2125,7 @@ namespace cryptonote const uint64_t req_to_height = req.to_height ? req.to_height : (m_core.get_current_blockchain_height() - 1); for (uint64_t amount: req.amounts) { - auto data = rpc::RpcHandler::get_output_distribution(m_core, amount, req.from_height, req_to_height, req.cumulative); + auto data = rpc::RpcHandler::get_output_distribution([this](uint64_t amount, uint64_t from, uint64_t to, uint64_t &start_height, std::vector &distribution, uint64_t &base) { return m_core.get_output_distribution(amount, from, to, start_height, distribution, base); }, amount, req.from_height, req_to_height, req.cumulative); if (!data) { error_resp.code = CORE_RPC_ERROR_CODE_INTERNAL_ERROR; diff --git a/src/rpc/daemon_handler.cpp b/src/rpc/daemon_handler.cpp index 8822bd378..64a5cc858 100644 --- a/src/rpc/daemon_handler.cpp +++ b/src/rpc/daemon_handler.cpp @@ -751,7 +751,7 @@ namespace rpc const uint64_t req_to_height = req.to_height ? req.to_height : (m_core.get_current_blockchain_height() - 1); for (std::uint64_t amount : req.amounts) { - auto data = get_output_distribution(m_core, amount, req.from_height, req_to_height, req.cumulative); + auto data = rpc::RpcHandler::get_output_distribution([this](uint64_t amount, uint64_t from, uint64_t to, uint64_t &start_height, std::vector &distribution, uint64_t &base) { return m_core.get_output_distribution(amount, from, to, start_height, distribution, base); }, amount, req.from_height, req_to_height, req.cumulative); if (!data) { res.distributions.clear(); diff --git a/src/rpc/rpc_handler.cpp b/src/rpc/rpc_handler.cpp index d4beb1928..63664bf8b 100644 --- a/src/rpc/rpc_handler.cpp +++ b/src/rpc/rpc_handler.cpp @@ -26,7 +26,7 @@ namespace rpc } boost::optional - RpcHandler::get_output_distribution(core& src, std::uint64_t amount, std::uint64_t from_height, std::uint64_t to_height, bool cumulative) + RpcHandler::get_output_distribution(const std::function&, uint64_t&)> &f, uint64_t amount, uint64_t from_height, uint64_t to_height, bool cumulative) { static struct D { @@ -43,7 +43,7 @@ namespace rpc std::vector distribution; std::uint64_t start_height, base; - if (!src.get_output_distribution(amount, from_height, to_height, start_height, distribution, base)) + if (!f(amount, from_height, to_height, start_height, distribution, base)) return boost::none; if (to_height > 0 && to_height >= from_height) diff --git a/src/rpc/rpc_handler.h b/src/rpc/rpc_handler.h index 3cccef78a..e0d520408 100644 --- a/src/rpc/rpc_handler.h +++ b/src/rpc/rpc_handler.h @@ -56,7 +56,7 @@ class RpcHandler virtual std::string handle(const std::string& request) = 0; static boost::optional - get_output_distribution(core& src, std::uint64_t amount, std::uint64_t from_height, std::uint64_t to_height, bool cumulative); + get_output_distribution(const std::function&, uint64_t&)> &f, uint64_t amount, uint64_t from_height, uint64_t to_height, bool cumulative); }; -- cgit v1.2.3