Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
latentvector committed Apr 14, 2024
1 parent 7e930e6 commit 004cc19
Show file tree
Hide file tree
Showing 12 changed files with 160 additions and 115 deletions.
35 changes: 35 additions & 0 deletions commune/subspace/vali.py
Original file line number Diff line number Diff line change
@@ -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


23 changes: 0 additions & 23 deletions commune/subspace/vali/subspace_vali.py

This file was deleted.

3 changes: 3 additions & 0 deletions docs/blackpaper/3_emissions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion docs/blackpaper/5_staking.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
11 changes: 6 additions & 5 deletions docs/blackpaper/7_tokens.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ Token State
},
'native_pool_balance': 1000 # the balance of the pool
}
}



```

Expand Down Expand Up @@ -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='
6 changes: 2 additions & 4 deletions docs/blackpaper/8_multichain.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion scripts/kill_ports.sh
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
76 changes: 76 additions & 0 deletions vali/README.md
Original file line number Diff line number Diff line change
@@ -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': {}
}
]


2 changes: 1 addition & 1 deletion vali/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
51 changes: 0 additions & 51 deletions vali/vali copy.yaml

This file was deleted.

61 changes: 33 additions & 28 deletions vali/vali.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()}
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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

Expand Down
Loading

0 comments on commit 004cc19

Please sign in to comment.