Skip to content

Commit

Permalink
fix: Implement LegacyGovUpdateParams for querying legacy proposals (b…
Browse files Browse the repository at this point in the history
…ackport #476) (#477)

* fix: Implement LegacyGovUpdateParams for querying legacy proposals (#476)

* fix: Implement LegacyGovUpdateParams for querying legacy proposals

* buf-lint

* lint

* upgrade handler

(cherry picked from commit 71d54a4)

# Conflicts:
#	app/upgrades.go
#	x/oracle/types/msgs.go
#	x/oracle/types/tx.pb.go

* fix conflicts

* tx.pb conflict

---------

Co-authored-by: ryanbajollari <54822716+rbajollari@users.noreply.github.com>
Co-authored-by: rbajollari <rbajollari@gmail.com>
  • Loading branch information
3 people authored Jul 12, 2024
1 parent 499d97c commit 2d3ebd7
Show file tree
Hide file tree
Showing 7 changed files with 910 additions and 83 deletions.
11 changes: 11 additions & 0 deletions app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func (app App) RegisterUpgradeHandlers() {
app.registerUpgrade0_3_0Rc8(upgradeInfo)
app.registerUpgrade0_3_1Rc1(upgradeInfo)
app.registerUpgrade0_3_1Rc2(upgradeInfo)
app.registerUpgrade0_3_1(upgradeInfo)
}

// performs upgrade from v0.1.3 to v0.1.4
Expand Down Expand Up @@ -183,6 +184,16 @@ func (app *App) registerUpgrade0_3_1Rc2(_ upgradetypes.Plan) {
)
}

func (app *App) registerUpgrade0_3_1(_ upgradetypes.Plan) {
const planName = "v0.3.1"
app.UpgradeKeeper.SetUpgradeHandler(planName,
func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
ctx.Logger().Info("Upgrade handler execution", "name", planName)
return app.mm.RunMigrations(ctx, app.configurator, fromVM)
},
)
}

// helper function to check if the store loader should be upgraded
func (app *App) storeUpgrade(planName string, ui upgradetypes.Plan, stores storetypes.StoreUpgrades) {
if ui.Name == planName && !app.UpgradeKeeper.IsSkipHeight(ui.Height) {
Expand Down
23 changes: 22 additions & 1 deletion proto/ojo/oracle/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ service Msg {
rpc DelegateFeedConsent(MsgDelegateFeedConsent)
returns (MsgDelegateFeedConsentResponse);

// LegacyGovUpdateParams defines the legacy message that updates the oracle parameters.
rpc LegacyGovUpdateParams(MsgLegacyGovUpdateParams)
returns (MsgLegacyGovUpdateParamsResponse);

// GovUpdateParams updates the oracle parameters.
rpc GovUpdateParams(MsgGovUpdateParams)
returns (MsgGovUpdateParamsResponse);
Expand Down Expand Up @@ -98,6 +102,24 @@ message MsgDelegateFeedConsent {
// type.
message MsgDelegateFeedConsentResponse {}

// MsgLegacyGovUpdateParams defines the Msg/MsgLegacyGovUpdateParams request type.
message MsgLegacyGovUpdateParams {
option (gogoproto.equal) = true;
option (gogoproto.goproto_getters) = false;
option (gogoproto.goproto_stringer) = false;
option (cosmos.msg.v1.signer) = "authority";

// authority is the address of the governance account.
string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
string title = 2;
string description = 3;
repeated string keys = 4;
Params changes = 5 [ (gogoproto.nullable) = false ];
}

// MsgLegacyGovUpdateParams defines the Msg/MsgLegacyGovUpdateParams response type.
message MsgLegacyGovUpdateParamsResponse {}

// MsgGovUpdateParams defines the Msg/GovUpdateParams request type.
message MsgGovUpdateParams {
option (gogoproto.equal) = true;
Expand All @@ -121,7 +143,6 @@ message MsgGovUpdateParams {
// MsgGovUpdateParamsResponse defines the Msg/GovUpdateParams response type.
message MsgGovUpdateParamsResponse {}


// MsgGovAddDenoms defines the Msg/GovAddDenoms request type.
message MsgGovAddDenoms {
option (gogoproto.equal) = true;
Expand Down
106 changes: 106 additions & 0 deletions x/oracle/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package keeper

import (
"context"
"fmt"
"strings"

"cosmossdk.io/errors"
Expand Down Expand Up @@ -140,6 +141,111 @@ func (ms msgServer) DelegateFeedConsent(
return &types.MsgDelegateFeedConsentResponse{}, err
}

func (ms msgServer) LegacyGovUpdateParams(
goCtx context.Context,
msg *types.MsgLegacyGovUpdateParams,
) (*types.MsgLegacyGovUpdateParamsResponse, error) {
if msg.Authority != ms.authority {
err := errors.Wrapf(
types.ErrNoGovAuthority,
"invalid authority; expected %s, got %s",
ms.authority,
msg.Authority,
)
return nil, err
}

ctx := sdk.UnwrapSDKContext(goCtx)

for _, key := range msg.Keys {
switch key {
case string(types.KeyVotePeriod):
ms.SetVotePeriod(ctx, msg.Changes.VotePeriod)

case string(types.KeyVoteThreshold):
ms.SetVoteThreshold(ctx, msg.Changes.VoteThreshold)

case string(types.KeyRewardBands):
ms.SetRewardBand(ctx, msg.Changes.RewardBands)

case string(types.KeyRewardDistributionWindow):
if msg.Changes.RewardDistributionWindow < ms.Keeper.VotePeriod(ctx) {
return nil, fmt.Errorf("oracle parameter RewardDistributionWindow must be greater than or equal with VotePeriod")
}
ms.SetRewardDistributionWindow(ctx, msg.Changes.RewardDistributionWindow)

case string(types.KeyAcceptList):
accept := msg.Changes.AcceptList.Normalize()
mandatory := ms.Keeper.MandatoryList(ctx).Normalize()
if !accept.ContainDenoms(mandatory) {
return nil, fmt.Errorf("denom in MandatoryList not present in AcceptList")
}
ms.SetAcceptList(ctx, accept)

case string(types.KeyMandatoryList):
mandatory := msg.Changes.MandatoryList.Normalize()
accept := ms.Keeper.AcceptList(ctx).Normalize()
if !accept.ContainDenoms(mandatory) {
return nil, fmt.Errorf("denom in MandatoryList not present in AcceptList")
}
ms.SetMandatoryList(ctx, mandatory)

case string(types.KeySlashFraction):
ms.SetSlashFraction(ctx, msg.Changes.SlashFraction)

case string(types.KeySlashWindow):
if msg.Changes.SlashWindow < ms.Keeper.VotePeriod(ctx) {
return nil, fmt.Errorf("oracle parameter SlashWindow must be greater than or equal with VotePeriod")
}
ms.SetSlashWindow(ctx, msg.Changes.SlashWindow)

case string(types.KeyMinValidPerWindow):
ms.SetMinValidPerWindow(ctx, msg.Changes.MinValidPerWindow)

case string(types.KeyHistoricStampPeriod):
if msg.Changes.HistoricStampPeriod < 1 {
return nil, fmt.Errorf("oracle parameters HistoricStampPeriod must be greater than 0")
}
if msg.Changes.HistoricStampPeriod > ms.Keeper.MedianStampPeriod(ctx) {
return nil, fmt.Errorf("oracle parameter HistoricStampPeriod must be less than or equal with MedianStampPeriod")
}
if msg.Changes.HistoricStampPeriod%ms.Keeper.VotePeriod(ctx) != 0 {
return nil, fmt.Errorf("oracle parameters HistoricStampPeriod must be exact multiples of VotePeriod")
}
ms.SetHistoricStampPeriod(ctx, msg.Changes.HistoricStampPeriod)

case string(types.KeyMedianStampPeriod):
if msg.Changes.MedianStampPeriod < 1 {
return nil, fmt.Errorf("oracle parameters MedianStampPeriod must be greater than 0")
}
if msg.Changes.MedianStampPeriod < ms.Keeper.HistoricStampPeriod(ctx) {
return nil, fmt.Errorf("oracle parameter MedianStampPeriod must be greater than or equal with HistoricStampPeriod")
}
if msg.Changes.MedianStampPeriod%ms.Keeper.VotePeriod(ctx) != 0 {
return nil, fmt.Errorf("oracle parameters MedianStampPeriod must be exact multiples of VotePeriod")
}
ms.SetMedianStampPeriod(ctx, msg.Changes.MedianStampPeriod)

case string(types.KeyMaximumPriceStamps):
if msg.Changes.MaximumPriceStamps < 1 {
return nil, fmt.Errorf("oracle parameters MaximumPriceStamps must be greater than 0")
}
ms.SetMaximumPriceStamps(ctx, msg.Changes.MaximumPriceStamps)

case string(types.KeyMaximumMedianStamps):
if msg.Changes.MaximumMedianStamps < 1 {
return nil, fmt.Errorf("oracle parameters MaximumMedianStamps must be greater than 0")
}
ms.SetMaximumMedianStamps(ctx, msg.Changes.MaximumMedianStamps)

default:
return nil, fmt.Errorf("%s is not an existing oracle param key", key)
}
}

return &types.MsgLegacyGovUpdateParamsResponse{}, nil
}

func (ms msgServer) GovUpdateParams(
goCtx context.Context,
msg *types.MsgGovUpdateParams,
Expand Down
3 changes: 3 additions & 0 deletions x/oracle/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
cdc.RegisterConcrete(&MsgAggregateExchangeRatePrevote{}, "ojo/oracle/MsgAggregateExchangeRatePrevote", nil)
cdc.RegisterConcrete(&MsgAggregateExchangeRateVote{}, "ojo/oracle/MsgAggregateExchangeRateVote", nil)
cdc.RegisterConcrete(&MsgDelegateFeedConsent{}, "ojo/oracle/MsgDelegateFeedConsent", nil)
cdc.RegisterConcrete(&MsgLegacyGovUpdateParams{}, "ojo/oracle/MsgLegacyGovUpdateParams", nil)
cdc.RegisterConcrete(&MsgGovUpdateParams{}, "ojo/oracle/MsgGovUpdateParams", nil)
cdc.RegisterConcrete(&MsgGovAddDenoms{}, "ojo/oracle/MsgGovAddDenoms", nil)
cdc.RegisterConcrete(&MsgGovRemoveCurrencyPairProviders{}, "ojo/oracle/MsgGovRemoveCurrencyPairProviders", nil)
Expand All @@ -49,6 +50,7 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) {
&MsgDelegateFeedConsent{},
&MsgAggregateExchangeRatePrevote{},
&MsgAggregateExchangeRateVote{},
&MsgLegacyGovUpdateParams{},
&MsgGovUpdateParams{},
&MsgGovAddDenoms{},
&MsgGovRemoveCurrencyPairProviders{},
Expand All @@ -57,6 +59,7 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) {

registry.RegisterImplementations(
(*govtypes.Content)(nil),
&MsgLegacyGovUpdateParams{},
&MsgGovUpdateParams{},
&MsgGovAddDenoms{},
&MsgGovRemoveCurrencyPairProviders{},
Expand Down
117 changes: 117 additions & 0 deletions x/oracle/types/msgs.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package types

import (
"fmt"

"github.com/cometbft/cometbft/crypto/tmhash"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
Expand All @@ -13,6 +15,7 @@ var (
_ sdk.Msg = &MsgDelegateFeedConsent{}
_ sdk.Msg = &MsgAggregateExchangeRatePrevote{}
_ sdk.Msg = &MsgAggregateExchangeRateVote{}
_ sdk.Msg = &MsgLegacyGovUpdateParams{}
_ sdk.Msg = &MsgGovUpdateParams{}
_ sdk.Msg = &MsgGovCancelUpdateParamPlan{}
)
Expand Down Expand Up @@ -172,6 +175,120 @@ func (msg MsgDelegateFeedConsent) ValidateBasic() error {
return nil
}

// NewLegacyMsgUpdateParams will creates a new LegacyMsgUpdateParams instance
func NewLegacyMsgUpdateParams(
authority string,
title string,
description string,
keys []string,
changes Params,
) *MsgLegacyGovUpdateParams {
return &MsgLegacyGovUpdateParams{
Title: title,
Description: description,
Authority: authority,
Keys: keys,
Changes: changes,
}
}

// Type implements Msg interface
func (msg MsgLegacyGovUpdateParams) Type() string { return sdk.MsgTypeURL(&msg) }

// String implements the Stringer interface.
func (msg MsgLegacyGovUpdateParams) String() string {
out, _ := yaml.Marshal(msg)
return string(out)
}

// GetSigners implements Msg
func (msg MsgLegacyGovUpdateParams) GetSigners() []sdk.AccAddress {
return checkers.Signers(msg.Authority)
}

// ValidateBasic implements Msg and validates params for each param key
// specified in the proposal. If one param is invalid, the whole proposal
// will fail to go through.
func (msg MsgLegacyGovUpdateParams) ValidateBasic() error {
if err := checkers.ValidateProposal(msg.Title, msg.Description, msg.Authority); err != nil {
return err
}

for _, key := range msg.Keys {
switch key {
case string(KeyVotePeriod):
if err := validateVotePeriod(msg.Changes.VotePeriod); err != nil {
return err
}

case string(KeyVoteThreshold):
if err := validateVoteThreshold(msg.Changes.VoteThreshold); err != nil {
return err
}

case string(KeyRewardBands):
if err := validateRewardBands(msg.Changes.RewardBands); err != nil {
return err
}

case string(KeyRewardDistributionWindow):
if err := validateRewardDistributionWindow(msg.Changes.RewardDistributionWindow); err != nil {
return err
}

case string(KeyAcceptList):
if err := validateDenomList(msg.Changes.AcceptList); err != nil {
return err
}

case string(KeyMandatoryList):
if err := validateDenomList(msg.Changes.MandatoryList); err != nil {
return err
}

case string(KeySlashFraction):
if err := validateSlashFraction(msg.Changes.SlashFraction); err != nil {
return err
}

case string(KeySlashWindow):
if err := validateSlashWindow(msg.Changes.SlashWindow); err != nil {
return err
}

case string(KeyMinValidPerWindow):
if err := validateMinValidPerWindow(msg.Changes.MinValidPerWindow); err != nil {
return err
}

case string(KeyHistoricStampPeriod):
if err := validateHistoricStampPeriod(msg.Changes.HistoricStampPeriod); err != nil {
return err
}

case string(KeyMedianStampPeriod):
if err := validateMedianStampPeriod(msg.Changes.MedianStampPeriod); err != nil {
return err
}

case string(KeyMaximumPriceStamps):
if err := validateMaximumPriceStamps(msg.Changes.MaximumPriceStamps); err != nil {
return err
}

case string(KeyMaximumMedianStamps):
if err := validateMaximumMedianStamps(msg.Changes.MaximumMedianStamps); err != nil {
return err
}

default:
return fmt.Errorf("%s is not an existing oracle param key", key)
}
}

return nil
}

// NewMsgUpdateParams will creates a new MsgUpdateParams instance
func NewMsgUpdateParams(authority, title, description string, plan ParamUpdatePlan) *MsgGovUpdateParams {
return &MsgGovUpdateParams{
Expand Down
19 changes: 19 additions & 0 deletions x/oracle/types/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
)

var (
proposalTypeMsgLegacyGovUpdateParams = MsgLegacyGovUpdateParams{}.String()
proposalTypeMsgGovUpdateParams = MsgGovUpdateParams{}.String()
proposalTypeMsgGovCancelUpdateParams = MsgGovCancelUpdateParamPlan{}.String()
proposalTypeMsgGovAddDenoms = MsgGovAddDenoms{}.String()
Expand All @@ -13,13 +14,31 @@ var (
)

func init() {
gov.RegisterProposalType(proposalTypeMsgLegacyGovUpdateParams)
gov.RegisterProposalType(proposalTypeMsgGovUpdateParams)
gov.RegisterProposalType(proposalTypeMsgGovCancelUpdateParams)
gov.RegisterProposalType(proposalTypeMsgGovAddDenoms)
gov.RegisterProposalType(proposalTypeMsgGovRemoveCurrencyPairProviders)
gov.RegisterProposalType(proposalTypeMsgGovRemoveCurrencyDeviationThresholds)
}

// Implements Proposal Interface
var _ gov.Content = &MsgLegacyGovUpdateParams{}

// GetTitle returns the title of a community pool spend proposal.
func (msg *MsgLegacyGovUpdateParams) GetTitle() string { return msg.Title }

// GetDescription returns the description of a community pool spend proposal.
func (msg *MsgLegacyGovUpdateParams) GetDescription() string { return msg.Description }

// GetDescription returns the routing key of a community pool spend proposal.
func (msg *MsgLegacyGovUpdateParams) ProposalRoute() string { return RouterKey }

// ProposalType returns the type of a community pool spend proposal.
func (msg *MsgLegacyGovUpdateParams) ProposalType() string {
return proposalTypeMsgLegacyGovUpdateParams
}

// Implements Proposal Interface
var _ gov.Content = &MsgGovUpdateParams{}

Expand Down
Loading

0 comments on commit 2d3ebd7

Please sign in to comment.