Skip to content

Commit

Permalink
fix log spam from check_consensus_validator_status task with large …
Browse files Browse the repository at this point in the history
…validator sets
  • Loading branch information
pk910 committed Mar 11, 2024
1 parent f3d320d commit 6e03592
Showing 1 changed file with 31 additions and 20 deletions.
51 changes: 31 additions & 20 deletions pkg/coordinator/tasks/check_consensus_validator_status/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,29 @@ func (t *Task) runValidatorStatusCheck() bool {
}

currentIndex := uint64(0)
matchingValidators := uint64(0)
pubkey := []byte{}

var namePattern *regexp.Regexp

if t.config.ValidatorPubKey != "" {
pubkey = common.FromHex(t.config.ValidatorPubKey)
}

if t.config.ValidatorNamePattern != "" {
pattern, err := regexp.Compile(t.config.ValidatorNamePattern)
if err != nil {
t.logger.Errorf("check failed: validator name pattern invalid: %v", err)
return false
}

namePattern = pattern
}

for {
validator := validatorSet[phase0.ValidatorIndex(currentIndex)]
if validator == nil {
return false
break
}

currentIndex++
Expand All @@ -145,32 +163,19 @@ func (t *Task) runValidatorStatusCheck() bool {
continue
}

if t.config.ValidatorNamePattern != "" {
validatorName := t.ctx.Scheduler.GetServices().ValidatorNames().GetValidatorName(uint64(validator.Index))
matched, err := regexp.MatchString(t.config.ValidatorNamePattern, validatorName)

if err != nil {
t.logger.Errorf("check failed: validator name pattern invalid: %v", err)
return false
}

if !matched {
continue
}
if t.config.ValidatorNamePattern != "" && !namePattern.MatchString(t.ctx.Scheduler.GetServices().ValidatorNames().GetValidatorName(uint64(validator.Index))) {
continue
}

if t.config.ValidatorPubKey != "" {
pubkey := common.FromHex(t.config.ValidatorPubKey)

if !bytes.Equal(pubkey, validator.Validator.PublicKey[:]) {
t.logger.Infof("check failed: no matching validator found")
continue
}
if t.config.ValidatorPubKey != "" && !bytes.Equal(pubkey, validator.Validator.PublicKey[:]) {
continue
}

// found a matching validator
t.logger.Infof("validator found: index %v, status: %v", validator.Index, validator.Status.String())

matchingValidators++

if t.config.ValidatorInfoResultVar != "" {
validatorJSON, err := json.Marshal(validator)
if err == nil {
Expand Down Expand Up @@ -204,4 +209,10 @@ func (t *Task) runValidatorStatusCheck() bool {

return true
}

if matchingValidators == 0 {
t.logger.Infof("check failed: no matching validator found")
}

return false
}

0 comments on commit 6e03592

Please sign in to comment.