Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release/6.12.2 #1910

Merged
merged 9 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## 6.12.2 / 2024-05-20

## What's Changed
* Add setting delegate take
* fix: deprecated transfer method usage

**Full Changelog**: https://github.com/opentensor/bittensor/compare/v6.12.1...54eee604c00ac4f04a31d5d7bc663124731a34d8


## 6.12.1 / 2024-05-17

## What's Changed
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.12.1
6.12.2
2 changes: 1 addition & 1 deletion bittensor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

# Bittensor code and protocol version.

__version__ = "6.12.1"
__version__ = "6.12.2"

version_split = __version__.split(".")
__version_as_int__: int = (
Expand Down
2 changes: 2 additions & 0 deletions bittensor/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
RunFaucetCommand,
SenateCommand,
SetIdentityCommand,
SetTakeCommand,
StakeCommand,
StakeShow,
SubnetGetHyperparamsCommand,
Expand Down Expand Up @@ -121,6 +122,7 @@
"senate": SenateCommand,
"register": RootRegisterCommand,
"proposals": ProposalsCommand,
"set_take": SetTakeCommand,
"delegate": DelegateStakeCommand,
"undelegate": DelegateUnstakeCommand,
"my_delegates": MyDelegatesCommand,
Expand Down
1 change: 1 addition & 0 deletions bittensor/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
DelegateStakeCommand,
DelegateUnstakeCommand,
MyDelegatesCommand,
SetTakeCommand,
)
from .wallets import (
NewColdkeyCommand,
Expand Down
113 changes: 111 additions & 2 deletions bittensor/commands/delegates.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
import bittensor
from typing import List, Optional
from rich.table import Table
from rich.prompt import Prompt
from rich.prompt import Confirm
from rich.prompt import Confirm, FloatPrompt, Prompt
from rich.console import Text
from tqdm import tqdm
from substrateinterface.exceptions import SubstrateRequestException
Expand Down Expand Up @@ -891,3 +890,113 @@ def check_config(config: "bittensor.config"):
):
wallet_name = Prompt.ask("Enter wallet name", default=defaults.wallet.name)
config.wallet.name = str(wallet_name)


class SetTakeCommand:
"""
Executes the ``set_take`` command, which sets the delegate take.
The command performs several checks:
1. Hotkey is already a delegate
2. New take value is within 0-18% range
Optional Arguments:
- ``take``: The new take value
- ``wallet.name``: The name of the wallet to use for the command.
- ``wallet.hotkey``: The name of the hotkey to use for the command.
Usage:
To run the command, the user must have a configured wallet with both hotkey and coldkey. Also, the hotkey should already be a delegate.
Example usage::
btcli root set_take --wallet.name my_wallet --wallet.hotkey my_hotkey
Note:
This function can be used to update the takes individually for every subnet
"""

@staticmethod
def run(cli: "bittensor.cli"):
r"""Set delegate take."""
try:
subtensor: "bittensor.subtensor" = bittensor.subtensor(
config=cli.config, log_verbose=False
)
SetTakeCommand._run(cli, subtensor)
finally:
if "subtensor" in locals():
subtensor.close()
bittensor.logging.debug("closing subtensor connection")

@staticmethod
def _run(cli: "bittensor.cli", subtensor: "bittensor.subtensor"):
r"""Set delegate take."""
config = cli.config.copy()
wallet = bittensor.wallet(config=cli.config)

# Unlock the wallet.
wallet.hotkey
wallet.coldkey

# Check if the hotkey is not a delegate.
if not subtensor.is_hotkey_delegate(wallet.hotkey.ss58_address):
bittensor.__console__.print(
"Aborting: Hotkey {} is NOT a delegate.".format(
wallet.hotkey.ss58_address
)
)
return

# Prompt user for take value.
new_take_str = config.get("take")
if new_take_str == None:
new_take = FloatPrompt.ask(f"Enter take value (0.18 for 18%)")
else:
new_take = float(new_take_str)

if new_take > 0.18:
bittensor.__console__.print(
"ERROR: Take value should be in the range of 0 to 18%"
)
return

result: bool = subtensor.set_take(
wallet=wallet,
delegate_ss58=wallet.hotkey.ss58_address,
take=new_take,
)
if not result:
bittensor.__console__.print("Could not set the take")
else:
# Check if we are a delegate.
is_delegate: bool = subtensor.is_hotkey_delegate(wallet.hotkey.ss58_address)
if not is_delegate:
bittensor.__console__.print(
"Could not set the take [white]{}[/white]".format(subtensor.network)
)
return
bittensor.__console__.print(
"Successfully set the take on [white]{}[/white]".format(
subtensor.network
)
)

@staticmethod
def add_args(parser: argparse.ArgumentParser):
set_take_parser = parser.add_parser(
"set_take", help="""Set take for delegate"""
)
set_take_parser.add_argument(
"--take",
dest="take",
type=float,
required=False,
help="""Take as a float number""",
)
bittensor.wallet.add_args(set_take_parser)
bittensor.subtensor.add_args(set_take_parser)

@staticmethod
def check_config(config: "bittensor.config"):
if not config.is_set("wallet.name") and not config.no_prompt:
wallet_name = Prompt.ask("Enter wallet name", default=defaults.wallet.name)
config.wallet.name = str(wallet_name)

if not config.is_set("wallet.hotkey") and not config.no_prompt:
hotkey = Prompt.ask("Enter hotkey name", default=defaults.wallet.hotkey)
config.wallet.hotkey = str(hotkey)
31 changes: 16 additions & 15 deletions bittensor/commands/unstake.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,22 +85,23 @@ def check_config(cls, config: "bittensor.config"):
hotkeys = str(config.hotkeys).replace("[", "").replace("]", "")
else:
hotkeys = str(config.wallet.hotkey)
if not Confirm.ask(
"Unstake all Tao from: [bold]'{}'[/bold]?".format(hotkeys)
):
amount = Prompt.ask("Enter Tao amount to unstake")
config.unstake_all = False
try:
config.amount = float(amount)
except ValueError:
console.print(
":cross_mark:[red] Invalid Tao amount[/red] [bold white]{}[/bold white]".format(
amount
)
)
sys.exit()
else:
if config.no_prompt:
config.unstake_all = True
else:
# I really don't like this logic flow. It can be a bit confusing to read for something
# as serious as unstaking all.
if Confirm.ask(f"Unstake all Tao from: [bold]'{hotkeys}'[/bold]?"):
config.unstake_all = True
else:
config.unstake_all = False
amount = Prompt.ask("Enter Tao amount to unstake")
try:
config.amount = float(amount)
except ValueError:
console.print(
f":cross_mark:[red] Invalid Tao amount[/red] [bold white]{amount}[/bold white]"
)
sys.exit()

@staticmethod
def add_args(command_parser):
Expand Down
6 changes: 6 additions & 0 deletions bittensor/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ class NominationError(ChainTransactionError):
pass


class TakeError(ChainTransactionError):
r"""Error raised when a increase / decrease take transaction fails."""

pass


class TransferError(ChainTransactionError):
r"""Error raised when a transfer transaction fails."""

Expand Down
142 changes: 141 additions & 1 deletion bittensor/extrinsics/delegation.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@

import logging
import bittensor
from ..errors import NominationError, NotDelegateError, NotRegisteredError, StakeError
from ..errors import (
NominationError,
NotDelegateError,
NotRegisteredError,
StakeError,
TakeError,
)
from rich.prompt import Confirm
from typing import Union, Optional
from bittensor.utils.balance import Balance
Expand Down Expand Up @@ -357,3 +363,137 @@ def undelegate_extrinsic(
except StakeError as e:
bittensor.__console__.print(":cross_mark: [red]Stake Error: {}[/red]".format(e))
return False


def decrease_take_extrinsic(
subtensor: "bittensor.subtensor",
wallet: "bittensor.wallet",
hotkey_ss58: Optional[str] = None,
take: int = 0,
wait_for_finalization: bool = False,
wait_for_inclusion: bool = True,
) -> bool:
r"""Decrease delegate take for the hotkey.

Args:
wallet (bittensor.wallet):
Bittensor wallet object.
hotkey_ss58 (Optional[str]):
The ``ss58`` address of the hotkey account to stake to defaults to the wallet's hotkey.
take (float):
The ``take`` of the hotkey.
Returns:
success (bool): ``True`` if the transaction was successful.
"""
# Unlock the coldkey.
wallet.coldkey
wallet.hotkey

with bittensor.__console__.status(
":satellite: Sending decrease_take_extrinsic call on [white]{}[/white] ...".format(
subtensor.network
)
):
try:
success = subtensor._do_decrease_take(
wallet=wallet,
hotkey_ss58=hotkey_ss58,
take=take,
wait_for_inclusion=wait_for_inclusion,
wait_for_finalization=wait_for_finalization,
)

if success == True:
bittensor.__console__.print(
":white_heavy_check_mark: [green]Finalized[/green]"
)
bittensor.logging.success(
prefix="Decrease Delegate Take",
sufix="<green>Finalized: </green>" + str(success),
)

return success

except Exception as e:
bittensor.__console__.print(
":cross_mark: [red]Failed[/red]: error:{}".format(e)
)
bittensor.logging.warning(
prefix="Set weights", sufix="<red>Failed: </red>" + str(e)
)
except TakeError as e:
bittensor.__console__.print(
":cross_mark: [red]Failed[/red]: error:{}".format(e)
)
bittensor.logging.warning(
prefix="Set weights", sufix="<red>Failed: </red>" + str(e)
)

return False


def increase_take_extrinsic(
subtensor: "bittensor.subtensor",
wallet: "bittensor.wallet",
hotkey_ss58: Optional[str] = None,
take: int = 0,
wait_for_finalization: bool = False,
wait_for_inclusion: bool = True,
) -> bool:
r"""Increase delegate take for the hotkey.

Args:
wallet (bittensor.wallet):
Bittensor wallet object.
hotkey_ss58 (Optional[str]):
The ``ss58`` address of the hotkey account to stake to defaults to the wallet's hotkey.
take (float):
The ``take`` of the hotkey.
Returns:
success (bool): ``True`` if the transaction was successful.
"""
# Unlock the coldkey.
wallet.coldkey
wallet.hotkey

with bittensor.__console__.status(
":satellite: Sending increase_take_extrinsic call on [white]{}[/white] ...".format(
subtensor.network
)
):
try:
success = subtensor._do_increase_take(
wallet=wallet,
hotkey_ss58=hotkey_ss58,
take=take,
wait_for_inclusion=wait_for_inclusion,
wait_for_finalization=wait_for_finalization,
)

if success == True:
bittensor.__console__.print(
":white_heavy_check_mark: [green]Finalized[/green]"
)
bittensor.logging.success(
prefix="Increase Delegate Take",
sufix="<green>Finalized: </green>" + str(success),
)

return success

except Exception as e:
bittensor.__console__.print(
":cross_mark: [red]Failed[/red]: error:{}".format(e)
)
bittensor.logging.warning(
prefix="Set weights", sufix="<red>Failed: </red>" + str(e)
)
except TakeError as e:
bittensor.__console__.print(
":cross_mark: [red]Failed[/red]: error:{}".format(e)
)
bittensor.logging.warning(
prefix="Set weights", sufix="<red>Failed: </red>" + str(e)
)

return False
1 change: 1 addition & 0 deletions bittensor/extrinsics/root.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ def set_root_weights_extrinsic(
success (bool):
Flag is ``true`` if extrinsic was finalized or uncluded in the block. If we did not wait for finalization / inclusion, the response is ``true``.
"""

# First convert types.
if isinstance(netuids, list):
netuids = torch.tensor(netuids, dtype=torch.int64)
Expand Down
Loading