|
@ -20,7 +20,8 @@ import ( |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
var ( |
|
|
var ( |
|
|
timeoutPropose = 3000 * time.Millisecond // Maximum duration of RoundStepPropose
|
|
|
|
|
|
|
|
|
timeoutPropose0 = 3000 * time.Millisecond // Wait this long for a proposal
|
|
|
|
|
|
timeoutProposeDelta = 0500 * time.Millisecond // timeoutProposeN is timeoutPropose0 + timeoutProposeDelta*N
|
|
|
timeoutPrevote0 = 1000 * time.Millisecond // After any +2/3 prevotes received, wait this long for stragglers.
|
|
|
timeoutPrevote0 = 1000 * time.Millisecond // After any +2/3 prevotes received, wait this long for stragglers.
|
|
|
timeoutPrevoteDelta = 0500 * time.Millisecond // timeoutPrevoteN is timeoutPrevote0 + timeoutPrevoteDelta*N
|
|
|
timeoutPrevoteDelta = 0500 * time.Millisecond // timeoutPrevoteN is timeoutPrevote0 + timeoutPrevoteDelta*N
|
|
|
timeoutPrecommit0 = 1000 * time.Millisecond // After any +2/3 precommits received, wait this long for stragglers.
|
|
|
timeoutPrecommit0 = 1000 * time.Millisecond // After any +2/3 precommits received, wait this long for stragglers.
|
|
@ -687,9 +688,6 @@ func (cs *ConsensusState) enterNewRound(height int, round int) { |
|
|
|
|
|
|
|
|
// Enter: from NewRound(height,round).
|
|
|
// Enter: from NewRound(height,round).
|
|
|
func (cs *ConsensusState) enterPropose(height int, round int) { |
|
|
func (cs *ConsensusState) enterPropose(height int, round int) { |
|
|
// cs.mtx.Lock()
|
|
|
|
|
|
// cs.mtx.Unlock()
|
|
|
|
|
|
|
|
|
|
|
|
if cs.Height != height || round < cs.Round || (cs.Round == round && RoundStepPropose <= cs.Step) { |
|
|
if cs.Height != height || round < cs.Round || (cs.Round == round && RoundStepPropose <= cs.Step) { |
|
|
log.Debug(Fmt("enterPropose(%v/%v): Invalid args. Current step: %v/%v/%v", height, round, cs.Height, cs.Round, cs.Step)) |
|
|
log.Debug(Fmt("enterPropose(%v/%v): Invalid args. Current step: %v/%v/%v", height, round, cs.Height, cs.Round, cs.Step)) |
|
|
return |
|
|
return |
|
@ -710,7 +708,7 @@ func (cs *ConsensusState) enterPropose(height int, round int) { |
|
|
}() |
|
|
}() |
|
|
|
|
|
|
|
|
// This step times out after `timeoutPropose`
|
|
|
// This step times out after `timeoutPropose`
|
|
|
cs.scheduleTimeout(timeoutPropose, height, round, RoundStepPropose) |
|
|
|
|
|
|
|
|
cs.scheduleTimeout(timeoutPropose0+timeoutProposeDelta*time.Duration(round), height, round, RoundStepPropose) |
|
|
|
|
|
|
|
|
// Nothing more to do if we're not a validator
|
|
|
// Nothing more to do if we're not a validator
|
|
|
if cs.privValidator == nil { |
|
|
if cs.privValidator == nil { |
|
@ -837,8 +835,6 @@ func (cs *ConsensusState) createProposalBlock() (block *types.Block, blockParts |
|
|
// Prevote for LockedBlock if we're locked, or ProposalBlock if valid.
|
|
|
// Prevote for LockedBlock if we're locked, or ProposalBlock if valid.
|
|
|
// Otherwise vote nil.
|
|
|
// Otherwise vote nil.
|
|
|
func (cs *ConsensusState) enterPrevote(height int, round int) { |
|
|
func (cs *ConsensusState) enterPrevote(height int, round int) { |
|
|
//cs.mtx.Lock()
|
|
|
|
|
|
//defer cs.mtx.Unlock()
|
|
|
|
|
|
if cs.Height != height || round < cs.Round || (cs.Round == round && RoundStepPrevote <= cs.Step) { |
|
|
if cs.Height != height || round < cs.Round || (cs.Round == round && RoundStepPrevote <= cs.Step) { |
|
|
log.Debug(Fmt("enterPrevote(%v/%v): Invalid args. Current step: %v/%v/%v", height, round, cs.Height, cs.Round, cs.Step)) |
|
|
log.Debug(Fmt("enterPrevote(%v/%v): Invalid args. Current step: %v/%v/%v", height, round, cs.Height, cs.Round, cs.Step)) |
|
|
return |
|
|
return |
|
@ -902,8 +898,6 @@ func (cs *ConsensusState) doPrevote(height int, round int) { |
|
|
|
|
|
|
|
|
// Enter: any +2/3 prevotes at next round.
|
|
|
// Enter: any +2/3 prevotes at next round.
|
|
|
func (cs *ConsensusState) enterPrevoteWait(height int, round int) { |
|
|
func (cs *ConsensusState) enterPrevoteWait(height int, round int) { |
|
|
//cs.mtx.Lock()
|
|
|
|
|
|
//defer cs.mtx.Unlock()
|
|
|
|
|
|
if cs.Height != height || round < cs.Round || (cs.Round == round && RoundStepPrevoteWait <= cs.Step) { |
|
|
if cs.Height != height || round < cs.Round || (cs.Round == round && RoundStepPrevoteWait <= cs.Step) { |
|
|
log.Debug(Fmt("enterPrevoteWait(%v/%v): Invalid args. Current step: %v/%v/%v", height, round, cs.Height, cs.Round, cs.Step)) |
|
|
log.Debug(Fmt("enterPrevoteWait(%v/%v): Invalid args. Current step: %v/%v/%v", height, round, cs.Height, cs.Round, cs.Step)) |
|
|
return |
|
|
return |
|
@ -930,8 +924,6 @@ func (cs *ConsensusState) enterPrevoteWait(height int, round int) { |
|
|
// else, unlock an existing lock and precommit nil if +2/3 of prevotes were nil,
|
|
|
// else, unlock an existing lock and precommit nil if +2/3 of prevotes were nil,
|
|
|
// else, precommit nil otherwise.
|
|
|
// else, precommit nil otherwise.
|
|
|
func (cs *ConsensusState) enterPrecommit(height int, round int) { |
|
|
func (cs *ConsensusState) enterPrecommit(height int, round int) { |
|
|
//cs.mtx.Lock()
|
|
|
|
|
|
// defer cs.mtx.Unlock()
|
|
|
|
|
|
if cs.Height != height || round < cs.Round || (cs.Round == round && RoundStepPrecommit <= cs.Step) { |
|
|
if cs.Height != height || round < cs.Round || (cs.Round == round && RoundStepPrecommit <= cs.Step) { |
|
|
log.Debug(Fmt("enterPrecommit(%v/%v): Invalid args. Current step: %v/%v/%v", height, round, cs.Height, cs.Round, cs.Step)) |
|
|
log.Debug(Fmt("enterPrecommit(%v/%v): Invalid args. Current step: %v/%v/%v", height, round, cs.Height, cs.Round, cs.Step)) |
|
|
return |
|
|
return |
|
@ -1027,8 +1019,6 @@ func (cs *ConsensusState) enterPrecommit(height int, round int) { |
|
|
|
|
|
|
|
|
// Enter: any +2/3 precommits for next round.
|
|
|
// Enter: any +2/3 precommits for next round.
|
|
|
func (cs *ConsensusState) enterPrecommitWait(height int, round int) { |
|
|
func (cs *ConsensusState) enterPrecommitWait(height int, round int) { |
|
|
//cs.mtx.Lock()
|
|
|
|
|
|
//defer cs.mtx.Unlock()
|
|
|
|
|
|
if cs.Height != height || round < cs.Round || (cs.Round == round && RoundStepPrecommitWait <= cs.Step) { |
|
|
if cs.Height != height || round < cs.Round || (cs.Round == round && RoundStepPrecommitWait <= cs.Step) { |
|
|
log.Debug(Fmt("enterPrecommitWait(%v/%v): Invalid args. Current step: %v/%v/%v", height, round, cs.Height, cs.Round, cs.Step)) |
|
|
log.Debug(Fmt("enterPrecommitWait(%v/%v): Invalid args. Current step: %v/%v/%v", height, round, cs.Height, cs.Round, cs.Step)) |
|
|
return |
|
|
return |
|
@ -1051,8 +1041,6 @@ func (cs *ConsensusState) enterPrecommitWait(height int, round int) { |
|
|
|
|
|
|
|
|
// Enter: +2/3 precommits for block
|
|
|
// Enter: +2/3 precommits for block
|
|
|
func (cs *ConsensusState) enterCommit(height int, commitRound int) { |
|
|
func (cs *ConsensusState) enterCommit(height int, commitRound int) { |
|
|
//cs.mtx.Lock()
|
|
|
|
|
|
//defer cs.mtx.Unlock()
|
|
|
|
|
|
if cs.Height != height || RoundStepCommit <= cs.Step { |
|
|
if cs.Height != height || RoundStepCommit <= cs.Step { |
|
|
log.Debug(Fmt("enterCommit(%v/%v): Invalid args. Current step: %v/%v/%v", height, commitRound, cs.Height, cs.Round, cs.Step)) |
|
|
log.Debug(Fmt("enterCommit(%v/%v): Invalid args. Current step: %v/%v/%v", height, commitRound, cs.Height, cs.Round, cs.Step)) |
|
|
return |
|
|
return |
|
@ -1117,9 +1105,6 @@ func (cs *ConsensusState) tryFinalizeCommit(height int) { |
|
|
|
|
|
|
|
|
// Increment height and goto RoundStepNewHeight
|
|
|
// Increment height and goto RoundStepNewHeight
|
|
|
func (cs *ConsensusState) finalizeCommit(height int) { |
|
|
func (cs *ConsensusState) finalizeCommit(height int) { |
|
|
//cs.mtx.Lock()
|
|
|
|
|
|
//defer cs.mtx.Unlock()
|
|
|
|
|
|
|
|
|
|
|
|
if cs.Height != height || cs.Step != RoundStepCommit { |
|
|
if cs.Height != height || cs.Step != RoundStepCommit { |
|
|
log.Debug(Fmt("finalizeCommit(%v): Invalid args. Current step: %v/%v/%v", height, cs.Height, cs.Round, cs.Step)) |
|
|
log.Debug(Fmt("finalizeCommit(%v): Invalid args. Current step: %v/%v/%v", height, cs.Height, cs.Round, cs.Step)) |
|
|
return |
|
|
return |
|
@ -1199,9 +1184,6 @@ func (cs *ConsensusState) finalizeCommit(height int) { |
|
|
//-----------------------------------------------------------------------------
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
func (cs *ConsensusState) setProposal(proposal *types.Proposal) error { |
|
|
func (cs *ConsensusState) setProposal(proposal *types.Proposal) error { |
|
|
//cs.mtx.Lock()
|
|
|
|
|
|
//defer cs.mtx.Unlock()
|
|
|
|
|
|
|
|
|
|
|
|
// Already have one
|
|
|
// Already have one
|
|
|
if cs.Proposal != nil { |
|
|
if cs.Proposal != nil { |
|
|
return nil |
|
|
return nil |
|
@ -1236,9 +1218,6 @@ func (cs *ConsensusState) setProposal(proposal *types.Proposal) error { |
|
|
// NOTE: block is not necessarily valid.
|
|
|
// NOTE: block is not necessarily valid.
|
|
|
// This can trigger us to go into enterPrevote asynchronously (before we timeout of propose) or to attempt to commit
|
|
|
// This can trigger us to go into enterPrevote asynchronously (before we timeout of propose) or to attempt to commit
|
|
|
func (cs *ConsensusState) addProposalBlockPart(height int, part *types.Part) (added bool, err error) { |
|
|
func (cs *ConsensusState) addProposalBlockPart(height int, part *types.Part) (added bool, err error) { |
|
|
//cs.mtx.Lock()
|
|
|
|
|
|
//defer cs.mtx.Unlock()
|
|
|
|
|
|
|
|
|
|
|
|
// Blocks might be reused, so round mismatch is OK
|
|
|
// Blocks might be reused, so round mismatch is OK
|
|
|
if cs.Height != height { |
|
|
if cs.Height != height { |
|
|
return false, nil |
|
|
return false, nil |
|
|