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: general oracle improvements and ABCI determinism #1391

Merged
merged 7 commits into from
Sep 18, 2022

Conversation

robert-zaremba
Copy link
Member

@robert-zaremba robert-zaremba commented Sep 15, 2022

Description

Few improvements while going through the oracle code.
Notable hardening the OrganizeBallotByDenom function to use deterministic list, rather than map. This could cause potential chain halt.

Closes: #1046


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 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)
  • provided a link to the relevant issue or specification
  • added a changelog entry to CHANGELOG.md
  • included comments for documenting Go code
  • 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 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)

@@ -20,25 +20,21 @@
defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyEndBlocker)

params := k.GetParams(ctx)
if IsPeriodLastBlock(ctx, params.VotePeriod) {
if isPeriodLastBlock(ctx, params.VotePeriod) {

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
x/oracle/abci.go Fixed Show fixed Hide fixed
x/oracle/abci.go Fixed Show fixed Hide fixed
x/oracle/abci.go Fixed Show fixed Hide fixed
// Organize votes to ballot by denom
// NOTE: **Filter out inactive or jailed validators**
voteMap := k.OrganizeBallotByDenom(ctx, validatorClaimMap)
k.ClearExchangeRates(ctx)

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt

ballotDenomSlice := types.BallotMapToSlice(voteMap)
// NOTE: it filters out inactive or jailed validators
ballotDenomSlice := k.OrganizeBallotByDenom(ctx, validatorClaimMap)

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
@@ -106,14 +95,14 @@

// Slash oracle providers who missed voting over the threshold and
// reset miss counters of all validators at the last block of slash window
if IsPeriodLastBlock(ctx, params.SlashWindow) {
if isPeriodLastBlock(ctx, params.SlashWindow) {

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
@adamewozniak
Copy link
Collaborator

looking at this tomorrow morning

Copy link
Collaborator

@adamewozniak adamewozniak left a comment

Choose a reason for hiding this comment

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

lgtm except for 1 comment, pre-approving

x/oracle/abci.go Show resolved Hide resolved
validatorClaimMap[valAddr.String()] = types.NewClaim(validator.GetConsensusPower(powerReduction), 0, 0, valAddr)
i++
}
for _, v := range k.StakingKeeper.GetBondedValidatorsByPower(ctx) {

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
i++
}
for _, v := range k.StakingKeeper.GetBondedValidatorsByPower(ctx) {
addr := v.GetOperator()

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
}
for _, v := range k.StakingKeeper.GetBondedValidatorsByPower(ctx) {
addr := v.GetOperator()
validatorClaimMap[addr.String()] = types.NewClaim(v.GetConsensusPower(powerReduction), 0, 0, addr)

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
}
for _, v := range k.StakingKeeper.GetBondedValidatorsByPower(ctx) {
addr := v.GetOperator()
validatorClaimMap[addr.String()] = types.NewClaim(v.GetConsensusPower(powerReduction), 0, 0, addr)

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
@codecov-commenter
Copy link

codecov-commenter commented Sep 18, 2022

Codecov Report

Merging #1391 (cd97331) into main (ee334f2) will increase coverage by 0.08%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1391      +/-   ##
==========================================
+ Coverage   52.44%   52.52%   +0.08%     
==========================================
  Files          71       70       -1     
  Lines        6802     6692     -110     
==========================================
- Hits         3567     3515      -52     
+ Misses       2966     2909      -57     
+ Partials      269      268       -1     
Impacted Files Coverage Δ
x/oracle/keeper/ballot.go 100.00% <100.00%> (ø)
x/oracle/keeper/keeper.go 84.79% <100.00%> (+0.28%) ⬆️
x/oracle/types/utils_test.go

@robert-zaremba robert-zaremba changed the title chore: general oracle improvements fix: general oracle improvements and ABCI determinism Sep 18, 2022
@toteki toteki merged commit 4217dcc into main Sep 18, 2022
@toteki toteki deleted the robert/oracle-updates branch September 18, 2022 21:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Internal x/oracle audit
4 participants