Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for slashing parameters and missed blocks per signing window #85

Merged
merged 4 commits into from
Nov 15, 2024

Conversation

qwertzlbert
Copy link
Contributor

@qwertzlbert qwertzlbert commented Nov 6, 2024

This pull request introduces a new set of features for exporting network slashing parameters to Prometheus, along with additional metrics to monitor validator performance and slashing conditions.

Key Changes
Prometheus Metrics for Slashing Parameters:

Exports key network slashing parameters, such as the Signing Window size and Slashing Penalties to Prometheus.
Validator “Missed Blocks per Signing Window” Tracking:

Adds the ability to query the current count of "Missed Blocks per Signing Window" for each validator. This metric aligns with the network’s threshold for determining whether a validator should be jailed.
Optional Slashing Metrics Collection:

Users can disable the collection of slashing-related metrics by using the --no-slashing argument.
Consensus Address Matching for Validator Metrics:

The validator's public key (PubKey) and the network's detected human-readable prefix are used to derive the consensus address. This enables proper mapping of metrics returned from the SigningInfo module, which provides metrics in the Bech32 Consensus Address format.

Testing and Validation
This change has been tested across several networks, ensuring compatibility and accurate metric collection:

Networks Tested:

  • Axelar
  • Cosmos
  • Band
  • Osmosis
  • Injective
  • Zeta
  • Agoric

Additionally a unit tests have been added and updated.

Additional Notes

These additions will enhance monitoring and alerting capabilities for validator operators by providing real-time insights into slashing parameters and validator performance. This feature set will improve operational awareness, helping operators avoid slashing events.


New prometheus metrics added:

.
.
.
# HELP cosmos_validator_watcher_signed_blocks_window Number of blocks per signing window
# TYPE cosmos_validator_watcher_signed_blocks_window gauge
cosmos_validator_watcher_signed_blocks_window{chain_id="cosmoshub-4"} 10000
# HELP cosmos_validator_watcher_min_signed_blocks_per_window Minimum number of blocks required to be signed per signing window
# TYPE cosmos_validator_watcher_min_signed_blocks_per_window gauge
cosmos_validator_watcher_min_signed_blocks_per_window{chain_id="cosmoshub-4"} 0.05
# HELP cosmos_validator_watcher_min_signed_blocks_per_window Minimum number of blocks required to be signed per signing window
# HELP cosmos_validator_watcher_downtime_jail_duration Duration of the jail period for a validator in seconds
# TYPE cosmos_validator_watcher_downtime_jail_duration gauge
cosmos_validator_watcher_downtime_jail_duration{chain_id="cosmoshub-4"} 600
# TYPE cosmos_validator_watcher_min_signed_blocks_per_window gauge
cosmos_validator_watcher_min_signed_blocks_per_window{chain_id="cosmoshub-4"} 0.05
# HELP cosmos_validator_watcher_slash_fraction_double_sign Slash penaltiy for double-signing
# TYPE cosmos_validator_watcher_slash_fraction_double_sign gauge
cosmos_validator_watcher_slash_fraction_double_sign{chain_id="cosmoshub-4"} 0.05
# HELP cosmos_validator_watcher_slash_fraction_downtime Slash penaltiy for downtime
# TYPE cosmos_validator_watcher_slash_fraction_downtime gauge
cosmos_validator_watcher_slash_fraction_downtime{chain_id="cosmoshub-4"} 0.0001
.
.
.

Example Log for cosmoshub-4

12:30AM INF connected to https://cosmos-rpc.publicnode.com:443 chainID=cosmoshub-4 height=22945025
12:30AM INF connected to https://cosmos-rpc.polkachu.com:443 chainID=cosmoshub-4 height=22945026
12:30AM INF tracking validator D9F8A41B782AA6A66ADC81F953923C7DCE7B6001 alias=figment moniker=Figment
12:30AM INF starting HTTP server on :8080
12:30AM INF Updating slashing metrics for chain cosmoshub-4 Downtime jail duration:=10m0s Min signed per window:=0.050000000000000000 Signed blocks window:=10000 Slash fraction double sign:=0.050000000000000000 Slash fraction downtime:=0.000100000000000000 Slashing parameters for chain:=cosmoshub-4
12:30AM INF Tracked validator missed blocks: 20
12:30AM INF fetched staking validators and signing infos
#22945025 180/180 validators ✅ figment
#22945026 180/180 validators ✅ figment
#22945027 180/180 validators ✅ figment
#22945028 180/180 validators ✅ figment
#22945029 180/180 validators ✅ figment
#22945030 180/180 validators ✅ figment

Please let me know if I should add some additional code changes.

* Signed-off-by: Simon Lichtenauer <[email protected]>

* Add slashing watcher (#1)
Signed-off-by: Simon Lichtenauer <[email protected]>
@MattKetmo
Copy link
Member

Hello @qwertzlbert thanks for your contribution. I will have a look next week :)

pkg/crypto/utils.go Outdated Show resolved Hide resolved
Comment on lines 20 to 23
min_signed_per_window float64
downtime_jail_duration float64
slash_fraction_double_sign float64
slash_fraction_downtime float64
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use camelCase everywhere

pkg/watcher/slashing.go Outdated Show resolved Hide resolved
pkg/watcher/slashing.go Outdated Show resolved Hide resolved
pkg/watcher/validators.go Outdated Show resolved Hide resolved
pkg/watcher/validators.go Show resolved Hide resolved
pkg/watcher/validators.go Outdated Show resolved Hide resolved
pkg/watcher/validators.go Outdated Show resolved Hide resolved
@qwertzlbert
Copy link
Contributor Author

@MattKetmo thanks for your quick and extensive review! I'll add the suggested changes as soon as possible.

qwertzlbert and others added 3 commits November 12, 2024 21:16
remove PubKeyBech32Address and add support for Bech32 to PubKeyAddress

Co-authored-by: Matt Ketmo <[email protected]>
change debug message

Co-authored-by: Matt Ketmo <[email protected]>
* add additional helper function to makes switch conditional re-usable

Signed-off-by: Simon Lichtenauer <[email protected]>

* change to camelCase

Signed-off-by: Simon Lichtenauer <[email protected]>

* fix: remove not needed redundant variable asignments and log.Info messages

Signed-off-by: Simon Lichtenauer <[email protected]>

* fix: ensure slashing module is also not used in watcher.validator module

Signed-off-by: Simon Lichtenauer <[email protected]>

* fix: use camelCase

Signed-off-by: Simon Lichtenauer <[email protected]>

---------

Signed-off-by: Simon Lichtenauer <[email protected]>
@qwertzlbert
Copy link
Contributor Author

qwertzlbert commented Nov 12, 2024

@MattKetmo I addressed your comments and added your suggestions and required changes. Feel free to take another look whenever you have time.
I did not deploy the changes to my test environment yet however, so please let me check this in a more "productive" setting before merging


Edit: Just tested. Changes are working fine

@MattKetmo MattKetmo changed the title Add support for Slashing Parameters and Missed Blocks per Signing Window feat: add support for slashing parameters and missed blocks per signing window Nov 14, 2024
@MattKetmo MattKetmo added the feature New feature or request label Nov 14, 2024
@MattKetmo MattKetmo merged commit 541890a into kilnfi:main Nov 15, 2024
3 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants