Problem Statement / Feature Objective
The reputation engine maintains a sliding window of historical scores for each validator (WINDOW_SIZE = 4096 epochs). The window buffer is implemented as a circular buffer of fixed length WINDOW_SIZE. When a validator is first observed, the buffer is initialized with zeroes and the write pointer starts at index 0. After exactly 4096 epochs, the write pointer wraps to index 0 and overwrites the oldest entry. However, the buffer does not track the number of valid entries written, causing a read of the full window to include uninitialized zero entries as valid historical scores, diluting the reputation average.
Technical Invariants & Bounds
- WINDOW_SIZE: 4096 entries per validator.
- Buffer: Vec with capacity WINDOW_SIZE, pre-filled with 0.
- Write pointer: circular index starting at 0, wrapping at WINDOW_SIZE.
- Read returns WINDOW_SIZE entries from (pointer - WINDOW_SIZE) to pointer.
- Zero entries from uninitialized period dilute average by ~50% for new validators.
- Zero entries are indistinguishable from actual scores of 0 (inactive validators).
Codebase Navigation Guide
- src/reputation/historical-window.rs - CircularWindow struct, push_score(), window_slice().
- src/reputation/score-engine.rs - compute_weighted_average() that consumes window.
- tests/reputation/historical_window_test.rs - buffer behavior tests.
Implementation Blueprint
- In src/reputation/historical-window.rs, add a entries_written: u64 counter that tracks total pushes to the buffer.
- In window_slice(), return only min(entries_written, WINDOW_SIZE) entries, ignoring uninitialized positions.
- If entries_written < WINDOW_SIZE, the effective window is smaller and the average should be computed over the actual number of entries, not the full WINDOW_SIZE.
- Update compute_weighted_average() to use the actual entry count for normalization.
- Write a test: push 100 scores to a new validator's window and assert the window returns exactly 100 entries, not 4096.
Problem Statement / Feature Objective
The reputation engine maintains a sliding window of historical scores for each validator (WINDOW_SIZE = 4096 epochs). The window buffer is implemented as a circular buffer of fixed length WINDOW_SIZE. When a validator is first observed, the buffer is initialized with zeroes and the write pointer starts at index 0. After exactly 4096 epochs, the write pointer wraps to index 0 and overwrites the oldest entry. However, the buffer does not track the number of valid entries written, causing a read of the full window to include uninitialized zero entries as valid historical scores, diluting the reputation average.
Technical Invariants & Bounds
Codebase Navigation Guide
Implementation Blueprint