Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
latentvector committed May 2, 2024
1 parent 4b6b991 commit d39c627
Show file tree
Hide file tree
Showing 10 changed files with 306 additions and 370 deletions.
1 change: 0 additions & 1 deletion commune/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,6 @@ def call_search(cls,
namespace = c.namespace(search=search, network=network)
future2module = {}
for module, address in namespace.items():
c.print(args, kwargs, extra_kwargs)
future = c.submit(c.call,

kwargs = { 'module': module, 'fn': fn, 'timeout': timeout,
Expand Down
1 change: 0 additions & 1 deletion commune/os.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ def cpu_usage(self):
import psutil
# get the system performance data for the cpu
cpu_usage = psutil.cpu_percent()
c.print(c.fn_schema(psutil.cpu_percent))
return cpu_usage


Expand Down
37 changes: 33 additions & 4 deletions commune/subspace/subspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@ class Subspace(c.Module):
Handles interactions with the subspace chain.
"""


whitelist = ['query',
'score',
'keys',
'incentives',
'stakes',
'netuids',
'subnet2netuid',
'query_map',
'get_module',
'get_balance',
Expand Down Expand Up @@ -93,6 +97,10 @@ def __init__(
**kwargs,
):
self.set_config(kwargs=kwargs)
c.print(self.config)
if self.config.run_loop == True:
c.print('Running loop')
c.thread(self.run_loop)

network_mode = 'ws'

Expand Down Expand Up @@ -2322,7 +2330,11 @@ def state_dict(self ,

def sync(self,*args, **kwargs):

self.stake_from(update=1)
self.global_params(update=1)
self.subnet_params(update=1)
self.get_balances(update=1)



def check_storage(self, block_hash = None, network=network):
Expand Down Expand Up @@ -2852,6 +2864,7 @@ def unstake(
key : 'c.Key' = None, # defaults to first key
netuid : Union[str, int] = 0, # defaults to module.netuid
network: str= None,
buffer = 0,
**kwargs
) -> dict:
"""
Expand Down Expand Up @@ -2893,10 +2906,12 @@ def unstake(
raise Exception('Invalid input')

if amount == None:
stake_to = self.get_stake_to(netuid=netuid, names = False, fmt='nano', key=module_key)
amount = stake_to[module_key] - 100000
stake_to = self.get_stake_to(netuid=netuid, names = False, fmt='nano', key=key.ss58_address)
amount = stake_to[module_key]
else:
amount = int(self.to_nanos(amount))

amount = max(0, amount - buffer)
# convert to nanos
params={
'amount': amount ,
Expand Down Expand Up @@ -3306,7 +3321,7 @@ def register_servers(cls, servers = None , key2address = None, timeout=60, netui
key2address = key2address or c.key2address()
if servers == None:
servers = list(key2address.keys())
key2address = {k:v for k,v in key2address.items() if k in servers}
key2address = {s['name']: s['ss58_address'] for s in servers}
futures = []
launcher_keys = c.launcher_keys()
future2launcher = {}
Expand Down Expand Up @@ -3356,6 +3371,19 @@ def unregistered_servers(self, search=None, netuid = 0, network = network, time
if key2address[s] not in keys:
unregister_servers += [s]
return unregister_servers


def rm_min_value_keys(self, min_value=0.1, **kwargs):
key2balance = self.key2value(**kwargs)
key2address = c.address2key()
for k,v in key2balance.items():
if v < min_value and k in key2address:
c.print(f'Removing {k} with value {v}')
# try:
# c.rm_key(k)
# except Exception as e:
# c.print(f'Error removing {k} with value {v} {e}')
return {'success': True, 'message': f'Removed keys with value < {min_value}'}

def get_balances(self,
keys=None,
Expand All @@ -3376,6 +3404,7 @@ def get_balances(self,
key2address = c.key2address(search=search)
if keys == None:
keys = list(key2address.keys())

if len(keys) > n:
c.print(f'Getting balances for {len(keys)} keys > {n} keys, using batch_size {batch_size}')
balances = self.balances(network=network, **kwargs)
Expand Down
1 change: 1 addition & 0 deletions commune/subspace/subspace.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
block_time: 8
run_loop: False
chain_release_path: f"{c.repo_path}/subspace/target/release/node-subspace"
network_mode: ws
frontend:
Expand Down
21 changes: 21 additions & 0 deletions commune/watchdog/watchdog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import commune as c

class Watchdog(c.Module):
def __init__(self):
c.thread(self.run_loop)

def sync(self):
c.print('syncing...')
c.ip(update=1)
c.tree(update=1)
c.namespace(update=1)
c.print('synced')
def run_loop(self, sleep_time=60):
while True:
try:
self.sync()
except Exception as e:
print(e)
pass
c.sleep(sleep_time)
print(f'sleeping for {sleep_time} seconds')
Loading

0 comments on commit d39c627

Please sign in to comment.