Observer mode fix (#78)

* Fixed observer mode consensus issues.
* Added startup_mode to fix mode change check.
This commit is contained in:
Ravin Perera
2020-01-17 11:04:45 +05:30
committed by GitHub
parent f8dd2e014b
commit 8cf869cf9e
4 changed files with 42 additions and 40 deletions

View File

@@ -132,6 +132,7 @@ void consensus()
// In stage 0 we create a novel proposal and broadcast it.
const p2p::proposal stg_prop = create_stage0_proposal();
broadcast_proposal(stg_prop);
}
else // Stage 1, 2, 3
@@ -205,8 +206,8 @@ void consensus()
}
else
{
//Node is in sync with current lcl ->switch to proposing mode.
conf::change_operating_mode(conf::OPERATING_MODE::PROPOSING);
//Node is in sync with current lcl ->switch to proposer mode.
conf::change_operating_mode(conf::OPERATING_MODE::PROPOSER);
}
if (ctx.stage == 1 || (ctx.stage == 3 && ctx.is_state_syncing))
@@ -216,6 +217,7 @@ void consensus()
{
// In stage 1, 2, 3 we vote for incoming proposals and promote winning votes based on thresholds.
const p2p::proposal stg_prop = create_stage123_proposal(votes);
broadcast_proposal(stg_prop);
if (ctx.stage == 3)
@@ -586,8 +588,8 @@ p2p::proposal create_stage123_proposal(vote_counter &votes)
*/
void broadcast_proposal(const p2p::proposal &p)
{
// In observing mode, we do not send out any proposals.
if (conf::cfg.mode == conf::OPERATING_MODE::OBSERVING)
// In observer mode, we do not send out any proposals.
if (conf::cfg.current_mode == conf::OPERATING_MODE::OBSERVER)
return;
p2p::peer_outbound_message msg(std::make_shared<flatbuffers::FlatBufferBuilder>(1024));
@@ -658,11 +660,11 @@ void check_lcl_votes(bool &is_desync, bool &should_request_history, std::string
if (total_lcl_votes < (MAJORITY_THRESHOLD * conf::cfg.unl.size()))
{
LOG_DBG << "Not enough peers proposing to perform consensus votes:" << std::to_string(total_lcl_votes) << " needed:" << std::to_string(MAJORITY_THRESHOLD * conf::cfg.unl.size());
LOG_DBG << "Not enough peers proposer to perform consensus votes:" << std::to_string(total_lcl_votes) << " needed:" << std::to_string(MAJORITY_THRESHOLD * conf::cfg.unl.size());
is_desync = true;
//Not enough nodes are propsing. So Node is switching to Proposing if it's in observing mode.
conf::change_operating_mode(conf::OPERATING_MODE::PROPOSING);
//Not enough nodes are propsing. So Node is switching to Proposer if it's in observer mode.
conf::change_operating_mode(conf::OPERATING_MODE::PROPOSER);
return;
}
@@ -685,8 +687,8 @@ void check_lcl_votes(bool &is_desync, bool &should_request_history, std::string
LOG_DBG << "We are not on the consensus ledger, requesting history from a random peer";
is_desync = true;
//Node is in not sync with current lcl ->switch to observing mode.
conf::change_operating_mode(conf::OPERATING_MODE::OBSERVING);
//Node is not in sync with current lcl ->switch to observer mode.
conf::change_operating_mode(conf::OPERATING_MODE::OBSERVER);
should_request_history = true;
return;
@@ -896,8 +898,8 @@ void check_state(vote_counter &votes)
{
if (ctx.state_sync_lcl != ctx.lcl)
{
// Change the mode to passive and not sending out proposals till the state is synced
conf::change_operating_mode(conf::OPERATING_MODE::OBSERVING);
// Switch to observer mode to avoid sending out proposals till the state is synced
conf::change_operating_mode(conf::OPERATING_MODE::OBSERVER);
const hasher::B2H majority_state_hash = *reinterpret_cast<const hasher::B2H *>(majority_state.c_str());
LOG_INFO << "Starting state sync. Curr state:" << *reinterpret_cast<const hasher::B2H *>(ctx.curr_hash_state.c_str()) << " majority:" << majority_state_hash;
@@ -914,7 +916,7 @@ void check_state(vote_counter &votes)
ctx.is_state_syncing = false;
ctx.state_sync_lcl.clear();
conf::change_operating_mode(conf::OPERATING_MODE::PROPOSING);
conf::change_operating_mode(conf::OPERATING_MODE::PROPOSER);
}
}