From 64519e25d8c31d27b6ee81f4f94f6c8959c155ef Mon Sep 17 00:00:00 2001 From: pinkiebell <40266861+pinkiebell@users.noreply.github.com> Date: Sat, 13 Apr 2019 20:34:25 +0200 Subject: [PATCH] Fix consensus stalling after readOnly switch Consensus stalls if there are no other validators in the network and the validator is switched from readOnly=true back to readOnly=false. Fixes #3 --- consensus/state.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/consensus/state.go b/consensus/state.go index 83a6568deb0..2bf69fb7e13 100644 --- a/consensus/state.go +++ b/consensus/state.go @@ -781,8 +781,17 @@ func (cs *ConsensusState) handleTxsAvailable() { } func (cs *ConsensusState) SetReadonly(readonly bool) { - cs.readonly = readonly cs.Logger.Info("[SetReadonly]: Set to " + strconv.FormatBool(readonly) + " " + strconv.FormatBool(cs.readonly)) + cs.mtx.Lock() + cs.readonly = readonly + cs.mtx.Unlock() + + if (!cs.readonly) { + if (cs.LastCommit.HasAll()) { + // Fix consensus stalling after readOnly switch with no other validators in the network + cs.scheduleTimeout(5000, cs.Height, cs.Round, cstypes.RoundStepPrevoteWait) + } + } } func (cs *ConsensusState) IsReadonly() bool {