Skip to content

Commit

Permalink
address Riley's PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
shellvish committed Jun 27, 2022
1 parent 2adbbbc commit 82a1e27
Show file tree
Hide file tree
Showing 11 changed files with 100 additions and 100 deletions.
2 changes: 1 addition & 1 deletion proto/stakeibc/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ message MsgChangeValidatorWeightResponse {
message MsgDeleteValidator {
string creator = 1;
string hostZone = 2;
string name = 3;
string valAddr = 3 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];
}

message MsgDeleteValidatorResponse {
Expand Down
8 changes: 4 additions & 4 deletions x/stakeibc/keeper/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func (k Keeper) CreateDepositRecordsForEpoch(ctx sdk.Context, epochNumber int64)

func (k Keeper) SetWithdrawalAddress(ctx sdk.Context) {
setWithdrawalAddresses := func(ctx sdk.Context, index int64, zoneInfo types.HostZone) error {
k.Logger(ctx).Info(fmt.Sprintf("\tsetting withdrawal addresses on host zones"))
k.Logger(ctx).Info("\tsetting withdrawal addresses on host zones")
err := k.SetWithdrawalAddressOnHost(ctx, zoneInfo)
if err != nil {
k.Logger(ctx).Error(fmt.Sprintf("Did not set withdrawal address to %s on %s", zoneInfo.GetWithdrawalAccount().GetAddress(), zoneInfo.GetChainId()))
Expand All @@ -167,7 +167,7 @@ func (k Keeper) StakeExistingDepositsOnHostZones(ctx sdk.Context, epochNumber in
continue
}
delegateAccount := hostZone.GetDelegationAccount()
if delegateAccount == nil || delegateAccount.Address == "" {
if delegateAccount == nil || delegateAccount.GetAddress() == "" {
k.Logger(ctx).Error("[STAKE] Zone %s is missing a delegation address!", hostZone.ChainId)
continue
}
Expand Down Expand Up @@ -221,11 +221,11 @@ func (k Keeper) TransferExistingDepositsToHostZones(ctx sdk.Context, epochNumber
continue
}
delegateAccount := hostZone.GetDelegationAccount()
if delegateAccount == nil || delegateAccount.Address == "" {
if delegateAccount == nil || delegateAccount.GetAddress() == "" {
k.Logger(ctx).Error("[TRANSFER] Zone %s is missing a delegation address!", hostZone.ChainId)
continue
}
delegateAddress := delegateAccount.Address
delegateAddress := delegateAccount.GetAddress()
// TODO(TEST-89): Set NewHeight relative to the most recent known gaia height (based on the LC)
// TODO(TEST-90): why do we have two gaia LCs?
timeoutHeight := clienttypes.NewHeight(0, 1000000)
Expand Down
26 changes: 13 additions & 13 deletions x/stakeibc/keeper/host_zone.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,29 +93,29 @@ func (k Keeper) GetAllHostZone(ctx sdk.Context) (list []types.HostZone) {
return
}

func (k Keeper) AddValidatorToHostZone(ctx sdk.Context, chainId string, val types.Validator) (success bool) {
hostZone, found := k.GetHostZone(ctx, chainId)
if !found {
k.Logger(ctx).Error(fmt.Sprintf("HostZone not found %s", chainId))
return false
}
hostZone.Validators = append(hostZone.Validators, &val)
return true
}

func (k Keeper) RemoveValidatorFromHostZone(ctx sdk.Context, chainId string, validatorName string) (success bool) {
// func (k Keeper) AddValidatorToHostZone(ctx sdk.Context, chainId string, val types.Validator) (success bool) {
// hostZone, found := k.GetHostZone(ctx, chainId)
// if !found {
// k.Logger(ctx).Error(fmt.Sprintf("HostZone not found %s", chainId))
// return false
// }
// hostZone.Validators = append(hostZone.Validators, &val)
// return true
// }

func (k Keeper) RemoveValidatorFromHostZone(ctx sdk.Context, chainId string, validatorAddress string) (success bool) {
hostZone, found := k.GetHostZone(ctx, chainId)
if !found {
k.Logger(ctx).Error(fmt.Sprintf("HostZone not found %s", chainId))
return false
}
for i, val := range hostZone.Validators {
if val.Name == validatorName {
if val.GetAddress() == validatorAddress {
hostZone.Validators = append(hostZone.Validators[:i], hostZone.Validators[i+1:]...)
return true
}
}
k.Logger(ctx).Error(fmt.Sprintf("Validator %s not found on Host Zone %s", validatorName, chainId))
k.Logger(ctx).Error(fmt.Sprintf("Validator %s not found on Host Zone %s", validatorAddress, chainId))
return false
}

Expand Down
2 changes: 1 addition & 1 deletion x/stakeibc/keeper/msg_server_add_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func (k msgServer) AddValidator(goCtx context.Context, msg *types.MsgAddValidato
validators := hostZone.Validators
// check that we don't already have this validator
for _, validator := range validators {
if validator.Address == msg.Address {
if validator.GetAddress() == msg.Address {
k.Logger(ctx).Info(fmt.Sprintf("Validator address %s already exists on Host Zone %s", msg.Address, msg.HostZone))
return nil, types.ErrValidatorAlreadyExists
}
Expand Down
2 changes: 1 addition & 1 deletion x/stakeibc/keeper/msg_server_change_validator_weight.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func (k msgServer) ChangeValidatorWeight(goCtx context.Context, msg *types.MsgCh
}
validators := hostZone.Validators
for _, validator := range validators {
if validator.Address == msg.ValAddr {
if validator.GetAddress() == msg.ValAddr {
validator.Weight = msg.Weight
k.SetHostZone(ctx, hostZone)
return &types.MsgChangeValidatorWeightResponse{}, nil
Expand Down
4 changes: 2 additions & 2 deletions x/stakeibc/keeper/msg_server_delete_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (
func (k msgServer) DeleteValidator(goCtx context.Context, msg *types.MsgDeleteValidator) (*types.MsgDeleteValidatorResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

validatorRemoved := k.RemoveValidatorFromHostZone(ctx, msg.HostZone, msg.Name)
validatorRemoved := k.RemoveValidatorFromHostZone(ctx, msg.HostZone, msg.ValAddr)
if !validatorRemoved {
k.Logger(ctx).Error(fmt.Sprintf("Validator %s not found in host zone %s", msg.Name, msg.HostZone))
k.Logger(ctx).Error(fmt.Sprintf("Validator %s not found in host zone %s", msg.ValAddr, msg.HostZone))
return nil, types.ErrValidatorNotFound
}

Expand Down
4 changes: 2 additions & 2 deletions x/stakeibc/keeper/msg_server_rebalance_validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (k msgServer) RebalanceValidators(goCtx context.Context, msg *types.MsgReba
}

var msgs []sdk.Msg
delegatorAddressStr := hostZone.DelegationAccount.Address
delegatorAddressStr := hostZone.GetDelegationAccount().GetAddress()
delegatorAddress := sdk.AccAddress(delegatorAddressStr)

for i := 1; i < maxNumRebalance; i++ {
Expand Down Expand Up @@ -138,7 +138,7 @@ func (k msgServer) RebalanceValidators(goCtx context.Context, msg *types.MsgReba
}

connectionId := hostZone.GetConnectionId()
err = k.SubmitTxs(ctx, connectionId, msgs, *hostZone.DelegationAccount)
err = k.SubmitTxs(ctx, connectionId, msgs, *hostZone.GetDelegationAccount())
if err != nil {
return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "Failed to SubmitTxs for %s, %s, %s", connectionId, hostZone.ChainId, msgs)
}
Expand Down
2 changes: 1 addition & 1 deletion x/stakeibc/keeper/msg_server_submit_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func (k Keeper) UpdateWithdrawalBalance(ctx sdk.Context, zoneInfo types.HostZone
if withdrawalIca == nil || withdrawalIca.Address == "" {
k.Logger(ctx).Error("Zone %s is missing a delegation address!", zoneInfo.ChainId)
}
k.Logger(ctx).Info(fmt.Sprintf("\tQuerying withdrawalBalances for %s at %d height", zoneInfo.ChainId))
k.Logger(ctx).Info(fmt.Sprintf("\tQuerying withdrawalBalances for %s", zoneInfo.ChainId))

_, addr, _ := bech32.DecodeAndConvert(withdrawalIca.GetAddress())
data := bankTypes.CreateAccountBalancesPrefix(addr)
Expand Down
14 changes: 7 additions & 7 deletions x/stakeibc/keeper/validator_selection.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (k Keeper) GetValidatorDelegationAmtDifferences(ctx sdk.Context, hostZone t
return nil, err
}
for _, validator := range validators {
delegationDelta[validator.Address] = int64(targetDelegation[validator.Address]) - int64(validator.DelegationAmt)
delegationDelta[validator.GetAddress()] = int64(targetDelegation[validator.GetAddress()]) - int64(validator.DelegationAmt)
}
return delegationDelta, nil
}
Expand All @@ -38,16 +38,16 @@ func (k Keeper) GetTargetValAmtsForHostZone(ctx sdk.Context, hostZone types.Host
k.Logger(ctx).Error(fmt.Sprintf("Cannot calculate target delegation if final amount is 0 %s", hostZone.ChainId))
return nil, types.ErrNoValidatorWeights
}
var targetWeight map[string]uint64
targetWeight := make(map[string]uint64)
allocatedAmt := uint64(0)
for i, validator := range hostZone.Validators {
if i == len(hostZone.Validators)-1 {
// for the last element, we need to make sure that the allocatedAmt is equal to the finalDelegation
targetWeight[validator.Address] = finalDelegation - allocatedAmt
targetWeight[validator.GetAddress()] = finalDelegation - allocatedAmt
} else {
delegateAmt := uint64(float64(validator.Weight*finalDelegation) / float64(totalWeight))
allocatedAmt += delegateAmt
targetWeight[validator.Address] = delegateAmt
targetWeight[validator.GetAddress()] = delegateAmt
}

}
Expand All @@ -56,11 +56,11 @@ func (k Keeper) GetTargetValAmtsForHostZone(ctx sdk.Context, hostZone types.Host

func (k Keeper) GetTotalValidatorDelegations(ctx sdk.Context, hostZone types.HostZone) uint64 {
validators := hostZone.GetValidators()
total_weight := uint64(0)
total_delegation := uint64(0)
for _, validator := range validators {
total_weight += validator.DelegationAmt
total_delegation += validator.DelegationAmt
}
return total_weight
return total_delegation
}

func (k Keeper) GetTotalValidatorWeight(ctx sdk.Context, hostZone types.HostZone) uint64 {
Expand Down
4 changes: 2 additions & 2 deletions x/stakeibc/types/message_delete_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ const TypeMsgDeleteValidator = "delete_validator"

var _ sdk.Msg = &MsgDeleteValidator{}

func NewMsgDeleteValidator(creator string, hostZone string, name string) *MsgDeleteValidator {
func NewMsgDeleteValidator(creator string, hostZone string, valAddr string) *MsgDeleteValidator {
return &MsgDeleteValidator{
Creator: creator,
HostZone: hostZone,
Name: name,
ValAddr: valAddr,
}
}

Expand Down
Loading

0 comments on commit 82a1e27

Please sign in to comment.