Skip to content

NormalizedSnapshot is orphaned: the dashboard aggregate documented in history_snapshot.rs is never exposed or used #467

Description

@usmanimamu17-create

Problem

src/history_snapshot.rs documents normalize_history() as the way to summarize history "for dashboard telemetry":

/// Summarised view of SLA calculation history.
/// Provides a lightweight aggregate of the full history without exposing
/// individual record details. Suitable for dashboard telemetry.
pub struct NormalizedSnapshot { pub count: u32, pub has_violations: bool, pub has_rewards: bool }

Grep shows normalize_history is called only by its own tests. No contract method returns a NormalizedSnapshot, and the type is not #[contracttype], so it cannot cross the contract boundary at all.

Consequences:

  • The documented dashboard path doesn't exist: the module's usage example (let snapshot = normalize_history(&history);) is library-only; a backend dashboard cannot obtain this aggregate from the contract and must re-implement the scan over get_history (which is the expensive full read — companion issue).
  • The type is unusable as documented: even if a method were added, NormalizedSnapshot lacks #[contracttype], so it would fail at the host boundary — the same trap ConfigBundle's issue fix: config_bundle.rs type mismatch causes runtime deserialization failure #1 hit.
  • The module duplicates knowledge with get_stats: SLAStats already carries cumulative totals; NormalizedSnapshot's booleans (any violations/rewards) overlap with stats but with different semantics (windowed vs. cumulative), and nothing reconciles the two views.

Root cause

The module was authored as a utility alongside the history work and never wired to a contract endpoint or marked #[contracttype].

Why this is architecturally hard

  1. Exposing it requires a decision: a #[contracttype] aggregate type + a view method (an ABI addition, stability-guarded) that internally does the full-history scan — reintroducing the read-cost problem — or dropping the module in favor of SLAStats (which the contract already exposes).
  2. The "any violation/reward in window" semantics are only meaningful if the window is defined; the module takes the full history with no window parameter, so its dashboard value is unclear.
  3. The fix should reconcile this with get_severity_telemetry (which covers per-severity windows) so the dashboard story is one coherent surface.

Acceptance criteria

  • NormalizedSnapshot/normalize_history is either exposed as a #[contracttype] view with defined window semantics, or removed with its documentation relocated.
  • No docs present a dashboard aggregate that the contract cannot return.
  • The relationship to SLAStats/get_severity_telemetry is documented.

Out of scope

The full-history read cost (companion issue) and new telemetry counters.

Getting started

just test

Good first files to read: apexchainx_calculator/src/history_snapshot.rs, apexchainx_calculator/src/lib.rs (get_stats, get_severity_telemetry).

Activity

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

Metadata

Metadata

Labels

GrantFox OSSIssue tracked in GrantFox OSSMaybe RewardedIssue may be eligible for a GrantFox rewardStellar WaveIssues in the Stellar wave programThird CampaignCampaign: Third Campaignarea/observabilityImported campaign issue labelpriority/lowImported campaign issue label

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions