aboutsummaryrefslogtreecommitdiff
path: root/src/rpc
diff options
context:
space:
mode:
Diffstat (limited to 'src/rpc')
-rw-r--r--src/rpc/core_rpc_server.cpp12
-rw-r--r--src/rpc/core_rpc_server.h2
-rw-r--r--src/rpc/core_rpc_server_commands_defs.h23
-rw-r--r--src/rpc/rpc_handler.cpp21
4 files changed, 56 insertions, 2 deletions
diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp
index cefba39f7..3851af3c8 100644
--- a/src/rpc/core_rpc_server.cpp
+++ b/src/rpc/core_rpc_server.cpp
@@ -2032,6 +2032,18 @@ namespace cryptonote
return true;
}
//------------------------------------------------------------------------------------------------------------------------------
+ bool core_rpc_server::on_pop_blocks(const COMMAND_RPC_POP_BLOCKS::request& req, COMMAND_RPC_POP_BLOCKS::response& res)
+ {
+ PERF_TIMER(on_pop_blocks);
+
+ m_core.get_blockchain_storage().pop_blocks(req.nblocks);
+
+ res.height = m_core.get_current_blockchain_height();
+ res.status = CORE_RPC_STATUS_OK;
+
+ return true;
+ }
+ //------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_relay_tx(const COMMAND_RPC_RELAY_TX::request& req, COMMAND_RPC_RELAY_TX::response& res, epee::json_rpc::error& error_resp)
{
PERF_TIMER(on_relay_tx);
diff --git a/src/rpc/core_rpc_server.h b/src/rpc/core_rpc_server.h
index 6a616e2e0..081ccc25d 100644
--- a/src/rpc/core_rpc_server.h
+++ b/src/rpc/core_rpc_server.h
@@ -117,6 +117,7 @@ namespace cryptonote
MAP_URI_AUTO_JON2("/get_outs", on_get_outs, COMMAND_RPC_GET_OUTPUTS)
MAP_URI_AUTO_JON2_IF("/update", on_update, COMMAND_RPC_UPDATE, !m_restricted)
MAP_URI_AUTO_BIN2("/get_output_distribution.bin", on_get_output_distribution_bin, COMMAND_RPC_GET_OUTPUT_DISTRIBUTION)
+ MAP_URI_AUTO_JON2_IF("/pop_blocks", on_pop_blocks, COMMAND_RPC_POP_BLOCKS, !m_restricted)
BEGIN_JSON_RPC_MAP("/json_rpc")
MAP_JON_RPC("get_block_count", on_getblockcount, COMMAND_RPC_GETBLOCKCOUNT)
MAP_JON_RPC("getblockcount", on_getblockcount, COMMAND_RPC_GETBLOCKCOUNT)
@@ -188,6 +189,7 @@ namespace cryptonote
bool on_stop_save_graph(const COMMAND_RPC_STOP_SAVE_GRAPH::request& req, COMMAND_RPC_STOP_SAVE_GRAPH::response& res);
bool on_update(const COMMAND_RPC_UPDATE::request& req, COMMAND_RPC_UPDATE::response& res);
bool on_get_output_distribution_bin(const COMMAND_RPC_GET_OUTPUT_DISTRIBUTION::request& req, COMMAND_RPC_GET_OUTPUT_DISTRIBUTION::response& res);
+ bool on_pop_blocks(const COMMAND_RPC_POP_BLOCKS::request& req, COMMAND_RPC_POP_BLOCKS::response& res);
//json_rpc
bool on_getblockcount(const COMMAND_RPC_GETBLOCKCOUNT::request& req, COMMAND_RPC_GETBLOCKCOUNT::response& res);
diff --git a/src/rpc/core_rpc_server_commands_defs.h b/src/rpc/core_rpc_server_commands_defs.h
index d54bfbf8d..0a07930ec 100644
--- a/src/rpc/core_rpc_server_commands_defs.h
+++ b/src/rpc/core_rpc_server_commands_defs.h
@@ -2328,4 +2328,27 @@ namespace cryptonote
};
};
+ struct COMMAND_RPC_POP_BLOCKS
+ {
+ struct request
+ {
+ uint64_t nblocks;
+
+ BEGIN_KV_SERIALIZE_MAP()
+ KV_SERIALIZE(nblocks);
+ END_KV_SERIALIZE_MAP()
+ };
+
+ struct response
+ {
+ std::string status;
+ uint64_t height;
+
+ BEGIN_KV_SERIALIZE_MAP()
+ KV_SERIALIZE(status)
+ KV_SERIALIZE(height)
+ END_KV_SERIALIZE_MAP()
+ };
+ };
+
}
diff --git a/src/rpc/rpc_handler.cpp b/src/rpc/rpc_handler.cpp
index 63664bf8b..e0a81c70f 100644
--- a/src/rpc/rpc_handler.cpp
+++ b/src/rpc/rpc_handler.cpp
@@ -43,8 +43,25 @@ namespace rpc
std::vector<std::uint64_t> distribution;
std::uint64_t start_height, base;
- if (!f(amount, from_height, to_height, start_height, distribution, base))
- return boost::none;
+
+ // see if we can extend the cache - a common case
+ if (d.cached && amount == 0 && d.cached_from == from_height && to_height > d.cached_to)
+ {
+ std::vector<std::uint64_t> new_distribution;
+ if (!f(amount, d.cached_to + 1, to_height, start_height, new_distribution, base))
+ return boost::none;
+ distribution = d.cached_distribution;
+ distribution.reserve(distribution.size() + new_distribution.size());
+ for (const auto &e: new_distribution)
+ distribution.push_back(e);
+ start_height = d.cached_start_height;
+ base = d.cached_base;
+ }
+ else
+ {
+ if (!f(amount, from_height, to_height, start_height, distribution, base))
+ return boost::none;
+ }
if (to_height > 0 && to_height >= from_height)
{