Merge branch 'issue-430' into 'develop'

Improved get_active_sons and get_son_network_status API/CLI [issue 430]

See merge request PBSA/peerplays!150
This commit is contained in:
serkixenos 2022-09-14 18:03:40 +00:00
commit e287d8a845
4 changed files with 167 additions and 51 deletions

View file

@ -184,6 +184,10 @@ public:
fc::optional<son_object> get_son_by_account(const std::string account_id_or_name) const;
map<string, son_id_type> lookup_son_accounts(const string &lower_bound_name, uint32_t limit) const;
uint64_t get_son_count() const;
flat_map<sidechain_type, vector<son_info>> get_active_sons();
vector<son_info> get_active_sons_by_sidechain(sidechain_type sidechain);
map<sidechain_type, map<son_id_type, string>> get_son_network_status();
map<son_id_type, string> get_son_network_status_by_sidechain(sidechain_type sidechain);
// SON wallets
optional<son_wallet_object> get_active_son_wallet();
@ -1848,6 +1852,80 @@ uint64_t database_api_impl::get_son_count() const {
return _db.get_index_type<son_index>().indices().size();
}
flat_map<sidechain_type, vector<son_info>> database_api::get_active_sons() {
return my->get_active_sons();
}
flat_map<sidechain_type, vector<son_info>> database_api_impl::get_active_sons() {
return get_global_properties().active_sons;
}
vector<son_info> database_api::get_active_sons_by_sidechain(sidechain_type sidechain) {
return my->get_active_sons_by_sidechain(sidechain);
}
vector<son_info> database_api_impl::get_active_sons_by_sidechain(sidechain_type sidechain) {
const global_property_object &gpo = get_global_properties();
vector<son_info> result;
if (gpo.active_sons.find(sidechain) != gpo.active_sons.end()) {
result = gpo.active_sons.at(sidechain);
}
return result;
}
map<sidechain_type, map<son_id_type, string>> database_api::get_son_network_status() {
return my->get_son_network_status();
}
map<sidechain_type, map<son_id_type, string>> database_api_impl::get_son_network_status() {
map<sidechain_type, map<son_id_type, string>> result;
for (auto active_sidechain_type : active_sidechain_types) {
result[active_sidechain_type] = get_son_network_status_by_sidechain(active_sidechain_type);
}
return result;
}
map<son_id_type, string> database_api::get_son_network_status_by_sidechain(sidechain_type sidechain) {
return my->get_son_network_status_by_sidechain(sidechain);
}
map<son_id_type, string> database_api_impl::get_son_network_status_by_sidechain(sidechain_type sidechain) {
const global_property_object &gpo = get_global_properties();
map<son_id_type, string> result;
if (gpo.active_sons.find(sidechain) != gpo.active_sons.end()) {
for (const auto si : gpo.active_sons.at(sidechain)) {
const auto son_obj = si.son_id(_db);
const auto sso = son_obj.statistics(_db);
string status;
if (sso.last_active_timestamp.find(sidechain) != sso.last_active_timestamp.end()) {
if (sso.last_active_timestamp.at(sidechain) + fc::seconds(gpo.parameters.son_heartbeat_frequency()) > time_point::now()) {
status = "OK, regular SON heartbeat";
} else {
if (sso.last_active_timestamp.at(sidechain) + fc::seconds(gpo.parameters.son_down_time()) > time_point::now()) {
status = "OK, irregular SON heartbeat, but not triggering SON down proposal";
} else {
status = "NOT OK, irregular SON heartbeat, triggering SON down proposal]";
}
}
} else {
status = "No heartbeats sent";
}
result[si.son_id] = status;
}
}
return result;
}
//////////////////////////////////////////////////////////////////////
// //
// SON Wallets //

View file

@ -675,6 +675,32 @@ public:
*/
uint64_t get_son_count() const;
/**
* @brief Get list of active sons
* @return List of active SONs
*/
flat_map<sidechain_type, vector<son_info>> get_active_sons();
/**
* @brief Get list of active sons
* @param sidechain Sidechain type [bitcoin|ethereum|hive]
* @return List of active SONs
*/
vector<son_info> get_active_sons_by_sidechain(sidechain_type sidechain);
/**
* @brief Get SON network status
* @return SON network status description for a given sidechain type
*/
map<sidechain_type, map<son_id_type, string>> get_son_network_status();
/**
* @brief Get SON network status
* @param sidechain Sidechain type [bitcoin|ethereum|hive]
* @return SON network status description for a given sidechain type
*/
map<son_id_type, string> get_son_network_status_by_sidechain(sidechain_type sidechain);
/////////////////////////
// SON Wallets //
/////////////////////////
@ -1149,6 +1175,10 @@ FC_API(graphene::app::database_api,
(get_son_by_account)
(lookup_son_accounts)
(get_son_count)
(get_active_sons)
(get_active_sons_by_sidechain)
(get_son_network_status)
(get_son_network_status_by_sidechain)
// SON wallets
(get_active_son_wallet)

View file

@ -1377,10 +1377,30 @@ class wallet_api
map<string, son_id_type> list_active_sons();
/**
* @brief Get SON network status
* @return SON network status description
* @brief Get list of active sons
* @return List of active SONs
*/
map<son_id_type, string> get_son_network_status();
flat_map<sidechain_type, vector<son_info>> get_active_sons();
/**
* @brief Get list of active sons
* @param sidechain Sidechain type [bitcoin|ethereum|hive]
* @return List of active SONs
*/
vector<son_info> get_active_sons_by_sidechain(sidechain_type sidechain);
/**
* @brief Get SON network status
* @return SON network status description for a given sidechain type
*/
map<sidechain_type, map<son_id_type, string>> get_son_network_status();
/**
* @brief Get SON network status
* @param sidechain Sidechain type [bitcoin|ethereum|hive]
* @return SON network status description for a given sidechain type
*/
map<son_id_type, string> get_son_network_status_by_sidechain(sidechain_type sidechain);
/**
* @brief Get active SON wallet
@ -2599,7 +2619,10 @@ FC_API( graphene::wallet::wallet_api,
(activate_deregistered_son)
(list_sons)
(list_active_sons)
(get_active_sons)
(get_active_sons_by_sidechain)
(get_son_network_status)
(get_son_network_status_by_sidechain)
(request_son_maintenance)
(cancel_request_son_maintenance)
(get_active_son_wallet)

View file

@ -2274,55 +2274,25 @@ public:
FC_CAPTURE_AND_RETHROW()
}
//! Fixme - do we need to specify sidechain_type as params here?
map<son_id_type, string> get_son_network_status()
{
try
{
const global_property_object& gpo = get_global_properties();
flat_map<sidechain_type, vector<son_info>> get_active_sons()
{ try {
return _remote_db->get_active_sons();
} FC_CAPTURE_AND_RETHROW() }
set<son_id_type> son_ids_set;
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(son_ids_set, son_ids_set.end()),
[](const son_info &swi) {
return swi.son_id;
});
}
vector<son_id_type> son_ids;
son_ids.reserve(son_ids_set.size());
std::transform(son_ids_set.cbegin(), son_ids_set.cend(),
std::inserter(son_ids, son_ids.end()),
[](const son_id_type& sit) {
return sit;
});
vector<son_info> get_active_sons_by_sidechain(sidechain_type sidechain)
{ try {
return _remote_db->get_active_sons_by_sidechain(sidechain);
} FC_CAPTURE_AND_RETHROW() }
map<son_id_type, string> result;
std::vector<fc::optional<son_object>> son_objects = _remote_db->get_sons(son_ids);
for(auto son_obj: son_objects) {
string status;
if (son_obj) {
son_statistics_object sso = get_object(son_obj->statistics);
for(const auto& active_sidechain_type : active_sidechain_types) {
if (sso.last_active_timestamp.at(active_sidechain_type) + fc::seconds(gpo.parameters.son_heartbeat_frequency()) > time_point::now()) {
status = "[OK, regular SON heartbeat for sidechain " + std::to_string(static_cast<unsigned int>(active_sidechain_type)) + "] ";
} else {
if (sso.last_active_timestamp.at(active_sidechain_type) + fc::seconds(gpo.parameters.son_down_time()) > time_point::now()) {
status = "[OK, irregular SON heartbeat, but not triggering SON down proposal for sidechain " + std::to_string(static_cast<unsigned int>(active_sidechain_type)) + "] ";
} else {
status = "[NOT OK, irregular SON heartbeat, triggering SON down proposal for sidechain " + std::to_string(static_cast<unsigned int>(active_sidechain_type)) + "] ";
}
}
}
} else {
status = "NOT OK, invalid SON id";
}
result[son_obj->id] = status;
}
return result;
}
FC_CAPTURE_AND_RETHROW()
}
map<sidechain_type, map<son_id_type, string>> get_son_network_status()
{ try {
return _remote_db->get_son_network_status();
} FC_CAPTURE_AND_RETHROW() }
map<son_id_type, string> get_son_network_status_by_sidechain(sidechain_type sidechain)
{ try {
return _remote_db->get_son_network_status_by_sidechain(sidechain);
} FC_CAPTURE_AND_RETHROW() }
optional<son_wallet_object> get_active_son_wallet()
{ try {
@ -5310,11 +5280,26 @@ map<string, son_id_type> wallet_api::list_active_sons()
return my->list_active_sons();
}
map<son_id_type, string> wallet_api::get_son_network_status()
flat_map<sidechain_type, vector<son_info>> wallet_api::get_active_sons()
{
return my->get_active_sons();
}
vector<son_info> wallet_api::get_active_sons_by_sidechain(sidechain_type sidechain)
{
return my->get_active_sons_by_sidechain(sidechain);
}
map<sidechain_type, map<son_id_type, string>> wallet_api::get_son_network_status()
{
return my->get_son_network_status();
}
map<son_id_type, string> wallet_api::get_son_network_status_by_sidechain(sidechain_type sidechain)
{
return my->get_son_network_status_by_sidechain(sidechain);
}
optional<son_wallet_object> wallet_api::get_active_son_wallet()
{
return my->get_active_son_wallet();