Skip to content

Commit

Permalink
remove nonce verification from miner axon.
Browse files Browse the repository at this point in the history
  • Loading branch information
acer-king committed Oct 15, 2024
1 parent ce7bb34 commit afbd923
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
26 changes: 26 additions & 0 deletions cortext/axon.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import bittensor
import bittensor as bt
from substrateinterface import Keypair
from bittensor.errors import SynapseDendriteNoneException


class CortexAxon(bt.axon):
def default_verify(self, synapse: bittensor.Synapse):
if synapse.dendrite is not None:
keypair = Keypair(ss58_address=synapse.dendrite.hotkey)

# Build the signature messages.
message = f"{synapse.dendrite.nonce}.{synapse.dendrite.hotkey}.{self.wallet.hotkey.ss58_address}.{synapse.dendrite.uuid}.{synapse.computed_body_hash}"

# Build the unique endpoint key.
endpoint_key = f"{synapse.dendrite.hotkey}:{synapse.dendrite.uuid}"

if not keypair.verify(message, synapse.dendrite.signature):
raise Exception(
f"Signature mismatch with {message} and {synapse.dendrite.signature}"
)

# Success
self.nonces[endpoint_key] = synapse.dendrite.nonce # type: ignore
else:
raise SynapseDendriteNoneException()
5 changes: 3 additions & 2 deletions miner/miner.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from cortext.protocol import StreamPrompting
from cortext.metaclasses import ServiceRegistryMeta
from cortext.axon import CortexAxon
from miner.services import ALL_SERVICE_TYPE

from miner.config import get_config, Config
Expand Down Expand Up @@ -88,14 +89,14 @@ def init_axon(self):
bt.logging.debug(
f"Starting axon on port {self.config.axon.port} and external ip {self.config.axon.external_ip}"
)
self.axon = bt.axon(
self.axon = CortexAxon(
wallet=self.wallet,
port=self.config.axon.port,
external_ip=self.config.axon.external_ip
)
else:
bt.logging.debug(f"Starting axon on port {self.config.axon.port}")
self.axon = bt.axon(wallet=self.wallet, port=self.config.axon.port)
self.axon = CortexAxon(wallet=self.wallet, port=self.config.axon.port)

# Get all registered services
for service in self.services:
Expand Down

0 comments on commit afbd923

Please sign in to comment.