Skip to content

Commit

Permalink
Proposer will only propose once per round
Browse files Browse the repository at this point in the history
Signed-off-by: Yilun <[email protected]>
  • Loading branch information
yilunzhang authored and gdmmx committed Feb 17, 2019
1 parent d039dcb commit 8abae27
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion consensus/moca/proposing.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ import (

// startProposing starts the proposing routing
func (consensus *Consensus) startProposing() {
var lastProposedHeight uint32
proposingTimer := time.NewTimer(proposingStartDelay)
for {
select {
case <-proposingTimer.C:
currentHeight := ledger.DefaultLedger.Store.GetHeight()
expectedHeight := consensus.GetExpectedHeight()
timestamp := time.Now().Unix()
if expectedHeight == currentHeight+1 && consensus.isBlockProposer(currentHeight, timestamp) {
if expectedHeight > lastProposedHeight && expectedHeight == currentHeight+1 && consensus.isBlockProposer(currentHeight, timestamp) {
log.Infof("I am the block proposer at height %d", expectedHeight)

block, err := consensus.proposeBlock(expectedHeight, timestamp)
Expand All @@ -36,6 +37,7 @@ func (consensus *Consensus) startProposing() {
break
}

lastProposedHeight = expectedHeight
time.Sleep(electionStartDelay)
}
}
Expand Down

0 comments on commit 8abae27

Please sign in to comment.