From b09c22b224bdfd6c62d23d2bcc8b84c0adadf039 Mon Sep 17 00:00:00 2001 From: Vlad Dobromyslov Date: Thu, 7 Apr 2022 14:50:41 +0300 Subject: [PATCH] #339 - fix active_sidechain_types for peerplays_sidechain_plugin --- .../peerplays_sidechain_plugin.cpp | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/libraries/plugins/peerplays_sidechain/peerplays_sidechain_plugin.cpp b/libraries/plugins/peerplays_sidechain/peerplays_sidechain_plugin.cpp index aaaeb801..840fdf98 100644 --- a/libraries/plugins/peerplays_sidechain/peerplays_sidechain_plugin.cpp +++ b/libraries/plugins/peerplays_sidechain/peerplays_sidechain_plugin.cpp @@ -310,22 +310,22 @@ const son_object peerplays_sidechain_plugin_impl::get_son_object(son_id_type son return *son_obj; } +//! Fixme - do we need to provide sidechain_type as param for this function? bool peerplays_sidechain_plugin_impl::is_active_son(son_id_type son_id) { const auto &idx = plugin.database().get_index_type().indices().get(); auto son_obj = idx.find(son_id); if (son_obj == idx.end()) return false; - //! Fixme - now only bitcoin, fix according to sidechain_type - const chain::global_property_object &gpo = plugin.database().get_global_properties(); - vector active_son_ids; - active_son_ids.reserve(gpo.active_sons.at(sidechain_type::bitcoin).size()); - std::transform(gpo.active_sons.at(sidechain_type::bitcoin).cbegin(), gpo.active_sons.at(sidechain_type::bitcoin).cend(), - std::inserter(active_son_ids, active_son_ids.end()), - [](const son_info &swi) { - return swi.son_id; - }); + set active_son_ids; + for(const auto& active_sidechain_type : active_sidechain_types) { + std::transform(gpo.active_sons.at(active_sidechain_type).cbegin(), gpo.active_sons.at(active_sidechain_type).cend(), + std::inserter(active_son_ids, active_son_ids.end()), + [](const son_info &swi) { + return swi.son_id; + }); + } auto it = std::find(active_son_ids.begin(), active_son_ids.end(), son_id); @@ -456,9 +456,13 @@ void peerplays_sidechain_plugin_impl::schedule_son_processing() { } void peerplays_sidechain_plugin_impl::son_processing() { - //! Fixme - here we must check size for every sidechain - if (plugin.database().get_global_properties().active_sons.at(sidechain_type::bitcoin).size() <= 0 && - plugin.database().get_global_properties().active_sons.at(sidechain_type::hive).size() <= 0) { + //! Check whether we have active SONs + bool have_active_sons = false; + for(const auto& active_sidechain_type : active_sidechain_types) { + if(plugin.database().get_global_properties().active_sons.at(active_sidechain_type).size() >= 0) + have_active_sons = true; + } + if (!have_active_sons) { return; }