Giter Club home page Giter Club logo

validator-alertbot's Introduction

validator-alertbot

Validator alertbot for cosmos ecosystem

  • Validator alert bot is a custom alerting module has been developed to alert on key validator health events. The module uses data from influxdb and trigger alerts based on user-configured thresholds. It also provides telegram based commands to know information about your validator activity.

Install Prerequisites

  • Go 13.x+
  • InfluxDB 1.7+
  • Docker 19+

Here we are provinding steps to install influxdb, we assume you already have go and docker installed.

Install InfluxDB

 cd $HOME
wget -q https://repos.influxdata.com/influxdata-archive_compat.key
echo '393e8779c89ac8d958f81f942f9ad7fb82a25e133faddaf92e15b16e6ac9ce4c influxdata-archive_compat.key' | sha256sum -c && cat influxdata-archive_compat.key | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/influxdata-archive_compat.gpg > /dev/null
echo 'deb [signed-by=/etc/apt/trusted.gpg.d/influxdata-archive_compat.gpg] https://repos.influxdata.com/debian stable main' | sudo tee /etc/apt/sources.list.d/influxdata.list

Start influxDB

 sudo apt-get update && sudo apt-get install influxdb
 sudo service influxdb start

The default port that runs the InfluxDB HTTP service is :8086

Note : If you want cusomize the configuration, edit influxdb.conf at /etc/influxdb/influxdb.conf and don't forget to restart the server after the changes. You can find a sample 'influxdb.conf' file here.

Getting Started (Download and run the alert bot)

git clone https://github.com/vitwit/validator-alertbot.git
cd validator-alertbot
cp example.config.toml config.toml

Configure the following variables in config.toml

  • tg_chat_id

    • Telegram chat ID to receive Telegram alerts, required for Telegram alerting.
  • tg_bot_token

    • Telegram bot token, required for Telegram alerting. The bot should be added to the chat and should have send message permission.
  • sendgrid_token

    • If you want to get email notifications, then configure your sendgrid_token
  • email_address

    • Configure your email address to which you wish to get the email notifications.
  • alert_time1 and alert_time2

    • These are for regular status updates. To receive validator status daily (twice), configure these parameters in the form of "02:25PM". The time here refers to UTC time.
  • val_operator_addr

    • Operator address of your validator which will be used to get staking, delegation and distribution rewards.
  • validator_hex_addr

    • Validator hex address useful to know about last proposed block, missed blocks and voting power.
  • lcd_endpoint

  • external_rpc

    • External open RPC endpoint(secondary RPC other than your own validator). Useful to gather information like validator caught up, syncing and missed blocks etc.
  • validator_rpc_endpoint

    • Validator rpc end point (RPC of your own validator) useful to gather information about network info, validator voting power etc.
  • balance_change_alert

    • If you want to receive alerts when your account balance changes then configure balance_change_alert to "yes" otherwise "no".
  • block_diff_alert

    • If you want to receive block difference alert configure this enable_alert to "yes" otherwise "no".

    • Configure block_diff_threshold An integer value to receive Block difference alerts, e.g. a value of 2 would alert you if your validator falls 2 or more blocks behind the chain's current block height.

  • voting_power_alert

    • If you want to receive block difference alert configure this enable_alert to "yes" otherwise "no".

    • Configure voting_power_threshold to receive alert when the voting power reaches or drops below of the threshold given.

  • Peers_alert

    • If you want to receive block difference alert configure this enable_alert to "yes" otherwise "no".

    • Configure num_peers_threshold to get an alert if the no.of connected peers falls below the threshold.

  • influxdb

    • Configure port, username and database. Make sure not to forget creating a database and configure it before you run the code.

After populating config.toml, check if you have connected to influxdb and created a database which you are going to use.

If your connection throws error "database not found", create a database

$   cd $HOME
$   influx
>   CREATE DATABASE db_name

ex: CREATE DATABASE akash_alertbot

Add a retention policy for the db

$ use db_name
$ CREATE RETENTION POLICY "seven_days_only" ON db_name DURATION 7d REPLICATION 1 DEFAULT;
$ show retention policies

Note : Before running the code make sure that you have configured all the required details otherwise the code may give fatal errors.

  • Build and run the alerting bot using binary
$ go build -o validator-alert-bot && ./validator-alert-bot
  • Run using docker
$ docker build -t alertbot .
$ docker run -d --name validator-alertbot alertbot

Here is the list of available alerts and telegram commands

  • Alert about validator node sync status.
  • Alert when a validator miss a block
  • Alert when there is a change in account balance.
  • Alert when no.of peers count falls below of num_peers_threshold which is user configured in config.toml
  • Alert when the block difference between network and validator reaches or exceeds the block_diff_threshold which is user configured in config.toml.
  • Alert about validator health, i.e. whether it's voting or jailed. You can get alerts twice a day based on the time you have configured alert_time1 and alert_time2 in config.toml. This is a useful sanity check, to confirm the validator is voting (or alerting you if it's jailed).
  • Alert when the voting power of your validator drops below voting_power_threshold which is user configured in config.toml

List of avaliable telegram commands

To get response from these commands you can just /command_name* from your autorized telegram account. You will be getting response to your telegram account based on the tg_bot_token you have configured in config.toml

  • /status : Gives validator's status,current block height, voting power and network current block height.
  • /node : Gives status of caught-up
  • /peers : Returns number of connected peers
  • /balance : Returns the current balance of your account
  • /list : List of available commands

Feedback and Questions

Please feel free to create issues in this repo to ask questions and/or suggest additional metrics, alerts or features.

validator-alertbot's People

Contributors

prathyushalakkireddy avatar kaustubhkapatral avatar nagatulasi avatar anilcse avatar

Stargazers

Lyeoeon avatar Chris avatar  avatar  avatar

Watchers

bhargavdath avatar Sai Kumar avatar

Forkers

ritvik32

validator-alertbot's Issues

Refactor tracking issue

Current implementation of alertbot has been rendered inefficient due to a number of changes in the Cosmos SDK. The queries made on both the RPC and LCD endpoints are quite resource intensive and cause a lot of load on the server which affects the node's performance. The following list are a few changes which need to be implemented to improve the alertbot

Missed blocks :-

In the current implementation of missed blocks calculation, every block is queried using the LCD endpoint. If validator's hex address (which is defined in the config.toml file) is not present in the the precommits array in the repsonse then the block is marked as missed and inserted in the db. If the number of continuous missed blocks exceeds the missed blocks threshold (which is defined in the config.toml file) then an alert is fired to the user. Querying each and every block puts a lot of load on the node and in the latest release of cosmos sdk /blocks LCD endpoints has been discontinued. This leads to every block being marked as missed and sends an alert to the user.

Instead of relying on the approach of querying each block we should switch to relying on slashing info endpoint. LCD.endpoint/cosmos/slashing/v1beta1/signing_infos/<cons-address>.

{
  "val_signing_info": {
    "address": "cosmosvalcons1d65x8dzt5d5lww0x2k2hwrdtjtyf4ysjdyv245",
    "start_height": "5915501",
    "index_offset": "9487453",
    "jailed_until": "1970-01-01T00:00:00Z",
    "tombstoned": false,
    "missed_blocks_counter": "4"
  }
}

This is a sample response of the endpoint. missed_blocks_counter in the response is the number of blocks a validator has missed in the min_signed_blocks window. Counter increases by +1 whenever a validator misses a block. We should rely on this for alerting the user on missed blocks of their validator. The scrape rate for this job should be in every 15 mins instead of every 3s (which is defined in the config.toml file). In addition to this we should add a sanity check on the index_offset field. The value of index_offset should increase between the scrapes.

Tx alerts:-

In the current implementation of delegation/redelegation/undelegation alerts. each and every block is queried and all the txs present in the blocks are indexed to check if the validator or account address is present in any of the txs. Just like the missed block alerting, querying every block and indexing the txs puts a lot of load on the node. This implementation should be replaced with an approach that relies on tx events. Subscribing to delegation/redelegation/undelegation events and balance change events for account address would drop the load considerably.

Proposal alerts:-

This implementation of proposal alerts can be removed entirely as an another bot has been developed which send out alerts for new proposals.

Query commands:-

Alertbot has telegram commands integrated which when typed gives the user info about various things like /status, /peers, /node, /balance, /rewards, /rpc_status, /endpoints. Value for these responses is continuously queried on chain and stored in the db even if those commands are not being executed. Approach for that should be changed and those specific endpoints should only be queried if the user request it.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.