Validator Rewards Tracker

The Validator Rewards Tracker is designed to track pool rewards and operator commissions from a blockchain. It fetches data from an RPC endpoint, processes it caches the results in JSON files periodically. The application also provides an HTTP API for querying current pool rewards and operator commission.

Installation and setup

Clone the repository and navigate to the project directory:

git clone https://github.com/Entropy-Foundation/supra-toolbox.git
cd trackers/rewards_tracker

Build the project:

cargo build --release

Prerequisite

Before running this code we need to have three json file available at root of this project folder as per given in example below:

  1. pool_details.json (list of pool with their operator and commission details)
{
  "block_height": 0,
  "data": {
    "0xabc": {
      "operator_address": "0x123",
      "commission_info": {
        "current_commission_percentage": 10,
        "next_commission_percentage": null,
        "next_commission_effective_time": null
      }
    },
    "0xdef": {
      "operator_address": "0x456",
      "commission_info": {
        "current_commission_percentage": 10,
        "next_commission_percentage": null,
        "next_commission_effective_time": null
      }
    },
    "0xghi": {
      "operator_address": "0x789",
      "commission_info": {
        "current_commission_percentage": 10,
        "next_commission_percentage": null,
        "next_commission_effective_time": null
      }
    }
  }
}
  1. legacy_commission_percentage_data.json ( pool address and thir history of commission change with their epoch_id and commission percentage)
{
    "0xabc": {
        "0": 10,
        "1": 10,
        "5": 12,
        "8": 9
    },
    "0xdef": {
        "0": 10,
        "3": 15,
        "6": 20
    },
    "0xghi": {
        "0": 10,
        "2": 14,
        "4": 17,
        "7": 8
    }
}
  1. config.json (to set up all the configuration)
{
    "rpc_base_url" : "http://localhost:27000/rpc",
    "epoch_interval" : 60,
    "file_update_interval" : 30,
    "serving_endpoint" : 3030,
    "legacy_commission_percentage_file_path" : "your_file_path_to/legacy_commission_percentage_data.json",
    "pool_details_file_path" : "your_file_path_to/pool_details.json"
}

Usage

Run the application with the following command options:

  1. To run application with sync flag which enables synchronization mode which fetches all historical rewards before running regular service.
cargo run --release -- <path_of_config_file> --sync
  1. To start application with normal process from the particular block height. It will not sync previous blocks.
cargo run --release -- <path_of_config_file> <block height> 

HTTP API Endpoints

The application starts an HTTP server to provide an interface for querying reward data. The default port is 8080.

EndpointMethodDescription
/pool_rewardsGETRetrieves pool rewards data.
/operator_commissionsGETRetrieves operator commission data.

Example API request:

curl http://machine_ip:3030/pool_rewards

Logging Mechanism

The application uses env_logger for logging various stages of execution, including data fetching, processing, and errors.

Log Levels

  • ERROR - Logs failures during execution.
  • INFO - Logs key status updates.
  • DEBUG - Logs detailed data processing information.

Enabling Logging

To enable info logs, set the RUST_LOG environment variable before running the application:

RUST_LOG=info cargo run --release -- <path_of_config_file> --sync

This helps in monitoring and debugging the service effectively.