Skip to content

Commit

Permalink
Add other validator shaping params to consumer chain list
Browse files Browse the repository at this point in the history
  • Loading branch information
p-offtermatt committed May 7, 2024
1 parent 0b1b148 commit 8cebfa8
Show file tree
Hide file tree
Showing 4 changed files with 375 additions and 122 deletions.
10 changes: 10 additions & 0 deletions proto/interchain_security/ccv/provider/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,16 @@ message Chain {
// 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;
// Corresponds to the maximum power (percentage-wise) a validator can have on the consumer chain.
uint32 validators_power_cap = 5;
// Corresponds to the maximum number of validators that can validate a consumer chain.
// Only applicable to Opt In chains. Setting `validator_set_cap` on a Top N chain is a no-op.
uint32 validator_set_cap = 6;
// Corresponds to a list of provider consensus addresses of validators that are the ONLY ones that can validate
// the consumer chain.
repeated string allowlist = 7;
// Corresponds to a list of provider consensus addresses of validators that CANNOT validate the consumer chain.
repeated string denylist = 8;
}

message QueryValidatorConsumerAddrRequest {
Expand Down
Empty file modified scripts/protocgen.sh
100644 → 100755
Empty file.
60 changes: 56 additions & 4 deletions x/ccv/provider/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,11 +268,29 @@ func (k Keeper) GetAllConsumerChains(ctx sdk.Context) (chains []types.Chain) {
minPowerInTopN = -1
}

validatorSetCap, _ := k.GetValidatorSetCap(ctx, chainID)
validatorsPowerCap, _ := k.GetValidatorsPowerCap(ctx, chainID)
allowlist := k.GetAllowList(ctx, chainID)
strAllowlist := make([]string, len(allowlist))
for i, addr := range allowlist {
strAllowlist[i] = addr.String()
}

denylist := k.GetDenyList(ctx, chainID)
strDenylist := make([]string, len(denylist))
for i, addr := range denylist {
strDenylist[i] = addr.String()
}

chains = append(chains, types.Chain{
ChainId: chainID,
ClientId: clientID,
Top_N: topN,
MinPowerInTop_N: minPowerInTopN,
ChainId: chainID,
ClientId: clientID,
Top_N: topN,
MinPowerInTop_N: minPowerInTopN,
ValidatorSetCap: validatorSetCap,
ValidatorsPowerCap: validatorsPowerCap,
Allowlist: strAllowlist,
Denylist: strDenylist,
})
}

Expand Down Expand Up @@ -1460,6 +1478,23 @@ func (k Keeper) SetAllowlist(
store.Set(types.AllowlistCapKey(chainID, providerAddr), []byte{})
}

// GetAllowList returns all allowlisted validators
func (k Keeper) GetAllowList(
ctx sdk.Context,
chainID string,
) (providerConsAddresses []types.ProviderConsAddress) {
store := ctx.KVStore(k.storeKey)
key := types.ChainIdWithLenKey(types.AllowlistPrefix, chainID)
iterator := sdk.KVStorePrefixIterator(store, key)
defer iterator.Close()

for ; iterator.Valid(); iterator.Next() {
providerConsAddresses = append(providerConsAddresses, types.NewProviderConsAddress(iterator.Key()[len(key):]))
}

return providerConsAddresses
}

// IsAllowlisted returns `true` if validator with `providerAddr` has been allowlisted on chain `chainID`
func (k Keeper) IsAllowlisted(
ctx sdk.Context,
Expand Down Expand Up @@ -1510,6 +1545,23 @@ func (k Keeper) SetDenylist(
store.Set(types.DenylistCapKey(chainID, providerAddr), []byte{})
}

// GetDenyList returns all denylisted validators
func (k Keeper) GetDenyList(
ctx sdk.Context,
chainID string,
) (providerConsAddresses []types.ProviderConsAddress) {
store := ctx.KVStore(k.storeKey)
key := types.ChainIdWithLenKey(types.DenylistPrefix, chainID)
iterator := sdk.KVStorePrefixIterator(store, key)
defer iterator.Close()

for ; iterator.Valid(); iterator.Next() {
providerConsAddresses = append(providerConsAddresses, types.NewProviderConsAddress(iterator.Key()[len(key):]))
}

return providerConsAddresses
}

// IsDenylisted returns `true` if validator with `providerAddr` has been denylisted on chain `chainID`
func (k Keeper) IsDenylisted(
ctx sdk.Context,
Expand Down
Loading

0 comments on commit 8cebfa8

Please sign in to comment.