Skip to content

Commit

Permalink
Add run_update to [pns]. Add debugging symbols. Update version. Globa…
Browse files Browse the repository at this point in the history
…l GRPC server. Update scrtxxs
  • Loading branch information
MathNodes committed Apr 23, 2024
1 parent 8839231 commit f176eb1
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 44 deletions.
9 changes: 6 additions & 3 deletions helpers/insert-nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import uuid
import argparse
import sys
from time import sleep

VERSION = 20240423.0032

def connDB():
db = pymysql.connect(host=scrtxxs.MySQLHost,
Expand Down Expand Up @@ -50,7 +52,7 @@ def connDB():
node_addresses.append(d)
k += 1

print(f"Inserting: {k}, nodes into plan: {puuid}...")
print(f"[in]: Inserting: {k}, nodes into plan: {puuid}...")
queries = []
for a in node_addresses:
q ='''
Expand All @@ -61,11 +63,12 @@ def connDB():
k = 0
for q in queries:
try:
print(q)
print(f"[in]: {q}")
c.execute(q)
db.commit()
k += 1
sleep(2)
except Exception as e:
print(str(e))

print(f"Inserted: {k}, nodes into plan: {puuid}.")
print(f"[in]: Inserted: {k}, nodes into plan: {puuid}.")
46 changes: 27 additions & 19 deletions helpers/plan-node-subscriptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

'''
Run in a crontab:
* * * * * cmd
0 * * * * cmd
'''


Expand All @@ -27,8 +27,9 @@

MNAPI = "https://api.sentinel.mathnodes.com"
NODEAPI = "/sentinel/nodes/%s"
GRPC = scrtxxs.GRPC_MN

VERSION = 20240417.1744
VERSION = 20240423.0031

class PlanSubscribe():

Expand Down Expand Up @@ -60,9 +61,9 @@ def __init__(self, keyring_passphrase, wallet_name, seed_phrase = None):

private_key = self.keyring.get_password("meile-plan", self.wallet_name)

grpcaddr, grpcport = urlparse(scrtxxs.GRPC).netloc.split(":")
grpcaddr, grpcport = urlparse(GRPC).netloc.split(":")

self.sdk = SDKInstance(grpcaddr, int(grpcport), secret=private_key)
self.sdk = SDKInstance(grpcaddr, int(grpcport), secret=private_key, ssl=True)


def __keyring(self, keyring_passphrase: str):
Expand Down Expand Up @@ -176,7 +177,7 @@ def run_insert(node_file, uuid):
if __name__ == "__main__":


parser = argparse.ArgumentParser(description="Meile Plan Subscriber - v0.2 - freQniK")
parser = argparse.ArgumentParser(description="Meile Plan Subscriber - v0.3 - freQniK")

parser.add_argument('--file', help="--file <nodefile>, absolute path of a list of sentnode... addresses separated by newline", metavar="file")
parser.add_argument('--seed', action='store_true',help='set if you are specifying a seedphrase', default=False)
Expand All @@ -195,52 +196,59 @@ def run_insert(node_file, uuid):
nodes = nodefile.readlines()

for n in nodes:
print(f"Subscribing to {n} for {scrtxxs.HOURS} hour(s) on plan {args.uuid}...")
print(f"[pns]: Subscribing to {n} for {scrtxxs.HOURS} hour(s) on plan {args.uuid}...")
response = ps.subscribe_to_nodes_for_plan(n, scrtxxs.HOURS)
print(response)
print("Waiting 5s...")
print("[pns]: Waiting 5s...")
sleep(5)
print(f"Adding {n} to plan {plan_id},{args.uuid}...")
print(f"[pns]: Adding {n} to plan {plan_id},{args.uuid}...")
ps.add_node_to_plan(plan_id, n)



print("Inserting nodes in plan DB...", end='')
print("[pns]: Inserting nodes in plan DB...", end='')
run_insert(args.file, args.uuid)
sleep(2)
print("Done.")

print("[pns]: Done.")
print("[pns]: Wainting...")
sleep(20)
print("[pns]: Updating plan_node_subscriptions...")
run_update(args.uuid)
print("[pns]: Done.")

else:
print("[pns]: Computing Resubscriptions...")
resub_plan_nodes = ps.ComputeResub(ps.GetPlanNodes())
print(resub_plan_nodes)
print(f"[pns]: {resub_plan_nodes}")

uuids = ''
for plan,nodes in resub_plan_nodes.items():
uuids = ','.join([uuids,plan])
for n in nodes:
print(f"Checking if {n} is active...")
print(f"[pns]: Checking if {n} is active...")
try:
resp = requests.get(MNAPI + NODEAPI % n)
nodeJSON = resp.json()

if nodeJSON['node']['status'] == "inactive":
print("Node is inactive, skipping...")
print("[pns]: Node is inactive, skipping...")
continue
except Exception as e:
print(str(e))
pass

print(f"Subscribing to {n} for {scrtxxs.HOURS} hour(s) on plan {plan}...")
print(f"[pns]: Subscribing to {n} for {scrtxxs.HOURS} hour(s) on plan {plan}...")
response = ps.subscribe_to_nodes_for_plan(n, scrtxxs.HOURS)
print(response)
print(f"[pns]: {response}")

print("[pns]: Waiting....")
sleep(10)
# Run db updater script with UUIDs
uuids = uuids.split(',')[1:]
print(uuids)
print(f"[pns]: uuids: {uuids}")
for uuid in uuids:
print(f"Updating node subs for plan {uuid}...", end='')
print(f"[pns]: Updating node subs for plan {uuid}...", end='')
run_update(uuid)
sleep(2)
print("Done.")
print("[pns]: Done.")

16 changes: 11 additions & 5 deletions helpers/update-node-scriptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,18 @@
import sys

UUID = ""
VERSION = 20240423.0019
GRPC = scrtxxs.GRPC_MN

class UpdateNodeScriptions():

def __init__(self):
#private_key = self.keyring.get_password("meile-plan", self.wallet_name)

#grpcaddr, grpcport = urlparse(scrtxxs.GRPC).netloc.split(":")
grpcaddr, grpcport = urlparse(scrtxxs.GRPC).netloc.split(":")
grpcaddr, grpcport = urlparse(GRPC).netloc.split(":")

self._sdk = SDKInstance(grpcaddr, int(grpcport))
self._sdk = SDKInstance(grpcaddr, int(grpcport), ssl=True)
self._db = pymysql.connect(host=scrtxxs.MySQLHost,
port=scrtxxs.MySQLPort,
user=scrtxxs.MySQLUsername,
Expand Down Expand Up @@ -52,6 +54,7 @@ def qs_on_plan(self, nodes):
for s in SubsNodesInfo:
for n in nodes:
if n == s['Node']:
print(f"[uns]: node: {n} is on plan and is subscribed")
node_subs_on_plan.append(s)


Expand Down Expand Up @@ -93,11 +96,12 @@ def UpdateSubsExpiration(self, subs, uuid):
str(s['Inactive Date']))

c.execute(q)
print(f"[uns]: {q}")
self._db.commit()


if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Meile Plan Sub Updater - v0.1 - freQniK")
parser = argparse.ArgumentParser(description="Meile Plan Sub Updater - v0.3 - freQniK")
parser.add_argument('--uuid', help="--uuid <uuid> , plan uuid", metavar="uuid")

args = parser.parse_args()
Expand All @@ -108,8 +112,10 @@ def UpdateSubsExpiration(self, subs, uuid):


uns = UpdateNodeScriptions()

print("[uns]: Getting Nodes on Plan...")
nodes = uns.GetNodesOnPlan(args.uuid)
print(f"[uns]: {nodes}")
print("[uns]: Querying subscriptions of nodes on plan...")
subs_on_plan = uns.qs_on_plan(nodes)

print("[uns]: Updating node inactive date on plan in database...")
uns.UpdateSubsExpiration(subs_on_plan, args.uuid)
40 changes: 23 additions & 17 deletions scrtxxs.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
import pwd
import os

WalletAddress = "sent..."
WalletName = "Name"
HotWalletPW = "password"
SQLAlchemyScrtKey = 'sql_scrt_key'
MySQLHost = "127.0.0.1"
MySQLPort = 3306
MySQLUsername = 'username'
MySQLPassword = 'password'
MySQLDB = 'db_name'
BYTES = 1073741824000 # 1 TB
RPC = "https://rpc.mathnodes.com:443"
GRPC_BLUEFREN = "https://grpc.bluefren.xyz:443"
CHAINID = "sentinelhub-2"
KeyringDIR = "/home/" + str(pwd.getpwuid(os.getuid())[0])
LogDIR = '/home/' + str(pwd.getpwuid(os.getuid())[0]) + '/Logs'
dbDIR = '/home/' + str(pwd.getpwuid(os.getuid())[0]) + '/dbs'
sentinelhub = "/home/" + str(pwd.getpwuid(os.getuid())[0]) + "/go/bin/sentinelhub"
WalletAddress = "sent..."
WalletName = "Name"
HotWalletPW = "password"
SQLAlchemyScrtKey = 'sql_scrt_key'
MySQLHost = "127.0.0.1"
MySQLPort = 3306
MySQLUsername = 'username'
MySQLPassword = 'password'
MySQLDB = 'db_name'
BYTES = 1073741824000 # 1 TB
HOURS = 360
RPC = "https://rpc.mathnodes.com:443"
GRPC = "http://aimokoivunen.mathnodes.com:9090"
GRPC2 = "https://grpc.dvpn.me:443"
GRPC_MN = "https://grpc.mathnodes.com:443"
GRPC_BLUEFREN = "https://grpc.bluefren.xyz:443"
CHAINID = "sentinelhub-2"
KeyringDIR = "/home/" + str(pwd.getpwuid(os.getuid())[0])
LogDIR = '/home/' + str(pwd.getpwuid(os.getuid())[0]) + '/Logs'
dbDIR = '/home/' + str(pwd.getpwuid(os.getuid())[0]) + '/dbs'
sentinelhub = "/home/" + str(pwd.getpwuid(os.getuid())[0]) + "/go/bin/sentinelhub"
COINSTATS_API_KEYS = [""]
HELPERS = "/home/" + str(pwd.getpwuid(os.getuid())[0]) + '/api/helpers'

0 comments on commit f176eb1

Please sign in to comment.