Skip to content

Commit

Permalink
Revert "Add set_delegate_take command to btcli (#1563)"
Browse files Browse the repository at this point in the history
This reverts commit 2a3f6f6.

We're holding off on delegate set_take for now. Not on main or test chain.
  • Loading branch information
ifrit98 committed Nov 29, 2023
1 parent 5d533bd commit 94a6e37
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 227 deletions.
1 change: 0 additions & 1 deletion bittensor/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@
"my_delegates": MyDelegatesCommand,
"list_delegates": ListDelegatesCommand,
"nominate": NominateCommand,
"set_delegate_take": SetDelegateTakeCommand,
},
},
"wallet": {
Expand Down
1 change: 0 additions & 1 deletion bittensor/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@
DelegateStakeCommand,
DelegateUnstakeCommand,
MyDelegatesCommand,
SetDelegateTakeCommand,
)
from .wallets import (
NewColdkeyCommand,
Expand Down
98 changes: 0 additions & 98 deletions bittensor/commands/delegates.py
Original file line number Diff line number Diff line change
Expand Up @@ -835,101 +835,3 @@ def check_config(config: "bittensor.config"):
):
wallet_name = Prompt.ask("Enter wallet name", default=defaults.wallet.name)
config.wallet.name = str(wallet_name)


class SetDelegateTakeCommand:
"""
Executes the 'set_delegate_take' command, which sets the commission rate (take percentage)
for a user's delegate on the Bittensor network. This commission is the fraction of rewards
that the delegate takes from staking operations.
Optional Arguments:
- wallet.name: The name of the wallet to use for the command.
- delegate.take: The take percentage to set for the delegate.
The function performs several checks:
- Ensures the take value is within the valid range (0.0 to 1.0).
- Verifies that the hotkey associated with the wallet is registered as a delegate.
- Sets the take percentage on the network if the above conditions are met.
Usage:
The user is prompted to enter the desired take value, which must be a float between 0 and 1.
The value is then scaled and cast to an integer ratio before being sent to the network.
Example usage:
>>> btcli root set_delegate_take --take 0.1
>>> btcli root set_delegate_take --wallet.name my_wallet --wallet.hotkey my_hotkey --take 0.1
Note:
This command will result in a change to the blockchain state and may incur transaction fees.
It is interactive and requires input from the user. This function is intended to be used as
part of the Bittensor CLI and not as a standalone function within user code.
"""

@staticmethod
def run(cli):
r"""Set your delegate's take percentage."""
wallet = bittensor.wallet(config=cli.config)
subtensor = bittensor.subtensor(config=cli.config)

# Unlock the wallet.
wallet.hotkey
wallet.coldkey

take = float(cli.config.take)
if take > 1 or take < 0:
bittensor.__console__.print(
"Aborting: Invalid take value: {}".format(cli.config.delegate.take)
)
return

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

result: bool = subtensor.set_delegate_take(
wallet, int(take * 65535)
) # Cast 0-1 float to u16 ratio for chain
if not result:
bittensor.__console__.print(
"Could not set delegate take on [white]{}[/white]".format(
subtensor.network
)
)
else:
bittensor.__console__.print(
"Successfully set delegate take on [white]{}[/white]".format(
subtensor.network
)
)

@staticmethod
def add_args(parser: argparse.ArgumentParser):
set_delegate_take_parser = parser.add_parser(
"set_delegate_take", help="""Set your delegate's take percentage."""
)
set_delegate_take_parser.add_argument(
"--take", dest="take", type=str, required=False
)

bittensor.wallet.add_args(set_delegate_take_parser)
bittensor.subtensor.add_args(set_delegate_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)

if not config.is_set("take") and not config.no_prompt:
take = Prompt.ask("Enter new delegate take value (0 - 1)")
config.take = take
60 changes: 0 additions & 60 deletions bittensor/extrinsics/delegation.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,66 +95,6 @@ def nominate_extrinsic(
return False


def set_delegate_take_extrinsic(
subtensor: "bittensor.subtensor",
wallet: "bittensor.wallet",
take: int,
wait_for_finalization: bool = False,
wait_for_inclusion: bool = True,
) -> bool:
r"""Set the delegate take for the provided hotkey.
Args:
wallet ( bittensor.wallet ):
The wallet to become a delegate for.
take (int):
The u16 ratio of a delegator's rewards you'll take.
Returns:
success (bool):
True if the transaction was successful.
"""
# Unlock the coldkey.
wallet.coldkey
wallet.hotkey

# Check if the hotkey is already a delegate.
if not subtensor.is_hotkey_delegate(wallet.hotkey.ss58_address):
logger.error("Hotkey {} isn't a delegate.".format(wallet.hotkey.ss58_address))
return False

with bittensor.__console__.status(
":satellite: Sending call on [white]{}[/white] ...".format(subtensor.network)
):
try:
success = subtensor._do_set_delegate_take(
wallet=wallet,
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="Set delegate take",
sufix="<green>Finalized: </green>" + str(success),
)

# Raises NominationError if False
return success

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

return False


def delegate_extrinsic(
subtensor: "bittensor.subtensor",
wallet: "bittensor.wallet",
Expand Down
68 changes: 1 addition & 67 deletions bittensor/subtensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
delegate_extrinsic,
nominate_extrinsic,
undelegate_extrinsic,
set_delegate_take_extrinsic,
)
from .extrinsics.senate import (
register_senate_extrinsic,
Expand Down Expand Up @@ -454,37 +453,6 @@ def undelegate(
prompt=prompt,
)

def set_delegate_take(
self,
wallet: "bittensor.wallet",
take: int,
wait_for_finalization: bool = False,
wait_for_inclusion: bool = True,
) -> bool:
"""
Sets the percentage of incentives that a delegate neuron takes from its delegators. This action adjusts
the reward distribution mechanism between a delegate and its supporting neurons.
Args:
wallet (bittensor.wallet): The wallet of the delegate neuron.
take (int): The percentage (0-100) of incentives to take from delegators.
wait_for_finalization (bool, optional): Waits for the transaction to be finalized on the blockchain.
wait_for_inclusion (bool, optional): Waits for the transaction to be included in a block.
Returns:
bool: True if the setting of delegate take percentage is successful, False otherwise.
This method allows a delegate neuron to specify its share of the incentives generated through delegation,
aligning with the network's principles of decentralized governance and fair incentive distribution.
"""
return set_delegate_take_extrinsic(
subtensor=self,
wallet=wallet,
take=take,
wait_for_finalization=wait_for_finalization,
wait_for_inclusion=wait_for_inclusion,
)

#####################
#### Set Weights ####
#####################
Expand Down Expand Up @@ -1925,7 +1893,7 @@ def make_substrate_call_with_retry():
call = substrate.compose_call(
call_module="SubtensorModule",
call_function="root_register",
call_params={"hotkey": wallet.hotkey.ss58_address, "take": 11796},
call_params={"hotkey": wallet.hotkey.ss58_address},
)
extrinsic = substrate.create_signed_extrinsic(
call=call, keypair=wallet.coldkey
Expand Down Expand Up @@ -4005,40 +3973,6 @@ def make_substrate_call_with_retry():

return make_substrate_call_with_retry()

def _do_set_delegate_take(
self,
wallet: "bittensor.wallet",
take: int,
wait_for_inclusion: bool = True,
wait_for_finalization: bool = False,
) -> bool:
@retry(delay=2, tries=3, backoff=2, max_delay=4)
def make_substrate_call_with_retry():
with self.substrate as substrate:
call = substrate.compose_call(
call_module="SubtensorModule",
call_function="set_delegate_take",
call_params={"hotkey": wallet.hotkey.ss58_address, "take": take},
)
extrinsic = substrate.create_signed_extrinsic(
call=call, keypair=wallet.coldkey
) # sign with coldkey
response = substrate.submit_extrinsic(
extrinsic,
wait_for_inclusion=wait_for_inclusion,
wait_for_finalization=wait_for_finalization,
)
# We only wait here if we expect finalization.
if not wait_for_finalization and not wait_for_inclusion:
return True
response.process_events()
if response.is_success:
return True
else:
raise NominationError(response.error_message)

return make_substrate_call_with_retry()

################
#### Legacy ####
################
Expand Down

0 comments on commit 94a6e37

Please sign in to comment.