|
@ -898,8 +898,8 @@ func ReactorMetrics(metrics *Metrics) ReactorOption { |
|
|
//-----------------------------------------------------------------------------
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
var ( |
|
|
var ( |
|
|
ErrPeerStateHeightRegression = errors.New("Error peer state height regression") |
|
|
|
|
|
ErrPeerStateInvalidStartTime = errors.New("Error peer state invalid startTime") |
|
|
|
|
|
|
|
|
ErrPeerStateHeightRegression = errors.New("error peer state height regression") |
|
|
|
|
|
ErrPeerStateInvalidStartTime = errors.New("error peer state invalid startTime") |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
// PeerState contains the known state of a peer, including its connection and
|
|
|
// PeerState contains the known state of a peer, including its connection and
|
|
@ -1399,7 +1399,7 @@ func RegisterConsensusMessages(cdc *amino.Codec) { |
|
|
|
|
|
|
|
|
func decodeMsg(bz []byte) (msg ConsensusMessage, err error) { |
|
|
func decodeMsg(bz []byte) (msg ConsensusMessage, err error) { |
|
|
if len(bz) > maxMsgSize { |
|
|
if len(bz) > maxMsgSize { |
|
|
return msg, fmt.Errorf("Msg exceeds max size (%d > %d)", len(bz), maxMsgSize) |
|
|
|
|
|
|
|
|
return msg, fmt.Errorf("msg exceeds max size (%d > %d)", len(bz), maxMsgSize) |
|
|
} |
|
|
} |
|
|
err = cdc.UnmarshalBinaryBare(bz, &msg) |
|
|
err = cdc.UnmarshalBinaryBare(bz, &msg) |
|
|
return |
|
|
return |
|
@ -1420,20 +1420,20 @@ type NewRoundStepMessage struct { |
|
|
// ValidateBasic performs basic validation.
|
|
|
// ValidateBasic performs basic validation.
|
|
|
func (m *NewRoundStepMessage) ValidateBasic() error { |
|
|
func (m *NewRoundStepMessage) ValidateBasic() error { |
|
|
if m.Height < 0 { |
|
|
if m.Height < 0 { |
|
|
return errors.New("Negative Height") |
|
|
|
|
|
|
|
|
return errors.New("negative Height") |
|
|
} |
|
|
} |
|
|
if m.Round < 0 { |
|
|
if m.Round < 0 { |
|
|
return errors.New("Negative Round") |
|
|
|
|
|
|
|
|
return errors.New("negative Round") |
|
|
} |
|
|
} |
|
|
if !m.Step.IsValid() { |
|
|
if !m.Step.IsValid() { |
|
|
return errors.New("Invalid Step") |
|
|
|
|
|
|
|
|
return errors.New("invalid Step") |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// NOTE: SecondsSinceStartTime may be negative
|
|
|
// NOTE: SecondsSinceStartTime may be negative
|
|
|
|
|
|
|
|
|
if (m.Height == 1 && m.LastCommitRound != -1) || |
|
|
if (m.Height == 1 && m.LastCommitRound != -1) || |
|
|
(m.Height > 1 && m.LastCommitRound < -1) { // TODO: #2737 LastCommitRound should always be >= 0 for heights > 1
|
|
|
(m.Height > 1 && m.LastCommitRound < -1) { // TODO: #2737 LastCommitRound should always be >= 0 for heights > 1
|
|
|
return errors.New("Invalid LastCommitRound (for 1st block: -1, for others: >= 0)") |
|
|
|
|
|
|
|
|
return errors.New("invalid LastCommitRound (for 1st block: -1, for others: >= 0)") |
|
|
} |
|
|
} |
|
|
return nil |
|
|
return nil |
|
|
} |
|
|
} |
|
@ -1460,19 +1460,19 @@ type NewValidBlockMessage struct { |
|
|
// ValidateBasic performs basic validation.
|
|
|
// ValidateBasic performs basic validation.
|
|
|
func (m *NewValidBlockMessage) ValidateBasic() error { |
|
|
func (m *NewValidBlockMessage) ValidateBasic() error { |
|
|
if m.Height < 0 { |
|
|
if m.Height < 0 { |
|
|
return errors.New("Negative Height") |
|
|
|
|
|
|
|
|
return errors.New("negative Height") |
|
|
} |
|
|
} |
|
|
if m.Round < 0 { |
|
|
if m.Round < 0 { |
|
|
return errors.New("Negative Round") |
|
|
|
|
|
|
|
|
return errors.New("negative Round") |
|
|
} |
|
|
} |
|
|
if err := m.BlockPartsHeader.ValidateBasic(); err != nil { |
|
|
if err := m.BlockPartsHeader.ValidateBasic(); err != nil { |
|
|
return fmt.Errorf("Wrong BlockPartsHeader: %v", err) |
|
|
|
|
|
|
|
|
return fmt.Errorf("wrong BlockPartsHeader: %v", err) |
|
|
} |
|
|
} |
|
|
if m.BlockParts.Size() == 0 { |
|
|
if m.BlockParts.Size() == 0 { |
|
|
return errors.New("Empty BlockParts") |
|
|
return errors.New("Empty BlockParts") |
|
|
} |
|
|
} |
|
|
if m.BlockParts.Size() != m.BlockPartsHeader.Total { |
|
|
if m.BlockParts.Size() != m.BlockPartsHeader.Total { |
|
|
return fmt.Errorf("BlockParts bit array size %d not equal to BlockPartsHeader.Total %d", |
|
|
|
|
|
|
|
|
return fmt.Errorf("blockParts bit array size %d not equal to BlockPartsHeader.Total %d", |
|
|
m.BlockParts.Size(), |
|
|
m.BlockParts.Size(), |
|
|
m.BlockPartsHeader.Total) |
|
|
m.BlockPartsHeader.Total) |
|
|
} |
|
|
} |
|
@ -1517,13 +1517,13 @@ type ProposalPOLMessage struct { |
|
|
// ValidateBasic performs basic validation.
|
|
|
// ValidateBasic performs basic validation.
|
|
|
func (m *ProposalPOLMessage) ValidateBasic() error { |
|
|
func (m *ProposalPOLMessage) ValidateBasic() error { |
|
|
if m.Height < 0 { |
|
|
if m.Height < 0 { |
|
|
return errors.New("Negative Height") |
|
|
|
|
|
|
|
|
return errors.New("negative Height") |
|
|
} |
|
|
} |
|
|
if m.ProposalPOLRound < 0 { |
|
|
if m.ProposalPOLRound < 0 { |
|
|
return errors.New("Negative ProposalPOLRound") |
|
|
|
|
|
|
|
|
return errors.New("negative ProposalPOLRound") |
|
|
} |
|
|
} |
|
|
if m.ProposalPOL.Size() == 0 { |
|
|
if m.ProposalPOL.Size() == 0 { |
|
|
return errors.New("Empty ProposalPOL bit array") |
|
|
|
|
|
|
|
|
return errors.New("empty ProposalPOL bit array") |
|
|
} |
|
|
} |
|
|
if m.ProposalPOL.Size() > types.MaxVotesCount { |
|
|
if m.ProposalPOL.Size() > types.MaxVotesCount { |
|
|
return errors.Errorf("ProposalPOL bit array is too big: %d, max: %d", m.ProposalPOL.Size(), types.MaxVotesCount) |
|
|
return errors.Errorf("ProposalPOL bit array is too big: %d, max: %d", m.ProposalPOL.Size(), types.MaxVotesCount) |
|
@ -1548,13 +1548,13 @@ type BlockPartMessage struct { |
|
|
// ValidateBasic performs basic validation.
|
|
|
// ValidateBasic performs basic validation.
|
|
|
func (m *BlockPartMessage) ValidateBasic() error { |
|
|
func (m *BlockPartMessage) ValidateBasic() error { |
|
|
if m.Height < 0 { |
|
|
if m.Height < 0 { |
|
|
return errors.New("Negative Height") |
|
|
|
|
|
|
|
|
return errors.New("negative Height") |
|
|
} |
|
|
} |
|
|
if m.Round < 0 { |
|
|
if m.Round < 0 { |
|
|
return errors.New("Negative Round") |
|
|
|
|
|
|
|
|
return errors.New("negative Round") |
|
|
} |
|
|
} |
|
|
if err := m.Part.ValidateBasic(); err != nil { |
|
|
if err := m.Part.ValidateBasic(); err != nil { |
|
|
return fmt.Errorf("Wrong Part: %v", err) |
|
|
|
|
|
|
|
|
return fmt.Errorf("wrong Part: %v", err) |
|
|
} |
|
|
} |
|
|
return nil |
|
|
return nil |
|
|
} |
|
|
} |
|
@ -1594,16 +1594,16 @@ type HasVoteMessage struct { |
|
|
// ValidateBasic performs basic validation.
|
|
|
// ValidateBasic performs basic validation.
|
|
|
func (m *HasVoteMessage) ValidateBasic() error { |
|
|
func (m *HasVoteMessage) ValidateBasic() error { |
|
|
if m.Height < 0 { |
|
|
if m.Height < 0 { |
|
|
return errors.New("Negative Height") |
|
|
|
|
|
|
|
|
return errors.New("negative Height") |
|
|
} |
|
|
} |
|
|
if m.Round < 0 { |
|
|
if m.Round < 0 { |
|
|
return errors.New("Negative Round") |
|
|
|
|
|
|
|
|
return errors.New("negative Round") |
|
|
} |
|
|
} |
|
|
if !types.IsVoteTypeValid(m.Type) { |
|
|
if !types.IsVoteTypeValid(m.Type) { |
|
|
return errors.New("Invalid Type") |
|
|
|
|
|
|
|
|
return errors.New("invalid Type") |
|
|
} |
|
|
} |
|
|
if m.Index < 0 { |
|
|
if m.Index < 0 { |
|
|
return errors.New("Negative Index") |
|
|
|
|
|
|
|
|
return errors.New("negative Index") |
|
|
} |
|
|
} |
|
|
return nil |
|
|
return nil |
|
|
} |
|
|
} |
|
@ -1626,16 +1626,16 @@ type VoteSetMaj23Message struct { |
|
|
// ValidateBasic performs basic validation.
|
|
|
// ValidateBasic performs basic validation.
|
|
|
func (m *VoteSetMaj23Message) ValidateBasic() error { |
|
|
func (m *VoteSetMaj23Message) ValidateBasic() error { |
|
|
if m.Height < 0 { |
|
|
if m.Height < 0 { |
|
|
return errors.New("Negative Height") |
|
|
|
|
|
|
|
|
return errors.New("negative Height") |
|
|
} |
|
|
} |
|
|
if m.Round < 0 { |
|
|
if m.Round < 0 { |
|
|
return errors.New("Negative Round") |
|
|
|
|
|
|
|
|
return errors.New("negative Round") |
|
|
} |
|
|
} |
|
|
if !types.IsVoteTypeValid(m.Type) { |
|
|
if !types.IsVoteTypeValid(m.Type) { |
|
|
return errors.New("Invalid Type") |
|
|
|
|
|
|
|
|
return errors.New("invalid Type") |
|
|
} |
|
|
} |
|
|
if err := m.BlockID.ValidateBasic(); err != nil { |
|
|
if err := m.BlockID.ValidateBasic(); err != nil { |
|
|
return fmt.Errorf("Wrong BlockID: %v", err) |
|
|
|
|
|
|
|
|
return fmt.Errorf("wrong BlockID: %v", err) |
|
|
} |
|
|
} |
|
|
return nil |
|
|
return nil |
|
|
} |
|
|
} |
|
@ -1659,20 +1659,20 @@ type VoteSetBitsMessage struct { |
|
|
// ValidateBasic performs basic validation.
|
|
|
// ValidateBasic performs basic validation.
|
|
|
func (m *VoteSetBitsMessage) ValidateBasic() error { |
|
|
func (m *VoteSetBitsMessage) ValidateBasic() error { |
|
|
if m.Height < 0 { |
|
|
if m.Height < 0 { |
|
|
return errors.New("Negative Height") |
|
|
|
|
|
|
|
|
return errors.New("negative Height") |
|
|
} |
|
|
} |
|
|
if m.Round < 0 { |
|
|
if m.Round < 0 { |
|
|
return errors.New("Negative Round") |
|
|
|
|
|
|
|
|
return errors.New("negative Round") |
|
|
} |
|
|
} |
|
|
if !types.IsVoteTypeValid(m.Type) { |
|
|
if !types.IsVoteTypeValid(m.Type) { |
|
|
return errors.New("Invalid Type") |
|
|
|
|
|
|
|
|
return errors.New("invalid Type") |
|
|
} |
|
|
} |
|
|
if err := m.BlockID.ValidateBasic(); err != nil { |
|
|
if err := m.BlockID.ValidateBasic(); err != nil { |
|
|
return fmt.Errorf("Wrong BlockID: %v", err) |
|
|
|
|
|
|
|
|
return fmt.Errorf("wrong BlockID: %v", err) |
|
|
} |
|
|
} |
|
|
// NOTE: Votes.Size() can be zero if the node does not have any
|
|
|
// NOTE: Votes.Size() can be zero if the node does not have any
|
|
|
if m.Votes.Size() > types.MaxVotesCount { |
|
|
if m.Votes.Size() > types.MaxVotesCount { |
|
|
return fmt.Errorf("Votes bit array is too big: %d, max: %d", m.Votes.Size(), types.MaxVotesCount) |
|
|
|
|
|
|
|
|
return fmt.Errorf("votes bit array is too big: %d, max: %d", m.Votes.Size(), types.MaxVotesCount) |
|
|
} |
|
|
} |
|
|
return nil |
|
|
return nil |
|
|
} |
|
|
} |
|
|