Skip to content

feat: implement batch transaction execution with gas optimization (#129) - #141

Merged
elizabetheonoja-art merged 1 commit into
Utility-Protocol:mainfrom
Chigybillionz:feat/batch-executor
Aug 22, 2026
Merged

feat: implement batch transaction execution with gas optimization (#129)#141
elizabetheonoja-art merged 1 commit into
Utility-Protocol:mainfrom
Chigybillionz:feat/batch-executor

Conversation

@Chigybillionz

Copy link
Copy Markdown
Contributor

**Close #129

Summary of the issue
Users need the ability to execute multiple operations within a single Soroban transaction to optimize gas costs and guarantee atomic execution. Previously, operations were submitted individually, which increased transaction fees and risked partial application of state if sequential transactions failed.

Root cause
The main UtilityContract lacked a unified proxy entry point to bundle and route multiple cross-contract function calls in a single atomic payload.

Solution implemented
Implemented a new batch_executor module that allows users to pass an array of BatchOperation structs (containing contract address, function symbol, and arguments). The executor iteratively routes these calls and bundles their return values. If any operation within the batch fails, the entire transaction is atomically reverted (Soroban's default panic bubbling mechanism).

Key changes made

  • Created batch_executor.rs to encapsulate the logic for iterative execution and define the BatchOperation structure.
  • Created batch_executor_tests.rs to validate batch size limits (max 20), verify atomic execution, and ensure successful cross-contract data returns.
  • Added a estimate_batch_gas heuristic helper to gauge total off-chain gas consumption based on standard per-op estimates.
  • Integrated and exposed execute_batch and estimate_batch_gas on the UtilityContract interface in lib.rs.

Any trade-offs or considerations

  • Atomicity: Rather than explicitly wrapping calls in try_invoke_contract and implementing custom cleanup patterns, we lean on Soroban's native SDK behavior where a panic on a sub-contract call naturally reverts the entire state. This provides strict atomic safety (all-or-nothing) with zero overhead.
  • Gas Estimation: The gas estimation helper relies on a heuristic. For high-accuracy gas limits, downstream clients should still leverage the Soroban preflight API to simulate the transaction exactly.

Testing steps (how to verify the fix)

  1. Check out this branch locally.
  2. Navigate to contracts/utility_contracts.
  3. Run cargo test test_batch to run the specific unit tests confirming batch boundary bounds and atomic execution behavior.
  4. Deploy to testnet and use the Soroban CLI to simulate a payload containing multiple BatchOperation structs.

Please kindly review this task. If there are any corrections, improvements, adjustments, or merge conflicts that you notice regarding my implementation, I'd really appreciate your feedback. I'd also love to hear your overall review of my work on this branch.
Thank you!

@elizabetheonoja-art
elizabetheonoja-art merged commit 8a43100 into Utility-Protocol:main Aug 22, 2026
7 of 11 checks passed
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.

Batch Transaction Execution with Gas Optimization

2 participants