Skip to content

Commit

Permalink
VA: Cleanup performRemoteValidation
Browse files Browse the repository at this point in the history
  • Loading branch information
beautifulentropy committed Nov 14, 2024
1 parent c39f33e commit ffd1721
Showing 1 changed file with 32 additions and 33 deletions.
65 changes: 32 additions & 33 deletions va/va.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,8 @@ func (va *ValidationAuthorityImpl) performRemoteValidation(
ctx context.Context,
req *vapb.PerformValidationRequest,
) *probs.ProblemDetails {
if len(va.remoteVAs) == 0 {
remoteVACount := len(va.remoteVAs)
if remoteVACount == 0 {
return nil
}

Expand All @@ -471,79 +472,77 @@ func (va *ValidationAuthorityImpl) performRemoteValidation(
}).Observe(va.clk.Since(start).Seconds())
}()

type rvaResult struct {
hostname string
response *vapb.ValidationResult
err error
type response struct {
addr string
result *vapb.ValidationResult
err error
}

results := make(chan *rvaResult, len(va.remoteVAs))

for _, i := range rand.Perm(len(va.remoteVAs)) {
remoteVA := va.remoteVAs[i]
go func(rva RemoteVA, out chan<- *rvaResult) {
responses := make(chan *response, remoteVACount)
for _, i := range rand.Perm(remoteVACount) {
go func(rva RemoteVA, out chan<- *response) {
res, err := rva.PerformValidation(ctx, req)
out <- &rvaResult{
hostname: rva.Address,
response: res,
err: err,
out <- &response{
addr: rva.Address,
result: res,
err: err,
}
}(remoteVA, results)
}(va.remoteVAs[i], responses)
}

required := len(va.remoteVAs) - va.maxRemoteFailures
good := 0
bad := 0
required := remoteVACount - va.maxRemoteFailures
var passed []string
var failed []string
var firstProb *probs.ProblemDetails

for res := range results {
for resp := range responses {
var currProb *probs.ProblemDetails

if res.err != nil {
bad++
if resp.err != nil {
failed = append(failed, resp.result.Perspective)

if canceled.Is(res.err) {
if canceled.Is(resp.err) {
currProb = probs.ServerInternal("Remote PerformValidation RPC canceled")
} else {
va.log.Errf("Remote VA %q.PerformValidation failed: %s", res.hostname, res.err)
va.log.Errf("Remote VA %q.PerformValidation failed: %s", resp.addr, resp.err)
currProb = probs.ServerInternal("Remote PerformValidation RPC failed")
}
} else if res.response.Problems != nil {
bad++
} else if resp.result.Problems != nil {
failed = append(failed, resp.result.Perspective)

var err error
currProb, err = bgrpc.PBToProblemDetails(res.response.Problems)
currProb, err = bgrpc.PBToProblemDetails(resp.result.Problems)
if err != nil {
va.log.Errf("Remote VA %q.PerformValidation returned malformed problem: %s", res.hostname, err)
va.log.Errf("Remote VA %q.PerformValidation returned malformed problem: %s", resp.addr, err)
currProb = probs.ServerInternal("Remote PerformValidation RPC returned malformed result")
}
} else {
good++
passed = append(passed, resp.result.Perspective)
}

if firstProb == nil && currProb != nil {
firstProb = currProb
}

// Return as soon as we have enough successes or failures for a definitive result.
if good >= required {
if len(passed) >= required {
return nil
}
if bad > va.maxRemoteFailures {
if len(failed) > va.maxRemoteFailures {
va.metrics.remoteValidationFailures.Inc()
firstProb.Detail = fmt.Sprintf("During secondary validation: %s", firstProb.Detail)
return firstProb
}

// If we somehow haven't returned early, we need to break the loop once all
// of the VAs have returned a result.
if good+bad >= len(va.remoteVAs) {
if len(passed)+len(failed) >= remoteVACount {
break
}
}

// This condition should not occur - it indicates the good/bad counts neither
// met the required threshold nor the maxRemoteFailures threshold.
// This condition should not occur - it indicates the passed/failed counts
// neither met the required threshold nor the maxRemoteFailures threshold.
return probs.ServerInternal("Too few remote PerformValidation RPC results")
}

Expand Down

0 comments on commit ffd1721

Please sign in to comment.