Skip to content
Snippets Groups Projects

Save raw points data

Merged
Jonah Hussonrequested to merge
raw-points into master
1 open thread
1 file
+ 11
3
Compare changes
  • Side-by-side
  • Inline
+ 18
3
@@ -26,6 +26,7 @@ THOUSAND = 1_000
@@ -26,6 +26,7 @@ THOUSAND = 1_000
state_key = "consensus_points_timestamp" # Static key used for states table
state_key = "consensus_points_timestamp" # Static key used for states table
positive_points_func = 'submit_cmix_points'
positive_points_func = 'submit_cmix_points'
negative_points_func = 'submit_cmix_deductions'
negative_points_func = 'submit_cmix_deductions'
 
raw_points_log = ''
#################
#################
@@ -124,7 +125,7 @@ def process_period(conn, substrate, keypair, point_info, start_period, end_perio
@@ -124,7 +125,7 @@ def process_period(conn, substrate, keypair, point_info, start_period, end_perio
round_info, active_nodes = get_round_info_for_period(conn, start_period, end_period)
round_info, active_nodes = get_round_info_for_period(conn, start_period, end_period)
# Calculate points for the retrieved round information
# Calculate points for the retrieved round information
wallet_points = round_point_computation(point_info, round_info, active_nodes)
wallet_points, raw_points = round_point_computation(point_info, round_info, active_nodes)
# Define Lists
# Define Lists
positive = []
positive = []
@@ -143,6 +144,9 @@ def process_period(conn, substrate, keypair, point_info, start_period, end_perio
@@ -143,6 +144,9 @@ def process_period(conn, substrate, keypair, point_info, start_period, end_perio
if len(negative) > 0:
if len(negative) > 0:
push_point_info(substrate, negative_points_func, keypair, negative)
push_point_info(substrate, negative_points_func, keypair, negative)
 
with open(raw_points_log, "a") as f:
 
f.write(f"[{datetime.datetime.now()}] {raw_points}\n")
 
# Save end_period timestamp to database to lock in the operation
# Save end_period timestamp to database to lock in the operation
update_last_checked_timestamp(conn, end_period)
update_last_checked_timestamp(conn, end_period)
@@ -153,7 +157,7 @@ def round_point_computation(point_info, round_info, active_nodes):
@@ -153,7 +157,7 @@ def round_point_computation(point_info, round_info, active_nodes):
:param round_info:
:param round_info:
:param active_nodes:
:param active_nodes:
:param point_info: point_info dictionary polled from consensus
:param point_info: point_info dictionary polled from consensus
:return:
:return: wallet_points, raw_points dicts
"""
"""
bin_multipliers = point_info['multipliers']
bin_multipliers = point_info['multipliers']
success_points = point_info['success_points']
success_points = point_info['success_points']
@@ -161,6 +165,7 @@ def round_point_computation(point_info, round_info, active_nodes):
@@ -161,6 +165,7 @@ def round_point_computation(point_info, round_info, active_nodes):
country_bins = point_info['countries']
country_bins = point_info['countries']
wallet_points = {} # dictionary of wallet -> points to pass to push_point_info
wallet_points = {} # dictionary of wallet -> points to pass to push_point_info
 
raw_points_dict = {} # Dict of raw points (without multipliers) to print to a log file
node_multipliers = {} # Dictionary containing point multipliers for each node
node_multipliers = {} # Dictionary containing point multipliers for each node
node_wallets = {} # Dictionary parsed from active nodes to more efficiently associate ID with Wallet ID
node_wallets = {} # Dictionary parsed from active nodes to more efficiently associate ID with Wallet ID
@@ -173,6 +178,7 @@ def round_point_computation(point_info, round_info, active_nodes):
@@ -173,6 +178,7 @@ def round_point_computation(point_info, round_info, active_nodes):
node_multipliers[node_id] = bin_multipliers[node_bin] # Assign multiplier to node
node_multipliers[node_id] = bin_multipliers[node_bin] # Assign multiplier to node
node_wallets[node_id] = wallet_address # Add wallet association for node id
node_wallets[node_id] = wallet_address # Add wallet association for node id
wallet_points[wallet_address] = 0
wallet_points[wallet_address] = 0
 
raw_points_dict[wallet_address] = 0
# Calculate point information for each round
# Calculate point information for each round
for row in round_info:
for row in round_info:
@@ -184,6 +190,7 @@ def round_point_computation(point_info, round_info, active_nodes):
@@ -184,6 +190,7 @@ def round_point_computation(point_info, round_info, active_nodes):
topology = row[6]
topology = row[6]
points = 0
points = 0
 
raw_points = 0
if round_err:
if round_err:
# Determine negative points for failures
# Determine negative points for failures
round_id = row[0]
round_id = row[0]
@@ -192,6 +199,7 @@ def round_point_computation(point_info, round_info, active_nodes):
@@ -192,6 +199,7 @@ def round_point_computation(point_info, round_info, active_nodes):
else:
else:
log.debug(f"Round {round_id}: Realtime error")
log.debug(f"Round {round_id}: Realtime error")
points = fail_points
points = fail_points
 
raw_points = fail_points
else:
else:
# Handle point multipliers
# Handle point multipliers
# NOTE: Weirdness can result here from nodes going offline between eras. Should be reviewed.
# NOTE: Weirdness can result here from nodes going offline between eras. Should be reviewed.
@@ -199,6 +207,7 @@ def round_point_computation(point_info, round_info, active_nodes):
@@ -199,6 +207,7 @@ def round_point_computation(point_info, round_info, active_nodes):
if node_multipliers.get(bytes(node_id))]
if node_multipliers.get(bytes(node_id))]
multiplier = max(multipliers)
multiplier = max(multipliers)
points = success_points * multiplier
points = success_points * multiplier
 
raw_points = success_points
# Assign points to wallets
# Assign points to wallets
for node_id in topology:
for node_id in topology:
@@ -206,9 +215,10 @@ def round_point_computation(point_info, round_info, active_nodes):
@@ -206,9 +215,10 @@ def round_point_computation(point_info, round_info, active_nodes):
wallet = node_wallets.get(bytes(node_id))
wallet = node_wallets.get(bytes(node_id))
if wallet:
if wallet:
wallet_points[wallet] += points
wallet_points[wallet] += points
 
raw_points_dict[wallet] += raw_points
log.debug(f"Wallet points: {wallet_points}")
log.debug(f"Wallet points: {wallet_points}")
return wallet_points
return wallet_points, raw_points_dict
#######################
#######################
@@ -387,12 +397,16 @@ def get_args():
@@ -387,12 +397,16 @@ def get_args():
get_args controls the argparse usage for the script. It sets up and parses
get_args controls the argparse usage for the script. It sets up and parses
arguments and returns them in dict format
arguments and returns them in dict format
"""
"""
 
global raw_points_log
parser = argparse.ArgumentParser(description="Options for point assignment script")
parser = argparse.ArgumentParser(description="Options for point assignment script")
parser.add_argument("--verbose", action="store_true",
parser.add_argument("--verbose", action="store_true",
help="Print debug logs", default=False)
help="Print debug logs", default=False)
parser.add_argument("--log", type=str,
parser.add_argument("--log", type=str,
help="Path to output log information",
help="Path to output log information",
default="/tmp/points.log")
default="/tmp/points.log")
 
parser.add_argument("--raw-points-log", type=str,
 
help="Path to output log information",
 
default="/cmix/raw-points.log")
parser.add_argument("--xxdot-url", type=str, help="xxdot url",
parser.add_argument("--xxdot-url", type=str, help="xxdot url",
default="ws://localhost:9944")
default="ws://localhost:9944")
parser.add_argument("--xxdot-reg", type=str, help="xxdot registry file path",
parser.add_argument("--xxdot-reg", type=str, help="xxdot registry file path",
@@ -420,6 +434,7 @@ def get_args():
@@ -420,6 +434,7 @@ def get_args():
level=log.DEBUG if args['verbose'] else log.INFO,
level=log.DEBUG if args['verbose'] else log.INFO,
datefmt='%d-%b-%y %H:%M:%S',
datefmt='%d-%b-%y %H:%M:%S',
filename=args["log"])
filename=args["log"])
 
raw_points_log = args['raw_points_log']
return args
return args
Loading