Skip to content
Snippets Groups Projects

Remove truncate and add on conflict clause instead

Compare and Show latest version
1 file
+ 13
9
Compare changes
  • Side-by-side
  • Inline
+ 13
9
@@ -80,7 +80,7 @@ def main():
@@ -80,7 +80,7 @@ def main():
# Deal with bins
# Deal with bins
bins, chain_conf = poll_cmix_info(substrate)
bins, chain_conf = poll_cmix_info(substrate)
log.debug(f"Polled bins: {bins}")
log.debug(f"Polled {len(bins)} bins!")
if bins != current_bins:
if bins != current_bins:
log.info(f"Updating GeoBins: {bins}")
log.info(f"Updating GeoBins: {bins}")
set_bins(conn, bins)
set_bins(conn, bins)
@@ -94,7 +94,7 @@ def main():
@@ -94,7 +94,7 @@ def main():
# Deal with active nodes
# Deal with active nodes
new_dict = poll_active_nodes(substrate)
new_dict = poll_active_nodes(substrate)
log.debug(f"Polled active nodes: {new_dict}")
log.debug(f"Polled {len(new_dict)} active nodes!")
if active_dict != new_dict:
if active_dict != new_dict:
log.info(f"Updating active nodes: {len(new_dict)} nodes")
log.info(f"Updating active nodes: {len(new_dict)} nodes")
@@ -110,7 +110,7 @@ def main():
@@ -110,7 +110,7 @@ def main():
# Pass a copy because the dict will be mutated
# Pass a copy because the dict will be mutated
set_active_nodes(conn, copy.deepcopy(new_dict))
set_active_nodes(conn, copy.deepcopy(new_dict))
#
# Update the new dictionary of active nodes
active_dict = new_dict
active_dict = new_dict
time.sleep(polling_freq)
time.sleep(polling_freq)
@@ -225,16 +225,19 @@ def get_substrate_provider():
@@ -225,16 +225,19 @@ def get_substrate_provider():
def revoke_auth(to_revoke):
def revoke_auth(to_revoke):
"""
"""
revoke_auth accepts a list of node IDs to revoke auth from
revoke_auth accepts a list of node IP addresses to revoke auth from
:param to_revoke: list of node IDs
:param to_revoke: list of node IP addresses
"""
"""
 
log.info(f"Revoking access to {len(to_revoke)} nodes...")
for nid in to_revoke:
for nid in to_revoke:
cmd = f"sudo nft -a list chain inet filter input | grep '{nid}' | awk -F'handle ' '{{print $2}}' | xargs -Ixxx sudo nft delete rule inet filter input handle xxx"
cmd = f"sudo nft -a list chain inet filter input | grep '{nid}' | awk -F'handle ' '{{print $2}}' | xargs -Ixxx sudo nft delete rule inet filter input handle xxx"
 
log.debug(cmd)
p = subprocess.Popen(cmd.split())
p = subprocess.Popen(cmd.split())
output, error = p.communicate()
output, error = p.communicate()
log.debug(output)
if output:
 
log.debug(output)
if error:
if error:
log.error(error)
raise IOError(error)
def id_to_reg_code(cmix_id):
def id_to_reg_code(cmix_id):
@@ -707,7 +710,7 @@ def set_authorizer_nodes(conn, to_add, to_delete):
@@ -707,7 +710,7 @@ def set_authorizer_nodes(conn, to_add, to_delete):
node_list = get_authorizer_nodes(conn)
node_list = get_authorizer_nodes(conn)
to_revoke = []
to_revoke = []
delete_command = "DELETE FROM nodes WHERE id = ?;"
delete_command = "DELETE FROM nodes WHERE id = %s;"
for row in node_list:
for row in node_list:
if row[0] in to_delete:
if row[0] in to_delete:
try:
try:
@@ -716,7 +719,8 @@ def set_authorizer_nodes(conn, to_add, to_delete):
@@ -716,7 +719,8 @@ def set_authorizer_nodes(conn, to_add, to_delete):
except Exception as e:
except Exception as e:
log.error(f"Failed to remove node from authorizer DB: {cur.query}")
log.error(f"Failed to remove node from authorizer DB: {cur.query}")
raise e
raise e
to_revoke.append(row[1])
if row[1]:
 
to_revoke.append(row[1])
insert_list = [(i, None, None) for i in to_add]
insert_list = [(i, None, None) for i in to_add]
# Insert Node information into authorizer db
# Insert Node information into authorizer db
Loading