Skip to content

Commit

Permalink
Extract summary prep.
Browse files Browse the repository at this point in the history
  • Loading branch information
beautifulentropy committed Nov 8, 2024
1 parent 29dee31 commit 1149ac4
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions va/vampic.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ func (va *ValidationAuthorityImpl) onPrimaryVA() bool {
}

// mpicSummary contains multiple fields that are exported for logging purposes.
// Use newSummary() to create a new mpicSummary.
type mpicSummary struct {
// Passed is the list of distinct perspectives that Passed validation.
Passed []string `json:"passedPerspectives"`
Expand All @@ -71,14 +70,21 @@ type mpicSummary struct {
QuorumResult string `json:"quorumResult"`
}

// newSummary returns a new mpicSummary with empty slices so that JSON output is
// always an empty array instead of "null".
func newSummary() mpicSummary {
return mpicSummary{
Passed: []string{},
Failed: []string{},
RIRs: []string{},
// prepareSummary prepares a summary of the validation results for logging
// purposes.
func prepareSummary(passed, failed []string, passedRIRs map[string]struct{}, remoteVACount int) mpicSummary {
summary := mpicSummary{
Passed: append([]string{}, passed...),
Failed: append([]string{}, failed...),
RIRs: []string{},
QuorumResult: fmt.Sprintf("%d/%d", len(passed), remoteVACount),
}
for rir := range maps.Keys(passedRIRs) {
summary.RIRs = append(summary.RIRs, rir)
}
slices.Sort(summary.RIRs)

return summary
}

// validateChallengeAuditLog contains multiple fields that are exported for
Expand Down Expand Up @@ -190,15 +196,7 @@ func (va *ValidationAuthorityImpl) remoteValidateChallenge(ctx context.Context,
}

// Prepare the summary, this MUST be returned even if the validation failed.
summary := mpicSummary{
Passed: passed,
Failed: failed,
QuorumResult: fmt.Sprintf("%d/%d", len(passed), remoteVACount),
}
for rir := range maps.Keys(passedRIRs) {
summary.RIRs = append(summary.RIRs, rir)
}
slices.Sort(summary.RIRs)
summary := prepareSummary(passed, failed, passedRIRs, remoteVACount)

if len(passed) >= required {
// We may have enough successful responses.
Expand Down Expand Up @@ -249,7 +247,7 @@ func (va *ValidationAuthorityImpl) ValidateChallenge(ctx context.Context, req *v
var prob *probs.ProblemDetails
var localLatency time.Duration
var latency time.Duration
summary := newSummary()
var summary mpicSummary
start := va.clk.Now()

auditLog := validateChallengeAuditLog{
Expand Down

0 comments on commit 1149ac4

Please sign in to comment.