-
Notifications
You must be signed in to change notification settings - Fork 18
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
feat: add oracle upgrade endblocker #578
Merged
Merged
Changes from 14 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
3893eae
feat: add extra commission rate flags to genoracle cmd
audtlr24 8330472
feat: add v2.1.0 upgrade handler (#552)
0xHansLee eda304c
ci: make actions work for main branch (#555)
fecab14
feat: add oracle upgrade proposal tx & cli
audtlr24 af4a238
feat: add test code
audtlr24 402eeb1
feat: add oracle upgrade proposal tx & cli
audtlr24 468a132
feat: add test code
audtlr24 31557d5
Merge remote-tracking branch 'origin/ft/569/oracle-upgrade-handler' i…
audtlr24 860223d
feat: add oracle upgrade to EndBlocker
audtlr24 07b94cc
fix
audtlr24 cb6b661
fix
audtlr24 1ee72d5
fix
audtlr24 34fee18
fix
audtlr24 660d959
Merge remote-tracking branch 'origin/ft/569/oracle-upgrade-handler' i…
audtlr24 eb162b1
Merge remote-tracking branch 'origin/main' into ft/570/upgrade-endblo…
audtlr24 8e1a3d8
fix
audtlr24 d6c6033
fix
audtlr24 da6a09a
Update x/oracle/types/oracle.go
audtlr24 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
syntax = "proto3"; | ||
package panacea.oracle.v2; | ||
|
||
option go_package = "github.com/medibloc/panacea-core/x/oracle/types"; | ||
option (gogoproto.goproto_getters_all) = false; | ||
|
||
import "gogoproto/gogo.proto"; | ||
|
||
// Plan defines upgrade plan information. | ||
message Plan { | ||
option (gogoproto.equal) = true; | ||
|
||
string unique_id = 1; | ||
|
||
int64 height = 2; | ||
} | ||
|
||
// OracleUpgradeProposal defines the information required for a proposal. | ||
message OracleUpgradeProposal { | ||
option (gogoproto.equal) = true; | ||
|
||
string title = 1; | ||
string description = 2; | ||
Plan plan = 3 [(gogoproto.nullable) = false]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package oracle | ||
|
||
import ( | ||
"errors" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/medibloc/panacea-core/v2/x/oracle/keeper" | ||
"github.com/medibloc/panacea-core/v2/x/oracle/types" | ||
) | ||
|
||
func EndBlocker(ctx sdk.Context, keeper keeper.Keeper) { | ||
handlerOracleUpgrade(ctx, keeper) | ||
} | ||
|
||
func handlerOracleUpgrade(ctx sdk.Context, keeper keeper.Keeper) { | ||
upgradeInfo, err := keeper.GetOracleUpgradeInfo(ctx) | ||
if err != nil { | ||
if errors.Is(err, types.ErrOracleUpgradeInfoNotFound) { | ||
return | ||
} else { | ||
panic(err) | ||
} | ||
} | ||
|
||
if upgradeInfo.ShouldExecute(ctx) { | ||
if err := keeper.ApplyUpgrade(ctx, upgradeInfo); err != nil { | ||
panic(err) | ||
} | ||
keeper.RemoveOracleUpgradeInfo(ctx) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package oracle_test | ||
|
||
import ( | ||
"encoding/base64" | ||
"testing" | ||
|
||
"github.com/btcsuite/btcd/btcec" | ||
"github.com/medibloc/panacea-core/v2/types/testsuite" | ||
"github.com/medibloc/panacea-core/v2/x/oracle" | ||
"github.com/medibloc/panacea-core/v2/x/oracle/types" | ||
"github.com/stretchr/testify/suite" | ||
) | ||
|
||
type abciTestSuite struct { | ||
testsuite.TestSuite | ||
|
||
uniqueID string | ||
} | ||
|
||
func TestAbciTestSuite(t *testing.T) { | ||
suite.Run(t, new(abciTestSuite)) | ||
} | ||
|
||
func (suite *abciTestSuite) BeforeTest(_, _ string) { | ||
ctx := suite.Ctx | ||
suite.uniqueID = "uniqueID" | ||
|
||
oraclePrivKey, err := btcec.NewPrivateKey(btcec.S256()) | ||
suite.Require().NoError(err) | ||
|
||
suite.OracleKeeper.SetParams(ctx, types.Params{ | ||
OraclePublicKey: base64.StdEncoding.EncodeToString(oraclePrivKey.PubKey().SerializeCompressed()), | ||
OraclePubKeyRemoteReport: base64.StdEncoding.EncodeToString([]byte("oraclePubKeyRemoteReport")), | ||
UniqueId: suite.uniqueID, | ||
}) | ||
} | ||
|
||
func (suite *abciTestSuite) TestOracleUpgradeSuccess() { | ||
ctx := suite.Ctx | ||
ctx = ctx.WithBlockHeight(1) | ||
|
||
suite.Require().Equal(suite.uniqueID, suite.OracleKeeper.GetParams(ctx).UniqueId) | ||
|
||
upgradeUniqueID := "upgradeUniqueID" | ||
|
||
upgradeInfo := &types.OracleUpgradeInfo{ | ||
UniqueId: upgradeUniqueID, | ||
Height: 10, | ||
} | ||
|
||
suite.Require().NoError(suite.OracleKeeper.SetOracleUpgradeInfo(ctx, upgradeInfo)) | ||
|
||
ctx = ctx.WithBlockHeight(10) | ||
|
||
oracle.EndBlocker(ctx, suite.OracleKeeper) | ||
|
||
suite.Require().Equal(upgradeUniqueID, suite.OracleKeeper.GetParams(ctx).UniqueId) | ||
|
||
_, err := suite.OracleKeeper.GetOracleUpgradeInfo(ctx) | ||
suite.Require().Error(err, types.ErrOracleUpgradeInfoNotFound) | ||
} | ||
|
||
func (suite *abciTestSuite) TestOracleUpgradeFailedBeforeReachUpgradeHeight() { | ||
ctx := suite.Ctx | ||
ctx = ctx.WithBlockHeight(1) | ||
|
||
suite.Require().Equal(suite.uniqueID, suite.OracleKeeper.GetParams(ctx).UniqueId) | ||
|
||
upgradeUniqueID := "upgradeUniqueID" | ||
|
||
upgradeInfo := &types.OracleUpgradeInfo{ | ||
UniqueId: upgradeUniqueID, | ||
Height: 10, | ||
} | ||
|
||
suite.Require().NoError(suite.OracleKeeper.SetOracleUpgradeInfo(ctx, upgradeInfo)) | ||
|
||
ctx = ctx.WithBlockHeight(9) | ||
|
||
oracle.EndBlocker(ctx, suite.OracleKeeper) | ||
|
||
suite.Require().Equal(suite.uniqueID, suite.OracleKeeper.GetParams(ctx).UniqueId) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package cli | ||
|
||
import ( | ||
"github.com/cosmos/cosmos-sdk/client" | ||
"github.com/cosmos/cosmos-sdk/client/flags" | ||
"github.com/medibloc/panacea-core/v2/x/oracle/types" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func CmdGetOracleUpgradeInfo() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "oracle-upgrade-info", | ||
Short: "Query an oracle upgrade information", | ||
Args: cobra.ExactArgs(0), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
clientCtx, err := client.GetClientQueryContext(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
queryClient := types.NewQueryClient(clientCtx) | ||
|
||
res, err := queryClient.OracleUpgradeInfo(cmd.Context(), &types.QueryOracleUpgradeInfoRequest{}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return clientCtx.PrintProto(res) | ||
}, | ||
} | ||
|
||
flags.AddQueryFlagsToCmd(cmd) | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package cli | ||
|
||
import ( | ||
"github.com/cosmos/cosmos-sdk/client" | ||
"github.com/cosmos/cosmos-sdk/client/tx" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
govcli "github.com/cosmos/cosmos-sdk/x/gov/client/cli" | ||
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" | ||
"github.com/medibloc/panacea-core/v2/x/oracle/types" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
const ( | ||
FlagUpgradeUniqueID = "upgrade-unique-id" | ||
FlagUpgradeHeight = "upgrade-height" | ||
) | ||
|
||
func CmdUpgradeOracleProposal() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "oracle-upgrade (--upgrade-unique-id [uniqueID]) (--upgrade-height [height]) [flags]", | ||
Args: cobra.ExactArgs(0), | ||
Short: "Submit an oracle upgrade proposal", | ||
Long: "Submit an oracle upgrade proposal along with an initial deposit.\n + " + | ||
"You must enter the uniqueID of a new version of oracle and target block height for upgrade.", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
clientCtx, err := client.GetClientTxContext(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
from := clientCtx.GetFromAddress() | ||
|
||
depositStr, err := cmd.Flags().GetString(govcli.FlagDeposit) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
deposit, err := sdk.ParseCoinsNormalized(depositStr) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
content, err := makeProposalContent(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
msg, err := govtypes.NewMsgSubmitProposal(content, deposit, from) | ||
if err != nil { | ||
return err | ||
} | ||
if err := msg.ValidateBasic(); err != nil { | ||
return err | ||
} | ||
|
||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) | ||
}, | ||
} | ||
cmd.Flags().String(govcli.FlagTitle, "", "title of proposal") | ||
cmd.Flags().String(govcli.FlagDescription, "", "description of proposal") | ||
cmd.Flags().String(govcli.FlagDeposit, "", "deposit of proposal") | ||
cmd.Flags().Int64(FlagUpgradeHeight, 0, "The height at which the upgrade must happen") | ||
cmd.Flags().String(FlagUpgradeUniqueID, "", "Oracle's uniqueID to be upgraded") | ||
|
||
if err := cmd.MarkFlagRequired(FlagUpgradeHeight); err != nil { | ||
panic(err) | ||
} | ||
if err := cmd.MarkFlagRequired(FlagUpgradeUniqueID); err != nil { | ||
panic(err) | ||
} | ||
return cmd | ||
} | ||
|
||
func makeProposalContent(cmd *cobra.Command) (govtypes.Content, error) { | ||
title, err := cmd.Flags().GetString(govcli.FlagTitle) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
description, err := cmd.Flags().GetString(govcli.FlagDescription) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
height, err := cmd.Flags().GetInt64(FlagUpgradeHeight) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
uniqueID, err := cmd.Flags().GetString(FlagUpgradeUniqueID) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
plan := types.Plan{UniqueId: uniqueID, Height: height} | ||
if err := plan.ValidateBasic(); err != nil { | ||
return nil, err | ||
} | ||
content := types.NewOracleUpgradeProposal(title, description, plan) | ||
return content, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package client | ||
|
||
import ( | ||
govclient "github.com/cosmos/cosmos-sdk/x/gov/client" | ||
"github.com/medibloc/panacea-core/v2/x/oracle/client/rest" | ||
|
||
"github.com/medibloc/panacea-core/v2/x/oracle/client/cli" | ||
) | ||
|
||
var ProposalHandler = govclient.NewProposalHandler(cli.CmdUpgradeOracleProposal, rest.ProposalRESTHandler) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about not deleting the upgrade info?
When a new upgrade proposal passes, it will be overwritten anyway.
The reason I'm talking about this is because of the following case:
If the oracles didn't upgrade until the target height, they had to re-request
register-oracle
transaction again to be shared the oracle private key in the new binary(upgrade version).However, at this time, the oracles will be able to enter the commission rate, which overwrites the existing oracle commission rate.
In other words, this case should also be done through
upgrade-oracle
, and to do so, it seems that upgrade info should be left. upgrade info will mean upcoming or recent upgrade information.--
FYI) Plus, in
register-oracle
, the check that if the oracle has already been set or not should be added.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good idea.
Then, how about
OracleKeyMigration
rather than a nameOracleUpgrade
?OracleKeyMigration works only when it has the same value as uniqueID of
OracleUpgradeInfo
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, please forget the name change. I'll think about it more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I understand the problem.
If the oracles didn't upgrade until the target height, oracle operator have to use
upgrade-oracle
because the oracle is already inOracle
store.For now, I think @H4NLee 's suggestion is the best way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you reflect this flow, please leave a comment :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fixed it in 8e1a3d8.