From f7765c148d995431c19552e35d09012f3e2b1e15 Mon Sep 17 00:00:00 2001 From: Sergey Kroshnin Date: Wed, 22 May 2019 15:46:39 +0300 Subject: [PATCH] Set minimum difficulty for RPC "work_generate" (#2006) * Set minimum difficulty for RPC "work_generate" * Update CLI --debug_opencl for low difficulty --- nano/lib/errors.cpp | 2 +- nano/nano_node/entry.cpp | 5 +++++ nano/node/json_handler.cpp | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/nano/lib/errors.cpp b/nano/lib/errors.cpp index a97ceccfb..0c70e3c7d 100644 --- a/nano/lib/errors.cpp +++ b/nano/lib/errors.cpp @@ -153,7 +153,7 @@ std::string nano::error_rpc_messages::message (int ev) const case nano::error_rpc::confirmation_not_found: return "Active confirmation not found"; case nano::error_rpc::difficulty_limit: - return "Difficulty above config limit"; + return "Difficulty above config limit or below publish threshold"; case nano::error_rpc::invalid_balance: return "Invalid balance number"; case nano::error_rpc::invalid_destinations: diff --git a/nano/nano_node/entry.cpp b/nano/nano_node/entry.cpp index 5f0651852..6765dfb32 100644 --- a/nano/nano_node/entry.cpp +++ b/nano/nano_node/entry.cpp @@ -390,6 +390,11 @@ int main (int argc, char * const * argv) std::cerr << "Invalid difficulty\n"; result = -1; } + else if (difficulty < network_constants.publish_threshold) + { + std::cerr << "Difficulty below publish threshold\n"; + result = -1; + } } if (!result) { diff --git a/nano/node/json_handler.cpp b/nano/node/json_handler.cpp index 647700b67..8be6142ce 100644 --- a/nano/node/json_handler.cpp +++ b/nano/node/json_handler.cpp @@ -4345,7 +4345,7 @@ void nano::json_handler::work_generate () ec = nano::error_rpc::bad_difficulty_format; } } - if (!ec && difficulty > node_rpc_config.max_work_generate_difficulty) + if (!ec && (difficulty > node_rpc_config.max_work_generate_difficulty || difficulty < node.network_params.network.publish_threshold)) { ec = nano::error_rpc::difficulty_limit; }