Skip to content
Merged
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
4 changes: 0 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
# Changelog

## 2.1.0 / 2024-03-30

**Full Changelog**: https://github.com/eclipsevortex/SubVortex/compare/v2.0.0...v2.1.0

## 2.0.0 / 2024-03-28

## What's Changed
Expand Down
28 changes: 22 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
- [Registering your wallet](#registering-your-wallet)
- [Running a Miner](#running-a-miner)
- [Running a Validator](#running-a-validator)
- [Releases](#releases)
- [New Releases](#new-releases)
- [Troubleshooting](#troubleshooting)
- [Troubleshooting Subtensor](#troubleshooting-subtensor)
- [License](#license)
Expand Down Expand Up @@ -352,9 +352,6 @@ pm2 start neurons/miner.py \

### Running a Validator

> **MINIMUM 1000 TAO REQUIRED TO SET WEIGHTS** <br />
A validate function will blacklist set-weights transactions from keys with less than 1000 TAO. This is designed to reduce chain bloat and make it easier for validators and root network participants to set weights on the chain.

> IMPORTANT: Before running a validator, be sure you have a redis up and running. Please see the [Redis guide](./scripts/redis/README.md) for more details.

> IMPORTANT: By default wandb is enabled when running a validator. It is **HIGHLY RECOMMANDED** to not disable it as it enables everyone to access various statistics for better performance on the subnet but if you want to do it, just add `--wandb.off` to the followed pm2 command. If you want to keep wandb enabled, please refer to the [Wandb guide](./docs/wandb/wandb.md) for more details as there are some manually steps to go throught before running the validator.
Expand All @@ -375,9 +372,28 @@ pm2 start neurons/validator.py \

> NOTE: to access the wandb UI to get statistics about the miners, you can click on this [link](https://wandb.ai/eclipsevortext/subvortex-team) and choose the validator run you want.

## Releases
## New Releases

When a new version of the subnet is released, each miner/validatior have to be updated.

> Be sure you are in the SubVortex directory

Get the lastest version of the subnet

```
git pull
```

- [Release-2.1.0](./scripts/release/release-2.1.0/RELEASE-2.1.0.md)
Install the dependencies

```
pip install -r requirements.txt
pip install -e .
```

Restart miners/validators if running them in your base environment or restart pm2 by executing `pm2 restart all` if you are using pm2 as process manager.

> NOTE: to access the wandb UI to get statistics about the miners, you can click on this [link](https://wandb.ai/eclipsevortext/subvortex-team) and choose the validator run you want.

## Troubleshooting

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.1.0
2.0.0
4 changes: 2 additions & 2 deletions docs/wandb/wandb.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ wandb: Paste an API key from your profile and hit enter, or press ctrl+c to quit

# Configuration

## Validator <a id="configuration-validator"></a>
## Validator

The default configuration is enough to have a good user experience so there is no real need to update it.

Expand All @@ -89,7 +89,7 @@ Options

To enhance user experience, we have decided to name each run using the format `validator-<VALIDATOR_UID>-<COUNT>`. This format allows users to easily identify the runs of the validator they wish to access. The count will increment with each run until it reaches 10000, at which point it will reset.

## Miner <a id="configuration-miner"></a>
## Miner

For miner, wandb is not needed so nothing to do here.

Expand Down
4 changes: 0 additions & 4 deletions neurons/miner.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import threading
import traceback

from subnet import __version__ as THIS_VERSION
from subnet.protocol import IsAlive, Score

from subnet.shared.checks import check_registration
Expand Down Expand Up @@ -193,9 +192,6 @@ def _score(self, synapse: Score) -> Score:
bt.logging.info(f"[{validator_uid}] Reliability score {synapse.reliability}")
bt.logging.info(f"[{validator_uid}] Distribution score {synapse.distribution}")
bt.logging.success(f"[{validator_uid}] Score {synapse.score}")

synapse.version = THIS_VERSION

return synapse

def blacklist_score(self, synapse: Score) -> typing.Tuple[bool, str]:
Expand Down
115 changes: 92 additions & 23 deletions neurons/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@
from redis import asyncio as aioredis
import threading
import bittensor as bt
from shlex import quote
from copy import deepcopy
from pprint import pformat
from traceback import print_exception
from substrateinterface.base import SubstrateInterface

from subnet.shared.checks import check_registration
from subnet.shared.utils import get_redis_password
from subnet.shared.subtensor import get_current_block
from subnet.shared.subtrate import get_weights_min_stake
from subnet.shared.weights import should_set_weights

from subnet.validator.config import config, check_config, add_args
Expand Down Expand Up @@ -180,6 +183,9 @@ def run(self):
load_state(self)
checkpoint(self)

bt.logging.info("starting subscription handler")
self.run_subscription_thread()

try:
while 1:
start_epoch = time.time()
Expand Down Expand Up @@ -230,28 +236,17 @@ async def run_forward():
bt.logging.info("Checkpointing...")
checkpoint(self)

# Check validator has enough state to set weight
bt.logging.info("Checking if enough stake to set weights")
validator_stake = self.metagraph.S[self.uid]
weight_min_stake = get_weights_min_stake(self.subtensor.substrate)
has_enough_stake = validator_stake > weight_min_stake
if has_enough_stake == False:
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!"
)

# Set the weights on chain.
bt.logging.info("Checking if should set weights")
validator_should_set_weights = should_set_weights(
get_current_block(self.subtensor),
prev_set_weights_block,
360, # tempo
has_enough_stake == False or self.config.neuron.disable_set_weights,
self.config.neuron.disable_set_weights,
)
bt.logging.debug(
f"Should validator check weights? -> {validator_should_set_weights}"
)

if validator_should_set_weights:
bt.logging.debug(f"Setting weights {self.moving_averaged_scores}")
set_weights_for_validator(
Expand All @@ -273,27 +268,101 @@ async def run_forward():
if self.config.neuron.verbose:
bt.logging.debug(f"block at end of step: {self.prev_step_block}")
bt.logging.debug(f"Step took {time.time() - start_epoch} seconds")

self.step += 1

except Exception as err:
bt.logging.error("Error in training loop", str(err))
bt.logging.debug(print_exception(type(err), err, err.__traceback__))

except KeyboardInterrupt:
if not self.config.wandb.off:
bt.logging.info(
"KeyboardInterrupt caught, gracefully closing the wandb run..."
)
if self.wandb is not None:
self.wandb.finish()
assert self.wandb.run is None

# After all we have to ensure subtensor connection is closed properly
finally:
if hasattr(self, "subtensor"):
bt.logging.debug("Closing subtensor connection")
self.subtensor.close()
self.stop_subscription_thread()

if self.wandb is not None:
bt.logging.debug("Finishing wandb run")
self.wandb.finish()

# TODO: After investigation done and decision taken, remove or change it
def start_event_subscription(self):
"""
Starts the subscription handler in a background thread.
"""
substrate = SubstrateInterface(
ss58_format=bt.__ss58_format__,
use_remote_preset=True,
url=self.subtensor.chain_endpoint,
type_registry=bt.__type_registry__,
)
self.subscription_substrate = substrate

def neuron_registered_subscription_handler(obj, update_nr, subscription_id):
block_no = obj["header"]["number"]
block_hash = substrate.get_block_hash(block_id=block_no)
bt.logging.debug(f"subscription block hash: {block_hash}")
events = substrate.get_events(block_hash)

for event in events:
event_dict = event["event"].decode()
if event_dict["event_id"] == "NeuronRegistered":
netuid, uid, hotkey = event_dict["attributes"]
if int(netuid) == 21:
self.log(
f"NeuronRegistered Event {uid}! Rebalancing data...\n"
f"{pformat(event_dict)}\n"
)

self.last_registered_block = block_no
self.rebalance_queue.append(hotkey)

# If we have some hotkeys deregistered, and it's been 5 blocks since we've caught a registration: rebalance
if (
len(self.rebalance_queue) > 0
and self.last_registered_block + 5 <= block_no
):
hotkeys = deepcopy(self.rebalance_queue)
self.rebalance_queue.clear()
self.log(f"Running rebalance in separate process on hotkeys {hotkeys}")

# Fire off the script
hotkeys_str = ",".join(map(str, hotkeys))
hotkeys_arg = quote(hotkeys_str)
# subprocess.Popen(
# [
# self.rebalance_script_path,
# hotkeys_arg,
# self.subtensor.chain_endpoint,
# str(self.config.database.index),
# ]
# )

substrate.subscribe_block_headers(neuron_registered_subscription_handler)

def run_subscription_thread(self):
"""
Start the block header subscription handler in a separate thread.
"""
if not self.subscription_is_running:
self.subscription_thread = threading.Thread(
target=self.start_event_subscription, daemon=True
)
self.subscription_thread.start()
self.subscription_is_running = True
bt.logging.debug("Started subscription handler.")

def stop_subscription_thread(self):
"""
Stops the subscription handler that is running in the background thread.
"""
if self.subscription_is_running:
bt.logging.debug("Stopping subscription in background thread.")
self.should_exit = True
self.subscription_thread.join(5)
self.subscription_is_running = False
self.subscription_substrate.close()
bt.logging.debug("Stopped subscription handler.")


if __name__ == "__main__":
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ torch==2.0.1
redis==5.0.1
aioredis==2.0.1
wandb==0.16.5
substrate-interface==1.7.5
98 changes: 0 additions & 98 deletions scripts/redis/docs/redis-backup.md

This file was deleted.

Loading