feat: implement batching for multiple extrinsic calls to reduce trans…#764
Closed
mimalsm wants to merge 4 commits intoopentensor:stagingfrom
Closed
feat: implement batching for multiple extrinsic calls to reduce trans…#764mimalsm wants to merge 4 commits intoopentensor:stagingfrom
mimalsm wants to merge 4 commits intoopentensor:stagingfrom
Conversation
…action fees This commit implements comprehensive batching support for CLI commands that can submit multiple extrinsic calls, significantly reducing transaction fees for users. This addresses GitHub issue opentensor#567. Core Changes: ============= 1. New Batching Interface (subtensor_interface.py) - Added sign_and_send_batch_extrinsic() method to support batching multiple GenericCall objects into a single transaction - Supports three batch types: 'batch', 'batch_all', and 'force_batch' - Defaults to 'batch_all' to ensure atomicity (all succeed or all fail) - Fully integrates with existing features: MEV protection, proxy transactions, era management, and nonce handling - Returns detailed results including success status, extrinsic receipt, and individual call results 2. Stake Add Command Refactoring (stake/add.py) - Refactored to collect multiple stake operations (across different netuids and/or hotkeys) into a single batch transaction - Automatically uses batching when multiple --netuid or --hotkey arguments are provided - Optimized balance fetching using asyncio.gather for parallel queries - Enhanced display to show: * Individual stake changes per netuid/hotkey combination * Final coldkey balance change (previous_balance -> current_balance) * Clear visual feedback for each operation in the batch 3. Stake Remove Command Refactoring (stake/remove.py) - Refactored unstake() to batch multiple remove_stake operations - Refactored unstake_all() to batch multiple unstake_all operations - Supports batching when: * Multiple --netuid arguments are provided * Multiple --hotkey arguments are provided * --include-hotkeys with multiple hotkeys is used - Optimized stake balance fetching using asyncio.gather - Enhanced display to show: * Individual unstake changes per netuid/hotkey * Remaining stake balances after operations * Final coldkey balance change (previous_balance -> current_balance) - Captures initial balance at function start for accurate display 4. CLI Validation Updates (cli.py) - Removed restriction preventing unstake_all with multiple --include-hotkeys - Updated logic to properly initialize wallet when include_hotkeys is provided - Now supports batching unstake_all operations across multiple hotkeys Technical Details: ================== - Batch Type: Uses Utility.batch_all by default, ensuring atomic execution - Fee Savings: Multiple operations combined into single transaction fee - Backward Compatibility: Single operations still work as before (no batching) - Error Handling: batch_all ensures all operations succeed or fail together - Display Consistency: Balance changes shown consistently across all stake operations Benefits: ========= - Significant fee reduction when performing multiple stake/unstake operations - Improved user experience with clear feedback on all operations - Atomic operations prevent partial failures - Maintains all existing functionality (MEV protection, proxy, etc.)
Contributor
thewhaleking
left a comment
There was a problem hiding this comment.
Looks nice, needs tests.
9461131 to
cb80c5c
Compare
thewhaleking
requested changes
Dec 18, 2025
Comment on lines
+510
to
+531
| call = await subtensor.substrate.compose_call( | ||
| call_module="SubtensorModule", | ||
| call_function="add_stake_limit", | ||
| call_params={ | ||
| "hotkey": staking_address, | ||
| "netuid": netuid, | ||
| "amount_staked": am.rao, | ||
| "limit_price": price_with_tol.rao, | ||
| "allow_partial": allow_partial_stake, | ||
| }, | ||
| ) | ||
| else: | ||
| # Regular staking for root subnet or non-safe staking | ||
| call = await subtensor.substrate.compose_call( | ||
| call_module="SubtensorModule", | ||
| call_function="add_stake", | ||
| call_params={ | ||
| "hotkey": staking_address, | ||
| "netuid": netuid, | ||
| "amount_staked": am.rao, | ||
| }, | ||
| ) |
Contributor
There was a problem hiding this comment.
you'll want to get the block_hash = chain head at the beginning of the function, and then, in these compose_call calls, pass the block_hash=block_hash, which will significantly speed things up (otherwise it needs to make a network call for each compose_call call.
cb80c5c to
d0e0696
Compare
Author
|
I just noticed that many of my prs are all closed. giving up gittensor |
2 tasks
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.
…action fees
This commit implements comprehensive batching support for CLI commands that can submit multiple extrinsic calls, significantly reducing transaction fees for users. This addresses GitHub issue #567.
Core Changes:
New Batching Interface (subtensor_interface.py)
Stake Add Command Refactoring (stake/add.py)
Stake Remove Command Refactoring (stake/remove.py)
CLI Validation Updates (cli.py)
Technical Details:
Benefits:
Closes #567