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

Remove abusable code from subnet template #88

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
52 changes: 30 additions & 22 deletions neurons/miner.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,30 +94,38 @@ async def blacklist(

Otherwise, allow the request to be processed further.
"""
# TODO(developer): Define how miners should blacklist requests.
uid = self.metagraph.hotkeys.index(synapse.dendrite.hotkey)
if (
not self.config.blacklist.allow_non_registered
and synapse.dendrite.hotkey not in self.metagraph.hotkeys
):
# Ignore requests from un-registered entities.
try:
# TODO(developer): Define how miners should blacklist requests.
if not synapse.dendrite.hotkey:
return True, "Missing hotkey/Malformed request"

if (
not self.config.blacklist.allow_non_registered
and synapse.dendrite.hotkey not in self.metagraph.hotkeys
):
# Ignore requests from un-registered entities.
bt.logging.trace(
f"Blacklisting un-registered hotkey {synapse.dendrite.hotkey}"
)
return True, "Unrecognized hotkey"

uid = self.metagraph.hotkeys.index(synapse.dendrite.hotkey)

if self.config.blacklist.force_validator_permit:
# If the config is set to force validator permit, then we should only allow requests from validators.
if not self.metagraph.validator_permit[uid]:
bt.logging.warning(
f"Blacklisting a request from non-validator hotkey {synapse.dendrite.hotkey}"
)
return True, "Non-validator hotkey"

bt.logging.trace(
f"Blacklisting un-registered hotkey {synapse.dendrite.hotkey}"
f"Not Blacklisting recognized hotkey {synapse.dendrite.hotkey}"
)
return True, "Unrecognized hotkey"

if self.config.blacklist.force_validator_permit:
# If the config is set to force validator permit, then we should only allow requests from validators.
if not self.metagraph.validator_permit[uid]:
bt.logging.warning(
f"Blacklisting a request from non-validator hotkey {synapse.dendrite.hotkey}"
)
return True, "Non-validator hotkey"

bt.logging.trace(
f"Not Blacklisting recognized hotkey {synapse.dendrite.hotkey}"
)
return False, "Hotkey recognized!"
return False, "Hotkey recognized!"
except Exception as e:
bt.logging.error(f"Exception in blacklist_fn: {str(e)}")
return True
cxmplex marked this conversation as resolved.
Show resolved Hide resolved

async def priority(self, synapse: template.protocol.Dummy) -> float:
"""
Expand Down