mirror of
https://github.com/luxfi/consensus.git
synced 2026-09-24 00:26:58 +00:00
- 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.
81 lines
2.3 KiB
Go
81 lines
2.3 KiB
Go
// 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)
|
||
}
|
||
}
|
||
}
|