diff --git a/consensus/msgs.go b/consensus/msgs.go index cef9886e6..f4a078e71 100644 --- a/consensus/msgs.go +++ b/consensus/msgs.go @@ -245,6 +245,9 @@ func (m *VoteSetMaj23Message) ValidateBasic() error { if !types.IsVoteTypeValid(m.Type) { return errors.New("invalid Type") } + if m.Round < 0 { + return errors.New("negative Round") + } if err := m.BlockID.ValidateBasic(); err != nil { return fmt.Errorf("wrong BlockID: %v", err) } diff --git a/rpc/core/blocks.go b/rpc/core/blocks.go index 468bf7d6a..f5ddb31c6 100644 --- a/rpc/core/blocks.go +++ b/rpc/core/blocks.go @@ -68,12 +68,16 @@ func filterMinMax(base, height, min, max, limit uint64) (uint64, uint64, error) // limit min to within `limit` of max // so the total number of blocks returned will be `limit` - min = tmmath.MaxUint64(min, max-limit+1) + mm := tmmath.MaxInt64(int64(min), int64(max-limit+1)) - if min > max { + // min can be zero and we will allow it + if mm > int64(max) { return min, max, fmt.Errorf("%w: min height %d can't be greater than max height %d", ctypes.ErrInvalidRequest, min, max) } + if mm < 0 { + min = 0 + } return min, max, nil } diff --git a/rpc/core/blocks_test.go b/rpc/core/blocks_test.go index 58a557be7..bf370050b 100644 --- a/rpc/core/blocks_test.go +++ b/rpc/core/blocks_test.go @@ -22,7 +22,7 @@ func TestBlockchainInfo(t *testing.T) { min, max uint64 base, height uint64 limit uint64 - resultLength int64 + resultLength uint64 wantErr bool }{ @@ -48,7 +48,7 @@ func TestBlockchainInfo(t *testing.T) { {1, 5, 0, 1, 10, 1, false}, {1, 5, 0, 10, 10, 5, false}, {1, 15, 0, 10, 10, 10, false}, - {1, 15, 0, 15, 10, 10, false}, + {1, 15, 0, 15, 10, 10, false}, // {1, 15, 0, 15, 20, 15, false}, {1, 20, 0, 15, 20, 15, false}, {1, 20, 0, 20, 20, 20, false},