From 71ade136cc5efb3a69c4c45953a22cdc9f4739f7 Mon Sep 17 00:00:00 2001 From: satyakoneru Date: Thu, 19 Dec 2019 07:45:12 +0000 Subject: [PATCH] SON206 - Plugin SON Heartbeat changes, stub testing and changes --- .../chain/include/graphene/chain/son_object.hpp | 4 ++++ .../peerplays_sidechain_plugin.cpp | 16 +++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/libraries/chain/include/graphene/chain/son_object.hpp b/libraries/chain/include/graphene/chain/son_object.hpp index 4cbff5ed..977c6b99 100644 --- a/libraries/chain/include/graphene/chain/son_object.hpp +++ b/libraries/chain/include/graphene/chain/son_object.hpp @@ -101,4 +101,8 @@ FC_REFLECT_DERIVED( graphene::chain::son_statistics_object, (graphene::db::object), (owner) (txs_signed) + (total_downtime) + (current_interval_downtime) + (last_down_timestamp) + (last_active_timestamp) ) diff --git a/libraries/plugins/peerplays_sidechain/peerplays_sidechain_plugin.cpp b/libraries/plugins/peerplays_sidechain/peerplays_sidechain_plugin.cpp index 2778ff8c..5276e5e7 100644 --- a/libraries/plugins/peerplays_sidechain/peerplays_sidechain_plugin.cpp +++ b/libraries/plugins/peerplays_sidechain/peerplays_sidechain_plugin.cpp @@ -147,12 +147,12 @@ void peerplays_sidechain_plugin::schedule_heartbeat_loop() void peerplays_sidechain_plugin::heartbeat_loop() { - ilog("peerplays_sidechain_plugin: sending heartbeat"); chain::database& d = database(); chain::son_id_type son_id = *(_sons.begin()); const chain::global_property_object& gpo = d.get_global_properties(); auto it = std::find(gpo.active_sons.begin(), gpo.active_sons.end(), son_id); if(it != gpo.active_sons.end()) { + ilog("peerplays_sidechain_plugin: sending heartbeat"); chain::son_heartbeat_operation op; const auto& idx = d.get_index_type().indices().get(); auto son_obj = idx.find( son_id ); @@ -160,10 +160,20 @@ void peerplays_sidechain_plugin::heartbeat_loop() op.son_id = son_id; op.ts = fc::time_point::now() + fc::seconds(0); chain::signed_transaction trx = d.create_signed_transaction(_private_keys.begin()->second, op); - fc::async( [this,trx](){ p2p_node().broadcast(net::trx_message(trx)); } ); + fc::future fut = fc::async( [&](){ + try { + d.push_transaction(trx); + p2p_node().broadcast(net::trx_message(trx)); + return true; + } catch(fc::exception e){ + ilog("peerplays_sidechain_plugin: sending heartbeat failed with exception ${e}",("e", e.what())); + std::cout << e.what() << std::endl; + return false; + } + }); + fut.wait(fc::seconds(10)); } schedule_heartbeat_loop(); } - } } // graphene::peerplays_sidechain