CreateEmptyBlocks and CreateEmptyBlocksInterval

This commit is contained in:
Ethan Buchman
2017-08-04 21:46:17 -04:00
parent fb47ca6d35
commit 37f1390473
7 changed files with 34 additions and 13 deletions

View File

@ -718,6 +718,8 @@ func (cs *ConsensusState) handleTimeout(ti timeoutInfo, rs RoundState) {
// NewRound event fired from enterNewRound.
// XXX: should we fire timeout here (for timeout commit)?
cs.enterNewRound(ti.Height, 0)
case RoundStepNewRound:
cs.enterPropose(ti.Height, 0)
case RoundStepPropose:
types.FireEventTimeoutPropose(cs.evsw, cs.RoundStateEvent())
cs.enterPrevote(ti.Height, ti.Round)
@ -790,8 +792,11 @@ func (cs *ConsensusState) enterNewRound(height int, round int) {
// Wait for txs to be available in the mempool
// before we enterPropose in round 0. If the last block changed the app hash,
// we may need an empty "proof" block, and enterPropose immediately.
waitForTxs := cs.config.NoEmptyBlocks && round == 0 && !cs.needProofBlock(height)
waitForTxs := cs.config.WaitForTxs() && round == 0 && !cs.needProofBlock(height)
if waitForTxs {
if cs.config.CreateEmptyBlocksInterval > 0 {
cs.scheduleTimeout(cs.config.EmptyBlocks(), height, round, RoundStepNewRound)
}
go cs.proposalHeartbeat(height, round)
} else {
cs.enterPropose(height, round)
@ -841,8 +846,9 @@ func (cs *ConsensusState) proposalHeartbeat(height, round int) {
}
}
// Enter (!NoEmptyBlocks): from enterNewRound(height,round)
// Enter (NoEmptyBlocks) : after enterNewRound(height,round), once txs are in the mempool
// Enter (CreateEmptyBlocks): from enterNewRound(height,round)
// Enter (CreateEmptyBlocks, CreateEmptyBlocksInterval > 0 ): after enterNewRound(height,round), after timeout of CreateEmptyBlocksInterval
// Enter (!CreateEmptyBlocks) : after enterNewRound(height,round), once txs are in the mempool
func (cs *ConsensusState) enterPropose(height int, round int) {
if cs.Height != height || round < cs.Round || (cs.Round == round && RoundStepPropose <= cs.Step) {
cs.Logger.Debug(cmn.Fmt("enterPropose(%v/%v): Invalid args. Current step: %v/%v/%v", height, round, cs.Height, cs.Round, cs.Step))