validate that TimeInMeshQuantum is non-zero

otherwise we get a division by zero
This commit is contained in:
vyzo 2020-04-22 21:25:28 +03:00
parent 11ef2a9cf2
commit 61a13a3ed7
2 changed files with 7 additions and 0 deletions

View File

@ -179,6 +179,9 @@ func (p *TopicScoreParams) validate() error {
}
// check P1
if p.TimeInMeshQuantum == 0 {
return fmt.Errorf("invalid TimeInMeshQuantum; must be non zero")
}
if p.TimeInMeshWeight < 0 {
return fmt.Errorf("invalid TimeInMeshWeight; must be positive (or 0 to disable)")
}

View File

@ -32,6 +32,10 @@ func TestPeerScoreThresholdsValidation(t *testing.T) {
}
func TestTopicScoreParamsValidation(t *testing.T) {
if (&TopicScoreParams{}).validate() == nil {
t.Fatal("expected validation error")
}
if (&TopicScoreParams{TopicWeight: -1}).validate() == nil {
t.Fatal("expected validation error")
}