Skip to content

Conversation

@SmartDever02
Copy link
Contributor

This PR implements comprehensive batching support for CLI commands that can submit multiple extrinsic calls, significantly reducing transaction fees for users. This closes GitHub issue #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.)

Tests for batching:

  • Created test_batching.py for batching extrinsic opeartions

Closes #567

Contribution by Gittensor, learn more at https://gittensor.io/

@SmartDever02
Copy link
Contributor Author

what's the reason tests failing in pipeline? as on my local they passed.
image

@SmartDever02
Copy link
Contributor Author

what's the reason tests failing in pipeline? as on my local they passed. image

okay it was because of #778 , pushed a fix

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.

1 participant