Skip to content

Commit

Permalink
added changes to docker and testnet additions
Browse files Browse the repository at this point in the history
  • Loading branch information
latentvector committed Jun 14, 2024
1 parent 95474bd commit e7d85c2
Show file tree
Hide file tree
Showing 31 changed files with 283 additions and 168 deletions.
30 changes: 18 additions & 12 deletions commune/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ def get_output(self, argv):
if you are calling a function ont he module function (the root module), it is not necessary to specify the module
c {fn} arg1 arg2 arg3 ... argn
"""


if '/' in argv[0]:
argv = argv[0].split('/') + argv[1:]
is_fn = False
Expand Down Expand Up @@ -81,18 +83,6 @@ def get_output(self, argv):

return output

def history(self,**kwargs):
history = self.history_module.history(**kwargs)
return history

def rm_history(self,*args, **kwargs):
history = self.history_module.rm_history(*args, **kwargs)
return history


def history_paths(self, **kwargs):
history = self.history_module.history_paths(**kwargs)
return history


@classmethod
Expand Down Expand Up @@ -164,6 +154,22 @@ def determine_type(cls, x):
return x


@classmethod
def history(cls,**kwargs):
history = cls.history_module().history(**kwargs)
return history

@classmethod
def rm_history(cls,*args, **kwargs):
history = cls.history_module().rm_history(*args, **kwargs)
return history


@classmethod
def history_paths(cls, **kwargs):
history = cls.history_module().history_paths(**kwargs)
return history

def main():
import sys
cli()
32 changes: 32 additions & 0 deletions commune/docker/files/Dockerfile.poetry_ubuntu
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
FROM ubuntu:22.04

# Set the working directory in the container
WORKDIR /app
# Set environment variables

ENV PYTHONUNBUFFERED True
ARG DEBIAN_FRONTEND=noninteractive
RUN usermod -s /bin/bash root
RUN apt-get update

# INSTALL RUST ENV
RUN apt-get install curl nano build-essential cargo libstd-rust-dev -y

# INSTALL NODEJS ENV
RUN apt-get install -y nodejs npm
# install pm2 for process management (currently required for commune)
RUN npm install -g pm2

# INSTALL PYTHON ENV
RUN apt-get install python3-pip python3 python3-dev python-is-python3 -y
RUN python -m pip install --upgrade pip

# --- INSTALL POETRY ---
RUN pip install poetry
COPY ./pyproject.toml /app/pyproject.toml
# you may need the lock or you can disable it
COPY ./poetry.lock /app/poetry.lock
COPY ./ /app
RUN poetry install

ENTRYPOINT [ "tail", "-f", "/dev/null"]
40 changes: 18 additions & 22 deletions commune/module/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,6 @@ def resolve_path(cls, path:str = None, extension:Optional[str]= None, file_type:
dirpath = os.path.dirname(path)
if not os.path.exists(dirpath):
os.makedirs(dirpath, exist_ok=True)

return path

@classmethod
Expand Down Expand Up @@ -2722,27 +2721,24 @@ def memory_usage(fmt='gb'):

@classmethod
def argparse(cls, verbose: bool = False, **kwargs):
argv = ' '.join(c.argv())
if ' --' in argv or ' -' in argv:
parser = argparse.ArgumentParser(description='Argparse for the module')
parser.add_argument('-fn', '--fn', dest='function', help='The function of the key', type=str, default="__init__")
parser.add_argument('-kwargs', '--kwargs', dest='kwargs', help='key word arguments to the function', type=str, default="{}")
parser.add_argument('-p', '-params', '--params', dest='params', help='key word arguments to the function', type=str, default="{}")
parser.add_argument('-i','-input', '--input', dest='input', help='key word arguments to the function', type=str, default="{}")
parser.add_argument('-args', '--args', dest='args', help='arguments to the function', type=str, default="[]")
args = parser.parse_args()
if verbose:
c.print('Argparse Args: ',args, color='cyan')
args.kwargs = json.loads(args.kwargs.replace("'",'"'))
args.params = json.loads(args.params.replace("'",'"'))
args.inputs = json.loads(args.input.replace("'",'"'))

# if you pass in the params, it will override the kwargs
if len(args.params) > len(args.kwargs):
args.kwargs = args.params
args.args = json.loads(args.args.replace("'",'"'))
else:
args = c.parse_args()
parser = argparse.ArgumentParser(description='Argparse for the module')
parser.add_argument('-fn', '--fn', dest='function', help='The function of the key', type=str, default="__init__")
parser.add_argument('-kwargs', '--kwargs', dest='kwargs', help='key word arguments to the function', type=str, default="{}")
parser.add_argument('-p', '-params', '--params', dest='params', help='key word arguments to the function', type=str, default="{}")
parser.add_argument('-i','-input', '--input', dest='input', help='key word arguments to the function', type=str, default="{}")
parser.add_argument('-args', '--args', dest='args', help='arguments to the function', type=str, default="[]")
args = parser.parse_args()
if verbose:
c.print('Argparse Args: ',args, color='cyan')
args.kwargs = json.loads(args.kwargs.replace("'",'"'))
args.params = json.loads(args.params.replace("'",'"'))
args.inputs = json.loads(args.input.replace("'",'"'))

# if you pass in the params, it will override the kwargs
if len(args.params) > len(args.kwargs):
args.kwargs = args.params
args.args = json.loads(args.args.replace("'",'"'))
c.print('args', args, color='cyan')
return args


Expand Down
29 changes: 19 additions & 10 deletions commune/subspace/subspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,29 @@ def __init__(
self.set_config(kwargs=kwargs)


def resolve_url(self, url = None, mode='http', **kwargs):
def filter_url(self, url):
"""
Filter urls based on the url_search parameter
"""
if self.config.url_search == None:
return True
url_search_terms = [url.strip() for x in self.config.url_search.split(',')]
return any([x in url for x in url_search_terms])

def resolve_url(self, url = None, mode=None, **kwargs):
mode = mode or self.config.network_mode
url = url or self.config.url
assert mode in ['http', 'ws']
if url != None:
return url

network = self.resolve_network()
def is_match(x):
url_search_terms = [x.strip() for x in self.config.url_search.split(',')]
return any([url in x for url in url_search_terms])
mode = mode or self.config.network_mode
assert mode in ['http', 'ws', 'wss', 'https']
if url == None:
urls_map = getattr(self.config.urls, network)
urls = []
for provider, mode2url in urls_map.items():
if is_match(provider):
urls += list(mode2url[mode])
urls = urls_map.get(mode, [])
assert len(urls) > 0, f'No urls found for network {network} and mode {mode}'
if len(urls) > 1:
urls_map = list(filter(self.filter_url, urls))
url = c.choice(urls)
return url

Expand Down
86 changes: 38 additions & 48 deletions commune/subspace/subspace.yaml
Original file line number Diff line number Diff line change
@@ -1,26 +1,33 @@
block_time: 8
network: test
netuid: 0
subnet: commune
mode: http
run_loop: False
chain_release_path: f"{c.repo_path}/subspace/target/release/node-subspace"
network_mode: ws

frontend:
telemetry:
feed: ws://165.22.186.112:50094/feed
frontend: http://165.22.186.112:50107
shard: ws://165.22.186.112:50090/submit 0
key: null
local: false
loop: false
network: main
netuid: 0
mode: http
retry_params:
backoff: 2
delay: 2
max_delay: 4
tries: 2
save_interval: 1800
subnet: commune

url: null
url_search: commune-api-node-1 # search for the best node
urls:
main:
http:
- https://commune.api.onfinality.io/public-http
- https://commune-api-node-1.communeai.net/
- https://commune-api-node-2.communeai.net/
- https://commune-api-node-3.communeai.net/
- https://commune-api-node-4.communeai.net/
ws:
- wss://commune.api.onfinality.io/public-ws
- wss://commune-api-node-1.communeai.net/
- wss://commune-api-node-2.communeai.net/
- wss://commune-api-node-3.communeai.net/
- wss://commune-api-node-4.communeai.net/
test:
ws:
- wss://testnet-commune-api-node-0.communeai.net
http:
- https://testnet-commune-api-node-0.communeai.net

global_features: [
"MaxNameLength",
"MaxAllowedModules",
Expand Down Expand Up @@ -54,32 +61,15 @@ module_features : [
"stake_from",
"delegation_fee",
]
supported_schemas:
- Sr25519
- Ed25519

token_decimals: 9
url: null
url_search: commies
urls:
main:
commies:
http:
- https://commune-api-node-1.communeai.net/
- https://commune-api-node-2.communeai.net/
- https://commune-api-node-3.communeai.net/
- https://commune-api-node-4.communeai.net/
ws:
- wss://commune-api-node-1.communeai.net/
- wss://commune-api-node-2.communeai.net/
- wss://commune-api-node-3.communeai.net/
- wss://commune-api-node-4.communeai.net/
local:
http:
- http://0.0.0.0:9944
ws:
- ws://0.0.0.0:9944
onfinality:
http:
- https://commune.api.onfinality.io/public-http
ws:
- wss://commune.api.onfinality.io/public-ws
block_time: 8
loop: false
retry_params:
backoff: 2
delay: 2
max_delay: 4
tries: 2

save_interval: 1800
supported_schemas: [Sr25519, Ed25519]
Loading

0 comments on commit e7d85c2

Please sign in to comment.