diff --git a/nano/rpc/rpc_handler.cpp b/nano/rpc/rpc_handler.cpp index 5c6c201b..d92611be 100644 --- a/nano/rpc/rpc_handler.cpp +++ b/nano/rpc/rpc_handler.cpp @@ -86,9 +86,9 @@ void nano::rpc_handler::process_request () } else if (action == "process") { - auto force = request.get_optional ("force"); - auto watch_work = request.get_optional ("watch_work"); - if (((force.is_initialized () && *force) || (watch_work.is_initialized () && !*watch_work)) && !rpc_config.enable_control) + auto force = request.get_optional ("force").value_or (false); + auto watch_work = request.get_optional ("watch_work").value_or (true); + if ((force || watch_work) && !rpc_config.enable_control) { json_error_response (response, rpc_control_disabled_ec.message ()); error = true; diff --git a/nano/rpc_test/rpc.cpp b/nano/rpc_test/rpc.cpp index 50902fdd..e9f8dc23 100644 --- a/nano/rpc_test/rpc.cpp +++ b/nano/rpc_test/rpc.cpp @@ -1798,7 +1798,7 @@ TEST (rpc, process_block_with_work_watcher) rpc.start (); boost::property_tree::ptree request; request.put ("action", "process"); - request.put ("work_watcher", true); + request.put ("watch_work", true); std::string json; send->serialize_json (json); request.put ("block", json); @@ -1835,6 +1835,46 @@ TEST (rpc, process_block_with_work_watcher) ASSERT_NO_ERROR (system.poll ()); } ASSERT_GT (updated_difficulty, difficulty1); + + // Try without enable_control which watch_work requires if set to true + { + nano::rpc_config rpc_config (nano::get_available_port (), false); + rpc_config.rpc_process.ipc_port = node1.config.ipc_config.transport_tcp.port; + nano::ipc_rpc_processor ipc_rpc_processor (system.io_ctx, rpc_config); + nano::rpc rpc (system.io_ctx, rpc_config, ipc_rpc_processor); + rpc.start (); + boost::property_tree::ptree request; + request.put ("action", "process"); + request.put ("watch_work", true); + std::string json; + send->serialize_json (json); + request.put ("block", json); + { + test_response response (request, rpc.config.port, system.io_ctx); + system.deadline_set (5s); + while (response.status == 0) + { + ASSERT_NO_ERROR (system.poll ()); + } + ASSERT_EQ (200, response.status); + std::error_code ec (nano::error_rpc::rpc_control_disabled); + ASSERT_EQ (ec.message (), response.json.get ("error")); + } + + // Check no enable_control error message is present when not watching work + request.put ("watch_work", false); + { + test_response response (request, rpc.config.port, system.io_ctx); + system.deadline_set (5s); + while (response.status == 0) + { + ASSERT_NO_ERROR (system.poll ()); + } + ASSERT_EQ (200, response.status); + std::error_code ec (nano::error_rpc::rpc_control_disabled); + ASSERT_NE (ec.message (), response.json.get ("error")); + } + } } TEST (rpc, process_block_no_work)