Skip to content

Commit

Permalink
fix: getting bonded validator power in oracle endblocker (#1845)
Browse files Browse the repository at this point in the history
* fix validator power

* Floating point math and unit test

* fix e2e

* CHANGELOG++

---------

Co-authored-by: toteki <63419657+toteki@users.noreply.github.com>
(cherry picked from commit c258acc)

# Conflicts:
#	tests/e2e/e2e_setup_test.go
#	tests/e2e/e2e_test.go
  • Loading branch information
rbajollari authored and mergify[bot] committed Feb 17, 2023
1 parent b0d054a commit e5be033
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 5 deletions.
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
17 changes: 16 additions & 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 Expand Up @@ -1034,6 +1034,21 @@ func (s *IntegrationTestSuite) runPriceFeeder() {
s.T().Logf("started price-feeder container: %s", s.priceFeederResource.Container.ID)
}

<<<<<<< HEAD
=======
func (s *IntegrationTestSuite) initUmeeClient() {
var err error
s.umeeClient, err = client.NewUmeeClient(
s.chain.id,
"tcp://localhost:26657",
"tcp://localhost:9090",
"val1",
s.chain.validators[0].mnemonic,
)
s.Require().NoError(err)
}

>>>>>>> c258acc (fix: getting bonded validator power in oracle endblocker (#1845))
func noRestart(config *docker.HostConfig) {
// in this case we don't want the nodes to restart on failure
config.RestartPolicy = docker.RestartPolicy{
Expand Down
11 changes: 11 additions & 0 deletions tests/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ func (s *IntegrationTestSuite) TestUmeeTokenTransfers() {
// prices based on those params, checks that the stored medians and
// medians deviations are correct, updates the oracle params with
// a gov prop, then checks the medians and median deviations again.
<<<<<<< HEAD
func (s *IntegrationTestSuite) TestHistorical() {
umeeClient, err := client.NewUmeeClient(
s.chain.id,
Expand All @@ -154,6 +155,16 @@ func (s *IntegrationTestSuite) TestHistorical() {
"val1",
s.chain.validators[2].mnemonic,
)
=======
func (s *IntegrationTestSuite) TestMedians() {
err := grpc.MedianCheck(s.umeeClient)
s.Require().NoError(err)
}

func (s *IntegrationTestSuite) TestUpdateOracleParams() {
s.T().Skip("paused due to validator power threshold enforcing")
params, err := s.umeeClient.QueryClient.QueryParams()
>>>>>>> c258acc (fix: getting bonded validator power in oracle endblocker (#1845))
s.Require().NoError(err)

err = grpc.MedianCheck(umeeClient)
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

0 comments on commit e5be033

Please sign in to comment.