Skip to content

Commit

Permalink
addressed vishal PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
sampocs committed Dec 18, 2023
1 parent 93f238c commit 39149ed
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
9 changes: 7 additions & 2 deletions x/stakeibc/keeper/host_zone.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,14 @@ func (k Keeper) AddValidatorToHostZone(ctx sdk.Context, chainId string, validato
SlashQueryCheckpoint: checkpoint,
})

// Finally, confirm none of the validator's exceed the weight cap
if err := k.CheckValidatorWeightsBelowCap(ctx, hostZone.Validators); err != nil {
return err
}

k.SetHostZone(ctx, hostZone)

// Finally, confirm none of the validator's exceed the weight cap
return k.CheckValidatorWeightsBelowCap(ctx, hostZone.Validators)
return nil
}

// Removes a validator from a host zone
Expand Down Expand Up @@ -325,6 +329,7 @@ func (k Keeper) CheckValidatorWeightsBelowCap(ctx sdk.Context, validators []*typ
return nil
}

// The weight cap in params is an int representing a percentage (e.g. 10 is 10%)
params := k.GetParams(ctx)
validatorWeightCap := float64(params.ValidatorWeightCap)

Expand Down
18 changes: 9 additions & 9 deletions x/stakeibc/keeper/host_zone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,15 +382,15 @@ func (s *KeeperTestSuite) TestCheckValidatorWeightsBelowCap() {
name: "not enough validators",
weightCap: 10,
validators: []*types.Validator{
{Address: "val1", Weight: 0},
{Address: "val2", Weight: 0},
{Address: "val3", Weight: 0},
{Address: "val4", Weight: 0},
{Address: "val5", Weight: 0},
{Address: "val6", Weight: 0},
{Address: "val7", Weight: 0},
{Address: "val8", Weight: 0},
{Address: "val9", Weight: 0},
{Address: "val1", Weight: 1},
{Address: "val2", Weight: 1},
{Address: "val3", Weight: 1},
{Address: "val4", Weight: 1},
{Address: "val5", Weight: 1},
{Address: "val6", Weight: 1},
{Address: "val7", Weight: 1},
{Address: "val8", Weight: 1},
{Address: "val9", Weight: 1},
},
exceedsCap: false,
},
Expand Down

0 comments on commit 39149ed

Please sign in to comment.