|
|
@ -1115,7 +1115,6 @@ func (cs *State) handleTxsAvailable(ctx context.Context) { |
|
|
|
// NOTE: cs.StartTime was already set for height.
|
|
|
|
func (cs *State) enterNewRound(ctx context.Context, height int64, round int32) { |
|
|
|
// TODO: remove panics in this function and return an error
|
|
|
|
|
|
|
|
logger := cs.logger.With("height", height, "round", round) |
|
|
|
|
|
|
|
if cs.Height != height || round < cs.Round || (cs.Round == round && cs.Step != cstypes.RoundStepNewHeight) { |
|
|
@ -1345,6 +1344,8 @@ func (cs *State) defaultDecideProposal(ctx context.Context, height int64, round |
|
|
|
// Returns true if the proposal block is complete &&
|
|
|
|
// (if POLRound was proposed, we have +2/3 prevotes from there).
|
|
|
|
func (cs *State) isProposalComplete() bool { |
|
|
|
cs.mtx.RLock() |
|
|
|
defer cs.mtx.RUnlock() |
|
|
|
if cs.Proposal == nil || cs.ProposalBlock == nil { |
|
|
|
return false |
|
|
|
} |
|
|
@ -2054,19 +2055,27 @@ func (cs *State) RecordMetrics(height int64, block *types.Block) { |
|
|
|
func (cs *State) defaultSetProposal(proposal *types.Proposal, recvTime time.Time) error { |
|
|
|
// Already have one
|
|
|
|
// TODO: possibly catch double proposals
|
|
|
|
if cs.Proposal != nil || proposal == nil { |
|
|
|
return nil |
|
|
|
} |
|
|
|
if shouldReturn, err := func() (bool, error) { |
|
|
|
cs.mtx.RLock() |
|
|
|
defer cs.mtx.RUnlock() |
|
|
|
|
|
|
|
// Does not apply
|
|
|
|
if proposal.Height != cs.Height || proposal.Round != cs.Round { |
|
|
|
return nil |
|
|
|
} |
|
|
|
if cs.Proposal != nil || proposal == nil { |
|
|
|
return true, nil |
|
|
|
} |
|
|
|
|
|
|
|
// Verify POLRound, which must be -1 or in range [0, proposal.Round).
|
|
|
|
if proposal.POLRound < -1 || |
|
|
|
(proposal.POLRound >= 0 && proposal.POLRound >= proposal.Round) { |
|
|
|
return ErrInvalidProposalPOLRound |
|
|
|
// Does not apply
|
|
|
|
if proposal.Height != cs.Height || proposal.Round != cs.Round { |
|
|
|
return true, nil |
|
|
|
} |
|
|
|
|
|
|
|
// Verify POLRound, which must be -1 or in range [0, proposal.Round).
|
|
|
|
if proposal.POLRound < -1 || |
|
|
|
(proposal.POLRound >= 0 && proposal.POLRound >= proposal.Round) { |
|
|
|
return true, ErrInvalidProposalPOLRound |
|
|
|
} |
|
|
|
return false, nil |
|
|
|
}(); shouldReturn { |
|
|
|
return err |
|
|
|
} |
|
|
|
|
|
|
|
p := proposal.ToProto() |
|
|
@ -2078,8 +2087,12 @@ func (cs *State) defaultSetProposal(proposal *types.Proposal, recvTime time.Time |
|
|
|
} |
|
|
|
|
|
|
|
proposal.Signature = p.Signature |
|
|
|
cs.Proposal = proposal |
|
|
|
cs.ProposalReceiveTime = recvTime |
|
|
|
func() { |
|
|
|
cs.mtx.Lock() |
|
|
|
defer cs.mtx.RUnlock() |
|
|
|
cs.Proposal = proposal |
|
|
|
cs.ProposalReceiveTime = recvTime |
|
|
|
}() |
|
|
|
cs.calculateProposalTimestampDifferenceMetric() |
|
|
|
// We don't update cs.ProposalBlockParts if it is already set.
|
|
|
|
// This happens if we're already in cstypes.RoundStepCommit or if there is a valid block in the current round.
|
|
|
|