@@ -458,7 +458,8 @@ func (va *ValidationAuthorityImpl) performRemoteValidation(
458458 ctx context.Context ,
459459 req * vapb.PerformValidationRequest ,
460460) * probs.ProblemDetails {
461- if len (va .remoteVAs ) == 0 {
461+ remoteVACount := len (va .remoteVAs )
462+ if remoteVACount == 0 {
462463 return nil
463464 }
464465
@@ -469,79 +470,84 @@ func (va *ValidationAuthorityImpl) performRemoteValidation(
469470 }).Observe (va .clk .Since (start ).Seconds ())
470471 }()
471472
472- type rvaResult struct {
473- hostname string
474- response * vapb.ValidationResult
475- err error
473+ type response struct {
474+ addr string
475+ result * vapb.ValidationResult
476+ err error
476477 }
477478
478- results := make (chan * rvaResult , len (va .remoteVAs ))
479-
480- for _ , i := range rand .Perm (len (va .remoteVAs )) {
481- remoteVA := va .remoteVAs [i ]
482- go func (rva RemoteVA , out chan <- * rvaResult ) {
479+ responses := make (chan * response , remoteVACount )
480+ for _ , i := range rand .Perm (remoteVACount ) {
481+ go func (rva RemoteVA , out chan <- * response ) {
483482 res , err := rva .PerformValidation (ctx , req )
484- out <- & rvaResult {
485- hostname : rva .Address ,
486- response : res ,
487- err : err ,
483+ out <- & response {
484+ addr : rva .Address ,
485+ result : res ,
486+ err : err ,
488487 }
489- }(remoteVA , results )
488+ }(va . remoteVAs [ i ], responses )
490489 }
491490
492- required := len (va .remoteVAs ) - va .maxRemoteFailures
493- good := 0
494- bad := 0
491+ required := remoteVACount - va .maxRemoteFailures
492+ var passed []string
493+ // failed contains a list of perspectives that failed to validate the domain
494+ // or the addresses of remote VAs that failed to respond.
495+ var failed []string
495496 var firstProb * probs.ProblemDetails
496497
497- for res := range results {
498+ for resp := range responses {
498499 var currProb * probs.ProblemDetails
499500
500- if res .err != nil {
501- bad ++
501+ if resp .err != nil {
502+ // Failed to communicate with the remote VA.
503+ failed = append (failed , resp .addr )
502504
503- if canceled .Is (res .err ) {
505+ if canceled .Is (resp .err ) {
504506 currProb = probs .ServerInternal ("Remote PerformValidation RPC canceled" )
505507 } else {
506- va .log .Errf ("Remote VA %q.PerformValidation failed: %s" , res . hostname , res .err )
508+ va .log .Errf ("Remote VA %q.PerformValidation failed: %s" , resp . addr , resp .err )
507509 currProb = probs .ServerInternal ("Remote PerformValidation RPC failed" )
508510 }
509- } else if res .response .Problems != nil {
510- bad ++
511+ } else if resp .result .Problems != nil {
512+ // The remote VA returned a problem.
513+ failed = append (failed , resp .result .Perspective )
511514
512515 var err error
513- currProb , err = bgrpc .PBToProblemDetails (res . response .Problems )
516+ currProb , err = bgrpc .PBToProblemDetails (resp . result .Problems )
514517 if err != nil {
515- va .log .Errf ("Remote VA %q.PerformValidation returned malformed problem: %s" , res . hostname , err )
518+ va .log .Errf ("Remote VA %q.PerformValidation returned malformed problem: %s" , resp . addr , err )
516519 currProb = probs .ServerInternal ("Remote PerformValidation RPC returned malformed result" )
517520 }
518521 } else {
519- good ++
522+ // The remote VA returned a successful result.
523+ passed = append (passed , resp .result .Perspective )
520524 }
521525
522526 if firstProb == nil && currProb != nil {
527+ // A problem was encountered for the first time.
523528 firstProb = currProb
524529 }
525530
526- // Return as soon as we have enough successes or failures for a definitive result.
527- if good >= required {
531+ if len ( passed ) >= required {
532+ // Enough successful responses to reach quorum.
528533 return nil
529534 }
530- if bad > va .maxRemoteFailures {
535+ if len (failed ) > va .maxRemoteFailures {
536+ // Too many failed responses to reach quorum.
531537 va .metrics .remoteValidationFailures .Inc ()
532538 firstProb .Detail = fmt .Sprintf ("During secondary validation: %s" , firstProb .Detail )
533539 return firstProb
534540 }
535541
536542 // If we somehow haven't returned early, we need to break the loop once all
537543 // of the VAs have returned a result.
538- if good + bad >= len ( va . remoteVAs ) {
544+ if len ( passed ) + len ( failed ) >= remoteVACount {
539545 break
540546 }
541547 }
542548
543- // This condition should not occur - it indicates the good/bad counts neither
544- // met the required threshold nor the maxRemoteFailures threshold.
549+ // This condition should not occur - it indicates the passed/failed counts
550+ // neither met the required threshold nor the maxRemoteFailures threshold.
545551 return probs .ServerInternal ("Too few remote PerformValidation RPC results" )
546552}
547553
0 commit comments