Skip to content

Commit

Permalink
fix: Decrementing jailed fp counter (#324)
Browse files Browse the repository at this point in the history
Closes #259. Using gauge is not easy to fix the issue as we don't know
the number of fps being jailed. Therefore, this PR fixed the issue by
adding a separate counter for unjailed fps.
  • Loading branch information
gitferry authored Dec 5, 2024
1 parent 08903f1 commit 213b1ae
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

## Unreleased

### Bug fixes

- [#324](https://github.com/babylonlabs-io/babylon/pull/324) Fix decrementing
jailed fp counter

## v0.18.0

### Improvements
Expand Down
2 changes: 1 addition & 1 deletion x/finality/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ func (ms msgServer) UnjailFinalityProvider(ctx context.Context, req *types.MsgUn
return nil, fmt.Errorf("failed to unjail finality provider %s: %w", fpPk.MarshalHex(), err)
}

types.DecrementJailedFinalityProviderCounter()
types.IncrementUnjailedFinalityProviderCounter()

return &types.MsgUnjailFinalityProviderResponse{}, nil
}
Expand Down
17 changes: 11 additions & 6 deletions x/finality/types/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,14 @@ const (

/* Metrics for monitoring finality provider liveness */

// MetricsKeyJailedFinalityProviderCounter is the number of finality providers
// that are being labeled as jailed
// MetricsKeyJailedFinalityProviderCounter is the total number of finality providers
// that are labeled as jailed
MetricsKeyJailedFinalityProviderCounter = "jailed_finality_provider_counter"
// MetricsKeyUnjailedFinalityProviderCounter is the total number of finality providers
// that are unjailed
// the number of finality providers that are being jailed can be calculated by
// jailed_finality_provider_counter - unjailed_finality_provider_counter
MetricsKeyUnjailedFinalityProviderCounter = "unjailed_finality_provider_counter"
)

// RecordLastHeight records the last height. It is triggered upon `IndexBlock`
Expand Down Expand Up @@ -64,14 +69,14 @@ func IncrementJailedFinalityProviderCounter() {
)
}

// DecrementJailedFinalityProviderCounter decrements the counter for the jailed
// IncrementUnjailedFinalityProviderCounter increments the counter for the unjailed
// finality providers
func DecrementJailedFinalityProviderCounter() {
keys := []string{MetricsKeyJailedFinalityProviderCounter}
func IncrementUnjailedFinalityProviderCounter() {
keys := []string{MetricsKeyUnjailedFinalityProviderCounter}
labels := []metrics.Label{telemetry.NewLabel(telemetry.MetricLabelNameModule, ModuleName)}
telemetry.IncrCounterWithLabels(
keys,
-1,
1,
labels,
)
}

0 comments on commit 213b1ae

Please sign in to comment.