aboutsummaryrefslogtreecommitdiff
path: root/src/daemon
diff options
context:
space:
mode:
Diffstat (limited to 'src/daemon')
-rw-r--r--src/daemon/command_parser_executor.cpp25
-rw-r--r--src/daemon/command_parser_executor.h2
-rw-r--r--src/daemon/command_server.cpp6
-rw-r--r--src/daemon/core.h17
-rw-r--r--src/daemon/daemon.cpp7
-rw-r--r--src/daemon/rpc.h3
-rw-r--r--src/daemon/rpc_command_executor.cpp27
-rw-r--r--src/daemon/rpc_command_executor.h2
8 files changed, 66 insertions, 23 deletions
diff --git a/src/daemon/command_parser_executor.cpp b/src/daemon/command_parser_executor.cpp
index 1638cf505..853cde9c3 100644
--- a/src/daemon/command_parser_executor.cpp
+++ b/src/daemon/command_parser_executor.cpp
@@ -674,6 +674,31 @@ bool t_command_parser_executor::sync_info(const std::vector<std::string>& args)
return m_executor.sync_info();
}
+bool t_command_parser_executor::pop_blocks(const std::vector<std::string>& args)
+{
+ if (args.size() != 1)
+ {
+ std::cout << "Exactly one parameter is needed" << std::endl;
+ return false;
+ }
+
+ try
+ {
+ uint64_t nblocks = boost::lexical_cast<uint64_t>(args[0]);
+ if (nblocks < 1)
+ {
+ std::cout << "number of blocks must be greater than 0" << std::endl;
+ return false;
+ }
+ return m_executor.pop_blocks(nblocks);
+ }
+ catch (const boost::bad_lexical_cast&)
+ {
+ std::cout << "number of blocks must be a number greater than 0" << std::endl;
+ }
+ return false;
+}
+
bool t_command_parser_executor::version(const std::vector<std::string>& args)
{
std::cout << "Monero '" << MONERO_RELEASE_NAME << "' (v" << MONERO_VERSION_FULL << ")" << std::endl;
diff --git a/src/daemon/command_parser_executor.h b/src/daemon/command_parser_executor.h
index a70070171..e2844e8b7 100644
--- a/src/daemon/command_parser_executor.h
+++ b/src/daemon/command_parser_executor.h
@@ -139,6 +139,8 @@ public:
bool sync_info(const std::vector<std::string>& args);
+ bool pop_blocks(const std::vector<std::string>& args);
+
bool version(const std::vector<std::string>& args);
};
diff --git a/src/daemon/command_server.cpp b/src/daemon/command_server.cpp
index 35504f2c9..527ed2cf1 100644
--- a/src/daemon/command_server.cpp
+++ b/src/daemon/command_server.cpp
@@ -282,6 +282,12 @@ t_command_server::t_command_server(
, "Print information about the blockchain sync state."
);
m_command_lookup.set_handler(
+ "pop_blocks"
+ , std::bind(&t_command_parser_executor::pop_blocks, &m_parser, p::_1)
+ , "pop_blocks <nblocks>"
+ , "Remove blocks from end of blockchain"
+ );
+ m_command_lookup.set_handler(
"version"
, std::bind(&t_command_parser_executor::version, &m_parser, p::_1)
, "Print version information."
diff --git a/src/daemon/core.h b/src/daemon/core.h
index d1defd573..c15d8d236 100644
--- a/src/daemon/core.h
+++ b/src/daemon/core.h
@@ -67,31 +67,16 @@ public:
m_core.set_cryptonote_protocol(&protocol);
}
- std::string get_config_subdir() const
- {
- bool testnet = command_line::get_arg(m_vm_HACK, cryptonote::arg_testnet_on);
- bool stagenet = command_line::get_arg(m_vm_HACK, cryptonote::arg_stagenet_on);
- bool mainnet = !testnet && !stagenet;
- std::string port = command_line::get_arg(m_vm_HACK, nodetool::arg_p2p_bind_port);
- if ((mainnet && port != std::to_string(::config::P2P_DEFAULT_PORT))
- || (testnet && port != std::to_string(::config::testnet::P2P_DEFAULT_PORT))
- || (stagenet && port != std::to_string(::config::stagenet::P2P_DEFAULT_PORT))) {
- return port;
- }
- return std::string();
- }
-
bool run()
{
//initialize core here
MGINFO("Initializing core...");
- std::string config_subdir = get_config_subdir();
#if defined(PER_BLOCK_CHECKPOINT)
const cryptonote::GetCheckpointsCallback& get_checkpoints = blocks::GetCheckpointsData;
#else
const cryptonote::GetCheckpointsCallback& get_checkpoints = nullptr;
#endif
- if (!m_core.init(m_vm_HACK, config_subdir.empty() ? NULL : config_subdir.c_str(), nullptr, get_checkpoints))
+ if (!m_core.init(m_vm_HACK, nullptr, get_checkpoints))
{
return false;
}
diff --git a/src/daemon/daemon.cpp b/src/daemon/daemon.cpp
index 49d6d49cf..13478f39d 100644
--- a/src/daemon/daemon.cpp
+++ b/src/daemon/daemon.cpp
@@ -75,18 +75,15 @@ public:
protocol.set_p2p_endpoint(p2p.get());
core.set_protocol(protocol.get());
- const auto testnet = command_line::get_arg(vm, cryptonote::arg_testnet_on);
- const auto stagenet = command_line::get_arg(vm, cryptonote::arg_stagenet_on);
- const auto regtest = command_line::get_arg(vm, cryptonote::arg_regtest_on);
const auto restricted = command_line::get_arg(vm, cryptonote::core_rpc_server::arg_restricted_rpc);
const auto main_rpc_port = command_line::get_arg(vm, cryptonote::core_rpc_server::arg_rpc_bind_port);
- rpcs.emplace_back(new t_rpc{vm, core, p2p, restricted, testnet ? cryptonote::TESTNET : stagenet ? cryptonote::STAGENET : regtest ? cryptonote::FAKECHAIN : cryptonote::MAINNET, main_rpc_port, "core"});
+ rpcs.emplace_back(new t_rpc{vm, core, p2p, restricted, main_rpc_port, "core"});
auto restricted_rpc_port_arg = cryptonote::core_rpc_server::arg_rpc_restricted_bind_port;
if(!command_line::is_arg_defaulted(vm, restricted_rpc_port_arg))
{
auto restricted_rpc_port = command_line::get_arg(vm, restricted_rpc_port_arg);
- rpcs.emplace_back(new t_rpc{vm, core, p2p, true, testnet ? cryptonote::TESTNET : stagenet ? cryptonote::STAGENET : cryptonote::MAINNET, restricted_rpc_port, "restricted"});
+ rpcs.emplace_back(new t_rpc{vm, core, p2p, true, restricted_rpc_port, "restricted"});
}
}
};
diff --git a/src/daemon/rpc.h b/src/daemon/rpc.h
index 9621b0d01..37dffc097 100644
--- a/src/daemon/rpc.h
+++ b/src/daemon/rpc.h
@@ -54,7 +54,6 @@ public:
, t_core & core
, t_p2p & p2p
, const bool restricted
- , const cryptonote::network_type nettype
, const std::string & port
, const std::string & description
)
@@ -62,7 +61,7 @@ public:
{
MGINFO("Initializing " << m_description << " RPC server...");
- if (!m_server.init(vm, restricted, nettype, port))
+ if (!m_server.init(vm, restricted, port))
{
throw std::runtime_error("Failed to initialize " + m_description + " RPC server.");
}
diff --git a/src/daemon/rpc_command_executor.cpp b/src/daemon/rpc_command_executor.cpp
index 5ae9851a7..015e1e1f9 100644
--- a/src/daemon/rpc_command_executor.cpp
+++ b/src/daemon/rpc_command_executor.cpp
@@ -1967,4 +1967,31 @@ bool t_rpc_command_executor::sync_info()
return true;
}
+bool t_rpc_command_executor::pop_blocks(uint64_t num_blocks)
+{
+ cryptonote::COMMAND_RPC_POP_BLOCKS::request req;
+ cryptonote::COMMAND_RPC_POP_BLOCKS::response res;
+ std::string fail_message = "pop_blocks failed";
+
+ req.nblocks = num_blocks;
+ if (m_is_rpc)
+ {
+ if (!m_rpc_client->rpc_request(req, res, "/pop_blocks", fail_message.c_str()))
+ {
+ return true;
+ }
+ }
+ else
+ {
+ if (!m_rpc_server->on_pop_blocks(req, res) || res.status != CORE_RPC_STATUS_OK)
+ {
+ tools::fail_msg_writer() << make_error(fail_message, res.status);
+ return true;
+ }
+ }
+ tools::success_msg_writer() << "new height: " << res.height;
+
+ return true;
+}
+
}// namespace daemonize
diff --git a/src/daemon/rpc_command_executor.h b/src/daemon/rpc_command_executor.h
index 9e6010c5b..592584a5f 100644
--- a/src/daemon/rpc_command_executor.h
+++ b/src/daemon/rpc_command_executor.h
@@ -152,6 +152,8 @@ public:
bool relay_tx(const std::string &txid);
bool sync_info();
+
+ bool pop_blocks(uint64_t num_blocks);
};
} // namespace daemonize