From cf77b55695cbca88560df9e73db8cfa97114bf62 Mon Sep 17 00:00:00 2001 From: Guilherme Lawless Date: Mon, 14 Oct 2019 10:35:40 +0100 Subject: [PATCH] Attempt to fetch account from block hash in RPC work_generate (#2339) Also fixes distributed_work relaying the account by not storing as a const ref --- nano/node/distributed_work.hpp | 2 +- nano/node/json_handler.cpp | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/nano/node/distributed_work.hpp b/nano/node/distributed_work.hpp index 4943d26a..1dd476f3 100644 --- a/nano/node/distributed_work.hpp +++ b/nano/node/distributed_work.hpp @@ -56,7 +56,7 @@ public: unsigned int backoff; // in seconds nano::node & node; nano::root root; - boost::optional const & account; + boost::optional const account; std::mutex mutex; std::map outstanding; std::vector> connections; diff --git a/nano/node/json_handler.cpp b/nano/node/json_handler.cpp index cf4d6389..22061de4 100644 --- a/nano/node/json_handler.cpp +++ b/nano/node/json_handler.cpp @@ -4791,6 +4791,15 @@ void nano::json_handler::work_generate () } else { + if (!account_opt.is_initialized ()) + { + // Fetch account from block if not given + auto transaction_l (node.store.tx_begin_read ()); + if (node.store.block_exists (transaction_l, hash)) + { + account = node.store.block_account (transaction_l, hash); + } + } auto secondary_work_peers_l (request.get ("secondary_work_peers", false)); auto const & peers_l (secondary_work_peers_l ? node.config.secondary_work_peers : node.config.work_peers); if (node.work_generation_enabled (peers_l))