Skip to content

Commit

Permalink
convert vote extension to protobuf & use legacyDec.BigInt
Browse files Browse the repository at this point in the history
  • Loading branch information
antstalepresh committed Feb 19, 2024
1 parent c29d16a commit f828fee
Show file tree
Hide file tree
Showing 6 changed files with 1,170 additions and 75 deletions.
28 changes: 28 additions & 0 deletions proto/kujira/oracle/extension.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
syntax = "proto3";
package kujira.oracle;

import "gogoproto/gogo.proto";
import "kujira/oracle/genesis.proto";
import "tendermint/abci/types.proto";

option go_package = "github.com/Team-Kujira/core/x/oracle/types";

message DenomPrice {
string denom = 1;
string price = 2 [
(gogoproto.nullable) = false,
(gogoproto.customtype) = "cosmossdk.io/math.Int"
];
}

message VoteExtension {
int64 height = 1;
repeated DenomPrice prices = 2 [ (gogoproto.nullable) = false ];
}

// VoteExtensionTx defines vote extension execution tx
message VoteExtensionTx {
repeated DenomPrice stake_weighted_prices = 1 [ (gogoproto.nullable) = false ];
MissCounter miss_counter = 2 [ (gogoproto.nullable) = false ];
tendermint.abci.ExtendedCommitInfo extended_commit_info = 3 [ (gogoproto.nullable) = false ];
}
9 changes: 6 additions & 3 deletions x/oracle/abci/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/mempool"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/gogoproto/proto"
)

// StakeWeightedPrices defines the structure a proposer should use to calculate
Expand Down Expand Up @@ -248,13 +249,15 @@ func (h *ProposalHandler) GetBallotByDenom(ci abci.ExtendedCommitInfo, validator
if ok {
power := claim.Power

var voteExt OracleVoteExtension
if err := json.Unmarshal(v.VoteExtension, &voteExt); err != nil {
var voteExt types.VoteExtension
if err := proto.Unmarshal(v.VoteExtension, &voteExt); err != nil {
h.logger.Error("failed to decode vote extension", "err", err, "validator", fmt.Sprintf("%x", v.Validator.Address))
return votes
}

for base, price := range voteExt.Prices {
for _, denomPrice := range voteExt.Prices {
base := denomPrice.Denom
price := math.LegacyNewDecFromBigIntWithPrec(denomPrice.Price.BigInt(), math.LegacyPrecision)
tmpPower := power
if !price.IsPositive() {
// Make the power of abstain vote zero
Expand Down
Loading

0 comments on commit f828fee

Please sign in to comment.