Add persistence layer for swapReputationScorer.js - #961
Merged
fejilaup-cloud merged 1 commit intoAug 31, 2026
Merged
Conversation
Reputation scores were computed purely in-memory with no durable store, so a score existed only for the duration of the call that produced it. This adds a pluggable ReputationStore interface plus two implementations: - MemoryReputationStore: process-local, non-durable (default for tests/short scripts) - FileReputationStore: scores serialized to JSON on disk, durable across process restarts persistReputationScore/getPersistedReputationScore wrap the existing pure calculateReputationScore so scoring logic itself is untouched. A production multi-instance deployment can back the same interface with the API server's own Redis-backed cache (api-server/src/cache.rs, 'reputation:' key prefix) or a DB table without touching this layer. Closes AtomicIP#878
|
@paul-motron Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
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.
Summary
swapReputationScorer.jscomputed reputation scores as a pure, in-memory calculation with no durable store — a score only existed for the duration of the call that produced it. This adds a persistence layer so scores survive process restarts.Changes
swapReputationScorer.js(see the new "Persistence — Issue Add persistence layer forswapReputationScorer.js#878" block at the top of the file).ReputationStoreinterface (get/set/getAll) so scoring logic stays decoupled from where scores live, with two implementations:MemoryReputationStore— process-localMap, non-durable. Default for tests/short-lived scripts.FileReputationStore— scores serialized to a JSON file on disk, durable across process restarts. Re-reads from disk on every call rather than caching in memory, so it stays correct if multiple short-lived processes share the same file.persistReputationScore(input, store, nowMs?)andgetPersistedReputationScore(participantId, store), which wrap the existing purecalculateReputationScore— the scoring math itself is untouched.FileReputationStoreinstance and reads it back with a brand-new instance pointed at the same file (no shared in-memory state), simulating a process restart.Design notes
This repo's JS side (
src/) has no DB/cache infrastructure of its own — that only exists in the separate Rustapi-server(api-server/src/cache.rs, which already reserves areputation:key prefix, sourced today from the on-chain RPC client rather than this scorer). Given that, this PR keeps the persistence layer self-contained and backend-agnostic rather than reaching into the Rust service:FileReputationStoreis the practical default for a single-instance deployment or tooling that doesn't have a DB handy.Closes #878