Skip to content

Commit

Permalink
remove todos and update doc
Browse files Browse the repository at this point in the history
  • Loading branch information
sainoe committed Nov 23, 2023
1 parent 441bcee commit 167a74d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 14 deletions.
11 changes: 6 additions & 5 deletions x/ccv/provider/keeper/key_assignment.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,8 @@ func (k Keeper) DeleteConsumerAddrsToPrune(ctx sdk.Context, chainID string, vscI
}

// AssignConsumerKey assigns the consumerKey to the validator with providerAddr
// on the consumer chain with ID chainID
// on the consumer chain with ID chainID, if it is either registered or currently
// voted on in a ConsumerAddition governance proposal
func (k Keeper) AssignConsumerKey(
ctx sdk.Context,
chainID string,
Expand Down Expand Up @@ -398,15 +399,15 @@ func (k Keeper) AssignConsumerKey(
providerAddr := types.NewProviderConsAddress(consAddrTmp)

if existingVal, found := k.stakingKeeper.GetValidatorByConsAddr(ctx, consumerAddr.ToSdkConsAddr()); found {
// If there is a validator using the consumer key to validate on the provider
// we prevent assigning the consumer key, unless the validator is assigning validator.
// This ensures that a validator joining the active set who has not explicitly assigned
// a consumer key, will be able to use their provider key as consumer key (as per default).
// If there is already a different validator using the consumer key to validate on the provider
// we prevent assigning the consumer key.
if existingVal.OperatorAddress != validator.OperatorAddress {
return errorsmod.Wrapf(
types.ErrConsumerKeyInUse, "a different validator already uses the consumer key",
)
}
// We prevent a validator from assigning the default provider key as a consumer key
// if it has not already assigned a different consumer key
_, found := k.GetValidatorConsumerPubKey(ctx, chainID, providerAddr)
if !found {
return errorsmod.Wrapf(
Expand Down
9 changes: 2 additions & 7 deletions x/ccv/provider/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,11 @@ func NewMsgServerImpl(keeper *Keeper) types.MsgServer {

var _ types.MsgServer = msgServer{}

// CreateValidator defines a method for creating a new validator
// AssignConsumerKey defines a method to assign a consensus key on a consumer chain
// for a given validator on the provider
func (k msgServer) AssignConsumerKey(goCtx context.Context, msg *types.MsgAssignConsumerKey) (*types.MsgAssignConsumerKeyResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

// It is possible to assign keys for consumer chains that are not yet approved.
// TODO: In future, a mechanism will be added to limit assigning keys to chains
// which are approved or pending approval, only.
// Note that current attack potential is restricted because validators must sign
// the transaction, and the chainID size is limited.

providerValidatorAddr, err := sdk.ValAddressFromBech32(msg.ProviderAddr)
if err != nil {
return nil, err
Expand Down
3 changes: 1 addition & 2 deletions x/ccv/provider/types/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ func (msg MsgAssignConsumerKey) ValidateBasic() error {
// It is possible to assign keys for consumer chains that are not yet approved.
// This can only be done by a signing validator, but it is still sensible
// to limit the chainID size to prevent abuse.
// TODO: In future, a mechanism will be added to limit assigning keys to chains
// which are approved or pending approval, only.

if 128 < len(msg.ChainId) {
return ErrBlankConsumerChainID
}
Expand Down

0 comments on commit 167a74d

Please sign in to comment.