From 8e0a2c5ec4c3194b5e4278cc24ae3b9d363a113e Mon Sep 17 00:00:00 2001 From: Yilun Date: Wed, 26 Aug 2020 12:13:38 -0700 Subject: [PATCH] Fix the bug that consensus timer can be triggered without proposal Signed-off-by: Yilun --- cmd/nknd/nknd.go | 2 +- consensus/proposal.go | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/cmd/nknd/nknd.go b/cmd/nknd/nknd.go index 6a62cf044..81ffd510e 100644 --- a/cmd/nknd/nknd.go +++ b/cmd/nknd/nknd.go @@ -44,7 +44,7 @@ import ( ) const ( - NetVersionNum = 17 // This is temporary and will be removed soon after mainnet is stabilized + NetVersionNum = 18 // This is temporary and will be removed soon after mainnet is stabilized ) var ( diff --git a/consensus/proposal.go b/consensus/proposal.go index 135b57aa3..e71bb0e74 100644 --- a/consensus/proposal.go +++ b/consensus/proposal.go @@ -95,9 +95,11 @@ func (consensus *Consensus) waitAndHandleProposal() (*election.Election, error) } } + proposalCount := 0 for { select { case proposal := <-proposalChan: + proposalCount++ blockHash := proposal.Hash() if !consensus.canVerifyHeight(consensusHeight) { @@ -180,10 +182,13 @@ func (consensus *Consensus) waitAndHandleProposal() (*election.Election, error) } case <-electionStartTimer.C: - return elc, nil + if proposalCount > 0 { + return elc, nil + } + return nil, errors.New("election wait for proposal timeout") case <-timeoutTimer.C: - return nil, errors.New("Wait for proposal timeout") + return nil, errors.New("wait for proposal timeout") } } }