From f9cf204e592c7986813ce22a1bed653af25d9f0b Mon Sep 17 00:00:00 2001 From: cryptocode <34946442+cryptocode@users.noreply.github.com> Date: Wed, 14 Nov 2018 19:06:12 +0100 Subject: [PATCH] Only observe blocks if callback configured to avoid unecessary background calls. (#1375) --- rai/node/node.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/rai/node/node.cpp b/rai/node/node.cpp index 3ae5b037..bc206823 100644 --- a/rai/node/node.cpp +++ b/rai/node/node.cpp @@ -1338,13 +1338,13 @@ vote_uniquer (block_uniquer) peers.disconnect_observer = [this]() { observers.disconnect.notify (); }; - observers.blocks.add ([this](std::shared_ptr block_a, rai::account const & account_a, rai::amount const & amount_a, bool is_state_send_a) { - if (this->block_arrival.recent (block_a->hash ())) - { - auto node_l (shared_from_this ()); - background ([node_l, block_a, account_a, amount_a, is_state_send_a]() { - if (!node_l->config.callback_address.empty ()) - { + if (!config.callback_address.empty ()) + { + observers.blocks.add ([this](std::shared_ptr block_a, rai::account const & account_a, rai::amount const & amount_a, bool is_state_send_a) { + if (this->block_arrival.recent (block_a->hash ())) + { + auto node_l (shared_from_this ()); + background ([node_l, block_a, account_a, amount_a, is_state_send_a]() { boost::property_tree::ptree event; event.add ("account", account_a.to_account ()); event.add ("hash", block_a->hash ().to_string ()); @@ -1444,10 +1444,10 @@ vote_uniquer (block_uniquer) node_l->stats.inc (rai::stat::type::error, rai::stat::detail::http_callback, rai::stat::dir::out); } }); - } - }); - } - }); + }); + } + }); + } observers.endpoint.add ([this](rai::endpoint const & endpoint_a) { this->network.send_keepalive (endpoint_a); rep_query (*this, endpoint_a);