feat: Add batch extrinsic support to reduce transaction fees#863
Open
bittoby wants to merge 1 commit intoopentensor:stagingfrom
Open
feat: Add batch extrinsic support to reduce transaction fees#863bittoby wants to merge 1 commit intoopentensor:stagingfrom
bittoby wants to merge 1 commit intoopentensor:stagingfrom
Conversation
Author
|
@thewhaleking could you review my PR? Welcome to any feedbacks. |
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.
Problem
Every stake/unstake operation currently submits a separate on-chain extrinsic. A user staking to 3 netuids across 2 hotkeys pays 6 individual transaction fees. This adds up fast.
Solution
Wrap multiple calls into a single
Utility.batch_alltransaction so the user only pays one fee regardless of how many operations they're performing.The core change is a new
sign_and_send_batch_extrinsic()method onSubtensorInterfacethat composes abatch_allcall and delegates to the existingsign_and_send_extrinsic. This means proxy, MEV protection, nonce, era, and signing logic are all reused - no duplication.Batching kicks in automatically when there are 2+ operations. Single operations go through the original path unchanged.
What's batched
btcli stake add- multiple netuid/hotkey stake operationsbtcli stake remove- multiple netuid/hotkey unstake operationsbtcli stake remove --all- unstake-all across multiple hotkeysNotes
batch_allis atomic: all calls succeed or the entire batch reverts. No partial execution.Files changed
subtensor_interface.py- newsign_and_send_batch_extrinsic()methodstake/add.py- batch path for multi-operation stakingstake/remove.py- batch path for multi-operation unstaking + unstake-alltests/unit_tests/test_batching.py- 7 unit tests covering the batch methodTest plan
Fixes: #567