-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
241 additions
and
239 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) | ||
} | ||
} |
51 changes: 34 additions & 17 deletions
51
...updaters/provider_freeze_updater_mocks.go → ...ers/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.