Skip to content

Recipient Payout Ordering Guarantee #561

Description

@Kingsman-99

Description

The release_funds() loop currently iterates recipients in the order returned by soroban_sdk::Map, which is key-hash ordered and opaque to callers, making event logs non-deterministic and complicating any future partial-failure rollback logic. A canonical, reproducible payout ordering — sorted by recipient Address byte representation — must be enforced and reflected in event emissions.

Technical Context

contracts/split/src/lib.rsrelease_funds() loop body that calls token::Client::transfer() per recipient; contracts/split/src/storage.rsload_recipients() returns Vec<RecipientShare> iterated from a soroban_sdk::Map; add sort_recipients(recipients: &mut Vec<RecipientShare>) in contracts/split/src/math.rs using sort_by on the Address byte slice via recipient.to_string().as_bytes(); contracts/split/src/events.rspayout_initiated(invoice_id, index, recipient, amount) event should include the 0-based position index.

Acceptance Criteria

  • load_recipients() returns a Vec<RecipientShare> sorted by Address byte representation in ascending lexicographic order before the payout loop begins
  • Each payout_initiated event includes the recipient's 0-based position index in the sorted order
  • Sorting is applied in memory after the initial Map read and introduces no additional storage reads
  • A test in contracts/split/src/tests/ordering_tests.rs inserts 5 recipients in reverse-alphabetical order and asserts that events are emitted in alphabetical order
  • A property-based or exhaustive test confirms sort stability across at least 10 distinct random orderings of a 4-recipient list
  • All CI checks (cargo build --target wasm32-unknown-unknown, cargo test, cargo clippy) pass and the branch has no merge conflicts

Metadata

Metadata

Labels

Stellar WaveIssues in the Stellar wave programcomplexity: highComplex feature requiring deep knowledge - 200 ptsperformance

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions