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

feat: Add oracle module #392

Merged
merged 6 commits into from Apr 14, 2023
Merged

feat: Add oracle module #392

merged 6 commits into from Apr 14, 2023

Conversation

ajeet97
Copy link
Member

@ajeet97 ajeet97 commented Apr 14, 2023

Check #379 for description

@ajeet97 ajeet97 changed the title Ajeet/oracle feat: Add oracle module Apr 14, 2023
akaladarshi and others added 5 commits April 14, 2023 15:09
Adds the oracle module in the `x` folder. Oracle module is responsible for:
- Tally all the votes sent by the validators through the `oracle-feeder` within the voting period and calculate the median.

- Select the validators who have voted within the reasonable spread.

-  Distribute the reward to the selected validators from the reward pool.

- Slash the validator whose vote rate is less than the `minValidPerWindow`.

- Funds for the reward pool will be transferred through the `fund-reward-pool` command.

- Reward pool can be queried through the `reward-pool-balance` command.

At the last block of the voting period, the votes of all the valid validators will be tallied and the median will be calculated. Validators who have voted within the reasonable spread will be rewarded.
The reward will be decided based on the reward band and their voting power and the validator who has voted less than the minimum valid vote per window will be slashed(jailed).
The reward will be distributed from the reward pool account controlled by the oracle module and the funds to the reward pool can be transferred through the `fund-reward-pool` command from any address.
1. Overview

This PR improves the keeper test suite layout. It separates helper functions into x/oracle/testutil package, which can be reused (that's a canonical way to do it), also cleanups the test setup stage that runs before each step.

I moved a chunk of logic from ABCI handler into keeper to make it testable (the Tally and related ballot logic).

Also, implemented a unit test that checks slashing, that improves test coverage for now.

2. Implementation details

Rationale for this is to have better test organisation and coverage. There is also to demonstrate a way how to test slashing.
1. Overview

- Filter out the exchange rates which have votes below the vote threshold `< 50%`.

- Remove the `ValidatorsPowerStoreIterator` and instead use `GetBondedValidatorsByPower`.

- Refactor.
---------

Co-authored-by: Max Kupriianov <max@kc.vc>
1. Overview

Update oracle exchange_rate response to return the exchange rate of an asset in string.

Separate exchange_rate and all_exchange_rates queries.

2. Implementation details

Created two separate oracle queries exchange_rate, and all_exchange_rates.
exchange_rate: Takes the asset symbol as a request and returns its exchange in string.
all_exchange_rates: Doesn't take any request and returns exchange rates of all the assets stored on chain in sdk.DecCoins
1. Overview

 Add more tests in x/types.

 Change v.BaseDenom to v.SymbolDenom in tally.go. Since we are using symbol everywhere.
@ajeet97 ajeet97 marked this pull request as ready for review April 14, 2023 09:40
@ajeet97 ajeet97 requested a review from xlab April 14, 2023 09:40
@github-actions
Copy link

Coverage after merging ajeet/oracle into master

7.40%

Coverage Report
FileBranchesFuncsLinesUncovered Lines
simapp
   test_helpers.go100%100%22.38%..., 78, 79, 80, 82
   genesis_account.go100%100%100%
   encoding.go100%100%100%
   test_suite.go100%100%0%..., 52, 53, 54, 56
   state.go100%100%0%..., 94, 97, 98, 99
   app.go100%100%79.43%..., 686, 687, 688, 689
   config.go100%100%56.10%..., 72, 73, 74, 75
   utils.go100%100%20.25%..., 96, 97, 98, 99
   export.go100%100%15.27%..., 93, 97, 98, 99
   genesis.go100%100%100%
simapp/simd/cmd
   testnet.go100%100%79.44%..., 408, 409, 62, 63
   root.go100%100%81.94%..., 64, 65, 68, 69
   genaccounts.go100%100%71.54%..., 95, 96, 97, 98
x/epochs/client/cli
   tx.go100%100%0%..., 22, 23, 24, 25
   query.go100%100%0%..., 95, 96, 97, 98
x/epochs/keeper
   abci.go100%100%100%
   keeper.go100%100%92.86%30
   epoch.go100%100%85.71%..., 26, 62, 88, 93
   grpc_query.go100%100%38.46%..., 51, 53, 54, 55
   genesis.go100%100%90.91%14
   hooks.go100%100%100%
x/epochs/types
   query.pb.go100%100%2.24%..., 96, 97, 98, 99
   genesis.pb.go100%100%28.80%..., 96, 97, 98, 99
   keys.go100%100%0%20, 21, 22
   identifier.go100%100%0%..., 25, 7, 8, 9
   hooks.go100%100%100%
   genesis.go100%100%59.18%..., 57, 58, 61, 62
   query.pb.gw.go100%100%0%..., 96, 97, 98, 99
x/halving/simulation
   params.go100%100%100%
   genesis.go100%100%100%
x/halving/types
   halving.pb.go100%100%2.76%..., 96, 97, 98, 99
   query.pb.gw.go100%100%0%..., 95, 96, 97, 98
   genesis.pb.go100%100%2.55%..., 68, 69, 98, 99
   genesis.go100%100%86.67%25, 26
   query.pb.go100%100%1.91%..., 96, 97, 98, 99
   params.go100%100%85.29%23, 24, 25, 43, 44
x/interchainquery
   handler.go100%100%40%17, 18, 19
   module.go100%100%62.50%..., 87, 90, 91, 92
   genesis.go100%100%54.55%21, 22, 23, 24, 25
x/interchainquery/keeper
   msg_server.go100%100%65.08%..., 71, 74, 82, 83
   grpc_query.go100%100%74.07%..., 33, 40, 43, 44
   abci.go100%100%92.68%58, 59, 60
   keeper.go100%100%67.59%..., 43, 66, 67, 89
   queries.go100%100%98%67
x/interchainquery/types
   query.pb.gw.go100%100%0%..., 96, 97, 98, 99
   msgs.go100%100%56%..., 42, 48, 49, 50
   keys.go100%100%0%28, 29, 30
   query.pb.go100%100%1.32%..., 996, 997, 998, 999
   messages.pb.gw.go100%100%0%..., 92, 93, 95, 99
   genesis.pb.go100%100%0.76%..., 996, 997, 998, 999
   genesis.go100%100%63.64%15, 16, 17, 18
   messages.pb.go100%100%3.58%..., 96, 97, 98, 99
   codec.go100%100%100%
x/lsnative/distribution
   handler.go100%100%0%..., 14, 15, 17, 18
   abci.go100%100%0%..., 32, 33, 36, 37
   module.go100%100%0%..., 81, 82, 83, 99
x/lsnative/distribution/client/cli
   tx.go100%100%4.01%..., 96, 97, 98, 99
   utils.go100%100%63.64%16, 17, 20, 21
   query.go100%100%0%..., 95, 97, 98, 99
x/lsnative/distribution/client/common
   common.go100%100%15.25%..., 91, 92, 93, 95
x/lsnative/distribution/client/testutil
   grpc_query_suite.go100%100%99.76%459
   suite.go100%100%98.68%..., 632, 633, 634, 635
   helpers.go100%100%100%
   withdraw_all_suite.go100%100%100%
x/lsnative/distribution/keeper
   grpc_query.go100%100%0%..., 95, 96, 98, 99
   validator.go100%100%0%..., 96, 97, 98, 99
   store.go100%100%0%..., 95, 96, 97, 98
   proposal_handler.go100%100%0%..., 25, 26, 27, 28
   hooks.go100%100%0%..., 94, 97, 98, 99
   invariants.go100%100%0%..., 93, 94, 96, 99
   msg_server.go100%100%0%..., 96, 97, 98, 99
   keeper.go100%100%0%..., 95, 96, 97, 98
   genesis.go100%100%0%..., 92, 93, 94, 99
   fee_pool.go100%100%0%..., 26, 27, 29, 30
   querier.go100%100%0%..., 95, 96, 97, 98
   delegation.go100%100%0%..., 89, 90, 91, 92
   alias_functions.go100%100%0%..., 17, 20, 21, 22
   allocation.go100%100%0%..., 96, 97, 98, 99
   migrations.go100%100%0%..., 16, 19, 20, 21
   params.go100%100%0%..., 41, 42, 43, 9
x/lsnative/distribution/migrations/v043
   store.go100%100%0%..., 21, 22, 23, 24
   helpers.go100%100%0%..., 67, 68, 69, 70
x/lsnative/distribution/simulation
   params.go100%100%0%..., 33, 36, 37, 38
   genesis.go100%100%0%..., 80, 81, 83, 84
   operations.go100%100%0%..., 96, 97, 98, 99
   decoder.go100%100%0%..., 63, 64, 66, 67
   proposals.go100%100%0%..., 46, 47, 48, 49
x/lsnative/distribution/types
   distribution.pb.go100%100%0.61%..., 996, 997, 998, 999
   delegator.go100%100%0%..., 13, 14, 8, 9
   tx.pb.go100%100%0.72%..., 971, 972, 973, 974
   msg.go100%100%37.41%..., 76, 77, 96, 97
   query.go100%100%0%..., 31, 37, 38, 39
   proposal.go100%100%12.12%..., 67, 68, 69, 70
   params.go100%100%46.88%..., 69, 70, 71, 73
   genesis.go100%100%0%..., 45, 46, 47, 48
   query.pb.gw.go100%100%0%..., 994, 995, 996, 998
   query.pb.go100%100%0.67%..., 996, 997, 998, 999
   keys.go100%100%0%..., 95, 96, 97, 98
   validator.go100%100%0%..., 44, 45, 46, 47
   genesis.pb.go100%100%0.64%..., 996, 997, 998, 999
   querier.go100%100%0%..., 84, 92, 93, 94
   fee_pool.go100%100%0%..., 19, 20, 21, 23
   codec.go100%100%52.78%..., 40, 41, 42, 43
x/lsnative/genutil
   collect.go100%100%0%..., 93, 97, 98, 99
   gentx.go100%100%0%..., 96, 97, 98, 99
   genesis.go100%100%0%16, 17, 18, 19, 20
   module.go100%100%0%..., 94, 95, 96, 97
   utils.go100%100%63.64%..., 90, 91, 95, 96
x/lsnative/genutil/client/cli
   migrate.go100%100%0%..., 96, 97, 98, 99
   init.go100%100%0%..., 96, 97, 98, 99
   validate_genesis.go100%100%0%..., 66, 67, 68, 70
   collect.go100%100%0%..., 66, 67, 68, 69
   gentx.go100%100%0%..., 95, 96, 97, 99
x/lsnative/genutil/types
   genesis_state.go100%100%0%..., 96, 97, 98, 99
   types.go100%100%0%..., 42, 43, 44, 45
   genesis.pb.go100%100%2.54%..., 68, 69, 70, 99
x/lsnative/slashing
   abci.go100%100%0%..., 21, 22, 23, 24
   module.go100%100%0%..., 84, 85, 98, 99
x/lsnative/slashing/keeper
   signing_info.go100%100%0%..., 96, 97, 98, 99
   unjail.go100%100%0%..., 48, 49, 52, 53
   grpc_query.go100%100%0%..., 70, 71, 72, 73
   hooks.go100%100%0%..., 95, 96, 98, 99
   msg_server.go100%100%0%..., 42, 43, 44, 45
   infractions.go100%100%0%..., 96, 97, 98, 99
   migrations.go100%100%0%..., 16, 19, 20, 21
   params.go100%100%0%..., 49, 52, 53, 54
   genesis.go100%100%0%..., 64, 65, 66, 68
   querier.go100%100%0%..., 88, 89, 90, 92
   keeper.go100%100%0%..., 93, 94, 95, 96
x/lsnative/slashing/migrations/v043
   store.go100%100%0%..., 18, 19, 20, 21
x/lsnative/slashing/simulation
   decoder.go100%100%0%..., 38, 40, 42, 43
   params.go100%100%0%..., 32, 35, 36, 37
   genesis.go100%100%0%..., 91, 92, 94, 95
   operations.go100%100%0%..., 96, 97, 98, 99
x/lsnative/slashing/types
   signing_info.go100%100%0%..., 42, 43, 44, 45
   genesis.pb.go100%100%1.01%..., 996, 997, 998, 999
   codec.go100%100%63.16%..., 20, 21, 22, 23
   querier.go100%100%0%19, 20, 21
   params.go100%100%0%..., 93, 94, 96, 99
   keys.go100%100%0%..., 64, 67, 68, 69
   query.pb.gw.go100%100%0%..., 95, 97, 98, 99
   msg.go100%100%0%..., 40, 41, 42, 43
   query.pb.go100%100%1.04%..., 994, 995, 998, 999
   slashing.pb.go100%100%0.91%..., 966, 967, 969, 99
   tx.pb.go100%100%1.26%..., 96, 97, 98, 99
   genesis.go100%100%0%..., 61, 62, 63, 65
x/lsnative/staking
   module.go100%100%0%..., 83, 86, 87, 88
   abci.go100%100%0%..., 24, 25, 26, 27
   genesis.go100%100%0%..., 81, 82, 84, 87
x/lsnative/staking/client/cli
   flags.go100%100%47.27%..., 96, 97, 98, 99
   tx.go100%100%12.69%..., 93, 94, 95, 99
   query.go100%100%0%..., 982, 983, 984, 99
   utils.go100%100%0%..., 28, 30, 31, 32
x/lsnative/staking/keeper
   delegation.go100%100%0%..., 995, 996, 997, 998
   tokenize_share_record.go100%100%0%..., 95, 96, 98, 99
   invariants.go100%100%0%..., 96, 97, 98, 99
   keeper.go100%100%0%..., 94, 95, 96, 97
   params.go100%100%0%..., 74, 77, 78, 79
   power_reduction.go100%100%0%..., 14, 15, 16, 9
   migrations.go100%100%0%..., 24, 27, 28, 29
   slash.go100%100%0%..., 94, 95, 96, 99
   val_state_change.go100%100%0%..., 89, 90, 91, 94
   alias_functions.go100%100%0%..., 92, 93, 94, 96
   hooks.go100%100%0%..., 92, 93, 94, 95
   genesis.go100%100%0%..., 94, 95, 96, 97
   querier.go100%100%0%..., 94, 95, 96, 98
   test_common.go100%100%0%..., 64, 66, 67, 68
   query_utils.go100%100%0%..., 93, 97, 98, 99
   historical_info.go100%100%0%..., 96, 97, 98, 99
   validator.go100%100%0%..., 93, 94, 96, 97
   msg_server.go100%100%0%..., 95, 97, 98, 99
   grpc_query.go100%100%0%..., 96, 97, 98, 99
   pool.go100%100%0%..., 74, 75, 76, 78
x/lsnative/staking/migrations/v043
   store.go100%100%0%..., 76, 77, 78, 79
x/lsnative/staking/migrations/v046
   json.go100%100%0%10, 11, 12, 13, 9
   store.go100%100%0%..., 24, 25, 26, 27
x/lsnative/staking/simulation
   genesis.go100%100%0%..., 96, 97, 98, 99
   params.go100%100%0%..., 26, 29, 30, 31
   decoder.go100%100%0%..., 58, 59, 60, 61
   operations.go100%100%0%..., 96, 97, 98, 99
x/lsnative/staking/types
   codec.go100%100%57.78%..., 50, 51, 52, 53
   authz.go100%100%0%..., 95, 96, 98, 99
   params.go100%100%0%..., 94, 95, 96, 97
   keys.go100%100%0%..., 96, 97, 98, 99
   query.pb.gw.go100%100%0%..., 993, 997, 998, 999
   delegation.go100%100%0%..., 93, 95, 98, 99
   genesis.go100%100%0%..., 41, 42, 43, 45
   validator.go100%100%0%..., 95, 96, 97, 99
   querier.go100%100%0%..., 71, 80, 81, 82
   genesis.pb.go100%100%0.61%..., 994, 997, 998, 999
   historical_info.go100%100%0%..., 78, 79, 80, 82
   hooks.go100%100%0%..., 93, 95, 98, 99
   tx.pb.go100%100%0.59%..., 992, 993, 994, 995
   query.pb.go100%100%0.61%..., 985, 99, 998, 999
   commission.go100%100%0%..., 95, 96, 98, 99
   tokenize_share_record.go100%100%0%..., 14, 16, 17, 18
   authz.pb.go100%100%1.04%..., 96, 97, 98, 99
   pool.go100%100%0%..., 18, 19, 20, 21
   staking.pb.go100%100%0.42%..., 996, 997, 998, 999
   msg.go100%100%0%..., 96, 97, 98, 99
x/oracle/keeper
   alias_functions.go100%100%100%
   keeper.go100%100%93.45%..., 46, 67, 68, 69
   ballot.go100%100%100%
   msg_server.go100%100%78.52%..., 85, 86, 89, 90
   genesis.go100%100%93.33%..., 34, 43, 52, 63
   params.go100%100%68.89%..., 75, 79, 80, 81
   slash.go100%100%97.44%41
   utils.go100%100%77.78%10, 9
   tally.go100%100%93.55%..., 113, 114, 60, 61
   reward.go100%100%91.67%14, 15, 72, 88
   grpc_query.go100%100%15.29%..., 96, 97, 98, 99
x/oracle/types
   hash.go100%100%68.42%..., 65, 66, 68, 69
   params.go100%100%88.59%..., 306, 307, 308, 310
   denom.go100%100%100%
   query.pb.gw.go100%100%0%..., 95, 97, 98, 99
   genesis.pb.go100%100%0.93%..., 993, 994, 998, 999
   query.pb.go100%100%0.83%..., 969, 97, 98, 99
   codec.go100%100%52.38%..., 45, 46, 47, 48
   vote.go100%100%100%
   keys.go100%100%0%..., 58, 59, 60, 61
   ballot.go100%100%96.61%110, 111, 195, 196
   genesis.go100%100%66.67%..., 23, 24, 25, 26
   tx.pb.go100%100%0.90%..., 993, 994, 996, 999
   oracle.pb.go100%100%0.76%..., 995, 996, 997, 998
   msgs.go100%100%73.85%..., 57, 58, 93, 96

Copy link
Contributor

@xlab xlab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!!

@xlab xlab merged commit ac343b9 into master Apr 14, 2023
3 checks passed
@xlab xlab deleted the ajeet/oracle branch April 14, 2023 13:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants