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 #379

Merged
merged 10 commits into from
Feb 27, 2023
Merged

Conversation

akaladarshi
Copy link
Contributor

@akaladarshi akaladarshi commented Feb 7, 2023

1. Overview

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.

2. Implementation details

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.

3. How to test/use

make test-unit

4. Checklist

  • Does the Readme need to be updated?

6. Future Work (optional)

  • Track the reward pool balance so we can transfer the funds.

@akaladarshi akaladarshi marked this pull request as draft February 7, 2023 14:11
@github-actions
Copy link

github-actions bot commented Feb 7, 2023

Coverage after merging tikaryan/oracle-module into master

46.13%

Coverage Report
FileBranchesFuncsLinesUncovered Lines
simapp
   genesis.go100%100%100%
   config.go100%100%56.10%..., 72, 73, 74, 75
   test_suite.go100%100%0%..., 52, 53, 54, 56
   state.go100%100%0%..., 96, 97, 98, 99
   test_helpers.go100%100%0.93%..., 96, 97, 98, 99
   app.go100%100%78.36%..., 682, 683, 684, 685
   genesis_account.go100%100%100%
   utils.go100%100%20.25%..., 96, 97, 98, 99
   encoding.go100%100%100%
   export.go100%100%15.27%..., 93, 97, 98, 99
simapp/simd/cmd
   genaccounts.go100%100%72.44%..., 95, 97, 98, 99
   root.go100%100%72.69%..., 66, 67, 70, 71
x/epochs/client/cli
   query.go100%100%0%..., 95, 96, 97, 98
   tx.go100%100%0%..., 22, 23, 24, 25
x/epochs/keeper
   grpc_query.go100%100%43.48%..., 47, 49, 50, 51
   hooks.go100%100%100%
   keeper.go100%100%92.86%31
   epoch.go100%100%85.71%..., 26, 62, 88, 93
   abci.go100%100%100%
   genesis.go100%100%90.91%14
x/epochs/types
   identifier.go100%100%0%..., 25, 7, 8, 9
   hooks.go100%100%100%
   keys.go100%100%0%20, 21, 22
   genesis.go100%100%59.18%..., 57, 58, 61, 62
x/halving/simulation
   params.go100%100%100%
   genesis.go100%100%100%
x/halving/types
   genesis.go100%100%86.67%25, 26
   params.go100%100%85.29%23, 24, 25, 43, 44
x/interchainquery
   handler.go100%100%40%16, 17, 18
   genesis.go100%100%54.55%21, 22, 23, 24, 25
   module.go100%100%62.50%..., 87, 90, 91, 92
x/interchainquery/keeper
   queries.go100%100%98%66
   abci.go100%100%92.68%58, 59, 60
   grpc_query.go100%100%74.07%..., 33, 40, 43, 44
   msg_server.go100%100%65.08%..., 71, 74, 82, 83
   keeper.go100%100%67.59%..., 64, 65, 87, 99
x/interchainquery/types
   genesis.go100%100%63.64%15, 16, 17, 18
   keys.go100%100%0%28, 29, 30
   codec.go100%100%100%
   msgs.go100%100%56%..., 42, 48, 49, 50
x/oracle/keeper
   alias_functions.go100%100%100%
   msg_server.go100%100%2.16%..., 94, 95, 96, 97
   grpc_query.go100%100%2%..., 88, 90, 98, 99
   params.go100%100%35.71%..., 61, 62, 63, 64
   slash.go100%100%0%..., 49, 50, 54, 55
   reward.go100%100%89.58%14, 15, 71, 77, 87
   utils.go100%100%66.67%7, 8
   ballot.go100%100%0%..., 67, 68, 69, 70
   keeper.go100%100%56.97%..., 96, 97, 98, 99

@akaladarshi akaladarshi marked this pull request as ready for review February 8, 2023 07:39
@akaladarshi akaladarshi requested a review from xlab February 8, 2023 07:40
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.

In general, the codebase looks solid! Well done.

The most required thing there is better test coverage, especially unit tests for functions that contain math and are not so obvious.

Also, I didn't find docs for the parameters. It looks some of them (VoteThreshold) are not even used at the moment. Others like RewardSpread have dubious meaning (at the first glance). (some good examples: example1, example2)

There is an extra part related to spam prevention which I don't understand and it probably belongs to a separate PR.

Last thing, we need to ensure that this implementation matches the design (IRD or other spec), I think it would be cool if most heavy parts of the code would refer to such a document.

x/oracle/types/msgs.go Outdated Show resolved Hide resolved
proto/persistence/oracle/v1beta1/oracle.proto Show resolved Hide resolved
proto/persistence/oracle/v1beta1/oracle.proto Outdated Show resolved Hide resolved
proto/persistence/oracle/v1beta1/query.proto Outdated Show resolved Hide resolved
x/oracle/keeper/keeper.go Outdated Show resolved Hide resolved
x/oracle/keeper/keeper.go Outdated Show resolved Hide resolved
var ten = sdk.MustNewDecFromStr("10")

// Keeper of the oracle store
type Keeper struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

I suggest designing Keepers exposed as interfaces. Makes testing much easier and in general increases modularity.

Copy link
Contributor

Choose a reason for hiding this comment

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

type keeper struct {

and

type Keeper interface {

the latter lists all its keeper methods that this module exposes to other places like ABCI.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is done for consistency of the code base. But if required we can have a PR to change all keeper struct to the interface.

Copy link
Contributor

Choose a reason for hiding this comment

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

No need for this one, it's fine. After migration to v0.46 or v0.47 the consistency will shift towards interfaces anyways.

x/oracle/keeper/params.go Show resolved Hide resolved
x/oracle/abci.go Show resolved Hide resolved
@akaladarshi akaladarshi changed the base branch from master to tikaryan/development February 14, 2023 14:44
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.

Spotted one new thing.

proto/persistence/oracle/v1beta1/query.proto Outdated Show resolved Hide resolved
@xlab
Copy link
Contributor

xlab commented Feb 24, 2023

All changes are good. Also, I rebased them on my PR - #382 so it's also ready to merge into this one.

One note:

The doc now refers to https://classic-docs.terra.money/docs/develop/module-specifications/spec-oracle.html#parameters which includes VoteThreshold parameter. But afaik that parameter is not used in our implementation. Yet, we need use it the same way.

Actually, I think this flow may help us to avoid security issues with only one voter in a ballot.
Screenshot 2023-02-24 at 01 17 37

@akaladarshi akaladarshi merged commit c7896c1 into tikaryan/development Feb 27, 2023
akaladarshi added a commit that referenced this pull request Mar 19, 2023
## 1. Overview

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.

## 2. Implementation details

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.
@ajeet97 ajeet97 mentioned this pull request Apr 14, 2023
ajeet97 pushed a commit that referenced this pull request Apr 14, 2023
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.
xlab pushed a commit that referenced this pull request Apr 14, 2023
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.
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

2 participants