Zilliqa / Zilliqa

Zilliqa is the world's first high-throughput public blockchain platform - designed to scale to thousands ​of transactions per second.
https://www.zilliqa.com
GNU General Public License v3.0
1.13k stars 280 forks source link

Implement state machine for `Node::SetState` #340

Open digiront opened 6 years ago

digiront commented 6 years ago

Problem

Regarding this:

void Node::SetState(NodeState state)
{
    m_state = state;
    LOG_EPOCH(INFO, to_string(m_mediator.m_currentEpochNum).c_str(),
              "Node State is now " << m_state << " at epoch "
                                   << m_mediator.m_currentEpochNum);
}

Setting a new state always succeeds. This implies it's the caller's responsibility to verify the state transition before calling Node::setState.

Suggestion

A state machine would simplify all setState callers by abstracting away the state transition logic. Given such a state machine, the caller just needs to know if the state was changed successfully. Another benefit is that this would simplify testing.

Resources

digiront commented 6 years ago

Based on this comment https://github.com/Zilliqa/Zilliqa/pull/326#issuecomment-398008302 this improvement also applies to