Skip to content

Commit

Permalink
refactor(oracle): simplify window progress query (#1294)
Browse files Browse the repository at this point in the history
Simplifies the math for the oracle window progress query.

This was one of those things, "wait, why did I do it that way?"

---

### Author Checklist

_All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues._

I have...

- [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] added `!` to the type prefix if API or client breaking change
- [ ] added appropriate labels to the PR
- [ ] targeted the correct branch (see [PR Targeting](https://github.com/umee-network/umee/blob/main/CONTRIBUTING.md#pr-targeting))
- [ ] provided a link to the relevant issue or specification
- [ ] added a changelog entry to `CHANGELOG.md`
- [ ] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [ ] updated the relevant documentation or specification
- [ ] reviewed "Files changed" and left comments if necessary
- [ ] confirmed all CI checks have passed

### Reviewers Checklist

_All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items._

I have...

- [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] confirmed all author checklist items have been addressed
- [ ] reviewed state machine logic
- [ ] reviewed API design and naming
- [ ] reviewed documentation is accurate
- [ ] reviewed tests and test coverage
- [ ] manually tested (if applicable)
  • Loading branch information
adamewozniak authored Aug 26, 2022
1 parent 4bdbf52 commit dbf5b89
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 19 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
- [987](https://github.com/umee-network/umee/pull/987) Streamline x/leverage CLI tests
- [1012](https://github.com/umee-network/umee/pull/1012) Improve negative time elapsed error message
- [1236](https://github.com/umee-network/umee/pull/1236) Improve leverage event fields.
- [1294](https://github.com/umee-network/umee/pull/1294) Simplify window progress query math.

### Bug Fixes

Expand Down
11 changes: 2 additions & 9 deletions x/oracle/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,16 +148,9 @@ func (q querier) SlashWindow(
ctx := sdk.UnwrapSDKContext(goCtx)
params := q.GetParams(ctx)

slashWindow := params.SlashWindow
votePeriod := params.VotePeriod
currentBlock := uint64(ctx.BlockHeight())
votePeriodsPerSlashWindow := slashWindow / votePeriod

currentSlashWindow := currentBlock / votePeriodsPerSlashWindow
blocksIntoSlashWindow := currentBlock - (currentSlashWindow * slashWindow)

return &types.QuerySlashWindowResponse{
WindowProgress: blocksIntoSlashWindow / votePeriod,
WindowProgress: (uint64(ctx.BlockHeight()) / params.VotePeriod) %
params.SlashWindow,
}, nil
}

Expand Down
20 changes: 10 additions & 10 deletions x/oracle/types/query.pb.gw.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit dbf5b89

Please sign in to comment.