Skip to content

fix: cleanup_stream removes orphaned StreamMetadata and Delegate entries#256

Merged
Austinaminu2 merged 1 commit into
FlowwStar:mainfrom
samsolo247:fix/cleanup-stream-orphaned-metadata-delegate
Jul 21, 2026
Merged

fix: cleanup_stream removes orphaned StreamMetadata and Delegate entries#256
Austinaminu2 merged 1 commit into
FlowwStar:mainfrom
samsolo247:fix/cleanup-stream-orphaned-metadata-delegate

Conversation

@samsolo247

Copy link
Copy Markdown

Summary

Fixes #220.

cleanup_stream removed Stream(id) and its four index entries, but left StreamMetadata(id) and Delegate(id) as orphaned persistent ledger entries — growing unbounded over the contract's lifetime.

Changes

contracts/streaming/src/lib.rs

Extended cleanup_stream to remove DataKey::StreamMetadata(id) and DataKey::Delegate(id) after deleting the stream entry. A .has() guard is used before each removal because both fields are optional — calling .remove() on an absent key panics in Soroban.

// Remove optional associated entries if they exist.
if env.storage().persistent().has(&DataKey::StreamMetadata(stream_id)) {
    env.storage().persistent().remove(&DataKey::StreamMetadata(stream_id));
}
if env.storage().persistent().has(&DataKey::Delegate(stream_id)) {
    env.storage().persistent().remove(&DataKey::Delegate(stream_id));
}

contracts/streaming/src/test.rs

Two new tests:

  • test_cleanup_stream_removes_all_associated_storage_keys — creates a stream, sets both metadata and a delegate, cancels the stream, calls cleanup_stream, then asserts all three keys (Stream, StreamMetadata, Delegate) are absent.
  • test_cleanup_stream_works_without_optional_entries — verifies cleanup_stream does not panic when neither metadata nor delegate were ever set.

Testing

cargo test

All 123 tests pass (121 pre-existing + 2 new).

Closes #220

Fixes FlowwStar#220.

cleanup_stream previously only removed the Stream(id) entry and its
sent/received index entries, leaving StreamMetadata(id) and Delegate(id)
as orphaned persistent storage entries indefinitely.

Changes:
- contracts/streaming/src/lib.rs: extend cleanup_stream to also call
  .remove() on DataKey::StreamMetadata(id) and DataKey::Delegate(id)
  when they exist, reclaiming all storage associated with a stream.
- contracts/streaming/src/test.rs: add two new tests
    * test_cleanup_stream_removes_all_associated_storage_keys — creates
      a stream, sets both metadata and a delegate, cancels, then asserts
      all three keys are absent after cleanup_stream.
    * test_cleanup_stream_works_without_optional_entries — verifies
      cleanup_stream does not panic when neither metadata nor delegate
      were ever set.
@Austinaminu2
Austinaminu2 merged commit 4759f1e into FlowwStar:main Jul 21, 2026
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.

bug: cleanup_stream leaves orphaned StreamMetadata and Delegate storage entries

3 participants