Fixed wrong commit handling.
block was not finalized if block was received after entering commit
step.
@@ -193,7 +193,7 @@ func (cs *consensus) receiveBlockPart(msg *blockPartMessage) (bool, error) {
if cs.step == stepPropose && cs.isProposalAndPOLPrevotesComplete() {
cs.enterPrevote()
} else if cs.step == stepCommit && cs.currentBlockParts.IsComplete() {
- cs.enterNewHeight()
+ cs.commitAndEnterNewHeight()
}
return true, nil
}
@@ -511,17 +511,7 @@ func (cs *consensus) enterPrecommitWait() {
}
}
-func (cs *consensus) enterCommit(partSetID *PartSetID) {
- cs.resetForNewStep()
- cs.setStep(stepCommit)
- cs.nextProposeTime = time.Now().Add(timeoutCommit)
-
- if !cs.currentBlockParts.ID().Equal(partSetID) {
- cs.currentBlockParts = &blockPartSet{
- PartSet: newPartSetFromID(partSetID),
- }
- }
- if cs.currentBlockParts.IsComplete() {
+func (cs *consensus) commitAndEnterNewHeight() {
if !cs.currentBlockParts.noImport {
hrs := cs.hrs
_, err := cs.bm.Import(
@@ -531,31 +521,45 @@ func (cs *consensus) enterCommit(partSetID *PartSetID) {
defer cs.mutex.Unlock()
if cs.hrs != hrs {
- return
+ logger.Panicf("commitAndEnterNewHeight: bad cs.hrs=%v\n", cs.hrs)
}
if err != nil {
- panic(err)
+ logger.Panicf("commitAndEnterNewHeight: %v\n", err)
}
cs.currentBlockParts.noImport = true
err = cs.bm.Finalize(cs.currentBlockParts.block)
if err != nil {
- logger.Panicf("enterCommit: %v\n", err)
+ logger.Panicf("commitAndEnterNewHeight: %v\n", err)
}
cs.enterNewHeight()
},
)
if err != nil {
- logger.Panicf("enterCommit: %v\n", err)
+ logger.Panicf("commitAndEnterNewHeight: %v\n", err)
}
} else {
err := cs.bm.Finalize(cs.currentBlockParts.block)
if err != nil {
- logger.Panicf("enterCommit: %v\n", err)
+ logger.Panicf("commitAndEnterNewHeight: %v\n", err)
}
cs.enterNewHeight()
}
}
+
+func (cs *consensus) enterCommit(partSetID *PartSetID) {
+ cs.resetForNewStep()
+ cs.setStep(stepCommit)
+ cs.nextProposeTime = time.Now().Add(timeoutCommit)
+
+ if !cs.currentBlockParts.ID().Equal(partSetID) {
+ cs.currentBlockParts = &blockPartSet{
+ PartSet: newPartSetFromID(partSetID),
+ }
+ }
+ if cs.currentBlockParts.IsComplete() {
+ cs.commitAndEnterNewHeight()
+ }
}
func (cs *consensus) enterNewHeight() {
