diff --git a/commune/subspace/vali.py b/commune/subspace/vali.py new file mode 100644 index 000000000..270bcaca7 --- /dev/null +++ b/commune/subspace/vali.py @@ -0,0 +1,35 @@ +import commune as c + + +class Vali(c.m('vali')): + def __init__(self, + search='subspace', + reference='subspace', + netuid = 0, + network = 'local', + **kwargs): + self.init_vali(kwargs) + self.reference = c.m(reference)() + self.sync_time = 10 + + def get_module_key(self): + keys = self.reference.keys(netuid = self.config.netuid) + return c.shuffle(keys)[0] + + + def score_module(self, module): + key = self.get_module_key() + local_output = self.reference.get_module(key) + remote_output = module.get_module(key) + + c.print('remote_output', remote_output) + c.print('local_output', local_output) + remote_hash = c.hash(remote_output) + local_hash = c.hash(local_output) + + if local_hash == remote_hash: + return 1 + else: + return 0 + + diff --git a/commune/subspace/vali/subspace_vali.py b/commune/subspace/vali/subspace_vali.py deleted file mode 100644 index c4cb60c44..000000000 --- a/commune/subspace/vali/subspace_vali.py +++ /dev/null @@ -1,23 +0,0 @@ -import commune as c - -class SubspaceVali(c.Module): - def __init__(self,network='main' , - tempo=10, max_age=10,): - self.subspace = c.module('subspace')(network=network) - self.max_age = max_age - self.network = network - self.tempo = tempo - - def score(self,module='subspace', netuid=0) -> int: - remote_subspace = c.connect(module) - keys = self.subspace.keys() - key = c.choice(keys) - kwargs = {'module_key': key, 'netuid': netuid} - futures = [c.submit(remote_subspace.get_module, kwargs=kwargs), - c.submit(self.subspace.get_module, kwargs=kwargs)] - remote_module, local_module = c.wait(futures) - c.print(remote_module, local_module) - remote_hash = c.hash(remote_module) - local_hash = c.hash(local_module) - score = int(remote_hash==local_hash) - return {'w': score} \ No newline at end of file diff --git a/docs/blackpaper/3_emissions.md b/docs/blackpaper/3_emissions.md index 3d7979258..88f94e304 100644 --- a/docs/blackpaper/3_emissions.md +++ b/docs/blackpaper/3_emissions.md @@ -3,6 +3,9 @@ +Th + + **Stake Based Conseneus Protocals** Commune is a flexible modular chain that allows for multiple consensus protocals. The two main protocals are yuma and yomama. Commune intends to have a flexible network that can adapt to different use cases and add additional protocals in the future for different use cases. diff --git a/docs/blackpaper/5_staking.md b/docs/blackpaper/5_staking.md index 4a50f5c54..3fc136c07 100644 --- a/docs/blackpaper/5_staking.md +++ b/docs/blackpaper/5_staking.md @@ -9,7 +9,7 @@ c.stake('5E2SmnsAiciqU67pUT3PcpdUL623HccjarKeRv2NhZA2zNES', 100, netuid=10) or to stake multiple amounts to multiple keys, you can do so like this ```python -c.stake_multiple(['5E2SmnsAiciqU67pUT3PcpdUL623HccjarKeRv2NhZA2zNES', '5ERLrXrrKPg9k99yp8DuGhop6eajPEgzEED8puFzmtJfyJES'], [100, 100], netuid=10) +c.stake_multiple(modules=['5E2SmnsAiciqU67pUT3PcpdUL623HccjarKeRv2NhZA2zNES', '5ERLrXrrKPg9k99yp8DuGhop6eajPEgzEED8puFzmtJfyJES'], amounts=[100, 100], netuid=10) ``` to transfer 100 between two registered modules you can do so like this. diff --git a/docs/blackpaper/7_tokens.md b/docs/blackpaper/7_tokens.md index a32f37d3f..a0b98984e 100644 --- a/docs/blackpaper/7_tokens.md +++ b/docs/blackpaper/7_tokens.md @@ -41,7 +41,8 @@ Token State }, 'native_pool_balance': 1000 # the balance of the pool } -} + + ``` @@ -99,13 +100,13 @@ If a module or subnet points towards a token address. The mint ratio will direct Connecting a token to a module or subnet ```python -c.update_module('module', token_ratio=0.1) +c.add_module_token(module='module', # the module address + token='5F4bEvY7UBoM47qqedn8tv55YFAuqFwq1AgNHN9MXV5Dpteg', # the token address + emission_ratio=0.1 # the ratio of emissions that are minted to the token + ) ``` This means 10 percent of the liquidity (0.1) is being directed into the pool while getting the tokens minted in addition to the tokens from the pool. This forces less volitility as it incentivizes volume. - Connecting all of the Assets in the World : A decentralized blackrock The following will connect all of the assets in the world to the chain. We do this by allowing for the option for minting tokens using multisignature wallets. These signers of the ultisignature can approve the minting and burning of tokens upon collateralization of the assets. This allows for any token to be minted and burned upon the collateralization of the assets. -```python -c.add_module_token(module='model.openai::jay', token_address=' \ No newline at end of file diff --git a/docs/blackpaper/8_multichain.md b/docs/blackpaper/8_multichain.md index 01718f978..fa0eb7a59 100644 --- a/docs/blackpaper/8_multichain.md +++ b/docs/blackpaper/8_multichain.md @@ -1,8 +1,7 @@ -Tokens: - -We want anyone to make a token where the community can provide liquidity to support new ideas that benefit open source projects. These tokens can be minted if they are connected the a subnet or a module. The native token has a null address of +Multichain: +We live in a multichain world ```python c.add_token(key='5Fe8eMg6YGDhZUwnnmiarTyNNGACGHeoDTVXez94yGA9mz9w', #the key of the token supply=1000000, # initial supplys @@ -79,7 +78,6 @@ Native Pool Balance The native pool balance is the balance of the native tokens in the pool. This is the balance of the native tokens in the pool. - ```python diff --git a/scripts/kill_ports.sh b/scripts/kill_ports.sh index fca25e7ea..57f7fd744 100755 --- a/scripts/kill_ports.sh +++ b/scripts/kill_ports.sh @@ -1,6 +1,6 @@ #!/bin/bash -for port in $(seq 50000 50150); do +for port in $(seq 50000 50250); do pid=$(lsof -ti :$port) if [[ ! -z "$pid" ]]; then echo "Killing process $pid on port $port" diff --git a/vali/README.md b/vali/README.md index e69de29bb..5b064a02c 100644 --- a/vali/README.md +++ b/vali/README.md @@ -0,0 +1,76 @@ + + + + +c serve subspace.vali + + +{'success': True, 'name': 'subspace.vali', 'address': '67.250.163.31:50161', 'kwargs': {}} + + +c subspace/fleet n=10 + +[ + { + 'success': True, + 'name': 'subspace::3', + 'address': '67.250.163.31:50143', + 'kwargs': {} + }, + { + 'success': True, + 'name': 'subspace::7', + 'address': '67.250.163.31:50187', + 'kwargs': {} + }, + { + 'success': True, + 'name': 'subspace::5', + 'address': '67.250.163.31:50140', + 'kwargs': {} + }, + { + 'success': True, + 'name': 'subspace::9', + 'address': '67.250.163.31:50214', + 'kwargs': {} + }, + { + 'success': True, + 'name': 'subspace::0', + 'address': '67.250.163.31:50173', + 'kwargs': {} + }, + { + 'success': True, + 'name': 'subspace::4', + 'address': '67.250.163.31:50200', + 'kwargs': {} + }, + { + 'success': True, + 'name': 'subspace::2', + 'address': '67.250.163.31:50149', + 'kwargs': {} + }, + { + 'success': True, + 'name': 'subspace::1', + 'address': '67.250.163.31:50131', + 'kwargs': {} + }, + { + 'success': True, + 'name': 'subspace::8', + 'address': '67.250.163.31:50193', + 'kwargs': {} + }, + { + 'success': True, + 'name': 'subspace::6', + 'address': '67.250.163.31:50062', + 'kwargs': {} + } +] + + diff --git a/vali/app.py b/vali/app.py index d5390cacc..cac8eadd9 100644 --- a/vali/app.py +++ b/vali/app.py @@ -20,7 +20,7 @@ def dashboard(cls): if len(state) == 0 : state = { 'run_info': server.run_info, - 'module_infos': server.module_infos(update=True) + 'module_infos': server.leaderboard(update=True) } self.put(state_path, state) diff --git a/vali/vali copy.yaml b/vali/vali copy.yaml deleted file mode 100644 index 54f0f2014..000000000 --- a/vali/vali copy.yaml +++ /dev/null @@ -1,51 +0,0 @@ - -# network -path: null -network: subspace -netuid: 0 # optional if you have a voting network with subnets [bittensor, commune] -verbose: False -sync_interval: 100 -sleep_interval: 5 -search: null -max_age: 500 -vote: True -fn : null - -# score -alpha: 0.5 - -worker_fn_name: worker -# voting -vote: True -min_stake: 1 -vote_interval: 100 # the interval to vote (in blocks (8 seconds per block)) -vote_timeout: 50 # the timeout for the vote (in blocks) -voting_networks: ['subspace', 'bittensor'] - -# stats -max_history: 10 - -# score -connect_score: 0.1 -latency_score_weight: 0.2 -alpha: 0.5 # the ma average -vote_tag : null - -# workers -mode: thread -batch_size: 32 # the batch size for the worker -workers: 2 # the number of workers -threads_per_worker: 32 -timeout: 8 -sleep_time: 0.05 -refresh : True -start: True -is_main_worker: True -min_num_weights: 10 -debug: False -print_interval: 10 -clone_suffix : clone - - - - diff --git a/vali/vali.py b/vali/vali.py index d68ec7d0c..7d7c75344 100644 --- a/vali/vali.py +++ b/vali/vali.py @@ -203,15 +203,11 @@ def network_staleness(self): def is_voting_network(self): return 'subspace' in self.config.network or 'bittensor' in self.config.network - def filter_module(self, module:str): if self.config.search in module: return True return False - - - - + def set_network(self, network:str=None, search:str=None, @@ -265,6 +261,8 @@ def set_network(self, namespace = c.module('namespace').namespace(search=search, max_age=max_age) self.namespace = namespace + self.namespace = {k: v for k, v in self.namespace.items() if self.filter_module(k)} + self.n = len(self.namespace) self.name2address = self.namespace self.address2name = {v: k for k, v in self.namespace.items()} @@ -436,12 +434,15 @@ def vote_info(self): return info - def votes(self): + def votes(self, + + ): network = self.config.network - module_infos = self.module_infos(network=network, df=False) + keys = ['name', 'w', 'staleness','latency', 'ss58_address'], + leaderboard = self.leaderboard(network=network, keys=keys, to_dict=True, n= self.config.max_votes) votes = {'keys' : [],'weights' : [],'uids': [], 'timestamp' : c.time() } key2uid = self.subspace.key2uid() if hasattr(self, 'subspace') else {} - for info in module_infos: + for info in leaderboard: ## valid modules have a weight greater than 0 and a valid ss58_address if 'ss58_address' in info and info['w'] >= 0: if info['ss58_address'] in key2uid: @@ -486,47 +487,51 @@ def set_weights(self, def module_info(self, **kwargs): return self.subspace.module_info(self.key.ss58_address, netuid=self.netuid, **kwargs) - def module_infos(self, + def leaderboard(self, keys = ['name', 'w', 'staleness', - 'latency', 'ss58_address'], + 'latency'], path = 'cache/module_infos', max_age = 3600, min_weight = 0, network = None, - ascending = True, - sort_by = ['staleness'], - df = True, - n = None, + ascending = False, + sort_by = ['w','staleness'], + to_dict = False, + n = 50, + page = None, **kwargs ): paths = self.module_paths(network=network) - module_infos = [] + df = [] # chunk the jobs into batches for path in paths: r = self.get(path, max_age=max_age) if isinstance(r, dict) and 'ss58_address' in r: r['staleness'] = c.time() - r.get('timestamp', 0) - module_infos += [{k: r.get(k, None) for k in keys}] + df += [{k: r.get(k, None) for k in keys}] else : self.rm(path) - self.put(path, module_infos) - module_infos = c.df(module_infos) - assert len(module_infos) > 0 - module_infos = module_infos.sort_values(by=sort_by, ascending=ascending) + self.put(path, df) + df = c.df(df) + assert len(df) > 0 + # sort_by = [s for s in sort_by if s in df.columns] + df = df.sort_values(by=sort_by, ascending=ascending) if min_weight > 0: - module_infos = module_infos[module_infos['w'] > min_weight] + df = df[df['w'] > min_weight] if n != None: - module_infos = module_infos[:n] - if not df: - return module_infos.to_dict(orient='records') + if page != None: + df = df[page*n:(page+1)*n] + else: + df = df[:n] - return module_infos + + if to_dict: + return df.to_dict(orient='records') - def leaderboard(self, *args, df=True, **kwargs): - df = self.module_infos(*args, df=df, **kwargs) return df - + + l = leaderboard diff --git a/vali/vali.yaml b/vali/vali.yaml index d20007dbf..45707230c 100644 --- a/vali/vali.yaml +++ b/vali/vali.yaml @@ -4,7 +4,7 @@ network: subspace netuid: 0 # optional if you have a voting network with subnets [bittensor, commune] verbose: False sync_interval: 10 -min_update_interval: 1 +min_update_interval: 4 # the minimum interval to update the network sleep_interval: 5 sample_sleep_interval: 0.1 initial_sleep : 1 @@ -47,6 +47,7 @@ min_num_weights: 10 debug: False print_interval: 2 clone_suffix : clone +max_votes: 1000