Skip to content

Commit

Permalink
feat: use config from toml, refactor. Fixed #8, #9 (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
freak12techno authored Jun 1, 2022
1 parent a5fae60 commit 06bff3f
Show file tree
Hide file tree
Showing 15 changed files with 1,030 additions and 778 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
main

config.toml
dist/
39 changes: 39 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
linters-settings:
gocritic:
disabled-checks:
- ifElseChain
gosec:
excludes:
- G402
- G404
revive:
rules:
- name: var-declaration
disabled: true

linters:
enable-all: true
disable:
- funlen
- scopelint
- interfacer
- exhaustivestruct
- maligned
- golint
- nlreturn
- wrapcheck
- gomnd
- cyclop
- goerr113
- exhaustruct
- wsl
- lll
- dupl
- varnamelen
- gomoddirectives
# - prealloc
# - unparam
# - nestif
# - errcheck
# - noctx
# - gocognit
55 changes: 16 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,18 @@ Download the latest release from [the releases page](https://github.com/solarlab

```sh
wget <the link from the releases page>
tar xvfz missed-blocks-checker_*
tar <downloaded file>
./missed-blocks-checker --telegram-token <bot token> --telegram-chat <user or chat ID from the previous step>
```

That's not really interesting, what you probably want to do is to have it running in the background. For that, first of all, we have to copy the file to the system apps folder:
Alternatively, install `golang` (>1.18), clone the repo and build it. This will generate a `./main` binary file in the repository folder:
```
git clone https://github.com/solarlabsteam/missed-blocks-checker
cd missed-blocks-checker
go build
```

What you probably want to do is to have it running in the background. For that, first of all, we have to copy the file to the system apps folder:

```sh
sudo cp ./missed-blocks-checker /usr/bin
Expand All @@ -39,7 +46,7 @@ User=<username>
TimeoutStartSec=0
CPUWeight=95
IOWeight=95
ExecStart=missed-blocks-checker --telegram-token <bot token> --telegram-chat <user or chat ID>
ExecStart=missed-blocks-checker --config <config path>
Restart=always
RestartSec=2
LimitNOFILE=800000
Expand All @@ -52,9 +59,9 @@ WantedBy=multi-user.target
Then we'll add this service to the autostart and run it:

```sh
sudo systemctl daemon-reload
sudo systemctl enable missed-blocks-checker
sudo systemctl start missed-blocks-checker
sudo systemctl daemon-reload # reload config to reflect changed
sudo systemctl enable missed-blocks-checker # put service to autostart
sudo systemctl start missed-blocks-checker # start the service
sudo systemctl status missed-blocks-checker # validate it's running
```

Expand All @@ -70,37 +77,7 @@ It periodically queries the full node via gRPC for all validators and their miss

## How can I configure it?

You can pass the artuments to the executable file to configure it. Here is the parameters list:

- `--bech-prefix` - the global prefix for addresses. Defaults to `persistence`
- `--node` - the gRPC node URL. Defaults to `localhost:9090`
- `--log-devel` - logger level. Defaults to `info`. You can set it to `debug` to make it more verbose.
- `--limit` - pagination limit for gRPC requests. Defaults to 1000.
- `--telegram-token` - Telegram bot token
- `--telegram-chat` - Telegram user or chat ID
- `--mintscan-prefix` - This bot generates links to Mintscan for validators, using this prefix. Links have the following format: `https://mintscan.io/<mintscan-prefix>/validator/<validator ID>`. Defaults to `persistence`.
- `--interval` - Interval between the two checks, in seconds. Defaults to 120
- `--include` - a comma-separated list of validators' operators addresses. If specified, only the validators from this list would be monitored.
- `--exclude` - a comma-separated list of validators' operators addresses. If specified, all validators except the ones from this list would be monitored.

(Note that you cannot use `--include` and `--exclude` at the same time.)


You can also specify custom Bech32 prefixes for wallets, validators, consensus nodes, and their pubkeys by using the following params:
- `--bech-validator-prefix`
- `--bech-validator-pubkey-prefix`
- `--bech-consensus-node-prefix`
- `--bech-consensus-node-pubkey-prefix`

By default, if not specified, it defaults to the next values (as it works this way for the most of the networks):
- `--bech-validator-prefix` = `--bech-prefix` + "valoper"
- `--bech-validator-pubkey-prefix` = `--bech-prefix` + "valoperpub"
- `--bech-consensus-node-prefix` = `--bech-prefix` + "valcons"
- `--bech-consensus-node-pubkey-prefix` = `--bech-prefix` + "valconspub"

An example of the network where you have to specify all the prefixes manually is Iris.

Additionally, you can pass a `--config` flag with a path to your config file (I use .toml, but anything supported by [viper](https://github.com/spf13/viper) should work).
All configuration is done via `.toml` config file, which is mandatory. Run the app with `--config <path/to/config.toml>` to specify config. Check out `config.example.toml` to see the params that can be set.

## Notifications channels

Expand All @@ -112,13 +89,13 @@ Go to @BotFather in Telegram and create a bot. After that, there are two options
- you want to send messages to a channel. Write something to a channel, then forward it to @getmyid_bot and copy the `Forwarded from chat` number. Then add the bot as an admin.


Then run a program with `--telegram-token <token> --telegram-chat <chat ID>`.
Then add a Telegram config to your config file (see `config.example.toml` for reference).

2) Slack

Go to the Slack web interface -> Manage apps and create a new app.
Give the app the `chat:write` scope and add the integration to a channel by typing `/invite <bot username>` there.
After that, run the program with `--slack-token <token> --slack-chat <channel name>`.
After that add a Slack config to your config file (see `config.example.toml` for reference).


## Which networks this is guaranteed to work?
Expand Down
95 changes: 95 additions & 0 deletions config.example.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# Bech prefixes for network.
bech-prefix = "cosmos"
# If a network has specific bech prefixes for validator and for consensus node
# and their pubkeys, it's possible to specify them separately.
bech-validator-prefix = "cosmosvaloper"
bech-validator-pubkey-prefix = "cosmosvaloperpub"
bech-consensus-node-prefix = "cosmosvalcons"
bech-consensus-node-pubkey-prefix = "cosmosvalconspub"
# Scrape interval, in seconds. Defaults to 120
interval = 120
# List of validators to monitor, with it specified, only the selected validators
# will be monitored. Cannot be used together with exclude-validators.
# If both include-validators and exclude-validators are not specified,
# all validators will be monitored.
include-validators = ["cosmosvaloperxxx"]
# List of validators to exclude from monitoring, with it specified, all validators except mentioned
# will be monitored. Cannot be used together with include-validators.
exclude-validators = ["cosmosvaloperyyy"]

# Node config.
[node]
# gRPC node address to get signing info and validators info from, defaults to localhost:9090
grpc-address = "localhost:9090"
# Tendermint RPC node to get block info from. Defaults to http://localhost:26657.
rpc-address = "http://localhost:26657"

# Logging config.
[log]
# Log level. Defaults to 'info', you can set it to 'debug' or even 'trace'
# to make it more verbose.
level = "info"
# Log all output in JSON except for fatal errors, useful if you are using
# logging aggregation solutions such as ELK stack.
json = true

# Chain info config.
[chain-info]
# Mintscan prefix, to generate links to validator.
mintscan-prefix = "cosmos"

# List of missed blocks groups.
[[missed-blocks-groups]]
# Start value of missed blocks. If a validator's missed blocks counter is between this
# and end value, it will fall under this group.
start = 0
# End value of missed blocks
end = 999
# Emoji displayed when a validator enters this group.
emoji-start = "🟡"
# Emoji displayed when a validator leaves this group.
emoji-end = "🟢"
# Description displayed when a validator enters this group.
desc-start = "is skipping blocks (0-10%)"
# Description displayed when a validator leaves this group.
desc-end = "is recovered (<10%)"

[[missed-blocks-groups]]
start = 1000
end = 4999
emoji-start = "🟠"
emoji-end = "🟡"
desc-start = "is skipping blocks (>10%)"
desc-end = "is recovering (<50%)"

[[missed-blocks-groups]]
start = 5000
end = 8999
emoji-start = "🔴"
emoji-end = "🟠"
desc-start = "is skipping blocks (>50%)"
desc-end = "is recovering (<90%)"

[[missed-blocks-groups]]
start = 9000
end = 10000
emoji-start = "🔴"
emoji-end = "🟠"
desc-start = "is skipping blocks (>90%)"
desc-end = "is recovering (90-100%)"

# Telegram reporter. All fields are mandatory, otherwise the reporter won't be enabled.
[telegram]
# A Telegram bot token.
token = "111:222"
# A Telegram chat to send messages to.
chat = -123
# Path to a file storing all information about people's links to validators.
config-path = "/home/user/config/missed-blocks-checker-telegram-labels.toml"

# Slack reporter. All fields are mandatory, otherwise the reporter won't be enabled.
[slack]
# A Slack bot token.
token = "xorb-xxxyyyy"
# A Slack channel or username to send messages to.
chat = "#general"
Loading

0 comments on commit 06bff3f

Please sign in to comment.