Skip to content

Commit

Permalink
update VoteExtension2 to VoteExtension
Browse files Browse the repository at this point in the history
  • Loading branch information
antstalepresh committed Jul 12, 2024
1 parent 95f54a2 commit b1c5f91
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 95 deletions.
2 changes: 1 addition & 1 deletion proto/kujira/oracle/oracle.proto
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ message ExchangeRateTuple {
];
}

message VoteExtension2 {
message VoteExtension {
int64 height = 1;
map<uint32, bytes> prices = 2;
}
6 changes: 3 additions & 3 deletions x/oracle/abci/compress.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func DecompressDecimal(bz []byte) math.LegacyDec {
return amountDec
}

func ComposeVoteExtension2(k keeper.Keeper, ctx sdk.Context, height int64, exchangeRates sdk.DecCoins) types.VoteExtension2 {
func ComposeVoteExtension(k keeper.Keeper, ctx sdk.Context, height int64, exchangeRates sdk.DecCoins) types.VoteExtension {
params := k.GetParams(ctx)
symbolIDs := make(map[string]uint32)
for _, symbol := range params.RequiredSymbols {
Expand All @@ -49,13 +49,13 @@ func ComposeVoteExtension2(k keeper.Keeper, ctx sdk.Context, height int64, excha
}
prices[id] = CompressDecimal(rate.Amount, 8)
}
return types.VoteExtension2{
return types.VoteExtension{
Height: height,
Prices: prices,
}
}

func ExchangeRatesFromVoteExtension2(k keeper.Keeper, ctx sdk.Context, voteExt types.VoteExtension2) sdk.DecCoins {
func ExchangeRatesFromVoteExtension(k keeper.Keeper, ctx sdk.Context, voteExt types.VoteExtension) sdk.DecCoins {
params := k.GetParams(ctx)
idToSymbol := make(map[uint32]string)
for _, symbol := range params.RequiredSymbols {
Expand Down
4 changes: 2 additions & 2 deletions x/oracle/abci/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,13 +248,13 @@ func (h *ProposalHandler) GetBallotByDenom(ctx sdk.Context, ci abci.ExtendedComm
if ok {
power := claim.Power

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

exchangeRates := ExchangeRatesFromVoteExtension2(h.keeper, ctx, voteExt)
exchangeRates := ExchangeRatesFromVoteExtension(h.keeper, ctx, voteExt)
for _, tuple := range exchangeRates {
base := tuple.Denom
price := tuple.Amount
Expand Down
20 changes: 10 additions & 10 deletions x/oracle/abci/proposal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,14 @@ func TestGetBallotByDenom(t *testing.T) {
power := int64(100)

// organize votes by denom
voteExt1 := types.VoteExtension2{
voteExt1 := types.VoteExtension{
Height: 1,
Prices: map[uint32][]byte{
1: abci.CompressDecimal(math.LegacyNewDec(25000), 8),
2: abci.CompressDecimal(math.LegacyNewDec(2200), 8),
},
}
voteExt2 := types.VoteExtension2{
voteExt2 := types.VoteExtension{
Height: 1,
Prices: map[uint32][]byte{
1: abci.CompressDecimal(math.LegacyNewDec(25030), 8),
Expand Down Expand Up @@ -165,14 +165,14 @@ func TestComputeStakeWeightedPricesAndMissMap(t *testing.T) {
input, h := SetupTest(t)

// organize votes by denom
voteExt1 := types.VoteExtension2{
voteExt1 := types.VoteExtension{
Height: 1,
Prices: map[uint32][]byte{
1: abci.CompressDecimal(math.LegacyNewDec(25000), 8),
2: abci.CompressDecimal(math.LegacyNewDec(2200), 8),
},
}
voteExt2 := types.VoteExtension2{
voteExt2 := types.VoteExtension{
Height: 1,
Prices: map[uint32][]byte{
1: abci.CompressDecimal(math.LegacyNewDec(25030), 8),
Expand Down Expand Up @@ -497,14 +497,14 @@ func TestPrepareProposal(t *testing.T) {
require.Error(t, err)

// Valid vote extension data
voteExt1 := types.VoteExtension2{
voteExt1 := types.VoteExtension{
Height: 1,
Prices: map[uint32][]byte{
1: abci.CompressDecimal(math.LegacyNewDec(25000), 8),
2: abci.CompressDecimal(math.LegacyNewDec(2200), 8),
},
}
voteExt2 := types.VoteExtension2{
voteExt2 := types.VoteExtension{
Height: 1,
Prices: map[uint32][]byte{
1: abci.CompressDecimal(math.LegacyNewDec(25030), 8),
Expand Down Expand Up @@ -646,14 +646,14 @@ func TestProcessProposal(t *testing.T) {
input.Ctx = input.Ctx.WithCometInfo(info)

// Valid vote extension data
voteExt1 := types.VoteExtension2{
voteExt1 := types.VoteExtension{
Height: 1,
Prices: map[uint32][]byte{
1: abci.CompressDecimal(math.LegacyNewDec(25000), 8),
2: abci.CompressDecimal(math.LegacyNewDec(2200), 8),
},
}
voteExt2 := types.VoteExtension2{
voteExt2 := types.VoteExtension{
Height: 1,
Prices: map[uint32][]byte{
1: abci.CompressDecimal(math.LegacyNewDec(25030), 8),
Expand Down Expand Up @@ -856,14 +856,14 @@ func TestPreBlocker(t *testing.T) {
input.Ctx = input.Ctx.WithConsensusParams(consParams)

// Valid vote extension data
voteExt1 := types.VoteExtension2{
voteExt1 := types.VoteExtension{
Height: 1,
Prices: map[uint32][]byte{
1: abci.CompressDecimal(math.LegacyNewDec(25000), 8),
2: abci.CompressDecimal(math.LegacyNewDec(2200), 8),
},
}
voteExt2 := types.VoteExtension2{
voteExt2 := types.VoteExtension{
Height: 1,
Prices: map[uint32][]byte{
1: abci.CompressDecimal(math.LegacyNewDec(25030), 8),
Expand Down
8 changes: 4 additions & 4 deletions x/oracle/abci/vote_extensions.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (h *VoteExtHandler) ExtendVoteHandler(oracleConfig OracleConfig) sdk.Extend

h.logger.Info("computing oracle prices for vote extension", "height", req.Height, "time", h.lastPriceSyncTS, "endpoint", oracleConfig.Endpoint)

emptyVoteExt := types.VoteExtension2{
emptyVoteExt := types.VoteExtension{
Height: req.Height,
Prices: make(map[uint32][]byte),
}
Expand Down Expand Up @@ -81,7 +81,7 @@ func (h *VoteExtHandler) ExtendVoteHandler(oracleConfig OracleConfig) sdk.Extend
}

// produce a canonical vote extension
voteExt := ComposeVoteExtension2(h.Keeper, ctx, req.Height, computedPrices)
voteExt := ComposeVoteExtension(h.Keeper, ctx, req.Height, computedPrices)

h.logger.Info("computed prices", "prices", computedPrices)

Expand All @@ -97,7 +97,7 @@ func (h *VoteExtHandler) ExtendVoteHandler(oracleConfig OracleConfig) sdk.Extend

func (h *VoteExtHandler) VerifyVoteExtensionHandler(_ OracleConfig) sdk.VerifyVoteExtensionHandler {
return func(ctx sdk.Context, req *abci.RequestVerifyVoteExtension) (*abci.ResponseVerifyVoteExtension, error) {
var voteExt types.VoteExtension2
var voteExt types.VoteExtension

if len(req.VoteExtension) == 0 {
return &abci.ResponseVerifyVoteExtension{Status: abci.ResponseVerifyVoteExtension_ACCEPT}, nil
Expand All @@ -116,7 +116,7 @@ func (h *VoteExtHandler) VerifyVoteExtensionHandler(_ OracleConfig) sdk.VerifyVo

// Verify incoming prices from a validator are valid. Note, verification during
// VerifyVoteExtensionHandler MUST be deterministic.
prices := ExchangeRatesFromVoteExtension2(h.Keeper, ctx, voteExt)
prices := ExchangeRatesFromVoteExtension(h.Keeper, ctx, voteExt)
if err := h.verifyOraclePrices(ctx, prices); err != nil {
return nil, fmt.Errorf("failed to verify oracle prices from validator %X: %w", req.ValidatorAddress, err)
}
Expand Down
4 changes: 2 additions & 2 deletions x/oracle/abci/vote_extensions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func TestExtendVoteHandler(t *testing.T) {
ProposerAddress: []byte{},
})
require.NoError(t, err)
voteExt := types.VoteExtension2{}
voteExt := types.VoteExtension{}
err = voteExt.Decompress(res.VoteExtension)
require.NoError(t, err)
require.Equal(t, voteExt.Height, int64(3))
Expand Down Expand Up @@ -74,7 +74,7 @@ func TestVerifyVoteExtensionHandler(t *testing.T) {
Endpoint: testServer.URL,
})

voteExt := types.VoteExtension2{
voteExt := types.VoteExtension{
Height: 3,
Prices: map[uint32][]byte{
1: abci.CompressDecimal(math.LegacyMustNewDecFromStr("47375.706652541026694000"), 8),
Expand Down
4 changes: 2 additions & 2 deletions x/oracle/types/oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func DenomToID(denom string) (uint64, error) {
return binary.LittleEndian.Uint64(md), nil
}

func (m VoteExtension2) Compress() ([]byte, error) {
func (m VoteExtension) Compress() ([]byte, error) {
// Encode vote extension to bytes
bz, err := m.Marshal()
if err != nil {
Expand All @@ -42,7 +42,7 @@ func (m VoteExtension2) Compress() ([]byte, error) {
return b.Bytes(), nil
}

func (m *VoteExtension2) Decompress(bz []byte) error {
func (m *VoteExtension) Decompress(bz []byte) error {
if len(bz) == 0 {
return nil
}
Expand Down
Loading

0 comments on commit b1c5f91

Please sign in to comment.