Skip to content

Commit

Permalink
Add minimum power in top N to the list-consumer-chains query
Browse files Browse the repository at this point in the history
  • Loading branch information
p-offtermatt committed May 7, 2024
1 parent 5bb6b1c commit d5e5c63
Show file tree
Hide file tree
Showing 3 changed files with 176 additions and 120 deletions.
3 changes: 3 additions & 0 deletions proto/interchain_security/ccv/provider/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ message Chain {
string client_id = 2;
// If chain with `chainID` is a Top-N chain, i.e., enforces at least one validator to validate chain `chainID`
uint32 top_N = 3;
// If the chain is a Top-N chain, this is the minimum power required to be in the top N.
// Otherwise, this is -1.
int64 min_power_in_top_N = 4;
}

message QueryValidatorConsumerAddrRequest {
Expand Down
22 changes: 18 additions & 4 deletions x/ccv/provider/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,12 +253,26 @@ func (k Keeper) GetAllConsumerChains(ctx sdk.Context) (chains []types.Chain) {
chainID := string(iterator.Key()[1:])
clientID := string(iterator.Value())

topN, _ := k.GetTopN(ctx, chainID)
topN, found := k.GetTopN(ctx, chainID)

var minPowerInTopN int64
if found && topN > 0 {
res, err := k.ComputeMinPowerToOptIn(ctx, chainID, k.stakingKeeper.GetLastValidators(ctx), topN)
if err != nil {
k.Logger(ctx).Error("failed to compute min power to opt in for chain", "chain", chainID, "error", err)
minPowerInTopN = -1
} else {
minPowerInTopN = res
}
} else {
minPowerInTopN = -1
}

chains = append(chains, types.Chain{
ChainId: chainID,
ClientId: clientID,
Top_N: topN,
ChainId: chainID,
ClientId: clientID,
Top_N: topN,
MinPowerInTop_N: minPowerInTopN,
})
}

Expand Down
Loading

0 comments on commit d5e5c63

Please sign in to comment.