internal/consensus: enforce proposer waits in state machine

This commit is contained in:
William Banfield
2021-11-30 18:55:15 -05:00
parent 9e76e604dd
commit 43cf2a43fb

View File

@@ -1069,9 +1069,10 @@ func (cs *State) enterNewRound(height int64, round int32) {
cs.scheduleTimeout(cs.config.CreateEmptyBlocksInterval, height, round,
cstypes.RoundStepNewRound)
}
} else {
cs.enterPropose(height, round)
return
}
cs.enterPropose(height, round)
}
// needProofBlock returns true on the first height (so the genesis app hash is signed right away)
@@ -1104,6 +1105,16 @@ func (cs *State) enterPropose(height int64, round int32) {
return
}
ourAddress := cs.privValidatorPubKey.Address()
if cs.isProposer(ourAddress) {
proposerWaitTime := proposerWaitTime(tmtime.DefaultSource{}, cs.state.LastBlockTime)
if proposerWaitTime > 0 {
fmt.Println("scheduling a wait!")
cs.scheduleTimeout(proposerWaitTime, height, round, cstypes.RoundStepNewRound)
return
}
}
logger.Debug("entering propose step", "current", fmt.Sprintf("%v/%v/%v", cs.Height, cs.Round, cs.Step))
defer func() {
@@ -1141,18 +1152,16 @@ func (cs *State) enterPropose(height int64, round int32) {
return
}
address := cs.privValidatorPubKey.Address()
// if not a validator, we're done
if !cs.Validators.HasAddress(address) {
logger.Debug("node is not a validator", "addr", address, "vals", cs.Validators)
if !cs.Validators.HasAddress(ourAddress) {
logger.Debug("node is not a validator", "addr", ourAddress, "vals", cs.Validators)
return
}
if cs.isProposer(address) {
if cs.isProposer(ourAddress) {
logger.Debug(
"propose step; our turn to propose",
"proposer", address,
"proposer", ourAddress,
)
cs.decideProposal(height, round)