-
Notifications
You must be signed in to change notification settings - Fork 209
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: PRT - Add provider freeze and jailed status metric (#1729)
* add AvailabilityStateUpdater per chain to rpcprovider * added provider availability updater * fix lint * added correct metrics * remove redundent comment * update latest epoch * wip - adding unitests * wip - availabilitty updater mock and tests * fix frozen metric help description * revert init lava * fix pr - freeze metric creation logic and split jailed metric data * fix lint * fix make lint * set updater key with chainid only * fix public address setup for freeze updater * add unitests for freeze updater epoch updates * change query to provider instead of providers * fix jailed status metric labels * Update protocol/metrics/metrics_provider_manager.go Co-authored-by: Elad Gildnur <6321801+shleikes@users.noreply.github.com> * Fix after merge * Numerus changes * Fix lint --------- Co-authored-by: leon mandel <lmandel@leons-MacBook-Pro.local> Co-authored-by: Ran Mishael <106548467+ranlavanet@users.noreply.github.com> Co-authored-by: Elad Gildnur <6321801+shleikes@users.noreply.github.com> Co-authored-by: Elad Gildnur <elad.gildnur@gmail.com> Co-authored-by: Ran Mishael <ran@lavanet.xyz> Co-authored-by: omerlavanet <omer@lavanet.xyz>
- Loading branch information
1 parent
da37d59
commit a0b0de8
Showing
6 changed files
with
349 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
protocol/statetracker/updaters/provider_freeze_jail_updater.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package updaters | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"github.com/lavanet/lava/v4/utils" | ||
pairingtypes "github.com/lavanet/lava/v4/x/pairing/types" | ||
"google.golang.org/grpc" | ||
) | ||
|
||
const ( | ||
CallbackKeyForFreezeUpdate = "freeze-update" | ||
) | ||
|
||
type ProviderPairingStatusStateQueryInf interface { | ||
Provider(ctx context.Context, in *pairingtypes.QueryProviderRequest, opts ...grpc.CallOption) (*pairingtypes.QueryProviderResponse, error) | ||
} | ||
|
||
type ProviderMetricsManagerInf interface { | ||
SetFrozenStatus(string, bool) | ||
SetJailStatus(string, bool) | ||
SetJailedCount(string, uint64) | ||
} | ||
|
||
type FrozenStatus uint64 | ||
|
||
const ( | ||
AVAILABLE FrozenStatus = iota | ||
FROZEN | ||
) | ||
|
||
type ProviderFreezeJailUpdater struct { | ||
pairingQueryClient ProviderPairingStatusStateQueryInf | ||
metricsManager ProviderMetricsManagerInf | ||
publicAddress string | ||
} | ||
|
||
func NewProviderFreezeJailUpdater( | ||
pairingQueryClient ProviderPairingStatusStateQueryInf, | ||
publicAddress string, | ||
metricsManager ProviderMetricsManagerInf, | ||
) *ProviderFreezeJailUpdater { | ||
return &ProviderFreezeJailUpdater{ | ||
pairingQueryClient: pairingQueryClient, | ||
publicAddress: publicAddress, | ||
metricsManager: metricsManager, | ||
} | ||
} | ||
|
||
func (pfu *ProviderFreezeJailUpdater) UpdateEpoch(epoch uint64) { | ||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) | ||
response, err := pfu.pairingQueryClient.Provider(ctx, &pairingtypes.QueryProviderRequest{Address: pfu.publicAddress}) | ||
cancel() | ||
|
||
if err != nil { | ||
utils.LavaFormatError("Failed querying pairing client for provider", err) | ||
return | ||
} | ||
|
||
for _, provider := range response.StakeEntries { | ||
if provider.Address != pfu.publicAddress || !provider.IsAddressVaultOrProvider(provider.Address) { | ||
// should never happen, but just in case | ||
continue | ||
} | ||
|
||
pfu.metricsManager.SetJailedCount(provider.Chain, provider.Jails) | ||
pfu.metricsManager.SetJailStatus(provider.Chain, provider.IsJailed(time.Now().UTC().Unix())) | ||
pfu.metricsManager.SetFrozenStatus(provider.Chain, provider.IsFrozen() || provider.StakeAppliedBlock > epoch) | ||
} | ||
} |
121 changes: 121 additions & 0 deletions
121
protocol/statetracker/updaters/provider_freeze_jail_updater_mocks.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.