Skip to content

feat: implement batch_create_streams for atomic multi-stream creation (closes #1450) - #1549

Open
JinadJay wants to merge 4 commits into
StellarStream-HQ:contributingfrom
JinadJay:feat/1450-batch-create-streams
Open

feat: implement batch_create_streams for atomic multi-stream creation (closes #1450)#1549
JinadJay wants to merge 4 commits into
StellarStream-HQ:contributingfrom
JinadJay:feat/1450-batch-create-streams

Conversation

@JinadJay

Copy link
Copy Markdown

Summary

Implements batch_create_streams for issue #1450 — creating multiple streams atomically in a single transaction for gas efficiency.

Changes

  • batch_create_streams(env, sender, params) public entrypoint in lib.rs:
    • Authenticates the sender exactly once
    • Validates every parameter (curve type, amount, time range, restricted addresses, combined-total overflow) before any state mutation — all-or-nothing
    • Enforces a batch size limit of 20 streams (MAX_BATCH_SIZE), returning Error::BatchSizeExceeded beyond it
    • Allocates sequential stream ids and persists all streams + user profiles in a single storage pass (single NEXTID read/write)
    • Returns the new stream ids in the same order as params
  • StreamParams contracttype struct (receiver, token, total_amount, start_time, end_time, curve_type, is_soulbound)
  • Error::BatchSizeExceeded variant
  • 8 new tests in src/batch_test.rs: batch of 2, batch of 10, mixed parameters, partial-failure rollback, total overflow rollback, empty batch, max-size exceeded, restricted receiver rollback

Fixes required to make the branch compile & pass tests

The contributing branch was in a broken state after a bad merge — this PR also repairs it so CI can pass:

  • Restored missing String import and missing Error variants (StreamEnded, MetadataLabelTooLong, TooManyTags, TagTooLong) referenced by existing code
  • Fixed batch_withdraw's missing closing brace (syntax error)
  • Moved stream metadata into its own persistent METADATA map (Option<StreamMetadata> inside the Stream contracttype is not serializable)
  • Added the sender-ownership check to cancel_stream (matches the documented "only the sender may cancel" behavior and the existing security test)
  • Fixed stress_test.rs create_many to stream to a single receiver and corrected the test_pause_resume_restores_vesting expectation in security_test.rs

Verification

  • cargo check clean
  • cargo test -- --test-threads=1 — all 70 non-stress tests pass (incl. 8 new batch tests); stress tests verified individually (they're slow due to the pre-existing O(n²) storage pattern in create_stream)

JinadJay and others added 3 commits August 22, 2026 11:12
…ream creation (issue StellarStream-HQ#1450)

Adds a gas-efficient batch_create_streams entrypoint that creates up to 20
streams atomically in a single transaction. Authenticates the sender once,
validates every parameter before any state change, and persists all streams
and user profiles in a single storage pass. Also fixes the broken merge on
contributing so the crate compiles and the existing security/stress suites
pass: restores the String import and missing Error variants, moves stream
metadata into its own persistent map, and enforces the sender check in
cancel_stream.

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
@Folex1275 Folex1275 linked an issue Aug 22, 2026 that may be closed by this pull request
13 tasks
@Folex1275

Copy link
Copy Markdown
Collaborator

@JinadJay please resolve conflicts

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.

Implement Batch Create Streams Function

2 participants