-
Notifications
You must be signed in to change notification settings - Fork 138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add queries for PSS and consumer commission rate #1733
Merged
Merged
Changes from 38 commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
b0d4cf9
init commit
insumity 0162242
nit change
insumity 7ad2993
cleaning up
insumity 5cd5ba5
clean up
insumity 5393f19
Merge branch 'feat/partial-set-security' into insumity/add-opt-in-set
insumity 03af237
fix distribution test
insumity 07429fa
Update x/ccv/provider/keeper/hooks.go
insumity 0ab0b32
took into Simon's comments
insumity 1a0fa9e
took into rest of the comments
insumity 56ca38d
nit change
insumity c614fd2
return an error if validator cannot opt out from a Top N chain
insumity 6503f9b
removed automatic opt-in for validators that vote Yes on proposals
insumity 330c085
tiny fix for E2E tests
insumity 629cfd1
nit change to remove unecessary else
insumity afd4652
update consumer chains query to return topN
sainoe 2e95f89
update query consu chains proto
sainoe a9db491
Merge remote-tracking branch 'remotes/upstream/insumity/add-opt-in-se…
sainoe 1e3a8e7
add consumer chains per validator query
sainoe 149ba7a
Add PSS command to provider's cli
sainoe 24be8b2
nits
sainoe b311f35
add consumer commission rate query
sainoe 22ca561
Merge branch 'feat/partial-set-security' into sainoe/pss-query
sainoe 5509108
nits
sainoe ad91b0e
big renaming
sainoe 559b28f
fix doc
sainoe 00e43a9
nits
sainoe 4f9084f
nits
sainoe d4fc4cb
docs
sainoe 938d930
Update proto/interchain_security/ccv/provider/v1/query.proto
sainoe 9739ddd
nit
sainoe c01ab08
add OptedIn in QueryConsumerChainsValidatorHasToValidate
sainoe 4661a99
remove OptIn field in consumer chains query response
sainoe 219d310
Merge remote-tracking branch 'remotes/upstream/sainoe/pss-query' into…
sainoe 10dbb53
include validators that opt-in during the next epochs
sainoe d642e8a
update has-to-validate condition
sainoe 69d0b28
Merge branch 'feat/partial-set-security' into sainoe/pss-query
sainoe f9e63f0
fix tinny bug in the tests after merging feat/partial-security
sainoe 3ae3031
update doc
sainoe ed402f8
update cli description
sainoe c75594f
Update x/ccv/provider/keeper/grpc_query.go
sainoe 899f3ea
Merge branch 'sainoe/pss-query' of https://github.com/cosmos/intercha…
sainoe b1c1beb
changes
sainoe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ package keeper | |
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"google.golang.org/grpc/codes" | ||
"google.golang.org/grpc/status" | ||
|
@@ -42,7 +43,6 @@ func (k Keeper) QueryConsumerChains(goCtx context.Context, req *types.QueryConsu | |
|
||
ctx := sdk.UnwrapSDKContext(goCtx) | ||
|
||
// convert to array of pointers | ||
chains := []*types.Chain{} | ||
for _, chain := range k.GetAllConsumerChains(ctx) { | ||
// prevent implicit memory aliasing | ||
|
@@ -221,3 +221,121 @@ func (k Keeper) QueryParams(c context.Context, _ *types.QueryParamsRequest) (*ty | |
|
||
return &types.QueryParamsResponse{Params: params}, nil | ||
} | ||
|
||
// QueryConsumerChainOptedInValidators returns all validators that opted-in to a given consumer chain | ||
func (k Keeper) QueryConsumerChainOptedInValidators(goCtx context.Context, req *types.QueryConsumerChainOptedInValidatorsRequest) (*types.QueryConsumerChainOptedInValidatorsResponse, error) { | ||
if req == nil { | ||
return nil, status.Error(codes.InvalidArgument, "empty request") | ||
} | ||
|
||
consumerChainID := req.ChainId | ||
if consumerChainID == "" { | ||
return nil, status.Error(codes.InvalidArgument, "empty chainId") | ||
} | ||
|
||
optedInVals := []string{} | ||
ctx := sdk.UnwrapSDKContext(goCtx) | ||
|
||
if !k.IsConsumerProposedOrRegistered(ctx, consumerChainID) { | ||
return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("unknown consumer chain: %s", consumerChainID)) | ||
} | ||
|
||
for _, v := range k.GetAllOptedIn(ctx, ctx.ChainID()) { | ||
optedInVals = append(optedInVals, v.ToSdkConsAddr().String()) | ||
} | ||
|
||
return &types.QueryConsumerChainOptedInValidatorsResponse{ | ||
ValidatorsProviderAddresses: optedInVals, | ||
}, nil | ||
} | ||
|
||
// QueryConsumerChainsValidatorHasToValidate returns all consumer chains that the given validator has to validate now | ||
// or in the next epoch if nothing change. | ||
sainoe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
func (k Keeper) QueryConsumerChainsValidatorHasToValidate(goCtx context.Context, req *types.QueryConsumerChainsValidatorHasToValidateRequest) (*types.QueryConsumerChainsValidatorHasToValidateResponse, error) { | ||
if req == nil { | ||
return nil, status.Error(codes.InvalidArgument, "empty request") | ||
} | ||
|
||
if req.ProviderAddress == "" { | ||
return nil, status.Error(codes.InvalidArgument, "empty provider address") | ||
} | ||
|
||
consAddr, err := sdk.ConsAddressFromBech32(req.ProviderAddress) | ||
if err != nil { | ||
return nil, status.Error(codes.InvalidArgument, "invalid provider address") | ||
} | ||
|
||
ctx := sdk.UnwrapSDKContext(goCtx) | ||
|
||
// get all the consumer chains for which the validator is either already | ||
// opted-in, currently a consumer validator or if its voting power is within the TopN validators | ||
consumersToValidate := []string{} | ||
for _, consumer := range k.GetAllConsumerChains(ctx) { | ||
chainID := consumer.ChainId | ||
provAddr := types.NewProviderConsAddress(consAddr) | ||
if !k.IsOptedIn(ctx, chainID, provAddr) && !k.IsConsumerValidator(ctx, chainID, provAddr) { | ||
// check that the validator voting power isn't in the TopN | ||
if topN, found := k.GetTopN(ctx, chainID); found && topN > 0 { | ||
val, found := k.stakingKeeper.GetValidatorByConsAddr(ctx, consAddr) | ||
if !found { | ||
return nil, status.Error(codes.InvalidArgument, "invalid provider address") | ||
} | ||
power := k.stakingKeeper.GetLastValidatorPower(ctx, val.GetOperator()) | ||
minPowerToOptIn := k.ComputeMinPowerToOptIn(ctx, chainID, k.stakingKeeper.GetLastValidators(ctx), topN) | ||
|
||
// Check that the validator's voting power is smaller | ||
// than the minimum to be automatically opt-in | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Not sure if this should be "bigger" instead of "smaller" because "to be automatically opted in" you need this to be bigger? |
||
if power < minPowerToOptIn { | ||
continue | ||
} | ||
} | ||
} | ||
|
||
consumersToValidate = append(consumersToValidate, chainID) | ||
} | ||
|
||
return &types.QueryConsumerChainsValidatorHasToValidateResponse{ | ||
ConsumerChainIds: consumersToValidate, | ||
}, nil | ||
} | ||
|
||
// QueryValidatorConsumerCommissionRate returns the commission rate a given | ||
// validator charges on a given consumer chain | ||
func (k Keeper) QueryValidatorConsumerCommissionRate(goCtx context.Context, req *types.QueryValidatorConsumerCommissionRateRequest) (*types.QueryValidatorConsumerCommissionRateResponse, error) { | ||
if req == nil { | ||
return nil, status.Error(codes.InvalidArgument, "empty request") | ||
} | ||
|
||
consumerChainID := req.ChainId | ||
if consumerChainID == "" { | ||
return nil, status.Error(codes.InvalidArgument, "empty chainId") | ||
} | ||
|
||
consAddr, err := sdk.ConsAddressFromBech32(req.ProviderAddress) | ||
if err != nil { | ||
return nil, status.Error(codes.InvalidArgument, "invalid provider address") | ||
} | ||
|
||
ctx := sdk.UnwrapSDKContext(goCtx) | ||
|
||
if !k.IsConsumerProposedOrRegistered(ctx, consumerChainID) { | ||
return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("unknown consumer chain: %s", consumerChainID)) | ||
} | ||
|
||
res := &types.QueryValidatorConsumerCommissionRateResponse{} | ||
|
||
// Check if the validator has a commission rate set for the consumer chain, | ||
// otherwise use the commission rate from the validator staking module struct | ||
consumerRate, found := k.GetConsumerCommissionRate(ctx, consumerChainID, types.NewProviderConsAddress(consAddr)) | ||
if found { | ||
res.Rate = consumerRate | ||
} else { | ||
v, ok := k.stakingKeeper.GetValidatorByConsAddr(ctx, consAddr) | ||
if !ok { | ||
return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("unknown validator: %s", consAddr.String())) | ||
} | ||
res.Rate = v.Commission.Rate | ||
} | ||
|
||
return res, nil | ||
} |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we make this a bit more explicit?