-
Notifications
You must be signed in to change notification settings - Fork 193
/
msg_server_change_validator_weight.go
42 lines (33 loc) · 1.28 KB
/
msg_server_change_validator_weight.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package keeper
import (
"context"
"fmt"
errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/Stride-Labs/stride/v11/x/stakeibc/types"
)
func (k msgServer) ChangeValidatorWeight(goCtx context.Context, msg *types.MsgChangeValidatorWeight) (*types.MsgChangeValidatorWeightResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
hostZone, found := k.GetHostZone(ctx, msg.HostZone)
if !found {
k.Logger(ctx).Error(fmt.Sprintf("Host Zone %s not found", msg.HostZone))
return nil, types.ErrInvalidHostZone
}
validators := hostZone.Validators
for _, validator := range validators {
if validator.GetAddress() == msg.ValAddr {
// when changing a weight from 0 to non-zero, make sure we have space in the val set for this new validator
if validator.Weight == 0 && msg.Weight > 0 {
err := k.ConfirmValSetHasSpace(ctx, validators)
if err != nil {
return nil, errorsmod.Wrap(types.ErrMaxNumValidators, "cannot set val weight from zero to nonzero on host zone")
}
}
validator.Weight = msg.Weight
k.SetHostZone(ctx, hostZone)
return &types.MsgChangeValidatorWeightResponse{}, nil
}
}
k.Logger(ctx).Error(fmt.Sprintf("Validator %s not found on Host Zone %s", msg.ValAddr, msg.HostZone))
return nil, types.ErrValidatorNotFound
}