From 8abae27e8160caab4a58283ad8a5a0fddd11e27e Mon Sep 17 00:00:00 2001 From: Yilun Date: Sat, 16 Feb 2019 21:37:14 -0800 Subject: [PATCH] Proposer will only propose once per round Signed-off-by: Yilun --- consensus/moca/proposing.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/consensus/moca/proposing.go b/consensus/moca/proposing.go index 722a268de..864e22773 100644 --- a/consensus/moca/proposing.go +++ b/consensus/moca/proposing.go @@ -11,6 +11,7 @@ import ( // startProposing starts the proposing routing func (consensus *Consensus) startProposing() { + var lastProposedHeight uint32 proposingTimer := time.NewTimer(proposingStartDelay) for { select { @@ -18,7 +19,7 @@ func (consensus *Consensus) startProposing() { 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) @@ -36,6 +37,7 @@ func (consensus *Consensus) startProposing() { break } + lastProposedHeight = expectedHeight time.Sleep(electionStartDelay) } }