Skip to content

feat(meter-aggregator): bounded meter aggregation with rollups and inline pruning#40

Merged
elizabetheonoja-art merged 2 commits into
Utility-Protocol:mainfrom
real-venus:feature/meter-aggregator-rollup-pruning
Jun 25, 2026
Merged

feat(meter-aggregator): bounded meter aggregation with rollups and inline pruning#40
elizabetheonoja-art merged 2 commits into
Utility-Protocol:mainfrom
real-venus:feature/meter-aggregator-rollup-pruning

Conversation

@real-venus

Copy link
Copy Markdown
Contributor

Closes #10

  • Raw readings stored under individual keys RawReading(device, seq) with a
    monotonic sequence number → O(1) append, seq order == time order.
  • On every submit_reading, the value is folded into the matching hourly and
    daily rollup buckets using overflow-checked i128 checked_add.
  • Inline pruning: raw readings older than MAX_RAW_RETENTION_SECS (7 days)
    are deleted during submission, amortized O(1) via a watermark cursor
    PruneCursor(device), capped at PRUNE_BATCH_SIZE (10) per call.
  • get_aggregated_volume reads tiered: daily → hourly → live raw fallback.
  • rollup_day (admin) reclaims a completed day's redundant hourly buckets.

Files

  • contracts/meter-aggregator/src/{constants,types,storage,lib,test}.rs
  • contracts/meter-aggregator/{Cargo.toml,README.md}
  • contracts/Cargo.toml (registers the new workspace member)

…line pruning

Add a new meter-aggregator Soroban contract that prevents unbounded raw
reading accumulation from exhausting per-device contract storage.

- Raw readings stored by monotonic seq (O(1) append, time-ordered)
- Each reading folded into hourly + daily rollup buckets (overflow-checked)
- Inline amortized pruning via watermark cursor, batch-capped per call
- 7-day raw retention (MAX_RAW_RETENTION_SECS), PRUNE_BATCH_SIZE=10
- get_aggregated_volume reads tiered: daily -> hourly -> raw
- rollup_day reclaims a completed day's hourly buckets
- Tests: rollup correctness, overflow, prune boundary, batch limit,
  storage-exhaustion prevention

Registered as a workspace member in contracts/Cargo.toml.
…gator-rollup-pruning

# Conflicts:
#	contracts/Cargo.toml
@elizabetheonoja-art elizabetheonoja-art merged commit eefcb7a into Utility-Protocol:main Jun 25, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unbounded Meter Data Accumulation Leading to Contract Storage Exhaustion

2 participants