Skip to content

Commit

Permalink
Fix the bug that consensus timer can be triggered without proposal
Browse files Browse the repository at this point in the history
Signed-off-by: Yilun <[email protected]>
  • Loading branch information
yilunzhang committed Aug 26, 2020
1 parent 5a10c39 commit 8e0a2c5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cmd/nknd/nknd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
9 changes: 7 additions & 2 deletions consensus/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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")
}
}
}
Expand Down

0 comments on commit 8e0a2c5

Please sign in to comment.