Skip to content

Handle event ring-buffer resizing safely in set_max_events #28

Description

@priscaenoch

Problem

The explorer contract stores decoded events in a ring buffer indexed by seq % max (see the slot computation in get_events/submit_event). set_max_events (explorer/src/lib.rs) validates only that the new value is at least MIN_MAX_EVENTS, then overwrites DataKey::MaxEvents. It does not remap existing entries. After a resize, seq % new_max points at different physical slots than the data was written to, so get_event/get_events return wrong, misordered, or missing events for everything already stored. This silently corrupts the readable history.

What needs to be done

  • Define and implement safe resize semantics. Options, to be chosen and documented:
    • Rebuild/migrate the buffer contents into the new layout during set_max_events.
    • Or reset/clear the buffer on resize with an explicit event and documented consequence.
    • Or forbid resizing while the buffer is non-empty and require an explicit clear first.
  • Ensure get_event/get_events remain correct across a resize.
  • Extend the instance TTL on the write and emit an event describing the resize.

Files

  • explorer/src/lib.rs

Acceptance deliverables

  • Reads return correct, correctly ordered events before and after a resize (per the chosen, documented semantics).
  • The resize behavior is documented in the README.
  • All CI checks pass; the change cannot be merged until CI is green.

Tests to pass

  • Test: write events, call set_max_events, then read back and assert the documented behavior (no silent corruption).
  • Test: get_events ordering is correct after a resize.

Metadata

Metadata

Assignees

No one assigned

    Labels

    GrantFox OSSIssue tracked in GrantFox OSSMaybe RewardedIssue may be eligible for a GrantFox rewardThird CampaignCampaign: Third CampaignbugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions