This repository contains the PoktInfo services that depend on Pocket's chain data. Rewards info ingests the proofs and claims in order to index every time a node earns by documenting reward and relay amounts. Nodes Info indexes the network's nodes information over time. Location info indexes where the nodes in nodes info are geographically located and other related information such as ISP and IP.
- Follow the Installation steps of common, a requisite for PoktInfo which contains the ORM, generic interactions, and more.
- Clone this repository
- Follow the steps for the desired service below
To run this service and gather historical data:
python run_rewards.py history <START_HEIGHT> <END_HEIGHT>
To run this service "live" and collect current and future data:
python run_rewards.py live
run_rewards.py
is the main file which invokes the logic in rewards_calc.py
.
run_rewards.py
invokesrun_rewards()
which uses process pools to callrecord_rewards()
for each block within the specified range- Calls
get_relays_wrapper()
which queries all the claims on the state atheight - 1
and passes them toget_relays()
which matches the proofs fromheight
to the claims and multiplies them by the correctrelaysToTokensMultiplier
andvalidatorPercentage
- Perform sanity check to ensure that
(totalSupply(height) - totalSupply(height - 1)) * validatorPercentage == totalRewards(height)
- Saves reward information in db
- Calls
Performs the same process as historical mode, but calls record_rewards
starting at the last cached block sequentially. If the last cached block is equal to the current height, the process will sleep until the current height increments. We separate historical
and live
processes because historical
allows for indexing multiple blocks at once which is beneficial given Pocket's long query times.
Please see here for the rewards info schema definition.
To run this service in historical mode:
python run_rewards.py history <START_HEIGHT> <END_HEIGHT>
To run this service in live mode:
python run_rewards.py live
run_nodes.py
is the main file which invokes the logic in nodes_info.py
.
run_nodes_info(from_height: int, to_height: int)
is called and sequentially callsrecord_nodes_info_wrapper
for each block- The calls are made in series because the state of
height - 1
is required to manage changes to a node atheight
- The calls are made in series because the state of
- Queries all nodes at
height
and iterates through each node to check for changes to the nodesservice_url
,chains
orunstaking_time
. - If there is a change, the
end_height
of the node in the table will be marked toheight - 1
, and it will create a new row withstart_height = height
Live mode starts from the last indexed height and will call record_nodes_info_wrapper
until the indexed height is equal to the current height. It will sleep until the current height increments.
Please see here for the nodes info schema definition.
To run location info:
python3 location_service.py <RAN_FROM>
ran_from
specifies the region where the instance of location info is running from. Because of modifications like geomesh, where operators are able to have multiple clients per address
by using a regional load balancing service, one must run location info in several regions in order to detect all the actual instances of a given servicer/validator. Based on where this service is ran, you will get different results. (e.g. If you run from the U.S, you will find U.S versions of the network's nodes rather than an exhaustive list) Options: na, eu, sg
Logic and main is in location_service.py
.
Be sure that you update the ip-api key in common repo ip_api_utils.py
.
- Every 6 hours
run_location_service()
is called- Active nodes are queried from nodes_info
- For each node, location data is queried from ip-api using the node's
service_url
- If
address
,city
,ip
orisp
differ for the recorded node, than the old one'send_height
will be specified and a new row will be created. Theran_from
column will be set to the value specified in the CLI argument.
Because you cannot find out where something was physically located in the past, location info only has a live mode.
Please see here for the nodes info schema definition.