Merge pull request #9 from guilledk/spam-command

add enqueue spam command
pull/14/head
Guillermo Rodriguez 2023-07-04 01:49:03 -03:00 committed by GitHub
commit b48ce8ac3f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 62 additions and 28 deletions

72
skynet/cli.py 100644 → 100755
View File

@ -13,7 +13,7 @@ import asyncio
import requests import requests
from leap.cleos import CLEOS from leap.cleos import CLEOS
from leap.sugar import collect_stdout from leap.sugar import collect_stdout, Name, asset_from_str
from leap.hyperion import HyperionAPI from leap.hyperion import HyperionAPI
from skynet.ipfs import IPFSHTTP from skynet.ipfs import IPFSHTTP
@ -100,7 +100,8 @@ def download():
'--node-url', '-n', default='https://skynet.ancap.tech') '--node-url', '-n', default='https://skynet.ancap.tech')
@click.option( @click.option(
'--reward', '-r', default='20.0000 GPU') '--reward', '-r', default='20.0000 GPU')
@click.option('--algo', '-a', default='midj') @click.option('--jobs', '-j', default=1)
@click.option('--model', '-m', default='prompthero/openjourney')
@click.option( @click.option(
'--prompt', '-p', default='a red old tractor in a sunny wheat field') '--prompt', '-p', default='a red old tractor in a sunny wheat field')
@click.option('--output', '-o', default='output.png') @click.option('--output', '-o', default='output.png')
@ -110,12 +111,14 @@ def download():
@click.option('--step', '-s', default=26) @click.option('--step', '-s', default=26)
@click.option('--seed', '-S', default=None) @click.option('--seed', '-S', default=None)
@click.option('--upscaler', '-U', default='x4') @click.option('--upscaler', '-U', default='x4')
@click.option('--binary_data', '-b', default='')
def enqueue( def enqueue(
account: str, account: str,
permission: str, permission: str,
key: str | None, key: str | None,
node_url: str, node_url: str,
reward: str, reward: str,
jobs: int,
**kwargs **kwargs
): ):
key, account, permission = load_account_info( key, account, permission = load_account_info(
@ -125,6 +128,8 @@ def enqueue(
'user', node_url, None, None) 'user', node_url, None, None)
with open_cleos(node_url, key=key) as cleos: with open_cleos(node_url, key=key) as cleos:
async def enqueue_n_jobs():
for i in range(jobs):
if not kwargs['seed']: if not kwargs['seed']:
kwargs['seed'] = random.randint(0, 10e9) kwargs['seed'] = random.randint(0, 10e9)
@ -132,14 +137,23 @@ def enqueue(
'method': 'diffuse', 'method': 'diffuse',
'params': kwargs 'params': kwargs
}) })
binary = '' binary = kwargs['binary_data']
ec, out = cleos.push_action( res = await cleos.a_push_action(
'telos.gpu', 'enqueue', [account, req, binary, reward], f'{account}@{permission}' 'telos.gpu',
'enqueue',
{
'user': Name(account),
'request_body': req,
'binary_data': binary,
'reward': asset_from_str(reward),
'min_verification': 1
},
account, key, permission,
) )
print(res)
trio.run(enqueue_n_jobs)
print(collect_stdout(out))
assert ec == 0
@skynet.command() @skynet.command()
@click.option('--loglevel', '-l', default='INFO', help='Logging level') @click.option('--loglevel', '-l', default='INFO', help='Logging level')
@ -235,12 +249,17 @@ def dequeue(
'user', node_url, None, None) 'user', node_url, None, None)
with open_cleos(node_url, key=key) as cleos: with open_cleos(node_url, key=key) as cleos:
ec, out = cleos.push_action( res = trio.run(cleos.a_push_action,
'telos.gpu', 'dequeue', [account, request_id], f'{account}@{permission}' 'telos.gpu',
'dequeue',
{
'user': Name(account),
'request_id': int(request_id),
},
account, key, permission,
) )
print(res)
print(collect_stdout(out))
assert ec == 0
@skynet.command() @skynet.command()
@click.option( @click.option(
@ -269,12 +288,17 @@ def config(
node_url, _, _ = load_endpoint_info( node_url, _, _ = load_endpoint_info(
'user', node_url, None, None) 'user', node_url, None, None)
with open_cleos(node_url, key=key) as cleos: with open_cleos(node_url, key=key) as cleos:
ec, out = cleos.push_action( res = trio.run(cleos.a_push_action,
'telos.gpu', 'config', [token_contract, token_symbol], f'{account}@{permission}' 'telos.gpu',
'config',
{
'token_contract': token_contract,
'token_symbol': token_symbol,
},
account, key, permission,
) )
print(res)
print(collect_stdout(out))
assert ec == 0
@skynet.command() @skynet.command()
@click.option( @click.option(
@ -298,11 +322,21 @@ def deposit(
node_url, _, _ = load_endpoint_info( node_url, _, _ = load_endpoint_info(
'user', node_url, None, None) 'user', node_url, None, None)
with open_cleos(node_url, key=key) as cleos:
ec, out = cleos.transfer_token(account, 'telos.gpu', quantity)
print(collect_stdout(out)) with open_cleos(node_url, key=key) as cleos:
assert ec == 0 res = trio.run(cleos.a_push_action,
'eosio.token',
'transfer',
{
'sender': Name(account),
'recipient': Name('telos.gpu'),
'amount': asset_from_str(quantity),
'memo': f'{account} transferred {quantity} to telos.gpu'
},
account, key, permission,
)
print(res)
@skynet.group() @skynet.group()
def run(*args, **kwargs): def run(*args, **kwargs):

4
skynet/config.py 100644 → 100755
View File

@ -71,8 +71,8 @@ def load_account_info(
if not key and 'key' in sub_config: if not key and 'key' in sub_config:
key = sub_config['key'] key = sub_config['key']
if not account and 'name' in sub_config: if not account and 'account' in sub_config:
account = sub_config['name'] account = sub_config['account']
if not permission and 'permission' in sub_config: if not permission and 'permission' in sub_config:
permission = sub_config['permission'] permission = sub_config['permission']