diff --git a/requirements.txt b/requirements.txt index c1b866e93..e5d84109b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ bittensor -torch \ No newline at end of file +torch +substrateinterface \ No newline at end of file diff --git a/template/base/validator.py b/template/base/validator.py index 79579f50c..a81a84088 100644 --- a/template/base/validator.py +++ b/template/base/validator.py @@ -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): @@ -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(): diff --git a/template/utils/substrate.py b/template/utils/substrate.py new file mode 100644 index 000000000..121e4e9bb --- /dev/null +++ b/template/utils/substrate.py @@ -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)