The Beacon Chain Indexer calculates the participation rate of the entire network based on the last five epochs. It utilizes a Rust and PostgreSQL database for data storage and retrieval.
To run the Beacon Chain Indexer, make sure you have the following software installed:
- Rust (version 1.72.0-nightly or later)
- PostgreSQL (version 15.3 or later)
Please ensure that Rust and Cargo are properly set up on your system, and install PostgreSQL according to the instructions provided for your operating system.
-
Create a new PostgreSQL database for the Beacon Chain Indexer.
-
Connect to the PostgreSQL database using your preferred method (e.g., psql command-line tool, GUI client).
-
Run the following SQL query to create the necessary table in the database:
CREATE TABLE IF NOT EXISTS slots (
id BIGINT PRIMARY KEY,
slot_number BIGINT NOT NULL,
validator_set_size BIGINT NOT NULL,
epoch BIGINT NOT NULL,
missed_attestation BIGINT NOT NULL,
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);
This query creates a table named slots
with columns for id
, slot_number
, validator_set_size
, epoch
, missed_attestation
, and created_at
.
-
Clone this repository to your local machine.
-
Navigate to the project directory.
-
Update the database configuration in the
main.rs
file. Open themain.rs
file and locate thePostgresDatabase::new
function call. Modify the function arguments with your database connection details (host, port, user, password, dbname). -
Build and run the project using Cargo.
-
The Beacon Chain Indexer will start processing slots. You can access the calculated participation rate by making a GET request to the
/network/participation_rate
endpoint. (curl http://127.0.0.1:8000/network/participation_rate )
The project follows the following directory structure:
api/
: Contains the API-related code and handlers.database/
: Contains the code for interacting with the PostgreSQL database.indexer/
: Contains the code for processing slots and calculating the participation rate.models/
: Contains the data models used in the project.- main/ : Contains the code for running HttpServer and processing slot scheduler
The Beacon Chain Indexer project relies on the following external dependencies:
actix-web
: A powerful web framework for building APIs with Rust.tokio-postgres
: A PostgreSQL client library for asynchronous Rust.serde
: A library for serializing and deserializing Rust data structures.reqwest
: A simple HTTP client for making API requests.
For a complete list of dependencies and their versions, refer to the Cargo.toml
file.
The Beacon Chain Indexer project provides functionality for calculating the participation rate of the entire network based on the last five epochs. However, there are several potential areas for future enhancement and additional functionality, It can be extend to calculate the Individual Validator Participation Rate.
Contributions to the Beacon Chain Indexer are welcome! If you find any issues or have suggestions for improvements.