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

fix: check validator has enough stake to set weight on the network #81

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
bittensor
torch
torch
substrateinterface
8 changes: 8 additions & 0 deletions template/base/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from template.base.neuron import BaseNeuron
from template.mock import MockDendrite
from template.utils.config import add_validator_args
from template.utils.substrate import get_weights_min_stake


class BaseValidatorNeuron(BaseNeuron):
Expand Down Expand Up @@ -221,6 +222,13 @@ def set_weights(self):
"""
Sets the validator weights to the metagraph hotkeys based on the scores it has received from the miners. The weights determine the trust and incentive level the validator assigns to miner nodes on the network.
"""
validator_stake = self.metagraph.S[self.uid]
weight_min_stake = get_weights_min_stake(self.subtensor.substrate)
if validator_stake < weight_min_stake:
bt.logging.warning(
f"Not enough stake t{validator_stake} to set weight, require a minimum of t{weight_min_stake}. Please stake more if you do not want to be de-registered!"
)
return

# Check if self.scores contains any NaN values and log a warning if it does.
if torch.isnan(self.scores).any():
Expand Down
14 changes: 14 additions & 0 deletions template/utils/substrate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import bittensor as bt
from substrateinterface import SubstrateInterface

def get_weights_min_stake(substrate: SubstrateInterface):
"""
Return the minimum of TAO a validator need to have the set weight
"""
weight_min_stake = substrate.query(
module="SubtensorModule", storage_function="WeightsMinStake", params=[]
)
bt.logging.debug(f"get_weights_min_stake() {weight_min_stake}")

# Convert Rao to Tao
return int(float(weight_min_stake.value) * 10**-9)