Skip to content

Build a Gas-Bounded Batch Execution Scheduler With Priority Queuing and Fair Cross-Tenant Resource Allocation #1625

Description

@Emmyt24

Description

batch_operations.rs executes batch items sequentially with no awareness of per-item gas cost or fairness across tenants — a single large batch from one tenant can consume a disproportionate share of a ledger's compute budget, with no mechanism to schedule batches fairly or split an oversized batch safely across ledgers.

Requirements and Context

  • Implement a scheduler that estimates gas cost per batch item before execution and enforces a configurable per-ledger gas budget
  • When a batch would exceed the remaining budget, split it into a completed portion and a continuation that resumes on a subsequent ledger, with no partial-item execution
  • Implement fair-share scheduling so no single tenant's batches can starve another tenant's queued batch across consecutive ledgers
  • Calibrate gas estimates against the existing gas_benchmark_comprehensive.rs numbers
  • Proof of work (required): this is a hard/complex issue — the PR description must include (1) a screenshot of the full relevant test suite run showing all tests passing, and (2) a screenshot of a successful project/module build or compile (cargo build --release) with no errors. PRs missing either screenshot will not be reviewed.

Suggested Execution

Branch: feat/contract-gas-bounded-batch-scheduler

Implement Changes

  • Add a gas-estimation function per batch operation type
  • Implement budget-aware batch splitting that persists continuation state between ledgers
  • Add a fair-share queue keyed by tenant that round-robins remaining budget across tenants with pending batches
  • Add tests for: budget-respecting split, correct continuation resumption, and fair-share starvation prevention across 3+ tenants

Test and Commit

Run cargo test batch_scheduler --package token-factory — budget-aware splitting, continuation resumption, and fair-share scheduling all pass. Then run cargo build --release and confirm it completes with no errors. Attach a screenshot of both the passing test run and the successful build to the PR description as proof of work.

Example Commit Message

feat(contracts): gas-bounded batch execution scheduler with fair cross-tenant scheduling

Closes #<issue>

Guidelines

  • Branch from main, open a PR back to main
  • All new code must have corresponding tests
  • Run npm run lint and npm run test before pushing
  • Follow existing naming conventions and file structure
  • PR description must reference this issue number (e.g., Closes #<issue>)
  • Keep commits atomic and use conventional commit format
  • This is a hard/complex issue: PR must include a screenshot of the test suite passing and a screenshot of a successful build/compile — PRs without both screenshots will be marked incomplete and not merged

Metadata

Metadata

Assignees

No one assigned

    Labels

    contractSoroban smart contract workhardHard/complex, cross-cutting contribution

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions