From 89ca9167d3fa64200f2ca141472f16eec19853e1 Mon Sep 17 00:00:00 2001 From: Srdjan Obucina Date: Tue, 4 Feb 2020 19:56:20 +0100 Subject: [PATCH] Squashed commit of the following: commit a688bb93ed4e16232a907aa8c76e240c83c771bf Author: obucinac Date: Tue Feb 4 19:31:45 2020 +0100 son_wallet_object operations and multisig wallet recreation by RPC (#263) * Extend GPO.active_sons to contain votes and all public keys * Introduce son_wallet_object * son_wallet_object operations * Create son_wallet_object on new set of SONs, to initiate primary wallet recreation * son_wallet_object API and cli wallet commands * Send RPC command to bitcoin node to recreate multisig wallet * Updating wallet info through operation instead through database.modify() for persistance * Update libraries/chain/include/graphene/chain/protocol/son_wallet.hpp * Update libraries/chain/include/graphene/chain/protocol/son_wallet.hpp * Fix #include * Refactor primary wallet recreation * PW recreation refactoring, prevent duplicated recreations, update wallet address through proposal * Quickfix for checking payer in evaluator * Fix failing son_wallet_tests - Check for son_btc_account is temporarely disabled * Remove redundant file Co-authored-by: gladcow commit 6e61d6b055eb276757e426245a3a7c23a61b3854 Author: satyakoneru Date: Tue Feb 4 00:14:39 2020 +1100 SON233 - Provide correct downtime metrics to user (#278) --- libraries/chain/db_maint.cpp | 16 ++++++++++++++++ .../chain/include/graphene/chain/database.hpp | 1 + libraries/chain/son_evaluator.cpp | 1 + libraries/chain/son_wallet_evaluator.cpp | 2 -- .../peerplays_sidechain_plugin.cpp | 6 +++--- 5 files changed, 21 insertions(+), 5 deletions(-) diff --git a/libraries/chain/db_maint.cpp b/libraries/chain/db_maint.cpp index 0cd36eb4..935e520e 100644 --- a/libraries/chain/db_maint.cpp +++ b/libraries/chain/db_maint.cpp @@ -165,6 +165,20 @@ void database::pay_sons() } } +void database::update_son_metrics() +{ + const auto& son_idx = get_index_type().indices().get< by_id >(); + for( auto& son : son_idx ) + { + auto& stats = son.statistics(*this); + modify( stats, [&]( son_statistics_object& _stats) + { + _stats.total_downtime += _stats.current_interval_downtime; + _stats.current_interval_downtime = 0; + }); + } +} + void database::pay_workers( share_type& budget ) { // ilog("Processing payroll! Available budget is ${b}", ("b", budget)); @@ -576,6 +590,8 @@ void database::update_active_sons() _sso.scheduler.update(active_sons); }); + update_son_metrics(); + if(gpo.active_sons.size() > 0 ) { if(gpo.parameters.get_son_btc_account_id() == GRAPHENE_NULL_ACCOUNT) { const auto& son_btc_account = create( [&]( account_object& obj ) { diff --git a/libraries/chain/include/graphene/chain/database.hpp b/libraries/chain/include/graphene/chain/database.hpp index 56a62577..ea2ccffd 100644 --- a/libraries/chain/include/graphene/chain/database.hpp +++ b/libraries/chain/include/graphene/chain/database.hpp @@ -548,6 +548,7 @@ namespace graphene { namespace chain { void perform_chain_maintenance(const signed_block& next_block, const global_property_object& global_props); void update_active_witnesses(); void update_active_committee_members(); + void update_son_metrics(); void update_active_sons(); void update_worker_votes(); diff --git a/libraries/chain/son_evaluator.cpp b/libraries/chain/son_evaluator.cpp index 34f4daa3..79660921 100644 --- a/libraries/chain/son_evaluator.cpp +++ b/libraries/chain/son_evaluator.cpp @@ -165,6 +165,7 @@ object_id_type son_heartbeat_evaluator::do_apply(const son_heartbeat_operation& void_result son_report_down_evaluator::do_evaluate(const son_report_down_operation& op) { try { + FC_ASSERT(db().head_block_time() >= HARDFORK_SON_TIME, "Not allowed until SON HARDFORK"); // can be removed after HF date pass FC_ASSERT(op.payer == db().get_global_properties().parameters.get_son_btc_account_id(), "Payer should be the son btc account"); const auto& idx = db().get_index_type().indices().get(); FC_ASSERT( idx.find(op.son_id) != idx.end() ); diff --git a/libraries/chain/son_wallet_evaluator.cpp b/libraries/chain/son_wallet_evaluator.cpp index 4c92a957..55d4645d 100644 --- a/libraries/chain/son_wallet_evaluator.cpp +++ b/libraries/chain/son_wallet_evaluator.cpp @@ -34,8 +34,6 @@ void_result recreate_son_wallet_evaluator::do_evaluate(const son_wallet_recreate object_id_type recreate_son_wallet_evaluator::do_apply(const son_wallet_recreate_operation& op) { try { - FC_ASSERT(db().head_block_time() >= HARDFORK_SON_TIME, "Not allowed until SON HARDFORK"); - const auto& idx = db().get_index_type().indices().get(); auto itr = idx.rbegin(); if(itr != idx.rend()) diff --git a/libraries/plugins/peerplays_sidechain/peerplays_sidechain_plugin.cpp b/libraries/plugins/peerplays_sidechain/peerplays_sidechain_plugin.cpp index fd8990ec..6f7a0d77 100644 --- a/libraries/plugins/peerplays_sidechain/peerplays_sidechain_plugin.cpp +++ b/libraries/plugins/peerplays_sidechain/peerplays_sidechain_plugin.cpp @@ -8,9 +8,7 @@ #include #include -#include #include -#include #include #include @@ -306,6 +304,7 @@ void peerplays_sidechain_plugin_impl::create_son_down_proposals() chain::database& d = plugin.database(); const chain::global_property_object& gpo = d.get_global_properties(); + const chain::dynamic_global_property_object& dgpo = d.get_dynamic_global_properties(); const auto& idx = d.get_index_type().indices().get(); std::set sons_being_reported_down = d.get_sons_being_reported_down(); chain::son_id_type my_son_id = *(_sons.begin()); @@ -315,7 +314,8 @@ void peerplays_sidechain_plugin_impl::create_son_down_proposals() } auto son_obj = idx.find( son_inf.son_id ); auto stats = son_obj->statistics(d); - fc::time_point_sec last_active_ts = stats.last_active_timestamp; + fc::time_point_sec last_maintenance_time = dgpo.next_maintenance_time - gpo.parameters.maintenance_interval; + fc::time_point_sec last_active_ts = ((stats.last_active_timestamp > last_maintenance_time) ? stats.last_active_timestamp : last_maintenance_time); int64_t down_threshold = 2*180000000; if(son_obj->status == chain::son_status::active && (fc::time_point::now() - last_active_ts) > fc::microseconds(down_threshold)) { ilog("peerplays_sidechain_plugin: sending son down proposal for ${t} from ${s}",("t",std::string(object_id_type(son_obj->id)))("s",std::string(object_id_type(my_son_id))));