Refactored vote status reporting. (#349)

* Refactored global sync status tracking.
* Updated streamer for vote status.
* Docker image now uses 'latest' tag.
* Updated hp version.
This commit is contained in:
Ravin Perera
2021-09-22 09:28:01 +05:30
committed by GitHub
parent 6dc0776b56
commit 647759501f
16 changed files with 99 additions and 98 deletions

View File

@@ -12,9 +12,8 @@ namespace status
util::sequence_hash lcl_id; // Last ledger id/hash pair.
ledger::ledger_record last_ledger; // Last ledger record that the node created.
// Indicates whether this node is in sync with other nodes or not.
// -1=unknown, 0=not-in-sync, 1=in-sync
std::atomic<int> in_sync = -1;
// Indicates the current voting status.
std::atomic<VOTE_STATUS> vote_status = VOTE_STATUS::UNKNOWN;
std::shared_mutex unl_mutex;
std::set<std::string> unl; // List of last reported unl binary pubkeys.
@@ -38,23 +37,18 @@ namespace status
void ledger_created(const util::sequence_hash &ledger_id, const ledger::ledger_record &ledger)
{
// If currently not-in-sync, report it as in-sync when a ledger is created.
if (in_sync.load() != 1)
sync_status_changed(true);
std::unique_lock lock(ledger_mutex);
lcl_id = ledger_id;
last_ledger = ledger;
event_queue.try_enqueue(ledger_created_event{ledger});
}
void sync_status_changed(const bool new_in_sync)
void set_vote_status(const VOTE_STATUS new_status)
{
const int new_value = new_in_sync ? 1 : 0;
if (new_value != in_sync.load())
if (new_status != vote_status.load())
{
in_sync = new_value;
event_queue.try_enqueue(sync_status_change_event{new_in_sync});
vote_status = new_status;
event_queue.try_enqueue(vote_status_change_event{new_status});
}
}
@@ -64,9 +58,9 @@ namespace status
return lcl_id;
}
const bool is_in_sync()
VOTE_STATUS get_vote_status()
{
return in_sync.load() == 1;
return vote_status.load();
}
const ledger::ledger_record get_last_ledger()
@@ -119,7 +113,7 @@ namespace status
return peers;
}
const size_t get_peers_count()
size_t get_peers_count()
{
return peer_count.load();
}
@@ -135,7 +129,7 @@ namespace status
}
}
const bool get_weakly_connected()
bool get_weakly_connected()
{
return weakly_connected.load();
}
@@ -145,7 +139,7 @@ namespace status
available_mesh_capacity = new_capacity;
}
const int16_t get_available_mesh_capacity()
int16_t get_available_mesh_capacity()
{
return available_mesh_capacity.load();
}