Save blocks on catch-up too.

This commit is contained in:
Jae Kwon 2014-12-31 16:46:49 -08:00
parent 0dac36aa5d
commit d20251849e
2 changed files with 14 additions and 4 deletions

View File

@ -280,7 +280,7 @@ OUTER_LOOP:
}
// If the peer is on a previous height, help catch up.
if rs.Height > prs.Height {
if 0 < prs.Height && prs.Height < rs.Height {
log.Debug("Data catchup", "height", rs.Height, "peerHeight", prs.Height)
if index, ok := prs.ProposalBlockBitArray.Not().PickRandom(); ok {
// Ensure that the peer's PartSetHeaeder is correct

View File

@ -237,9 +237,10 @@ type ConsensusState struct {
mtx sync.Mutex
RoundState
state *state.State // State until height-1.
stagedBlock *Block // Cache last staged block.
stagedState *state.State // Cache result of staged block.
state *state.State // State until height-1.
stagedBlock *Block // Cache last staged block.
stagedState *state.State // Cache result of staged block.
lastCommittedHeight uint // Last called saveCommitVoteBlock() on.
}
func NewConsensusState(state *state.State, blockStore *BlockStore, mempoolReactor *mempool.MempoolReactor) *ConsensusState {
@ -828,6 +829,8 @@ func (cs *ConsensusState) TryFinalizeCommit(height uint) bool {
err := cs.stageBlock(cs.ProposalBlock, cs.ProposalBlockParts)
if err == nil {
log.Debug(Fmt("Finalizing commit of block: %v", cs.ProposalBlock))
// We have the block, so save/stage/sign-commit-vote.
cs.saveCommitVoteBlock(cs.ProposalBlock, cs.ProposalBlockParts)
// Increment height.
cs.updateToState(cs.stagedState)
// cs.Step is now RoundStepNewHeight or RoundStepNewRound
@ -1038,6 +1041,13 @@ func (cs *ConsensusState) signAddVote(type_ byte, hash []byte, header PartSetHea
func (cs *ConsensusState) saveCommitVoteBlock(block *Block, blockParts *PartSet) {
// Only run once per height.
if cs.lastCommittedHeight >= block.Height {
return
} else {
cs.lastCommittedHeight = block.Height
}
// The proposal must be valid.
if err := cs.stageBlock(block, blockParts); err != nil {
// Prevent zombies.