fix: cleanup_stream removes orphaned StreamMetadata and Delegate entries#256
Merged
Austinaminu2 merged 1 commit intoJul 21, 2026
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #220.
cleanup_streamremovedStream(id)and its four index entries, but leftStreamMetadata(id)andDelegate(id)as orphaned persistent ledger entries — growing unbounded over the contract's lifetime.Changes
contracts/streaming/src/lib.rsExtended
cleanup_streamto removeDataKey::StreamMetadata(id)andDataKey::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.contracts/streaming/src/test.rsTwo new tests:
test_cleanup_stream_removes_all_associated_storage_keys— creates a stream, sets both metadata and a delegate, cancels the stream, callscleanup_stream, then asserts all three keys (Stream,StreamMetadata,Delegate) are absent.test_cleanup_stream_works_without_optional_entries— verifiescleanup_streamdoes not panic when neither metadata nor delegate were ever set.Testing
All 123 tests pass (121 pre-existing + 2 new).
Closes #220