Compare commits
2 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9cd413e547 | ||
|
|
bf0a0067f9 |
3 changed files with 61 additions and 6 deletions
|
|
@ -123,6 +123,22 @@ object_id_type son_heartbeat_evaluator::do_apply(const son_heartbeat_operation&
|
||||||
auto itr = idx.find(op.son_id);
|
auto itr = idx.find(op.son_id);
|
||||||
if(itr != idx.end())
|
if(itr != idx.end())
|
||||||
{
|
{
|
||||||
|
const global_property_object& gpo = db().get_global_properties();
|
||||||
|
vector<son_id_type> active_son_ids;
|
||||||
|
active_son_ids.reserve(gpo.active_sons.size());
|
||||||
|
std::transform(gpo.active_sons.begin(), gpo.active_sons.end(),
|
||||||
|
std::inserter(active_son_ids, active_son_ids.end()),
|
||||||
|
[](const son_info& swi) {
|
||||||
|
return swi.son_id;
|
||||||
|
});
|
||||||
|
|
||||||
|
auto it_son = std::find(active_son_ids.begin(), active_son_ids.end(), op.son_id);
|
||||||
|
bool is_son_active = true;
|
||||||
|
|
||||||
|
if(it_son == active_son_ids.end()) {
|
||||||
|
is_son_active = false;
|
||||||
|
}
|
||||||
|
|
||||||
if(itr->status == son_status::in_maintenance) {
|
if(itr->status == son_status::in_maintenance) {
|
||||||
db().modify( itr->statistics( db() ), [&]( son_statistics_object& sso )
|
db().modify( itr->statistics( db() ), [&]( son_statistics_object& sso )
|
||||||
{
|
{
|
||||||
|
|
@ -130,8 +146,12 @@ object_id_type son_heartbeat_evaluator::do_apply(const son_heartbeat_operation&
|
||||||
sso.last_active_timestamp = op.ts;
|
sso.last_active_timestamp = op.ts;
|
||||||
} );
|
} );
|
||||||
|
|
||||||
db().modify(*itr, [&op](son_object &so) {
|
db().modify(*itr, [&is_son_active](son_object &so) {
|
||||||
|
if(is_son_active) {
|
||||||
so.status = son_status::active;
|
so.status = son_status::active;
|
||||||
|
} else {
|
||||||
|
so.status = son_status::inactive;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
} else if (itr->status == son_status::active) {
|
} else if (itr->status == son_status::active) {
|
||||||
db().modify( itr->statistics( db() ), [&]( son_statistics_object& sso )
|
db().modify( itr->statistics( db() ), [&]( son_statistics_object& sso )
|
||||||
|
|
|
||||||
|
|
@ -186,6 +186,10 @@ void peerplays_sidechain_plugin_impl::heartbeat_loop()
|
||||||
{
|
{
|
||||||
chain::database& d = plugin.database();
|
chain::database& d = plugin.database();
|
||||||
chain::son_id_type son_id = *(_sons.begin());
|
chain::son_id_type son_id = *(_sons.begin());
|
||||||
|
const auto& idx = d.get_index_type<chain::son_index>().indices().get<by_id>();
|
||||||
|
auto son_obj = idx.find( son_id );
|
||||||
|
if(son_obj == idx.end())
|
||||||
|
return;
|
||||||
const chain::global_property_object& gpo = d.get_global_properties();
|
const chain::global_property_object& gpo = d.get_global_properties();
|
||||||
vector<son_id_type> active_son_ids;
|
vector<son_id_type> active_son_ids;
|
||||||
active_son_ids.reserve(gpo.active_sons.size());
|
active_son_ids.reserve(gpo.active_sons.size());
|
||||||
|
|
@ -196,11 +200,9 @@ void peerplays_sidechain_plugin_impl::heartbeat_loop()
|
||||||
});
|
});
|
||||||
|
|
||||||
auto it = std::find(active_son_ids.begin(), active_son_ids.end(), son_id);
|
auto it = std::find(active_son_ids.begin(), active_son_ids.end(), son_id);
|
||||||
if(it != active_son_ids.end()) {
|
if(it != active_son_ids.end() || son_obj->status == chain::son_status::in_maintenance) {
|
||||||
ilog("peerplays_sidechain_plugin: sending heartbeat");
|
ilog("peerplays_sidechain_plugin: sending heartbeat");
|
||||||
chain::son_heartbeat_operation op;
|
chain::son_heartbeat_operation op;
|
||||||
const auto& idx = d.get_index_type<chain::son_index>().indices().get<by_id>();
|
|
||||||
auto son_obj = idx.find( son_id );
|
|
||||||
op.owner_account = son_obj->son_account;
|
op.owner_account = son_obj->son_account;
|
||||||
op.son_id = son_id;
|
op.son_id = son_id;
|
||||||
op.ts = fc::time_point::now() + fc::seconds(0);
|
op.ts = fc::time_point::now() + fc::seconds(0);
|
||||||
|
|
|
||||||
|
|
@ -723,7 +723,40 @@ BOOST_AUTO_TEST_CASE( son_heartbeat_test ) {
|
||||||
generate_block();
|
generate_block();
|
||||||
trx.clear();
|
trx.clear();
|
||||||
BOOST_REQUIRE_EQUAL(son_stats_obj->current_interval_downtime, op.ts.sec_since_epoch() - son_stats_obj->last_down_timestamp.sec_since_epoch());
|
BOOST_REQUIRE_EQUAL(son_stats_obj->current_interval_downtime, op.ts.sec_since_epoch() - son_stats_obj->last_down_timestamp.sec_since_epoch());
|
||||||
downtime = op.ts.sec_since_epoch() - son_stats_obj->last_down_timestamp.sec_since_epoch();
|
downtime += op.ts.sec_since_epoch() - son_stats_obj->last_down_timestamp.sec_since_epoch();
|
||||||
|
BOOST_CHECK( obj->status == son_status::inactive);
|
||||||
|
BOOST_CHECK( son_stats_obj->last_active_timestamp == op.ts);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Modify SON's status to in_maintenance
|
||||||
|
db.modify( *obj, [&]( son_object& _s)
|
||||||
|
{
|
||||||
|
_s.status = son_status::in_maintenance;
|
||||||
|
});
|
||||||
|
|
||||||
|
// SON is selected as one of the active SONs
|
||||||
|
db.modify( db.get_global_properties(), [&]( global_property_object& _gpo )
|
||||||
|
{
|
||||||
|
son_info son_inf;
|
||||||
|
son_inf.son_id = son_id_type(0);
|
||||||
|
_gpo.active_sons.push_back(son_inf);
|
||||||
|
});
|
||||||
|
|
||||||
|
{
|
||||||
|
generate_block();
|
||||||
|
// Send Heartbeat for an in_maintenance SON
|
||||||
|
son_heartbeat_operation op;
|
||||||
|
op.owner_account = alice_id;
|
||||||
|
op.son_id = son_id_type(0);
|
||||||
|
op.ts = (db.head_block_time()+fc::seconds(2*db.block_interval()));
|
||||||
|
|
||||||
|
trx.operations.push_back(op);
|
||||||
|
sign(trx, alice_private_key);
|
||||||
|
PUSH_TX( db, trx, ~0);
|
||||||
|
generate_block();
|
||||||
|
trx.clear();
|
||||||
|
BOOST_REQUIRE_EQUAL(son_stats_obj->current_interval_downtime, downtime + op.ts.sec_since_epoch() - son_stats_obj->last_down_timestamp.sec_since_epoch());
|
||||||
|
downtime += op.ts.sec_since_epoch() - son_stats_obj->last_down_timestamp.sec_since_epoch();
|
||||||
BOOST_CHECK( obj->status == son_status::active);
|
BOOST_CHECK( obj->status == son_status::active);
|
||||||
BOOST_CHECK( son_stats_obj->last_active_timestamp == op.ts);
|
BOOST_CHECK( son_stats_obj->last_active_timestamp == op.ts);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue