Skip to content

Commit

Permalink
fix: prevent miner from setting weights
Browse files Browse the repository at this point in the history
  • Loading branch information
jarvis8x7b committed Feb 25, 2024
1 parent cbde40b commit 13192d8
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 35 deletions.
7 changes: 0 additions & 7 deletions neurons/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,13 @@ def _filter_valid_responses(responses: List[RankingRequest]) -> List[RankingRequ


class Validator(BaseNeuron):
"""Singleton class for validator, this means that trying to instantiate the
same validator class will always return the same instance. This prevents
trying to maintain multiple metagraphs, subtensors, etc.
"""

def __init__(self):
super(Validator, self).__init__()

self.axon.attach(
forward_fn=self.forward_mturk_response,
blacklist_fn=self.blacklist_mturk_response,
)
self.axon.serve(netuid=self.config.netuid, subtensor=self.subtensor)

##### FROM BaseValidatorNeuron ########################################
# Save a copy of the hotkeys to local memory.
Expand Down
29 changes: 1 addition & 28 deletions template/base/miner.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,34 +148,7 @@ def __exit__(self, exc_type, exc_value, traceback):
self.stop_run_thread()

def set_weights(self):
"""
Self-assigns a weight of 1 to the current miner (identified by its UID) and
a weight of 0 to all other peers in the network. The weights determine the trust level the miner assigns to other nodes on the network.
Raises:
Exception: If there's an error while setting weights, the exception is logged for diagnosis.
"""
try:
# --- query the chain for the most current number of peers on the network
chain_weights = torch.zeros(
self.subtensor.subnetwork_n(netuid=self.metagraph.netuid)
)
chain_weights[self.uid] = 1

# --- Set weights.
self.subtensor.set_weights(
wallet=self.wallet,
netuid=self.metagraph.netuid,
uids=torch.arange(0, len(chain_weights)),
weights=chain_weights.to("cpu"),
wait_for_inclusion=False,
version_key=self.spec_version,
)

except Exception as e:
bt.logging.error(f"Failed to set weights on chain with exception: { e }")

bt.logging.info(f"Set weights: {chain_weights}")
pass

def resync_metagraph(self):
"""Resyncs the metagraph and updates the hotkeys and moving averages based on the new metagraph."""
Expand Down

0 comments on commit 13192d8

Please sign in to comment.