bittensor icon indicating copy to clipboard operation
bittensor copied to clipboard

Childkey takes

Open distributedstatemachine opened this issue 1 year ago • 0 comments

Description

Implement set_childkey_take functionality in the Bittensor CLI to interact with the newly added chain feature. This allows a coldkey to set the childkey take for a given hotkey on a specific subnet.

Acceptance Criteria

  1. Implement set_childkey_take function in the Subtensor class
  2. Implement get_childkey_take function in the Subtensor class
  3. Create a new CLI command for setting childkey take
  4. Create a new CLI command for querying childkey take
  5. Write unit tests for new functionality
  6. Update documentation

Tasks

  1. Implement set_childkey_take function in the Subtensor class
def set_childkey_take(
    self,
    wallet: "bittensor.wallet",
    hotkey: str,
    netuid: int,
    take: float,
    wait_for_inclusion: bool = True,
    wait_for_finalization: bool = False,
) -> bool:
    # Validate input
    if not 0 <= take <= 0.18:
        raise ValueError("Take must be between 0 and 0.18")

    # Convert take to u16 representation
    take_u16 = int(take * 10000)

    # Create and send extrinsic
    try:
        success = self._do_set_childkey_take(
            wallet=wallet,
            hotkey=hotkey,
            netuid=netuid,
            take=take_u16,
            wait_for_inclusion=wait_for_inclusion,
            wait_for_finalization=wait_for_finalization,
        )
        return success
    except Exception as e:
        bittensor.__console__.print(f":cross_mark: [red]Failed to set childkey take: {e}[/red]")
        return False
  1. Implement get_childkey_take function in the Subtensor class
def get_childkey_take(
    self,
    hotkey: str,
    netuid: int,
    block: Optional[int] = None
) -> Optional[float]:
    try:
        result = self.query_subtensor("ChildkeyTake", block, [hotkey, netuid])
        if result is None:
            return None
        return float(result) / 10000  # Convert from u16 to float
    except Exception as e:
        bittensor.__console__.print(f":cross_mark: [red]Failed to get childkey take: {e}[/red]")
        return None
  1. Create a new CLI command for setting childkey take
class SetChildkeyTakeCommand:
    @staticmethod
    def run(cli: "bittensor.cli"):
        r"""Set childkey take for a hotkey on a specific subnet."""
        wallet = bittensor.wallet(config=cli.config)
        subtensor = bittensor.subtensor(config=cli.config)

        # Get parameters
        hotkey = cli.config.hotkey
        netuid = cli.config.netuid
        take = cli.config.take

        # Set childkey take
        success = subtensor.set_childkey_take(
            wallet=wallet,
            hotkey=hotkey,
            netuid=netuid,
            take=take,
            wait_for_inclusion=cli.config.wait_for_inclusion,
            wait_for_finalization=cli.config.wait_for_finalization,
        )

        if success:
            cli.console.print(f"Successfully set childkey take for hotkey {hotkey} on subnet {netuid} to {take}")
        else:
            cli.console.print(f"Failed to set childkey take for hotkey {hotkey} on subnet {netuid}")
  1. Create a new CLI command for querying childkey take
class GetChildkeyTakeCommand:
    @staticmethod
    def run(cli: "bittensor.cli"):
        r"""Get childkey take for a hotkey on a specific subnet."""
        subtensor = bittensor.subtensor(config=cli.config)

        # Get parameters
        hotkey = cli.config.hotkey
        netuid = cli.config.netuid

        # Get childkey take
        take = subtensor.get_childkey_take(hotkey=hotkey, netuid=netuid)

        if take is not None:
            cli.console.print(f"Childkey take for hotkey {hotkey} on subnet {netuid}: {take}")
        else:
            cli.console.print(f"Failed to get childkey take for hotkey {hotkey} on subnet {netuid}")

distributedstatemachine avatar Aug 20 '24 23:08 distributedstatemachine