fix: eliminate reputation update race via append-only event log (#3)#44
Merged
JamesEjembi merged 1 commit intoJun 24, 2026
Merged
Conversation
…Node-Labs#3) Reputation was a single scalar updated read-compute-write, so a successful attestation (+10) and a slashing event (-500) processed together raced: the last writer won and a +10 could clobber the slash (final 760 instead of 260), dropping the authoritative slash. Fix stores reputation as a per-event log (blueprint step 3): each adjustment is appended as a ReputationEvent and the score is the clamped sum, so two updates each record their event and the result is independent of write order. A monotonic slash_count + try_slash (step 4) make slashing idempotent against duplicate replays. - reputation/score.rs: ReputationLedger (set_initial_score, update_reputation, try_slash, score, slash_count), ReputationSource, ReputationEvent, range/adjustment constants - tests/score_tests.rs: concurrent attestation+slash -> 260 (never 760/250), slash-always-(-500), duplicate-slash skip, clamp, order-independence property test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix #3 — Node Reputation Score Update Race in Concurrent Attestation Processing
Closes #3
Changes
src/reputation/score.rsReputationLedger(set_initial_score,update_reputation,try_slash,score,slash_count,event_count),ReputationSource,ReputationEvent, range/adjustment constantssrc/reputation/mod.rspub mod scoretests/reputation/score_tests.rs(+tests/reputation.rs)