Files
consensus/config/bench_cert_policy_test.go
zeekay d335ca78d5 feat(config): CertPolicy record (LP-217) and drop LUX_ env prefix
- Introduce config/cert_policy.go: single CertPolicy record (Mode +
  Variant + TimeoutMs + Fallback) collapses three knobs from LP-217 /
  LP-202 / LP-204 into one operator-facing struct. Validated at chain
  genesis; refuses launch when invalid. Distinct from PQMode enum
  (pq_mode.go) — CertPolicy is the deployment knob, PQMode is the
  protocol-level identifier.
- Add config/cert_policy_test.go and config/bench_cert_policy_test.go
  covering validation matrix + fallback-tier degradation contract.
- PQModeFromEnv: drop legacy LUX_CONSENSUS_PQ_MODE fallback per the
  "one canonical, unprefixed name" directive. CONSENSUS_PQ_MODE is the
  only honoured env var.
- engine/pq/consensus.go: minor follow-up wiring.
- paper/* + PQ-GPU-AUDIT.md + README.md: align prose with CertPolicy
  framing and unprefixed env names.
2026-06-04 17:04:32 -07:00

81 lines
2.3 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Copyright (C) 2026, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package config
import "testing"
// BenchmarkParseCertPolicy measures ParseCertPolicy(strings) — the
// genesis-loader path that turns YAML strings into a validated
// CertPolicy. Includes parseMode×2 + variant switch + Validate.
func BenchmarkParseCertPolicy(b *testing.B) {
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err := ParseCertPolicy("PQ-strict", "hybrid", 5_000, "PQ-fast")
if err != nil {
b.Fatalf("ParseCertPolicy: %v", err)
}
}
}
// BenchmarkParseCertPolicy_Strict measures the strict-PQ variant.
func BenchmarkParseCertPolicy_Strict(b *testing.B) {
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err := ParseCertPolicy("PQ-heavy", "strict", 8_000, "PQ-fast")
if err != nil {
b.Fatalf("ParseCertPolicy: %v", err)
}
}
}
// BenchmarkCertPolicy_Validate isolates the rule-check path (no
// parsing).
func BenchmarkCertPolicy_Validate(b *testing.B) {
cp := CertPolicy{Mode: CertModeStrict, Variant: CertVariantHybrid, TimeoutMs: 5_000, Fallback: CertModeFast}
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
if err := cp.Validate(); err != nil {
b.Fatalf("Validate: %v", err)
}
}
}
// BenchmarkCertPolicy_RequiredLegs measures the leg-set computation.
// Called per cert verification to know which legs to require.
func BenchmarkCertPolicy_RequiredLegs(b *testing.B) {
cp := CertPolicy{Mode: CertModeHeavy, Variant: CertVariantHybrid, TimeoutMs: 8_000, Fallback: CertModeFast}
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
_ = cp.RequiredLegs()
}
}
// BenchmarkCertPolicy_WireName measures the wire-name format path
// (called on every cert emission for the wire identifier).
func BenchmarkCertPolicy_WireName(b *testing.B) {
cp := CertPolicy{Mode: CertModeHeavy, Variant: CertVariantStrict, TimeoutMs: 8_000, Fallback: CertModeFast}
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
_ = cp.WireName()
}
}
// BenchmarkParseWireName measures the inverse — parsing one of the
// seven canonical wire names back to (Mode, Variant).
func BenchmarkParseWireName(b *testing.B) {
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, _, err := ParseWireName("strict-PQ-heavy")
if err != nil {
b.Fatalf("ParseWireName: %v", err)
}
}
}