Skip to content

dkg: validate cluster definition threshold - #4634

Open
pinebit wants to merge 2 commits into
mainfrom
pinebit/dkg-threshold-fix
Open

dkg: validate cluster definition threshold#4634
pinebit wants to merge 2 commits into
mainfrom
pinebit/dkg-threshold-fix

Conversation

@pinebit

@pinebit pinebit commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator

Add threshold validation to charon dkg. The cluster definition threshold is now rejected with an error when below 2 or above the number of operators, and a warning is logged when it differs from the recommended ceil(2n/3) value.

Previously charon dkg ran the ceremony with any threshold in the definition file. charon create dkg already validates and warns on non-default thresholds, but definitions from other sources (URL, handcrafted JSON) reached the DKG ceremony unchecked. An unsafe threshold (e.g. 2 in a 4-operator cluster) allows fewer members than intended to reconstruct the validator key.

The check runs after the definition is loaded, covering both the definition file path and the append-validators path.

Also makes the app/log test initializers (InitConsoleForT, InitJSONForT, InitLogfmtForT) safe for use in packages with concurrent logging: the write syncer is now wrapped with zapcore.Lock and the previous global logger is restored on test cleanup. Previously the initializers replaced the global logger permanently, so tests running afterwards in the same package wrote to the test buffer, racing on unsynchronized writers (caught by CI in TestFrostDKG running after the new TestCheckThreshold).

category: bug
ticket: none

Reject cluster definitions with a threshold below 2 or above the number
of operators, and log a warning when the threshold differs from the
recommended ceil(2n/3) value. Previously charon dkg ran the ceremony
silently with any threshold, unlike charon create dkg which validates
and warns.

category: bug
ticket: none

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@pinebit
pinebit requested a review from KaloyanTanev August 10, 2026 10:21
Wrap the test write syncer with zapcore.Lock and restore the previous
global logger on test cleanup. Previously Init*ForT replaced the global
logger permanently, so tests running afterwards in the same package
wrote to the test buffer, racing on unsynchronized writers when logging
concurrently (caught by CI in dkg TestFrostDKG after TestCheckThreshold).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@sonarqubecloud

Copy link
Copy Markdown

Comment thread app/log/config.go

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a race condition in our logging, which is now fixed here

@codecov

codecov Bot commented Aug 10, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.59259% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 58.21%. Comparing base (aea5631) to head (c8f4a1d).

Files with missing lines Patch % Lines
dkg/dkg.go 83.33% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4634      +/-   ##
==========================================
+ Coverage   58.16%   58.21%   +0.05%     
==========================================
  Files         247      247              
  Lines       34056    34073      +17     
==========================================
+ Hits        19807    19834      +27     
+ Misses      11779    11762      -17     
- Partials     2470     2477       +7     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@KaloyanTanev

Copy link
Copy Markdown
Collaborator

Have you tested if the new logger works fine on loki/grafana?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants