Skip to content
Snippets Groups Projects

Save raw points data

Merged
Jonah Hussonrequested to merge
raw-points into master
1 open thread
+ 18
3
@@ -26,6 +26,7 @@ THOUSAND = 1_000
state_key = "consensus_points_timestamp" # Static key used for states table
positive_points_func = 'submit_cmix_points'
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
round_info, active_nodes = get_round_info_for_period(conn, start_period, end_period)
# 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
positive = []
@@ -143,6 +144,9 @@ def process_period(conn, substrate, keypair, point_info, start_period, end_perio
if len(negative) > 0:
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
update_last_checked_timestamp(conn, end_period)
@@ -153,7 +157,7 @@ def round_point_computation(point_info, round_info, active_nodes):
:param round_info:
:param active_nodes:
:param point_info: point_info dictionary polled from consensus
:return:
:return: wallet_points, raw_points dicts
"""
bin_multipliers = point_info['multipliers']
success_points = point_info['success_points']
@@ -161,6 +165,7 @@ def round_point_computation(point_info, round_info, active_nodes):
country_bins = point_info['countries']
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_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):
node_multipliers[node_id] = bin_multipliers[node_bin] # Assign multiplier to node
node_wallets[node_id] = wallet_address # Add wallet association for node id
wallet_points[wallet_address] = 0
raw_points_dict[wallet_address] = 0
# Calculate point information for each round
for row in round_info:
@@ -184,6 +190,7 @@ def round_point_computation(point_info, round_info, active_nodes):
topology = row[6]
points = 0
raw_points = 0
if round_err:
# Determine negative points for failures
round_id = row[0]
@@ -192,6 +199,7 @@ def round_point_computation(point_info, round_info, active_nodes):
else:
log.debug(f"Round {round_id}: Realtime error")
points = fail_points
raw_points = fail_points
else:
# Handle point multipliers
# 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):
if node_multipliers.get(bytes(node_id))]
multiplier = max(multipliers)
points = success_points * multiplier
raw_points = success_points
# Assign points to wallets
for node_id in topology:
@@ -206,9 +215,10 @@ def round_point_computation(point_info, round_info, active_nodes):
wallet = node_wallets.get(bytes(node_id))
if wallet:
wallet_points[wallet] += points
raw_points_dict[wallet] += raw_points
log.debug(f"Wallet points: {wallet_points}")
return wallet_points
return wallet_points, raw_points_dict
#######################
@@ -387,12 +397,16 @@ def get_args():
get_args controls the argparse usage for the script. It sets up and parses
arguments and returns them in dict format
"""
global raw_points_log
parser = argparse.ArgumentParser(description="Options for point assignment script")
parser.add_argument("--verbose", action="store_true",
help="Print debug logs", default=False)
parser.add_argument("--log", type=str,
help="Path to output log information",
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",
default="ws://localhost:9944")
parser.add_argument("--xxdot-reg", type=str, help="xxdot registry file path",
@@ -420,6 +434,7 @@ def get_args():
level=log.DEBUG if args['verbose'] else log.INFO,
datefmt='%d-%b-%y %H:%M:%S',
filename=args["log"])
raw_points_log = args['raw_points_log']
return args
Loading